/**
* Using getAllowedParams(), makes an array of the values provided by the user,
* with key being the name of the variable, and value - validated value from user or default.
- * This method can be used to generate local variables using extract().
* limit=max will not be parsed if $parseMaxLimit is set to false; use this
* when the max limit is not definite, e.g. when getting revisions.
*/
public function execute() {
// Get parameters
- extract( $this->extractRequestParams() );
- $retval = '';
+ $params = $this->extractRequestParams();
//Create title for parser
- $title_obj = Title :: newFromText( $title );
+ $title_obj = Title :: newFromText( $params['title'] );
if(!$title_obj)
- $title_obj = Title :: newFromText( "API" ); // Default title is "API". For example, ExpandTemplates uses "ExpendTemplates" for it
+ $title_obj = Title :: newFromText( "API" ); // default
$result = $this->getResult();
// Parse text
global $wgParser;
$options = new ParserOptions();
- if ( $generatexml )
+ if ( $params['generatexml'] )
{
$wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
- $dom = $wgParser->preprocessToDom( $text );
+ $dom = $wgParser->preprocessToDom( $params['text'] );
if ( is_callable( array( $dom, 'saveXML' ) ) ) {
$xml = $dom->saveXML();
} else {
}
$xml_result = array();
$result->setContent( $xml_result, $xml );
- $result->addValue( null, 'parsetree', $xml_result);
+ $result->addValue( null, 'parsetree', $xml_result);
}
- $retval = $wgParser->preprocess( $text, $title_obj, $options );
+ $retval = $wgParser->preprocess( $params['text'], $title_obj, $options );
// Return result
$retval_array = array();
* @access public
*/
public function execute() {
- $name = $password = $domain = null;
- extract($this->extractRequestParams());
+ $params = $this->extractRequestParams();
$result = array ();
- $params = new FauxRequest(array (
- 'wpName' => $name,
- 'wpPassword' => $password,
- 'wpDomain' => $domain,
+ $req = new FauxRequest(array (
+ 'wpName' => $params['name'],
+ 'wpPassword' => $params['password'],
+ 'wpDomain' => $params['domain'],
'wpRemember' => ''
));
wfSetupSession();
}
- $loginForm = new LoginForm($params);
+ $loginForm = new LoginForm($req);
switch ($authRes = $loginForm->authenticateUserData()) {
case LoginForm :: SUCCESS :
global $wgUser, $wgCookiePrefix;
*/
public function execute() {
$this->profileIn();
- $titles = $pageids = $revids = null;
- extract($this->extractRequestParams());
+ $params = $this->extractRequestParams();
// Only one of the titles/pageids/revids is allowed at the same time
$dataSource = null;
- if (isset ($titles))
+ if (isset ($params['titles']))
$dataSource = 'titles';
- if (isset ($pageids)) {
+ if (isset ($params['pageids'])) {
if (isset ($dataSource))
$this->dieUsage("Cannot use 'pageids' at the same time as '$dataSource'", 'multisource');
$dataSource = 'pageids';
}
- if (isset ($revids)) {
+ if (isset ($params['revids'])) {
if (isset ($dataSource))
$this->dieUsage("Cannot use 'revids' at the same time as '$dataSource'", 'multisource');
$dataSource = 'revids';
switch ($dataSource) {
case 'titles' :
- $this->initFromTitles($titles);
+ $this->initFromTitles($params['titles']);
break;
case 'pageids' :
- $this->initFromPageIds($pageids);
+ $this->initFromPageIds($params['pageids']);
break;
case 'revids' :
if($this->mResolveRedirects)
$this->setWarning('Redirect resolution cannot be used together with the revids= parameter. '.
'Any redirects the revids= point to have not been resolved.');
$this->mResolveRedirects = false;
- $this->initFromRevIDs($revids);
+ $this->initFromRevIDs($params['revids']);
break;
default :
// Do nothing - some queries do not need any of the data sources.
);
public function __construct($query, $moduleName) {
- $code = $prefix = $linktbl = null;
extract($this->backlinksSettings[$moduleName]);
parent :: __construct($query, $moduleName, $code);
* Generates and outputs the result of this query based upon the provided parameters.
*/
public function execute() {
- /* Initialize vars */
- $limit = $prop = $namespace = $titles = $show = $type = $dir = $start = $end = $token = null;
-
/* Get the parameters of the request. */
- extract($this->extractRequestParams());
+ $params = $this->extractRequestParams();
/* Build our basic query. Namely, something along the lines of:
* SELECT * FROM recentchanges WHERE rc_timestamp > $start
$db = $this->getDB();
$this->addTables('recentchanges');
$this->addOption('USE INDEX', array('recentchanges' => 'rc_timestamp'));
- $this->addWhereRange('rc_timestamp', $dir, $start, $end);
- $this->addWhereFld('rc_namespace', $namespace);
+ $this->addWhereRange('rc_timestamp', $params['dir'], $params['start'], $params['end']);
+ $this->addWhereFld('rc_namespace', $params['namespace']);
$this->addWhereFld('rc_deleted', 0);
- if($titles)
+ if($params['titles'])
{
$lb = new LinkBatch;
- foreach($titles as $t)
+ foreach($params['titles'] as $t)
{
$obj = Title::newFromText($t);
$lb->addObj($obj);
$this->addWhere($where);
}
- if(!is_null($type))
- $this->addWhereFld('rc_type', $this->parseRCType($type));
+ if(!is_null($params['type']))
+ $this->addWhereFld('rc_type', $this->parseRCType($params['type']));
- if (!is_null($show)) {
- $show = array_flip($show);
+ if (!is_null($params['show'])) {
+ $show = array_flip($params['show']);
/* Check for conflicting parameters. */
if ((isset ($show['minor']) && isset ($show['!minor']))
));
/* Determine what properties we need to display. */
- if (!is_null($prop)) {
- $prop = array_flip($prop);
+ if (!is_null($params['prop'])) {
+ $prop = array_flip($params['prop']);
/* Set up internal members based upon params. */
$this->fld_comment = isset ($prop['comment']);
$this->addFields('page_is_redirect');
}
}
- $this->token = $token;
- /* Specify the limit for our query. It's $limit+1 because we (possibly) need to
- * generate a "continue" parameter, to allow paging. */
- $this->addOption('LIMIT', $limit +1);
+ $this->token = $params['token'];
+ $this->addOption('LIMIT', $params['limit'] +1);
$data = array ();
$count = 0;
/* Iterate through the rows, adding data extracted from them to our query result. */
while ($row = $db->fetchObject($res)) {
- if (++ $count > $limit) {
+ if (++ $count > $params['limit']) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->rc_timestamp));
break;
}
public function execute() {
- $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = $expandtemplates = $generatexml = $section = $token = null;
- extract($this->extractRequestParams(false));
+ $params = $this->extractRequestParams(false);
// If any of those parameters are used, work in 'enumeration' mode.
// Enum mode can only be used when exactly one page is provided.
// Enumerating revisions on multiple pages make it extremely
// difficult to manage continuations and require additional SQL indexes
- $enumRevMode = (!is_null($user) || !is_null($excludeuser) || !is_null($limit) || !is_null($startid) || !is_null($endid) || $dir === 'newer' || !is_null($start) || !is_null($end));
+ $enumRevMode = (!is_null($params['user']) || !is_null($params['excludeuser']) ||
+ !is_null($params['limit']) || !is_null($params['startid']) ||
+ !is_null($params['endid']) || $params['dir'] === 'newer' ||
+ !is_null($params['start']) || !is_null($params['end']));
$pageSet = $this->getPageSet();
$this->addTables( 'page' );
$this->addWhere('page_id = rev_page');
- $prop = array_flip($prop);
+ $prop = array_flip($params['prop']);
// Optional fields
$this->fld_ids = isset ($prop['ids']);
$this->fld_comment = isset ($prop['comment']);
$this->fld_size = isset ($prop['size']);
$this->fld_user = isset ($prop['user']);
- $this->token = $token;
+ $this->token = $params['token'];
if ( !is_null($this->token) || $pageCount > 0) {
$this->addFields( Revision::selectPageFields() );
$this->fld_content = true;
- $this->expandTemplates = $expandtemplates;
- $this->generateXML = $generatexml;
- if(isset($section))
- $this->section = $section;
+ $this->expandTemplates = $params['expandtemplates'];
+ $this->generateXML = $params['generatexml'];
+ if(isset($params['section']))
+ $this->section = $params['section'];
else
$this->section = false;
}
$userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
$botMax = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
+ $limit = $params['limit'];
if( $limit == 'max' ) {
$limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
$this->getResult()->addValue( 'limits', $this->getModuleName(), $limit );
if ($enumRevMode) {
// This is mostly to prevent parameter errors (and optimize SQL?)
- if (!is_null($startid) && !is_null($start))
+ if (!is_null($params['startid']) && !is_null($params['start']))
$this->dieUsage('start and startid cannot be used together', 'badparams');
- if (!is_null($endid) && !is_null($end))
+ if (!is_null($params['endid']) && !is_null($params['end']))
$this->dieUsage('end and endid cannot be used together', 'badparams');
- if(!is_null($user) && !is_null( $excludeuser))
+ if(!is_null($params['user']) && !is_null($params['excludeuser']))
$this->dieUsage('user and excludeuser cannot be used together', 'badparams');
// This code makes an assumption that sorting by rev_id and rev_timestamp produces
// one row with the same timestamp for the same page.
// The order needs to be the same as start parameter to avoid SQL filesort.
- if (is_null($startid) && is_null($endid))
- $this->addWhereRange('rev_timestamp', $dir, $start, $end);
+ if (is_null($params['startid']) && is_null($params['endid']))
+ $this->addWhereRange('rev_timestamp', $params['dir'],
+ $params['start'], $params['end']);
else
- $this->addWhereRange('rev_id', $dir, $startid, $endid);
+ $this->addWhereRange('rev_id', $params['dir'],
+ $params['startid'], $params['endid']);
// must manually initialize unset limit
if (is_null($limit))
// There is only one ID, use it
$this->addWhereFld('rev_page', current(array_keys($pageSet->getGoodTitles())));
- if(!is_null($user)) {
- $this->addWhereFld('rev_user_text', $user);
- } elseif (!is_null( $excludeuser)) {
- $this->addWhere('rev_user_text != ' . $this->getDB()->addQuotes($excludeuser));
+ if(!is_null($params['user'])) {
+ $this->addWhereFld('rev_user_text', $params['user']);
+ } elseif (!is_null( $params['excludeuser'])) {
+ $this->addWhere('rev_user_text != ' .
+ $this->getDB()->addQuotes($params['excludeuser']));
}
}
elseif ($revCount > 0) {
if (!$wgUser->isLoggedIn())
$this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
- $allrev = $start = $end = $namespace = $dir = $limit = $prop = $show = null;
- extract($this->extractRequestParams());
+ $params = $this->extractRequestParams();
- if (!is_null($prop) && is_null($resultPageSet)) {
+ if (!is_null($params['prop']) && is_null($resultPageSet)) {
- $prop = array_flip($prop);
+ $prop = array_flip($params['prop']);
$this->fld_ids = isset($prop['ids']);
$this->fld_title = isset($prop['title']);
$this->addFieldsIf('rc_old_len', $this->fld_sizes);
$this->addFieldsIf('rc_new_len', $this->fld_sizes);
}
- elseif ($allrev) {
+ elseif ($params['allrev']) {
$this->addFields(array (
'rc_this_oldid',
'rc_namespace',
'rc_deleted' => 0,
));
- $this->addWhereRange('rc_timestamp', $dir, $start, $end);
- $this->addWhereFld('wl_namespace', $namespace);
- $this->addWhereIf('rc_this_oldid=page_latest', !$allrev);
+ $this->addWhereRange('rc_timestamp', $params['dir'], $params['start'], $params['end']);
+ $this->addWhereFld('wl_namespace', $params['namespace']);
+ $this->addWhereIf('rc_this_oldid=page_latest', !$params['allrev']);
- if (!is_null($show)) {
- $show = array_flip($show);
+ if (!is_null($params['show'])) {
+ $show = array_flip($params['show']);
/* Check for conflicting parameters. */
if ((isset ($show['minor']) && isset ($show['!minor']))
# This is an index optimization for mysql, as done in the Special:Watchlist page
- $this->addWhereIf("rc_timestamp > ''", !isset ($start) && !isset ($end) && $wgDBtype == 'mysql');
+ $this->addWhereIf("rc_timestamp > ''", !isset ($params['start']) && !isset ($params['end']) && $wgDBtype == 'mysql');
- $this->addOption('LIMIT', $limit +1);
+ $this->addOption('LIMIT', $params['limit'] +1);
$data = array ();
$count = 0;
$db = $this->getDB();
while ($row = $db->fetchObject($res)) {
- if (++ $count > $limit) {
+ if (++ $count > $params['limit']) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->rc_timestamp));
break;
if ($vals)
$data[] = $vals;
} else {
- if ($allrev) {
+ if ($params['allrev']) {
$data[] = intval($row->rc_this_oldid);
} else {
$data[] = intval($row->rc_cur_id);
$this->getResult()->setIndexedTagName($data, 'item');
$this->getResult()->addValue('query', $this->getModuleName(), $data);
}
- elseif ($allrev) {
+ elseif ($params['allrev']) {
$resultPageSet->populateFromRevisionIDs($data);
} else {
$resultPageSet->populateFromPageIDs($data);
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg(current($retval));
- $current = $target = $summary = NULL;
- extract($details);
-
$info = array(
'title' => $titleObj->getPrefixedText(),
- 'pageid' => $current->getPage(),
- 'summary' => $summary,
+ 'pageid' => $details['current']->getPage(),
+ 'summary' => $details['summary'],
'revid' => $titleObj->getLatestRevID(),
- 'old_revid' => $current->getID(),
- 'last_revid' => $target->getID()
+ 'old_revid' => $details['current']->getID(),
+ 'last_revid' => $details['target']->getID()
);
$this->getResult()->addValue(null, $this->getModuleName(), $info);