KB Plugins

The best Wordpress plugins are free

Next post: Gravatars »
Previous post: New Theme »

Back to KB Plugins main page

Print this post

BasicBot.php

Most of my posts on this blog relate to my WordPress plugins. But I also host a wiki , and it took me some time to figure out how to code a MediaWiki bot in PHP to perform automated tasks.

Download my BasicBot MediaWiki Bot template here if you want. If you have questions, you can post them as comments here.

Please note that this project has moved to my back burner, and then some. I got it working for my purposes. If you get it working for yours, great. But don’t be surprised if it takes me awhile to respond…

14 comments »

1
Scott says
at 9:28 am on December 19, 2007 #

Adam, first of all, thank you so much for making BasicBot available for use. I have found it to be very useful. I had to spend quite a bit of time muddling through the code to understand it and write a subclass to extend it, but I am very glad that you have provided the code that you did.

Secondly, have you actually tested BasicBot successfully as a cron job? (A simple yes or no answer would suffice if you don’t have time to go into detail. Just as long as I know I’m heading in the right direction.) My bot works fine if I visit the link to the script directly, but as a cron job I don’t think the system regards the meta http-equiv=”refresh” tag because it’s not being run in a browser, and so the page won’t refresh and rerun the script. Thanks!

2
Thus saith Adam
at 9:34 am on December 19, 2007 #

No, I haven’t used it as a cron. I mainly use it with form-based bots (like a category renamer), so for my purposes, the meta refresh makes more sense than a cron. You would need to modify the code a bit for it to work well as a cron, but it shouldn’t be too big of a job.

3
Scott comments
at 10:26 am on December 19, 2007 #

Ok, thanks for the quick response!

4
Richard contributes
at 8:30 am on January 17, 2008 #

Hello,

First of all, tons of kudos for this bot. I’ve been looking for a tut how to make a bot for months and finally I found this, which is even better than I’d hoped to find. Thank you very much for this _O_.

I have one little problem tho, I don’t know how to solve it as my php skills are very limited. I put all the stuff in a secured directory on my webspace as you said and I changed the SERVER, USERID, USERNAME and PASSWORD. When I tried the WikifyBot.php, after changing the $source, its giving me an error:

Warning: file_put_contents("myroot"/BasicBot/temp/harvest_20080117_030947.php) [function.file-put-contents]: failed to open stream: No such file or directory in /"myroot"/BasicBot/BasicBot.php on line 483
Unable to write to temporary directory.

I tried CHMODding the files and the directory to 777, but that didn’t work. I probably did something wrong, I really hope you can help me out here.

Thanks!

5
Thus saith Adam
at 9:45 am on January 28, 2008 #

Sorry about the delay. My real work has me swamped. An initial thought:

I can see from the error message that something is screwy. It shouldn’t have the weird quotes around myroot in here:

file_put_contents(”myroot”/BasicBot/temp/harvest_20080117_030947.php)

Make sure you used straight quotes (not curly quotes) when defining the constants.

6
Mori writes
at 10:38 am on March 6, 2008 #

Hi Adam!

Great bot you’ve got here - I am using it, modded for my template work… But I’ve run into some, unsolved yet, problems. If the page I’m trying to edit via bot was deleted in the past, and now is restored, the bot just shows that XYZ deleted this page (however, clicking on the link gives you the page without problems, you can edit it manually). Why is that happening and how to fix it?

7
Thus saith Adam
at 8:41 am on March 10, 2008 #

Mori, that’s not a problem I’ve had, so I haven’t looked into what the solution might be. Sorry.

8
Mori opines
at 8:43 am on March 11, 2008 #

I’ve managed to somehow solve it by clearing the deleted pages log, but that’s not really a solution. I still wonder why is that happening - it’s not that the starttime is before the deletetime - I’ve triple-or-so checked it.

Nevertheless, thanks for the amazing code you’ve written!

9
at 9:41 am on March 14, 2008 #

I’d first like to say that this script looks fantastic and im very eager to deploy it, but I think I found a bug.

In BasicBot.php, for in the case of my site where i simply dropped the zip file and ran it, I have a weird problem with the $link variable when running WikifyBot.php.

Instead of it storing Pagename, it is storing “supplementpedia/index.php5?title=Pagename

So the entire link looks like this:

[link]

Can the code not handle having the wiki in a subdirectory?

10
Thus saith Adam
at 9:44 am on March 20, 2008 #

Subdirectories aren’t a problem. My wiki is in a subdirectory. But there are settings at the top of the file where you need to tell the bot about what subdirectories you are using. Set those.

11
Ryan proclaims
at 2:22 pm on May 13, 2008 #

I like you bot script, it is a great help. I run a mediawiki powered site and I want to make a bot to reset the sandbox, and I will use cronjobs to run it every once in awhile. The thing is I don’t get how editing works. How would I check the contens of a page, then if they do not match an empty snadbox (only the basic header and instructions), erase what is there then add the sandboxc header stuff and save it.

12
Miguel exclaims
at 1:37 pm on May 16, 2008 #

Hi. Can anyone give me any pointers on how I’d go about creating a bot that would log in as WikiSysop, access and edit MediaWiki:Main Page?

13
Ryan contributes
at 7:30 pm on May 19, 2008 #

Well I found a way to make my bot easier, I just need it to connect to my wiki, login, then goto [link](id of empty sb)&autoclick=wpSave&autosummary=(edit summary)

14
Marcus thinks
at 9:42 pm on May 23, 2008 #

Thanks for publishing this! I successfully used your bot template tonight to push out a bunch of changes to hundreds of files, it was very handy.

In the comments for “categoryFilterAll” you suggest editing the categoryPage.php file to add a div tag with a class of categoryItems. While looking for the spot to do that, I noticed there already was a div there, but with an ID of “mw-pages”. So rather than edit the wiki code, I changed the bot framework as follows:
// preg_match( "|<div[^>]*class=['\"]categoryItems['\"][^>]*>(.*)</div[^>]*>|Us",$this->results,$catLinks );
preg_match( "|<div[^>]*id=['\"]mw-pages['\"][^>]*>(.*)</div[^>]*>|Us",$this->results,$catLinks );

This is with mediawiki 1.12.0, I have no idea if that tag was there in earlier versions.

Thanks again for the groovey framework

Leave a comment

Comment Guidelines
  • Yes, your comments will be visible to everybody. (Unless you use the private contact form.)
  • Allowed HTML: <a> <b> <blockquote> <cite> <code> <em> <i> <strong>
  • Code: Put code in `backticks` (above your "Tab" key) or it won't display well
  • Gravatars: To override the default image by your comment, use a gravatar
  • Links: If you include more than one link, your comment will go into the spam queue

Please read before commenting: Because my real job has me swamped at the moment, I am not supporting my plugins at this time. Sorry. This may last several weeks.

If you have a bug report, feature request, or other general feedback about a plugin, please leave a comment—but do not expect an immediate response. If you are requesting help, though, please check the plugin's documentation thoroughly rather than ask your question as a comment.

Thank you for your understanding.