Difference between revisions of "Info object"

From Apibot
Jump to: navigation, search
(another info link)
m (Core -> Mains)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
A MediaWiki installation is able to supply an enormous wealth of info that can be useful for bot tasks. Apibot is able to fetch this info and supply it to the programs that use it. To decrease the wiki online traffic, the info is cached and reused according to specified settings. All this is done by the '''<code>Info</code>''' object, which is part of the Apibot [[Apibot 0.40 Mains class|Mains object]].
+
A MediaWiki installation can provide an enormous wealth of info that can be useful for bot tasks. Apibot is able to fetch this info and supply it to the programs that use it. To decrease the wiki online traffic, the info is cached and reused according to specified settings. All this is done by the '''<code>Info</code>''' object, which is part of the Apibot [[Core object]].
  
This class exports over 500 functions that return wiki and user info, as well as some useful conversions and tasks that rely on this info - more than any other part of Apibot. If the bot doesn't know the information returned by the function you called, it will try to auto-fetch and possibly cache it. If the information is still unavailable, the function will typically return <code>NULL</code>.
+
This class exports over 500 functions that return wiki and user info, as well as some useful conversions and tasks that rely on this info - more than any other part of Apibot.
 +
 
 +
If you call an Info function that returns information unknown to the bot, it will try to auto-fetch and possibly cache it. If the information is still unavailable, the function will return <code>NULL</code>.
  
 
== Types of info ==
 
== Types of info ==
  
Apibot divides the information from the wiki into several types:
+
Apibot divides the information from the wiki into several types. Currently are supported the following ones:
  
 
* general - common things about the wiki; matches the General subtype of the MediaWiki Meta Siteinfo.
 
* general - common things about the wiki; matches the General subtype of the MediaWiki Meta Siteinfo.
Line 13: Line 15:
 
* paraminfo - the MediaWiki Paraminfo
 
* paraminfo - the MediaWiki Paraminfo
  
== Info classes ==
+
== Implementation ==
  
The <code>Info</code> class is actually the last descendant in a class hierarchy:
+
The [[Core object]] has a property called <code>$info</code>, which is an object of the Info class. All its functions can be accessed there. Some other Apibot objects, eg. the [[Bridge interface]], export it not only as a Core property, but also directly as their own property, for backwards compatibility and convenience.
  
* <code>Info_Fetcher</code> - fetches the info; also, exports functions that return the general info
+
Info is actually a container class that collects the Info objects of the different Apibot backends. It has almost no methods of its own. When called with a method other than <code>log()</code>, it will check the present backend Info objects for this method, in a specified order (first API, then Web). If the method is found, it will be called and its result will be returned.
* <code>Base_Info</code> - extends <code>Info_Fetcher</code>; exports functions that return the siteinfo, userinfo, allmessages and paraminfo
 
* <code>Extended_Info</code> - extends <code>Base_Info</code>; exports functions that are convenient shortcuts for some frequently used specific function calls, and functions that provide useful stuff relying on the wiki info
 
* <code>Info</code> - extends <code>Extended_Info</code>; by default implements no new functions - it is a place for the bot user's custom functions, should s/he implement some. The <code>Info</code> object in the Apibot <code>Mains</code> object is of this class.
 
  
All of these classes are implemented in PHP files with matching names, situated in the directory <code>common/info</code>.
+
As of Apibot 0.40.12, only the API backend is able to obtain wiki info. In future Apibot versions, the Web backend may also gain some functionality, as the Web backend can also supply some of the info needed, and even a few bits of info that are currently not available conveniently through the API backend.
  
 
== Creating ==
 
== Creating ==
  
Creating an object of the class <code>Info</code> requires three parameters:
+
Creating an object of the class <code>Info</code> requires one parameter:
  
* <code>$exchanger_api</code> - an [[Apibot 0.40 Exchanger class|API exchanger]] object
+
* <code>$core</code> - a [[Core object]]. (It carries some objects the Info object needs to fetch, store and/or retrieve its payload.)
* <code>$infostore</code> - an [[Apibot 0.40 Infostore class|Infostore]] object
 
* <code>$settings</code> - a [[Apibot 0.40 Settings class|Settings]] object
 
  
In addition, it can also take forth paramerer:
+
The resulting Info object does not self-attach to the Core object it was created with. If the goal of creating it is to replace the current Info object of this Core object (or to supply one during the Core object construction), it must be explicitly assigned:
 +
