r87199 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87198‎ | r87199 | r87200 >
Date:17:46, 1 May 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 28143) SiteMatrix API module should allow filtering by wiki status (closed, private, fishbowl, etc.)

Add filtering by wiki state
Modified paths:
  • /trunk/extensions/SiteMatrix/SiteMatrixApi.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SiteMatrix/SiteMatrixApi.php
@@ -34,11 +34,12 @@
3535 $params = $this->extractRequestParams();
3636 $type = array_flip( $params['type'] );
3737 $state = array_flip( $params['state'] );
38 -
39 - $allOrClosed = isset( $state['all'] ) || isset( $state['closed'] );
40 - $allOrPrivate = isset( $state['all'] ) || isset( $state['private'] );
41 - $allOrFishbowl = isset( $state['all'] ) || isset( $state['fishbowl'] );
4238
 39+ $all = isset( $state['all'] );
 40+ $closed = isset( $state['closed'] );
 41+ $private = isset( $state['private'] );
 42+ $fishbowl = isset( $state['fishbowl'] );
 43+
4344 if ( isset( $type['language'] ) ) {
4445 foreach ( $matrix->getLangList() as $lang ) {
4546 $langhost = str_replace( '_', '-', $lang );
@@ -53,6 +54,12 @@
5455
5556 foreach ( $matrix->getSites() as $site ) {
5657 if ( $matrix->exist( $lang, $site ) ) {
 58+ $skip = true;
 59+
 60+ if ( $all ) {
 61+ $skip = false;
 62+ }
 63+
5764 $url = $matrix->getUrl( $lang, $site );
5865 $site_out = array(
5966 'url' => $url,
@@ -60,7 +67,14 @@
6168 );
6269 if( $matrix->isClosed( $lang, $site ) ) {
6370 $site_out['closed'] = '';
 71+ if ( $closed ) {
 72+ $skip = false;
 73+ }
6474 }
 75+
 76+ if ( $skip ) {
 77+ continue;
 78+ }
6579 $language['site'][] = $site_out;
6680 }
6781 }
@@ -84,16 +98,37 @@
8599 $wiki['url'] = $url;
86100 $wiki['code'] = str_replace( '_', '-', $lang ) . ( $site != 'wiki' ? $site : '' );
87101
 102+ $skip = true;
 103+
 104+ if ( $all ) {
 105+ $skip = false;
 106+ }
88107 if ( $matrix->isPrivate( $lang . $site ) ) {
89108 $wiki['private'] = '';
 109+
 110+ if ( $private ) {
 111+ $skip = false;
 112+ }
90113 }
91114 if ( $matrix->isFishbowl( $lang . $site ) ) {
92115 $wiki['fishbowl'] = '';
 116+
 117+ if ( $fishbowl ) {
 118+ $skip = false;
 119+ }
93120 }
94121 if ( $matrix->isClosed( $lang, $site ) ) {
95122 $wiki['closed'] = '';
 123+
 124+ if ( $closed ) {
 125+ $skip = false;
 126+ }
96127 }
97128
 129+ if ( $skip ) {
 130+ continue;
 131+ }
 132+
98133 $specials[] = $wiki;
99134 }
100135
@@ -112,12 +147,23 @@
113148 ),
114149 ApiBase::PARAM_DFLT => 'special|language',
115150 ),
 151+ 'state' => array(
 152+ ApiBase::PARAM_ISMULTI => true,
 153+ ApiBase::PARAM_TYPE => array(
 154+ 'all',
 155+ 'closed',
 156+ 'private',
 157+ 'fishbowl'
 158+ ),
 159+ ApiBase::PARAM_DFLT => 'all',
 160+ )
116161 );
117162 }
118163
119164 protected function getParamDescription() {
120165 return array(
121166 'type' => 'Filter the Site Matrix by type',
 167+ 'state' => 'Filter the Site Matrix by wiki state',
122168 );
123169 }
124170

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87196* (bug 28143) SiteMatrix API module should allow filtering by wiki status (cl...reedy17:31, 1 May 2011
r87198* (bug 28143) SiteMatrix API module should allow filtering by wiki status (cl...reedy17:34, 1 May 2011

Comments

#Comment by IAlex (talk | contribs)   10:48, 27 May 2011

Couldn't

$skip = true;

if ( $all ) {
	$skip = false;
}

be simplified as

$skip = !$all;

?

#Comment by Reedy (talk | contribs)   10:49, 27 May 2011

I suppose so, not really a big deal...

Status & tagging log