r44031 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44030‎ | r44031 | r44032 >
Date:23:06, 28 November 2008
Author:aaron
Status:ok
Tags:
Comment:
Various minor code style tweaks and cleanup to RC
Modified paths:
  • /trunk/phase3/includes/ChangesList.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRecentchanges.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ChangesList.php
@@ -3,10 +3,9 @@
44 /**
55 * @todo document
66 */
7 -class RCCacheEntry extends RecentChange
8 -{
 7+class RCCacheEntry extends RecentChange {
98 var $secureName, $link;
10 - var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
 9+ var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
1110 var $userlink, $timestamp, $watched;
1211
1312 static function newFromParent( $rc ) {
@@ -15,7 +14,7 @@
1615 $rc2->mExtra = $rc->mExtra;
1716 return $rc2;
1817 }
19 -} ;
 18+}
2019
2120 /**
2221 * Class to show various lists of changes:
@@ -25,13 +24,12 @@
2625 */
2726 class ChangesList {
2827 # Called by history lists and recent changes
29 - #
3028
3129 /**
3230 * Changeslist contructor
3331 * @param Skin $skin
3432 */
35 - function __construct( &$skin ) {
 33+ public function __construct( &$skin ) {
3634 $this->skin =& $skin;
3735 $this->preCacheMessages();
3836 }
@@ -58,7 +56,6 @@
5957 * they are called often, we call them once and save them in $this->message
6058 */
6159 private function preCacheMessages() {
62 - // Precache various messages
6360 if( !isset( $this->message ) ) {
6461 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
6562 'blocklink history boteditletter semicolon-separator' ) as $msg ) {
@@ -78,10 +75,10 @@
7976 * @return string
8077 */
8178 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
82 - $f = $new ? '<span class="newpage">' . $this->message['newpageletter'] . '</span>'
83 - : $nothing;
84 - $f .= $minor ? '<span class="minor">' . $this->message['minoreditletter'] . '</span>'
85 - : $nothing;
 79+ $f = $new ?
 80+ '<span class="newpage">' . $this->message['newpageletter'] . '</span>' : $nothing;
 81+ $f .= $minor ?
 82+ '<span class="minor">' . $this->message['minoreditletter'] . '</span>' : $nothing;
8683 $f .= $bot ? '<span class="bot">' . $this->message['boteditletter'] . '</span>' : $nothing;
8784 $f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
8885 return $f;
@@ -142,14 +139,13 @@
143140 # Hist
144141 $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) .
145142 ') . . ';
146 -
147143 # "[[x]] moved to [[y]]"
148144 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
149145 $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
150146 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
151147 }
152148
153 - protected function insertDateHeader(&$s, $rc_timestamp) {
 149+ protected function insertDateHeader( &$s, $rc_timestamp ) {
154150 global $wgLang;
155151
156152 # Make date header if necessary
@@ -164,21 +160,20 @@
165161 }
166162 }
167163
168 - protected function insertLog(&$s, $title, $logtype) {
 164+ protected function insertLog( &$s, $title, $logtype ) {
169165 $logname = LogPage::logName( $logtype );
170166 $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')';
171167 }
172168
173 - protected function insertDiffHist(&$s, &$rc, $unpatrolled) {
 169+ protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
174170 # Diff link
175171 if( !$this->userCan($rc,Revision::DELETED_TEXT) ) {
176172 $diffLink = $this->message['diff'];
177173 } else if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
178174 $diffLink = $this->message['diff'];
179175 } else {
180 - $rcidparam = $unpatrolled
181 - ? array( 'rcid' => $rc->mAttribs['rc_id'] )
182 - : array();
 176+ $rcidparam = $unpatrolled ?
 177+ array( 'rcid' => $rc->mAttribs['rc_id'] ) : array();
183178 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
184179 wfArrayToCGI( array(
185180 'curid' => $rc->mAttribs['rc_cur_id'],
@@ -188,7 +183,6 @@
189184 '', '', ' tabindex="'.$rc->counter.'"');
190185 }
191186 $s .= '('.$diffLink.') (';
192 -
193187 # History link
194188 $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'],
195189 wfArrayToCGI( array(
@@ -197,31 +191,32 @@
198192 $s .= ') . . ';
199193 }
200194
201 - protected function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
202 - # Article link
 195+ protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
 196+ global $wgContLang;
203197 # If it's a new article, there is no diff link, but if it hasn't been
204198 # patrolled yet, we need to give users a way to do so
205 - $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW )
206 - ? 'rcid='.$rc->mAttribs['rc_id']
207 - : '';
 199+ $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) ?
 200+ 'rcid='.$rc->mAttribs['rc_id'] : '';
208201 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
209202 $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
210203 $articlelink = '<span class="history-deleted">'.$articlelink.'</span>';
211204 } else {
212205 $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
213206 }
214 - if( $watched )
 207+ # Bolden pages watched by this user
 208+ if( $watched ) {
215209 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
216 - global $wgContLang;
 210+ }
 211+ # RTL/LTR marker
217212 $articlelink .= $wgContLang->getDirMark();
218213
219214 wfRunHooks('ChangesListInsertArticleLink',
220215 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched));
221216
222 - $s .= ' '.$articlelink;
 217+ $s .= " $articlelink";
