User:LivingBot/Wikibot

Wikibot is a basic PHP framework (or rather, a single class) that simplifies the coding and deployment of PHP-based Mediawiki bots. It was originally based on Kaspo's phpwikibot, but is now substantially different.

Main code file
The main class code can be found here. It definitely works in PHP version 5, and on the English Wikipedia. Other versions of the PHP engine and other MediaWiki sites remain as yet untested. You might want to check fairly regularly to see if there has been a new release.

How to make your own bot
The Wikibot PHP framework greatly speeds up the process of coding and setting up a bot. However, actually coding or writing a bot is only one part of developing a bot. The first step on the road to creating a bot should involve you reading this guide. Before you make any proper edits, ensure that your bot follows Wikipedia's bot policy and has a proper BRFA approved by a member of the Bot Approvals Group. Failure to comply with the policy may lead to your bot failing to be approved or being blocked from editing Wikipedia.

As for utilising Wikibot to code your bot, here is a step-by-step process. Those steps not in italics are optional but highly advisable.
 * 1) Create a new folder on your web server.
 * 2) Password protect access that folder with .htaccess (or similar). All files should be uploaded into that folder.
 * 3) Copy and paste the main code (see above) into a new file called Wikibot.php5 and upload it to your server.
 * 4) Create a new text file, password.txt. It should only contain your / your bot's Wikipedia password - no extra linebreaks or anything. Upload it.
 * 5) Create a new .php5 file (e.g. MyBot.php5). Upload it. This will be the file you actually edit.

Examples for what to put in the file created during step 5 are shown below.

Example code for your bot
These are some examples for what to put inside your MyBot.php5 file.

The bare basics
This lot won't actually do anything, but it'll set you up just fine.

Print a page
Load a page from Wikipedia, then print it.

Mimic another user's page
Load someone else's user page, then update yours to be the same.

Wikibot constructor
What it does: Creates a new Wikibot

Parameters:
 * 1) A username
 * 2) A password
 * 3) A Wiki identifier: most commonly a Wikipedia two-letter language code, e.g. "en". (Optional, defaults to "en".)
 * 4) A max number of edits per minute. (Optional, defaults to 5.)
 * 5) A max-lag (Optional, defaults to 5.)

Returns: A bot object ready for your use.

get_page
What it does: gets the contents of a given page

Parameters:
 * 1) The name of the page
 * 2) The wiki to use, if different to one you specified already. (Optional.)

Returns: A string containing the entire contents of that page, in Wiki format.

get_cats_of_page
What it does: fills an array with the names of all of the categories to which a given page belongs.

Parameters:
 * 1) The name of the page
 * 2) The wiki to use, if different to one you specified already. (Optional.)

Returns: An array filled with the names of categories.

create_page
What it does: creates a new page (won't touch the page if it already exists)

Parameters:
 * 1) The name of the page.
 * 2) The text, in wiki format, to place on the page.
 * 3) An edit summary.
 * 4) Use the minor flag? Either true or false. (Optional, defaults to false.)
 * 5) Use the bot flag? Either true or false. (Optional, defaults to true.)
 * 6) The wiki to use, if different to one you specified already. (Optional.)

Returns: true/false depending on result.

edit_page
What it does: edits a page (won't touch the page if it doesn't exist already).

Parameters:
 * 1) The name of the page.
 * 2) The text, in wiki format, to place on the page.
 * 3) An edit summary.
 * 4) Use the minor flag? Either true or false. (Optional, defaults to false.)
 * 5) Use the bot flag? Either true or false. (Optional, defaults to true.)
 * 6) The wiki to use, if different to one you specified already. (Optional.)

Returns: true/false depending on result.

category
What it does: lists the members of a category (non-recursive).

Parameters:
 * 1) The name of the category.
 * 2) A limit on the number of the pages to retrieve. (Optional, defaults to 500 which is the maximum possible unless your user has the apihighlimits right (e.g. it's flagged or an adminbot), in which case it's 5000.)
 * 3) A namespace to use. (Optional, defaults to "all".)
 * 4) The wiki to use, if different to one you specified already. (Optional.)
 * 5) A starting point, usually the "next" value from a previous search. (Optional, defaults to "".)

Returns: An array with the names of the members of the category. An extra item is added to the end of the array: the "next" value, ready to be fed to the function next time.

Does it work?
I haven't personally used it for a while now, but it should do: nothing's changed since.

Can I edit it? What licence is it released under?
It is everything you would expect Wikipedia to be: free (beer) and free (speech). You can edit the files yourself, or publish updates/extra functions straight to the file.

Does this create exclusion-compliant bots?
As of version 0.2.1, released February 14, 2009, yes. It is effectively compulsory for all bots using the framework.

Other questions? Problems?
If you have any questions of problems, just shout on my talk page.