WikiLink - The Mediawiki Interface

From Knot Atlas
Revision as of 04:57, 17 December 2006 by 213.42.21.77 (talk) (→‎License)
Jump to navigationJump to search

WikiLink is actually two separate things; firstly, a java class for interfacing with a mediawiki server, and secondly, a Mathematica package providing a wrapper around this. This page documents the Mathematica package, while the java class, and its addition functionality, will be documented elsewhere.

WikiLink is available as a standalone package, suitable for use with any Mediawiki installation, and is included in the KnotTheory` package.

morgan, john pierpont licata, riccardo - licata, riccardo: licata, riccardo licata, riccardo licata, riccardo licata, riccardo, hell - hell: hell hell hell hell, ackermann, max - ackermann, max: ackermann, max ackermann, max ackermann, max ackermann, max, qixia si - qixia si: qixia si qixia si qixia si qixia si, alex and emma - alex and emma: alex and emma alex and emma alex and emma alex and emma, capelle, jan van de- - capelle, jan van de-: capelle, jan van de- capelle, jan van de- capelle, jan van de- capelle, jan van de-, bikom - bikom: bikom bikom bikom bikom, paray-le-monial - paray-le-monial: paray-le-monial paray-le-monial paray-le-monial paray-le-monial, mitsuyoshi tosa - mitsuyoshi tosa: mitsuyoshi tosa mitsuyoshi tosa mitsuyoshi tosa mitsuyoshi tosa, four brothers - quattro fratelli - four brothers - quattro fratelli: four brothers - quattro fratelli four brothers - quattro fratelli four brothers - quattro fratelli four brothers - quattro fratelli, baumhauer, joseph - baumhauer, joseph: baumhauer, joseph baumhauer, joseph baumhauer, joseph baumhauer, joseph, bentley, john francis - bentley, john francis: bentley, john francis bentley, john francis bentley, john francis bentley, john francis, konarak - konarak: konarak konarak konarak konarak, beauvais - beauvais: beauvais beauvais beauvais beauvais, il viaggio di felicia - il viaggio di felicia: il viaggio di felicia il viaggio di felicia il viaggio di felicia il viaggio di felicia, fanum voltumnae - fanum voltumnae: fanum voltumnae fanum voltumnae fanum voltumnae fanum voltumnae, halle - halle: halle halle halle halle, divisionismo - divisionismo: divisionismo divisionismo divisionismo divisionismo, vivin, louis - vivin, louis: vivin, louis vivin, louis vivin, louis vivin, louis, thule springs - thule springs: thule springs thule springs thule springs thule springs, abercrombie, sir patrick - abercrombie, sir patrick: abercrombie, sir patrick abercrombie, sir patrick abercrombie, sir patrick abercrombie, sir patrick, tessenow heinrich - tessenow heinrich: tessenow heinrich tessenow heinrich tessenow heinrich tessenow heinrich, ebrach - ebrach: ebrach ebrach ebrach ebrach, piattabanda - piattabanda: piattabanda piattabanda piattabanda piattabanda, piles, roger de- - piles, roger de-: piles, roger de- piles, roger de- piles, roger de- piles, roger de-, charlotte gray - charlotte gray: charlotte gray charlotte gray charlotte gray charlotte gray, mills, robert - mills, robert: mills, robert mills, robert mills, robert mills, robert, belfagor - il fantasma del louvre - belfagor - il fantasma del louvre: belfagor - il fantasma del louvre belfagor - il fantasma del louvre belfagor - il fantasma del louvre belfagor - il fantasma del louvre, cenerentola a parigi - cenerentola a parigi: cenerentola a parigi cenerentola a parigi cenerentola a parigi cenerentola a parigi, la spirale della vendetta - la spirale della vendetta: la spirale della vendetta la spirale della vendetta la spirale della vendetta la spirale della vendetta, praetexta - praetexta: praetexta praetexta praetexta praetexta, fashion - fashion: fashion fashion fashion fashion, hilton, roger - hilton, roger: hilton, roger hilton, roger hilton, roger hilton, roger, lavedan, pierre - lavedan, pierre: lavedan, pierre lavedan, pierre lavedan, pierre lavedan, pierre, pontecagnano faiano - pontecagnano faiano: pontecagnano faiano pontecagnano faiano pontecagnano faiano pontecagnano faiano, susanna - susanna: susanna susanna susanna susanna, bambole russe - bambole russe: bambole russe bambole russe bambole russe bambole russe, commedia sexy - commedia sexy: commedia sexy commedia sexy commedia sexy commedia sexy, buke-zukuri - buke-zukuri: buke-zukuri buke-zukuri buke-zukuri buke-zukuri, costantino i (imperatore romano) - costantino i (imperatore romano): costantino i (imperatore romano) costantino i (imperatore romano) costantino i (imperatore romano) costantino i (imperatore romano), pawdawmu - pawdawmu: pawdawmu pawdawmu pawdawmu pawdawmu, gioco a due - gioco a due: gioco a due gioco a due gioco a due gioco a due, leptis magna - leptis magna: leptis magna leptis magna leptis magna leptis magna, killing zoe - killing zoe: killing zoe killing zoe killing zoe killing zoe, puy, jean - puy, jean: puy, jean puy, jean puy, jean puy, jean, jerry maguire - jerry maguire: jerry maguire jerry maguire jerry maguire jerry maguire, brouet, auguste - brouet, auguste: brouet, auguste brouet, auguste brouet, auguste brouet, auguste, pileta, la- - pileta, la-: pileta, la- pileta, la- pileta, la- pileta, la-, campanile - campanile: campanile campanile campanile campanile, arrieta, pedro de- - arrieta, pedro de-: arrieta, pedro de- arrieta, pedro de- arrieta, pedro de- arrieta, pedro de-, cambridge (u.s.a.) - cambridge (u.s.a.): cambridge (u.s.a.) cambridge (u.s.a.) cambridge (u.s.a.) cambridge (u.s.a.), arellano, juan de- - arellano, juan de-: arellano, juan de- arellano, juan de- arellano, juan de- arellano, juan de-, la cameriera - la cameriera: la cameriera la cameriera la cameriera la cameriera, honegger, david - honegger, david: honegger, david honegger, david honegger, david honegger, david, hals, frans - hals, frans: hals, frans hals, frans hals, frans hals, frans, black simphony - black simphony: black simphony black simphony black simphony black simphony, last night - last night: last night last night last night last night, spencer, stanley - spencer, stanley: spencer, stanley spencer, stanley spencer, stanley spencer, stanley, gertrud - gertrud: gertrud gertrud gertrud gertrud, tachi - tachi: tachi tachi tachi tachi, tisi, benvenuto - tisi, benvenuto: tisi, benvenuto tisi, benvenuto tisi, benvenuto tisi, benvenuto, novilara - novilara: novilara novilara novilara novilara, dragonfly - dragonfly: dragonfly dragonfly dragonfly dragonfly, ricostruire - ricostruire: ricostruire ricostruire ricostruire ricostruire, base (architettura) - base (architettura): base (architettura) base (architettura) base (architettura) base (architettura), muybridge, eadweard - muybridge, eadweard: muybridge, eadweard muybridge, eadweard muybridge, eadweard muybridge, eadweard, kahn, louis isadore - kahn, louis isadore: kahn, louis isadore kahn, louis isadore kahn, louis isadore kahn, louis isadore, looy, jacobus van- - looy, jacobus van-: looy, jacobus van- looy, jacobus van- looy, jacobus van- looy, jacobus van-, confessions of a teenage drama queen - confessions of a teenage drama queen: confessions of a teenage drama queen confessions of a teenage drama queen confessions of a teenage drama queen confessions of a teenage drama queen, liberty - liberty: liberty liberty liberty liberty, brinckmann, albert erich - brinckmann, albert erich: brinckmann, albert erich brinckmann, albert erich brinckmann, albert erich brinckmann, albert erich, carne tremula - carne tremula: carne tremula carne tremula carne tremula carne tremula, a good lawyer's wife - a good lawyer's wife: a good lawyer's wife a good lawyer's wife a good lawyer's wife a good lawyer's wife, bourgeois, victor - bourgeois, victor: bourgeois, victor bourgeois, victor bourgeois, victor bourgeois, victor, gods and generals - gods and generals: gods and generals gods and generals gods and generals gods and generals, fragile - fragile: fragile fragile fragile fragile, kitaj, ronald b. - kitaj, ronald b.: kitaj, ronald b. kitaj, ronald b. kitaj, ronald b. kitaj, ronald b., foster, sir norman - foster, sir norman: foster, sir norman foster, sir norman foster, sir norman foster, sir norman, vos, cornelis de- - vos, cornelis de-: vos, cornelis de- vos, cornelis de- vos, cornelis de- vos, cornelis de-, swatch - swatch: swatch swatch swatch swatch, venet, bernard - venet, bernard: venet, bernard venet, bernard venet, bernard venet, bernard, top - top: top top top top, mora - mora: mora mora mora mora, big fish - big fish: big fish big fish big fish big fish, bosch y gimpera, pedro - bosch y gimpera, pedro: bosch y gimpera, pedro bosch y gimpera, pedro bosch y gimpera, pedro bosch y gimpera, pedro, pailou - pailou: pailou pailou pailou pailou, nylon - nylon: nylon nylon nylon nylon, carlito's way - carlito's way: carlito's way carlito's way carlito's way carlito's way, loggiato - loggiato: loggiato loggiato loggiato loggiato, avedon, richard - avedon, richard: avedon, richard avedon, richard avedon, richard avedon, richard, orchard, william - orchard, william: orchard, william orchard, william orchard, william orchard, william, gremlins - gremlins: gremlins gremlins gremlins gremlins, accademismo - accademismo: accademismo accademismo accademismo accademismo, candela, felix - candela, felix: candela, felix candela, felix candela, felix candela, felix, azzolini, tito - azzolini, tito: azzolini, tito azzolini, tito azzolini, tito azzolini, tito, kiva - kiva: kiva kiva kiva kiva, robert de luzarches - robert de luzarches: robert de luzarches robert de luzarches robert de luzarches robert de luzarches, del perduto amore - del perduto amore: del perduto amore del perduto amore del perduto amore del perduto amore, shumman, kubo - shumman, kubo: shumman, kubo shumman, kubo shumman, kubo shumman, kubo, morgan, john pierpont - morgan, john pierpont: morgan, john pierpont morgan, john pierpont morgan, john pierpont morgan, john pierpont,

Download

If you already have KnotTheory` installed, there's no need to install anything. The functionality of WikiLink is available as soon as you open KnotTheory`.

