r63650 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63649‎ | r63650 | r63651 >
Date:20:54, 12 March 2010
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* (bug 16934) Closed wikis are now listed again
* Also mark closed wikis in api result

This requires some changes in the configuration:
* SiteMatrixGetPrivateAndFishbowlWikis hook has been removed and replaced with two
configuration settings $wgSiteMatrixPrivateSites and $wgSiteMatrixFishbowlSites.
They can either be an array of wiki IDs or a string pointing to a file listing those
sites (like $wgProxyList)
* Added $wgSiteMatrixClosedSites, same as the two settings above, but for the list of
closed wikis

Giving the current configuration on Wikimedia, something like that should work:
$wgSiteMatrixClosedSites = "$IP/../closed.dblist";
$wgSiteMatrixPrivateSites = "$IP/../private.dblist";
$wgSiteMatrixFishbowlSites = "$IP/../fishbowl.dblist";
Modified paths:
  • /trunk/extensions/SiteMatrix/SiteMatrix.php (modified) (history)
  • /trunk/extensions/SiteMatrix/SiteMatrix_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SiteMatrix/SiteMatrix.php
@@ -55,6 +55,9 @@
5656 'prefix' => 'v',
5757 )
5858 );
 59+$wgSiteMatrixPrivateSites = null;
 60+$wgSiteMatrixFishbowlSites = null;
 61+$wgSiteMatrixClosedSites = null;
