Bot internal structure

From Apibot
Revision as of 02:50, 2 August 2014 by Grigor Gatchev (talk | contribs) (some start (a lot remains to expand and fill in))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page explains Apibot internal structure.

The basic components of Apibot are:

  • Apibot core: performs the basic low-level functions, akin to the kernel of an OS
  • Queries: objects that fetch different types of information from the wiki
  • Tasks: objects that perform different operations on the wiki and the data it contains
  • Bridge: an interface that exports functions to obtain Queries objects or perform tasks (using Tasks objects as backends)
  • Assembly line: an interface that consists of a big number of specialized objects, who can be strung up like Unix commands, and use Queries and Tasks objects as backends.

Core structure

The Apibot core is effectively an object of the Mains class and the objects it envelops as its properties, directly or indirectly.

Mains object structure

Contains (as properties) objects from backend-independent classes.

  • Browser class - implements the HTTP(S) protocol, used to transfer data to/from the wiki site
  • Log class - implements message logging facility
  • Settings class - stores and provides the settings for the bot and its modules
  • Infostore class - reads from / writes to files different kinds of info - settings, cached data etc.
  • Info class - supplies various info about the bot, the wiki, the user account etc. An envelope for the backend-specific info classes.
  • Hooks class - maintains the hooking info
  • an array of Backend class objects - implement the backend-specific functionality

Backend object structure

Contains (as properties) objects from backend-specific classes.

  • Exchanger class - implements the specific data exchange with the wiki (uses the Browser object as a backend)
  • Identity class - stores and provides info about the bot account identity (eg. cookies)
  • Tokens class - fetches, stores and provides the various tokens MediaWiki requires for certain operations
  • API Info class or Web Info class - fetch, store and provide info about the wiki, user account etc.

Query object structure

Backend-independent Query object

This is the top Query level - the objects the Apibot interfaces see and work with.

A Query object is backend-independent. On creation it checks which backends can supply appropriate backend-specific Query modules, chooses one from the available by a configured or hardwired order of preference, creates a backend-specific Query module as its property and uses it to do the job.

Backend-specific Query object

The backend-specific Query object is the level under the backend-independent Query object. It directs the Query functionality down the appropriate backend path, masking some of its specifics, providing settings etc. On creation it creates an Action Query object as its property and uses it to do the job.

Action Query object

This is the level under the backend-independent Query object. It adds two important functionalities: logging and support for default parameters. On creation it creates an Query Module with Querymodules object as its property and uses it to do the job.

Query Module with Querymodules object

This is the level under the Action Query object. It is a Query Module, enhanced with support for Querymodules.

Each Querymodule provides the functionality to make a specific type of query. There is also "by_name" Querymodule, which allows making a type of query that does not have a specific Querymodule implemented in Apibot, if the wiki has provided paraminfo about this type of query. This functionality is the ability to receive the appropriate parameters and to supply them on request.

The Querymodules objects are maintained in an array tree. Their parameters can be conveniently set by functions exported by the Query Module with Querymodules object, and are automatically collected and supplied when a call to the wiki is being prepared.

The Query Module with Querymodules object also includes, supports and utilizes a Pageset module.

The Query Module itself is the lowest-level object in the Query structure. On creation it receives and stores as a property an Exchanger object, which it uses to do the exchange with the wiki. It also parses the data obtained and represents it as an array of wiki data elements, represented as scalars or arrays. As it is expected to often receive data by portions, it can also continue a request after a portion.

Task object structure

Backend-independent Task object

This is the top Task level - the objects the Apibot interfaces see and work with.

A Task object is backend-independent. On creation it checks which backends can supply appropriate backend-specific Task modules, chooses one from the available by a configured or hardwired order of preference, creates a backend-specific Task module as its property and uses it to do the job.

Backend-specific Task object

The backend-specific Task object is the level under the backend-independent Task object. It directs the Task functionality down the appropriate backend path, masking some of its specifics, providing settings etc. On creation it creates an Action object as its property and uses it to do the job.

Action object

This is the level under the backend-independent Task object. It adds two important functionalities: logging and support for default parameters. On creation it creates an Module object as its property and uses it to do the job.

Module object

This is the lowest level in a Task structure. On creation it receives and stores as a property an Exchanger object, which it uses to do the exchange with the wiki. It also parses the data obtained and represents it as a wiki data element, represented as a scalar or an array.