Difference between revisions of "Quick start guide"

From Apibot
Jump to: navigation, search
m (Mains -> Core)
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
 
require_once ( dirname ( __FILE__ ) . '/settings.php' );
 
require_once ( dirname ( __FILE__ ) . '/settings.php' );
 
require_once ( dirname ( __FILE__ ) . '/logins.php' );
 
require_once ( dirname ( __FILE__ ) . '/logins.php' );
require_once ( dirname ( __FILE__ ) . '/common/mains/mains.php' );
+
require_once ( dirname ( __FILE__ ) . '/core/core.php' );
  
$mains = new Mains ( $logins['FooUser@foowiki.com'], $bot_settings );
+
$core = new Core ( $logins['FooUser@foowiki.com'], $bot_settings );
  
 
require_once ( dirname ( __FILE__ ) . '/bridge/bridge.php' );
 
require_once ( dirname ( __FILE__ ) . '/bridge/bridge.php' );
  
$bridge = new Bridge ( $mains );
+
$bridge = new Bridge ( $core );
 
$page = $bridge->fetch_editable( "Project:Sandbox" );
 
$page = $bridge->fetch_editable( "Project:Sandbox" );
 
$page->prepend( "Hello world (prepended)\n" );
 
$page->prepend( "Hello world (prepended)\n" );
Line 61: Line 61:
 
   )
 
   )
 
);
 
);
 +
</pre>
 +
 +
==Execution==
 +
From the Linux command line:
 +
 +
<pre>
 +
$ php helloworld.php
 +
+ [2014-05-02 04:16:13] Started, Apibot 0.40.6
 +
+ [2014-05-02 04:16:13] Cookie-identifying at FooWiki as FooUser
 +
- [2014-05-02 04:16:13] info: Fetching general info for FooWiki...
 +
- [2014-05-02 04:16:15] info: General info contains no revision - will fetch param info on new version!
 +
- [2014-05-02 04:16:15] info: General info contains no revision - will fetch user info on new version!
 +
+ [2014-05-02 04:16:25] Page [[Project:Sandbox]] was submitted.
 +
- [2014-05-02 04:16:25]  (result: Success, pageid: 733, title: Project:Sandbox, contentmodel: wikitext, oldrevid: 15663, newrevid: 15688, newtimestamp: 2014-05-02T04:16:24Z)
 +
+ [2014-05-02 04:16:25] Ended, Apibot 0.40.6
 
</pre>
 
</pre>
  
 
==See also==
 
==See also==
 
*[[Introduction]]
 
*[[Introduction]]

Latest revision as of 01:34, 10 November 2014

Here is some code to get you started with ApiBot. It will edit the page "Project:Sandbox" on FooWiki (foowiki.com), prepending "Hello world (prepended)" to the text, and using "This is the summary for the hello world edit" as the summary. To make it work with your wiki, replace all mentions of FooWiki with the name of your wiki; replace all mentions of foowiki.com with the url of your wiki; and replace all mentions of FooUser with the name of your bot user.

Files

helloworld.php

<?php
require_once ( dirname ( __FILE__ ) . '/settings.php' );
require_once ( dirname ( __FILE__ ) . '/logins.php' );
require_once ( dirname ( __FILE__ ) . '/core/core.php' );

$core = new Core ( $logins['FooUser@foowiki.com'], $bot_settings );

require_once ( dirname ( __FILE__ ) . '/bridge/bridge.php' );

$bridge = new Bridge ( $core );
$page = $bridge->fetch_editable( "Project:Sandbox" );
$page->prepend( "Hello world (prepended)\n" );
$summary = "This is the summary for the hello world edit";
$bridge->edit( $page, $summary );

logins.php

<?php
$foowiki = array (
    'name'     => 'FooWiki',
    'urls'  => array(
        'api' => 'http://foowiki.com/w/api.php'
    ),
    'retries'  => array (
    'link_error' => 10,
    'bad_login'  => 3,
  ),
  'interval' => array (
    'link_error' => 10,
    'submit'     => 5,
  ),
  'limits' => array (
    'DL'    => NULL,  // max speed limits for this wiki, in bytes / sec; NULL - no limit
    'UL'    => NULL,
    'total' => NULL,
  ),
/*
  'http-auth' => array (  // HTTP transfer user and password, NOT wiki ones! if you don't know what these are, leave this commented out.
    'user' => "my_http_username",
    'pass' => "my_http_password",
  ),
*/
);

$logins = array (
  'FooUser@foowiki.com' => array (
    'user'            => 'FooUser',
    'password'        => "password",
    'domain'          => NULL,
    'remember_login'  => false,
    'mark_bot'        => false,
    'move_noredirect' => NULL,
    'move_withtalk'   => true,
    'wiki'            => $foowiki,
  )
);

Execution

From the Linux command line:

$ php helloworld.php
+ [2014-05-02 04:16:13] Started, Apibot 0.40.6
+ [2014-05-02 04:16:13] Cookie-identifying at FooWiki as FooUser
- [2014-05-02 04:16:13] info: Fetching general info for FooWiki...
- [2014-05-02 04:16:15] info: General info contains no revision - will fetch param info on new version!
- [2014-05-02 04:16:15] info: General info contains no revision - will fetch user info on new version!
+ [2014-05-02 04:16:25] Page [[Project:Sandbox]] was submitted.
- [2014-05-02 04:16:25]   (result: Success, pageid: 733, title: Project:Sandbox, contentmodel: wikitext, oldrevid: 15663, newrevid: 15688, newtimestamp: 2014-05-02T04:16:24Z)
+ [2014-05-02 04:16:25] Ended, Apibot 0.40.6

See also