r53309 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53308‎ | r53309 | r53310 >
Date:11:48, 15 July 2009
Author:demon
Status:ok
Tags:
Comment:
Followup to r53286: Fix trailing whitespace.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialAllmessages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialAllmessages.php
@@ -5,22 +5,22 @@
66 * @ingroup SpecialPage
77 */
88 class SpecialAllmessages extends SpecialPage {
9 -
 9+
1010 /**
1111 * Constructor
1212 */
1313 public function __construct() {
1414 parent::__construct( 'Allmessages' );
1515 }
16 -
 16+
1717 /**
1818 * Execute
1919 */
2020 function execute( $par ) {
2121 global $wgOut, $wgRequest;
22 -
 22+
2323 $this->setHeaders();
24 -
 24+
2525 global $wgUseDatabaseMessages;
2626 if( !$wgUseDatabaseMessages ) {
2727 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
@@ -31,49 +31,49 @@
3232
3333 $this->filter = $wgRequest->getVal( 'filter', 'all' );
3434 $this->prefix = $wgRequest->getVal( 'prefix', '' );
35 -
 35+
3636 $this->table = new AllmessagesTablePager( $this,
3737 $conds=array(),
3838 wfGetLangObj( $wgRequest->getVal( 'lang', false ) ) );
39 -
 39+
4040 $this->langCode = $this->table->lang->getCode();
41 -
 41+
4242 $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() .
4646 $this->table->getNavigationBar() );
47 -
 47+
4848 }
49 -
 49+
5050 function buildForm() {
5151 $url = $this->getTitle()->escapeLocalURL();
5252 $languages = Language::getLanguageNames( false );
5353 ksort( $languages );
54 -
 54+
5555 $out = "<form method=\"get\" action=\"$url\"><fieldset>\n" .
5656 Xml::hidden( 'title', $this->getTitle() ) .
5757 Xml::element( 'legend', null, wfMsg( 'allmessages' ) ) . "<table><tr>\n" .
5858 "<td class=\"mw-label\">" .
5959 Xml::label( wfMsg('allmessages-prefix'), 'am-form-prefix' ) .
6060 "</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'>" .
6464 Xml::label( wfMsg('allmessages-filter'), 'am-form-filter' ) .
65 - "</td>\n<td class='mw-input'>" .
 65+ "</td>\n<td class='mw-input'>" .
6666 Xml::radioLabel( wfMsg('allmessages-filter-unmodified'),
6767 'filter',
6868 'unmodified',
6969 'am-form-filter-unmodified',
7070 ( $this->filter == 'unmodified' ? true : false )
71 - ) .
 71+ ) .
7272 Xml::radioLabel( wfMsg('allmessages-filter-all'),
7373 'filter',
7474 'all',
7575 'am-form-filter-all',
7676 ( $this->filter == 'all' ? true : false )
77 - ) .
 77+ ) .
7878 Xml::radioLabel( wfMsg('allmessages-filter-modified'),
7979 'filter',
8080 'modified',
@@ -88,7 +88,7 @@
8989 $selected = $lang == $this->langCode ? 'selected="selected"' : '';
9090 $out .= "<option value=\"$lang\" $selected>$name</option>\n";
9191 }
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') ) .
9393 "</table>" .
9494 $this->table->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
9595 "</fieldset></form>";
@@ -96,35 +96,35 @@
9797 }
9898 }
9999
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
101101 * getting data from a table when in fact not all of it comes from the database.
102102 */
103103 class AllmessagesTablePager extends TablePager {
104 -
 104+
105105 var $messages = NULL;
106106 var $talkPages = NULL;
107 -
 107+
108108 function __construct( $page, $conds, $langObj = NULL ) {
109109 parent::__construct();
110110 $this->mIndexField = 'am_title';
111111 $this->mPage = $page;
112112 $this->mConds = $conds;
113113 $this->mDefaultDirection = true; //always sort ascending
114 -
 114+
115115 global $wgLang, $wgContLang, $wgRequest;
116 -
 116+
117117 $this->talk = $wgLang->lc( htmlspecialchars( wfMsg( 'talkpagelinktext' ) ) );
118 -
 118+
119119 $this->lang = ( $langObj ? $langObj : $wgContLang );
120120 $this->langcode = $this->lang->getCode();
121121 $this->foreign = $this->langcode != $wgContLang->getCode();
122 -
 122+
123123 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
124124 $this->custom = NULL; //So won't match in either case
125125 } else {
126126 $this->custom = $wgRequest->getVal( 'filter' ) == 'unmodified' ? 1 : 0;
127127 }
128 -
 128+
129129 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
130130 $prefix = $prefix != '' ? Title::makeTitleSafe( NS_MEDIAWIKI, $wgRequest->getVal( 'prefix', NULL ) ) : NULL;
131131 if( $prefix !== NULL ){
@@ -133,20 +133,20 @@
134134 $this->prefix = false;
135135 }
136136 $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
139139 //different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
140140 if( $this->foreign ) {
141141 $this->suffix = '/' . $this->langcode;
142 - } else {
 142+ } else {
143143 $this->suffix = '';
144144 }
145145 }
146 -
 146+
