<?php
-/*
+/**
* Created on Sep 2, 2008
*
* API for MediaWiki 1.14+
*
- * Copyright (C) 2008 Chad Horohoe
+ * Copyright © 2008 Chad Horohoe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
if ( !defined( 'MEDIAWIKI' ) ) {
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
class ApiPurge extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
/**
public function execute() {
global $wgUser;
$params = $this->extractRequestParams();
- if ( !$wgUser->isAllowed( 'purge' ) )
+ if ( !$wgUser->isAllowed( 'purge' ) ) {
$this->dieUsageMsg( array( 'cantpurge' ) );
- if ( !isset( $params['titles'] ) )
+ }
+ if ( !isset( $params['titles'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'titles' ) );
+ }
$result = array();
foreach ( $params['titles'] as $t ) {
$r = array();
$title = Title::newFromText( $t );
- if ( !$title instanceof Title )
- {
+ if ( !$title instanceof Title ) {
$r['title'] = $t;
$r['invalid'] = '';
$result[] = $r;
continue;
}
ApiQueryBase::addTitleInfo( $r, $title );
- if ( !$title->exists() )
- {
+ if ( !$title->exists() ) {
$r['missing'] = '';
$result[] = $r;
continue;
}
public function getAllowedParams() {
- return array (
+ return array(
'titles' => array(
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'titles' => 'A list of titles',
);
}
public function getDescription() {
- return array (
+ return array(
'Purge the cache for the given titles.'
);
}
-
- public function getPossibleErrors() {
+
+ public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'cantpurge' ),
array( 'missingparam', 'titles' ),
- ) );
+ ) );
}
protected function getExamples() {
<?php
-/*
+/**
* Created on Sep 7, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
private $mPageSet;
private $params, $redirect;
- private $mQueryPropModules = array (
+ private $mQueryPropModules = array(
'info' => 'ApiQueryInfo',
'revisions' => 'ApiQueryRevisions',
'links' => 'ApiQueryLinks',
'duplicatefiles' => 'ApiQueryDuplicateFiles',
);
- private $mQueryListModules = array (
+ private $mQueryListModules = array(
'allimages' => 'ApiQueryAllimages',
'allpages' => 'ApiQueryAllpages',
'alllinks' => 'ApiQueryAllLinks',
'protectedtitles' => 'ApiQueryProtectedTitles',
);
- private $mQueryMetaModules = array (
+ private $mQueryMetaModules = array(
'siteinfo' => 'ApiQuerySiteinfo',
'userinfo' => 'ApiQueryUserInfo',
'allmessages' => 'ApiQueryAllmessages',
private $mNamedDB = array();
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
// Allow custom modules to be added in LocalSettings.php
global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules;
- self :: appendUserModules( $this->mQueryPropModules, $wgAPIPropModules );
- self :: appendUserModules( $this->mQueryListModules, $wgAPIListModules );
- self :: appendUserModules( $this->mQueryMetaModules, $wgAPIMetaModules );
+ self::appendUserModules( $this->mQueryPropModules, $wgAPIPropModules );
+ self::appendUserModules( $this->mQueryListModules, $wgAPIListModules );
+ self::appendUserModules( $this->mQueryMetaModules, $wgAPIMetaModules );
$this->mPropModuleNames = array_keys( $this->mQueryPropModules );
$this->mListModuleNames = array_keys( $this->mQueryListModules );
* @return Database
*/
public function getDB() {
- if ( !isset ( $this->mSlaveDB ) ) {
+ if ( !isset( $this->mSlaveDB ) ) {
$this->profileDBIn();
$this->mSlaveDB = wfGetDB( DB_SLAVE, 'api' );
$this->profileDBOut();
// If &exportnowrap is set, use the raw formatter
if ( $this->getParameter( 'export' ) &&
$this->getParameter( 'exportnowrap' ) )
+ {
return new ApiFormatRaw( $this->getMain(),
$this->getMain()->createPrinterByName( 'xml' ) );
- else
+ } else {
return null;
+ }
}
/**
* #5 Execute all requested modules
*/
public function execute() {
-
$this->params = $this->extractRequestParams();
$this->redirects = $this->params['redirects'];
$this->mPageSet = new ApiPageSet( $this, $this->redirects );
// Instantiate requested modules
- $modules = array ();
+ $modules = array();
$this->InstantiateModules( $modules, 'prop', $this->mQueryPropModules );
$this->InstantiateModules( $modules, 'list', $this->mQueryListModules );
$this->InstantiateModules( $modules, 'meta', $this->mQueryMetaModules );
// If given, execute generator to substitute user supplied data with generated data.
- if ( isset ( $this->params['generator'] ) ) {
+ if ( isset( $this->params['generator'] ) ) {
$this->executeGeneratorModule( $this->params['generator'], $modules );
} else {
// Append custom fields and populate page/revision information
*/
private function InstantiateModules( &$modules, $param, $moduleList ) {
$list = @$this->params[$param];
- if ( !is_null ( $list ) )
- foreach ( $list as $moduleName )
+ if ( !is_null ( $list ) ) {
+ foreach ( $list as $moduleName ) {
$modules[] = new $moduleList[$moduleName] ( $this, $moduleName );
+ }
+ }
}
/**
* and missing or invalid title/pageids/revids.
*/
private function outputGeneralPageInfo() {
-
$pageSet = $this->getPageSet();
$result = $this->getResult();
// and the maximum result size must be even higher than that.
// Title normalizations
- $normValues = array ();
+ $normValues = array();
foreach ( $pageSet->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
- $normValues[] = array (
+ $normValues[] = array(
'from' => $rawTitleStr,
'to' => $titleStr
);
}
// Interwiki titles
- $intrwValues = array ();
+ $intrwValues = array();
foreach ( $pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
- $intrwValues[] = array (
+ $intrwValues[] = array(
'title' => $rawTitleStr,
'iw' => $interwikiStr
);
}
// Show redirect information
- $redirValues = array ();
+ $redirValues = array();
foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleStrTo ) {
- $redirValues[] = array (
+ $redirValues[] = array(
'from' => strval( $titleStrFrom ),
'to' => $titleStrTo
);
//
$missingRevIDs = $pageSet->getMissingRevisionIDs();
if ( count( $missingRevIDs ) ) {
- $revids = array ();
+ $revids = array();
foreach ( $missingRevIDs as $revid ) {
- $revids[$revid] = array (
+ $revids[$revid] = array(
'revid' => $revid
);
}
//
// Page elements
//
- $pages = array ();
+ $pages = array();
// Report any missing titles
foreach ( $pageSet->getMissingTitles() as $fakeId => $title ) {
$vals = array();
- ApiQueryBase :: addTitleInfo( $vals, $title );
+ ApiQueryBase::addTitleInfo( $vals, $title );
$vals['missing'] = '';
$pages[$fakeId] = $vals;
}
// Report any invalid titles
- foreach ( $pageSet->getInvalidTitles() as $fakeId => $title )
+ foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) {
$pages[$fakeId] = array( 'title' => $title, 'invalid' => '' );
+ }
// Report any missing page ids
foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
- $pages[$pageid] = array (
+ $pages[$pageid] = array(
'pageid' => $pageid,
'missing' => ''
);
foreach ( $pageSet->getGoodTitles() as $pageid => $title ) {
$vals = array();
$vals['pageid'] = $pageid;
- ApiQueryBase :: addTitleInfo( $vals, $title );
+ ApiQueryBase::addTitleInfo( $vals, $title );
$pages[$pageid] = $vals;
}
if ( count( $pages ) ) {
-
if ( $this->params['indexpageids'] ) {
$pageIDs = array_keys( $pages );
// json treats all map keys as strings - converting to match
// output with an ob
ob_start();
$exporter->openStream();
- foreach ( @$pageSet->getGoodTitles() as $title )
- if ( $title->userCanRead() )
+ foreach ( @$pageSet->getGoodTitles() as $title ) {
+ if ( $title->userCanRead() ) {
$exporter->pageByTitle( $title );
+ }
+ }
$exporter->closeStream();
$exportxml = ob_get_contents();
ob_end_clean();
* @param $modules array of module objects
*/
protected function executeGeneratorModule( $generatorName, $modules ) {
-
// Find class that implements requested generator
- if ( isset ( $this->mQueryListModules[$generatorName] ) ) {
+ if ( isset( $this->mQueryListModules[$generatorName] ) ) {
$className = $this->mQueryListModules[$generatorName];
- } elseif ( isset ( $this->mQueryPropModules[$generatorName] ) ) {
+ } elseif ( isset( $this->mQueryPropModules[$generatorName] ) ) {
$className = $this->mQueryPropModules[$generatorName];
} else {
- ApiBase :: dieDebug( __METHOD__, "Unknown generator=$generatorName" );
+ ApiBase::dieDebug( __METHOD__, "Unknown generator=$generatorName" );
}
// Generator results
// Create and execute the generator
$generator = new $className ( $this, $generatorName );
- if ( !$generator instanceof ApiQueryGeneratorBase )
- $this->dieUsage( "Module $generatorName cannot be used as a generator", "badgenerator" );
+ if ( !$generator instanceof ApiQueryGeneratorBase ) {
+ $this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' );
+ }
$generator->setGeneratorMode();
}
public function getAllowedParams() {
- return array (
- 'prop' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => $this->mPropModuleNames
+ return array(
+ 'prop' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => $this->mPropModuleNames
),
- 'list' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => $this->mListModuleNames
+ 'list' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => $this->mListModuleNames
),
- 'meta' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => $this->mMetaModuleNames
+ 'meta' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => $this->mMetaModuleNames
),
- 'generator' => array (
- ApiBase :: PARAM_TYPE => $this->mAllowedGenerators
+ 'generator' => array(
+ ApiBase::PARAM_TYPE => $this->mAllowedGenerators
),
'redirects' => false,
'indexpageids' => false,
* @return string
*/
public function makeHelpMsg() {
-
$msg = '';
// Make sure the internal object is empty
// (just in case a sub-module decides to optimize during instantiation)
$this->mPageSet = null;
- $this->mAllowedGenerators = array(); // Will be repopulated
+ $this->mAllowedGenerators = array(); // Will be repopulated
$astriks = str_repeat( '--- ', 8 );
$astriks2 = str_repeat( '*** ', 10 );
// Perform the base call last because the $this->mAllowedGenerators
// will be updated inside makeHelpMsgHelper()
// Use parent to make default message for the query module
- $msg = parent :: makeHelpMsg() . $msg;
+ $msg = parent::makeHelpMsg() . $msg;
return $msg;
}
* @return string
*/
private function makeHelpMsgHelper( $moduleList, $paramName ) {
-
- $moduleDescriptions = array ();
+ $moduleDescriptions = array();
foreach ( $moduleList as $moduleName => $moduleClass ) {
$module = new $moduleClass ( $this, $moduleName, null );
$msg = ApiMain::makeHelpMsgHeader( $module, $paramName );
$msg2 = $module->makeHelpMsg();
- if ( $msg2 !== false )
+ if ( $msg2 !== false ) {
$msg .= $msg2;
+ }
if ( $module instanceof ApiQueryGeneratorBase ) {
$this->mAllowedGenerators[] = $moduleName;
$msg .= "Generator:\n This module may be used as a generator\n";
*/
public function makeHelpMsgParameters() {
$psModule = new ApiPageSet( $this );
- return $psModule->makeHelpMsgParameters() . parent :: makeHelpMsgParameters();
+ return $psModule->makeHelpMsgParameters() . parent::makeHelpMsgParameters();
}
public function shouldCheckMaxlag() {
}
public function getParamDescription() {
- return array (
+ return array(
'prop' => 'Which properties to get for the titles/revisions/pageids',
'list' => 'Which lists to get',
'meta' => 'Which meta data to get about the site',
}
public function getDescription() {
- return array (
+ return array(
'Query API module allows applications to get needed pieces of data from the MediaWiki databases,',
'and is loosely based on the old query.php interface.',
'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites.'
);
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'badgenerator', 'info' => 'Module $generatorName cannot be used as a generator' ),
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment',
'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions',
);
public function getVersion() {
$psModule = new ApiPageSet( $this );
- $vers = array ();
+ $vers = array();
$vers[] = __CLASS__ . ': $Id$';
$vers[] = $psModule->getVersion();
return $vers;
<?php
-/*
+/**
* Created on December 12, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryAllCategories extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'ac' );
+ parent::__construct( $query, $moduleName, 'ac' );
}
public function execute() {
}
private function run( $resultPageSet = null ) {
-
$db = $this->getDB();
$params = $this->extractRequestParams();
$dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
$from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
$this->addWhereRange( 'cat_title', $dir, $from, null );
- if ( isset ( $params['prefix'] ) )
+ if ( isset( $params['prefix'] ) ) {
$this->addWhere( 'cat_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
+ }
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$this->addOption( 'ORDER BY', 'cat_title' . ( $params['dir'] == 'descending' ? ' DESC' : '' ) );
$prop = array_flip( $params['prop'] );
$this->addFieldsIf( array( 'cat_pages', 'cat_subcats', 'cat_files' ), isset( $prop['size'] ) );
- if ( isset( $prop['hidden'] ) )
- {
+ if ( isset( $prop['hidden'] ) ) {
$this->addTables( array( 'page', 'page_props' ) );
$this->addJoinConds( array(
'page' => array( 'LEFT JOIN', array(
// Normalize titles
$titleObj = Title::makeTitle( NS_CATEGORY, $row->cat_title );
- if ( !is_null( $resultPageSet ) )
+ if ( !is_null( $resultPageSet ) ) {
$pages[] = $titleObj->getPrefixedText();
- else {
+ } else {
$item = array();
$result->setContent( $item, $titleObj->getText() );
if ( isset( $prop['size'] ) ) {
$item['files'] = intval( $row->cat_files );
$item['subcats'] = intval( $row->cat_subcats );
}
- if ( isset( $prop['hidden'] ) && $row->cat_hidden )
+ if ( isset( $prop['hidden'] ) && $row->cat_hidden ) {
$item['hidden'] = '';
+ }
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $item );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->cat_title ) );
break;
}
}
public function getAllowedParams() {
- return array (
+ return array(
'from' => null,
'prefix' => null,
'dir' => array(
- ApiBase :: PARAM_DFLT => 'ascending',
- ApiBase :: PARAM_TYPE => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
'ascending',
'descending'
),
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'prop' => array (
- ApiBase :: PARAM_TYPE => array( 'size', 'hidden' ),
- ApiBase :: PARAM_DFLT => '',
- ApiBase :: PARAM_ISMULTI => true
+ 'prop' => array(
+ ApiBase::PARAM_TYPE => array( 'size', 'hidden' ),
+ ApiBase::PARAM_DFLT => '',
+ ApiBase::PARAM_ISMULTI => true
),
);
}
public function getParamDescription() {
- return array (
+ return array(
'from' => 'The category to start enumerating from.',
'prefix' => 'Search for all category titles that begin with this value.',
'dir' => 'Direction to sort in.',
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&list=allcategories&acprop=size',
'api.php?action=query&generator=allcategories&gacprefix=List&prop=info',
);
<?php
-/*
+/**
* Created on July 7, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryAllLinks extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'al' );
+ parent::__construct( $query, $moduleName, 'al' );
}
public function execute() {
}
private function run( $resultPageSet = null ) {
-
$db = $this->getDB();
$params = $this->extractRequestParams();
$fld_title = isset( $prop['title'] );
if ( $params['unique'] ) {
- if ( !is_null( $resultPageSet ) )
+ if ( !is_null( $resultPageSet ) ) {
$this->dieUsage( $this->getModuleName() . ' cannot be used as a generator in unique links mode', 'params' );
- if ( $fld_ids )
+ }
+ if ( $fld_ids ) {
$this->dieUsage( $this->getModuleName() . ' cannot return corresponding page ids in unique links mode', 'params' );
+ }
$this->addOption( 'DISTINCT' );
}
$this->addTables( 'pagelinks' );
$this->addWhereFld( 'pl_namespace', $params['namespace'] );
-
- if ( !is_null( $params['from'] ) && !is_null( $params['continue'] ) )
+
+ if ( !is_null( $params['from'] ) && !is_null( $params['continue'] ) ) {
$this->dieUsage( 'alcontinue and alfrom cannot be used together', 'params' );
- if ( !is_null( $params['continue'] ) )
- {
+ }
+ if ( !is_null( $params['continue'] ) ) {
$arr = explode( '|', $params['continue'] );
- if ( count( $arr ) != 2 )
- $this->dieUsage( "Invalid continue parameter", 'badcontinue' );
+ if ( count( $arr ) != 2 ) {
+ $this->dieUsage( 'Invalid continue parameter', 'badcontinue' );
+ }
$from = $this->getDB()->strencode( $this->titleToKey( $arr[0] ) );
$id = intval( $arr[1] );
- $this->addWhere( "pl_title > '$from' OR " .
- "(pl_title = '$from' AND " .
- "pl_from > $id)" );
+ $this->addWhere(
+ "pl_title > '$from' OR " .
+ "(pl_title = '$from' AND " .
+ "pl_from > $id)"
+ );
}
- if ( !is_null( $params['from'] ) )
+ if ( !is_null( $params['from'] ) ) {
$this->addWhere( 'pl_title>=' . $db->addQuotes( $this->titlePartToKey( $params['from'] ) ) );
- if ( isset ( $params['prefix'] ) )
+ }
+ if ( isset( $params['prefix'] ) ) {
$this->addWhere( 'pl_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
+ }
- $this->addFields( array (
+ $this->addFields( array(
'pl_title',
) );
$this->addFieldsIf( 'pl_from', !$params['unique'] );
$this->addOption( 'USE INDEX', 'pl_namespace' );
$limit = $params['limit'];
$this->addOption( 'LIMIT', $limit + 1 );
- if ( $params['unique'] )
+ if ( $params['unique'] ) {
$this->addOption( 'ORDER BY', 'pl_title' );
- else
+ } else {
$this->addOption( 'ORDER BY', 'pl_title, pl_from' );
+ }
$res = $this->select( __METHOD__ );
- $pageids = array ();
+ $pageids = array();
$count = 0;
$result = $this->getResult();
while ( $row = $db->fetchObject( $res ) ) {
if ( ++ $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
// TODO: Security issue - if the user has no right to view next title, it will still be shown
- if ( $params['unique'] )
+ if ( $params['unique'] ) {
$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->pl_title ) );
- else
+ } else {
$this->setContinueEnumParameter( 'continue', $this->keyToTitle( $row->pl_title ) . "|" . $row->pl_from );
+ }
break;
}
if ( is_null( $resultPageSet ) ) {
$vals = array();
- if ( $fld_ids )
+ if ( $fld_ids ) {
$vals['fromid'] = intval( $row->pl_from );
+ }
if ( $fld_title ) {
- $title = Title :: makeTitle( $params['namespace'], $row->pl_title );
+ $title = Title::makeTitle( $params['namespace'], $row->pl_title );
ApiQueryBase::addTitleInfo( $vals, $title );
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
- if ( !$fit )
- {
- if ( $params['unique'] )
+ if ( !$fit ) {
+ if ( $params['unique'] ) {
$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->pl_title ) );
- else
+ } else {
$this->setContinueEnumParameter( 'continue', $this->keyToTitle( $row->pl_title ) . "|" . $row->pl_from );
+ }
break;
}
} else {
}
public function getAllowedParams() {
- return array (
+ return array(
'continue' => null,
'from' => null,
'prefix' => null,
'unique' => false,
- 'prop' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_DFLT => 'title',
- ApiBase :: PARAM_TYPE => array (
+ 'prop' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_DFLT => 'title',
+ ApiBase::PARAM_TYPE => array(
'ids',
'title'
)
),
- 'namespace' => array (
- ApiBase :: PARAM_DFLT => 0,
- ApiBase :: PARAM_TYPE => 'namespace'
+ 'namespace' => array(
+ ApiBase::PARAM_DFLT => 0,
+ ApiBase::PARAM_TYPE => 'namespace'
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'from' => 'The page title to start enumerating from.',
'prefix' => 'Search for all page titles that begin with this value.',
'unique' => 'Only show unique links. Cannot be used with generator or prop=ids',
public function getDescription() {
return 'Enumerate all links that point to a given namespace';
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'params', 'info' => $this->getModuleName() . ' cannot be used as a generator in unique links mode' ),
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&list=alllinks&alunique&alfrom=B',
);
}
<?php
-/*
+/**
* Created on July 7, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryAllUsers extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'au' );
+ parent::__construct( $query, $moduleName, 'au' );
}
public function execute() {
$this->addTables( 'user', 'u1' );
$useIndex = true;
- if ( !is_null( $params['from'] ) )
+ if ( !is_null( $params['from'] ) ) {
$this->addWhere( 'u1.user_name >= ' . $db->addQuotes( $this->keyToTitle( $params['from'] ) ) );
+ }
- if ( !is_null( $params['prefix'] ) )
+ if ( !is_null( $params['prefix'] ) ) {
$this->addWhere( 'u1.user_name' . $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) );
+ }
if ( !is_null( $params['group'] ) ) {
$useIndex = false;
'ug1.ug_group' => $params['group'] ) ) ) );
}
- if ( $params['witheditsonly'] )
+ if ( $params['witheditsonly'] ) {
$this->addWhere( 'user_editcount > 0' );
+ }
if ( $fld_groups ) {
// Show the groups the given users belong to
$res = $this->select( __METHOD__ );
- $data = array ();
+ $data = array();
$count = 0;
$lastUserData = false;
$lastUser = false;
// to make sure all rows that belong to the same user are received.
//
while ( true ) {
-
$row = $db->fetchObject( $res );
$count++;
if ( !$row || $lastUser !== $row->user_name ) {
// Save the last pass's user data
- if ( is_array( $lastUserData ) )
- {
+ if ( is_array( $lastUserData ) ) {
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
null, $lastUserData );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'from',
$this->keyToTitle( $lastUserData['name'] ) );
break;
}
// No more rows left
- if ( !$row )
+ if ( !$row ) {
break;
+ }
if ( $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
$lastUserData['blockedby'] = $row->blocker_name;
$lastUserData['blockreason'] = $row->ipb_reason;
}
- if ( $fld_editcount )
+ if ( $fld_editcount ) {
$lastUserData['editcount'] = intval( $row->user_editcount );
- if ( $fld_registration )
+ }
+ if ( $fld_registration ) {
$lastUserData['registration'] = $row->user_registration ?
wfTimestamp( TS_ISO_8601, $row->user_registration ) : '';
+ }
}
if ( $sqlLimit == $count ) {
// BUG! database contains group name that User::getAllGroups() does not return
// TODO: should handle this more gracefully
- ApiBase :: dieDebug( __METHOD__,
+ ApiBase::dieDebug( __METHOD__,
'MediaWiki configuration error: the database contains more user groups than known to User::getAllGroups() function' );
}
}
public function getAllowedParams() {
- return array (
+ return array(
'from' => null,
'prefix' => null,
'group' => array(
- ApiBase :: PARAM_TYPE => User::getAllGroups()
+ ApiBase::PARAM_TYPE => User::getAllGroups()
),
- 'prop' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array (
+ 'prop' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'blockinfo',
'groups',
'editcount',
'registration'
)
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'witheditsonly' => false,
);
}
public function getParamDescription() {
- return array (
+ return array(
'from' => 'The user name to start enumerating from.',
'prefix' => 'Search for all page titles that begin with this value.',
'group' => 'Limit users to a given group name',
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&list=allusers&aufrom=Y',
);
}
<?php
-/*
+/**
* Created on Mar 16, 2008
*
* API for MediaWiki 1.12+
*
- * Copyright (C) 2008 Vasiliev Victor vasilvv@gmail.com,
+ * Copyright © 2008 Vasiliev Victor vasilvv@gmail.com,
* based on ApiQueryAllpages.php
*
* This program is free software; you can redistribute it and/or modify
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryAllimages extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'ai' );
+ parent::__construct( $query, $moduleName, 'ai' );
$this->mRepo = RepoGroup::singleton()->getLocalRepo();
}
-
+
/**
* Overide parent method to make sure to make sure the repo's DB is used
* which may not necesarilly be the same as the local DB.
- *
+ *
* TODO: allow querying non-local repos.
*/
protected function getDB() {
}
public function executeGenerator( $resultPageSet ) {
- if ( $resultPageSet->isResolvingRedirects() )
+ if ( $resultPageSet->isResolvingRedirects() ) {
$this->dieUsage( 'Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator', 'params' );
+ }
$this->run( $resultPageSet );
}
private function run( $resultPageSet = null ) {
$repo = $this->mRepo;
- if ( !$repo instanceof LocalRepo )
+ if ( !$repo instanceof LocalRepo ) {
$this->dieUsage( 'Local file repository does not support querying all images', 'unsupportedrepo' );
+ }
$db = $this->getDB();
$dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
$from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
$this->addWhereRange( 'img_name', $dir, $from, null );
- if ( isset ( $params['prefix'] ) )
+ if ( isset( $params['prefix'] ) )
$this->addWhere( 'img_name' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
- if ( isset ( $params['minsize'] ) ) {
+ if ( isset( $params['minsize'] ) ) {
$this->addWhere( 'img_size>=' . intval( $params['minsize'] ) );
}
- if ( isset ( $params['maxsize'] ) ) {
+ if ( isset( $params['maxsize'] ) ) {
$this->addWhere( 'img_size<=' . intval( $params['maxsize'] ) );
}
return array (
'from' => null,
'prefix' => null,
- 'minsize' => array (
- ApiBase :: PARAM_TYPE => 'integer',
+ 'minsize' => array(
+ ApiBase::PARAM_TYPE => 'integer',
),
- 'maxsize' => array (
- ApiBase :: PARAM_TYPE => 'integer',
+ 'maxsize' => array(
+ ApiBase::PARAM_TYPE => 'integer',
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'dir' => array (
- ApiBase :: PARAM_DFLT => 'ascending',
- ApiBase :: PARAM_TYPE => array (
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
'ascending',
'descending'
)
),
'sha1' => null,
'sha1base36' => null,
- 'prop' => array (
- ApiBase :: PARAM_TYPE => ApiQueryImageInfo::getPropertyNames(),
- ApiBase :: PARAM_DFLT => 'timestamp|url',
- ApiBase :: PARAM_ISMULTI => true
+ 'prop' => array(
+ ApiBase::PARAM_TYPE => ApiQueryImageInfo::getPropertyNames(),
+ ApiBase::PARAM_DFLT => 'timestamp|url',
+ ApiBase::PARAM_ISMULTI => true
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'from' => 'The image title to start enumerating from.',
'prefix' => 'Search for all image titles that begin with this value.',
'dir' => 'The direction in which to list',
public function getDescription() {
return 'Enumerate all images sequentially';
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'params', 'info' => 'Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator' ),
}
protected function getExamples() {
- return array (
+ return array(
'Simple Use',
' Show a list of images starting at the letter "B"',
' api.php?action=query&list=allimages&aifrom=B',
<?php
-/*
+/**
* Created on Dec 1, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryAllmessages extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'am' );
+ parent::__construct( $query, $moduleName, 'am' );
}
public function execute() {
$params = $this->extractRequestParams();
- if ( !is_null( $params['lang'] ) )
- {
+ if ( !is_null( $params['lang'] ) ) {
global $wgLang;
$wgLang = Language::factory( $params['lang'] );
}
-
+
$prop = array_flip( (array)$params['prop'] );
// Determine which messages should we print
if ( isset( $params['filter'] ) ) {
$messages_filtered = array();
foreach ( $messages_target as $message ) {
- if ( strpos( $message, $params['filter'] ) !== false ) { // !== is used because filter can be at the beginnig of the string
+ // !== is used because filter can be at the beginning of the string
+ if ( strpos( $message, $params['filter'] ) !== false ) {
$messages_filtered[] = $message;
}
}
$result = $this->getResult();
foreach ( $messages_target as $message ) {
// Skip all messages up to $params['from']
- if ( $skip && $message === $params['from'] )
+ if ( $skip && $message === $params['from'] ) {
$skip = false;
+ }
if ( !$skip ) {
$a = array( 'name' => $message );
// Check if the parser is enabled:
if ( $params['enableparser'] ) {
$msg = wfMsgExt( $message, array( 'parsemag' ), $args );
- } else if ( $args ) {
+ } elseif ( $args ) {
$msgString = wfMsgGetKey( $message, true, false, false );
$msg = wfMsgReplaceArgs( $msgString, $args );
} else {
$msg = wfMsgGetKey( $message, true, false, false );
}
- if ( wfEmptyMsg( $message, $msg ) )
+ if ( wfEmptyMsg( $message, $msg ) ) {
$a['missing'] = '';
- else {
+ } else {
ApiResult::setContent( $a, $msg );
if ( isset( $prop['default'] ) ) {
$default = wfMsgGetKey( $message, false, false, false );
if ( $default !== $msg ) {
- if ( wfEmptyMsg( $message, $default ) )
+ if ( wfEmptyMsg( $message, $default ) ) {
$a['defaultmissing'] = '';
- else
+ } else {
$a['default'] = $default;
+ }
}
}
}
}
public function getAllowedParams() {
- return array (
- 'messages' => array (
- ApiBase :: PARAM_DFLT => '*',
- ApiBase :: PARAM_ISMULTI => true,
+ return array(
+ 'messages' => array(
+ ApiBase::PARAM_DFLT => '*',
+ ApiBase::PARAM_ISMULTI => true,
),
'prop' => array(
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'default'
)
),
'enableparser' => false,
'args' => array(
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true
),
'filter' => array(),
'lang' => null,
}
public function getParamDescription() {
- return array (
+ return array(
'messages' => 'Which messages to output. "*" means all messages',
'prop' => 'Which properties to get',
'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
return array(
'api.php?action=query&meta=allmessages&amfilter=ipb-',
'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
- );
+ );
}
public function getVersion() {
<?php
-/*
+/**
* Created on Sep 25, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryAllpages extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'ap' );
+ parent::__construct( $query, $moduleName, 'ap' );
}
public function execute() {
}
public function executeGenerator( $resultPageSet ) {
- if ( $resultPageSet->isResolvingRedirects() )
+ if ( $resultPageSet->isResolvingRedirects() ) {
$this->dieUsage( 'Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params' );
+ }
$this->run( $resultPageSet );
}
// Page filters
$this->addTables( 'page' );
-
- if ( $params['filterredir'] == 'redirects' )
+
+ if ( $params['filterredir'] == 'redirects' ) {
$this->addWhereFld( 'page_is_redirect', 1 );
- else if ( $params['filterredir'] == 'nonredirects' )
+ } elseif ( $params['filterredir'] == 'nonredirects' ) {
$this->addWhereFld( 'page_is_redirect', 0 );
+ }
$this->addWhereFld( 'page_namespace', $params['namespace'] );
$dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
$from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
$this->addWhereRange( 'page_title', $dir, $from, null );
-
- if ( isset ( $params['prefix'] ) )
+
+ if ( isset( $params['prefix'] ) ) {
$this->addWhere( 'page_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
+ }
if ( is_null( $resultPageSet ) ) {
- $selectFields = array (
+ $selectFields = array(
'page_namespace',
'page_title',
'page_id'
$this->addFields( $selectFields );
$forceNameTitleIndex = true;
- if ( isset ( $params['minsize'] ) ) {
+ if ( isset( $params['minsize'] ) ) {
$this->addWhere( 'page_len>=' . intval( $params['minsize'] ) );
$forceNameTitleIndex = false;
}
- if ( isset ( $params['maxsize'] ) ) {
+ if ( isset( $params['maxsize'] ) ) {
$this->addWhere( 'page_len<=' . intval( $params['maxsize'] ) );
$forceNameTitleIndex = false;
}
// Page protection filtering
- if ( !empty ( $params['prtype'] ) ) {
+ if ( !empty( $params['prtype'] ) ) {
$this->addTables( 'page_restrictions' );
$this->addWhere( 'page_id=pr_page' );
$this->addWhere( 'pr_expiry>' . $db->addQuotes( $db->timestamp() ) );
$this->addWhereFld( 'pr_type', $params['prtype'] );
- if ( isset ( $params['prlevel'] ) ) {
+ if ( isset( $params['prlevel'] ) ) {
// Remove the empty string and '*' from the prlevel array
$prlevel = array_diff( $params['prlevel'], array( '', '*' ) );
-
- if ( !empty( $prlevel ) )
+
+ if ( !empty( $prlevel ) ) {
$this->addWhereFld( 'pr_level', $prlevel );
+ }
}
- if ( $params['prfiltercascade'] == 'cascading' )
+ if ( $params['prfiltercascade'] == 'cascading' ) {
$this->addWhereFld( 'pr_cascade', 1 );
- else if ( $params['prfiltercascade'] == 'noncascading' )
+ } elseif ( $params['prfiltercascade'] == 'noncascading' ) {
$this->addWhereFld( 'pr_cascade', 0 );
+ }
$this->addOption( 'DISTINCT' );
$forceNameTitleIndex = false;
- } else if ( isset ( $params['prlevel'] ) ) {
+ } elseif ( isset( $params['prlevel'] ) ) {
$this->dieUsage( 'prlevel may not be used without prtype', 'params' );
}
$this->addJoinConds( array( 'langlinks' => array( 'LEFT JOIN', 'page_id=ll_from' ) ) );
$this->addWhere( 'll_from IS NULL' );
$forceNameTitleIndex = false;
- } else if ( $params['filterlanglinks'] == 'withlanglinks' ) {
+ } elseif ( $params['filterlanglinks'] == 'withlanglinks' ) {
$this->addTables( 'langlinks' );
$this->addWhere( 'page_id=ll_from' );
$this->addOption( 'STRAIGHT_JOIN' );
$forceNameTitleIndex = false;
}
- if ( $forceNameTitleIndex )
+ if ( $forceNameTitleIndex ) {
$this->addOption( 'USE INDEX', 'name_title' );
+ }
$limit = $params['limit'];
$this->addOption( 'LIMIT', $limit + 1 );
}
if ( is_null( $resultPageSet ) ) {
- $title = Title :: makeTitle( $row->page_namespace, $row->page_title );
+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
$vals = array(
'pageid' => intval( $row->page_id ),
'ns' => intval( $title->getNamespace() ),
- 'title' => $title->getPrefixedText() );
+ 'title' => $title->getPrefixedText()
+ );
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->page_title ) );
break;
}
public function getAllowedParams() {
global $wgRestrictionTypes, $wgRestrictionLevels;
- return array (
+ return array(
'from' => null,
'prefix' => null,
- 'namespace' => array (
- ApiBase :: PARAM_DFLT => 0,
- ApiBase :: PARAM_TYPE => 'namespace',
+ 'namespace' => array(
+ ApiBase::PARAM_DFLT => 0,
+ ApiBase::PARAM_TYPE => 'namespace',
),
- 'filterredir' => array (
- ApiBase :: PARAM_DFLT => 'all',
- ApiBase :: PARAM_TYPE => array (
+ 'filterredir' => array(
+ ApiBase::PARAM_DFLT => 'all',
+ ApiBase::PARAM_TYPE => array(
'all',
'redirects',
'nonredirects'
)
),
- 'minsize' => array (
- ApiBase :: PARAM_TYPE => 'integer',
+ 'minsize' => array(
+ ApiBase::PARAM_TYPE => 'integer',
),
- 'maxsize' => array (
- ApiBase :: PARAM_TYPE => 'integer',
+ 'maxsize' => array(
+ ApiBase::PARAM_TYPE => 'integer',
),
- 'prtype' => array (
- ApiBase :: PARAM_TYPE => $wgRestrictionTypes,
- ApiBase :: PARAM_ISMULTI => true
+ 'prtype' => array(
+ ApiBase::PARAM_TYPE => $wgRestrictionTypes,
+ ApiBase::PARAM_ISMULTI => true
),
- 'prlevel' => array (
- ApiBase :: PARAM_TYPE => $wgRestrictionLevels,
- ApiBase :: PARAM_ISMULTI => true
+ 'prlevel' => array(
+ ApiBase::PARAM_TYPE => $wgRestrictionLevels,
+ ApiBase::PARAM_ISMULTI => true
),
- 'prfiltercascade' => array (
- ApiBase :: PARAM_DFLT => 'all',
- ApiBase :: PARAM_TYPE => array (
+ 'prfiltercascade' => array(
+ ApiBase::PARAM_DFLT => 'all',
+ ApiBase::PARAM_TYPE => array(
'cascading',
'noncascading',
'all'
),
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'dir' => array (
- ApiBase :: PARAM_DFLT => 'ascending',
- ApiBase :: PARAM_TYPE => array (
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
'ascending',
'descending'
)
),
'filterlanglinks' => array(
- ApiBase :: PARAM_TYPE => array(
+ ApiBase::PARAM_TYPE => array(
'withlanglinks',
'withoutlanglinks',
'all'
),
- ApiBase :: PARAM_DFLT => 'all'
+ ApiBase::PARAM_DFLT => 'all'
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'from' => 'The page title to start enumerating from.',
'prefix' => 'Search for all page titles that begin with this value.',
'namespace' => 'The namespace to enumerate.',
public function getDescription() {
return 'Enumerate all pages sequentially in a given namespace';
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'params', 'info' => 'Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator' ),
}
protected function getExamples() {
- return array (
+ return array(
'Simple Use',
' Show a list of pages starting at the letter "B"',
' api.php?action=query&list=allpages&apfrom=B',
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiQueryBase.php" );
+ require_once( "ApiQueryBase.php" );
}
/**
private $pageMap, $resultArr;
// output element name, database column field prefix, database table
- private $backlinksSettings = array (
- 'backlinks' => array (
+ private $backlinksSettings = array(
+ 'backlinks' => array(
'code' => 'bl',
'prefix' => 'pl',
'linktbl' => 'pagelinks'
),
- 'embeddedin' => array (
+ 'embeddedin' => array(
'code' => 'ei',
'prefix' => 'tl',
'linktbl' => 'templatelinks'
),
- 'imageusage' => array (
+ 'imageusage' => array(
'code' => 'iu',
'prefix' => 'il',
'linktbl' => 'imagelinks'
extract( $this->backlinksSettings[$moduleName] );
$this->resultArr = array();
- parent :: __construct( $query, $moduleName, $code );
+ parent::__construct( $query, $moduleName, $code );
$this->bl_ns = $prefix . '_namespace';
$this->bl_from = $prefix . '_from';
$this->bl_table = $linktbl;
if ( $this->hasNS ) {
$this->bl_title = $prefix . '_title';
$this->bl_sort = "{$this->bl_ns}, {$this->bl_title}, {$this->bl_from}";
- $this->bl_fields = array (
+ $this->bl_fields = array(
$this->bl_ns,
$this->bl_title
);
} else {
$this->bl_title = $prefix . '_to';
$this->bl_sort = "{$this->bl_title}, {$this->bl_from}";
- $this->bl_fields = array (
+ $this->bl_fields = array(
$this->bl_title
);
}
$db = $this->getDB();
$this->addTables( array( $this->bl_table, 'page' ) );
$this->addWhere( "{$this->bl_from}=page_id" );
- if ( is_null( $resultPageSet ) )
+ if ( is_null( $resultPageSet ) ) {
$this->addFields( array( 'page_id', 'page_title', 'page_namespace' ) );
- else
+ } else {
$this->addFields( $resultPageSet->getPageTableFields() );
+ }
$this->addFields( 'page_is_redirect' );
$this->addWhereFld( $this->bl_title, $this->rootTitle->getDBkey() );
- if ( $this->hasNS )
+ if ( $this->hasNS ) {
$this->addWhereFld( $this->bl_ns, $this->rootTitle->getNamespace() );
+ }
$this->addWhereFld( 'page_namespace', $this->params['namespace'] );
- if ( !is_null( $this->contID ) )
+ if ( !is_null( $this->contID ) ) {
$this->addWhere( "{$this->bl_from}>={$this->contID}" );
+ }
- if ( $this->params['filterredir'] == 'redirects' )
+ if ( $this->params['filterredir'] == 'redirects' ) {
$this->addWhereFld( 'page_is_redirect', 1 );
- else if ( $this->params['filterredir'] == 'nonredirects' && !$this->redirect )
+ } elseif ( $this->params['filterredir'] == 'nonredirects' && !$this->redirect ) {
// bug 22245 - Check for !redirect, as filtering nonredirects, when getting what links to them is contradictory
$this->addWhereFld( 'page_is_redirect', 0 );
+ }
$this->addOption( 'LIMIT', $this->params['limit'] + 1 );
$this->addOption( 'ORDER BY', $this->bl_from );
$this->addTables( array( 'page', $this->bl_table ) );
$this->addWhere( "{$this->bl_from}=page_id" );
- if ( is_null( $resultPageSet ) )
+ if ( is_null( $resultPageSet ) ) {
$this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect' ) );
- else
+ } else {
$this->addFields( $resultPageSet->getPageTableFields() );
+ }
$this->addFields( $this->bl_title );
- if ( $this->hasNS )
+ if ( $this->hasNS ) {
$this->addFields( $this->bl_ns );
+ }
// We can't use LinkBatch here because $this->hasNS may be false
$titleWhere = array();
- foreach ( $this->redirTitles as $t )
+ foreach ( $this->redirTitles as $t ) {
$titleWhere[] = "{$this->bl_title} = " . $db->addQuotes( $t->getDBkey() ) .
- ( $this->hasNS ? " AND {$this->bl_ns} = '{$t->getNamespace()}'" : "" );
+ ( $this->hasNS ? " AND {$this->bl_ns} = '{$t->getNamespace()}'" : '' );
+ }
$this->addWhere( $db->makeList( $titleWhere, LIST_OR ) );
$this->addWhereFld( 'page_namespace', $this->params['namespace'] );
- if ( !is_null( $this->redirID ) )
- {
+ if ( !is_null( $this->redirID ) ) {
$first = $this->redirTitles[0];
$title = $db->strencode( $first->getDBkey() );
$ns = $first->getNamespace();
$from = $this->redirID;
- if ( $this->hasNS )
+ if ( $this->hasNS ) {
$this->addWhere( "{$this->bl_ns} > $ns OR " .
"({$this->bl_ns} = $ns AND " .
"({$this->bl_title} > '$title' OR " .
"({$this->bl_title} = '$title' AND " .
"{$this->bl_from} >= $from)))" );
- else
+ } else {
$this->addWhere( "{$this->bl_title} > '$title' OR " .
"({$this->bl_title} = '$title' AND " .
"{$this->bl_from} >= $from)" );
-
+ }
}
- if ( $this->params['filterredir'] == 'redirects' )
+ if ( $this->params['filterredir'] == 'redirects' ) {
$this->addWhereFld( 'page_is_redirect', 1 );
- else if ( $this->params['filterredir'] == 'nonredirects' )
+ } elseif ( $this->params['filterredir'] == 'nonredirects' ) {
$this->addWhereFld( 'page_is_redirect', 0 );
+ }
$this->addOption( 'LIMIT', $this->params['limit'] + 1 );
$this->addOption( 'ORDER BY', $this->bl_sort );
break;
}
- if ( is_null( $resultPageSet ) )
+ if ( is_null( $resultPageSet ) ) {
$this->extractRowInfo( $row );
- else
- {
+ } else {
$this->pageMap[$row->page_namespace][$row->page_title] = $row->page_id;
- if ( $row->page_is_redirect )
+ if ( $row->page_is_redirect ) {
$this->redirTitles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
+ }
$resultPageSet->processDbRow( $row );
}
}
$db->freeResult( $res );
- if ( $this->redirect && count( $this->redirTitles ) )
- {
+ if ( $this->redirect && count( $this->redirTitles ) ) {
$this->resetQueryParams();
$this->prepareSecondQuery( $resultPageSet );
$res = $this->select( __METHOD__ . '::secondQuery' );
$count = 0;
- while ( $row = $db->fetchObject( $res ) )
- {
- if ( ++$count > $this->params['limit'] )
- {
+ while ( $row = $db->fetchObject( $res ) ) {
+ if ( ++$count > $this->params['limit'] ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
// We need to keep the parent page of this redir in
- if ( $this->hasNS )
+ if ( $this->hasNS ) {
$parentID = $this->pageMap[$row-> { $this->bl_ns } ][$row-> { $this->bl_title } ];
- else
- $parentID = $this->pageMap[NS_IMAGE][$row-> { $this->bl_title } ];
+ } else {
+ $parentID = $this->pageMap[NS_IMAGE][$row->{$this->bl_title}];
+ }
$this->continueStr = $this->getContinueRedirStr( $parentID, $row->page_id );
break;
}
- if ( is_null( $resultPageSet ) )
+ if ( is_null( $resultPageSet ) ) {
$this->extractRedirRowInfo( $row );
- else
+ } else {
$resultPageSet->processDbRow( $row );
+ }
}
$db->freeResult( $res );
}
if ( is_null( $resultPageSet ) ) {
// Try to add the result data in one go and pray that it fits
$fit = $this->getResult()->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) );
- if ( !$fit )
- {
+ if ( !$fit ) {
// It didn't fit. Add elements one by one until the
// result is full.
- foreach ( $this->resultArr as $pageID => $arr )
- {
+ foreach ( $this->resultArr as $pageID => $arr ) {
// Add the basic entry without redirlinks first
$fit = $this->getResult()->addValue(
array( 'query', $this->getModuleName() ),
null, array_diff_key( $arr, array( 'redirlinks' => '' ) ) );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->continueStr = $this->getContinueStr( $pageID );
break;
}
$hasRedirs = false;
- foreach ( (array)@$arr['redirlinks'] as $key => $redir )
- {
+ foreach ( (array)@$arr['redirlinks'] as $key => $redir ) {
$fit = $this->getResult()->addValue(
array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
$key, $redir );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->continueStr = $this->getContinueRedirStr( $pageID, $redir['pageid'] );
break;
}
$hasRedirs = true;
}
- if ( $hasRedirs )
+ if ( $hasRedirs ) {
$this->getResult()->setIndexedTagName_internal(
array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
$this->bl_code );
- if ( !$fit )
+ }
+ if ( !$fit ) {
break;
+ }
}
}
$this->getResult()->setIndexedTagName_internal(
- array( 'query', $this->getModuleName() ),
- $this->bl_code );
+ array( 'query', $this->getModuleName() ),
+ $this->bl_code
+ );
}
- if ( !is_null( $this->continueStr ) )
+ if ( !is_null( $this->continueStr ) ) {
$this->setContinueEnumParameter( 'continue', $this->continueStr );
+ }
}
private function extractRowInfo( $row ) {
$t = Title::makeTitle( $row->page_namespace, $row->page_title );
$a = array( 'pageid' => intval( $row->page_id ) );
ApiQueryBase::addTitleInfo( $a, $t );
- if ( $row->page_is_redirect )
- {
+ if ( $row->page_is_redirect ) {
$a['redirect'] = '';
$this->redirTitles[] = $t;
}
$this->resultArr[$a['pageid']] = $a;
}
- private function extractRedirRowInfo( $row )
- {
+ private function extractRedirRowInfo( $row ) {
$a['pageid'] = intval( $row->page_id );
ApiQueryBase::addTitleInfo( $a, Title::makeTitle( $row->page_namespace, $row->page_title ) );
- if ( $row->page_is_redirect )
+ if ( $row->page_is_redirect ) {
$a['redirect'] = '';
+ }
$ns = $this->hasNS ? $row-> { $this->bl_ns } : NS_FILE;
$parentID = $this->pageMap[$ns][$row-> { $this->bl_title } ];
// Put all the results in an array first
}
protected function processContinue() {
- if ( !is_null( $this->params['continue'] ) )
+ if ( !is_null( $this->params['continue'] ) ) {
$this->parseContinueParam();
- else {
- if ( $this->params['title'] !== "" ) {
+ } else {
+ if ( $this->params['title'] !== '' ) {
$title = Title::newFromText( $this->params['title'] );
if ( !$title ) {
$this->dieUsageMsg( array( 'invalidtitle', $this->params['title'] ) );
}
// only image titles are allowed for the root in imageinfo mode
- if ( !$this->hasNS && $this->rootTitle->getNamespace() !== NS_FILE )
+ if ( !$this->hasNS && $this->rootTitle->getNamespace() !== NS_FILE ) {
$this->dieUsage( "The title for {$this->getModuleName()} query must be an image", 'bad_image_title' );
+ }
}
protected function parseContinueParam() {
// null stuff out now so we know what's set and what isn't
$this->rootTitle = $this->contID = $this->redirID = null;
$rootNs = intval( $continueList[0] );
- if ( $rootNs === 0 && $continueList[0] !== '0' )
+ if ( $rootNs === 0 && $continueList[0] !== '0' ) {
// Illegal continue parameter
- $this->dieUsage( "Invalid continue param. You should pass the original value returned by the previous query", "_badcontinue" );
+ $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', '_badcontinue' );
+ }
$this->rootTitle = Title::makeTitleSafe( $rootNs, $continueList[1] );
- if ( !$this->rootTitle )
- $this->dieUsage( "Invalid continue param. You should pass the original value returned by the previous query", "_badcontinue" );
+ if ( !$this->rootTitle ) {
+ $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', '_badcontinue' );
+ }
$contID = intval( $continueList[2] );
- if ( $contID === 0 && $continueList[2] !== '0' )
- $this->dieUsage( "Invalid continue param. You should pass the original value returned by the previous query", "_badcontinue" );
+ if ( $contID === 0 && $continueList[2] !== '0' ) {
+ $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', '_badcontinue' );
+ }
$this->contID = $contID;
$redirID = intval( @$continueList[3] );
-
- if ( $redirID === 0 && @$continueList[3] !== '0' )
+
+ if ( $redirID === 0 && @$continueList[3] !== '0' ) {
// This one isn't required
return;
+ }
$this->redirID = $redirID;
}
}
public function getAllowedParams() {
- $retval = array (
+ $retval = array(
'title' => null,
'continue' => null,
- 'namespace' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => 'namespace'
+ 'namespace' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => 'namespace'
),
'filterredir' => array(
- ApiBase :: PARAM_DFLT => 'all',
- ApiBase :: PARAM_TYPE => array(
+ ApiBase::PARAM_DFLT => 'all',
+ ApiBase::PARAM_TYPE => array(
'all',
'redirects',
'nonredirects'
)
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
)
);
- if ( $this->getModuleName() == 'embeddedin' )
+ if ( $this->getModuleName() == 'embeddedin' ) {
return $retval;
+ }
$retval['redirect'] = false;
return $retval;
}
public function getParamDescription() {
- $retval = array (
+ $retval = array(
'title' => 'Title to search.',
'continue' => 'When more results are available, use this to continue.',
'namespace' => 'The namespace to enumerate.',
);
- if ( $this->getModuleName() != 'embeddedin' )
+ if ( $this->getModuleName() != 'embeddedin' ) {
return array_merge( $retval, array(
'redirect' => 'If linking page is a redirect, find all pages that link to that redirect as well. Maximum limit is halved.',
'filterredir' => "How to filter for redirects. If set to nonredirects when {$this->bl_code}redirect is enabled, this is only applied to the second level",
'limit' => "How many total pages to return. If {$this->bl_code}redirect is enabled, limit applies to each level separately (which means you may get up to 2 * limit results)."
) );
+ }
return array_merge( $retval, array(
'filterredir' => 'How to filter for redirects',
'limit' => 'How many total pages to return.'
public function getDescription() {
switch ( $this->getModuleName() ) {
- case 'backlinks' :
+ case 'backlinks':
return 'Find all pages that link to the given page';
- case 'embeddedin' :
+ case 'embeddedin':
return 'Find all pages that embed (transclude) the given title';
- case 'imageusage' :
+ case 'imageusage':
return 'Find all pages that use the given image title.';
- default :
- ApiBase :: dieDebug( __METHOD__, 'Unknown module name' );
+ default:
+ ApiBase::dieDebug( __METHOD__, 'Unknown module name' );
}
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'invalidtitle', 'title' ),
}
protected function getExamples() {
- static $examples = array (
- 'backlinks' => array (
- "api.php?action=query&list=backlinks&bltitle=Main%20Page",
- "api.php?action=query&generator=backlinks&gbltitle=Main%20Page&prop=info"
+ static $examples = array(
+ 'backlinks' => array(
+ 'api.php?action=query&list=backlinks&bltitle=Main%20Page',
+ 'api.php?action=query&generator=backlinks&gbltitle=Main%20Page&prop=info'
),
- 'embeddedin' => array (
- "api.php?action=query&list=embeddedin&eititle=Template:Stub",
- "api.php?action=query&generator=embeddedin&geititle=Template:Stub&prop=info"
+ 'embeddedin' => array(
+ 'api.php?action=query&list=embeddedin&eititle=Template:Stub',
+ 'api.php?action=query&generator=embeddedin&geititle=Template:Stub&prop=info'
),
- 'imageusage' => array (
- "api.php?action=query&list=imageusage&iutitle=File:Albert%20Einstein%20Head.jpg",
- "api.php?action=query&generator=imageusage&giutitle=File:Albert%20Einstein%20Head.jpg&prop=info"
+ 'imageusage' => array(
+ 'api.php?action=query&list=imageusage&iutitle=File:Albert%20Einstein%20Head.jpg',
+ 'api.php?action=query&generator=imageusage&giutitle=File:Albert%20Einstein%20Head.jpg&prop=info'
)
);
<?php
-/*
+/**
* Created on Sep 7, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds;
public function __construct( $query, $moduleName, $paramPrefix = '' ) {
- parent :: __construct( $query->getMain(), $moduleName, $paramPrefix );
+ parent::__construct( $query->getMain(), $moduleName, $paramPrefix );
$this->mQueryModule = $query;
$this->mDb = null;
$this->resetQueryParams();
* Blank the internal arrays with query parameters
*/
protected function resetQueryParams() {
- $this->tables = array ();
- $this->where = array ();
- $this->fields = array ();
- $this->options = array ();
- $this->join_conds = array ();
+ $this->tables = array();
+ $this->where = array();
+ $this->fields = array();
+ $this->options = array();
+ $this->join_conds = array();
}
/**
*/
protected function addTables( $tables, $alias = null ) {
if ( is_array( $tables ) ) {
- if ( !is_null( $alias ) )
- ApiBase :: dieDebug( __METHOD__, 'Multiple table aliases not supported' );
+ if ( !is_null( $alias ) ) {
+ ApiBase::dieDebug( __METHOD__, 'Multiple table aliases not supported' );
+ }
$this->tables = array_merge( $this->tables, $tables );
} else {
- if ( !is_null( $alias ) )
+ if ( !is_null( $alias ) ) {
$tables = $this->getAliasedName( $tables, $alias );
+ }
$this->tables[] = $tables;
}
}
-
+
/**
* Get the SQL for a table name with alias
* @param $table string Table name
protected function getAliasedName( $table, $alias ) {
return $this->getDB()->tableName( $table ) . ' ' . $alias;
}
-
+
/**
* Add a set of JOIN conditions to the internal array
*
* @param $join_conds array JOIN conditions
*/
protected function addJoinConds( $join_conds ) {
- if ( !is_array( $join_conds ) )
+ if ( !is_array( $join_conds ) ) {
ApiBase::dieDebug( __METHOD__, 'Join conditions have to be arrays' );
+ }
$this->join_conds = array_merge( $this->join_conds, $join_conds );
}
* @param $value mixed Field name or array of field names
*/
protected function addFields( $value ) {
- if ( is_array( $value ) )
+ if ( is_array( $value ) ) {
$this->fields = array_merge( $this->fields, $value );
- else
+ } else {
$this->fields[] = $value;
+ }
}
/**
if ( is_array( $value ) ) {
// Sanity check: don't insert empty arrays,
// Database::makeList() chokes on them
- if ( count( $value ) )
+ if ( count( $value ) ) {
$this->where = array_merge( $this->where, $value );
- }
- else
+ }
+ } else {
$this->where[] = $value;
+ }
}
/**
* @param $value string Value; ignored if null or empty array;
*/
protected function addWhereFld( $field, $value ) {
- // Use count() to its full documented capabilities to simultaneously
+ // Use count() to its full documented capabilities to simultaneously
// test for null, empty array or empty countable object
- if ( count( $value ) )
+ if ( count( $value ) ) {
$this->where[$field] = $value;
+ }
}
/**
$before = ( $isDirNewer ? '<=' : '>=' );
$db = $this->getDB();
- if ( !is_null( $start ) )
+ if ( !is_null( $start ) ) {
$this->addWhere( $field . $after . $db->addQuotes( $start ) );
+ }
- if ( !is_null( $end ) )
+ if ( !is_null( $end ) ) {
$this->addWhere( $field . $before . $db->addQuotes( $end ) );
+ }
if ( $sort ) {
$order = $field . ( $isDirNewer ? '' : ' DESC' );
- if ( !isset( $this->options['ORDER BY'] ) )
+ if ( !isset( $this->options['ORDER BY'] ) ) {
$this->addOption( 'ORDER BY', $order );
- else
+ } else {
$this->addOption( 'ORDER BY', $this->options['ORDER BY'] . ', ' . $order );
+ }
}
}
* @param $value string Option value
*/
protected function addOption( $name, $value = null ) {
- if ( is_null( $value ) )
+ if ( is_null( $value ) ) {
$this->options[] = $name;
- else
+ } else {
$this->options[$name] = $value;
+ }
}
/**
$this->profileDBOut();
global $wgAPIMaxDBRows;
- if ( $rowcount > $wgAPIMaxDBRows )
+ if ( $rowcount > $wgAPIMaxDBRows ) {
return false;
+ }
return true;
}
/**
* Add a sub-element under the page element with the given page ID
* @param $pageId int Page ID
- * @param $data array Data array à la ApiResult
+ * @param $data array Data array à la ApiResult
* @return bool Whether the element fit in the result
*/
protected function addPageSubItems( $pageId, $data ) {
$this->getModuleName(),
$data );
}
-
+
/**
* Same as addPageSubItems(), but one element of $data at a time
* @param $pageId int Page ID
* @return bool Whether the element fit in the result
*/
protected function addPageSubItem( $pageId, $item, $elemname = null ) {
- if ( is_null( $elemname ) )
+ if ( is_null( $elemname ) ) {
$elemname = $this->getModulePrefix();
+ }
$result = $this->getResult();
$fit = $result->addValue( array( 'query', 'pages', $pageId,
$this->getModuleName() ), null, $item );
- if ( !$fit )
+ if ( !$fit ) {
return false;
+ }
$result->setIndexedTagName_internal( array( 'query', 'pages', $pageId,
$this->getModuleName() ), $elemname );
return true;
* @return Database
*/
protected function getDB() {
- if ( is_null( $this->mDb ) )
+ if ( is_null( $this->mDb ) ) {
$this->mDb = $this->getQuery()->getDB();
+ }
return $this->mDb;
}
* @param $name string Name to assign to the database connection
* @param $db int One of the DB_* constants
* @param $groups array Query groups
- * @return Database
+ * @return Database
*/
public function selectNamedDB( $name, $db, $groups ) {
$this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups );
*/
public function titleToKey( $title ) {
// Don't throw an error if we got an empty string
- if ( trim( $title ) == '' )
+ if ( trim( $title ) == '' ) {
return '';
+ }
$t = Title::newFromText( $title );
- if ( !$t )
+ if ( !$t ) {
$this->dieUsageMsg( array( 'invalidtitle', $title ) );
+ }
return $t->getPrefixedDbKey();
}
*/
public function keyToTitle( $key ) {
// Don't throw an error if we got an empty string
- if ( trim( $key ) == '' )
+ if ( trim( $key ) == '' ) {
return '';
+ }
$t = Title::newFromDbKey( $key );
// This really shouldn't happen but we gotta check anyway
- if ( !$t )
+ if ( !$t ) {
$this->dieUsageMsg( array( 'invalidtitle', $key ) );
+ }
return $t->getPrefixedText();
}
-
+
/**
* An alternative to titleToKey() that doesn't trim trailing spaces
* @param $titlePart string Title part with spaces
public function titlePartToKey( $titlePart ) {
return substr( $this->titleToKey( $titlePart . 'x' ), 0, - 1 );
}
-
+
/**
* An alternative to keyToTitle() that doesn't trim trailing spaces
* @param $keyPart string Key part with spaces
public function keyPartToTitle( $keyPart ) {
return substr( $this->keyToTitle( $keyPart . 'x' ), 0, - 1 );
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'invalidtitle', 'title' ),
private $mIsGenerator;
public function __construct( $query, $moduleName, $paramPrefix = '' ) {
- parent :: __construct( $query, $moduleName, $paramPrefix );
+ parent::__construct( $query, $moduleName, $paramPrefix );
$this->mIsGenerator = false;
}
* @return string Prefixed parameter name
*/
public function encodeParamName( $paramName ) {
- if ( $this->mIsGenerator )
- return 'g' . parent :: encodeParamName( $paramName );
- else
- return parent :: encodeParamName( $paramName );
+ if ( $this->mIsGenerator ) {
+ return 'g' . parent::encodeParamName( $paramName );
+ } else {
+ return parent::encodeParamName( $paramName );
+ }
}
/**