<pre>
 +
$info = new Info ( $core );
 +
$core->info = $info;
 +
</pre>
  
* <code>$force_load</code> - if true, will automatically fetch all wiki info on the object creation. Default is <code>false</code> - this allows fetching the info from the wiki only when it is needed.
+
== Public functions ==
  
== Public properties ==
+
Due to their big number, the functions are listed in separate subpages:
  
* <code>$autoload</code> - whether to request the info from the wiki automatically on need. Default is <code>true</code>. If <code>false</code>, info will be requested from wiki only if the wiki info fetching functions are explicitly called.
+
* [[Info object/Global|Global info management]]
 +
* [[Info object/General|Wiki general info]]
 +
* [[Info object/Siteinfo|Wiki siteinfo]]
 +
* [[Info object/Paraminfo|Wiki paraminfo]]
 +
* [[Info object/Userinfo|Wiki userinfo]]
 +
* [[Info object/Allmessages|Wiki allmessages]]
 +
* [[Info object/Extended|Extended wiki info]]
  
== Public functions ==
+
(The class may also contain other types of info functions, eg. global user info, which are still not official.)
  
Due to their numbers, the functions are listed in separate subpages:
+
== See also ==
  
* [[Apibot 0.40 Info class/Global|Global info management]]
+
* [[Core object]]
* [[Apibot 0.40 Info class/General|Wiki general info]]
 
* [[Apibot 0.40 Info class/Siteinfo|Wiki siteinfo]]
 
* [[Apibot 0.40 Info class/Paraminfo|Wiki paraminfo]]
 
* [[Apibot 0.40 Info class/Userinfo|Wiki userinfo]]
 
* [[Apibot 0.40 Info class/Allmessages|Wiki allmessages]]
 
* [[Apibot 0.40 Info class/Extended|Extended wiki info]]
 
 
 
(The class may also contain other types of info functions, eg. global user info, which are still not official.)
 

Latest revision as of 18:38, 19 October 2014

A MediaWiki installation can provide an enormous wealth of info that can be useful for bot tasks. Apibot is able to fetch this info and supply it to the programs that use it. To decrease the wiki online traffic, the info is cached and reused according to specified settings. All this is done by the Info object, which is part of the Apibot Core object.

This class exports over 500 functions that return wiki and user info, as well as some useful conversions and tasks that rely on this info - more than any other part of Apibot.

If you call an Info function that returns information unknown to the bot, it will try to auto-fetch and possibly cache it. If the information is still unavailable, the function will return NULL.

Types of info

Apibot divides the information from the wiki into several types. Currently are supported the following ones:

  • general - common things about the wiki; matches the General subtype of the MediaWiki Meta Siteinfo.
  • siteinfo - all other MediaWiki Meta Siteinfo
  • userinfo - the MediaWiki Meta Userinfo
  • allmessages - the MediaWiki Meta Allmessages
  • paraminfo - the MediaWiki Paraminfo

Implementation

The Core object has a property called $info, which is an object of the Info class. All its functions can be accessed there. Some other Apibot objects, eg. the Bridge interface, export it not only as a Core property, but also directly as their own property, for backwards compatibility and convenience.

Info is actually a container class that collects the Info objects of the different Apibot backends. It has almost no methods of its own. When called with a method other than log(), it will check the present backend Info objects for this method, in a specified order (first API, then Web). If the method is found, it will be called and its result will be returned.

As of Apibot 0.40.12, only the API backend is able to obtain wiki info. In future Apibot versions, the Web backend may also gain some functionality, as the Web backend can also supply some of the info needed, and even a few bits of info that are currently not available conveniently through the API backend.

Creating

Creating an object of the class Info requires one parameter:

  • $core - a Core object. (It carries some objects the Info object needs to fetch, store and/or retrieve its payload.)

The resulting Info object does not self-attach to the Core object it was created with. If the goal of creating it is to replace the current Info object of this Core object (or to supply one during the Core object construction), it must be explicitly assigned:

$info = new Info ( $core );
$core->info = $info;

Public functions

Due to their big number, the functions are listed in separate subpages:

(The class may also contain other types of info functions, eg. global user info, which are still not official.)

See also