Difference between revisions of "Mediawiki.el"

From WikEmacs
Jump to navigation Jump to search
(→‎Setup: MELPA has the latest package)
 
(46 intermediate revisions by 17 users not shown)
Line 1: Line 1:
'''Mediawiki.el''' is a package to help add content to any mediawiki
+
{{Package
site. You can use this library to browse and submit content to
+
|name=mediawiki.el
''WikEmacs''. It comes with a [[Major Mode]] to support editing
+
|description=Mediawiki interface and markup mode
Mediawiki markup.
+
|author= Jerry et al
 +
|maintainer=Mark A. Hershberger
 +
|source=https://code.launchpad.net/~hexmode/mediawiki-el/trunk
 +
|in_emacs=no
 +
|Development status=active
 +
|website=https://code.launchpad.net/~hexmode/mediawiki-el
 +
}}
  
 
'''Mediawiki.el''' is a package to help add content to any mediawiki
 
'''Mediawiki.el''' is a package to help add content to any mediawiki
site. You can use this library to browse and submit content to
+
site including ''WikEmacs''. It comes with a [[Major Mode]] to support editing
''WikEmacs''. It comes with a [[Major Mode]] to support editing
 
 
Mediawiki markup.
 
Mediawiki markup.
  
= Basic setup =
+
==Setup==
  
 
Install '''mediawiki.el''' from [[el-get]] or [[ELPA]].
 
Install '''mediawiki.el''' from [[el-get]] or [[ELPA]].
  
= Customization =
+
If you are using emacs-24, you could do the following: Edit your .emacs file like this:
 +
<syntaxhighlight lang="lisp">
 +
(require 'package)
 +
(package-initialize)
 +
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
 +
</syntaxhighlight>
 +
 
 +
Then, either use the menu ''Options->Manage Emacs Packages'' or type ''M-X package-list-packages''
 +
* search ''mediawiki'' and click on it
 +
... almost done.
 +
 
 +
 
 +
=== Site requirements ===
 +
 
 +
The MediaWiki site that you wish to edit must have its API enabled:
 +
 
 +
<pre>
 +
$wgEnableAPI=true;
 +
</pre>
 +
 
 +
==Customization==
  
 
; {{Command|load-library RET mediawiki RET}}
 
; {{Command|load-library RET mediawiki RET}}
: Load the library. This can be skipped if you have have
+
: Load the library  
Snippet{{(require 'mediawiki)}} to your {{InitFile}}.
 
  
 
; {{CustomizeVariable|mediawiki-site-alist}}
 
; {{CustomizeVariable|mediawiki-site-alist}}
Line 26: Line 50:
 
:: '''Password''': ''s!cr!t''
 
:: '''Password''': ''s!cr!t''
 
:: '''First Page''': ''Main Page''
 
:: '''First Page''': ''Main Page''
: You can provide "Username" and "Password" in your [[.authinfo]] file. home directory.
+
: You can provide "Username" and "Password" in your [[.authinfo]] file, located in you home directory. For a MediaWiki, .authinfo lines have the form:
 +
<syntaxhighlight lang="text">
 +
machine https://mymediawiki.com/wiki/ login myUsername password myPassword
 +
</syntaxhighlight>
 +
 
 +
Alternatively you can add this snippet of Emacs Lisp code to your
 +
[[.emacs]]:
 +
 
 +
<syntaxhighlight lang="lisp">
 +
(require 'mediawiki)
  
= Make submissions =
+
(setq mediawiki-site-alist '(("Wikipedia" "http://en.wikipedia.org/w/ "" "" "Main Page") ; put your user name and password if not using .authinfo
 +
                            ("WikEmacs" "http://wikemacs.org/" "" "" "Main Page")))
 +
 
 +
;; Emacs users care more for WikEmacs than Wikipedia :-).
 +
;; In any case, do not forget the slash at the end of the URL.
 +
(setq mediawiki-site-default "WikEmacs")
 +
</syntaxhighlight>
 +
 
 +
You can naturally add more MediaWiki sites to the
 +
'''mediawiki-site-alist''' variable.
 +
 
 +
==Usage==
 
; {{Command|mediawiki-site}}
 
; {{Command|mediawiki-site}}
: Choose a site for the current session.
+
: Choose a site (say "WikEmacs") for the current session.  
  
; {{Command|mediawiki-open RET WikEmacs RET}}
+
; {{CommandKeys|C-c C-o|mediawiki-open}}
 
: Open a page. To edit the main page, type "Main Page". Make your edits.
 
: Open a page. To edit the main page, type "Main Page". Make your edits.
  
Line 38: Line 82:
 
: Submit your modifications.
 
: Submit your modifications.
  
= Helpful Keybindings =
+
; {{CommandKeys|C-c C-c|mediawiki-save-and-bury}}
 +
: Submit modifications and bury the buffer.
  
; {{CommandKeys|C-c|mediawiki-save-and-bury}}
+
== Helpful Keybindings==
: Submit modifications and bury the buffer.
 
  
 
; {{CommandKeys|C-return|mediawiki-open-page-at-point}}
 
; {{CommandKeys|C-return|mediawiki-open-page-at-point}}
: Submit modifications and bury the buffer.
+
: Follow or browse to a WikiLink.
  
 
; {{CommandKeys|M-g|mediawiki-reload}}
 
; {{CommandKeys|M-g|mediawiki-reload}}
 
: Reload a page
 
: Reload a page
  
= Project Page =
+
; {{CommandKeys|Tab|mediawiki-mediawiki-goto-next-link}}
* [[https://launchpad.net/mediawiki-el Mediawiki.el page on Launchpad]]
+
: Get to next link
 +
 
 +
==Customizations==
 +
=== Word Wrap ===
 +
 
 +
Mediawiki sites are generally [[Emacs_Terminology#Fill |unfilled]]: do not add hard line breaks within a paragraph. There are various ways to wrap lines [[Emacs_Terminology#Screen Lines |visually]] while you edit. For example in Emacs 24 you may want to enable [[Visual Line]] mode with a [[mode hook]]:
 +
 
 +
<syntaxhighlight lang="lisp">
 +
(setq mediawiki-mode-hook (lambda ()
 +
                            (visual-line-mode 1)))
 +
</syntaxhighlight>
 +
 
 +
=== Edit or Create a page in a web browser ===
 +
 
 +
Right now '''Mediawiki.el''' fails silently whenever the site asks for number challenge
 +
(spam protection). The following snippet allows you to edit/create a
 +
page in a web browser
  
[[Category:Wikemacs]]
+
<syntaxhighlight lang="lisp">
[[Category:Markup Modes]]
+
(defun yyr-mediawiki-browser-edit/create-page (page &optional site)
 +
  "Edit a page in browser, asks for page name (sitename also if needed)"
 +
  (interactive "sPage name (words): ")
 +
  (let* ((site (mediawiki-prompt-for-site))
 +
        (url (mediawiki-site-extract site 1))
 +
        (index "index.php?title=")
 +
        (et "&action=edit"))
 +
    (funcall 'browse-url
 +
            (message "%s%s%s%s"
 +
                      url index (mediawiki-translate-pagename page) et))))
 +
</syntaxhighlight>
  
= Make submissions =
+
Call {{Function| yyr-mediawiki-browser-edit/create-page}}
; {{Command|mediawiki-site}}
 
: Choose a site for the current session.
 
  
; {{CommandKeys|mediawiki-open}}
+
=== Key binding to open current editing file in web browser ===
: Open a page. To edit the main page, type "Main Page". Make your edits.
 
  
; {{CommandKeys|C-x C-s|mediawiki-save}}
+
Bind {{Function|mediawiki-browse}} to some key chord. The following
: Submit your modifications.
+
uses {{Keys|C-c o}}
  
= Helpful Keybindings =
+
<syntaxhighlight lang="lisp">
  
; CommandKeys{{C-c |mediawiki-save-and-bury}}
+
(define-key mediawiki-mode-map (kbd "C-c o") 'mediawiki-browse)
: Submit modifications and bury the buffer.
 
  
; CommandKeys{{C-return|mediawiki-open-page-at-point}}
+
</syntaxhighlight>
: Submit modifications and bury the buffer.
 
  
; CommandKeys{{M-g|mediawiki-reload}}
+
==Known Bugs==
: Reload a page
+
* Version 2.2.2 works fine on GNU Emacs 24.0.94.1 (i386-mingw-nt5.1.2600) when there is no challenge (e.g. arithmetic problem). But when external links are added, so there is a challenge, mediawiki doesn't alert the user or show the arithmetic problem. The only evidence of failure is that the page is never updated.
  
= Project Page =
+
==External Links==
* [[https://launchpad.net/mediawiki-el Mediawiki.el page on Launchpad]]
+
*[http://www.emacswiki.org/emacs/MediaWikiMode EmacsWiki:MediaWikiMode]
 +
*[https://launchpad.net/mediawiki-el Project Page]
  
[[Category:Wikemacs Contributor]]
+
[[Category:Third Party Package]]
[[Category:Markup Modes]]
+
[[Category:Markup languages]]

Latest revision as of 15:14, 8 April 2015

mediawiki.el
Description Mediawiki interface and markup mode
Author Jerry et al
Maintainer Mark A. Hershberger
Source https://code.launchpad.net/~hexmode/mediawiki-el/trunk
Part of Emacs no

Mediawiki.el is a package to help add content to any mediawiki site including WikEmacs. It comes with a Major Mode to support editing Mediawiki markup.

Setup

Install mediawiki.el from el-get or ELPA.

If you are using emacs-24, you could do the following: Edit your .emacs file like this:

(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)

Then, either use the menu Options->Manage Emacs Packages or type M-X package-list-packages

  • search mediawiki and click on it

... almost done.


Site requirements

The MediaWiki site that you wish to edit must have its API enabled:

$wgEnableAPI=true;

Customization

M-x load-library RET mediawiki RET
Load the library
M-x customize-variable RET mediawiki-site-alist
Configure as follows and save your settings
Site Name: WikEmacs
URL: http://wikemacs.org/w/
Username: InCognito
Password: s!cr!t
First Page: Main Page
You can provide "Username" and "Password" in your .authinfo file, located in you home directory. For a MediaWiki, .authinfo lines have the form:
machine https://mymediawiki.com/wiki/ login myUsername password myPassword

Alternatively you can add this snippet of Emacs Lisp code to your .emacs:

(require 'mediawiki)

(setq mediawiki-site-alist '(("Wikipedia" "http://en.wikipedia.org/w/ "" "" "Main Page") ; put your user name and password if not using .authinfo
                             ("WikEmacs" "http://wikemacs.org/" "" "" "Main Page")))

;; Emacs users care more for WikEmacs than Wikipedia :-). 
;; In any case, do not forget the slash at the end of the URL.
(setq mediawiki-site-default "WikEmacs")

You can naturally add more MediaWiki sites to the mediawiki-site-alist variable.

Usage

M-x mediawiki-site
Choose a site (say "WikEmacs") for the current session.
[C-c C-o] (or M-x mediawiki-open)
Open a page. To edit the main page, type "Main Page". Make your edits.
[C-x C-s] (or M-x mediawiki-save)
Submit your modifications.
[C-c C-c] (or M-x mediawiki-save-and-bury)
Submit modifications and bury the buffer.

Helpful Keybindings

[C-return] (or M-x mediawiki-open-page-at-point)
Follow or browse to a WikiLink.
[M-g] (or M-x mediawiki-reload)
Reload a page
[Tab] (or M-x mediawiki-mediawiki-goto-next-link)
Get to next link

Customizations

Word Wrap

Mediawiki sites are generally unfilled: do not add hard line breaks within a paragraph. There are various ways to wrap lines visually while you edit. For example in Emacs 24 you may want to enable Visual Line mode with a mode hook:

(setq mediawiki-mode-hook (lambda ()
                            (visual-line-mode 1)))

Edit or Create a page in a web browser

Right now Mediawiki.el fails silently whenever the site asks for number challenge (spam protection). The following snippet allows you to edit/create a page in a web browser

(defun yyr-mediawiki-browser-edit/create-page (page &optional site)
  "Edit a page in browser, asks for page name (sitename also if needed)"
  (interactive "sPage name (words): ")
  (let* ((site (mediawiki-prompt-for-site))
         (url (mediawiki-site-extract site 1))
         (index "index.php?title=")
         (et "&action=edit"))
    (funcall 'browse-url
             (message "%s%s%s%s"
                      url index (mediawiki-translate-pagename page) et))))

Call yyr-mediawiki-browser-edit/create-page

Key binding to open current editing file in web browser

Bind mediawiki-browse to some key chord. The following uses [C-c o]

(define-key mediawiki-mode-map (kbd "C-c o") 'mediawiki-browse)

Known Bugs

  • Version 2.2.2 works fine on GNU Emacs 24.0.94.1 (i386-mingw-nt5.1.2600) when there is no challenge (e.g. arithmetic problem). But when external links are added, so there is a challenge, mediawiki doesn't alert the user or show the arithmetic problem. The only evidence of failure is that the page is never updated.

External Links