Please support wikEd[edit]

Please support wikEd by helping to fix the following browser and MediaWiki issues.

This is the developer page and program documentation for wikEd, a full-featured in-browser text editor that adds enhanced text processing functions to Wikipedia and other MediaWiki edit pages. Please use this talk page for discussing wikEd development issues.

How it works

wikEd replaces the classic textarea input field with an iframe in designmode. That is essentially a separate html page that can be edited. The browser's rich-text editing interface is used to manipulate the text upon clicking a wikEd button, see [1]. After pushing the Save page button the content is copied back to the hidden textarea and then submitted.

Program structure

(Somewhat outdated)

Built-in user interface texts
Edit-frame css rules
Main window css rules
Button image URLs
Button definitions
Toolbar definition
User customizable variables
Global variables including DOM elements
Check for updates (Ajax)
Schedules the setup routine to run after the page has been loaded
Loads the diff script
Loads the Live Preview script
Rearranges page elements into wrapper divs
Puts the wikEd buttons on the page
Generates the combo input boxes (input with drop-down button)
Generates the iframe in design mode that replaces the classic textarea input field
Copies the textarea content to the iframe
  • Event handler definitions
Load and parse the RegExTypoFix rules using Ajax

Programming conventions

Greasemonkey-compatibility

Debugging setup

For performance reasons it is highly recommended to test the scripts on a local copy of a Wikipedia edit page. (Outdated)

 var wikEdAutoUpdate = false;
 var wikEdUseLocalImages = true;
 var wikEdImagePathLocal = 'file:///D:/wikEd/images/'; // the directory were you keep all wikEd button images
 var wikEdSkipBrowserTest = true; // this enables wikEd under IE and Opera
 var wikEdShowSourceButton = true;
 var wikEdDiffScriptSrc = 'file:///D:/wikEd/diff.js'; // the local diff program used for 'Show current changes below'
 var wikEdInstaViewSrc = 'file:///D:/wikEd/instaview.js'; // InstaView AJAX preview

For finally testing the code on Wikipedia, every developer should create a code page in his own user space ending with .js (e.g. User:YourUsername/wikEd_dev.js). These pages can only be edited by the owner for security reasons.

Making wikEd cross-browser compatible

There is the new library IERange that provides DOM ranges for MS IE. This seems to work in general and has been added to wikEd. However, MSIE has no support for execCommand('inserthtml', code); and the workaround frameDocument.selection.createRange().pasteHTML(code); breaks the undo history!

wikEd API

See also: wikEd customization - custom_buttons

wikEd has the following hooks for custom function that are executed at certain events:

The usage is as follows:

 if (typeof(wikEd) == 'undefined') { wikEd = {}; }
 if (typeof(wikEd.config) == 'undefined') { wikEd.config = {}; }
 if (typeof(wikEd.config.setupHook ) == 'undefined') { wikEd.config.setupHook = []; }
 wikEd.config.setupHook.push(YourFunction);

Alternatively, before wikEd initializes, the following custom setting form is also available for convenience:

 var wikEdConfig = { 'setupHook': [YourFunction] };

To find out if the classic textarea or the wikEd edit frame is in place:

 if (wikEd.useWikEd == true)  {  } // edit frame in place
 if (wikEd.useWikEd == false) {  } // classic textarea in place

To find out it wikEd is turned off, indicated by a grey top logo wikEd disabled:

 if (wikEd.turnedOn == true)  {  } // wikEd turned on
 if (wikEd.turnedOn == false) {  } // wikEd turned off

To insert a string at the cursor position :

 wikEd.FrameExecCommand('inserthtml', string);

Access the plain text of the wikEd edit frame:

 var obj = {};
 wikEd.ParseDOM(obj, wikEd.frameBody);
 var plainText = obj.plain;
 var curserPosition = obj.plainFocus;

To test a wikEd variable (e.g. wikEd.useWikEd) without throwing an error if wikEd is not loaded:

 if (typeof wikEd != 'undefined') { if (wikEd.useWikEd == true) {  } }

Please use this discussion page if you have any questions.