User:DustyBot/Library

Dusty Library provides a set of functions you can use to write your own bot in PHP. The benefits of including this library are its simplicity, functionality, and compatibility. Care has been taken to avoid dependencies on PHP extensions. The library also attempts to emulate the standard PHP function set, as opposed to creating a new framework. It is also intended to be compatible with PHP 4, though this has not been tested. Bots using this library have been run successfully on both EN and Commons.

To download Dusty Library, go to User:DustyBot/dustylib.php, view the page source, and then copy it to disk, avoiding the source tags.

Function reference

Function-level documentation is included in the source file.

Template parsing

wp_parse_template($text)
wptmpl_create($title)
wptmpl_set_arg(&$tmpl, $param, $val)
wptmpl_unset_arg(&$tmpl, $param)
wptmpl_get_arg($tmpl, $param)
wptmpl_has_arg($tmpl, $param)
wptmpl_set_title(&$tmpl, $title)
wp_build_template($tmpl)
wp_find_template($title, $text, $ignore_case = false)

Page editing

wp_page_allows_bot($text, $context = null, $messages = null)
wp_get_edit_token($title, $context)
wp_edit_page($title, $content, $summary, $edtoken, $context, $timestamp = null)

Query

wp_get($title, $context = null, &$timestamp = null)
wp_get_multiple($titles, $context = null, &$timestamps = null)
wp_locate_files($files, $context)
wp_get_category_members($category, $context = null)

Session management

wp_create_context($maxlag = null, $bot = false, $api_url = null)
wp_context_set_query_limit($limit, &$context)
wp_login($username, $password, &$context)
wp_logout($context)

Other

wp_post($post, $context = null)

Example

This basic example overwrites your user page with a list of all the pages in Category:Space colonization. You'll have to supply your own username and password.

include "dustylib.php";

$context = wp_create_context(5);
/* Set the limit for the number of items listed in each query
 * This is only an optimization, the # of pages from get_cat_members is unchanged */
wp_context_set_query_limit(50, $context);

wp_login($username, $password, $context);

$title = "User:".$username;
$last_timestamp = null;
/* Get the timestamp of the last revision to avoid edit conflicts */
$old_page = wp_get($title, $context, $last_timestamp);

/* Check for bot exclusion */
if (!wp_page_allows_bot($old_page, $context)) {
    wp_logout($context);
    exit();
}

/* Get the list of members */
$members = wp_get_category_members("Space colonization", $context);

/* Create the new page contents */
$page = "";
foreach ($members as $title)
    $page .= "* [[".$title."]]\n";

/* Upload it */
$edtoken = wp_get_edit_token($title, $context);
wp_edit_page($title, $page, "List of interesting pages", $edtoken, $context, $last_timestamp);

wp_logout($context);

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.