User:Alex Smotrov/ExtEdit

ExtEdit.vbs is a WSH script that greatly simplifies editing Wikipedia pages with external editor.

It's a helper application as described on meta:Help:External editors.

How it works
Next to edit this page link you have a new → link.

You click on it and your browser calls ExtEdit, which gets article code from server, puts it into a file on your disk and opens it in your editor.

While in editor you press a key to call ExtEdit, which submits your text to the server as a preview in your browser.

You launch as many previews as needed, when you're finally satisfied you simply press «Save».

Why use it

 * to edit with comfort — in a big editor window with some syntax highlighting
 * for some advanced text operations — e.g. a lot of search and replaces
 * for offline editing; of course, either the page is rarely edited or you put inuse first
 * for creating new articles

Installation
Download ExtEdit.vbs:
 * directly from my site: ExtEdit.vbs
 * or go to this page, copy the code from textarea and create a local file ExtEdit.vbs yourself.


 * If you have antivirus software, it will give you a warning when you download and/or execute the script, since all WSH scripts are potentially dangerous. Simply instruct your antivirus to «always allow this script». You're welcome to look at the script code to make sure it does only what it's supposed to do.

Associate .wiki extension with your external editor software.

Configure your browser to call ExtEdit.vbs for application/x-external-editor :
 * FireFox: see Manual:External editors
 * Internet Explorer: there is probably a way to do it properly in IE by modifying registry … For now simply run ExtEdit.vbs, after your permission it will asscociate itself with .php files; it's not a proper way but it works.
 * Opera: click the link below, in «Download file» dialog click «Change», then select «Open with other application», click «Choose» and point to <tt>ExtEdit.vbs</tt>. Later you can change this in <tt>Preferences → Advanced → Downloads</tt>

Now click on [/w/index.php?title=Wikipedia:Sandbox&action=edit&externaledit=true Wikipedia:Sandbox&externaledit=true] and the code should open in your external editor.

Add external edit link to all pages: add to your monobook.js: //add ExtEdit link addOnloadHook(function{  var editTab = document.getElementById('ca-edit');   if (!editTab) return;   addPortletLink('p-cactions', editTab.firstChild.href + '&externaledit=true', '→', 'ca-exted', 'Edit with External Editor ',, editTab.nextSibling); })

Set up your external editor to call <tt>ExtEdit.vbs</tt> as an external utility for .wiki files.

Details
When the script is called from the browser, it:
 * recognizes the <tt>.php</tt> extension of input file
 * analyses the control file index.php
 * requests the page wiki code from MediaWiki server
 * saves it to local disk as <tt>.wiki</tt> file
 * (if the same <tt>.wiki</tt> file already exists, it's moved into <tt>.\backup</tt> subfolder)
 * creates additional <tt>.wiki.info</tt> file with the page address and LastModified date
 * runs <tt>.wiki</tt> file (which should open it in your associated editor)

When the script is called from your editor, it:
 * recognizes <tt>.wiki</tt> extension
 * reads <tt>.wiki.info</tt> file
 * generates a submit form
 * sumbits the form to MediaWiki server in your browser

If <tt>.wiki.info</tt> does not exists the script assumes the text to be a new article and it's address is extracted from the 1st line of your <tt>.wiki</tt> file in html comments, for example:

Edit conflicts
The script saves <tt>wpEdittime</tt> (Last Modified Date) of the article into <tt>.wiki.info</tt> file and then uses it in the preview submit form. So if somebody edited the same article by the time you hit «Save» button, MediaWiki server should warn you about edit conflict.

Preview
The script has two different methods for generating a preview:

use Internet Explorer object, then reuse it for next previews. This method makes subsequent previews much faster.
 * <tt>useIEpreview = true</tt> (by default):

create temporary <tt>.htm</tt> file, then launch it in your default browser.
 * <tt>useIEpreview = false</tt>:

Parameters
You can find some other parameters in the beginning of <tt>ExtEdit</tt> code.

External Editor
Your external editor should support UTF-8.

Other possible features:
 * wiki syntax highlighting
 * easy way to insert some special characters and wiki markup

Right now I'm using free editor Notepad++. After some setup it becomes more or less adequate:
 * userDefineLang.xml — syntax highlight file, put it next to <tt>notepad++.exe</tt> (not perfect but I doubt it can be improved much). [Note: Only works with a while background style, such as the Default Notepad++ style]
 * MediaWiki.api — an example of «quick inserts» list which is called by Ctrl-Enter, put it into <tt>.\plugins\APIs</tt>
 * Go to menu Run → Run, insert <tt>your_path\ExtEdit.vbs $(FULL_CURRENT_PATH)</tt>, click Save, choose a hot key (for example F12), press Ok.

To enter often used special characters you can also edit you keyboard layout (you will be able to use it in your browser too!) with Microsoft Keyboard Layout Creator (free download afer Windows Validation).

Comments about some other text editors:
 * PSPad — a very good editor, some powerful features, unfortunately user defined syntax highlighting is absolutely not compatible with wiki syntax
 * Programmer's Notepad — uses Scintilla component just like Notepad++, good support of user-defined syntax highlighting is promised some time in future.
 * Maybe some commercial editors would work, like EditPlus, UltraEdit and Multi-Edit
 * see Text_editor_support