< Development‎ | Tutorials
Revision as of 20:07, 10 July 2011 by Hormiere (Talk | contribs) (Created page with "= How to edit a wiki with Libmediawiki = Libmediawiki allows to edit a wiki easily. To reach its goal it uses the PHP API of Mediawiki. In this paper I will present how to edit...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to edit a wiki with Libmediawiki

Libmediawiki allows to edit a wiki easily. To reach its goal it uses the PHP API of Mediawiki. In this paper I will present how to edit a wiki with Libmediawiki. You can find the code in the edit sample stored in the library repository.

Before being able to use the library functions you must create a MediaWiki object which will contain the information needed for the request to interact with the Wiki.

MediaWiki mediawiki = new MediaWiki(QUrl(this->ui->mWikiEdit->text()));

Load a page

After the MediaWiki creation you can use the library features. First, we need to load the page which will be updated:

QueryRevision* const queryrevision(new QueryRevision(*mediawiki));
connect(queryrevision, SIGNAL(revision(const QList&)),this, SLOT(revisionHandle(const QList&)));
connect(queryrevision, SIGNAL(result(KJob* )),this, SLOT(revisionError(KJob*)));

We first create a request object, QueryRevision, which takes as parameter the previous MediaWiki object. With the setter, we define request options ( page name, content type... ). We connect signals and slots to handle request feedback which are page revision list and potentially an error message (WrongRevisionId, MultiPagesNotAllowed, TitleAccessDenied...). Finally we start the job which will process the asynchronous request.

In revisionHandle slot we can find the following code which gets the revision content requested:


That's all we have to do to load a page!


The second step is needed to update a wiki page.

Login* login = new Login(*mediawiki,this->ui->mLoginEdit->text(),this->ui->mMdpEdit->text());
connect(login, SIGNAL(result(KJob* )),this, SLOT(loginHandle(KJob*)));

Has you can see the login constructor take tree parameters, one MediaWiki object, the user name and the password ( the other request in Libmediawiki take MediaWiki object in constructor and should be customized later on using setter ). We connect the job result signal to catch request feedback. Finaly, we start the job which will trigger the login asynchronously.

Update a page

For the last example, we will update the wiki page. The Edit request can be used to create a non existing page, or update an existing page. To apply our update, the process is the same has QueryRevision request ( and all other request in Libmediawiki ), we create a request object with a MediaWiki instance as parameter, we customize our request with the setters and we start the job.

Edit* job = new Edit(*mediawiki,NULL);
connect(job, SIGNAL(result(KJob *)),this, SLOT(editError(KJob*)));

Questions, comments and feedback are welcome.

This page was last modified on 10 July 2011, at 20:07. Content is available under Creative Commons License SA 4.0 unless otherwise noted.