Otherwise, download WikiLink.zip. Unzip this anywhere you like. This will create a subdirectory called WikiLink, containing (at least) these files:

Filename Description
mathematica/WikiLink.nb The Mathematica notebook containing wrapper function definitions.
mathematica/WikiLink.m The Mathematica package automatically generated from WikiLink.nb.
wikilink.jar The WikiLink java classes and source code.

jars/jdom.jar
jars/commons-httpclient-3.0-rc2.jar
jars/commons-codec-1.3.jar
jars/commons-lang-2.1.jar
jars/commons-logging.jar

Libraries (all available under either GPL or the Apache license) required by wikilink.jar

Importing the package in Mathematica

If you're not using KnotTheory`, first, you'll need to set some paths, so WikiLink` can find the java files it needs. You need to add the "mathematica/" subdirectory of the WikiLink distribution to the Mathematica $Path.

In[1]:= WikiLinkPath = "/path/to/WikiLink/mathematica/";
In[2]:= AppendTo[$Path, WikiLinkPath];
In[3]:= <<WikiLink`

If you've already loaded KnotTheory` (e.g., with the statement <<KnotTheory`), you can simply begin at this point.

We then try to connect to the wiki. Executing this line will prompt you for a username and password.

In[6]:= CreateWikiConnection[ "http://katlas.math.toronto.edu/w/index.php", InputString["Enter Your Username:"], InputString["Enter Your Password:"] ]

