X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryAllPages.php;h=0ce1939b28bc970864640a441a271c876aca1095;hb=ddde7661a218b1e3fcf82764bc4b1c7c5dd16b1d;hp=0149ad2f7e518b4ee4723b93e90aa6df865cd605;hpb=3368cccde53732c1278f51632e69b9865c4ee6ba;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryAllPages.php b/includes/api/ApiQueryAllPages.php index 0149ad2f7e..0ce1939b28 100644 --- a/includes/api/ApiQueryAllPages.php +++ b/includes/api/ApiQueryAllPages.php @@ -102,11 +102,11 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $selectFields = array( + $selectFields = [ 'page_namespace', 'page_title', 'page_id' - ); + ]; } else { $selectFields = $resultPageSet->getPageTableFields(); } @@ -134,7 +134,7 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { if ( isset( $params['prlevel'] ) ) { // Remove the empty string and '*' from the prlevel array - $prlevel = array_diff( $params['prlevel'], array( '', '*' ) ); + $prlevel = array_diff( $params['prlevel'], [ '', '*' ] ); if ( count( $prlevel ) ) { $this->addWhereFld( 'pr_level', $prlevel ); @@ -161,7 +161,7 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { if ( $params['filterlanglinks'] == 'withoutlanglinks' ) { $this->addTables( 'langlinks' ); - $this->addJoinConds( array( 'langlinks' => array( 'LEFT JOIN', 'page_id=ll_from' ) ) ); + $this->addJoinConds( [ 'langlinks' => [ 'LEFT JOIN', 'page_id=ll_from' ] ] ); $this->addWhere( 'll_from IS NULL' ); $forceNameTitleIndex = false; } elseif ( $params['filterlanglinks'] == 'withlanglinks' ) { @@ -175,11 +175,15 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { // 1999 rules works fine, but that breaks other DBs. Sigh. /// @todo Once we drop support for 1992-rule DBs, we can simplify this. $dbType = $db->getType(); - if ( $dbType === 'mysql' || $dbType === 'sqlite' || - $dbType === 'postgres' && $db->getServerVersion() >= 9.1 - ) { - // 1999 rules, or screw-the-rules - $this->addOption( 'GROUP BY', array( 'page_title', 'page_id' ) ); + if ( $dbType === 'mysql' || $dbType === 'sqlite' ) { + // Ignore the rules, or 1999 rules if you count unique keys + // over non-NULL columns as satisfying the requirement for + // "functional dependency" and don't require including + // constant-in-WHERE columns in the GROUP BY. + $this->addOption( 'GROUP BY', [ 'page_title' ] ); + } elseif ( $dbType === 'postgres' && $db->getServerVersion() >= 9.1 ) { + // 1999 rules only counting primary keys + $this->addOption( 'GROUP BY', [ 'page_title', 'page_id' ] ); } else { // 1992 rules $this->addOption( 'GROUP BY', $selectFields ); @@ -196,14 +200,14 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { $this->addOption( 'LIMIT', $limit + 1 ); $res = $this->select( __METHOD__ ); - //Get gender information + // Get gender information if ( MWNamespace::hasGenderDistinction( $params['namespace'] ) ) { - $users = array(); + $users = []; foreach ( $res as $row ) { $users[] = $row->page_title; } GenderCache::singleton()->doQuery( $users, __METHOD__ ); - $res->rewind(); //reset + $res->rewind(); // reset } $count = 0; @@ -218,12 +222,12 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { if ( is_null( $resultPageSet ) ) { $title = Title::makeTitle( $row->page_namespace, $row->page_title ); - $vals = array( + $vals = [ 'pageid' => intval( $row->page_id ), 'ns' => intval( $title->getNamespace() ), 'title' => $title->getPrefixedText() - ); - $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); + ]; + $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); if ( !$fit ) { $this->setContinueEnumParameter( 'continue', $row->page_title ); break; @@ -234,87 +238,87 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'p' ); + $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' ); } } public function getAllowedParams() { - return array( + return [ 'from' => null, - 'continue' => array( + 'continue' => [ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', - ), + ], 'to' => null, 'prefix' => null, - 'namespace' => array( + 'namespace' => [ ApiBase::PARAM_DFLT => NS_MAIN, ApiBase::PARAM_TYPE => 'namespace', - ), - 'filterredir' => array( + ], + 'filterredir' => [ ApiBase::PARAM_DFLT => 'all', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'all', 'redirects', 'nonredirects' - ) - ), - 'minsize' => array( + ] + ], + 'minsize' => [ ApiBase::PARAM_TYPE => 'integer', - ), - 'maxsize' => array( + ], + 'maxsize' => [ ApiBase::PARAM_TYPE => 'integer', - ), - 'prtype' => array( + ], + 'prtype' => [ ApiBase::PARAM_TYPE => Title::getFilteredRestrictionTypes( true ), ApiBase::PARAM_ISMULTI => true - ), - 'prlevel' => array( + ], + 'prlevel' => [ ApiBase::PARAM_TYPE => $this->getConfig()->get( 'RestrictionLevels' ), ApiBase::PARAM_ISMULTI => true - ), - 'prfiltercascade' => array( + ], + 'prfiltercascade' => [ ApiBase::PARAM_DFLT => 'all', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'cascading', 'noncascading', 'all' - ), - ), - '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 - ), - 'dir' => array( + ], + 'dir' => [ ApiBase::PARAM_DFLT => 'ascending', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'ascending', 'descending' - ) - ), - 'filterlanglinks' => array( - ApiBase::PARAM_TYPE => array( + ] + ], + 'filterlanglinks' => [ + ApiBase::PARAM_TYPE => [ 'withlanglinks', 'withoutlanglinks', 'all' - ), + ], ApiBase::PARAM_DFLT => 'all' - ), - 'prexpiry' => array( - ApiBase::PARAM_TYPE => array( + ], + 'prexpiry' => [ + ApiBase::PARAM_TYPE => [ 'indefinite', 'definite', 'all' - ), + ], ApiBase::PARAM_DFLT => 'all' - ), - ); + ], + ]; } protected function getExamplesMessages() { - return array( + return [ 'action=query&list=allpages&apfrom=B' => 'apihelp-query+allpages-example-B', 'action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info' @@ -322,7 +326,7 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { 'action=query&generator=allpages&gaplimit=2&' . 'gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content' => 'apihelp-query+allpages-example-generator-revisions', - ); + ]; } public function getHelpUrls() {