This is the code behind User:Grammarbot. It is structured something like this:
cronjob (runs main.php every minute) - main.php (checks if bot is active, then includes do.php) -- do.php (parses article text, does text transformations, checks up on articles it did earlier) --- inc.php (sets up error handling and logging, sets edit summary, replacement text etc) ---- inc_db.php (db login details) ---- inc_wiki.php (wiki functions and site details)
I also have curl.exe (although I may move to using the PHP Curl library), cookieconf.txt (a config file for Curl), cookie.txt (the actual cookie file by and for Curl, which of course is kept where it won't be served to the public) and the public pages index.php, stop.php, stuff.php. Also, some more text files which you can see at stop.php, and logs.
The source of inc_wiki.php is available under GPL.
It includes the following functions:
gettext($title) takes the article text from Special:Export using an XML parser, converts it to ISO-8859-1 if the charset for the wiki isn't UTF-8 (as Special:Export is *always* in UTF-8), and returns it.
geteditpage($title) returns an array where $ar['text'] is the article text and $ar['attr'] is the form variables (including wpEditToken) to pass on to makeedit().
makeedit($title, $attr, $newtext) uses the $ar['attr'] you got from geteditpage() to commit an edit.
That is all. It is a bit messy and you will have to uncomment and edit a line in geteditpage() the first time you use it for it to login.
http://r3m0t.geniushost.net/cron/inc_wiki.txt
The other files in my bot are available if you email me.
wikitech-l@lists.wikimedia.org