Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | wfProfileIn( $fname.'-parser' ); |
44 | 44 | $this->mParser = new Parser; |
45 | 45 | wfProfileOut( $fname.'-parser' ); |
46 | | - |
| 46 | + |
47 | 47 | $this->load(); |
48 | 48 | wfProfileOut( $fname ); |
49 | 49 | } |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | */ |
56 | 56 | function load() { |
57 | 57 | global $wgAllMessagesEn; |
58 | | - |
| 58 | + |
59 | 59 | if ( $this->mDisable ) { |
60 | 60 | wfDebug( "MessageCache::load(): disabled\n" ); |
61 | 61 | return true; |
— | — | @@ -62,12 +62,12 @@ |
63 | 63 | $fname = 'MessageCache::load'; |
64 | 64 | wfProfileIn( $fname ); |
65 | 65 | $success = true; |
66 | | - |
| 66 | + |
67 | 67 | if ( $this->mUseCache ) { |
68 | 68 | wfProfileIn( $fname.'-fromcache' ); |
69 | 69 | $this->mCache = $this->mMemc->get( $this->mMemcKey ); |
70 | 70 | wfProfileOut( $fname.'-fromcache' ); |
71 | | - |
| 71 | + |
72 | 72 | # If there's nothing in memcached, load all the messages from the database |
73 | 73 | if ( !$this->mCache ) { |
74 | 74 | wfDebug( "MessageCache::load(): loading all messages\n" ); |
— | — | @@ -92,11 +92,11 @@ |
93 | 93 | } |
94 | 94 | $this->unlock(); |
95 | 95 | } |
96 | | - |
| 96 | + |
97 | 97 | if ( !is_array( $this->mCache ) ) { |
98 | 98 | wfMsg( "MessageCache::load(): individual message mode\n" ); |
99 | 99 | # 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 |
101 | 101 | $this->mDisable = true; |
102 | 102 | /* |
103 | 103 | if ( $this->mCache == "loading" ) { |
— | — | @@ -119,14 +119,14 @@ |
120 | 120 | * Loads all cacheable messages from the database |
121 | 121 | */ |
122 | 122 | function loadFromDB() { |
123 | | - $fname = 'MessageCache::loadFromDB'; |
| 123 | + $fname = 'MessageCache::loadFromDB'; |
124 | 124 | $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' ), |
127 | 127 | array( 'cur_is_redirect' => 0, 'cur_namespace' => NS_MEDIAWIKI ), |
128 | 128 | $fname |
129 | 129 | ); |
130 | | - |
| 130 | + |
131 | 131 | $this->mCache = array(); |
132 | 132 | for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) { |
133 | 133 | $this->mCache[$row->cur_title] = $row->cur_text; |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | |
136 | 136 | $dbr->freeResult( $res ); |
137 | 137 | } |
138 | | - |
| 138 | + |
139 | 139 | /** |
140 | 140 | * Not really needed anymore |
141 | 141 | */ |
— | — | @@ -148,7 +148,7 @@ |
149 | 149 | } |
150 | 150 | return $this->mKeys; |
151 | 151 | } |
152 | | - |
| 152 | + |
153 | 153 | /** |
154 | 154 | * Obsolete |
155 | 155 | */ |
— | — | @@ -156,7 +156,7 @@ |
157 | 157 | return true; |
158 | 158 | /* |
159 | 159 | global $wgAllMessagesEn, $wgLang; |
160 | | - return array_key_exists( $wgLang->lcfirst( $key ), $wgAllMessagesEn ) || |
| 160 | + return array_key_exists( $wgLang->lcfirst( $key ), $wgAllMessagesEn ) || |
161 | 161 | array_key_exists( $key, $wgAllMessagesEn ); |
162 | 162 | */ |
163 | 163 | } |
— | — | @@ -184,10 +184,10 @@ |
185 | 185 | for ($i=0; $i < MSG_WAIT_TIMEOUT && !$this->mMemc->add( $lockKey, 1, MSG_LOCK_TIMEOUT ); $i++ ) { |
186 | 186 | sleep(1); |
187 | 187 | } |
188 | | - |
| 188 | + |
189 | 189 | return $i >= MSG_WAIT_TIMEOUT; |
190 | 190 | } |
191 | | - |
| 191 | + |
192 | 192 | function unlock() { |
193 | 193 | if ( !$this->mUseCache ) { |
194 | 194 | return; |
— | — | @@ -196,29 +196,29 @@ |
197 | 197 | $lockKey = $this->mMemcKey . 'lock'; |
198 | 198 | $this->mMemc->delete( $lockKey ); |
199 | 199 | } |
200 | | - |
| 200 | + |
201 | 201 | function get( $key, $useDB ) { |
202 | 202 | global $wgLang, $wgLanguageCode; |
203 | | - |
| 203 | + |
204 | 204 | # If uninitialised, someone is trying to call this halfway through Setup.php |
205 | 205 | if ( !$this->mInitialised ) { |
206 | 206 | return "<$key>"; |
207 | 207 | } |
208 | | - |
| 208 | + |
209 | 209 | $message = false; |
210 | 210 | if ( !$this->mDisable && $useDB ) { |
211 | 211 | $title = $wgLang->ucfirst( $key ); |
212 | | - |
213 | 212 | |
| 213 | + |
214 | 214 | # Try the cache |
215 | 215 | if ( $this->mUseCache && $this->mCache && array_key_exists( $title, $this->mCache ) ) { |
216 | 216 | $message = $this->mCache[$title]; |
217 | 217 | } |
218 | | - |
| 218 | + |
219 | 219 | # If it wasn't in the cache, load each message from the DB individually |
220 | 220 | if ( !$message ) { |
221 | 221 | $dbr =& wfGetDB( DB_SLAVE ); |
222 | | - $result = $dbr->getArray( 'cur', array('cur_text'), |
| 222 | + $result = $dbr->getArray( 'cur', array('cur_text'), |
223 | 223 | array( 'cur_namespace' => NS_MEDIAWIKI, 'cur_title' => $title ), |
224 | 224 | 'MessageCache::get' ); |
225 | 225 | if ( $result ) { |
— | — | @@ -233,37 +233,37 @@ |
234 | 234 | |
235 | 235 | # Try the array in $wgLang |
236 | 236 | if ( !$message ) { |
237 | | - wfSuppressWarnings(); |
| 237 | + wfSuppressWarnings(); |
238 | 238 | $message = $wgLang->getMessage( $key ); |
239 | | - wfRestoreWarnings(); |
240 | | - } |
| 239 | + wfRestoreWarnings(); |
| 240 | + } |
241 | 241 | |
242 | 242 | # Try the English array |
243 | 243 | if ( !$message && $wgLanguageCode != 'en' ) { |
244 | | - wfSuppressWarnings(); |
| 244 | + wfSuppressWarnings(); |
245 | 245 | $message = Language::getMessage( $key ); |
246 | | - wfRestoreWarnings(); |
| 246 | + wfRestoreWarnings(); |
247 | 247 | } |
248 | | - |
| 248 | + |
249 | 249 | # Final fallback |
250 | 250 | if ( !$message ) { |
251 | 251 | $message = "<$key>"; |
252 | 252 | } |
253 | | - |
| 253 | + |
254 | 254 | # Replace brace tags |
255 | 255 | $message = $this->transform( $message ); |
256 | 256 | return $message; |
257 | 257 | } |
258 | 258 | |
259 | 259 | function transform( $message ) { |
260 | | - if( !$this->mDisableTransform ) { |
| 260 | + if( !$this->mDisableTransform ) { |
261 | 261 | if ( strstr( $message, '{{' ) !== false ) { |
262 | 262 | $message = $this->mParser->transformMsg( $message, $this->mParserOptions ); |
263 | 263 | } |
264 | 264 | } |
265 | 265 | return $message; |
266 | 266 | } |
267 | | - |
| 267 | + |
268 | 268 | function disable() { $this->mDisable = true; } |
269 | 269 | function enable() { $this->mDisable = false; } |
270 | 270 | function disableTransform() { $this->mDisableTransform = true; } |
— | — | @@ -278,7 +278,7 @@ |
279 | 279 | $this->mExtensionMessages[$key] = $value; |
280 | 280 | } |
281 | 281 | } |
282 | | - |
| 282 | + |
283 | 283 | /** |
284 | 284 | * Clear all stored messages. Mainly used after a mass rebuild. |
285 | 285 | */ |