X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBacklinks.php;h=fb502e40e75f1f66f51cf0e3ab71ddb88ccaf37d;hp=6a31e194eac3304281ed38596acf91a60619d64b;hb=e3bd13db0c285f312e31bb1b7271af4628cca80c;hpb=38ba6b620be9f6333d902055ae1c0c610af4985e diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index 6a31e194ea..fb502e40e7 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -47,39 +47,39 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { * * @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'; @@ -92,15 +92,15 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $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 - ); + ]; } } @@ -121,14 +121,14 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { * @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 ) { @@ -159,7 +159,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $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; } @@ -191,7 +191,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } 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; @@ -210,24 +210,24 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { */ 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(); @@ -269,7 +269,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } $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 ) { @@ -283,7 +283,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } $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; @@ -296,7 +296,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { // 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; } @@ -355,7 +355,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } // Parse and validate continuation parameter - $this->cont = array(); + $this->cont = []; if ( $this->params['continue'] !== null ) { $cont = explode( '|', $this->params['continue'] ); @@ -417,7 +417,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } // 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 @@ -448,16 +448,16 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { // 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]; @@ -471,10 +471,10 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } $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; } @@ -482,7 +482,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } if ( $hasRedirs ) { $result->addIndexedTagName( - array( 'query', $this->getModuleName(), $idx, 'redirlinks' ), + [ 'query', $this->getModuleName(), $idx, 'redirlinks' ], $this->bl_code ); } if ( !$fit ) { @@ -494,7 +494,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } $result->addIndexedTagName( - array( 'query', $this->getModuleName() ), + [ 'query', $this->getModuleName() ], $this->bl_code ); } @@ -504,43 +504,43 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } 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; } @@ -550,26 +550,26 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } 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()]; }