Writing a simple greeting bot for MediaWiki/Signing in

On this page you will learn how to login into MediaWiki so you can perform edits with an extra bot account.

Overview
First we will send our username and password to the api. It will give us some "cookies" and a token.

Exercise 1 - New functions
We will create a new class that represents a MediaWiki site like Wikiversity or Wikipedia in a specific language. This class will be used to send data to the wiki and even to sign in.

First we will create a new function to send data. The code is based on the last site: Introduction to MediaWiki scripting access.

The new thing is the POST data. Http requests can handle GET and POST data, for more information read Http. We need POST requests for example to login or to edit a page. Another thing is that we send and get cookies now. Cookies are informations we have to save and send back later. They will contain a key or token so we can authenticate us later and do not have to send our username and password all the time.

This is the function to login. We will use the function  and send our user information to the api.

Exercise 2 - A class for MediaWiki sites
Before we start to code the new class we first have to think how it should work. We will create a "class diagram" where we write all functions and properties the new class shoudl have without code. A class diagram is a table which informations about this aspects.

After we now have an overview which functions and properties the class should have, we can start to create the class.

Where to go next
Writing a simple greeting bot for MediaWiki/api.php