147147 function getAllMessages( $desc ){
148 -
 148+
149149 wfProfileIn( __METHOD__ . '-cache' );
150 -
 150+
151151 # Make sure all extension messages are available
152152 global $wgMessageCache;
153153 $wgMessageCache->loadAllMessages( 'en' );
@@ -156,34 +156,34 @@
157157 } else {
158158 ksort( $sortedArray );
159159 }
160 -
 160+
161161 $this->messages = array();
162162 foreach( $sortedArray as $key => $value ) {
163163 // All messages start with lowercase, but wikis might have both
164164 // upper and lowercase MediaWiki: pages if $wgCapitalLinks=false.
165165 $ukey = $this->lang->ucfirst( $key );
166 -
 166+
167167 // The value without any overrides from the MediaWiki: namespace
168168 $this->messages[$ukey]['default'] = wfMsgGetKey( $key, /*useDB*/false, $this->langcode, false );
169 -
 169+
170170 // 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+
173173 $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
176176 }
177 -
 177+
178178 wfProfileOut( __METHOD__ . '-cache' );
179 -
 179+
180180 return true;
181181 }
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;
184184 # their content is already in the message cache.
185185 function markCustomisedMessages(){
186186 $this->talkPages = array();
187 -
 187+
188188 wfProfileIn( __METHOD__ . "-db" );
189189
190190 $dbr = wfGetDB( DB_SLAVE );
@@ -193,7 +193,7 @@
194194 __METHOD__,
195195 array( 'USE INDEX' => 'name_title' )
196196 );
197 -
 197+
198198 while( $s = $dbr->fetchObject( $res ) ) {
199199 if( $s->page_namespace == NS_MEDIAWIKI ){
200200 if( $this->foreign ){
@@ -209,21 +209,21 @@
210210 }
211211 }
212212 $dbr->freeResult( $res );
213 -
 213+
214214 wfProfileOut( __METHOD__ . "-db" );
215 -
 215+
216216 return true;
217217 }
218 -
 218+
219219 /* This function normally does a database query to get the results; we need
220220 * to make a pretend result using a FakeResultWrapper.
221221 */
222222 function reallyDoQuery( $offset , $limit , $descending ){
223223 $mResult = new FakeResultWrapper( array() );
224 -
 224+
225225 if( !$this->messages ) $this->getAllMessages( $descending );
226226 if( $this->talkPages === NULL ) $this->markCustomisedMessages();
227 -
 227+
228228 $count = 0;
229229 foreach( $this->messages as $key => $value ){
230230 if( $value['customised'] !== $this->custom &&
@@ -235,7 +235,7 @@
236236 'am_default' => $value['default'],
237237 'am_customised' => $value['customised'],
238238 );
239 - unset( $this->messages[$key] ); // save a few bytes
 239+ unset( $this->messages[$key] ); // save a few bytes
240240 $count++;
241241 }
242242 if( $count == $limit ) break;
@@ -243,26 +243,26 @@
244244 unset( $this->messages ); //no longer needed, free up some memory
245245 return $mResult;
246246 }
247 -
 247+
248248 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') .
251251 "</tr>\n<tr><th>" . wfMsg('allmessagescurrent') . "</th></tr>\n";
252252 }
253 -
 253+
