User:Amgine/aNewsiebot

BrianMc asked me to look at and contribute to the NewsiBot mediawiki bot framework written in PHP. That bot is largely based on botclasses.php and the http class, which in turn have a long and complex genetic heritage from various projects and developers.

I looked. And, in my opinion, although the code works and does a lot of cool stuff&trade;, it needs a rather complete rewrite to take advantage of developments in php and improve its maintainability.

Target audience
This bot framework would be written for people who need to run automated tasks on a mediawiki installation which has a publicly accessible api.

The target bot author would be someone with a small familiarity with php, and a willingness to do stuff and figure it out as they go along. That is, they don't need a lot of php skills/knowledge/experience, they do need to be self-starters.

Outline of how it (might) work
The framework resides in a root folder, with a hierarchy something like this:

root/ +- bots/ +- yourbotname/ +- otherbot/ .. +- classes/ +- tests/ *- vendor/

The framework runs from the commandline, something like this: php anewsiebot yourbotname

This will load the custom configuration for yourbotname, which defines which wiki(s) and username(s) the bot will be working with, and then load the script the bot author has written which defines the cycle of tasks the bot will perform.

Where the bot lives
Each bot needs its own configuration file, and its own tasks file. A bot operator's life is simplified if each bot has its own subdirectory under root/bots/. What this should mean is nobody needs to edit anything above the bots/ directory, which will make the framework developer's lives easier too.

In the bot's folder will be, at least, the config.ini (configuration file), and the tasks.php (the script which actually runs the bot.) The configuration contains information about each wiki to work with, such as the url, the username, and the user password; every configuration variable which needs to be altered from the default values can be set in the config.ini.

The actual engine of the bot resides in the tasks file. This php script consists of a loop to cycle through each of the wikis on which the bot will operate, and within that loop is the tasks the bot will perform, which may itself be a loop in order to work through an iterative collection of tasks.

How is this different?
There are two points at which this is different from the current models of mediawiki bots coded in php:
 * 1) Bots are run from the root folder, but actually reside in a sub folder.
 * Primarily this is to make it easier for a bot author or operator to write, run, and maintain a bot without messy directories.
 * 1) The bot framework code is moving toward a more modular and maintainable source code.
 * By no means is this a "fix"! this is merely a few steps toward more standardized, modern coding models. We hope to continue this effort because it makes it much easier for people to contribute, and we hope it leads toward more stability by having auditable, testable code.

What's it do?
The framework creates a 'connection' object for each wiki to which the bot's configuration wishes to connect. It stores each of these in a temporary registry. Each connection contains a selection of pre-coded api requests, which are stackable, and methods to 'roll your own'.

There will also be a database connection manager, allowing the use of several different database engines or working with a database file in a standalone fashion (sqlite).

PHP already has excellent, simple tools for working with folders and files, but a priority goal for post-beta is adding a media file uploader module to allow simplified image uploads to wikis which accept file uploads, using either wiki templates or bot-based templates for meta data inclusion.

Discussion
Please feel free to discuss this initiative either here or on the talk page.