The function WikiUserName[] checks that we're logged in

In[4]:= ?WikiUserName
WikiUserName[] returns either the name of the user you are logged in as, your IP address if you're not logged in, or $Failed if something more complicated has happened!
In[5]:= WikiUserName[]
Out[5]= ScottManualRobot

Usage

WikiLink` provides functions for checking your login status, getting and setting pages, as well as transparently extending some of Mathematica's string manipulation functions to wiki pages.

In[6]:= ?WikiUserName
WikiUserName[] returns either the name of the user you are logged in as, your IP address if you're not logged in, or $Failed if something more complicated has happened!
In[7]:= ?WikiGetPageText
WikiGetPageText[pagename] returns the raw text of the specified page.
In[8]:= ?WikiSetPageText
WikiSetPageText[pagename, text] overwrites the contents of the specificied page with the given text. WikiSetPageText[pagename, text, summary] overwrites the contents of the specificied page with the given text and notes summary in the change log.
In[9]:= ?WikiSetPageTexts
WikiSetPageText[{{pagename1, text1},{pagename2,text2},...}] efficiently sets multiple pages, by first checking which texts are already up to date.
In[10]:= ?WikiUploadFile
WikiUploadFile[name, description] uploads the specified file to the wiki.

Thus for example after

In[11]:= WikiSetPageText["Sandbox", "A robotic edit, at 19:39, 31-August-2005."]
Out[11]= True

we get

In[12]:= WikiGetPageText["Sandbox"]
Out[12]= A robotic edit, at 19:39, 31-August-2005.

The function WikiSetPageTexts is most useful for batch uploads, as it does considerably more error checking, and filters out edits which won't change the page text. It takes as argument a list of {"title", "text"} pairs, and returns a list of those pairs which failed.

In[13]:= WikiSetPageTexts[{{"Sandbox", "A robotic edit, by --~~"<>"~~"}, {"Sandbox2", "The determinant of the knot [[3_1]] is 3."}}]
Out[13]= {}
In[14]:= WikiGetPageText["Sandbox2"]
Out[14]= The determinant of the knot [[3_1]] is 3.
String manipulation functions

WikiLink` provides functions WikiPageMatchQ, WikiPageFreeQ, WikiStringReplace and WikiStringCases. Each function works likes its usual Mathematica partner, StringMatchQ, StringFreeQ, StringReplace or StringCases. Instead of providing a string, or list of strings, as the first argument, you should give the name of a page, or a list of names.

