Difference between revisions of "Development/Tutorials/Libmediawiki"

(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...")
(Mark for archiving)
Line 1: Line 1:
= How to edit a wiki with Libmediawiki =
= How to edit a wiki with Libmediawiki =

Latest revision as of 14:46, 31 May 2019

This page has been archived
The information on this page is outdated or no longer in use but is kept for historical purposes. Please see the Category:Archives for similar pages.

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 edited on 31 May 2019, at 14:46. Content is available under Creative Commons License SA 4.0 unless otherwise noted.