You've already forked joomla_test
first commit
This commit is contained in:
238
libraries/joomla/mediawiki/categories.php
Normal file
238
libraries/joomla/mediawiki/categories.php
Normal file
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API Categories class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiCategories extends JMediawikiObject
|
||||
{
|
||||
/**
|
||||
* Method to list all categories the page(s) belong to.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve categories.
|
||||
* @param array $clprop List of additional properties to get.
|
||||
* @param array $clshow Type of categories to show.
|
||||
* @param integer $cllimit Number of categories to return.
|
||||
* @param boolean $clcontinue Continue when more results are available.
|
||||
* @param array $clcategories Only list these categories.
|
||||
* @param string $cldir Direction of listing.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function getCategories(array $titles, array $clprop = null, array $clshow = null, $cllimit = null, $clcontinue = false,
|
||||
array $clcategories = null, $cldir = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=categories';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($clprop))
|
||||
{
|
||||
$path .= '&clprop=' . $this->buildParameter($clprop);
|
||||
}
|
||||
|
||||
if (isset($clshow))
|
||||
{
|
||||
$path .= '&$clshow=' . $this->buildParameter($clshow);
|
||||
}
|
||||
|
||||
if (isset($cllimit))
|
||||
{
|
||||
$path .= '&cllimit=' . $cllimit;
|
||||
}
|
||||
|
||||
if ($clcontinue)
|
||||
{
|
||||
$path .= '&clcontinue=';
|
||||
}
|
||||
|
||||
if (isset($clcategories))
|
||||
{
|
||||
$path .= '&clcategories=' . $this->buildParameter($clcategories);
|
||||
}
|
||||
|
||||
if (isset($cldir))
|
||||
{
|
||||
$path .= '&cldir=' . $cldir;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get information about all categories used.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve categories.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getCategoriesUsed(array $titles)
|
||||
{
|
||||
// Build the request
|
||||
$path = '?action=query&generator=categories&prop=info';
|
||||
|
||||
// Append titles to the request
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get information about the given categories.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve categories.
|
||||
* @param boolean $clcontinue Continue when more results are available.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getCategoriesInfo(array $titles, $clcontinue = false)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=categoryinfo';
|
||||
|
||||
// Append titles to the request
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if ($clcontinue)
|
||||
{
|
||||
$path .= '&clcontinue=';
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to enumerate all categories.
|
||||
*
|
||||
* @param string $acfrom The category to start enumerating from.
|
||||
* @param string $acto The category to stop enumerating at.
|
||||
* @param string $acprefix Search for all category titles that begin with this value.
|
||||
* @param string $acdir Direction to sort in.
|
||||
* @param integer $acmin Minimum number of category members.
|
||||
* @param integer $acmax Maximum number of category members.
|
||||
* @param integer $aclimit How many categories to return.
|
||||
* @param array $acprop Which properties to get.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function enumerateCategories($acfrom = null, $acto = null, $acprefix = null, $acdir = null, $acmin = null,
|
||||
$acmax = null, $aclimit = null, array $acprop = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=allcategories';
|
||||
|
||||
if (isset($acfrom))
|
||||
{
|
||||
$path .= '&acfrom=' . $acfrom;
|
||||
}
|
||||
|
||||
if (isset($acto))
|
||||
{
|
||||
$path .= '&acto=' . $acto;
|
||||
}
|
||||
|
||||
if (isset($acprefix))
|
||||
{
|
||||
$path .= '&acprefix=' . $acprefix;
|
||||
}
|
||||
|
||||
if (isset($acdir))
|
||||
{
|
||||
$path .= '&acdir=' . $acdir;
|
||||
}
|
||||
|
||||
if (isset($acfrom))
|
||||
{
|
||||
$path .= '&acfrom=' . $acfrom;
|
||||
}
|
||||
|
||||
if (isset($acmin))
|
||||
{
|
||||
$path .= '&acmin=' . $acmin;
|
||||
}
|
||||
|
||||
if (isset($acmax))
|
||||
{
|
||||
$path .= '&acmax=' . $acmax;
|
||||
}
|
||||
|
||||
if (isset($aclimit))
|
||||
{
|
||||
$path .= '&aclimit=' . $aclimit;
|
||||
}
|
||||
|
||||
if (isset($acprop))
|
||||
{
|
||||
$path .= '&acprop=' . $this->buildParameter($acprop);
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to list change tags.
|
||||
*
|
||||
* @param array $tgprop List of properties to get.
|
||||
* @param string $tglimit The maximum number of tags to limit.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getChangeTags(array $tgprop = null, $tglimit = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=tags';
|
||||
|
||||
if (isset($tgprop))
|
||||
{
|
||||
$path .= '&tgprop=' . $this->buildParameter($tgprop);
|
||||
}
|
||||
|
||||
if (isset($tglimit))
|
||||
{
|
||||
$path .= '&tglimit=' . $tglimit;
|
||||
}
|
||||
|
||||
// @TODO add support for $tgcontinue
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
}
|
94
libraries/joomla/mediawiki/http.php
Normal file
94
libraries/joomla/mediawiki/http.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* HTTP client class for connecting to a MediaWiki instance.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiHttp extends JHttp
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Client options object.
|
||||
* @param JHttpTransport $transport The HTTP transport object.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JHttpTransport $transport = null)
|
||||
{
|
||||
// Override the JHttp contructor to use JHttpTransportStream.
|
||||
$this->options = isset($options) ? $options : new JRegistry;
|
||||
$this->transport = isset($transport) ? $transport : new JHttpTransportStream($this->options);
|
||||
|
||||
// Make sure the user agent string is defined.
|
||||
$this->options->def('api.useragent', 'JMediawiki/1.0');
|
||||
|
||||
// Set the default timeout to 120 seconds.
|
||||
$this->options->def('api.timeout', 120);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to send the GET command to the server.
|
||||
*
|
||||
* @param string $url Path to the resource.
|
||||
* @param array $headers An array of name-value pairs to include in the header of the request.
|
||||
*
|
||||
* @return JHttpResponse
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function get($url, array $headers = null)
|
||||
{
|
||||
// Look for headers set in the options.
|
||||
$temp = (array) $this->options->get('headers');
|
||||
|
||||
foreach ($temp as $key => $val)
|
||||
{
|
||||
if (!isset($headers[$key]))
|
||||
{
|
||||
$headers[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->transport->request('GET', new JUri($url), null, $headers, $this->options->get('api.timeout'), $this->options->get('api.useragent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to send the POST command to the server.
|
||||
*
|
||||
* @param string $url Path to the resource.
|
||||
* @param mixed $data Either an associative array or a string to be sent with the request.
|
||||
* @param array $headers An array of name-value pairs to include in the header of the request.
|
||||
*
|
||||
* @return JHttpResponse
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function post($url, $data, array $headers = null)
|
||||
{
|
||||
// Look for headers set in the options.
|
||||
$temp = (array) $this->options->get('headers');
|
||||
|
||||
foreach ($temp as $key => $val)
|
||||
{
|
||||
if (!isset($headers[$key]))
|
||||
{
|
||||
$headers[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->transport->request('POST', new JUri($url), $data, $headers, $this->options->get('api.timeout'), $this->options->get('api.useragent'));
|
||||
}
|
||||
}
|
250
libraries/joomla/mediawiki/images.php
Normal file
250
libraries/joomla/mediawiki/images.php
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API Images class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiImages extends JMediawikiObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Method to get all images contained on the given page(s).
|
||||
*
|
||||
* @param array $titles Page titles to retrieve images.
|
||||
* @param integer $imagelimit How many images to return.
|
||||
* @param boolean $imagecontinue When more results are available, use this to continue.
|
||||
* @param integer $imimages Only list these images.
|
||||
* @param string $imdir The direction in which to list.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getImages(array $titles, $imagelimit = null, $imagecontinue = null, $imimages = null, $imdir = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=images';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($imagelimit))
|
||||
{
|
||||
$path .= '&imagelimit=' . $imagelimit;
|
||||
}
|
||||
|
||||
if ($imagecontinue)
|
||||
{
|
||||
$path .= '&imagecontinue=';
|
||||
}
|
||||
|
||||
if (isset($imimages))
|
||||
{
|
||||
$path .= '&imimages=' . $imimages;
|
||||
}
|
||||
|
||||
if (isset($imdir))
|
||||
{
|
||||
$path .= '&imdir=' . $imdir;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all images contained on the given page(s).
|
||||
*
|
||||
* @param array $titles Page titles to retrieve links.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getImagesUsed(array $titles)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&generator=images&prop=info';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all image information and upload history.
|
||||
*
|
||||
* @param array $liprop What image information to get.
|
||||
* @param integer $lilimit How many image revisions to return.
|
||||
* @param string $listart Timestamp to start listing from.
|
||||
* @param string $liend Timestamp to stop listing at.
|
||||
* @param integer $liurlwidth URL to an image scaled to this width will be returned..
|
||||
* @param integer $liurlheight URL to an image scaled to this height will be returned.
|
||||
* @param string $limetadataversion Version of metadata to use.
|
||||
* @param string $liurlparam A handler specific parameter string.
|
||||
* @param boolean $licontinue When more results are available, use this to continue.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getImageInfo(array $liprop = null, $lilimit = null, $listart = null, $liend = null, $liurlwidth = null,
|
||||
$liurlheight = null, $limetadataversion = null, $liurlparam = null, $licontinue = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=imageinfo';
|
||||
|
||||
if (isset($liprop))
|
||||
{
|
||||
$path .= '&liprop=' . $this->buildParameter($liprop);
|
||||
}
|
||||
|
||||
if (isset($lilimit))
|
||||
{
|
||||
$path .= '&lilimit=' . $lilimit;
|
||||
}
|
||||
|
||||
if (isset($listart))
|
||||
{
|
||||
$path .= '&listart=' . $listart;
|
||||
}
|
||||
|
||||
if (isset($liend))
|
||||
{
|
||||
$path .= '&liend=' . $liend;
|
||||
}
|
||||
|
||||
if (isset($liurlwidth))
|
||||
{
|
||||
$path .= '&liurlwidth=' . $liurlwidth;
|
||||
}
|
||||
|
||||
if (isset($liurlheight))
|
||||
{
|
||||
$path .= '&liurlheight=' . $liurlheight;
|
||||
}
|
||||
|
||||
if (isset($limetadataversion))
|
||||
{
|
||||
$path .= '&limetadataversion=' . $limetadataversion;
|
||||
}
|
||||
|
||||
if (isset($liurlparam))
|
||||
{
|
||||
$path .= '&liurlparam=' . $liurlparam;
|
||||
}
|
||||
|
||||
if ($licontinue)
|
||||
{
|
||||
$path .= '&alcontinue=';
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to enumerate all images.
|
||||
*
|
||||
* @param string $aifrom The image title to start enumerating from.
|
||||
* @param string $aito The image title to stop enumerating at.
|
||||
* @param string $aiprefix Search for all image titles that begin with this value.
|
||||
* @param integer $aiminsize Limit to images with at least this many bytes.
|
||||
* @param integer $aimaxsize Limit to images with at most this many bytes.
|
||||
* @param integer $ailimit How many images in total to return.
|
||||
* @param string $aidir The direction in which to list.
|
||||
* @param string $aisha1 SHA1 hash of image.
|
||||
* @param string $aisha1base36 SHA1 hash of image in base 36.
|
||||
* @param array $aiprop What image information to get.
|
||||
* @param string $aimime What MIME type to search for.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function enumerateImages($aifrom = null, $aito = null, $aiprefix = null, $aiminsize = null, $aimaxsize = null, $ailimit = null,
|
||||
$aidir = null, $aisha1 = null, $aisha1base36 = null, array $aiprop = null, $aimime = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=allimages';
|
||||
|
||||
if (isset($aifrom))
|
||||
{
|
||||
$path .= '&aifrom=' . $aifrom;
|
||||
}
|
||||
|
||||
if (isset($aito))
|
||||
{
|
||||
$path .= '&aito=' . $aito;
|
||||
}
|
||||
|
||||
if (isset($aiprefix))
|
||||
{
|
||||
$path .= '&aiprefix=' . $aiprefix;
|
||||
}
|
||||
|
||||
if (isset($aiminsize))
|
||||
{
|
||||
$path .= '&aiminsize=' . $aiminsize;
|
||||
}
|
||||
|
||||
if (isset($aimaxsize))
|
||||
{
|
||||
$path .= '&aimaxsize=' . $aimaxsize;
|
||||
}
|
||||
|
||||
if (isset($ailimit))
|
||||
{
|
||||
$path .= '&ailimit=' . $ailimit;
|
||||
}
|
||||
|
||||
if (isset($aidir))
|
||||
{
|
||||
$path .= '&aidir=' . $aidir;
|
||||
}
|
||||
if (isset($aisha1))
|
||||
{
|
||||
$path .= '&aisha1=' . $aisha1;
|
||||
}
|
||||
|
||||
if (isset($aisha1base36))
|
||||
{
|
||||
$path .= '&$aisha1base36=' . $aisha1base36;
|
||||
}
|
||||
|
||||
if (isset($aiprop))
|
||||
{
|
||||
$path .= '&aiprop=' . $this->buildParameter($aiprop);
|
||||
}
|
||||
|
||||
if (isset($aimime))
|
||||
{
|
||||
$path .= '&aimime=' . $aimime;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
}
|
1
libraries/joomla/mediawiki/index.html
Normal file
1
libraries/joomla/mediawiki/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
330
libraries/joomla/mediawiki/links.php
Normal file
330
libraries/joomla/mediawiki/links.php
Normal file
@ -0,0 +1,330 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API Links class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiLinks extends JMediawikiObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Method to return all links from the given page(s).
|
||||
*
|
||||
* @param array $titles Page titles to retrieve links.
|
||||
* @param array $plnamespace Namespaces to get links.
|
||||
* @param string $pllimit Number of links to return.
|
||||
* @param string $plcontinue Continue when more results are available.
|
||||
* @param array $pltitles List links to these titles.
|
||||
* @param string $pldir Direction of listing.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getLinks(array $titles, array $plnamespace = null, $pllimit = null, $plcontinue = null, array $pltitles = null, $pldir = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=links';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($plnamespace))
|
||||
{
|
||||
$path .= '&plnamespace=' . $this->buildParameter($plnamespace);
|
||||
}
|
||||
|
||||
if (isset($pllimit))
|
||||
{
|
||||
$path .= '&pllimit=' . $pllimit;
|
||||
}
|
||||
|
||||
if (isset($plcontinue))
|
||||
{
|
||||
$path .= '&plcontinue=' . $plcontinue;
|
||||
}
|
||||
|
||||
if (isset($pltitles))
|
||||
{
|
||||
$path .= '&pltitles=' . $this->buildParameter($pltitles);
|
||||
}
|
||||
|
||||
if (isset($pldir))
|
||||
{
|
||||
$path .= '&pldir=' . $pldir;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to return info about the link pages.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve links.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getLinksUsed(array $titles)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&generator=links&prop=info';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to return all interwiki links from the given page(s).
|
||||
*
|
||||
* @param array $titles Page titles to retrieve links.
|
||||
* @param boolean $iwurl Whether to get the full url.
|
||||
* @param integer $iwlimit Number of interwiki links to return.
|
||||
* @param boolean $iwcontinue When more results are available, use this to continue.
|
||||
* @param string $iwprefix Prefix for the interwiki.
|
||||
* @param string $iwtitle Interwiki link to search for.
|
||||
* @param string $iwdir The direction in which to list.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getIWLinks(array $titles, $iwurl = false, $iwlimit = null, $iwcontinue = false, $iwprefix = null, $iwtitle = null, $iwdir = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=links';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if ($iwurl)
|
||||
{
|
||||
$path .= '&iwurl=';
|
||||
}
|
||||
|
||||
if (isset($iwlimit))
|
||||
{
|
||||
$path .= '&iwlimit=' . $iwlimit;
|
||||
}
|
||||
|
||||
if ($iwcontinue)
|
||||
{
|
||||
$path .= '&iwcontinue=';
|
||||
}
|
||||
|
||||
if (isset($iwprefix))
|
||||
{
|
||||
$path .= '&iwprefix=' . $iwprefix;
|
||||
}
|
||||
|
||||
if (isset($iwtitle))
|
||||
{
|
||||
$path .= '&iwtitle=' . $iwtitle;
|
||||
}
|
||||
|
||||
if (isset($iwdir))
|
||||
{
|
||||
$path .= '&iwdir=' . $iwdir;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to return all interlanguage links from the given page(s).
|
||||
*
|
||||
* @param array $titles Page titles to retrieve links.
|
||||
* @param integer $lllimit Number of langauge links to return.
|
||||
* @param boolean $llcontinue When more results are available, use this to continue.
|
||||
* @param string $llurl Whether to get the full URL.
|
||||
* @param string $lllang Language code.
|
||||
* @param string $lltitle Link to search for.
|
||||
* @param string $lldir The direction in which to list.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getLangLinks(array $titles, $lllimit = null, $llcontinue = false, $llurl = null, $lllang = null, $lltitle = null, $lldir = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=langlinks';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($lllimit))
|
||||
{
|
||||
$path .= '&lllimit=' . $lllimit;
|
||||
}
|
||||
|
||||
if ($llcontinue)
|
||||
{
|
||||
$path .= '&llcontinue=';
|
||||
}
|
||||
|
||||
if (isset($llurl))
|
||||
{
|
||||
$path .= '&llurl=' . $llurl;
|
||||
}
|
||||
|
||||
if (isset($lllang))
|
||||
{
|
||||
$path .= '&lllang=' . $lllang;
|
||||
}
|
||||
|
||||
if (isset($lltitle))
|
||||
{
|
||||
$path .= '&lltitle=' . $lltitle;
|
||||
}
|
||||
|
||||
if (isset($lldir))
|
||||
{
|
||||
$path .= '&lldir=' . $lldir;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to return all external urls from the given page(s).
|
||||
*
|
||||
* @param array $titles Page titles to retrieve links.
|
||||
* @param integer $ellimit Number of links to return.
|
||||
* @param string $eloffset When more results are available, use this to continue.
|
||||
* @param string $elprotocol Protocol of the url.
|
||||
* @param string $elquery Search string without protocol.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getExtLinks(array $titles, $ellimit = null, $eloffset = null, $elprotocol = null, $elquery = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=extlinks';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($ellimit))
|
||||
{
|
||||
$path .= '&ellimit=' . $ellimit;
|
||||
}
|
||||
|
||||
if (isset($eloffset))
|
||||
{
|
||||
$path .= '&eloffset=' . $eloffset;
|
||||
}
|
||||
|
||||
if (isset($elprotocol))
|
||||
{
|
||||
$path .= '&elprotocol=' . $elprotocol;
|
||||
}
|
||||
|
||||
if (isset($elquery))
|
||||
{
|
||||
$path .= '&elquery=' . $elquery;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to enumerate all links that point to a given namespace.
|
||||
*
|
||||
* @param boolean $alcontinue When more results are available, use this to continue.
|
||||
* @param string $alfrom Start listing at this title. The title need not exist.
|
||||
* @param string $alto The page title to stop enumerating at.
|
||||
* @param string $alprefix Search for all page titles that begin with this value.
|
||||
* @param string $alunique Only show unique links.
|
||||
* @param array $alprop What pieces of information to include.
|
||||
* @param string $alnamespace The namespace to enumerate.
|
||||
* @param integer $allimit Number of links to return.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function enumerateLinks($alcontinue = false, $alfrom = null, $alto = null, $alprefix = null, $alunique = null, array $alprop = null,
|
||||
$alnamespace = null, $allimit = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&meta=siteinfo';
|
||||
|
||||
if ($alcontinue)
|
||||
{
|
||||
$path .= '&alcontinue=';
|
||||
}
|
||||
|
||||
if (isset($alfrom))
|
||||
{
|
||||
$path .= '&alfrom=' . $alfrom;
|
||||
}
|
||||
|
||||
if (isset($alto))
|
||||
{
|
||||
$path .= '&alto=' . $alto;
|
||||
}
|
||||
|
||||
if (isset($alprefix))
|
||||
{
|
||||
$path .= '&alprefix=' . $alprefix;
|
||||
}
|
||||
|
||||
if (isset($alunique))
|
||||
{
|
||||
$path .= '&alunique=' . $alunique;
|
||||
}
|
||||
|
||||
if (isset($alprop))
|
||||
{
|
||||
$path .= '&alprop=' . $this->buildParameter($alprop);
|
||||
}
|
||||
|
||||
if (isset($alnamespace))
|
||||
{
|
||||
$path .= '&alnamespace=' . $alnamespace;
|
||||
}
|
||||
|
||||
if (isset($allimit))
|
||||
{
|
||||
$path .= '&allimit=' . $allimit;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
}
|
164
libraries/joomla/mediawiki/mediawiki.php
Normal file
164
libraries/joomla/mediawiki/mediawiki.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla Platform class for interacting with a Mediawiki server instance.
|
||||
*
|
||||
* @property-read JMediawikiSites $sites MediaWiki API object for sites.
|
||||
* @property-read JMediawikiPages $pages MediaWiki API object for pages.
|
||||
* @property-read JMediawikiUsers $users MediaWiki API object for users.
|
||||
* @property-read JMediawikiLinks $links MediaWiki API object for links.
|
||||
* @property-read JMediawikiCategories $categories MediaWiki API object for categories.
|
||||
* @property-read JMediawikiImages $images MediaWiki API object for images.
|
||||
* @property-read JMediawikiSearch $search MediaWiki API object for search.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawiki
|
||||
{
|
||||
/**
|
||||
* @var JRegistry Options for the MediaWiki object.
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var JMediawikiHttp The HTTP client object to use in sending HTTP requests.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var JMediawikiSites MediaWiki API object for Site.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $sites;
|
||||
|
||||
/**
|
||||
* @var JMediawikiPages MediaWiki API object for pages.
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $pages;
|
||||
|
||||
/**
|
||||
* @var JMediawikiUsers MediaWiki API object for users.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* @var JMediawikiLinks MediaWiki API object for links.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $links;
|
||||
|
||||
/**
|
||||
* @var JMediawikiCategories MediaWiki API object for categories.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* @var JMediawikiImages MediaWiki API object for images.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $images;
|
||||
|
||||
/**
|
||||
* @var JMediawikiSearch MediaWiki API object for search.
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $search;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options MediaWiki options object.
|
||||
* @param JMediawikiHttp $client The HTTP client object.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JMediawikiHttp $client = null)
|
||||
{
|
||||
$this->options = isset($options) ? $options : new JRegistry;
|
||||
$this->client = isset($client) ? $client : new JMediawikiHttp($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to lazily create API objects
|
||||
*
|
||||
* @param string $name Name of property to retrieve
|
||||
*
|
||||
* @return JMediaWikiObject MediaWiki API object (users, reviews, etc).
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
$class = 'JMediawiki' . ucfirst($name);
|
||||
$accessible = array(
|
||||
'categories',
|
||||
'images',
|
||||
'links',
|
||||
'pages',
|
||||
'search',
|
||||
'sites',
|
||||
'users'
|
||||
);
|
||||
|
||||
if (class_exists($class) && in_array($name, $accessible))
|
||||
{
|
||||
if (!isset($this->$name))
|
||||
{
|
||||
$this->$name = new $class($this->options, $this->client);
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Property %s is not accessible.', $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option from the JMediawiki instance.
|
||||
*
|
||||
* @param string $key The name of the option to get.
|
||||
*
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
return $this->options->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option for the JMediawiki instance.
|
||||
*
|
||||
* @param string $key The name of the option to set.
|
||||
* @param mixed $value The option value to set.
|
||||
*
|
||||
* @return JMediawiki This object for method chaining.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->options->set($key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
129
libraries/joomla/mediawiki/object.php
Normal file
129
libraries/joomla/mediawiki/object.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API object class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Mediawiki
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract class JMediawikiObject
|
||||
{
|
||||
|
||||
/**
|
||||
* @var JRegistry Options for the MediaWiki object.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var JMediawikiHttp The HTTP client object to use in sending HTTP requests.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Mediawiki options object.
|
||||
* @param JMediawikiHttp $client The HTTP client object.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JMediawikiHttp $client = null)
|
||||
{
|
||||
$this->options = isset($options) ? $options : new JRegistry;
|
||||
$this->client = isset($client) ? $client : new JMediawikiHttp($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build and return a full request URL for the request.
|
||||
*
|
||||
* @param string $path URL to inflect
|
||||
*
|
||||
* @return string The request URL.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
protected function fetchUrl($path)
|
||||
{
|
||||
// Append the path with output format
|
||||
$path .= '&format=xml';
|
||||
|
||||
$uri = new JUri($this->options->get('api.url') . '/api.php' . $path);
|
||||
|
||||
if ($this->options->get('api.username', false))
|
||||
{
|
||||
$uri->setUser($this->options->get('api.username'));
|
||||
}
|
||||
|
||||
if ($this->options->get('api.password', false))
|
||||
{
|
||||
$uri->setPass($this->options->get('api.password'));
|
||||
}
|
||||
|
||||
return (string) $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build request parameters from a string array.
|
||||
*
|
||||
* @param array $params string array that contains the parameters
|
||||
*
|
||||
* @return string request parameter
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function buildParameter(array $params)
|
||||
{
|
||||
$path = '';
|
||||
|
||||
foreach ($params as $param)
|
||||
{
|
||||
$path .= $param;
|
||||
|
||||
if (next($params) == true)
|
||||
{
|
||||
$path .= '|';
|
||||
}
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to validate response for errors
|
||||
*
|
||||
* @param JHttpresponse $response reponse from the mediawiki server
|
||||
*
|
||||
* @return Object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function validateResponse($response)
|
||||
{
|
||||
$xml = simplexml_load_string($response->body);
|
||||
|
||||
if (isset($xml->warnings))
|
||||
{
|
||||
throw new DomainException($xml->warnings->info);
|
||||
}
|
||||
|
||||
if (isset($xml->error))
|
||||
{
|
||||
throw new DomainException($xml->error['info']);
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
}
|
628
libraries/joomla/mediawiki/pages.php
Normal file
628
libraries/joomla/mediawiki/pages.php
Normal file
@ -0,0 +1,628 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API Pages class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiPages extends JMediawikiObject
|
||||
{
|
||||
/**
|
||||
* Method to edit a page.
|
||||
*
|
||||
* @param string $title Page title.
|
||||
* @param int $section Section number.
|
||||
* @param string $sectiontitle The title for a new section.
|
||||
* @param string $text Page content.
|
||||
* @param string $summary Title of the page you want to delete.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function editPage($title, $section = null, $sectiontitle = null, $text = null, $summary = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($title, 'edit');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=edit';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'title' => $title,
|
||||
'token' => $token,
|
||||
'section' => $section,
|
||||
'sectiontitle' => $section,
|
||||
'text' => $text,
|
||||
'summary' => $summary
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete a page.
|
||||
*
|
||||
* @param string $title Title of the page you want to delete.
|
||||
* @param string $reason Reason for the deletion.
|
||||
* @param string $watchlist Unconditionally add or remove the page from your watchlis.
|
||||
* @param string $oldimage The name of the old image to delete.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function deletePageByName($title, $reason = null, $watchlist = null, $oldimage = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($title, 'delete');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=delete';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'title' => $title,
|
||||
'token' => $token,
|
||||
'reason' => $reason,
|
||||
'watchlist' => $watchlist,
|
||||
'oldimage' => $oldimage
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete a page.
|
||||
*
|
||||
* @param string $pageid Page ID of the page you want to delete.
|
||||
* @param string $reason Reason for the deletion.
|
||||
* @param string $watchlist Unconditionally add or remove the page from your watchlis.
|
||||
* @param string $oldimage The name of the old image to delete.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function deletePageByID($pageid, $reason = null, $watchlist = null, $oldimage = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($pageid, 'delete');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=delete';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'pageid' => $pageid,
|
||||
'token' => $token,
|
||||
'reason' => $reason,
|
||||
'watchlist' => $watchlist,
|
||||
'oldimage' => $oldimage
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to restore certain revisions of a deleted page.
|
||||
*
|
||||
* @param string $title Title of the page you want to restore.
|
||||
* @param string $reason Reason for restoring (optional).
|
||||
* @param string $timestamp Timestamps of the revisions to restore.
|
||||
* @param string $watchlist Unconditionally add or remove the page from your watchlist.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function undeletePage($title, $reason = null, $timestamp = null, $watchlist = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($title, 'undelete');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=undelete';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'title' => $title,
|
||||
'token' => $token,
|
||||
'reason' => $reason,
|
||||
'timestamp' => $timestamp,
|
||||
'watchlist' => $watchlist,
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to move a page.
|
||||
*
|
||||
* @param string $from Title of the page you want to move.
|
||||
* @param string $to Title you want to rename the page to.
|
||||
* @param string $reason Reason for the move (optional).
|
||||
* @param string $movetalk Move the talk page, if it exists.
|
||||
* @param string $movesubpages Move subpages, if applicable.
|
||||
* @param boolean $noredirect Don't create a redirect.
|
||||
* @param string $watchlist Unconditionally add or remove the page from your watchlist.
|
||||
* @param boolean $ignorewarnings Ignore any warnings.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function movePageByName($from, $to, $reason = null, $movetalk = null, $movesubpages = null, $noredirect = null,
|
||||
$watchlist =null, $ignorewarnings = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($from, 'move');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=move';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'from' => $from,
|
||||
'to' => $reason,
|
||||
'token' => $token,
|
||||
'reason' => $reason,
|
||||
'movetalk' => $movetalk,
|
||||
'movesubpages' => $movesubpages,
|
||||
'noredirect' => $noredirect,
|
||||
'watchlist' => $watchlist,
|
||||
'ignorewarnings' => $ignorewarnings
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to move a page.
|
||||
*
|
||||
* @param int $fromid Page ID of the page you want to move.
|
||||
* @param string $to Title you want to rename the page to.
|
||||
* @param string $reason Reason for the move (optional).
|
||||
* @param string $movetalk Move the talk page, if it exists.
|
||||
* @param string $movesubpages Move subpages, if applicable.
|
||||
* @param boolean $noredirect Don't create a redirect.
|
||||
* @param string $watchlist Unconditionally add or remove the page from your watchlist.
|
||||
* @param boolean $ignorewarnings Ignore any warnings.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function movePageByID($fromid, $to, $reason = null, $movetalk = null, $movesubpages = null, $noredirect = null,
|
||||
$watchlist =null, $ignorewarnings = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($fromid, 'move');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=move';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'fromid' => $fromid,
|
||||
'to' => $reason,
|
||||
'token' => $token,
|
||||
'reason' => $reason,
|
||||
'movetalk' => $movetalk,
|
||||
'movesubpages' => $movesubpages,
|
||||
'noredirect' => $noredirect,
|
||||
'watchlist' => $watchlist,
|
||||
'ignorewarnings' => $ignorewarnings
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to undo the last edit to the page.
|
||||
*
|
||||
* @param string $title Title of the page you want to rollback.
|
||||
* @param string $user Name of the user whose edits are to be rolled back.
|
||||
* @param string $summary Custom edit summary. If not set, default summary will be used.
|
||||
* @param string $markbot Mark the reverted edits and the revert as bot edits.
|
||||
* @param string $watchlist Unconditionally add or remove the page from your watchlist.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function rollback($title, $user, $summary = null, $markbot = null, $watchlist = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($title, 'rollback');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=rollback';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'title' => $title,
|
||||
'token' => $token,
|
||||
'user' => $user,
|
||||
'expiry' => $summary,
|
||||
'markbot' => $markbot,
|
||||
'watchlist' => $watchlist
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to change the protection level of a page.
|
||||
*
|
||||
* @param string $title Title of the page you want to (un)protect.
|
||||
* @param string $protections Pipe-separated list of protection levels.
|
||||
* @param string $expiry Expiry timestamps.
|
||||
* @param string $reason Reason for (un)protecting (optional).
|
||||
* @param string $cascade Enable cascading protection.
|
||||
* @param string $watchlist Unconditionally add or remove the page from your watchlist.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function changeProtection($title, $protections, $expiry = null, $reason = null, $cascade = null, $watchlist = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($title, 'unblock');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=protect';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'title' => $title,
|
||||
'token' => $token,
|
||||
'protections' => $protections,
|
||||
'expiry' => $expiry,
|
||||
'reason' => $reason,
|
||||
'cascade' => $cascade,
|
||||
'watchlist' => $watchlist
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get basic page information.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve info.
|
||||
* @param array $inprop Which additional properties to get.
|
||||
* @param array $intoken Request a token to perform a data-modifying action on a page
|
||||
* @param boolean $incontinue When more results are available, use this to continue.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getPageInfo(array $titles, array $inprop = null, array $intoken = null, $incontinue = null)
|
||||
{
|
||||
// Build the request
|
||||
$path = '?action=query&prop=info';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($inprop))
|
||||
{
|
||||
$path .= '&inprop=' . $this->buildParameter($inprop);
|
||||
}
|
||||
|
||||
if (isset($intoken))
|
||||
{
|
||||
$path .= '&intoken=' . $this->buildParameter($intoken);
|
||||
}
|
||||
|
||||
if ($incontinue)
|
||||
{
|
||||
$path .= '&incontinue=';
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get various properties defined in the page content.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve properties.
|
||||
* @param boolean $ppcontinue When more results are available, use this to continue.
|
||||
* @param string $ppprop Page prop to look on the page for.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getPageProperties(array $titles, $ppcontinue = null, $ppprop = null)
|
||||
{
|
||||
// Build the request
|
||||
$path = '?action=query&prop=pageprops';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if ($ppcontinue)
|
||||
{
|
||||
$path .= '&ppcontinue=';
|
||||
}
|
||||
|
||||
if (isset($ppprop))
|
||||
{
|
||||
$path .= '&ppprop=' . $ppprop;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a list of revisions.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve revisions.
|
||||
* @param array $rvprop Which properties to get for each revision.
|
||||
* @param boolean $rvparse Parse revision content.
|
||||
* @param int $rvlimit Limit how many revisions will be returned.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getRevisions(array $titles, array $rvprop = null, $rvparse = null, $rvlimit = null)
|
||||
{
|
||||
// Build the request
|
||||
$path = '?action=query&prop=revisions';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($rvprop))
|
||||
{
|
||||
$path .= '&rvprop=' . $this->buildParameter($rvprop);
|
||||
}
|
||||
|
||||
if ($rvparse)
|
||||
{
|
||||
$path .= '&rvparse=';
|
||||
}
|
||||
|
||||
if (isset($rvlimit))
|
||||
{
|
||||
$path .= '&rvlimit=' . $rvlimit;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all page templates from the given page.
|
||||
*
|
||||
* @param array $titles Page titles to retrieve templates.
|
||||
* @param array $tlnamespace Show templates in this namespace(s) only.
|
||||
* @param integer $tllimit How many templates to return.
|
||||
* @param boolean $tlcontinue When more results are available, use this to continue.
|
||||
* @param string $tltemplates Only list these templates.
|
||||
* @param string $tldir The direction in which to list.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getPageTemplates(array $titles, array $tlnamespace = null, $tllimit = null, $tlcontinue = null, $tltemplates = null, $tldir = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&prop=templates';
|
||||
|
||||
// Append titles to the request.
|
||||
$path .= '&titles=' . $this->buildParameter($titles);
|
||||
|
||||
if (isset($tlnamespace))
|
||||
{
|
||||
$path .= '&tlnamespace=' . $this->buildParameter($tlnamespace);
|
||||
}
|
||||
|
||||
if (isset($tllimit))
|
||||
{
|
||||
$path .= '&tllimit=' . $tllimit;
|
||||
}
|
||||
|
||||
if ($tlcontinue)
|
||||
{
|
||||
$path .= '&tlcontinue=';
|
||||
}
|
||||
|
||||
if (isset($tltemplates))
|
||||
{
|
||||
$path .= '&tltemplates=' . $tltemplates;
|
||||
}
|
||||
|
||||
if (isset($tldir))
|
||||
{
|
||||
$path .= '&tldir=' . $tldir;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all pages that link to the given page.
|
||||
*
|
||||
* @param string $bltitle Title to search.
|
||||
* @param integer $blpageid Pageid to search.
|
||||
* @param boolean $blcontinue When more results are available, use this to continue.
|
||||
* @param array $blnamespace The namespace to enumerate.
|
||||
* @param string $blfilterredirect How to filter for redirects..
|
||||
* @param integer $bllimit How many total pages to return.
|
||||
* @param boolean $blredirect If linking page is a redirect, find all pages that link to that redirect as well.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getBackLinks($bltitle, $blpageid = null, $blcontinue = null, array $blnamespace = null, $blfilterredirect = null,
|
||||
$bllimit = null, $blredirect = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=backlinks';
|
||||
|
||||
if (isset($bltitle))
|
||||
{
|
||||
$path .= '&bltitle=' . $bltitle;
|
||||
}
|
||||
|
||||
if (isset($blpageid))
|
||||
{
|
||||
$path .= '&blpageid=' . $blpageid;
|
||||
}
|
||||
|
||||
if ($blcontinue)
|
||||
{
|
||||
$path .= '&blcontinue=';
|
||||
}
|
||||
|
||||
if (isset($blnamespace))
|
||||
{
|
||||
$path .= '&blnamespace=' . $this->buildParameter($blnamespace);
|
||||
}
|
||||
|
||||
if (isset($blfilterredirect))
|
||||
{
|
||||
$path .= '&blfilterredirect=' . $blfilterredirect;
|
||||
}
|
||||
|
||||
if (isset($bllimit))
|
||||
{
|
||||
$path .= '&bllimit=' . $bllimit;
|
||||
}
|
||||
|
||||
if ($blredirect)
|
||||
{
|
||||
$path .= '&blredirect=';
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all pages that link to the given interwiki link.
|
||||
*
|
||||
* @param string $iwbltitle Interwiki link to search for. Must be used with iwblprefix.
|
||||
* @param string $iwblprefix Prefix for the interwiki.
|
||||
* @param boolean $iwblcontinue When more results are available, use this to continue.
|
||||
* @param integer $iwbllimit How many total pages to return.
|
||||
* @param array $iwblprop Which properties to get.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getIWBackLinks($iwbltitle, $iwblprefix = null, $iwblcontinue = null, $iwbllimit = null, array $iwblprop = null)
|
||||
{
|
||||
// Build the request
|
||||
$path = '?action=query&list=iwbacklinks';
|
||||
|
||||
if (isset($iwbltitle))
|
||||
{
|
||||
$path .= '&iwbltitle=' . $iwbltitle;
|
||||
}
|
||||
|
||||
if (isset($iwblprefix))
|
||||
{
|
||||
$path .= '&iwblprefix=' . $iwblprefix;
|
||||
}
|
||||
|
||||
if ($iwblcontinue)
|
||||
{
|
||||
$path .= '&iwblcontinue=';
|
||||
}
|
||||
|
||||
if (isset($iwbllimit))
|
||||
{
|
||||
$path .= '&bllimit=' . $iwbllimit;
|
||||
}
|
||||
|
||||
if (isset($iwblprop))
|
||||
{
|
||||
$path .= '&iwblprop=' . $this->buildParameter($iwblprop);
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get access token.
|
||||
*
|
||||
* @param string $user The User to get token.
|
||||
* @param string $intoken The type of token.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function getToken($user, $intoken)
|
||||
{
|
||||
// Build the request path.
|
||||
$path = '?action=query&prop=info&intoken=' . $intoken . '&titles=User:' . $user;
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), null);
|
||||
|
||||
return (string) $this->validateResponse($response)->query->pages->page[$intoken . 'token'];
|
||||
}
|
||||
}
|
138
libraries/joomla/mediawiki/search.php
Normal file
138
libraries/joomla/mediawiki/search.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API Search class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiSearch extends JMediawikiObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Method to perform a full text search.
|
||||
*
|
||||
* @param string $srsearch Search for all page titles (or content) that has this value.
|
||||
* @param array $srnamespace The namespace(s) to enumerate.
|
||||
* @param string $srwhat Search inside the text or titles.
|
||||
* @param array $srinfo What metadata to return.
|
||||
* @param array $srprop What properties to return.
|
||||
* @param boolean $srredirects Include redirect pages in the search.
|
||||
* @param integer $sroffest Use this value to continue paging.
|
||||
* @param integer $srlimit How many total pages to return.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function search($srsearch, array $srnamespace = null, $srwhat = null, array $srinfo = null, array $srprop = null,
|
||||
$srredirects = null, $sroffest = null, $srlimit = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=search';
|
||||
|
||||
if (isset($srsearch))
|
||||
{
|
||||
$path .= '&srsearch=' . $srsearch;
|
||||
}
|
||||
|
||||
if (isset($srnamespace))
|
||||
{
|
||||
$path .= '&srnamespace=' . $this->buildParameter($srnamespace);
|
||||
}
|
||||
|
||||
if (isset($srwhat))
|
||||
{
|
||||
$path .= '&srwhat=' . $srwhat;
|
||||
}
|
||||
|
||||
if (isset($srinfo))
|
||||
{
|
||||
$path .= '&srinfo=' . $this->buildParameter($srinfo);
|
||||
}
|
||||
|
||||
if (isset($srprop))
|
||||
{
|
||||
$path .= '&srprop=' . $this->buildParameter($srprop);
|
||||
}
|
||||
|
||||
if ($srredirects)
|
||||
{
|
||||
$path .= '&srredirects=';
|
||||
}
|
||||
|
||||
if (isset($sroffest))
|
||||
{
|
||||
$path .= '&sroffest=' . $sroffest;
|
||||
}
|
||||
|
||||
if (isset($srlimit))
|
||||
{
|
||||
$path .= '&srlimit=' . $srlimit;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to search the wiki using opensearch protocol.
|
||||
*
|
||||
* @param string $search Search string.
|
||||
* @param integer $limit Maximum amount of results to return.
|
||||
* @param array $namespace Namespaces to search.
|
||||
* @param string $suggest Do nothing if $wgEnableOpenSearchSuggest is false.
|
||||
* @param string $format Output format.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function openSearch($search, $limit = null, array $namespace = null, $suggest = null, $format = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=search';
|
||||
|
||||
if (isset($search))
|
||||
{
|
||||
$path .= '&search=' . $search;
|
||||
}
|
||||
|
||||
if (isset($limit))
|
||||
{
|
||||
$path .= '&limit=' . $limit;
|
||||
}
|
||||
|
||||
if (isset($namespace))
|
||||
{
|
||||
$path .= '&namespace=' . $this->buildParameter($namespace);
|
||||
}
|
||||
|
||||
if (isset($suggest))
|
||||
{
|
||||
$path .= '&suggest=' . $suggest;
|
||||
}
|
||||
|
||||
if (isset($format))
|
||||
{
|
||||
$path .= '&format=' . $format;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
}
|
315
libraries/joomla/mediawiki/sites.php
Normal file
315
libraries/joomla/mediawiki/sites.php
Normal file
@ -0,0 +1,315 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API Sites class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiSites extends JMediawikiObject
|
||||
{
|
||||
/**
|
||||
* Method to get site information.
|
||||
*
|
||||
* @param array $siprop The sysinfo properties to get.
|
||||
* @param string $sifilteriw Only local or only non local entries to return.
|
||||
* @param boolean $sishowalldb List all database servers.
|
||||
* @param boolean $sinumberingroup List the number of users in usergroups.
|
||||
* @param array $siinlanguagecode Language code for localized languages.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getSiteInfo(array $siprop = null, $sifilteriw = null, $sishowalldb = false, $sinumberingroup = false, array $siinlanguagecode = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&meta=siteinfo';
|
||||
|
||||
if (isset($siprop))
|
||||
{
|
||||
$path .= '&siprop=' . $this->buildParameter($siprop);
|
||||
}
|
||||
|
||||
if (isset($sifilteriw))
|
||||
{
|
||||
$path .= '&sifilteriw=' . $sifilteriw;
|
||||
}
|
||||
|
||||
if ($sishowalldb)
|
||||
{
|
||||
$path .= '&sishowalldb=';
|
||||
}
|
||||
|
||||
if ($sinumberingroup)
|
||||
{
|
||||
$path .= '&sinumberingroup=';
|
||||
}
|
||||
|
||||
if (isset($siinlanguagecode))
|
||||
{
|
||||
$path .= '&siinlanguagecode=' . $this->buildParameter($siinlanguagecode);
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get events from logs.
|
||||
*
|
||||
* @param array $leprop List of properties to get.
|
||||
* @param string $letype Filter log actions to only this type.
|
||||
* @param string $leaction Filter log actions to only this type.
|
||||
* @param string $letitle Filter entries to those related to a page.
|
||||
* @param string $leprefix Filter entries that start with this prefix.
|
||||
* @param string $letag Filter entries with tag.
|
||||
* @param string $leuser Filter entries made by the given user.
|
||||
* @param string $lestart Starting timestamp.
|
||||
* @param string $leend Ending timestamp.
|
||||
* @param string $ledir Direction of enumeration.
|
||||
* @param integer $lelimit Event limit to return.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getEvents(array $leprop = null, $letype = null, $leaction = null, $letitle = null, $leprefix = null, $letag = null,
|
||||
$leuser = null, $lestart = null, $leend = null, $ledir = null, $lelimit = null)
|
||||
{
|
||||
// Build the request
|
||||
$path = '?action=query&list=logevents';
|
||||
|
||||
if (isset($leprop))
|
||||
{
|
||||
$path .= '&leprop=' . $this->buildParameter($leprop);
|
||||
}
|
||||
|
||||
if (isset($letype))
|
||||
{
|
||||
$path .= '&letype=' . $letype;
|
||||
}
|
||||
|
||||
if (isset($leaction))
|
||||
{
|
||||
$path .= '&leaction=' . $leaction;
|
||||
}
|
||||
|
||||
if (isset($letitle))
|
||||
{
|
||||
$path .= '&letitle=' . $letitle;
|
||||
}
|
||||
|
||||
if (isset($leprefix))
|
||||
{
|
||||
$path .= '&leprefix=' . $leprefix;
|
||||
}
|
||||
|
||||
if (isset($letag))
|
||||
{
|
||||
$path .= '&letag=' . $letag;
|
||||
}
|
||||
|
||||
if (isset($leuser))
|
||||
{
|
||||
$path .= '&leuser=' . $leuser;
|
||||
}
|
||||
|
||||
if (isset($lestart))
|
||||
{
|
||||
$path .= '&lestart=' . $lestart;
|
||||
}
|
||||
|
||||
if (isset($leend))
|
||||
{
|
||||
$path .= '&leend=' . $leend;
|
||||
}
|
||||
|
||||
if (isset($ledir))
|
||||
{
|
||||
$path .= '&ledir=' . $ledir;
|
||||
}
|
||||
|
||||
if (isset($lelimit))
|
||||
{
|
||||
$path .= '&lelimit=' . $lelimit;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get recent changes on a site.
|
||||
*
|
||||
* @param string $rcstart Starting timestamp.
|
||||
* @param string $rcend Ending timestamp.
|
||||
* @param string $rcdir Direction of enumeration.
|
||||
* @param array $rcnamespace Filter changes to only this namespace(s).
|
||||
* @param string $rcuser Filter changes by this user.
|
||||
* @param string $rcexcludeuser Filter changes to exclude changes by this user.
|
||||
* @param string $rctag Filter changes by this tag.
|
||||
* @param array $rcprop Filter log actions to only this type.
|
||||
* @param array $rctoken Which token to obtain for each change.
|
||||
* @param array $rcshow Filter changes by this criteria.
|
||||
* @param string $rclimit Changes limit to return.
|
||||
* @param string $rctype Filter event by type of changes.
|
||||
* @param string $rctoponly Filter changes which are latest revision.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getRecentChanges($rcstart = null, $rcend = null, $rcdir = null, array $rcnamespace = null, $rcuser = null, $rcexcludeuser = null,
|
||||
$rctag = null, array $rcprop = null, array $rctoken = null, array $rcshow = null, $rclimit = null, $rctype = null, $rctoponly = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=recentchanges';
|
||||
|
||||
if (isset($rcstart))
|
||||
{
|
||||
$path .= '&rcstart=' . $rcstart;
|
||||
}
|
||||
|
||||
if (isset($rcend))
|
||||
{
|
||||
$path .= '&rcend=' . $rcend;
|
||||
}
|
||||
|
||||
if (isset($rcdir))
|
||||
{
|
||||
$path .= '&rcdir=' . $rcdir;
|
||||
}
|
||||
|
||||
if (isset($rcnamespace))
|
||||
{
|
||||
$path .= '&rcnamespaces=' . $this->buildParameter($rcnamespace);
|
||||
}
|
||||
|
||||
if (isset($rcuser))
|
||||
{
|
||||
$path .= '&rcuser=' . $rcuser;
|
||||
}
|
||||
|
||||
if (isset($rcexcludeuser))
|
||||
{
|
||||
$path .= '&rcexcludeuser=' . $rcexcludeuser;
|
||||
}
|
||||
|
||||
if (isset($rctag))
|
||||
{
|
||||
$path .= '&rctag=' . $rctag;
|
||||
}
|
||||
|
||||
if (isset($rcprop))
|
||||
{
|
||||
$path .= '&rcprop=' . $this->buildParameter($rcprop);
|
||||
}
|
||||
|
||||
if (isset($rctoken))
|
||||
{
|
||||
$path .= '&rctoken=' . $this->buildParameter($rctoken);
|
||||
}
|
||||
|
||||
if (isset($rcshow))
|
||||
{
|
||||
$path .= '&rcshow=' . $this->buildParameter($rcshow);
|
||||
}
|
||||
|
||||
if (isset($rclimit))
|
||||
{
|
||||
$path .= '&rclimit=' . $rclimit;
|
||||
}
|
||||
|
||||
if (isset($rctype))
|
||||
{
|
||||
$path .= '&rctype=' . $rctype;
|
||||
}
|
||||
|
||||
if (isset($rctoponly))
|
||||
{
|
||||
$path .= '&rctoponly=' . $rctoponly;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get protected titles on a site.
|
||||
*
|
||||
* @param array $ptnamespace Only list titles in this namespace.
|
||||
* @param array $ptlevel Only list titles with these protection level.
|
||||
* @param integer $ptlimit Limit of pages to return.
|
||||
* @param string $ptdir Direction of enumeration.
|
||||
* @param string $ptstart Starting timestamp.
|
||||
* @param string $ptend Ending timestamp.
|
||||
* @param array $ptprop List of properties to get.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getProtectedTitles(array $ptnamespace = null, array $ptlevel = null, $ptlimit = null, $ptdir = null, $ptstart = null,
|
||||
$ptend = null, array $ptprop = null)
|
||||
{
|
||||
// Build the request.
|
||||
$path = '?action=query&list=protectedtitles';
|
||||
|
||||
if (isset($ptnamespace))
|
||||
{
|
||||
$path .= '&ptnamespace=' . $this->buildParameter($ptnamespace);
|
||||
}
|
||||
|
||||
if (isset($ptlevel))
|
||||
{
|
||||
$path .= '&ptlevel=' . $this->buildParameter($ptlevel);
|
||||
}
|
||||
|
||||
if (isset($ptlimit))
|
||||
{
|
||||
$path .= '&ptlimit=' . $ptlimit;
|
||||
}
|
||||
|
||||
if (isset($ptdir))
|
||||
{
|
||||
$path .= '&ptdir=' . $ptdir;
|
||||
}
|
||||
|
||||
if (isset($ptstart))
|
||||
{
|
||||
$path .= '&ptstart=' . $ptstart;
|
||||
}
|
||||
|
||||
if (isset($ptend))
|
||||
{
|
||||
$path .= '&ptend=' . $ptend;
|
||||
}
|
||||
|
||||
if (isset($ptprop))
|
||||
{
|
||||
$path .= '&ptprop=' . $this->buildParameter($ptprop);
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
}
|
442
libraries/joomla/mediawiki/users.php
Normal file
442
libraries/joomla/mediawiki/users.php
Normal file
@ -0,0 +1,442 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* MediaWiki API Users class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage MediaWiki
|
||||
* @since 12.3
|
||||
*/
|
||||
class JMediawikiUsers extends JMediawikiObject
|
||||
{
|
||||
/**
|
||||
* Method to login and get authentication tokens.
|
||||
*
|
||||
* @param string $lgname User Name.
|
||||
* @param string $lgpassword Password.
|
||||
* @param string $lgdomain Domain (optional).
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function login($lgname, $lgpassword, $lgdomain = null)
|
||||
{
|
||||
// Build the request path.
|
||||
$path = '?action=login&lgname=' . $lgname . '&lgpassword=' . $lgpassword;
|
||||
|
||||
if (isset($lgdomain))
|
||||
{
|
||||
$path .= '&lgdomain=' . $lgdomain;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), null);
|
||||
|
||||
// Request path with login token.
|
||||
$path = '?action=login&lgname=' . $lgname . '&lgpassword=' . $lgpassword . '&lgtoken=' . $this->validateResponse($response)->login['token'];
|
||||
|
||||
if (isset($lgdomain))
|
||||
{
|
||||
$path .= '&lgdomain=' . $lgdomain;
|
||||
}
|
||||
|
||||
// Set the session cookies returned.
|
||||
$headers = (array) $this->options->get('headers');
|
||||
$headers['Cookie'] = !empty($headers['Cookie']) ? empty($headers['Cookie']) : '';
|
||||
$headers['Cookie'] = $headers['Cookie'] . $response->headers['Set-Cookie'];
|
||||
$this->options->set('headers', $headers);
|
||||
|
||||
// Send the request again with the token.
|
||||
$response = $this->client->post($this->fetchUrl($path), null);
|
||||
$response_body = $this->validateResponse($response);
|
||||
|
||||
$headers = (array) $this->options->get('headers');
|
||||
$cookie_prefix = $response_body->login['cookieprefix'];
|
||||
$cookie = $cookie_prefix . 'UserID=' . $response_body->login['lguserid'] . '; ' . $cookie_prefix
|
||||
. 'UserName=' . $response_body->login['lgusername'];
|
||||
$headers['Cookie'] = $headers['Cookie'] . '; ' . $response->headers['Set-Cookie'] . '; ' . $cookie;
|
||||
$this->options->set('headers', $headers);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to logout and clear session data.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
// Build the request path.
|
||||
$path = '?action=login';
|
||||
|
||||
// @TODO clear internal data as well
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get user information.
|
||||
*
|
||||
* @param array $ususers A list of users to obtain the same information for.
|
||||
* @param array $usprop What pieces of information to include.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getUserInfo(array $ususers, array $usprop = null)
|
||||
{
|
||||
// Build the request path.
|
||||
$path = '?action=query&list=users';
|
||||
|
||||
// Append users to the request.
|
||||
$path .= '&ususers=' . $this->buildParameter($ususers);
|
||||
|
||||
if (isset($usprop))
|
||||
{
|
||||
$path .= '&usprop' . $this->buildParameter($usprop);
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get current user information.
|
||||
*
|
||||
* @param array $uiprop What pieces of information to include.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getCurrentUserInfo(array $uiprop = null)
|
||||
{
|
||||
// Build the request path.
|
||||
$path = '?action=query&meta=userinfo';
|
||||
|
||||
if (isset($uiprop))
|
||||
{
|
||||
$path .= '&uiprop' . $this->buildParameter($uiprop);
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get user contributions.
|
||||
*
|
||||
* @param string $ucuser The users to retrieve contributions for.
|
||||
* @param string $ucuserprefix Retrieve contibutions for all users whose names begin with this value.
|
||||
* @param integer $uclimit The users to retrieve contributions for.
|
||||
* @param string $ucstart The start timestamp to return from.
|
||||
* @param string $ucend The end timestamp to return to.
|
||||
* @param boolean $uccontinue When more results are available, use this to continue.
|
||||
* @param string $ucdir In which direction to enumerate.
|
||||
* @param array $ucnamespace Only list contributions in these namespaces.
|
||||
* @param array $ucprop Include additional pieces of information.
|
||||
* @param array $ucshow Show only items that meet this criteria.
|
||||
* @param string $uctag Only list revisions tagged with this tag.
|
||||
* @param string $uctoponly Only list changes which are the latest revision
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getUserContribs($ucuser = null, $ucuserprefix = null, $uclimit = null, $ucstart = null, $ucend = null, $uccontinue = null,
|
||||
$ucdir = null, array $ucnamespace = null, array $ucprop = null, array $ucshow = null, $uctag = null, $uctoponly = null)
|
||||
{
|
||||
// Build the request path.
|
||||
$path = '?action=query&list=usercontribs';
|
||||
|
||||
if (isset($ucuser))
|
||||
{
|
||||
$path .= '&ucuser=' . $ucuser;
|
||||
}
|
||||
|
||||
if (isset($ucuserprefix))
|
||||
{
|
||||
$path .= '&ucuserprefix=' . $ucuserprefix;
|
||||
}
|
||||
|
||||
if (isset($uclimit))
|
||||
{
|
||||
$path .= '&uclimit=' . $uclimit;
|
||||
}
|
||||
|
||||
if (isset($ucstart))
|
||||
{
|
||||
$path .= '&ucstart=' . $ucstart;
|
||||
}
|
||||
|
||||
if (isset($ucend))
|
||||
{
|
||||
$path .= '&ucend=' . $ucend;
|
||||
}
|
||||
|
||||
if ($uccontinue)
|
||||
{
|
||||
$path .= '&uccontinue=';
|
||||
}
|
||||
|
||||
if (isset($ucdir))
|
||||
{
|
||||
$path .= '&ucdir=' . $ucdir;
|
||||
}
|
||||
|
||||
if (isset($ucnamespace))
|
||||
{
|
||||
$path .= '&ucnamespace=' . $this->buildParameter($ucnamespace);
|
||||
}
|
||||
|
||||
if (isset($ucprop))
|
||||
{
|
||||
$path .= '&ucprop=' . $this->buildParameter($ucprop);
|
||||
}
|
||||
|
||||
if (isset($ucshow))
|
||||
{
|
||||
$path .= '&ucshow=' . $this->buildParameter($ucshow);
|
||||
}
|
||||
|
||||
if (isset($uctag))
|
||||
{
|
||||
$path .= '&uctag=' . $uctag;
|
||||
}
|
||||
|
||||
if (isset($uctoponly))
|
||||
{
|
||||
$path .= '&uctoponly=' . $uctoponly;
|
||||
}
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to block a user.
|
||||
*
|
||||
* @param string $user Username, IP address or IP range you want to block.
|
||||
* @param string $expiry Relative expiry time, Default: never.
|
||||
* @param string $reason Reason for block (optional).
|
||||
* @param boolean $anononly Block anonymous users only.
|
||||
* @param boolean $nocreate Prevent account creation.
|
||||
* @param boolean $autoblock Automatically block the last used IP address, and any subsequent IP addresses they try to login from.
|
||||
* @param boolean $noemail Prevent user from sending e-mail through the wiki.
|
||||
* @param boolean $hidename Hide the username from the block log.
|
||||
* @param boolean $allowusertalk Allow the user to edit their own talk page.
|
||||
* @param boolean $reblock If the user is already blocked, overwrite the existing block.
|
||||
* @param boolean $watchuser Watch the user/IP's user and talk pages.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function blockUser($user, $expiry = null, $reason = null, $anononly = null, $nocreate = null, $autoblock = null, $noemail = null,
|
||||
$hidename = null, $allowusertalk = null, $reblock = null, $watchuser = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($user, 'block');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=unblock';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'user' => $user,
|
||||
'token' => $token,
|
||||
'expiry' => $expiry,
|
||||
'reason' => $reason,
|
||||
'anononly' => $anononly,
|
||||
'nocreate' => $nocreate,
|
||||
'autoblock' => $autoblock,
|
||||
'noemail' => $noemail,
|
||||
'hidename' => $hidename,
|
||||
'allowusetalk' => $allowusertalk,
|
||||
'reblock' => $reblock,
|
||||
'watchuser' => $watchuser
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to unblock a user.
|
||||
*
|
||||
* @param string $user Username, IP address or IP range you want to unblock.
|
||||
* @param string $reason Reason for unblock (optional).
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function unBlockUserByName($user, $reason = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($user, 'unblock');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=unblock';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'user' => $user,
|
||||
'token' => $token,
|
||||
'reason' => $reason,
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to unblock a user.
|
||||
*
|
||||
* @param int $id Username, IP address or IP range you want to unblock.
|
||||
* @param string $reason Reason for unblock (optional).
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function unBlockUserByID($id, $reason = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($id, 'unblock');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=unblock';
|
||||
|
||||
// Build the request data.
|
||||
// TODO: $data doesn't seem to be used!
|
||||
$data = array(
|
||||
'id' => $id,
|
||||
'token' => $token,
|
||||
'reason' => $reason,
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->get($this->fetchUrl($path));
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to assign a user to a group.
|
||||
*
|
||||
* @param string $username User name.
|
||||
* @param array $add Add the user to these groups.
|
||||
* @param array $remove Remove the user from these groups.
|
||||
* @param string $reason Reason for the change.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function assignGroup($username, $add = null, $remove = null, $reason = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($username, 'unblock');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=userrights';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'username' => $username,
|
||||
'token' => $token,
|
||||
'add' => $add,
|
||||
'remove' => $remove,
|
||||
'reason' => $reason
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to email a user.
|
||||
*
|
||||
* @param string $target User to send email to.
|
||||
* @param string $subject Subject header.
|
||||
* @param string $text Mail body.
|
||||
* @param boolean $ccme Send a copy of this mail to me.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function emailUser($target, $subject = null, $text = null, $ccme = null)
|
||||
{
|
||||
// Get the token.
|
||||
$token = $this->getToken($target, 'emailuser');
|
||||
|
||||
// Build the request path.
|
||||
$path = '?action=emailuser';
|
||||
|
||||
// Build the request data.
|
||||
$data = array(
|
||||
'target' => $target,
|
||||
'token' => $token,
|
||||
'subject' => $subject,
|
||||
'text' => $text,
|
||||
'ccme' => $ccme
|
||||
);
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), $data);
|
||||
|
||||
return $this->validateResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get access token.
|
||||
*
|
||||
* @param string $user The User to get token.
|
||||
* @param string $intoken The type of token.
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getToken($user, $intoken)
|
||||
{
|
||||
// Build the request path.
|
||||
$path = '?action=query&prop=info&intoken=' . $intoken . '&titles=User:' . $user;
|
||||
|
||||
// Send the request.
|
||||
$response = $this->client->post($this->fetchUrl($path), null);
|
||||
|
||||
return (string) $this->validateResponse($response)->query->pages->page[$intoken . 'token'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user