Wikipedia:Text editor support

Jump to: navigation, search

It is often convenient to edit Wikipedia articles using a full-fledged text editor, instead of the standard text area of a web browser. Text editors provide facilities that are very useful for writing articles (especially long articles), such as spell checking, search and replace, macros, and syntax highlighting. They also provide a quick and easy way of saving a local backup copy of an article, possibly for future offline editing.

This article contains pointers for adapting several external and in-browser text editors to editing Wikipedia articles.

How to open articles in your text editor

A "manual" way of editing in an external GUI text editor is to select the entire contents of the browser text area (as with Ctrl-A or ⌘A), copy and paste from the text area to a new external editor window, perform the editing, select the editor window contents, then copy and paste back to the browser text area.

For a given software combination, there may be more efficient methods available:

Mozilla and Mozilla Firefox

If you are using the Mozilla web browser, it is possible to configure an external editor for editing text areas, including the Wikipedia edit area. This then avoids the need to copy and paste the article text between browser and editor. Several solutions exist:

  • MozEx. The official package does not support editing UTF-8-encoded documents and does not install properly on Mozilla Firefox. However, the development version does not have these problems. A quick MozEx tutorial is available.
  • ViewSourceWith works with recent versions of Firefox.
  • Editus Externus. Similar to the others, but the editor blocks the browser, so it is not possible to check other articles while writing.
  • TextArea Sputnik, supports nonblocking editing and different encodings in an external editor. (You may see question marks in an edit textbox unrelated to the edits you are making (for example, the Unicode grapheme and other glyphs at the bottom), but your edits won't destroy the characters.)
  • It's All Text!, supports nonblocking editing and utf-8 encoding.

With all these solutions, once you are done editing, you need to save in your editor, then click into the browser's text area and it will be updated. You can then hit Preview. If you want to continue editing after the preview, hit Back in your browser, then work in your editor. Alternatively, you can hit Preview before you start editing for the first time, then work in your editor, save, preview, edit some more, save, preview etc., without the need for hitting Back in between.

Use It's All Text! to invoke an external editor (e.g., vim, gvim)

If you use Firefox 2 under Linux, and are used to vim (or a similar editor), there is a great tool to invoke an external editor called It's All Text, which is very easy to install and to use. It just take one click to download and install this addon in Firefox. You then need to close all Firefox windows and restart again to activate this addon.

Next, you need to specify the path to your editor. There are two ways to bring up the Preferences window: (0) Switch to edit mode by clicking the Edit tab of a wiki page, or use the shortcut Shift+Alt+e, with the "accesskey" being Shift+Alt (in some other systems, the "accesskey" may be the Alt key; see Keyboard shortcuts for more details), then (1) Right click in the textarea; a dropdown menu will appear; move the cursor to It's All Text for another dropdown menu, and select Preferences at the bottom of this menu; or (2) Right click at the little button "Edit" at the lower-right corner of the textarea window. The path to your editor can be put in the Editor box of the Preferences window.

To invoke vim, you need to use the graphical version of vim called gvim, and thus put the path /usr/bin/gvim in the Editor box of the Preferences window. Putting /usr/bin/vim will not work; see below on how to get vim to work.

Once the above is done, to edit a wiki page, switch to Edit mode (as mentioned above) to bring up the textarea, and click at the little Edit button at the lower-right corner of the textarea.

To maximize the gvim window, press Alt+F5 in the xfce desktop environment.

After editing, you can save (write) the current file in gvim by pressing :w, then toggle back to the textarea of the wiki page (by pressing Alt+Tab if you use xfce or other desktop environments); you would see the textarea background turned yellow briefly, meaning that the textarea had been just modified and saved. Actually, each time you save the edited file, it takes about 1 or 2 seconds for the textarea to turn yellow briefly, indicating the saved version of the wiki article had been loaded into the textarea. You would see this color effect if your gvim widow did not occupy the whole monitor screen, and a portion of the textarea could be seen along side with the gvim window while editing.

All vim macros previously developed for use in editing latex files, html files, etc. worked. (See below in case you need to use vim instead of gvim.)

To preview what you have just edited, just toggle back to the wiki window (by pressing Alt+Tab if you use xfce), then type Shift+Alt+p. If you want to continue to see what you have just edited with gvim and included in the textarea, you can go back to the edit textarea by pressing Alt+LeftArrow to get your Firefox to display the previous page.

The location of to the saved edited files with gvim is in directory

  ~/.mozilla/firefox/default*/itsalltext/
  

with the filenames having the syntax:

  IP_address.random_code.txt

e.g.

  en.wikipedia.org.23311k351x.txt

The files in this directory will be removed. So if you want to preserve a text file for later editing, you may want to change the filename and move the file to another directory.

Another tip: While editing with It's All Text with gvim, if you were previewing the previous saved version of the text in Wikipedia, to preview a newer version, you want to first save this newer version in gvim. Then toggle back to the Wikipedia window, press Alt+RightArrow to go back to the edit textarea of the wiki article, wait for 1 or 2 seconds for the textarea to turn yellow briefly indicating that the newer version of the article had been loaded to the textarea. Next, press Shift+Alt+p to preview this newer version. To save the edited wiki page, you can use the shortcut Shift+Alt+s.

Getting vim to work with It's All Text: Some macro may work under vim, but not under gvim for some reasons (e.g., the macro to format text paragraphs). Or you just want to use vim within an X terminal as you used to do, instead of using gvim. To invoke vim within an X terminal window, you can write a csh (C-shell) script (see below) to invoke an X terminal and to run the vim command within that X terminal. Assume that the filename of this script is wiki.edit.vim, and that you put the script in the directory /home_dir/bin/ so that the path of the script would be

  /home_dir/bin/wiki.edit.vim

Put the above path in the Preferences box (instead of /usr/bin/gvim) of It's All Text. It should work. Note that /home_dir/ is the complete path to your home directory from the root (/) directory; don't use ~/ (tilde) instead of /home_dir/; it won't work.

The listing of the script wiki.edit.vim is given below:

#! /bin/csh -f
# $Id$
# vql, Thu, 27 Sep 2007, 17:56:09 EDT
#
# To pop up an X terminal (xterm) and run vim command within this
# terminal window.
# This script is intended to be invoked by the Firefox addon It's
# All Text for editing wiki pages
#
# The arguments for xterm are the same as those used to open up
# X terminals in laptop io2.  See ~/manuals/laptop.io2.fc3.html, 
# Section on xfce.
# For gray background: (NOT NEEDED, since the X terminal would be
#   closed down after quitting the wiki file); the \ is for 
#   continuation to the next line:
#
#   -bg gray \
#
# For font size:
#   -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 \
#
# For the sidebar:
#   -sb 
#
# For the size of the window (80 columns, 39 lines, right justified)
#   -geometry 80x39+800 \
#
# For executing vim on the file being the first argument of the script
#   -e /usr/bin/vim $argv[1]
#
# Exit codes:
# 0 = no problem

/usr/bin/xterm \
   -sb \
   -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 \
   -geometry 80x39+800 \
   -e /usr/bin/vim $argv[1]

You can delete one or more xterm options used in the above script such as -sb, -fn, -geometry, etc., if you don't need them. For example, the option -bg was already deleted, as explained in the comment block of the script. Enjoy editing wiki pages!

External editor feature

Starting with MediaWiki Version 1.5, the software allows you to edit any resource using any external tool. See Help:External editors for details.

Text browsers

elinks

The text-only browser elinks also provides a function to edit textareas. The Key combination Ctrl-T calls an external editor, e.g. vim. This allows also to use syntax highlighting, edit functions, spelling corrections and saving local copies.

w3m

w3m opens an external editor for textareas by default.

Lynx

Lynx allows editing a textarea with an external editor typing Ctrl-X and e when the cursor is in the textarea; this only works if this option is enabled when the browser is compiled.

Some versions of lynx (such as 2.8.5rel.1) use Ctrl-E to call the external editor.

Command line tools

There are also command line tools that allow you to download articles, edit them using your favorite text editor, and upload the edited articles back into the Wikipedia (or into any MediaWiki server). This bypasses the need for a web browser. These are (at least):

  • mvs, a Perl program available from CPAN. There's more information at Mediawiki::Client
    Property "Meta:WWW" (as page type) with input value "Mediawiki::Client" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process.
    . Unfortunately, mvs uses the name of the local file as the title of the page for the wiki remote server. If you need title pages in UTF-8 for Russian, Japanese or Arabic for example, you won't be able to upload such files. It seems that Mediawiki::Client as well as Perl libraries are not enough advanced in the management of UTF-8 characters to be fully operational, even if your terminal and shell are correctly set for UTF-8. But see Debian bug reports.
  • mwiki is a program to retrieve and upload articles from/to wikipedia servers. It is also capable of editing (sub)sections of articles. It stores the pagename (and other information) inside the file and seems to work well with UTF-8.
  • Meta:pywikipedia is an extensive library and set of utilities for doing innumerable things with wikipedia. It can also do something as simple as editing wikipedia pages. It has some ways to avoid the wrong transmission of titles in UTF-8, for example it allows to incorporate the name of the title within the file itself (in a comment for example) and to use another command line tool. The local filename could then be written in simple ASCII. Here is an example of a file, named locally 'foo.wiki', using pagefromfile.py (from Meta:pywikipedia):
{{-start-}}<!--'''Демография'''-->
Демография, или наука о народонаселении, изучает численность, состав, размещение и движение населения. 
{{-stop-}}

{{-start-}}<!--'''人口学'''-->
人口学 はヒトの人口の科学的研究をいい、主としてその大きさ、構造 2そしてその成長発展を研究対象とする。
{{-stop-}}

{{-start-}}<!--'''Demography'''-->
Demography is the scientific study of human populations primarily with respect to their size, their structure and their development
{{-stop-}}

{{-start-}}<!--'''الديمغرافية'''-->
الديمغرافية: علم يتناول دراسة المجتمعات البشرية من حيث حجومها و بناها و تطورها و خصائصها العامة و لا سيما من النواحي الكمية.
{{-stop-}}

In the above example, the command line to upload the four pages in one submission (the 'start' and 'stop' markups drive successively the four different pages Демография, 人口学, Demography and الديمغرافية) is:

  python pagefromfile.py -file:foo.wiki

Wikipediafs

Users of POSIX-compliant operating systems like Linux or Mac OS X also can use the virtual filesystem Wikipedia filesystem based on Python and FUSE. It allows the user to treat articles of any Mediawiki-based implementation like real files.

This software (version 0.3) was not easy to install since it required the installation of several other software. If you are a Firefox and vim user, a much simpler solution would be to use It's All Text and gvim to edit wiki pages.

How to set up specific editors for Wikipedia editing

GNU Emacs

There are a couple of Emacs major modes available for editing Wikipedia articles:

  • wikipedia-mode.el is a simple major mode that mostly provides syntax highlighting for wikipedia markup.
  • wikipedia.el is a much more advanced major mode which provides WYSIWYG editing of wikipedia articles. Note, however, that it is developed using the current CVS version of GNU Emacs, and may not be compatible with older versions. It is also in the alpha stage of development, so use it at your own risk.

Since Wikipedia articles don't use line breaks, you may want to install screen-lines.el, which redefines movement commands to work in terms of screen lines as opposed to text lines, or install longlines.el, which implements "word wrap" functionality for Emacs (longlines.el is now part of GNU Emacs). Installation instructions are here.

Eclipse plug-in

The Wikipedia editor plugin plog4u.org is available for Eclipse (cross-platform). With an automatically updating outline of the article. It has many features which are very helpful for editing wikipedia. It also downloads articles directly from Wikipedia and has highlighting.

Vim

To make Vim (Amiga, Linux, Mac OS X, Windows, OpenVMS, OS/2, Unix) support the MediaWiki markup used on Wikipedia (basically syntax highlighting; see It's All Text and vim/gvim for how to set up vim/gvim to edit wiki pages), save Wikipedia.vim to your "syntax" directory. By default, this directory is "~/.vim/syntax" on a Unix system, and "C:\Program Files\Vim\vimfiles\syntax" on a Windows system. If any of the directories above don't exist you may create them (the Unix/Linux command is mkdir).

To autodetect files ending in ".wiki", add the following lines to ".vim/filetype.vim" or "vimfiles\filetype.vim" (or create the file if it doesn't exist):

augroup filetypedetect
au BufNewFile,BufRead *.wiki setf Wikipedia
augroup END

Alternatively, add the following line to the vimrc file (typically ~/.vimrc on Unix and C:\Program Files\Vim\_vimrc on Windows) (this doesn't work in Vim 7, use the above example):

au BufRead,BufNewFile *.wiki setfiletype Wikipedia

Alternatively, the command ":setf Wikipedia" will temporarily set the syntax for the current file.

The above mentioned Firefox extension Mozex creates a temporary file ending in ".txt" rather than ".wiki" so the above autodetection will not work in combination with that plugin. One solution is to have Mozex invoke vim with these arguments:

-c "setf Wikipedia"

Wikipedia articles often only have line-breaks at the end of each paragraph, a situation Vim doesn't handle gracefully by default. Save the following lines to "~/.vim/ftplugin/Wikipedia.vim" or "vimfiles\ftplugin\Wikipedia.vim" to make it easier (you may need to put "filetype plugin on" in your vimrc).

setlocal encoding=utf-8
setlocal textwidth=0
setlocal linebreak
setlocal matchpairs+=<:>
nnoremap <buffer> k gk
nnoremap <buffer> j gj
nnoremap <buffer> <Up> gk
nnoremap <buffer> <Down> gj
nnoremap <buffer> 0 g0
nnoremap <buffer> ^ g^
nnoremap <buffer> $ g$
inoremap <buffer> <Up> <C-O>gk
inoremap <buffer> <Down> <C-O>gj
vnoremap <buffer> k gk
vnoremap <buffer> j gj
vnoremap <buffer> <Up> gk
vnoremap <buffer> <Down> gj
vnoremap <buffer> 0 g0
vnoremap <buffer> ^ g^
vnoremap <buffer> $ g$

Please feel free to edit Wikipedia.vim and upload an improved copy, or to check on the vim-devel list if anyone has requested the upload of Wikipedia.vim, and if not, to request it. (As of 2006-09-06, it is not in Vim's "syntax/" directory.)

The above scripts are also posted in the vim.org script collection, where they are occasionally updated with newer versions taken from community contributions on this site. Feel free to remind mvc to upload a newer copy periodically if those become stale, since they were uploaded from his vim.org account.

jEdit

For jEdit (Java-supporting OSes) there is a plugin available at http://www.djini.de/software/mwjed/ . Apart from providing syntax highlighting for wikipedia markup, it can communicate directly with the Wikipedia website using the HttpClient component from the Jakarta Project.

Kate / KWrite

For Kate (for GNU/Linux KDE desktop), rules for syntax highlighting are provided by the XML file de:Media:Wikimedia.xml. It recognizes HTML tags and entities, wiki control characters, links, section titles, tables and <nowiki> sections.

To install this template, copy it to ~/.kde/share/apps/katepart/syntax/ for per user settings or $(PREFIX)/share/apps/katepart/syntax/ for global settings. There's also an import tool : Settings → Configure Kate → Highlighting → Download.

SubEthaEdit

A syntax highlighting mode is available for SubEthaEdit (Mac OS X) as well. After downloading the mode bundle, drop it in /Library/Application Support/SubEthaEdit/Modes/ (system-wide) or ~/Library/Application Support/SubEthaEdit/Modes/ (user-specific). You may need to create the final two directories by hand. The mode will be automatically selected for files with a .wiki or .wikipedia extension.

TextMate

A "MediaWiki" bundle is available in the TextMate (cross-platform) bundle subversion repository. To learn how to load this bundle, see the TextMate manual page about installing more bundles. The bundle for now (8 August 2006) only does syntax highlighting, but the ability to fetch and post articles is coming soon.

NoteTab

A Clip Library plugin for the NoteTab (Windows) text editor contains some functions to automate Wiki markup.

In-browser editors

wikEd

wikEd is a full-featured in-browser text editor that adds enhanced text processing functions to Wikipedia and other MediaWiki edit pages (currently only for Firefox and other Mozilla browsers).

Features include:

  • Powerful search and replace (including Regular expressions)
  • Wikicode syntax highlighting
  • Fullscreen editing mode
  • Edit preview and show changes on the same page without reloading
  • MS-Word and web page import (including tables)
  • Single-click fixing of common mistakes

wikEd can either be installed by pasting a small code snippet to your monobook.js page or locally as a Greasemonkey user script. For detailed installation instructions see the wikEd homepage.

Dealing with special characters

The English Wikipedia (and most others) are now encoded using the UTF-8 character set, which allows the use of many foreign language characters and special symbols. Such characters may appear even in articles where you wouldn't expect them due to the use of interwiki links to foreign-language versions of the article. Therefore, it's very important to use an editor that does not mangle these characters or replace them with question marks. Check your editor's documentation to make sure that it supports Unicode or UTF-8, and enable it if needed. You don't necessarily need a special editor; recent versions of Notepad and Microsoft Word support Unicode, for example. An extensive list of Unicode-supporting editors is available for Windows and other operating systems (see also: Comparison_of_text_editors).

When making an edit to an article with special characters using a new editor, it's a good idea to use the "Show changes" button (next to "Show preview") to see exactly what changes your edit will make - if areas with special characters that you didn't intend to modify are highlighted as red, that means they will be corrupted, even though both versions may look the same to you because you don't have foreign fonts installed.

BabelPad is a free editor for Windows with special support for dealing with Unicode, and is ideal if you need to determine which of several similar-looking characters an article is using, or deal with hard-to-edit Unicode control codes (like for multidirectional text).

See also

de:Wikipedia:Texteditor-Unterstützung


Linked-in.jpg