}
if ( is_null( $resultPageSet ) ) {
- $selectFields = array(
+ $selectFields = [
'page_namespace',
'page_title',
'page_id'
- );
+ ];
} else {
$selectFields = $resultPageSet->getPageTableFields();
}
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 );
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' ) {
$this->addTables( 'langlinks' );
$this->addWhere( 'page_id=ll_from' );
$this->addOption( 'STRAIGHT_JOIN' );
- // We have to GROUP BY all selected fields to stop
- // PostgreSQL from whining
- $this->addOption( 'GROUP BY', $selectFields );
+
+ // MySQL filesorts if we use a GROUP BY that works with the rules
+ // in the 1992 SQL standard (it doesn't like having the
+ // constant-in-WHERE page_namespace column in there). Using the
+ // 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' ) {
+ // 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 );
+ }
+
$forceNameTitleIndex = false;
}
$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;
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;
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' );
+ $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
}
}
public function getAllowedParams() {
- return array(
+ return [
'from' => null,
- 'continue' => null,
+ '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'
- ),
- );
- }
-
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'from' => 'The page title to start enumerating from',
- 'continue' => 'When more results are available, use this to continue',
- 'to' => 'The page title to stop enumerating at',
- 'prefix' => 'Search for all page titles that begin with this value',
- 'namespace' => 'The namespace to enumerate',
- 'filterredir' => 'Which pages to list',
- 'dir' => 'The direction in which to list',
- 'minsize' => 'Limit to pages with at least this many bytes',
- 'maxsize' => 'Limit to pages with at most this many bytes',
- 'prtype' => 'Limit to protected pages only',
- 'prlevel' => "The protection level (must be used with {$p}prtype= parameter)",
- 'prfiltercascade'
- => "Filter protections based on cascadingness (ignored when {$p}prtype isn't set)",
- 'filterlanglinks' => array(
- 'Filter based on whether a page has langlinks',
- 'Note that this may not consider langlinks added by extensions.',
- ),
- 'limit' => 'How many total pages to return.',
- 'prexpiry' => array(
- 'Which protection expiry to filter the page on',
- ' indefinite - Get only pages with indefinite protection expiry',
- ' definite - Get only pages with a definite (specific) protection expiry',
- ' all - Get pages with any protections expiry'
- ),
- );
- }
-
- public function getDescription() {
- return 'Enumerate all pages sequentially in a given namespace.';
+ ],
+ ];
}
- public function getExamples() {
- return array(
- 'api.php?action=query&list=allpages&apfrom=B' => array(
- 'Simple Use',
- 'Show a list of pages starting at the letter "B"',
- ),
- 'api.php?action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info' => array(
- 'Using as Generator',
- 'Show info about 4 pages starting at the letter "T"',
- ),
- 'api.php?action=query&generator=allpages&gaplimit=2&' .
+ protected function getExamplesMessages() {
+ return [
+ 'action=query&list=allpages&apfrom=B'
+ => 'apihelp-query+allpages-example-B',
+ 'action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info'
+ => 'apihelp-query+allpages-example-generator',
+ 'action=query&generator=allpages&gaplimit=2&' .
'gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
- => array( 'Show content of first 2 non-redirect pages beginning at "Re"' )
- );
+ => 'apihelp-query+allpages-example-generator-revisions',
+ ];
}
public function getHelpUrls() {