You can use these to perform all sorts of editing tricks.

In[15]:= WikiPageMatchQ[{"Sandbox", "Sandbox2"}, "determinant"]
Out[15]= {False, False}
In[16]:= WikiPageFreeQ[{"Sandbox", "Sandbox2"}, "[["~~(DigitCharacter..)~~"_"~~(DigitCharacter..)~~"]]"]
Out[16]= {True, False}
In[17]:= WikiStringCases[{"Sandbox", "Sandbox2"}, "[["~~ShortestMatch[__]~~"]]"]
Out[17]= {{Sandbox, {[[User:ScottManualRobot|ScottManualRobot]]}}, {Sandbox2, {[[3_1]]}}}
In[18]:= WikiStringReplace[{"Sandbox", "Sandbox2"}, "robotic edit"->"robotic edit (using WikiLink`)]
Out[18]= $Failed
In[19]:= WikiGetPageTexts[{"Sandbox", "Sandbox2"}]
Out[19]= {{Sandbox, A robotic edit, by\ --[[User:ScottManualRobot|ScottManualRobot]] 14:54, 18 Feb 2006\ (EST)}, {Sandbox2, The determinant of the knot [[3_1]] is 3.}}

Troubleshooting

The instruction ShowJavaConsole[] will bring up a window in which some debugging information is displayed.

Compatibility

WikiLink has been tested against mediawiki 1.4.5beta3 and 1.4.7.

WikiLink has known issues on mediawiki 1.5.0. Retrieving multiple pages at once is broken. This appears to be a mediawiki bug, and will not be fixed. The same problem does not occur on mediawiki 1.5.8. --Scott 10:56, 27 Mar 2006 (EST)

I expect WikiGetPage text to continue working in mediawiki 1.5 and beyond, because it uses the stable interface Special:Export. Logging in and setting pages will quite likely break in the next version. If you've tried this, please let me know about your experiences. I'm hoping that soon (1.5?) Special:Import will become available, and I can switch to using this. --Scott 15:57, 31 Aug 2005 (EDT)

Todo

I'd love to create an Ant task which allows uploading a file to a wiki. We could then use this in build scripts for KnotTheory, etc. --Scott 04:07, 17 Sep 2005 (EDT)

See Also

All of the Mathematica notebooks in Category:Knot Atlas Maintenance Software rely on WikiLink, and so are good examples of how to use it.

You may also be interested in the Wikipedia page on mediawiki bots, and in particular the Python Wikipedia Robot Framework.