Chris G's botclasses/Introduction

A lot of people seem reluctant to get involved with writing bots because it sounds like it could be a lot of work. Actually, it's not; and once you write the code, you have it available for reuse later. Although it takes awhile to get set up writing bots, in the long run you'll accomplish your task faster and with greater accuracy, if you can design your bot well and avoid unfortunate glitches that require thousands of edits to fix (as was the case with LeucosticteBot's edits that got rolled back when we went back to our old database dump).

Bot frameworks
Rather than code a bot from scratch, you may as well just get a bot framework and write the small amount of additional code needed to customize its actions for your particular purposes. You have a lot of programming languages from which to choose. Personally, I'm biased toward PHP because it seems like a better language than, say, C++ ( are lame) and it's the language in which was written. Collaboration will probably be made easier if we write any bot code we intend to share in accordance with these coding conventions.

Chris G's botclasses
Judging by, it would seem that the only decent PHP bot framework around these days is 's botclasses.php. If you're going to use that, go ahead and get the other files from the parent directory as well, e.g. http.php, lyricswiki.php, and mediawiki.php. Maybe get lyricwiki.php too.

Put all those files in a (e.g. /home/myusername/wikibots/ if you're on Linux, or C:\Wikibots\ if you're using Windows), and then create a.

Create your bot account and fire up your bot
Go to the wiki and create your bot account, e.g. User:HelloWorldBot, and modify the bot code accordingly. E.g., instead of, put   or whatever you decided to call it. Also change the password from "REMOVED" to whatever the bot password is. If you want, go to Special:Userrights and flag your bot as a bot; that will flag its edits as bot edits and prevent its edits from being seen by default in Special:RecentChanges.

Save that file as  in the same folder as your other bot files. Then go to the command prompt, to that folder, and type. That will make an edit to RationalWikiWikiWiki:Bot sandbox, if all goes well. Remember, if your bot account is in the bot user group, then you'll need to click "Show bots" in order to see it in RecentChanges.

"I don't know how to get my bot to do x"
It helps if you know some basic programming concepts such as loops, if-then-else statements, and. But if you don't, that's what http://php.net is for. Or get one of those "for dummies" books on PHP and apply the concepts. Wikipedia is a great reference if you know what you're looking for; e.g. you can look up something like and it will tell you how to do it in many different programming languages.

If you know that stuff and are trying to figure out how to get your bot to, say, read the content of a page and put the results in an array, then your best bet is to "Use the Source, Luke" and read through botclasses.php for the necessary function. Of course, it would be better if there were some halfway-decent documentation and some examples you could follow; we should probably create a library of sample bot code so that people don't have to keep doing that research, which can be a significant deterrent to writing bots.

In that spirit, let's look at one more bot. Let's assume you want to download all the images from a wiki. A worthy cause; wikis go down all the time, and you can never have too many backups of their content. Getting the wikitext is not all that hard; it's just a matter of using mw:API:AllPages to get a list of pages, and then putting that list, 500 pages at a time, in Special:Export. If it's a small wiki, you don't even need to fool with a bot (although it might save a little time). Images are a bit more time-consuming since they have to be done one by one; therefore, you'll want to use a bot for that. So, create a /down/ directory underneath your bots directory.