Index: trunk/phase3/includes/specials/SpecialAllmessages.php |
— | — | @@ -5,22 +5,22 @@ |
6 | 6 | * @ingroup SpecialPage |
7 | 7 | */ |
8 | 8 | class SpecialAllmessages extends SpecialPage { |
9 | | - |
| 9 | + |
10 | 10 | /** |
11 | 11 | * Constructor |
12 | 12 | */ |
13 | 13 | public function __construct() { |
14 | 14 | parent::__construct( 'Allmessages' ); |
15 | 15 | } |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Execute |
19 | 19 | */ |
20 | 20 | function execute( $par ) { |
21 | 21 | global $wgOut, $wgRequest; |
22 | | - |
| 22 | + |
23 | 23 | $this->setHeaders(); |
24 | | - |
| 24 | + |
25 | 25 | global $wgUseDatabaseMessages; |
26 | 26 | if( !$wgUseDatabaseMessages ) { |
27 | 27 | $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' ); |
— | — | @@ -31,49 +31,49 @@ |
32 | 32 | |
33 | 33 | $this->filter = $wgRequest->getVal( 'filter', 'all' ); |
34 | 34 | $this->prefix = $wgRequest->getVal( 'prefix', '' ); |
35 | | - |
| 35 | + |
36 | 36 | $this->table = new AllmessagesTablePager( $this, |
37 | 37 | $conds=array(), |
38 | 38 | wfGetLangObj( $wgRequest->getVal( 'lang', false ) ) ); |
39 | | - |
| 39 | + |
40 | 40 | $this->langCode = $this->table->lang->getCode(); |
41 | | - |
| 41 | + |
42 | 42 | $wgOut->addHTML( $this->buildForm() . |
43 | | - $this->table->getNavigationBar() . |
44 | | - $this->table->getLimitForm() . |
45 | | - $this->table->getBody() . |
| 43 | + $this->table->getNavigationBar() . |
| 44 | + $this->table->getLimitForm() . |
| 45 | + $this->table->getBody() . |
46 | 46 | $this->table->getNavigationBar() ); |
47 | | - |
| 47 | + |
48 | 48 | } |
49 | | - |
| 49 | + |
50 | 50 | function buildForm() { |
51 | 51 | $url = $this->getTitle()->escapeLocalURL(); |
52 | 52 | $languages = Language::getLanguageNames( false ); |
53 | 53 | ksort( $languages ); |
54 | | - |
| 54 | + |
55 | 55 | $out = "<form method=\"get\" action=\"$url\"><fieldset>\n" . |
56 | 56 | Xml::hidden( 'title', $this->getTitle() ) . |
57 | 57 | Xml::element( 'legend', null, wfMsg( 'allmessages' ) ) . "<table><tr>\n" . |
58 | 58 | "<td class=\"mw-label\">" . |
59 | 59 | Xml::label( wfMsg('allmessages-prefix'), 'am-form-prefix' ) . |
60 | 60 | "</td>\n<td class=\"mw-input\">" . |
61 | | - Xml::input( 'prefix', 20, str_replace('_',' ',$this->prefix), array( 'id' => 'am-form-prefix' ) ) . |
62 | | - "</select>" . |
63 | | - "</td>\n</tr><tr>\n<td class='mw-label'>" . |
| 61 | + Xml::input( 'prefix', 20, str_replace('_',' ',$this->prefix), array( 'id' => 'am-form-prefix' ) ) . |
| 62 | + "</select>" . |
| 63 | + "</td>\n</tr><tr>\n<td class='mw-label'>" . |
64 | 64 | Xml::label( wfMsg('allmessages-filter'), 'am-form-filter' ) . |
65 | | - "</td>\n<td class='mw-input'>" . |
| 65 | + "</td>\n<td class='mw-input'>" . |
66 | 66 | Xml::radioLabel( wfMsg('allmessages-filter-unmodified'), |
67 | 67 | 'filter', |
68 | 68 | 'unmodified', |
69 | 69 | 'am-form-filter-unmodified', |
70 | 70 | ( $this->filter == 'unmodified' ? true : false ) |
71 | | - ) . |
| 71 | + ) . |
72 | 72 | Xml::radioLabel( wfMsg('allmessages-filter-all'), |
73 | 73 | 'filter', |
74 | 74 | 'all', |
75 | 75 | 'am-form-filter-all', |
76 | 76 | ( $this->filter == 'all' ? true : false ) |
77 | | - ) . |
| 77 | + ) . |
78 | 78 | Xml::radioLabel( wfMsg('allmessages-filter-modified'), |
79 | 79 | 'filter', |
80 | 80 | 'modified', |
— | — | @@ -88,7 +88,7 @@ |
89 | 89 | $selected = $lang == $this->langCode ? 'selected="selected"' : ''; |
90 | 90 | $out .= "<option value=\"$lang\" $selected>$name</option>\n"; |
91 | 91 | } |
92 | | - $out .= "</td>\n</tr><tr>\n<td></td><td>" . Xml::submitButton( wfMsg('allpagessubmit') ) . |
| 92 | + $out .= "</td>\n</tr><tr>\n<td></td><td>" . Xml::submitButton( wfMsg('allpagessubmit') ) . |
93 | 93 | "</table>" . |
94 | 94 | $this->table->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) . |
95 | 95 | "</fieldset></form>"; |
— | — | @@ -96,35 +96,35 @@ |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | | -/* use TablePager for prettified output. We have to pretend that we're |
| 100 | +/* use TablePager for prettified output. We have to pretend that we're |
101 | 101 | * getting data from a table when in fact not all of it comes from the database. |
102 | 102 | */ |
103 | 103 | class AllmessagesTablePager extends TablePager { |
104 | | - |
| 104 | + |
105 | 105 | var $messages = NULL; |
106 | 106 | var $talkPages = NULL; |
107 | | - |
| 107 | + |
108 | 108 | function __construct( $page, $conds, $langObj = NULL ) { |
109 | 109 | parent::__construct(); |
110 | 110 | $this->mIndexField = 'am_title'; |
111 | 111 | $this->mPage = $page; |
112 | 112 | $this->mConds = $conds; |
113 | 113 | $this->mDefaultDirection = true; //always sort ascending |
114 | | - |
| 114 | + |
115 | 115 | global $wgLang, $wgContLang, $wgRequest; |
116 | | - |
| 116 | + |
117 | 117 | $this->talk = $wgLang->lc( htmlspecialchars( wfMsg( 'talkpagelinktext' ) ) ); |
118 | | - |
| 118 | + |
119 | 119 | $this->lang = ( $langObj ? $langObj : $wgContLang ); |
120 | 120 | $this->langcode = $this->lang->getCode(); |
121 | 121 | $this->foreign = $this->langcode != $wgContLang->getCode(); |
122 | | - |
| 122 | + |
123 | 123 | if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){ |
124 | 124 | $this->custom = NULL; //So won't match in either case |
125 | 125 | } else { |
126 | 126 | $this->custom = $wgRequest->getVal( 'filter' ) == 'unmodified' ? 1 : 0; |
127 | 127 | } |
128 | | - |
| 128 | + |
129 | 129 | $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) ); |
130 | 130 | $prefix = $prefix != '' ? Title::makeTitleSafe( NS_MEDIAWIKI, $wgRequest->getVal( 'prefix', NULL ) ) : NULL; |
131 | 131 | if( $prefix !== NULL ){ |
— | — | @@ -133,20 +133,20 @@ |
134 | 134 | $this->prefix = false; |
135 | 135 | } |
136 | 136 | $this->getSkin(); |
137 | | - |
138 | | - //The suffix that may be needed for message names if we're in a |
| 137 | + |
| 138 | + //The suffix that may be needed for message names if we're in a |
139 | 139 | //different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr' |
140 | 140 | if( $this->foreign ) { |
141 | 141 | $this->suffix = '/' . $this->langcode; |
142 | | - } else { |
| 142 | + } else { |
143 | 143 | $this->suffix = ''; |
144 | 144 | } |
145 | 145 | } |
146 | | - |
| 146 | + |
147 | 147 | function getAllMessages( $desc ){ |
148 | | - |
| 148 | + |
149 | 149 | wfProfileIn( __METHOD__ . '-cache' ); |
150 | | - |
| 150 | + |
151 | 151 | # Make sure all extension messages are available |
152 | 152 | global $wgMessageCache; |
153 | 153 | $wgMessageCache->loadAllMessages( 'en' ); |
— | — | @@ -156,34 +156,34 @@ |
157 | 157 | } else { |
158 | 158 | ksort( $sortedArray ); |
159 | 159 | } |
160 | | - |
| 160 | + |
161 | 161 | $this->messages = array(); |
162 | 162 | foreach( $sortedArray as $key => $value ) { |
163 | 163 | // All messages start with lowercase, but wikis might have both |
164 | 164 | // upper and lowercase MediaWiki: pages if $wgCapitalLinks=false. |
165 | 165 | $ukey = $this->lang->ucfirst( $key ); |
166 | | - |
| 166 | + |
167 | 167 | // The value without any overrides from the MediaWiki: namespace |
168 | 168 | $this->messages[$ukey]['default'] = wfMsgGetKey( $key, /*useDB*/false, $this->langcode, false ); |
169 | | - |
| 169 | + |
170 | 170 | // The message that's actually used by the site |
171 | | - $this->messages[$ukey]['actual'] = wfMsgGetKey( $key, /*useDB*/true, $this->langcode, false ); |
172 | | - |
| 171 | + $this->messages[$ukey]['actual'] = wfMsgGetKey( $key, /*useDB*/true, $this->langcode, false ); |
| 172 | + |
173 | 173 | $this->messages[$ukey]['customised'] = 0; //for now |
174 | | - |
175 | | - $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this |
| 174 | + |
| 175 | + $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this |
176 | 176 | } |
177 | | - |
| 177 | + |
178 | 178 | wfProfileOut( __METHOD__ . '-cache' ); |
179 | | - |
| 179 | + |
180 | 180 | return true; |
181 | 181 | } |
182 | | - |
183 | | - # We only need a list of which messages have *been* customised; |
| 182 | + |
| 183 | + # We only need a list of which messages have *been* customised; |
184 | 184 | # their content is already in the message cache. |
185 | 185 | function markCustomisedMessages(){ |
186 | 186 | $this->talkPages = array(); |
187 | | - |
| 187 | + |
188 | 188 | wfProfileIn( __METHOD__ . "-db" ); |
189 | 189 | |
190 | 190 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -193,7 +193,7 @@ |
194 | 194 | __METHOD__, |
195 | 195 | array( 'USE INDEX' => 'name_title' ) |
196 | 196 | ); |
197 | | - |
| 197 | + |
198 | 198 | while( $s = $dbr->fetchObject( $res ) ) { |
199 | 199 | if( $s->page_namespace == NS_MEDIAWIKI ){ |
200 | 200 | if( $this->foreign ){ |
— | — | @@ -209,21 +209,21 @@ |
210 | 210 | } |
211 | 211 | } |
212 | 212 | $dbr->freeResult( $res ); |
213 | | - |
| 213 | + |
214 | 214 | wfProfileOut( __METHOD__ . "-db" ); |
215 | | - |
| 215 | + |
216 | 216 | return true; |
217 | 217 | } |
218 | | - |
| 218 | + |
219 | 219 | /* This function normally does a database query to get the results; we need |
220 | 220 | * to make a pretend result using a FakeResultWrapper. |
221 | 221 | */ |
222 | 222 | function reallyDoQuery( $offset , $limit , $descending ){ |
223 | 223 | $mResult = new FakeResultWrapper( array() ); |
224 | | - |
| 224 | + |
225 | 225 | if( !$this->messages ) $this->getAllMessages( $descending ); |
226 | 226 | if( $this->talkPages === NULL ) $this->markCustomisedMessages(); |
227 | | - |
| 227 | + |
228 | 228 | $count = 0; |
229 | 229 | foreach( $this->messages as $key => $value ){ |
230 | 230 | if( $value['customised'] !== $this->custom && |
— | — | @@ -235,7 +235,7 @@ |
236 | 236 | 'am_default' => $value['default'], |
237 | 237 | 'am_customised' => $value['customised'], |
238 | 238 | ); |
239 | | - unset( $this->messages[$key] ); // save a few bytes |
| 239 | + unset( $this->messages[$key] ); // save a few bytes |
240 | 240 | $count++; |
241 | 241 | } |
242 | 242 | if( $count == $limit ) break; |
— | — | @@ -243,26 +243,26 @@ |
244 | 244 | unset( $this->messages ); //no longer needed, free up some memory |
245 | 245 | return $mResult; |
246 | 246 | } |
247 | | - |
| 247 | + |
248 | 248 | function getStartBody() { |
249 | | - return "<table border=\"1\" class=\"TablePager\" style=\"width:100%;\" id=\"allmessagestable\"><thead>\n<tr>" . |
250 | | - "<th rowspan=\"2\">" . wfMsg('allmessagesname') . "</th><th>" . wfMsg('allmessagesdefault') . |
| 249 | + return "<table border=\"1\" class=\"TablePager\" style=\"width:100%;\" id=\"allmessagestable\"><thead>\n<tr>" . |
| 250 | + "<th rowspan=\"2\">" . wfMsg('allmessagesname') . "</th><th>" . wfMsg('allmessagesdefault') . |
251 | 251 | "</tr>\n<tr><th>" . wfMsg('allmessagescurrent') . "</th></tr>\n"; |
252 | 252 | } |
253 | | - |
| 253 | + |
254 | 254 | function formatValue( $field , $value ){ |
255 | 255 | global $wgLang; |
256 | 256 | switch( $field ){ |
257 | | - |
258 | | - case 'am_title' : |
259 | | - |
| 257 | + |
| 258 | + case 'am_title' : |
| 259 | + |
260 | 260 | $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix ); |
261 | 261 | $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix ); |
262 | 262 | |
263 | 263 | if( $this->mCurrentRow->am_customised ){ |
264 | 264 | $title = $this->mSkin->linkKnown( $title, $wgLang->lcfirst( $value ) ); |
265 | 265 | } else { |
266 | | - $title = $this->mSkin->link( $title, |
| 266 | + $title = $this->mSkin->link( $title, |
267 | 267 | $wgLang->lcfirst( $value ), |
268 | 268 | array(), |
269 | 269 | array(), |
— | — | @@ -271,26 +271,26 @@ |
272 | 272 | if( array_key_exists( $talk->getDBkey() , $this->talkPages ) ) { |
273 | 273 | $talk = $this->mSkin->linkKnown( $talk , $this->talk ); |
274 | 274 | } else { |
275 | | - $talk = $this->mSkin->link( $talk, |
276 | | - $this->talk, |
277 | | - array(), |
278 | | - array(), |
| 275 | + $talk = $this->mSkin->link( $talk, |
| 276 | + $this->talk, |
| 277 | + array(), |
| 278 | + array(), |
279 | 279 | array( 'broken' ) ); |
280 | 280 | } |
281 | 281 | return $title . ' (' . $talk . ')'; |
282 | | - |
| 282 | + |
283 | 283 | case 'am_default' : |
284 | 284 | return Sanitizer::escapeHtmlAllowEntities( $value, ENT_QUOTES ); |
285 | | - case 'am_actual' : |
| 285 | + case 'am_actual' : |
286 | 286 | return Sanitizer::escapeHtmlAllowEntities( $value, ENT_QUOTES ); |
287 | 287 | } |
288 | 288 | return ''; |
289 | 289 | } |
290 | | - |
| 290 | + |
291 | 291 | function formatRow( $row ){ |
292 | 292 | //Do all the normal stuff |
293 | 293 | $s = parent::formatRow( $row ); |
294 | | - |
| 294 | + |
295 | 295 | //But if there's a customised message, add that too. |
296 | 296 | if( $row->am_customised ){ |
297 | 297 | $s .= Xml::openElement( 'tr', $this->getRowAttrs( $row, true ) ); |
— | — | @@ -298,24 +298,24 @@ |
299 | 299 | if ( $formatted == '' ) { |
300 | 300 | $formatted = ' '; |
301 | 301 | } |
302 | | - $s .= Xml::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted ) |
| 302 | + $s .= Xml::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted ) |
303 | 303 | . "</tr>\n"; |
304 | 304 | } |
305 | | - return $s; |
| 305 | + return $s; |
306 | 306 | } |
307 | | - |
| 307 | + |
308 | 308 | function getRowAttrs( $row, $isSecond=false ){ |
309 | 309 | $arr = array(); |
310 | 310 | global $wgLang; |
311 | 311 | if( $row->am_customised ){ |
312 | 312 | $arr['class'] = 'allmessages-customised'; |
313 | | - } |
| 313 | + } |
314 | 314 | if( !$isSecond ){ |
315 | 315 | $arr['id'] = Sanitizer::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title ) ); |
316 | 316 | } |
317 | 317 | return $arr; |
318 | 318 | } |
319 | | - |
| 319 | + |
320 | 320 | function getCellAttrs( $field, $value ){ |
321 | 321 | if( $this->mCurrentRow->am_customised && $field == 'am_title' ){ |
322 | 322 | return array( 'rowspan' => '2', 'class' => $field ); |
— | — | @@ -323,7 +323,7 @@ |
324 | 324 | return array( 'class' => $field ); |
325 | 325 | } |
326 | 326 | } |
327 | | - |
| 327 | + |
328 | 328 | // This is not actually used, as getStartBody is overridden above |
329 | 329 | function getFieldNames() { |
330 | 330 | return array( 'am_title' => wfMsg('allmessagesname'), |
— | — | @@ -346,37 +346,37 @@ |
347 | 347 | * doesn't go anywhere near an actual database. |
348 | 348 | */ |
349 | 349 | class FakeResultWrapper extends ResultWrapper { |
350 | | - |
| 350 | + |
351 | 351 | var $result = array(); |
352 | 352 | var $db = NULL; //And it's going to stay that way :D |
353 | 353 | var $pos = 0; |
354 | 354 | var $currentRow = NULL; |
355 | | - |
| 355 | + |
356 | 356 | function __construct( $array ){ |
357 | 357 | $this->result = $array; |
358 | 358 | } |
359 | | - |
| 359 | + |
360 | 360 | function numRows() { |
361 | | - return count( $this->result ); |
| 361 | + return count( $this->result ); |
362 | 362 | } |
363 | | - |
| 363 | + |
364 | 364 | function fetchRow() { |
365 | 365 | $this->currentRow = $this->result[$this->pos++]; |
366 | 366 | return $this->currentRow; |
367 | 367 | } |
368 | | - |
| 368 | + |
369 | 369 | function seek( $row ) { |
370 | 370 | $this->pos = $row; |
371 | 371 | } |
372 | 372 | |
373 | 373 | function free() {} |
374 | | - |
| 374 | + |
375 | 375 | // Callers want to be able to access fields with $this->fieldName |
376 | 376 | function fetchObject(){ |
377 | 377 | $this->currentRow = $this->result[$this->pos++]; |
378 | | - return (object)$this->currentRow; |
| 378 | + return (object)$this->currentRow; |
379 | 379 | } |
380 | | - |
| 380 | + |
381 | 381 | function rewind() { |
382 | 382 | $this->pos = 0; |
383 | 383 | $this->currentRow = NULL; |