Sponsored Content
Full Discussion: Using Mediawiki API fails
Top Forums Web Development Using Mediawiki API fails Post 302867377 by bakunin on Thursday 24th of October 2013 06:08:22 AM
Old 10-24-2013
Using Mediawiki API fails

I am trying to create an automated documentation feature for our servers by using a Mediawiki and its API and feeding scripts on each server, but failed so far. The idea is to collect several vital data about a server by a script, create a wiki page and feed this into a central Mediawiki instance using wget as a means of transfer.

I set up a test-Wiki using Mediawiki 1.21.2 using a simple XAMPP stack on SLES11 (i intend to work on the software integration part later) and set up a user account with all rights (bureaucrat, administrator) to avoid any authentication issues for the test.

I finally wrote the following script on a test server to try creation of a wiki page:

Code:
#! /bin/ksh93

typeset WGET=$(which wget)
typeset chWikiInst="my_wiki"
typeset chWikiURL="http://<wikiserver>/wiki/api.php"
typeset fTgt=/tmp/wikitest
typeset fOut="$fTgt/outfile"
typeset chUser="wikiroot"
typeset chPwd="<password>"
typeset chToken=""
typeset chEditToken=""

rm outfile*
rm wikitest.login
rm wikitest.session*

# ----------------------- login --------------------
$WGET --post-data "action=login&lgname=${chUser}&lgpassword=${chPwd}&format=xml" \
      --save-cookies="$fTgt/wikitest.login" \
      --output-document="$fOut" \
      --keep-session-cookies \
      "$chWikiURL"

                                                       # extract info
chToken="$(sed 's/.*\ token="\([^"]*\)".*/\1/' "$fOut")"

$WGET --post-data "action=login&lgname=${chUser}&lgpassword=${chPwd}&lgtoken=${chToken}&format=xml" \
      --load-cookies="$fTgt/wikitest.login" \
      --save-cookies="$fTgt/wikitest.session" \
      --output-document="$fOut".1 \
      "$chWikiURL"

# ----------------------- get edit token -----------
wget --post-data "action=query&prop=info|revisions&intoken=edit&titles=Mypage&format=xml" \
     --load-cookies="$fTgt/wikitest.session" \
      --save-cookies="$fTgt/wikitest.sessionedit" \
      --output-document="$fOut".2 \
      "$chWikiURL"

chEditToken="$(sed -n 's/.*\ edittoken="\([^"]*\)".*/\1/p' "${fOut}.2")"

print - "------------------------------------------------"
print - "chEditToken=${chEditToken}"
print - "------------------------------------------------"


# ----------------------- edit page ----------------
wget --post-data "action=edit&title=Mypage&summary=wikitest%20summary&text=wikitest%20Text&token=${chEditToken}" \
     --load-cookies="$fTgt/wikitest.sessionedit" \
      --save-cookies="$fTgt/wikitest.sessionedit" \
      --output-document="$fOut".3 \
      "$chWikiURL"


# ----------------------- logout -------------------
$WGET --post-data "action=logout&format=xml" \
      --load-cookies="$fTgt/wikitest.session" \
      --save-cookies="$fTgt/wikitest.sessionend" \
      --output-document="$fOut".4 \
      "$chWikiURL"

exit 0

What worked was the login- the query- and the logout-part. I get the correct answers back, the cookies/tokens are set correctly and all works correctly. Somehow, though, when i try to use the edit-token to create the new page (it doesn't exist yet) i get back the API-documentation, which indicates an error.

I checked if the API is allowed to be used at all in LocalSettings.php and include/DefaultSettings.php, but everything seems to be as it should be.

wget and OS version is as follows:

Code:
# wget --version
GNU Wget 1.14 built on aix5.1.0.0.

Locale: /opt/freeware/share/locale 
Compile: xlc_r -D_LARGE_FILES -DHAVE_CONFIG_H 
    -DSYSTEM_WGETRC="/opt/freeware/etc/wgetrc" 
    -DLOCALEDIR="/opt/freeware/share/locale" -I. -I../lib -I../lib 
    -D_THREAD_SAFE -I/opt/freeware/include -I/opt/freeware/include 
    -qmaxmem=16384 -DSYSV -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX51 
    -D_ALL_SOURCE -DFUNCPROTO=15 -O -I/opt/freeware/include 
Link: xlc_r -D_LARGE_FILES -qmaxmem=16384 -DSYSV -D_AIX -D_AIX32 -D_AIX41 
    -D_AIX43 -D_AIX51 -D_ALL_SOURCE -DFUNCPROTO=15 -O 
    -I/opt/freeware/include -L/opt/freeware/lib 
    -Wl,-bmaxdata:0x80000000 -L/opt/freeware/lib 
    /opt/freeware/lib/libiconv.a /opt/freeware/lib/libintl.a 
    /opt/freeware/lib/libiconv.a /opt/freeware/lib/libssl.so 
    /opt/freeware/lib/libcrypto.so /opt/freeware/lib/libz.a -ldl -lz 
    -lz -lidn -lpcre ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a 
    -liconv 

# oslevel -s
5300-10-01-0921

# uname -a
AIX myTestHost 3 5 <####>

Can someone explain to me what i am doing wrong?

bakunin
 

5 More Discussions You Might Find Interesting

1. Solaris

how to install mediawiki

hi everybody.. i download and untar mediawiki ... i dont know how to install mediawiki.. there is no configure ... plz help me how to do it step bu step ... (1 Reply)
Discussion started by: coolboys
1 Replies

2. Red Hat

mediawiki page won't load - fedora 16, MediaWiki version 1.18.2

I created a mediawiki page and it was completely working and I had multiple pages within it. When I edited the $wgLogo = " "; to something I wanted (I put the link to the picture within " ") I had to edit the logo on the top right but now I can't even load any of my pages, I may have touched... (1 Reply)
Discussion started by: kelth
1 Replies

3. UNIX and Linux Applications

mediawiki page won't load - fedora 16, MediaWiki version 1.18.2

I created a mediawiki page and it was completely working and I had multiple pages within it. When I edited the $wgLogo = " "; to something I wanted (I put the link to the picture within " ") I had to edit the logo on the top right but now I can't even load any of my pages, I may have... (10 Replies)
Discussion started by: kelth
10 Replies

4. Shell Programming and Scripting

Need to run an API from a script and extract fields from output of API

Hi, I need to call an API (GetUsageDetails)from inside a shell script which takes an input argument acct_nbr. The output of API will be like : <usageAccum accumId="450" accumCaptn="PM_125" inclUnits="1410.00" inclUnitsUsed="744.00" shared="true" pooled="false" prorated="false"... (1 Reply)
Discussion started by: rkrish
1 Replies

5. Web Development

Face-api.js — JavaScript API for Face Recognition in the Browser with tensorflow.js

Ref: https://itnext.io/face-api-js-javascript-api-for-face-recognition-in-the-browser-with-tensorflow-js-bcc2a6c4cf07 (0 Replies)
Discussion started by: Neo
0 Replies
All times are GMT -4. The time now is 07:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy