From ee1ed3fd12f1f5af3009e27d13efd696ed95e925 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 28 Nov 2008 23:06:25 +0000 Subject: [PATCH] Various minor code style tweaks and cleanup to RC --- includes/ChangesList.php | 51 ++++---- includes/specials/SpecialRecentchanges.php | 143 ++++++++++----------- 2 files changed, 91 insertions(+), 103 deletions(-) diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 6b0a049a12..34b22943a8 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -3,10 +3,9 @@ /** * @todo document */ -class RCCacheEntry extends RecentChange -{ +class RCCacheEntry extends RecentChange { var $secureName, $link; - var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ; + var $curlink , $difflink, $lastlink, $usertalklink, $versionlink; var $userlink, $timestamp, $watched; static function newFromParent( $rc ) { @@ -15,7 +14,7 @@ class RCCacheEntry extends RecentChange $rc2->mExtra = $rc->mExtra; return $rc2; } -} ; +} /** * Class to show various lists of changes: @@ -25,13 +24,12 @@ class RCCacheEntry extends RecentChange */ class ChangesList { # Called by history lists and recent changes - # /** * Changeslist contructor * @param Skin $skin */ - function __construct( &$skin ) { + public function __construct( &$skin ) { $this->skin =& $skin; $this->preCacheMessages(); } @@ -58,7 +56,6 @@ class ChangesList { * they are called often, we call them once and save them in $this->message */ private function preCacheMessages() { - // Precache various messages if( !isset( $this->message ) ) { foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '. 'blocklink history boteditletter semicolon-separator' ) as $msg ) { @@ -78,10 +75,10 @@ class ChangesList { * @return string */ protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) { - $f = $new ? '' . $this->message['newpageletter'] . '' - : $nothing; - $f .= $minor ? '' . $this->message['minoreditletter'] . '' - : $nothing; + $f = $new ? + '' . $this->message['newpageletter'] . '' : $nothing; + $f .= $minor ? + '' . $this->message['minoreditletter'] . '' : $nothing; $f .= $bot ? '' . $this->message['boteditletter'] . '' : $nothing; $f .= $patrolled ? '!' : $nothing; return $f; @@ -142,14 +139,13 @@ class ChangesList { # Hist $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) . ') . . '; - # "[[x]] moved to [[y]]" $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir'; $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ), $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) ); } - protected function insertDateHeader(&$s, $rc_timestamp) { + protected function insertDateHeader( &$s, $rc_timestamp ) { global $wgLang; # Make date header if necessary @@ -164,21 +160,20 @@ class ChangesList { } } - protected function insertLog(&$s, $title, $logtype) { + protected function insertLog( &$s, $title, $logtype ) { $logname = LogPage::logName( $logtype ); $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')'; } - protected function insertDiffHist(&$s, &$rc, $unpatrolled) { + protected function insertDiffHist( &$s, &$rc, $unpatrolled ) { # Diff link if( !$this->userCan($rc,Revision::DELETED_TEXT) ) { $diffLink = $this->message['diff']; } else if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) { $diffLink = $this->message['diff']; } else { - $rcidparam = $unpatrolled - ? array( 'rcid' => $rc->mAttribs['rc_id'] ) - : array(); + $rcidparam = $unpatrolled ? + array( 'rcid' => $rc->mAttribs['rc_id'] ) : array(); $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], wfArrayToCGI( array( 'curid' => $rc->mAttribs['rc_cur_id'], @@ -188,7 +183,6 @@ class ChangesList { '', '', ' tabindex="'.$rc->counter.'"'); } $s .= '('.$diffLink.') ('; - # History link $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'], wfArrayToCGI( array( @@ -197,31 +191,32 @@ class ChangesList { $s .= ') . . '; } - protected function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) { - # Article link + protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) { + global $wgContLang; # If it's a new article, there is no diff link, but if it hasn't been # patrolled yet, we need to give users a way to do so - $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) - ? 'rcid='.$rc->mAttribs['rc_id'] - : ''; + $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) ? + 'rcid='.$rc->mAttribs['rc_id'] : ''; if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) { $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); $articlelink = ''.$articlelink.''; } else { $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); } - if( $watched ) + # Bolden pages watched by this user + if( $watched ) { $articlelink = "{$articlelink}"; - global $wgContLang; + } + # RTL/LTR marker $articlelink .= $wgContLang->getDirMark(); wfRunHooks('ChangesListInsertArticleLink', array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched)); - $s .= ' '.$articlelink; + $s .= " $articlelink"; } - protected function insertTimestamp(&$s, $rc) { + protected function insertTimestamp( &$s, $rc ) { global $wgLang; # Timestamp $s .= $this->message['semicolon-separator'] . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . '; diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 71cc67813d..bbd2234ed8 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -50,7 +50,7 @@ class SpecialRecentChanges extends SpecialPage { $opts->fetchValuesFromRequest( $wgRequest ); // Give precedence to subpage syntax - if ( $parameters !== null ) { + if( $parameters !== null ) { $this->parseParameters( $parameters, $opts ); } @@ -105,14 +105,14 @@ class SpecialRecentChanges extends SpecialPage { } foreach( $rows as $row ) { - if ( !$feedFormat ) { + if( !$feedFormat ) { // User page and talk links $batch->add( NS_USER, $row->rc_user_text ); $batch->add( NS_USER_TALK, $row->rc_user_text ); } } - if ( $feedFormat ) { + if( $feedFormat ) { list( $feed, $feedObj ) = $this->getFeedObject( $feedFormat ); $feed->execute( $feedObj, $rows, $opts['limit'], $opts['hideminor'], $lastmod ); } else { @@ -146,21 +146,21 @@ class SpecialRecentChanges extends SpecialPage { */ public function parseParameters( $par, FormOptions $opts ) { $bits = preg_split( '/\s*,\s*/', trim( $par ) ); - foreach ( $bits as $bit ) { - if ( 'hidebots' === $bit ) $opts['hidebots'] = true; - if ( 'bots' === $bit ) $opts['hidebots'] = false; - if ( 'hideminor' === $bit ) $opts['hideminor'] = true; - if ( 'minor' === $bit ) $opts['hideminor'] = false; - if ( 'hideliu' === $bit ) $opts['hideliu'] = true; - if ( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true; - if ( 'hideanons' === $bit ) $opts['hideanons'] = true; - if ( 'hidemyself' === $bit ) $opts['hidemyself'] = true; - - if ( is_numeric( $bit ) ) $opts['limit'] = $bit; + foreach( $bits as $bit ) { + if( 'hidebots' === $bit ) $opts['hidebots'] = true; + if( 'bots' === $bit ) $opts['hidebots'] = false; + if( 'hideminor' === $bit ) $opts['hideminor'] = true; + if( 'minor' === $bit ) $opts['hideminor'] = false; + if( 'hideliu' === $bit ) $opts['hideliu'] = true; + if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true; + if( 'hideanons' === $bit ) $opts['hideanons'] = true; + if( 'hidemyself' === $bit ) $opts['hidemyself'] = true; + + if( is_numeric( $bit ) ) $opts['limit'] = $bit; $m = array(); - if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1]; - if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1]; + if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1]; + if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1]; } } @@ -176,7 +176,7 @@ class SpecialRecentChanges extends SpecialPage { global $wgUseRCPatrol, $wgOut; $dbr = wfGetDB( DB_SLAVE ); $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __FUNCTION__ ); - if ( $feedFormat || !$wgUseRCPatrol ) { + if( $feedFormat || !$wgUseRCPatrol ) { if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){ # Client cache fresh and headers sent, nothing more to do. return false; @@ -229,12 +229,12 @@ class SpecialRecentChanges extends SpecialPage { $hideLoggedInUsers = $opts['hideliu'] && !$forcebot; $hideAnonymousUsers = $opts['hideanons'] && !$forcebot; - if ( $opts['hideminor'] ) $conds['rc_minor'] = 0; - if ( $opts['hidebots'] ) $conds['rc_bot'] = 0; - if ( $hidePatrol ) $conds['rc_patrolled'] = 0; - if ( $forcebot ) $conds['rc_bot'] = 1; - if ( $hideLoggedInUsers ) $conds[] = 'rc_user = 0'; - if ( $hideAnonymousUsers ) $conds[] = 'rc_user != 0'; + if( $opts['hideminor'] ) $conds['rc_minor'] = 0; + if( $opts['hidebots'] ) $conds['rc_bot'] = 0; + if( $hidePatrol ) $conds['rc_patrolled'] = 0; + if( $forcebot ) $conds['rc_bot'] = 1; + if( $hideLoggedInUsers ) $conds[] = 'rc_user = 0'; + if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0'; if( $opts['hidemyself'] ) { if( $wgUser->getId() ) { @@ -245,8 +245,8 @@ class SpecialRecentChanges extends SpecialPage { } # Namespace filtering - if ( $opts['namespace'] !== '' ) { - if ( !$opts['invert'] ) { + if( $opts['namespace'] !== '' ) { + if( !$opts['invert'] ) { $conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] ); } else { $conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] ); @@ -278,7 +278,8 @@ class SpecialRecentChanges extends SpecialPage { // JOIN on watchlist for users if( $uid ) { $tables[] = 'watchlist'; - $join_conds = array( 'watchlist' => array('LEFT JOIN',"wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") ); + $join_conds = array( 'watchlist' => array('LEFT JOIN', + "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") ); } wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) ); @@ -326,7 +327,7 @@ class SpecialRecentChanges extends SpecialPage { $limit = $opts['limit']; - if ( !$this->including() ) { + if( !$this->including() ) { // Output options box $this->doHeader( $opts ); } @@ -334,55 +335,47 @@ class SpecialRecentChanges extends SpecialPage { // And now for the content $wgOut->setSyndicated( true ); - $list = ChangesList::newFromUser( $wgUser ); - - if ( $wgAllowCategorizedRecentChanges ) { + if( $wgAllowCategorizedRecentChanges ) { $this->filterByCategories( $rows, $opts ); } - $s = $list->beginRecentChangesList(); - $counter = 1; - $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ); $watcherCache = array(); $dbr = wfGetDB( DB_SLAVE ); - foreach( $rows as $obj ){ - if( $limit == 0) { + $counter = 1; + $list = ChangesList::newFromUser( $wgUser ); + + $s = $list->beginRecentChangesList(); + foreach( $rows as $obj ) { + if( $limit == 0 ) { break; } + $rc = RecentChange::newFromRow( $obj ); + $rc->counter = $counter++; - if ( ! ( $opts['hideminor'] && $obj->rc_minor ) && - ! ( $opts['hidepatrolled'] && $obj->rc_patrolled ) ) { - $rc = RecentChange::newFromRow( $obj ); - $rc->counter = $counter++; - - if ($wgShowUpdatedMarker - && !empty( $obj->wl_notificationtimestamp ) - && ($obj->rc_timestamp >= $obj->wl_notificationtimestamp)) { - $rc->notificationtimestamp = true; - } else { - $rc->notificationtimestamp = false; - } + $rc->notificationtimestamp = false; // Default + if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) { + $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp); + } - $rc->numberofWatchingusers = 0; // Default - if ($showWatcherCount && $obj->rc_namespace >= 0) { - if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) { - $watcherCache[$obj->rc_namespace][$obj->rc_title] = - $dbr->selectField( 'watchlist', - 'COUNT(*)', - array( - 'wl_namespace' => $obj->rc_namespace, - 'wl_title' => $obj->rc_title, - ), - __METHOD__ . '-watchers' ); - } - $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title]; + $rc->numberofWatchingusers = 0; // Default + if( $showWatcherCount && $obj->rc_namespace >= 0 ) { + if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) { + $watcherCache[$obj->rc_namespace][$obj->rc_title] = + $dbr->selectField( 'watchlist', + 'COUNT(*)', + array( + 'wl_namespace' => $obj->rc_namespace, + 'wl_title' => $obj->rc_title, + ), + __METHOD__ . '-watchers' ); } - $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) ); - --$limit; + $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title]; } + $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) ); + --$limit; } $s .= $list->endRecentChangesList(); $wgOut->addHTML( $s ); @@ -413,13 +406,13 @@ class SpecialRecentChanges extends SpecialPage { $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) ); $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) ); - foreach ( $extraOpts as $optionRow ) { + foreach( $extraOpts as $optionRow ) { # Add submit button to the last row only ++$count; $addSubmit = $count === $extraOptsCount ? $submit : ''; $out .= Xml::openElement( 'tr' ); - if ( is_array( $optionRow ) ) { + if( is_array( $optionRow ) ) { $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] ); $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit ); } else { @@ -430,7 +423,7 @@ class SpecialRecentChanges extends SpecialPage { $out .= Xml::closeElement( 'table' ); $unconsumed = $opts->getUnconsumedValues(); - foreach ( $unconsumed as $key => $value ) { + foreach( $unconsumed as $key => $value ) { $out .= Xml::hidden( $key, $value ); } @@ -458,7 +451,7 @@ class SpecialRecentChanges extends SpecialPage { $extraOpts['namespace'] = $this->namespaceFilterForm( $opts ); global $wgAllowCategorizedRecentChanges; - if ( $wgAllowCategorizedRecentChanges ) { + if( $wgAllowCategorizedRecentChanges ) { $extraOpts['category'] = $this->categoryFilterForm( $opts ); } @@ -529,30 +522,30 @@ class SpecialRecentChanges extends SpecialPage { # Filter categories $cats = array(); - foreach ( $categories as $cat ) { + foreach( $categories as $cat ) { $cat = trim( $cat ); - if ( $cat == "" ) continue; + if( $cat == "" ) continue; $cats[] = $cat; } # Filter articles $articles = array(); $a2r = array(); - foreach ( $rows AS $k => $r ) { + foreach( $rows AS $k => $r ) { $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title ); $id = $nt->getArticleID(); - if ( $id == 0 ) continue; # Page might have been deleted... - if ( !in_array($id, $articles) ) { + if( $id == 0 ) continue; # Page might have been deleted... + if( !in_array($id, $articles) ) { $articles[] = $id; } - if ( !isset($a2r[$id]) ) { + if( !isset($a2r[$id]) ) { $a2r[$id] = array(); } $a2r[$id][] = $k; } # Shortcut? - if ( !count($articles) || !count($cats) ) + if( !count($articles) || !count($cats) ) return ; # Look up @@ -562,8 +555,8 @@ class SpecialRecentChanges extends SpecialPage { # Filter $newrows = array(); - foreach ( $match AS $id ) { - foreach ( $a2r[$id] AS $rev ) { + foreach( $match AS $id ) { + foreach( $a2r[$id] AS $rev ) { $k = $rev; $newrows[$k] = $rows[$k]; } -- 2.20.1