\Wiki

This class is interacts with the Wiki using api.php.

Summary

Methods
Properties
Constants
__construct()
__set()
setUserAgent()
setHttpHeader()
useDefaultHttpHeader()
query()
getpage()
getpageid()
categorymembers()
subpages()
login()
setLogin()
nobots()
getedittoken()
edit()
getfilelocation()
getfileuploader()
findstring()
replacestring()
gettemplate()
$url
$echoRet
$url
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$http
$token
$ecTimestamp
N/A

Properties

$url

$url : 

Type

$echoRet

$echoRet : 

Type

$url

$url : string

The Project URL (API path).

Type

string

$http

$http : 

Type

$token

$token : 

Type

$ecTimestamp

$ecTimestamp : 

Type

Methods

__construct()

__construct(  $url = 'https://commons.wikimedia.org/w/api.php',   $hu = null,   $hp = null) : void

This is the constructor.

Parameters

$url

The project and API URL

$hu
$hp

__set()

__set(  $var,   $val) : void

The set.

Parameters

$var
$val

setUserAgent()

setUserAgent(  $userAgent) 

Set/change the user agent.

Parameters

$userAgent

The user agent string.

setHttpHeader()

setHttpHeader(  $httpHeader) 

Set/change the http header.

Parameters

$httpHeader

The http header.

useDefaultHttpHeader()

useDefaultHttpHeader() 

Set/change the http headers.

query()

query(  $query,   $post = null,   $repeat = null,   $url = null) : mixed

Sends a query to the API.

Parameters

$query

The query string.

$post

POST data if its a post request (optional).

$repeat

How many times the request will be repeated.

$url

The URL where we want to work (for external services API).

Returns

mixed —

The response from server (API result).

getpage()

getpage(  $page,   $revid = null,   $detectEditConflict = false) : string

Gets the content of a page. Returns false on error.

Use getPageContents() as alternative to get the page in multiple formats

Parameters

$page

The wikipedia page to fetch.

$revid

The revision id to fetch (optional).

$detectEditConflict

Returns

string —

The wikitext for the given page.

getpageid()

getpageid(  $page) : string

Gets the ID for a page.

Parameters

$page

The wikipedia page to get the id for.

Returns

string —

The page ID.

categorymembers()

categorymembers(  $category,   $limit = 10,   $continue = null,   $subcat = false) : array

Returns an array with all the members of $category

Parameters

$category

The category to use.

$limit

The maximum members returned (10 by default)

$continue

The parameters to continue previous query

$subcat

(bool) Go into sub categories?

Returns

array —

The category ID.

subpages()

subpages(  $page) : array

Returns an array with all the subpages of $page.

Parameters

$page

Returns

array —

The subpages list.

login()

login(  $user,   $pass) : array

This function takes a username and password and logs you into Wiki.

Parameters

$user

Username to login as.

$pass

Password that corrisponds to the username.

Returns

array —

The API result

setLogin()

setLogin(  $data) : void

crappy hack to allow users to use cookies from old sessions.

Parameters

$data

The data to be parsed.

nobots()

nobots(  $page,   $user = null,   $text = null) : boolean

Check if we're allowed to edit $page.

See http://en.wikipedia.org/wiki/Template:Bots for more info.

Parameters

$page

The page we want to edit.

$user

The bot's username.

$text

Returns

boolean

getedittoken()

getedittoken() : string

This function returns the edit token for the current user.

Returns

string —

The edit token.

edit()

edit(  $page,   $data,   $summary = '',   $minor = false,   $bot = true,   $section = null,   $detectEC = false,   $maxlag = '') : array

Edits a page.

Parameters

$page

Page name to edit.

$data

Data to post to page.

$summary

Edit summary to use.

$minor

Whether or not to mark edit as minor. (Default false)

$bot

Whether or not to mark edit as a bot edit. (Default true)

$section
$detectEC
$maxlag

Returns

array —

The API result

getfilelocation()

getfilelocation(  $page) : string

BMcN 2012-09-16 Retrieve a media file's actual location.

Parameters

$page

The "File:" page on the wiki which the URL of is desired.

Returns

string —

The URL pointing directly to the media file (Eg http://upload.mediawiki.org/wikipedia/en/1/1/Example.jpg)

getfileuploader()

getfileuploader(  $page) : string

BMcN 2012-09-16 Retrieve a media file's uploader.

Parameters

$page

The "File:" page

Returns

string —

The user who uploaded the topmost version of the file.

findstring()

findstring(  $page,   $string) : boolean

Find a string

Parameters

$page

The page we're working with.

$string

The string that you want to find.

Returns

boolean —

Value (1 found and 0 not-found)

replacestring()

replacestring(  $page,   $string,   $newstring,   $regex = false) : string

Replace a string

Parameters

$page

The page we're working with.

$string

The string that you want to replace. (it can be a string or an array

$newstring

The string that will replace the present string. (same as above)

$regex

If $string will be considered as a regular expression

Returns

string —

The new text of page

gettemplate()

gettemplate(  $page,   $template) : string

Get a template from a page

Parameters

$page

The page we're working with

$template

The name of the template we are looking for

Returns

string —

The searched (NULL if the template has not been found)