223218 }
224219
225 - protected function insertTimestamp(&$s, $rc) {
 220+ protected function insertTimestamp( &$s, $rc ) {
226221 global $wgLang;
227222 # Timestamp
228223 $s .= $this->message['semicolon-separator'] . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
Index: trunk/phase3/includes/specials/SpecialRecentchanges.php
@@ -50,7 +50,7 @@
5151 $opts->fetchValuesFromRequest( $wgRequest );
5252
5353 // Give precedence to subpage syntax
54 - if ( $parameters !== null ) {
 54+ if( $parameters !== null ) {
5555 $this->parseParameters( $parameters, $opts );
5656 }
5757
@@ -105,14 +105,14 @@
106106 }
107107
108108 foreach( $rows as $row ) {
109 - if ( !$feedFormat ) {
 109+ if( !$feedFormat ) {
110110 // User page and talk links
111111 $batch->add( NS_USER, $row->rc_user_text );
112112 $batch->add( NS_USER_TALK, $row->rc_user_text );
113113 }
114114 }
115115
116 - if ( $feedFormat ) {
 116+ if( $feedFormat ) {
117117 list( $feed, $feedObj ) = $this->getFeedObject( $feedFormat );
118118 $feed->execute( $feedObj, $rows, $opts['limit'], $opts['hideminor'], $lastmod );
119119 } else {
@@ -146,21 +146,21 @@
147147 */
148148 public function parseParameters( $par, FormOptions $opts ) {
149149 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
150 - foreach ( $bits as $bit ) {
151 - if ( 'hidebots' === $bit ) $opts['hidebots'] = true;
152 - if ( 'bots' === $bit ) $opts['hidebots'] = false;
153 - if ( 'hideminor' === $bit ) $opts['hideminor'] = true;
154 - if ( 'minor' === $bit ) $opts['hideminor'] = false;
155 - if ( 'hideliu' === $bit ) $opts['hideliu'] = true;
156 - if ( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
157 - if ( 'hideanons' === $bit ) $opts['hideanons'] = true;
158 - if ( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
 150+ foreach( $bits as $bit ) {
 151+ if( 'hidebots' === $bit ) $opts['hidebots'] = true;
 152+ if( 'bots' === $bit ) $opts['hidebots'] = false;
 153+ if( 'hideminor' === $bit ) $opts['hideminor'] = true;
 154+ if( 'minor' === $bit ) $opts['hideminor'] = false;
 155+ if( 'hideliu' === $bit ) $opts['hideliu'] = true;
 156+ if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
 157+ if( 'hideanons' === $bit ) $opts['hideanons'] = true;
 158+ if( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
159159
160 - if ( is_numeric( $bit ) ) $opts['limit'] = $bit;
 160+ if( is_numeric( $bit ) ) $opts['limit'] = $bit;
161161
162162 $m = array();
163 - if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
164 - if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
 163+ if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
 164+ if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
165165 }
166166 }
167167
@@ -176,7 +176,7 @@
177177 global $wgUseRCPatrol, $wgOut;
178178 $dbr = wfGetDB( DB_SLAVE );
179179 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __FUNCTION__ );
180 - if ( $feedFormat || !$wgUseRCPatrol ) {
 180+ if( $feedFormat || !$wgUseRCPatrol ) {
181181 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
182182 # Client cache fresh and headers sent, nothing more to do.
183183 return false;
@@ -229,12 +229,12 @@
230230 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
231231 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
232232
233 - if ( $opts['hideminor'] ) $conds['rc_minor'] = 0;
234 - if ( $opts['hidebots'] ) $conds['rc_bot'] = 0;
235 - if ( $hidePatrol ) $conds['rc_patrolled'] = 0;
236 - if ( $forcebot ) $conds['rc_bot'] = 1;
237 - if ( $hideLoggedInUsers ) $conds[] = 'rc_user = 0';
238 - if ( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
 233+ if( $opts['hideminor'] ) $conds['rc_minor'] = 0;
 234+ if( $opts['hidebots'] ) $conds['rc_bot'] = 0;
 235+ if( $hidePatrol ) $conds['rc_patrolled'] = 0;
 236+ if( $forcebot ) $conds['rc_bot'] = 1;
 237+ if( $hideLoggedInUsers ) $conds[] = 'rc_user = 0';
 238+ if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
239239
240240 if( $opts['hidemyself'] ) {
241241 if( $wgUser->getId() ) {
@@ -245,8 +245,8 @@
246246 }
247247
248248 # Namespace filtering
249 - if ( $opts['namespace'] !== '' ) {
250 - if ( !$opts['invert'] ) {
 249+ if( $opts['namespace'] !== '' ) {
 250+ if( !$opts['invert'] ) {
251251 $conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] );
252252 } else {
253253 $conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] );
@@ -278,7 +278,8 @@
279279 // JOIN on watchlist for users
280280 if( $uid ) {
281281 $tables[] = 'watchlist';
282 - $join_conds = array( 'watchlist' => array('LEFT JOIN',"wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
 282+ $join_conds = array( 'watchlist' => array('LEFT JOIN',
 283+ "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
283284 }
284285
285286 wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
@@ -326,7 +327,7 @@
327328
328329 $limit = $opts['limit'];
329330
330 - if ( !$this->including() ) {
 331+ if( !$this->including() ) {
331332 // Output options box
332333 $this->doHeader( $opts );
333334 }
@@ -334,55 +335,47 @@
335336 // And now for the content
336337 $wgOut->setSyndicated( true );
337338
338 - $list = ChangesList::newFromUser( $wgUser );
339 -
340 - if ( $wgAllowCategorizedRecentChanges ) {
 339+ if( $wgAllowCategorizedRecentChanges ) {
341340 $this->filterByCategories( $rows, $opts );
342341 }
343342
344 - $s = $list->beginRecentChangesList();
345 - $counter = 1;
346 -
347343 $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
348344 $watcherCache = array();
349345
350346 $dbr = wfGetDB( DB_SLAVE );
351347
352 - foreach( $rows as $obj ){
353 - if( $limit == 0) {
 348+ $counter = 1;
 349+ $list = ChangesList::newFromUser( $wgUser );
 350+
 351+ $s = $list->beginRecentChangesList();
 352+ foreach( $rows as $obj ) {
 353+ if( $limit == 0 ) {
354354 break;
355355 }
 356+ $rc = RecentChange::newFromRow( $obj );
 357+ $rc->counter = $counter++;
356358
357 - if ( ! ( $opts['hideminor'] && $obj->rc_minor ) &&
358 - ! ( $opts['hidepatrolled'] && $obj->rc_patrolled ) ) {
359 - $rc = RecentChange::newFromRow( $obj );
360 - $rc->counter = $counter++;
 359+ $rc->notificationtimestamp = false; // Default
 360+ if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) {
 361+ $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp);
 362+ }
361363
362 - if ($wgShowUpdatedMarker
363 - && !empty( $obj->wl_notificationtimestamp )
364 - && ($obj->rc_timestamp >= $obj->wl_notificationtimestamp)) {
365 - $rc->notificationtimestamp = true;
366 - } else {
367 - $rc->notificationtimestamp = false;
 364+ $rc->numberofWatchingusers = 0; // Default
 365+ if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
 366+ if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) {
 367+ $watcherCache[$obj->rc_namespace][$obj->rc_title] =
 368+ $dbr->selectField( 'watchlist',
 369+ 'COUNT(*)',
 370+ array(
 371+ 'wl_namespace' => $obj->rc_namespace,
 372+ 'wl_title' => $obj->rc_title,
 373+ ),
 374+ __METHOD__ . '-watchers' );
368375 }
369 -
370 - $rc->numberofWatchingusers = 0; // Default
371 - if ($showWatcherCount && $obj->rc_namespace >= 0) {
372 - if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) {
373 - $watcherCache[$obj->rc_namespace][$obj->rc_title] =
374 - $dbr->selectField( 'watchlist',
375 - 'COUNT(*)',
376 - array(
377 - 'wl_namespace' => $obj->rc_namespace,
378 - 'wl_title' => $obj->rc_title,
379 - ),
380 - __METHOD__ . '-watchers' );
381 - }
382 - $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
383 - }
384 - $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
385 - --$limit;
 376+ $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
386377 }
 378+ $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
 379+ --$limit;
387380 }
388381 $s .= $list->endRecentChangesList();
389382 $wgOut->addHTML( $s );
@@ -413,13 +406,13 @@
414407 $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
415408
416409 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
417 - foreach ( $extraOpts as $optionRow ) {
 410+ foreach( $extraOpts as $optionRow ) {
418411 # Add submit button to the last row only
419412 ++$count;
420413 $addSubmit = $count === $extraOptsCount ? $submit : '';
421414
422415 $out .= Xml::openElement( 'tr' );
423 - if ( is_array( $optionRow ) ) {
 416+ if( is_array( $optionRow ) ) {
424417 $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
425418 $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
426419 } else {
@@ -430,7 +423,7 @@
431424 $out .= Xml::closeElement( 'table' );
432425
433426 $unconsumed = $opts->getUnconsumedValues();
434 - foreach ( $unconsumed as $key => $value ) {
 427+ foreach( $unconsumed as $key => $value ) {
435428 $out .= Xml::hidden( $key, $value );
436429 }
437430
@@ -458,7 +451,7 @@
459452 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
460453
461454 global $wgAllowCategorizedRecentChanges;
462 - if ( $wgAllowCategorizedRecentChanges ) {
 455+ if( $wgAllowCategorizedRecentChanges ) {
463456 $extraOpts['category'] = $this->categoryFilterForm( $opts );
464457 }
465458
@@ -529,30 +522,30 @@
530523
531524 # Filter categories
532525 $cats = array();
533 - foreach ( $categories as $cat ) {
 526+ foreach( $categories as $cat ) {
534527 $cat = trim( $cat );
535 - if ( $cat == "" ) continue;
 528+ if( $cat == "" ) continue;
536529 $cats[] = $cat;
537530 }
538531
539532 # Filter articles
540533 $articles = array();
541534 $a2r = array();
542 - foreach ( $rows AS $k => $r ) {
 535+ foreach( $rows AS $k => $r ) {
543536 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
544537 $id = $nt->getArticleID();
545 - if ( $id == 0 ) continue; # Page might have been deleted...
546 - if ( !in_array($id, $articles) ) {
 538+ if( $id == 0 ) continue; # Page might have been deleted...
 539+ if( !in_array($id, $articles) ) {
547540 $articles[] = $id;
548541 }
549 - if ( !isset($a2r[$id]) ) {
 542+ if( !isset($a2r[$id]) ) {
550543 $a2r[$id] = array();
551544 }
552545 $a2r[$id][] = $k;
553546 }
554547
555548 # Shortcut?
556 - if ( !count($articles) || !count($cats) )
 549+ if( !count($articles) || !count($cats) )
557550 return ;
558551
559552 # Look up
@@ -562,8 +555,8 @@
563556
564557 # Filter
565558 $newrows = array();
566 - foreach ( $match AS $id ) {
567 - foreach ( $a2r[$id] AS $rev ) {
 559+ foreach( $match AS $id ) {
 560+ foreach( $a2r[$id] AS $rev ) {
568561 $k = $rev;
569562 $newrows[$k] = $rows[$k];
570563 }

Status & tagging log