r80844 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80843‎ | r80844 | r80845 >
Date:07:09, 24 January 2011
Author:brion
Status:ok
Tags:
Comment:
Follow-up to r63650: refactor duplicated code in SiteMatrix's lazy list initialization
Modified paths:
  • /trunk/extensions/SiteMatrix/SiteMatrix_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SiteMatrix/SiteMatrix_body.php
@@ -21,7 +21,7 @@
2222 $wgConf->loadFullData();
2323
2424 if( file_exists( $wgSiteMatrixFile ) ){
25 - $this->langlist = array_map( 'trim', file( $wgSiteMatrixFile ) );
 25+ $this->langlist = $this->extractFile( $wgSiteMatrixFile );
2626 $hideEmpty = false;
2727 } else {
2828 $this->langlist = array_keys( Language::getLanguageNames( false ) );
@@ -145,6 +145,8 @@
146146 $dbname = $minor . $major;
147147
148148 if ( $wgSiteMatrixClosedSites === null ) {
 149+ // Fallback to old behavior checking read-only settings;
 150+ // not very reliable.
149151 global $wgConf;
150152
151153 if( $wgConf->get( 'wgReadOnly', $dbname, $major, array( 'site' => $major, 'lang' => $minor ) ) )
@@ -153,15 +155,11 @@
154156 if( $readOnlyFile && file_exists( $readOnlyFile ) )
155157 return true;
156158 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 - }
164159 }
165160
 161+ if( $this->closed == null ) {
 162+ $this->closed = $this->extractDbList( $wgSiteMatrixClosedSites );
 163+ }
166164 return in_array( $dbname, $this->closed );
167165 }
168166
@@ -169,12 +167,7 @@
170168 global $wgSiteMatrixPrivateSites;
171169
172170 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 - }
 171+ $this->private = $this->extractDbList( $wgSiteMatrixPrivateSites );
179172 }
180173
181174 return in_array( $dbname, $this->private );
@@ -184,16 +177,38 @@
185178 global $wgSiteMatrixFishbowlSites;
186179
187180 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 - }
 181+ $this->fishbowl = $this->extractDbList( $wgSiteMatrixFishbowlSites );
194182 }
195183
196184 return in_array( $dbname, $this->fishbowl );
197185 }
 186+
 187+ /**
 188+ * Pull a list of dbnames from a given text file, or pass through an array.
 189+ * Used for the DB list configuration settings.
 190+ *
 191+ * @param mixed $listOrFilename array of strings, or string with a filename
 192+ * @return array
 193+ */
 194+ private function extractDbList( $listOrFilename ) {
 195+ if ( is_string( $listOrFilename ) ) {
 196+ return $this->extractFile( $listOrFilename );
 197+ } elseif ( is_array( $listOrFilename ) ) {
 198+ return $listOrFilename;
 199+ } else {
 200+ return array();
 201+ }
 202+ }
 203+
 204+ /**
 205+ * Pull a list of dbnames from a given text file.
 206+ *
 207+ * @param string $filename
 208+ * @return array
 209+ */
 210+ private function extractFile( $filename ) {
 211+ return array_map( 'trim', file( $filename ) );
 212+ }
198213 }
199214
200215 class SiteMatrixPage extends SpecialPage {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r63650* (bug 16934) Closed wikis are now listed again...ialex20:54, 12 March 2010

Status & tagging log