*
* @var array
*/
- private $pageMap = array();
+ private $pageMap = [];
private $resultArr;
- private $redirTitles = array();
+ private $redirTitles = [];
private $continueStr = null;
// output element name, database column field prefix, database table
- private $backlinksSettings = array(
- 'backlinks' => array(
+ private $backlinksSettings = [
+ 'backlinks' => [
'code' => 'bl',
'prefix' => 'pl',
'linktbl' => 'pagelinks',
'helpurl' => 'https://www.mediawiki.org/wiki/API:Backlinks',
- ),
- 'embeddedin' => array(
+ ],
+ 'embeddedin' => [
'code' => 'ei',
'prefix' => 'tl',
'linktbl' => 'templatelinks',
'helpurl' => 'https://www.mediawiki.org/wiki/API:Embeddedin',
- ),
- 'imageusage' => array(
+ ],
+ 'imageusage' => [
'code' => 'iu',
'prefix' => 'il',
'linktbl' => 'imagelinks',
'helpurl' => 'https://www.mediawiki.org/wiki/API:Imageusage',
- )
- );
+ ]
+ ];
public function __construct( ApiQuery $query, $moduleName ) {
$settings = $this->backlinksSettings[$moduleName];
$prefix = $settings['prefix'];
$code = $settings['code'];
- $this->resultArr = array();
+ $this->resultArr = [];
parent::__construct( $query, $moduleName, $code );
$this->bl_ns = $prefix . '_namespace';
$this->hasNS = $moduleName !== 'imageusage';
if ( $this->hasNS ) {
$this->bl_title = $prefix . '_title';
- $this->bl_fields = array(
+ $this->bl_fields = [
$this->bl_ns,
$this->bl_title
- );
+ ];
} else {
$this->bl_title = $prefix . '_to';
- $this->bl_fields = array(
+ $this->bl_fields = [
$this->bl_title
- );
+ ];
}
}
* @return void
*/
private function runFirstQuery( $resultPageSet = null ) {
- $this->addTables( array( $this->bl_table, 'page' ) );
+ $this->addTables( [ $this->bl_table, 'page' ] );
$this->addWhere( "{$this->bl_from}=page_id" );
if ( is_null( $resultPageSet ) ) {
- $this->addFields( array( 'page_id', 'page_title', 'page_namespace' ) );
+ $this->addFields( [ 'page_id', 'page_title', 'page_namespace' ] );
} else {
$this->addFields( $resultPageSet->getPageTableFields() );
}
- $this->addFields( array( 'page_is_redirect', 'from_ns' => 'page_namespace' ) );
+ $this->addFields( [ 'page_is_redirect', 'from_ns' => 'page_namespace' ] );
$this->addWhereFld( $this->bl_title, $this->rootTitle->getDBkey() );
if ( $this->hasNS ) {
$this->addOption( 'LIMIT', $this->params['limit'] + 1 );
$sort = ( $this->params['dir'] == 'descending' ? ' DESC' : '' );
- $orderBy = array();
+ $orderBy = [];
if ( count( $this->params['namespace'] ) > 1 ) {
$orderBy[] = $this->bl_from_ns . $sort;
}
}
if ( is_null( $resultPageSet ) ) {
- $a = array( 'pageid' => intval( $row->page_id ) );
+ $a = [ 'pageid' => intval( $row->page_id ) ];
ApiQueryBase::addTitleInfo( $a, $t );
if ( $row->page_is_redirect ) {
$a['redirect'] = true;
*/
private function runSecondQuery( $resultPageSet = null ) {
$db = $this->getDB();
- $this->addTables( array( 'page', $this->bl_table ) );
+ $this->addTables( [ 'page', $this->bl_table ] );
$this->addWhere( "{$this->bl_from}=page_id" );
if ( is_null( $resultPageSet ) ) {
- $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect' ) );
+ $this->addFields( [ 'page_id', 'page_title', 'page_namespace', 'page_is_redirect' ] );
} else {
$this->addFields( $resultPageSet->getPageTableFields() );
}
- $this->addFields( array( $this->bl_title, 'from_ns' => 'page_namespace' ) );
+ $this->addFields( [ $this->bl_title, 'from_ns' => 'page_namespace' ] );
if ( $this->hasNS ) {
$this->addFields( $this->bl_ns );
}
// We can't use LinkBatch here because $this->hasNS may be false
- $titleWhere = array();
- $allRedirNs = array();
- $allRedirDBkey = array();
+ $titleWhere = [];
+ $allRedirNs = [];
+ $allRedirDBkey = [];
/** @var $t Title */
foreach ( $this->redirTitles as $t ) {
$redirNs = $t->getNamespace();
}
$this->addOption( 'LIMIT', $this->params['limit'] + 1 );
- $orderBy = array();
+ $orderBy = [];
$sort = ( $this->params['dir'] == 'descending' ? ' DESC' : '' );
// Don't order by namespace/title/from_namespace if it's constant in the WHERE clause
if ( $this->hasNS && count( $allRedirNs ) > 1 ) {
}
$orderBy[] = $this->bl_from . $sort;
$this->addOption( 'ORDER BY', $orderBy );
- $this->addOption( 'USE INDEX', array( 'page' => 'PRIMARY' ) );
+ $this->addOption( 'USE INDEX', [ 'page' => 'PRIMARY' ] );
$res = $this->select( __METHOD__ );
$count = 0;
// Note we must keep the parameters for the first query constant
// This may be overridden at a later step
$title = $row->{$this->bl_title};
- $this->continueStr = join( '|', array_slice( $this->cont, 0, 2 ) ) .
+ $this->continueStr = implode( '|', array_slice( $this->cont, 0, 2 ) ) .
"|$ns|$title|{$row->from_ns}|{$row->page_id}";
break;
}
}
// Parse and validate continuation parameter
- $this->cont = array();
+ $this->cont = [];
if ( $this->params['continue'] !== null ) {
$cont = explode( '|', $this->params['continue'] );
}
// Fill in any missing fields in case it's needed below
- $this->cont += array( 0, 0, 0, '', 0, 0, 0 );
+ $this->cont += [ 0, 0, 0, '', 0, 0, 0 ];
if ( is_null( $resultPageSet ) ) {
// Try to add the result data in one go and pray that it fits
// Add the basic entry without redirlinks first
$fit = $result->addValue(
- array( 'query', $this->getModuleName() ),
- $idx, array_diff_key( $arr, array( 'redirlinks' => '' ) ) );
+ [ 'query', $this->getModuleName() ],
+ $idx, array_diff_key( $arr, [ 'redirlinks' => '' ] ) );
if ( !$fit ) {
- $this->continueStr = join( '|', array_slice( $this->cont, 0, 6 ) ) .
+ $this->continueStr = implode( '|', array_slice( $this->cont, 0, 6 ) ) .
"|$pageID";
break;
}
$hasRedirs = false;
- $redirLinks = isset( $arr['redirlinks'] ) ? (array)$arr['redirlinks'] : array();
+ $redirLinks = isset( $arr['redirlinks'] ) ? (array)$arr['redirlinks'] : [];
ksort( $redirLinks );
if ( count( $this->cont ) >= 8 && $pageID == $startAt ) {
$redirStartAt = $this->cont[7];
}
$fit = $result->addValue(
- array( 'query', $this->getModuleName(), $idx, 'redirlinks' ),
+ [ 'query', $this->getModuleName(), $idx, 'redirlinks' ],
null, $redir );
if ( !$fit ) {
- $this->continueStr = join( '|', array_slice( $this->cont, 0, 6 ) ) .
+ $this->continueStr = implode( '|', array_slice( $this->cont, 0, 6 ) ) .
"|$pageID|$key";
break;
}
}
if ( $hasRedirs ) {
$result->addIndexedTagName(
- array( 'query', $this->getModuleName(), $idx, 'redirlinks' ),
+ [ 'query', $this->getModuleName(), $idx, 'redirlinks' ],
$this->bl_code );
}
if ( !$fit ) {
}
$result->addIndexedTagName(
- array( 'query', $this->getModuleName() ),
+ [ 'query', $this->getModuleName() ],
$this->bl_code
);
}
}
public function getAllowedParams() {
- $retval = array(
- 'title' => array(
+ $retval = [
+ 'title' => [
ApiBase::PARAM_TYPE => 'string',
- ),
- 'pageid' => array(
+ ],
+ 'pageid' => [
ApiBase::PARAM_TYPE => 'integer',
- ),
- 'continue' => array(
+ ],
+ 'continue' => [
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
- ),
- 'namespace' => array(
+ ],
+ 'namespace' => [
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => 'namespace'
- ),
- 'dir' => array(
+ ],
+ 'dir' => [
ApiBase::PARAM_DFLT => 'ascending',
- ApiBase::PARAM_TYPE => array(
+ ApiBase::PARAM_TYPE => [
'ascending',
'descending'
- )
- ),
- 'filterredir' => array(
+ ]
+ ],
+ 'filterredir' => [
ApiBase::PARAM_DFLT => 'all',
- ApiBase::PARAM_TYPE => array(
+ ApiBase::PARAM_TYPE => [
'all',
'redirects',
'nonredirects'
- )
- ),
- 'limit' => array(
+ ]
+ ],
+ 'limit' => [
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' ) {
return $retval;
}
}
protected function getExamplesMessages() {
- static $examples = array(
- 'backlinks' => array(
+ static $examples = [
+ 'backlinks' => [
'action=query&list=backlinks&bltitle=Main%20Page'
=> 'apihelp-query+backlinks-example-simple',
'action=query&generator=backlinks&gbltitle=Main%20Page&prop=info'
=> 'apihelp-query+backlinks-example-generator',
- ),
- 'embeddedin' => array(
+ ],
+ 'embeddedin' => [
'action=query&list=embeddedin&eititle=Template:Stub'
=> 'apihelp-query+embeddedin-example-simple',
'action=query&generator=embeddedin&geititle=Template:Stub&prop=info'
=> 'apihelp-query+embeddedin-example-generator',
- ),
- 'imageusage' => array(
+ ],
+ 'imageusage' => [
'action=query&list=imageusage&iutitle=File:Albert%20Einstein%20Head.jpg'
=> 'apihelp-query+imageusage-example-simple',
'action=query&generator=imageusage&giutitle=File:Albert%20Einstein%20Head.jpg&prop=info'
=> 'apihelp-query+imageusage-example-generator',
- )
- );
+ ]
+ ];
return $examples[$this->getModuleName()];
}