User:ClueBot II/ClueBot Script

From Wikipedia, the free encyclopedia

Shortcut:
WP:CBS

ClueBot Script is a trivial scripting language designed specifically for very basic Wikipedia bot tasks.

Contents

[edit] Syntax

The syntax is very similar to that of PHP. Each statement must end in a semicolon (";"). Conditionals are grouped in parenthesis ("()"). Groups of statements are grouped in braces ("{}"). Variables are prefixed with a percent sign ("%"). Functions are prefixed with a dollar sign ("$").

[edit] Statements

[edit] if

[edit] Syntax

if conditional statement

[edit] Description

Executes statement if conditional is satisfied.

[edit] while

[edit] Syntax

while conditional statement

[edit] Description

Execute statement until conditional is no longer satisfied.

[edit] foreach

[edit] Syntax

foreach list delimiter %value statement

[edit] Description

For each item in the list, list, delimited by the delimiter, delimiter, set %value to the value of the current item and execute statement.

[edit] eval

[edit] Syntax

eval ClueBot Script

[edit] Description

Evaluate the string ClueBot Script as ClueBot Script.

[edit] set

[edit] Syntax

set %variable conditional/value

[edit] Description

Sets %variable to the value of conditional/value.

[edit] unset

[edit] Syntax

unset %variable

[edit] Description

Unsets %variable.

[edit] varappend

[edit] Syntax

varappend %variable data

[edit] Description

Append the data, data, to the end of %variable.

[edit] varprepend

[edit] Syntax

varprepend %variable data

[edit] Description

Prepend the data, data, to the end of %variable.

[edit] pagereplace

[edit] Syntax

pagereplace1 page search replace

[edit] Description

Replaces all instances of the string search, with the string replace, on the page page.

[edit] pagepregreplace

[edit] Syntax

pagepregreplace1 page search replace

[edit] Description

Replaces all instances of the regular expression search with the regular expression replace string replace on the page page.

[edit] pageprepend

[edit] Syntax

pageprepend1 page data

[edit] Description

Prepends the data data to the beginning of the page page.

[edit] pageappend

[edit] Syntax

pageappend1 page data

[edit] Description

Appends the data data to the end of the page page.

[edit] pageset

[edit] Syntax

pageset1 page data

[edit] Description

Sets the content of the page page to the data data.

[edit] pageget

[edit] Syntax

pageget page %data

[edit] Description

Retrieves the page page into the variable %data.

[edit] getrecentchanges

[edit] Syntax

getrecentchanges %data delimiter count

[edit] Description

Retrieves the names of the pages in the count most recent changes into the variable %data, delimited by the string delimiter. The count parameter is optional and defaults to 10.

[edit] getcategorymembers

[edit] Syntax

getcategorymembers %data delimiter category count start

[edit] Description

Retrieves count page names in the category category beginning with start into the variable %data. The count parameter is optional and defaults to 500. The start parameter is optional and defaults to the first page in the category.

[edit] getbacklinks

[edit] Syntax

getbacklinks %data delimiter page count %continue

[edit] Description

Retrieves the pages that link to page into the variable %data. The count parameter is optional. The %continue parameter is optional, but if provided will determine where to continue, when the statement finishes, %continue will be filled with where it left off, so pass it back to continue where it left off.

[edit] getembeddedin

[edit] Syntax

getembeddedin %data delimiter page count %continue

[edit] Description

Retrieves the pages that transclude page into the variable %data. The count parameter is optional. The %continue parameter is optional, but if provided will determine where to continue, when the statement finishes, %continue will be filled with where it left off, so pass it back to continue where it left off.

[edit] getmodifiedtime

[edit] Syntax

getmodifiedtime %time page

[edit] Description

Retrieves the last modified unix timestamp of page into %time.

[edit] Functions

[edit] cat/+

[edit] Syntax

$cat(string1,string2,string3,...)

[edit] Description

Returns the input strings concatenated. + is an alias for cat.

[edit] substr/mid

[edit] Syntax

$substr(string,start)
$substr(string,start,length)

[edit] Description

Returns a part of string. If length is omitted, it returns string starting from start to the end of string, otherwise, it returns length characters, starting from start. This function works exactly like PHP's substr] function. mid is an alias for substr.

[edit] gettok/settok/addtok/deltok

[edit] Syntax

$gettok(list,delimiter,id)
$settok(list,delimiter,id,data)
$addtok(list,delimiter,data)
$deltok(list,delimiter,id)

[edit] Description

Id starts at 1. List is a delimited list. Delimiter is the delimiter of the list. Gettok returns the idth item in the list, unless id is 0, then it returns the number of items in the list. Settok sets an item in the list, overwriting the previous value (if necessary). Addtok adds an item to the end of the list. Deltok removes the idth item from the list.

[edit] strpos/stripos

[edit] Syntax

$strpos(haystack,needle)
$strpos(haystack,needle,offset)
$stripos(haystack,needle)
$stripos(haystack,needle,offset)

[edit] Description

Returns the numeric position of the first occurrence (or the offset occurrence, if offset is given) of needle in the haystack string. strpos and stripos are the same except stripos is case insensitive.

[edit] replace

[edit] Syntax

$replace(data,search1,replace1,search2,replace2,...,...,searchN,replaceN)

[edit] Description

Replace each occurrence of search with replace. Multiple search/replace pairs may be given at one time.

[edit] pregreplace

[edit] Syntax

$pregreplace(data,searchregex,replaceregex)

[edit] Description

Performs regular expression search/replace on data. searchregex is the pattern to match and replaceregex is what to replace it with.

[edit] time

[edit] Syntax

$time(0)

[edit] Description

Returns the unix timestamp.

[edit] Examples

set %page "User:ClueBot II/Sandbox"; 
set %data "{{db-user}}"; 
set %reason "And now we mark it for deletion. (bot)";
pageset %page %data %reason;
getcategorymembers %cm "\n" "Wikipedia bots";
set %output "";
foreach %cm "\n" %page {
        if ($mid(%page,0,5) == 'User:') {
                varappend %output $cat("\n* [[",%page,"|",$mid(%page,5),"]]");
        }
}
pageappend "Wikipedia:Sandbox" $cat("\n\nHere is a list of the bots on the first page of [[:Category:Wikipedia bots]]:",%output) "Adding list of bots.";

[edit] See also

The CBS interpreter.

[edit] Footnotes

  • Note 1: This command has an optional parameter editsummary which can be used to set an edit summary. Otherwise, one is automatically generated.