Infostore class

From Apibot
Jump to: navigation, search

To decrease the online traffic (always a service to the wiki), Apibot caches the info it receives into an info store. Handling of this store is the task of the Infostore object.

In theory, info can be preserved in any feasible way. The current implementation of the Infostore class stores the info in files in a specified directory, as a serialized PHP variable. Other implementations can be used freely, as long as they conform to the standard established by this implementation.

The information handled by the Infostore object can be either site information, or user information. Site information differs between sites, but is the same for every user of this site. User information differs not only between sites, but also between site users.

In addition, information can belong to many different types. For example, a site info can be general, paraminfo, siteinfo etc. An user info might be wiki userinfo, identity etc. Info types are specified while fetching info from the store or sending info to it.

The Infostore object is identity-specific. If the bot assumes a new identity (logins to a different site and/or with a different account), a new Infostore object must be created and replace the old one in the Core object.

Creating

Creating an object of the Infostore class requires three parameters:

  • $sitename - a name for the site currently used
  • $username - a name for the user currently used
  • $path - the info file pathname

Public methods

Siteinfo support

  • exists_siteinfo ( $type ) - whether siteinfo of this type exists
  • mtime_siteinfo ( $type ) - the last modification time for the siteinfo of this type (false if this siteinfo does not exist)
  • read_siteinfo ( $type ) - returns the siteinfo of this type, or false if it does not exist or is not readable
  • write_siteinfo ( $type, $data ) - writes this data as the siteinfo of this type, overwriting any old siteinfo if it exists; returns false if writing is unsuccessful
  • delete_siteinfo ( $type ) - deletes the siteinfo of this type; returns false if not deleted successfully, or if it does not exist

Userinfo support

  • exists_userinfo ( $type ) - whether userinfo of this type exists
  • mtime_userinfo ( $type ) - the last modification time for the userinfo of this type (false if this userinfo does not exist)
  • read_userinfo ( $type ) - returns the userinfo of this type, or false if it does not exist or is not readable
  • write_userinfo ( $type, $data ) - writes this data as the userinfo of this type, overwriting any old userinfo if it exists; returns false if writing is unsuccessful
  • delete_userinfo ( $type ) - deletes the userinfo of this type; returns false if not deleted successfully, or if it does not exist