5962
6063 $dir = dirname(__FILE__) . '/';
6164
Index: trunk/extensions/SiteMatrix/SiteMatrix_body.php
@@ -10,7 +10,8 @@
1111 require_once( $IP.'/languages/Names.php' );
1212
1313 class SiteMatrix {
14 - protected $langlist, $sites, $names, $hosts, $private, $fishbowl;
 14+ protected $langlist, $sites, $names, $hosts;
 15+ protected $private = null, $fishbowl = null, $closed = null;
1516 protected $specials, $matrix, $count, $countPerSite;
1617
1718 public function __construct(){
@@ -33,8 +34,6 @@
3435 $this->sites = array();
3536 $this->names = array();
3637 $this->hosts = array();
37 - $this->private = array();
38 - $this->fishbowl = array();
3938
4039 foreach( $wgSiteMatrixSites as $site => $conf ){
4140 $this->sites[] = $site;
@@ -94,8 +93,6 @@
9594 }
9695
9796 $this->count = count( $wgLocalDatabases );
98 -
99 - wfRunHooks( 'SiteMatrixGetPrivateAndFishbowlWikis', array( &$this->private, &$this->fishbowl ) );
10097 }
10198
10299 public static function sortSpecial( $a1, $a2 ){
@@ -115,15 +112,15 @@
116113 }
117114
118115 public function getSpecials(){
119 - return $this->specials;
 116+ return $this->specials;
120117 }
121118
122119 public function getCount(){
123 - return $this->count;
 120+ return $this->count;
124121 }
125122
126123 public function getCountPerSite( $site ){
127 - return $this->countPerSite[$site];
 124+ return $this->countPerSite[$site];
128125 }
129126
130127 public function getSiteUrl( $site ){
@@ -142,31 +139,59 @@
143140 return !empty( $this->matrix[$major][$minor] );
144141 }
145142
146 - # FIXME: Function does not work any longer:
147 - # 2008-01-09 04:08 Tim: migrated all locked wikis from $wgReadOnly(File) to permissions-based locking,
148 - # so that stewards can edit the alternate project links, and so that various MediaWiki components don't break on page view
 143+ public function isClosed( $minor, $major ) {
 144+ global $wgSiteMatrixClosedSites;
149145
150 - # From http://noc.wikimedia.org/conf/highlight.php?file=InitialiseSettings.php:
151 - # 'wgReadOnlyFile' => array(
152 - # # Now soft-locked via closed.dblist:
 146+ $dbname = $minor . $major;
153147
154 - public function isClosed( $minor, $major ) {
155 - global $wgConf;
 148+ if ( $wgSiteMatrixClosedSites === null ) {
 149+ global $wgConf;
156150
157 - $dbname = $minor . $major;
158 - if( $wgConf->get( 'wgReadOnly', $dbname, $major, array( 'site' => $major, 'lang' => $minor ) ) )
159 - return true;
160 - $readOnlyFile = $wgConf->get( 'wgReadOnlyFile', $dbname, $major, array( 'site' => $major, 'lang' => $minor ) );
161 - if( $readOnlyFile && file_exists( $readOnlyFile ) )
162 - return true;
163 - return false;
 151+ if( $wgConf->get( 'wgReadOnly', $dbname, $major, array( 'site' => $major, 'lang' => $minor ) ) )
 152+ return true;
 153+ $readOnlyFile = $wgConf->get( 'wgReadOnlyFile', $dbname, $major, array( 'site' => $major, 'lang' => $minor ) );
 154+ if( $readOnlyFile && file_exists( $readOnlyFile ) )
 155+ return true;
 156+ return false;
 157+ } elseif ( $this->closed == null ) {
 158+ $this->closed = array();
 159+ if ( is_string( $wgSiteMatrixClosedSites ) ) {
 160+ $this->closed = array_map( 'trim', file( $wgSiteMatrixClosedSites ) );
 161+ } elseif ( is_array( $wgSiteMatrixClosedSites ) ) {
 162+ $this->closed = $wgSiteMatrixClosedSites;
 163+ }
 164+ }
 165+
 166+ return in_array( $dbname, $this->closed );
164167 }
165168
166169 public function isPrivate( $dbname ) {
 170+ global $wgSiteMatrixPrivateSites;
 171+
 172+ if ( $this->private == null ) {
 173+ $this->private = array();
 174+ if ( is_string( $wgSiteMatrixPrivateSites ) ) {
 175+ $this->private = array_map( 'trim', file( $wgSiteMatrixPrivateSites ) );
 176+ } elseif ( is_array( $wgSiteMatrixPrivateSites ) ) {
 177+ $this->private = $wgSiteMatrixPrivateSites;
 178+ }
 179+ }
 180+
167181 return in_array( $dbname, $this->private );
168182 }
169183
170184 public function isFishbowl( $dbname ) {
 185+ global $wgSiteMatrixFishbowlSites;
 186+
 187+ if ( $this->fishbowl == null ) {
 188+ $this->fishbowl = array();
 189+ if ( is_string( $wgSiteMatrixFishbowlSites ) ) {
 190+ $this->fishbowl = array_map( 'trim', file( $wgSiteMatrixFishbowlSites ) );
 191+ } elseif ( is_array( $wgSiteMatrixFishbowlSites ) ) {
 192+ $this->fishbowl = $wgSiteMatrixFishbowlSites;
 193+ }
 194+ }
 195+
171196 return in_array( $dbname, $this->fishbowl );
172197 }
173198 }
@@ -180,12 +205,12 @@
181206 function execute( $par ) {
182207 global $wgOut, $wgRequest, $wgLanguageNames;
183208 wfLoadExtensionMessages( 'SiteMatrix' );
184 -
 209+
185210 $this->setHeaders();
186211 $this->outputHeader();
187212
188213 $matrix = new SiteMatrix();
189 -
 214+
190215 if( class_exists( 'LanguageNames' ) ) {
191216 global $wgLang;
192217 $localLanguageNames = LanguageNames::getNames( $wgLang->getCode() );
@@ -290,7 +315,7 @@
291316 list( $lang, $site ) = $special;
292317 $langhost = str_replace( '_', '-', $lang );
293318 $url = $matrix->getUrl( $lang, $site );
294 -
 319+
295320 # Handle options
296321 $flags = array();
297322 if( $matrix->isPrivate( $lang . $site ) )
@@ -326,7 +351,7 @@
327352 $matrix_out = array(
328353 'count' => $matrix->getCount(),
329354 );
330 -
 355+
331356 if( class_exists( 'LanguageNames' ) ) {
332357 global $wgLang;
333358 $localLanguageNames = LanguageNames::getNames( $wgLang->getCode() );
@@ -352,6 +377,8 @@
353378 'url' => $url,
354379 'code' => $site,
355380 );
 381+ if( $matrix->isClosed( $lang, $site ) )
 382+ $site_out['closed'] = '';
356383 $language['site'][] = $site_out;
357384 }
358385 }
@@ -370,12 +397,12 @@
371398 $wiki = array();
372399 $wiki['url'] = $url;
373400 $wiki['code'] = str_replace( '_', '-', $lang ) . ( $site != 'wiki' ? $site : '' );
374 -
375 - if( $matrix->isPrivate( $lang . $site ) )
 401+
 402+ if( $matrix->isPrivate( $lang . $site ) )
376403 $wiki['private'] = '';
377404 if( $matrix->isFishbowl( $lang . $site ) )
378405 $wiki['fishbowl'] = '';
379 -
 406+
380407 $specials[] = $wiki;
381408 }
382409

Follow-up revisions

RevisionCommit summaryAuthorDate
r80844Follow-up to r63650: refactor duplicated code in SiteMatrix's lazy list initi...brion07:09, 24 January 2011

Comments

#Comment by Tim Starling (talk | contribs)   23:11, 25 March 2010

Removing scaptrap tag since the configuration is done now.

#Comment by Brion VIBBER (talk | contribs)   07:09, 24 January 2011

Seems to work fine; I did a little code cleanup in r80844 to remove duplication of the array-or-filename logic.

Status & tagging log