254254 function formatValue( $field , $value ){
255255 global $wgLang;
256256 switch( $field ){
257 -
258 - case 'am_title' :
259 -
 257+
 258+ case 'am_title' :
 259+
260260 $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix );
261261 $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix );
262262
263263 if( $this->mCurrentRow->am_customised ){
264264 $title = $this->mSkin->linkKnown( $title, $wgLang->lcfirst( $value ) );
265265 } else {
266 - $title = $this->mSkin->link( $title,
 266+ $title = $this->mSkin->link( $title,
267267 $wgLang->lcfirst( $value ),
268268 array(),
269269 array(),
@@ -271,26 +271,26 @@
272272 if( array_key_exists( $talk->getDBkey() , $this->talkPages ) ) {
273273 $talk = $this->mSkin->linkKnown( $talk , $this->talk );
274274 } 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(),
279279 array( 'broken' ) );
280280 }
281281 return $title . ' (' . $talk . ')';
282 -
 282+
283283 case 'am_default' :
284284 return Sanitizer::escapeHtmlAllowEntities( $value, ENT_QUOTES );
285 - case 'am_actual' :
 285+ case 'am_actual' :
286286 return Sanitizer::escapeHtmlAllowEntities( $value, ENT_QUOTES );
287287 }
288288 return '';
289289 }
290 -
 290+
291291 function formatRow( $row ){
292292 //Do all the normal stuff
293293 $s = parent::formatRow( $row );
294 -
 294+
295295 //But if there's a customised message, add that too.
296296 if( $row->am_customised ){
297297 $s .= Xml::openElement( 'tr', $this->getRowAttrs( $row, true ) );
@@ -298,24 +298,24 @@
299299 if ( $formatted == '' ) {
300300 $formatted = '&nbsp;';
301301 }
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 )
303303 . "</tr>\n";
304304 }
305 - return $s;
 305+ return $s;
306306 }
307 -
 307+
308308 function getRowAttrs( $row, $isSecond=false ){
309309 $arr = array();
310310 global $wgLang;
311311 if( $row->am_customised ){
312312 $arr['class'] = 'allmessages-customised';
313 - }
 313+ }
314314 if( !$isSecond ){
315315 $arr['id'] = Sanitizer::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title ) );
316316 }
317317 return $arr;
318318 }
319 -
 319+
320320 function getCellAttrs( $field, $value ){
321321 if( $this->mCurrentRow->am_customised && $field == 'am_title' ){
322322 return array( 'rowspan' => '2', 'class' => $field );
@@ -323,7 +323,7 @@
324324 return array( 'class' => $field );
325325 }
326326 }
327 -
 327+
328328 // This is not actually used, as getStartBody is overridden above
329329 function getFieldNames() {
330330 return array( 'am_title' => wfMsg('allmessagesname'),
@@ -346,37 +346,37 @@
347347 * doesn't go anywhere near an actual database.
348348 */
349349 class FakeResultWrapper extends ResultWrapper {
350 -
 350+
351351 var $result = array();
352352 var $db = NULL; //And it's going to stay that way :D
353353 var $pos = 0;
354354 var $currentRow = NULL;
355 -
 355+
356356 function __construct( $array ){
357357 $this->result = $array;
358358 }
359 -
 359+
360360 function numRows() {
361 - return count( $this->result );
 361+ return count( $this->result );
362362 }
363 -
 363+
364364 function fetchRow() {
365365 $this->currentRow = $this->result[$this->pos++];
366366 return $this->currentRow;
367367 }
368 -
 368+
369369 function seek( $row ) {
370370 $this->pos = $row;
371371 }
372372
373373 function free() {}
374 -
 374+
375375 // Callers want to be able to access fields with $this->fieldName
376376 function fetchObject(){
377377 $this->currentRow = $this->result[$this->pos++];
378 - return (object)$this->currentRow;
 378+ return (object)$this->currentRow;
379379 }
380 -
 380+
381381 function rewind() {
382382 $this->pos = 0;
383383 $this->currentRow = NULL;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r53286(bug 16497) Paginate Special:AllMessagesdemon02:03, 15 July 2009

Status & tagging log