Writing a Wiki Bot

Monday, March 18, 2013

As part of the wiki re-fuckulation process a month back I had to move and reformat a bunch of pages. So I went about writing a wiki bot.

If you already have good knowledge of PHP this is about a billion times easier than it sounds due to a useful little library called wikimate. Its github page speaks for itself, it's incredibly painless to read page text, set page text, delete pages etc.

So as an example.. one of the fucked up things about the old wiki is that it didn't use categories. All of the functions were painstakingly listed on a page. So if you removed or added a function you had to edit this index page too. That's not how a wiki is meant to be indexed. So I went about getting all the listings on those pages and converting them to a new template, so they would be categorised properly and also be editable via a form.

When I'm posting this code I'm now showing you great coding – I'm showing you code that got shit done.


So this function looks on the Libraries page and splits it by newlines – so that $lines is an array of lines. Then if a line contains "{{Lib" it trims shit off, splits it by | and calls ConvertLib.


ConvertLib does pretty much the same thing. It gets the library's index page, goes line by line looking for LibraryFunc. Then it splits by | and calls Process.


Process is kind of a big boring function, so I'm splitting it into sections here. This part gets the target page. If it already exists then we already did our work, so it bails. If not it get the source page. This is the page we're gonna be reading and converting to the target page.


It reads the page contents into $text


Then it tries to find the information we need for the new page. This looks more complicated than it is. It's basically trying to find text between two other pieces of text. There's a bit of fucking about to get this to work properly.. This is probably where regex works well – but who wants to learn how to use regex – right?


Once we have the info we can build $out – in the format that we want.


The arguments were stored in a really shitty way under a single template (Arg1Name, Arg2Name, Arg1Type, Arg2Type blah blah). In the new system we store the arguments unnumbered under the Arg template – and fuck about adding numbers in javascript after the page is rendered.


The final thing is to set the text of the new page, and delete the old one. We set the delete reason on the old page so future generations can figure out why we did what we did.


How was I running this? Well you just install PHP and then you can open a command line and run "php.exe convert_libraries.php". You don't need to go through the trouble of uploading to a host and running it in the browser.

I had lots of fun playing with this stuff and I think it has made the wiki much friendlier to edit! So everyone wins!

More Rubbish

Your Portfolio Gave Me Diarrhea

Friday, October 1, 2021


Friday, September 24, 2021

We got married

Thursday, September 16, 2021

Unity Quiz

Sunday, September 6, 2020

Everything We Watched In Lockdown

Thursday, September 3, 2020

Oil your brain

Friday, March 15, 2013

Tax Investigation

Thursday, March 14, 2013

Lua Bindings

Wednesday, March 13, 2013

Office Progress

Tuesday, March 12, 2013


Monday, March 11, 2013