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 »
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!
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.
Ok, thanks for the quick response!
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:
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!
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
myrootin here:Make sure you used straight quotes (not curly quotes) when defining the constants.
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?
Mori, that’s not a problem I’ve had, so I haven’t looked into what the solution might be. Sorry.
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!
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?
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.
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.
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?
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)
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