Difference between revisions of "Quick start guide"

From Apibot
Jump to: navigation, search
Line 62: Line 62:
 
);
 
);
 
</pre>
 
</pre>
 +
 +
==See also==
 +
*[[Introduction]]

Revision as of 19:42, 28 April 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.

Files

helloworld.php

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

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

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

$bridge = new Bridge ( $mains );
$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,
  )
);

See also