Difference between revisions of "Info object"

From Apibot
Jump to: navigation, search
m (moved Info class to Info object: converting to an user-level description)
(userification)
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 [[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 [[Mains 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 ==
Line 15: Line 17:
 
== Implementation ==
 
== Implementation ==
  
The [[Mains class|Mains]] 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. [[Docs/Modules#The Bridge interface|Bridge]], export it not only as a Mains property, but also directly as their own property, for backwards compatibility and convenience.
+
The [[Mains 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 Mains 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 <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.
 
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.
  
The backend Info classes are children of the <code>Backend_Info</code> class, implemented in <code>backends/_generic/info.php</code>. <code>API_Info</code> is implemented in <code>backends/api/mains/info.php</code>, and <code>Web_Info</code> is implemented in <code>backends/web/mains/info.php</code>. Each of them is responsible for obtaining the wiki info through its backend.
+
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.
 
 
As of Apibot 0.40.10, only the API backend is able to obtain 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 ==
Line 27: Line 27:
 
Creating an object of the class <code>Info</code> requires one parameter:
 
Creating an object of the class <code>Info</code> requires one parameter:
  
* <code>$mains</code> - a [[Mains class|Mains]] object
+
* <code>$mains</code> - a [[Mains object]]
  
 
The resulting Info object does not self-attach to the Mains object it was created with. If the goal of creating it is to replace the current Info object of this Mains object (or to supply one during the Mains object construction), it must be explicitly assigned:
 
The resulting Info object does not self-attach to the Mains object it was created with. If the goal of creating it is to replace the current Info object of this Mains object (or to supply one during the Mains object construction), it must be explicitly assigned:
Line 39: Line 39:
 
Due to their big number, the functions are listed in separate subpages:
 
Due to their big number, the functions are listed in separate subpages:
  
* [[Info class/Global|Global info management]]
+
* [[Info object/Global|Global info management]]
* [[Info class/General|Wiki general info]]
+
* [[Info object/General|Wiki general info]]
* [[Info class/Siteinfo|Wiki siteinfo]]
+
* [[Info object/Siteinfo|Wiki siteinfo]]
* [[Info class/Paraminfo|Wiki paraminfo]]
+
* [[Info object/Paraminfo|Wiki paraminfo]]
* [[Info class/Userinfo|Wiki userinfo]]
+
* [[Info object/Userinfo|Wiki userinfo]]
* [[Info class/Allmessages|Wiki allmessages]]
+
* [[Info object/Allmessages|Wiki allmessages]]
* [[Info class/Extended|Extended wiki info]]
+
* [[Info object/Extended|Extended wiki info]]
  
 
(The class may also contain other types of info functions, eg. global user info, which are still not official.)
 
(The class may also contain other types of info functions, eg. global user info, which are still not official.)
 
=== Hooks ===
 
 
These Info functions can be hooked to through the <code>[[Hooks class|Hooks]]</code> <code>Mains</code> module:
 
 
{| class="wikitable"
 
! Function (with hook callback profile)
 
! Since Apibot version
 
|-
 
| <code>load_info ( $hook_object, $type )</code>
 
| v0.40.10
 
|}
 

Revision as of 16:11, 20 July 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 Mains 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 Mains 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 Mains 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:

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

$info = new Info ( $mains );
$mains->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.)