X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryExtLinksUsage.php;h=fc5d8a042598552bd871bd1f2ecc221264986daa;hb=8e744f6f482b80a806d43fb4ea2eded4c7fd517f;hp=38eba12c7381f26910f67f7f9af666a191e74746;hpb=38ba6b620be9f6333d902055ae1c0c610af4985e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php index 38eba12c73..fc5d8a0425 100644 --- a/includes/api/ApiQueryExtLinksUsage.php +++ b/includes/api/ApiQueryExtLinksUsage.php @@ -1,9 +1,5 @@ @gmail.com" * * This program is free software; you can redistribute it and/or modify @@ -55,17 +51,20 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { $query = $params['query']; $protocol = self::getProtocolPrefix( $params['protocol'] ); - $this->addTables( array( 'page', 'externallinks' ) ); // must be in this order for 'USE INDEX' + $this->addTables( [ 'page', 'externallinks' ] ); // must be in this order for 'USE INDEX' $this->addOption( 'USE INDEX', 'el_index' ); $this->addWhere( 'page_id=el_from' ); - $miser_ns = array(); + $miser_ns = []; if ( $this->getConfig()->get( 'MiserMode' ) ) { - $miser_ns = $params['namespace']; + $miser_ns = $params['namespace'] ?: []; } else { $this->addWhereFld( 'page_namespace', $params['namespace'] ); } + // Normalize query to match the normalization applied for the externallinks table + $query = Parser::normalizeLinkUrl( $query ); + $whereQuery = $this->prepareUrlQuerySearchString( $query, $protocol ); if ( $whereQuery !== null ) { @@ -78,11 +77,11 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { $fld_url = isset( $prop['url'] ); if ( is_null( $resultPageSet ) ) { - $this->addFields( array( + $this->addFields( [ 'page_id', 'page_namespace', 'page_title' - ) ); + ] ); $this->addFieldsIf( 'el_to', $fld_url ); } else { $this->addFields( $resultPageSet->getPageTableFields() ); @@ -112,9 +111,9 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $vals = array( + $vals = [ ApiResult::META_TYPE => 'assoc', - ); + ]; if ( $fld_ids ) { $vals['pageid'] = intval( $row->page_id ); } @@ -130,7 +129,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { } $vals['url'] = $to; } - $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); + $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); if ( !$fit ) { $this->setContinueEnumParameter( 'offset', $offset + $count - 1 ); break; @@ -141,50 +140,50 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $result->addIndexedTagName( array( 'query', $this->getModuleName() ), + $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $this->getModulePrefix() ); } } public function getAllowedParams() { - $ret = array( - 'prop' => array( + $ret = [ + 'prop' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_DFLT => 'ids|title|url', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'ids', 'title', 'url' - ), - ApiBase::PARAM_HELP_MSG_PER_VALUE => array(), - ), - 'offset' => array( + ], + ApiBase::PARAM_HELP_MSG_PER_VALUE => [], + ], + 'offset' => [ ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', - ), - 'protocol' => array( + ], + 'protocol' => [ ApiBase::PARAM_TYPE => self::prepareProtocols(), ApiBase::PARAM_DFLT => '', - ), + ], 'query' => null, - 'namespace' => array( + 'namespace' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_TYPE => 'namespace' - ), - '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 - ), + ], 'expandurl' => false, - ); + ]; if ( $this->getConfig()->get( 'MiserMode' ) ) { - $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = array( + $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = [ 'api-help-param-limited-in-miser-mode', - ); + ]; } return $ret; @@ -192,7 +191,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { public static function prepareProtocols() { global $wgUrlProtocols; - $protocols = array( '' ); + $protocols = [ '' ]; foreach ( $wgUrlProtocols as $p ) { if ( $p !== '//' ) { $protocols[] = substr( $p, 0, strpos( $p, ':' ) ); @@ -220,13 +219,13 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { } protected function getExamplesMessages() { - return array( + return [ 'action=query&list=exturlusage&euquery=www.mediawiki.org' => 'apihelp-query+exturlusage-example-simple', - ); + ]; } public function getHelpUrls() { - return 'https://www.mediawiki.org/wiki/API:Exturlusage'; + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Exturlusage'; } }