Bruger:JoenBot
Eksperimenterende semi automatisk robot til automatisering af kedelige ting. Styret at Joen. Tester ting på Bruger:JoenBot/Sandkasse.
SxWiki is a simple, set of functions written in PHP, that are useful for bots. It requires libcurl (see: http://php.net/curl).
- Developed by:
- License: GPL
- Source code
Indhold
Config variables
- int $maxlag, maxlag setting
- string $url, the base url to api.php and index.php (for example, on the english wikipedia, it is
- int $epm, limits edits per min.
sxLogin()
array sxLogin(string $username, string $password)
Returns an array containing uid (your numerical userid), and token (your login token).
sxGetPage()
string sxGetPage(string $article)
Returns raw article source.
sxGetURL()
string sxGetURL(string $url)
Returns the raw HTML at the specified URL. Useful for retrieving arbitrary pages (lists, diffs, etc) as an authenticated Wikipedia user.
sxPutPage()
bool sxPutPage(string $article, string $editsummary, string $newpage, int $minoredit, int $botedit)
If $minoredit is set to null, the edit will not be marked as minor. Any other setting will mark it as minor.
if $botedit is set to null, the edit will be made with &bot=0.
Returns true if the edit succeeded, false if it did not (presently only detects maxlag).
sxGetCat()
array sxGetCat(string $category, string $namespace)
$namespace is specified in numeric form (as a string, however!). See: Help:Namespace. $namespace may also be set to "all", to return everything.
Returns all subcategories or category members like so: (result for Category:Ohio law)
Array ( [0] => Capital punishment in Ohio [1] => Great Lakes Commission [2] => Category:Jurists from Cincinnati [3] => Ohio Constitution [4] => Ohio Revised Code [5] => Ohio State Issue 1 (2004) [6] => Category:Ohio state case law [7] => Category:Ohio state courts )
sxGetTransclusion()
array sxGetTransclusion(string $template, string $namespace)
$namespace is specified in numeric form (as a string, however!). See: Help:Namespace. $namespace may also be set to "all", to return everything.
Returns an array of all pages that the given template transcludes to. Supports all namespaces, not just template, for instance:
<source lang="php"> <? include('SxWiki.php'); include('config.php');
$test = sxGetTransclusion("User:SQL/Talkheader", "all");
print_r($test);
?> </source>
Would return:
Array ( [0] => User talk:SQL )
sxGetPrefix()
array sxGetPrefix(string $prefix)
Returns an array of pages matching the specified prefix.
sxLastEdited()
array sxLastEdited(string $article)
Returns the last user to edit $article, and, the last edit summary.
- [user] User name
- [editsum] Edit Summary
setEPM()
int setEPM(int $edits_per_min)
Lazy way to set $epm, just divides 60 by $edits_per_min.
sxBlockUser()
bool sxBlockUser(string $user, string $expiry, string $reason, mixed $ao, mixed $acb, mixed $autoblock, mixed $emailban)
Set a block. $ao, $acb, $autoblock, $emailban should be set to $null to disable these options.
- $ao - Anonymous only
- $acb - Account Creation Blocked
- $autoblock - Enable autoblock
- $emailban - E-mail disabled
Example:
<source lang="php"> sxBlockUser("SQLBotTestTarget", "1 second", "Test of block framework using SxWiki", $null, $null, $null, $null); </source>
Would result in:
08:52, January 7, 2008 SQL (Talk | contribs | block) blocked "SQLBotTestTarget (Talk | contribs)" (autoblock disabled) with an expiry time of 1 second (: Test of block framework using SxWiki) (Unblock)
sxUnBlockUser()
bool sxUnBlockUser(string $user, string $reason)
Removes blocks, on either users or IP's.
sxModRollback()
bool sxModRollback(string $user, string $reason string $operation)
Adds or removes rollback. $operation can be "add" or "del". Returns false if it fails, true if failure is not detected.
sxIsBlocked()
bool sxIsBlocked(string $user)
Detects if the specified user is presently blocked. Returns true if user is blocked, false if they are not.
Example application
<?php include("SxWiki.php"); //Include framework $url = 'http://en.wikipedia.org/w/'; //Set for the English Wikipedia $sxLgTA = sxLogin("Username", "Password"); //Log in $sxLgID = $sxLgTA[uid]; $sxLgT = $sxLgTA[token]; $maxlag = "5"; //Set maxlag to 5 $epm = setEPM(10); //set 10 edits per min.
$foocat = sxGetCat('FooBar', "0"); //Get Category:FooBar, items in NS 0
foreach($foocat as $singlefoo) { //Replace all instances of "foo" with "bar" in Category:FooBar
$oldpage = sxGetPage($singlefoo); //First we get the old version of this page $newpage = preg_replace('/\bfoo\b/i', 'bar', $oldpage); //Here, we replace all instances of "foo" with "bar" sxPutPage($singlefoo, 'Example application using SxWiki', $newpage, null); //Save the page
}
?>