r86763 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86762‎ | r86763 | r86764 >
Date:13:07, 23 April 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (bug 26882) Allow listing of indefinite protections with the api


Swap some !empty for count
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllpages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllpages.php
@@ -111,30 +111,38 @@
112112 }
113113
114114 // Page protection filtering
115 - if ( !empty( $params['prtype'] ) ) {
 115+ if ( count( $params['prtype'] ) || $params['prexpiry'] != 'all' ) {
116116 $this->addTables( 'page_restrictions' );
117117 $this->addWhere( 'page_id=pr_page' );
118118 $this->addWhere( 'pr_expiry>' . $db->addQuotes( $db->timestamp() ) );
119 - $this->addWhereFld( 'pr_type', $params['prtype'] );
120119
121 - if ( isset( $params['prlevel'] ) ) {
122 - // Remove the empty string and '*' from the prlevel array
123 - $prlevel = array_diff( $params['prlevel'], array( '', '*' ) );
 120+ if ( count( $params['prtype'] ) ) {
 121+ $this->addWhereFld( 'pr_type', $params['prtype'] );
124122
125 - if ( !empty( $prlevel ) ) {
126 - $this->addWhereFld( 'pr_level', $prlevel );
 123+ if ( isset( $params['prlevel'] ) ) {
 124+ // Remove the empty string and '*' from the prlevel array
 125+ $prlevel = array_diff( $params['prlevel'], array( '', '*' ) );
 126+
 127+ if ( count( $prlevel ) ) {
 128+ $this->addWhereFld( 'pr_level', $prlevel );
 129+ }
127130 }
 131+ if ( $params['prfiltercascade'] == 'cascading' ) {
 132+ $this->addWhereFld( 'pr_cascade', 1 );
 133+ } elseif ( $params['prfiltercascade'] == 'noncascading' ) {
 134+ $this->addWhereFld( 'pr_cascade', 0 );
 135+ }
 136+
 137+ $this->addOption( 'DISTINCT' );
128138 }
129 - if ( $params['prfiltercascade'] == 'cascading' ) {
130 - $this->addWhereFld( 'pr_cascade', 1 );
131 - } elseif ( $params['prfiltercascade'] == 'noncascading' ) {
132 - $this->addWhereFld( 'pr_cascade', 0 );
 139+ $forceNameTitleIndex = false;
 140+
 141+ if ( $params['prexpiry'] == 'indefinite' ) {
 142+ $this->addWhere( "pr_expiry = 'infinity' OR pr_expiry IS NULL" );
 143+ } elseif ( $params['prexpiry'] == 'definite' ) {
 144+ $this->addWhere( "pr_expiry != 'infinity'" );
133145 }
134146
135 - $this->addOption( 'DISTINCT' );
136 -
137 - $forceNameTitleIndex = false;
138 -
139147 } elseif ( isset( $params['prlevel'] ) ) {
140148 $this->dieUsage( 'prlevel may not be used without prtype', 'params' );
141149 }
@@ -256,7 +264,15 @@
257265 'all'
258266 ),
259267 ApiBase::PARAM_DFLT => 'all'
260 - )
 268+ ),
 269+ 'prexpiry' => array(
 270+ ApiBase::PARAM_TYPE => array(
 271+ 'indefinite',
 272+ 'definite',
 273+ 'all'
 274+ ),
 275+ ApiBase::PARAM_DFLT => 'all'
 276+ ),
261277 );
262278 }
263279
@@ -275,7 +291,13 @@
276292 'prlevel' => "The protection level (must be used with {$p}prtype= parameter)",
277293 'prfiltercascade' => "Filter protections based on cascadingness (ignored when {$p}prtype isn't set)",
278294 'filterlanglinks' => 'Filter based on whether a page has langlinks',
279 - 'limit' => 'How many total pages to return.'
 295+ 'limit' => 'How many total pages to return.',
 296+ 'prexpiry' => array(
 297+ 'Which protection expiry to filter the page on',
 298+ ' indefinite - Get only pages with indefinite protection expiry',
 299+ ' definite - Get only pages with a definite (specific) protection expiry',
 300+ ' all - Get pages with any protections expiry'
 301+ ),
280302 );
281303 }
282304
Index: trunk/phase3/RELEASE-NOTES
@@ -346,6 +346,7 @@
347347 * YAML API output is now 1.2 compliant, using JSON as the formatter
348348 * (bug 28672) give information about misermode on api
349349 * (bug 28558) Add iw_api and iw_wikiid to meta=siteinfo&siprop=interwikimap
 350+* (bug 26882) Allow listing of indefinite protections with the api
350351
351352 === Languages updated in 1.18 ===
352353

Follow-up revisions

RevisionCommit summaryAuthorDate
r86772Followup r86763, and also fix ancient revision from SpecialProtectedpages (Aa...reedy14:24, 23 April 2011

Comments

#Comment by Duplicatebug (talk | contribs)   14:19, 23 April 2011

I am not sure, but must it not use Database::getInfinity() to work with all databases?

#Comment by Happy-melon (talk | contribs)   14:20, 23 April 2011

Yes, it should.

#Comment by Reedy (talk | contribs)   14:21, 23 April 2011

I stole the code from Special:ProtectedPages

Which has...

	
		if( $this->indefonly ) {
			$conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
		}

I think you're right though.. I'll change both

Status & tagging log