Extension:ApiMagicWord

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
ApiMagicWord

Release status: experimental

Implementation Parser function
Description ApiMagicWord extension provide a wiki text access to enabled Application Programming Interfaces (API) of MediaWiki Web sites.
Author(s) Eric Larchertalk
Latest version 0.1b
License GNU General Public License
Download No link
Parameters

$wgApiMagicWordUseNoPrefixHash

Translate the ApiMagicWord extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

What can this extension do?[edit | edit source]

With a simple magic word #api, ApiMagicWord extension enabled wiki text access to the (enabled :-) Application Programming Interfaces (API) of MediaWiki Web sites.

By this way, it permits to interact, to get and post data from within each wiki page, with all the contents of those sites .

From within each wiki page with all the contents of the local site included, if its API is enabled.

Usage[edit | edit source]

Here, you can find some examples of the syntax call to http://fr.wikipedia.org/w/api.php (the API of the french wikipedia) from another Mediawiki wiki:

Note 1 : That suppose that, in the local wiki, wfrapi was declared as an interwikilink for http://fr.wikipedia.org/w/api.php?action=$1.

Note 2 : ApiMagicWord suppose too a simple relation between interwikilink to index.php and interwikilink to api.php : if wfrapi is an interwikilink for http://fr.wikipedia.org/w/api.php?action=$1, wfr is (one of) the interwikilink for http://fr.wikipedia.org/w/index.php?title=$1.

  • {{#api:wfrapi|action=query|list=recentchanges}}
  • {{#api:wfrapi|action=query|list=recentchanges|rcprop=user{{!}}comment{{!}}flags{{!}}timestamp{{!}}title{{!}}ids{{!}}sizes}}
  • {{#api:wfrapi|action=login|lgname=Eric Larcher|lgpassword=...}}
  • {{#api:wfrapi|action=logout}}

Remark :For meaning of {{!}}, see Help:Magic words#Other.

To format the results[edit | edit source]

Templates can be used to filter and/or format items send to the current wiki page :

Remark : of course, for a correct rendering, the templates have to bee create before their usage.

  • {{#api:wfrapi|action=login|lgname=Eric Larcher|lgpassword=...|template=Api/login}}
  • {{#api:wfrapi|action=edit|title=Utilisateur:Eric Larcher/callintertrans|text=encore un nouvel essai api|summary=test api||notbot/template=Api/edit}}
  • {{#api:wfrapi|action=query|list=recentchanges|template=Api/query/recentchanges}}
  • {{#api:wfrapi|action=query|list=recentchanges|template=Api/query/recentchanges2|rcprop=user{{!}}comment{{!}}flags{{!}}timestamp{{!}}title{{!}}ids{{!}}sizes}}
  • {{#api:|action=logout|template=Api/Void}}

Tips : As in the line above, it's possible to use an empty template to avoid all trace in the rendered wiki text.

Others ways, are :

  • when the result is not a list of more than one list of results :
    {{Api/query/anothertemplateapproach|{{subst:#api:wfrapi|action=query|list=recentchanges|rclimit=1}}}}.
  • (since version 0.1c) when the result is a list of one or more list of results :
    {{#arraymap:{{#api:wfrapi|action=query|list=recentchanges|rclimit=10|delimiter=&&}}|&&|x|{{Api/query/recentchanges|x}}|</tr><tr>}}, if for example we want to build a table.
    Remark : Of course, for that, #arraymap should be active. See Extension:Semantic Forms.

Access to the Api of a local Mediawiki wiki[edit | edit source]

For access to the Api of the local Mediawiki wiki, no need to specify an interwikilink :

  • {{#api:|action=query|list=recentchanges|template=Api/query/recentchanges}}
  • {{#api:|action=logout|template=Void}}
  • {{#api:|action=edit|title=Utilisateur:Eric Larcher/callintertrans|text=je recommence encore encore un nouvel essai api|notbot|summary=test api}}

ToDo[edit | edit source]

A lot of work !! Every help is welcome !

Download instructions[edit | edit source]

Please cut and paste the codes found in subpages :

 Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation[edit | edit source]

To install this extension, add the following to LocalSettings.php:

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/ApiMagicWord/ApiMagicWord.php");

Configuration parameters[edit | edit source]

If $wgApiMagicWordUseNoPrefixHash is set to true, then magic word api is without the preceding hash symbol, and more like a built-in function.

User rights[edit | edit source]

Have to be implemented.

Code[edit | edit source]

See :

See also[edit | edit source]