User:Syed/Sandbox

From Wikipedia, the free encyclopedia

Navigate Around My Humble Adobe (in style)

Main | Introduction | My Picture Gallery | My Userboxes | My Sandbox | My Talk Page

x 2 3 7 12 27
y 4 8 9 16 23

In the following table, find the following summation:

\sum y^2

Bonus, not in the table find:
\sum_{i=3}^7 2^i


Answer:
\sum y^2 = 4^2 + 8^2 + 9^2 + 16^2 + 23^2

\sum_{i=3}^7 2^i = 2^3 + 2^4 + 2^5 + 2^6 + 2^7


Contents

[edit] Documentation

SxWiki is a simple, set of functions written in PHP, that are useful for bots. It requires libcurl (see: http://php.net/curl).

[edit] 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

http://en.wikipedia.org/w/ )

  • int $epm, limits edits per min.

[edit] sxLogin()

array sxLogin(string $username, string $password)

Returns an array containing uid (your numerical userid), and token (your login token).

[edit] sxGetPage()

string sxGetPage(string $article)

Returns raw article source.

[edit] 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.

[edit] 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).

[edit] 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
)

[edit] 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:

<?
include('SxWiki.php');
include('config.php');
 
$test = sxGetTransclusion("User:SQL/Talkheader", "all");
 
print_r($test);
 
?>

Would return:

Array
(
    [0] => User talk:SQL
)

[edit] sxGetPrefix()

array sxGetPrefix(string $prefix)

Returns an array of pages matching the specified prefix.

[edit] sxLastEdited()

array sxLastEdited(string $article)

Returns the last user to edit $article, and, the last edit summary.

  • [user] User name
  • [editsum] Edit Summary

[edit] setEPM()

int setEPM(int $edits_per_min)

Lazy way to set $epm, just divides 60 by $edits_per_min.

[edit] 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:

sxBlockUser("SQLBotTestTarget", "1 second", "Test of block framework using [[User:SQL/SxWiki|SxWiki]]", $null, $null, 
$null, $null);

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)

[edit] sxUnBlockUser()

bool sxUnBlockUser(string $user, string $reason)

Removes blocks, on either users or IP's.

[edit] 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.

[edit] sxIsBlocked()

bool sxIsBlocked(string $user)

Detects if the specified user is presently blocked. Returns true if user is blocked, false if they are not.

[edit] 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

}


?>