AnomieBOT::API - AnomieBOT API access class
use AnomieBOT::API; my $api = AnomieBOT::API->new('/path/to/config_file', 1); $api->login(); $res=$api->query(list=>'allpages',apnamespace=>0,aplimit=>10);
AnomieBOT::API
is a class implementing various functions needed by a MediaWiki bot.
Unless otherwise noted, each method returns an object with certain standard properties:
page
property containing the full HTML returned with the error, and a httpcode
property with the HTTP response code.raw
property containing the response string;type
with the value "bydefault", "byname", or "optout".$api->iterator()
when the result set cannot be iterated.Note that this class supports runtime decoratoration, so the complete set of available methods depends on the most recent call to task()
.
name
. Anything set before the first section is considered "defaults" for any sections named "bot #".@include opts filename
. Any options begin with a "!" character; the remainder of the line is the filename. By default, the file may have its own defaults section (which is merged with the including file's) and sections; if the "!section" option is given, the file will be considered part of the current section and attempting to include other files or define sections will be considered an error. If the "!ifexists" option is given, it will not be an error if the file doesn't actually exist.[bot #]
sections of the config file is actually used.$from
to $to
(gzipping on the way), then truncate via $fh
.$nodelete
regexp.watchlist
value. Valid values are specified by the API, currently watch
, unwatch
, preferences
, or nochange
. The default is nochange
.$api->CFG->{$property}
.DBI->connect
and returns the database handle.replica_dsn
is not set in conf.ini, dies instead.$svc
replaces a $SVC
token in replica_dsn
. For Tool Forge, pass 'analytics' or 'web'. Defaults to 'web'.query()
, this method may pause for read throttling or maxlag errors.\@continues
specifies how to handle that: those multiple calls will be made automatically for all modules not named. Note that you will get errors if your query uses a generator and you specify any non-generator modules without also specifying the generator module. To specify the generator module, prefix the module name with "g|". If for some reason you need to specify the continuation parameter explicitly, join it to the module name with a "|" (e.g. "revisions|rvcontinue"); note this is not recommended.\@continues
is not provided, the default value consists of the generator or list modules specified in the query, plus "revisions|rvcontinue" (we don't want to download all several-thousand revisions automatically when prop=revisions is in enum mode).content
property of the return object. MediaWiki errors will not be detected.['editconflict']
when calling
action=edit if you were expecting edit conflicts.my $iter = $api->iterator( %q ) while(my $res = $iter->next()){ # Do stuff }
$res->{'query'}
, which must be an arrayref or a hashref.$api->iterator( titles => ['foo', 'bar', 'baz'], prop => 'info' )
result
property indicating success or failure. This is translated into a 'notloggedin' error code.$force
.meta=tokens
module). Available options are:
Title
is provided.Title
and set this to the appropriate token as detailed at
Template:bots#Message notification opt out.Title
. Don't do this frivolously.prop
module will be included in the query. If the value is a hash reference, the key-value pairs will be interpreted as the needed parameters for the module.links => 1, categories => { show => 'hidden' }
will include all the page links and the hidden categories in the returned object.revisions
and info
are always queried, with rvprop=ids|timestamp|content|flags|user|size|comment|tags
, rvslots=*
, and inprop=protection|talkid|subjectid
.code
and error
as usual, token
holding the token, curtimestamp
holding the timestamp, rights
holding the current user's rights, and if Title
was specified the properties returned for a query of that title.login(1)
will be automatically attempted; if it fails, an error code 'notloggedin' will be returned. If the current user cannot edit the wiki, a 'notallowed' error code will be returned. If the task's shutoff page (User:botname/shutoff/task) is non-empty, an error code 'shutoff' will be returned.gettoken()
, with the following differences:
Title
is always passed.Redir
is set, unless EditRedir
is true.gettoken()
, the following are available:
Redir
is defaulted to true. This causes Redir
to be set false.edit()
.assert
parameter to assert that the current user has the "bot" flag. This means that the edit will fail if your bot is not flagged; the AnomieBOT
trial.pl script overrides this default, so bot trials may still be done.$token
must be obtained from $api->gettoken
with the target file name passed as Title
. To specify the file contents, exactly one of the following options must be given:
Stash
was used), specify the returned file key here to complete the upload. SessionKey
is accepted as an alias for backwards compatability.Text
is not used.Comment
.move()
. The object contains the same properties as that returned by edittoken()
, plus the following:
$noredirect
parameter to move()
will be honored (i.e. the user has the 'suppressredirect' right).$totitle
.%param
must contain an "action" key, as well as any other keys needed for the action ("token" may be omitted).require AnomieBOT::API;
or use AnomieBOT::API;
.Copyright 2008–2013 Anomie
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AnomieBOT::API - AnomieBOT API access class
use AnomieBOT::API; my $api = AnomieBOT::API->new('/path/to/config_file', 1); $api->login(); $res=$api->query(list=>'allpages',apnamespace=>0,aplimit=>10);
AnomieBOT::API
is a class implementing various functions needed by a MediaWiki bot.
Unless otherwise noted, each method returns an object with certain standard properties:
page
property containing the full HTML returned with the error, and a httpcode
property with the HTTP response code.raw
property containing the response string;type
with the value "bydefault", "byname", or "optout".$api->iterator()
when the result set cannot be iterated.Note that this class supports runtime decoratoration, so the complete set of available methods depends on the most recent call to task()
.
name
. Anything set before the first section is considered "defaults" for any sections named "bot #".@include opts filename
. Any options begin with a "!" character; the remainder of the line is the filename. By default, the file may have its own defaults section (which is merged with the including file's) and sections; if the "!section" option is given, the file will be considered part of the current section and attempting to include other files or define sections will be considered an error. If the "!ifexists" option is given, it will not be an error if the file doesn't actually exist.[bot #]
sections of the config file is actually used.$from
to $to
(gzipping on the way), then truncate via $fh
.$nodelete
regexp.watchlist
value. Valid values are specified by the API, currently watch
, unwatch
, preferences
, or nochange
. The default is nochange
.$api->CFG->{$property}
.DBI->connect
and returns the database handle.replica_dsn
is not set in conf.ini, dies instead.$svc
replaces a $SVC
token in replica_dsn
. For Tool Forge, pass 'analytics' or 'web'. Defaults to 'web'.query()
, this method may pause for read throttling or maxlag errors.\@continues
specifies how to handle that: those multiple calls will be made automatically for all modules not named. Note that you will get errors if your query uses a generator and you specify any non-generator modules without also specifying the generator module. To specify the generator module, prefix the module name with "g|". If for some reason you need to specify the continuation parameter explicitly, join it to the module name with a "|" (e.g. "revisions|rvcontinue"); note this is not recommended.\@continues
is not provided, the default value consists of the generator or list modules specified in the query, plus "revisions|rvcontinue" (we don't want to download all several-thousand revisions automatically when prop=revisions is in enum mode).content
property of the return object. MediaWiki errors will not be detected.['editconflict']
when calling
action=edit if you were expecting edit conflicts.my $iter = $api->iterator( %q ) while(my $res = $iter->next()){ # Do stuff }
$res->{'query'}
, which must be an arrayref or a hashref.$api->iterator( titles => ['foo', 'bar', 'baz'], prop => 'info' )
result
property indicating success or failure. This is translated into a 'notloggedin' error code.$force
.meta=tokens
module). Available options are:
Title
is provided.Title
and set this to the appropriate token as detailed at
Template:bots#Message notification opt out.Title
. Don't do this frivolously.prop
module will be included in the query. If the value is a hash reference, the key-value pairs will be interpreted as the needed parameters for the module.links => 1, categories => { show => 'hidden' }
will include all the page links and the hidden categories in the returned object.revisions
and info
are always queried, with rvprop=ids|timestamp|content|flags|user|size|comment|tags
, rvslots=*
, and inprop=protection|talkid|subjectid
.code
and error
as usual, token
holding the token, curtimestamp
holding the timestamp, rights
holding the current user's rights, and if Title
was specified the properties returned for a query of that title.login(1)
will be automatically attempted; if it fails, an error code 'notloggedin' will be returned. If the current user cannot edit the wiki, a 'notallowed' error code will be returned. If the task's shutoff page (User:botname/shutoff/task) is non-empty, an error code 'shutoff' will be returned.gettoken()
, with the following differences:
Title
is always passed.Redir
is set, unless EditRedir
is true.gettoken()
, the following are available:
Redir
is defaulted to true. This causes Redir
to be set false.edit()
.assert
parameter to assert that the current user has the "bot" flag. This means that the edit will fail if your bot is not flagged; the AnomieBOT
trial.pl script overrides this default, so bot trials may still be done.$token
must be obtained from $api->gettoken
with the target file name passed as Title
. To specify the file contents, exactly one of the following options must be given:
Stash
was used), specify the returned file key here to complete the upload. SessionKey
is accepted as an alias for backwards compatability.Text
is not used.Comment
.move()
. The object contains the same properties as that returned by edittoken()
, plus the following:
$noredirect
parameter to move()
will be honored (i.e. the user has the 'suppressredirect' right).$totitle
.%param
must contain an "action" key, as well as any other keys needed for the action ("token" may be omitted).require AnomieBOT::API;
or use AnomieBOT::API;
.Copyright 2008–2013 Anomie
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.