r5326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5325‎ | r5326 | r5327 >
Date:14:55, 20 September 2004
Author:timwi
Status:old
Tags:
Comment:
no real change. (rm trailing whitespace, convert leading spaces to tabs)
Modified paths:
  • /trunk/phase3/includes/MessageCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MessageCache.php
@@ -42,7 +42,7 @@
4343 wfProfileIn( $fname.'-parser' );
4444 $this->mParser = new Parser;
4545 wfProfileOut( $fname.'-parser' );
46 -
 46+
4747 $this->load();
4848 wfProfileOut( $fname );
4949 }
@@ -54,7 +54,7 @@
5555 */
5656 function load() {
5757 global $wgAllMessagesEn;
58 -
 58+
5959 if ( $this->mDisable ) {
6060 wfDebug( "MessageCache::load(): disabled\n" );
6161 return true;
@@ -62,12 +62,12 @@
6363 $fname = 'MessageCache::load';
6464 wfProfileIn( $fname );
6565 $success = true;
66 -
 66+
6767 if ( $this->mUseCache ) {
6868 wfProfileIn( $fname.'-fromcache' );
6969 $this->mCache = $this->mMemc->get( $this->mMemcKey );
7070 wfProfileOut( $fname.'-fromcache' );
71 -
 71+
7272 # If there's nothing in memcached, load all the messages from the database
7373 if ( !$this->mCache ) {
7474 wfDebug( "MessageCache::load(): loading all messages\n" );
@@ -92,11 +92,11 @@
9393 }
9494 $this->unlock();
9595 }
96 -
 96+
9797 if ( !is_array( $this->mCache ) ) {
9898 wfMsg( "MessageCache::load(): individual message mode\n" );
9999 # If it is 'loading' or 'error', switch to individual message mode, otherwise disable
100 - # Causing too much DB load, disabling -- TS
 100+ # Causing too much DB load, disabling -- TS
101101 $this->mDisable = true;
102102 /*
103103 if ( $this->mCache == "loading" ) {
@@ -119,14 +119,14 @@
120120 * Loads all cacheable messages from the database
121121 */
122122 function loadFromDB() {
123 - $fname = 'MessageCache::loadFromDB';
 123+ $fname = 'MessageCache::loadFromDB';
124124 $dbr =& wfGetDB( DB_SLAVE );
125 - $res = $dbr->select( 'cur',
126 - array( 'cur_title', 'cur_text' ),
 125+ $res = $dbr->select( 'cur',
 126+ array( 'cur_title', 'cur_text' ),
127127 array( 'cur_is_redirect' => 0, 'cur_namespace' => NS_MEDIAWIKI ),
128128 $fname
129129 );
130 -
 130+
131131 $this->mCache = array();
132132 for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
133133 $this->mCache[$row->cur_title] = $row->cur_text;
@@ -134,7 +134,7 @@
135135
136136 $dbr->freeResult( $res );
137137 }
138 -
 138+
139139 /**
140140 * Not really needed anymore
141141 */
@@ -148,7 +148,7 @@
149149 }
150150 return $this->mKeys;
151151 }
152 -
 152+
153153 /**
154154 * Obsolete
155155 */
@@ -156,7 +156,7 @@
157157 return true;
158158 /*
159159 global $wgAllMessagesEn, $wgLang;
160 - return array_key_exists( $wgLang->lcfirst( $key ), $wgAllMessagesEn ) ||
 160+ return array_key_exists( $wgLang->lcfirst( $key ), $wgAllMessagesEn ) ||
161161 array_key_exists( $key, $wgAllMessagesEn );
162162 */
163163 }
@@ -184,10 +184,10 @@
185185 for ($i=0; $i < MSG_WAIT_TIMEOUT && !$this->mMemc->add( $lockKey, 1, MSG_LOCK_TIMEOUT ); $i++ ) {
186186 sleep(1);
187187 }
188 -
 188+
189189 return $i >= MSG_WAIT_TIMEOUT;
190190 }
191 -
 191+
192192 function unlock() {
193193 if ( !$this->mUseCache ) {
194194 return;
@@ -196,29 +196,29 @@
197197 $lockKey = $this->mMemcKey . 'lock';
198198 $this->mMemc->delete( $lockKey );
199199 }
200 -
 200+
201201 function get( $key, $useDB ) {
202202 global $wgLang, $wgLanguageCode;
203 -
 203+
204204 # If uninitialised, someone is trying to call this halfway through Setup.php
205205 if ( !$this->mInitialised ) {
206206 return "&lt;$key&gt;";
207207 }
208 -
 208+
209209 $message = false;
210210 if ( !$this->mDisable && $useDB ) {
211211 $title = $wgLang->ucfirst( $key );
212 -
213212
 213+
214214 # Try the cache
215215 if ( $this->mUseCache && $this->mCache && array_key_exists( $title, $this->mCache ) ) {
216216 $message = $this->mCache[$title];
217217 }
218 -
 218+
219219 # If it wasn't in the cache, load each message from the DB individually
220220 if ( !$message ) {
221221 $dbr =& wfGetDB( DB_SLAVE );
222 - $result = $dbr->getArray( 'cur', array('cur_text'),
 222+ $result = $dbr->getArray( 'cur', array('cur_text'),
223223 array( 'cur_namespace' => NS_MEDIAWIKI, 'cur_title' => $title ),
224224 'MessageCache::get' );
225225 if ( $result ) {
@@ -233,37 +233,37 @@
234234
235235 # Try the array in $wgLang
236236 if ( !$message ) {
237 - wfSuppressWarnings();
 237+ wfSuppressWarnings();
238238 $message = $wgLang->getMessage( $key );
239 - wfRestoreWarnings();
240 - }
 239+ wfRestoreWarnings();
 240+ }
241241
242242 # Try the English array
243243 if ( !$message && $wgLanguageCode != 'en' ) {
244 - wfSuppressWarnings();
 244+ wfSuppressWarnings();
245245 $message = Language::getMessage( $key );
246 - wfRestoreWarnings();
 246+ wfRestoreWarnings();
247247 }
248 -
 248+
249249 # Final fallback
250250 if ( !$message ) {
251251 $message = "&lt;$key&gt;";
252252 }
253 -
 253+
254254 # Replace brace tags
255255 $message = $this->transform( $message );
256256 return $message;
257257 }
258258
259259 function transform( $message ) {
260 - if( !$this->mDisableTransform ) {
 260+ if( !$this->mDisableTransform ) {
261261 if ( strstr( $message, '{{' ) !== false ) {
262262 $message = $this->mParser->transformMsg( $message, $this->mParserOptions );
263263 }
264264 }
265265 return $message;
266266 }
267 -
 267+
268268 function disable() { $this->mDisable = true; }
269269 function enable() { $this->mDisable = false; }
270270 function disableTransform() { $this->mDisableTransform = true; }
@@ -278,7 +278,7 @@
279279 $this->mExtensionMessages[$key] = $value;
280280 }
281281 }
282 -
 282+
283283 /**
284284 * Clear all stored messages. Mainly used after a mass rebuild.
285285 */

Status & tagging log