wiki.techinc.nl/includes/ChangesList.php

902 lines
28 KiB
PHP
Raw Normal View History

<?php
/**
* @todo document
*/
class RCCacheEntry extends RecentChange
{
var $secureName, $link;
var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
var $userlink, $timestamp, $watched;
static function newFromParent( $rc ) {
$rc2 = new RCCacheEntry;
$rc2->mAttribs = $rc->mAttribs;
$rc2->mExtra = $rc->mExtra;
return $rc2;
}
} ;
2005-01-27 19:51:47 +00:00
/**
* Class to show various lists of changes:
* - what links here
* - related changes
* - recent changes
2005-01-27 19:51:47 +00:00
*/
class ChangesList {
# Called by history lists and recent changes
#
2008-04-04 04:44:22 +00:00
/**
* Changeslist contructor
* @param Skin $skin
*/
2007-03-14 18:35:23 +00:00
function __construct( &$skin ) {
$this->skin =& $skin;
$this->preCacheMessages();
}
2006-01-07 13:31:29 +00:00
/**
* Fetch an appropriate changes list class for the specified user
* Some users might want to use an enhanced list format, for instance
*
* @param $user User to fetch the list class for
* @return ChangesList derivative
*/
Prevent the following strict-standards warnings - i.e. when running with error_logging(E_ALL | E_STRICT); - which seems to disable the yucky "@" operator, as well as maxing out the pedantry of warnings. Nothing major found, just nice to be as explicit and as forward-compatible as possible. * Strict Standards: Undefined index: switch in includes/Parser.php on line 3849 * Strict Standards: Undefined index: ref in includes/Parser.php on line 3818 * Strict Standards: Non-static method OutputPage::setEncodings() should not be called statically in index.php on line 11 * Strict Standards: Only variables should be assigned by reference in includes/Skin.php on line 888 * Strict Standards: Non-static method Title::newFromURL() should not be called statically in includes/SpecialContributions.php on line 178 * Strict Standards: Only variables should be assigned by reference in includes/GlobalFunctions.php on line 2054 * Strict Standards: Undefined index: contributions-summary in languages/Language.php on line 764 * Strict Standards: Undefined index: trackbackhtml in skins/MonoBook.php on line 86 * Strict Standards: Undefined index: blockip in skins/MonoBook.php on line 204 * Strict Standards: Undefined index: tagline in skins/MonoBook.php on line 261 * Strict Standards: Undefined index: uselang in includes/SkinTemplate.php on line 1159 * Strict Standards: Non-static method CoreParserFunctions::plural() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Undefined offset: 0 in includes/SkinTemplate.php on line 196 * Strict Standards: Undefined index: USE INDEX in includes/Database.php on line 1015 * Strict Standards: Undefined index: image_tests in includes/Parser.php on line 3488 * Strict Standards: Undefined offset: 0 in includes/Parser.php on line 3507 * Strict Standards: Non-static method ChangesList::newFromUser() should not be called statically in includes/SpecialWatchlist.php on line 361 * Strict Standards: Non-static method RecentChange::newFromCurRow() should not be called statically in includes/SpecialWatchlist.php on line 367 * Strict Standards: is_a(): Deprecated. Please use the instanceof operator in includes/Exception.php on line 168 * Strict Standards: Non-static method LogPage::logName() should not be called statically in includes/SpecialContributions.php on line 325 * Strict Standards: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in maintenance/commandLine.inc on line 191 * Strict Standards: Undefined index: meatball in languages/Language.php on line 234 * Strict Standards: rmdir(/tmp/mwParser-2108164586-images/thumb): Directory not empty in maintenance/parserTests.inc on line 605 * Cleaning out some new temp files left over by parserTests (there were one or two straggler dirs/files that would persist after the test run ended, due to new tests being added over time) * Strict Standards: Non-static method CoreParserFunctions::special() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Declaration of ListUsersPage::preprocessResults() should be compatible with that of QueryPage::preprocessResults() in includes/SpecialListusers.php on line 38 * Strict Standards: Only variables should be passed by reference in includes/SpecialBlockip.php on line 175 * Strict Standards: Skin::include_once(skins/Standard.deps.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in includes/Skin.php on line 121 * Strict Standards: Declaration of ApiMain::getResult() should be compatible with that of ApiBase::getResult() in includes/api/ApiMain.php on line 35 * Strict Standards: is_a(): Deprecated. Please use the instanceof operator in includes/WikiError.php on line 63 * Strict Standards: Non-static method WikiError::isError() should not be called statically in includes/SpecialImport.php on line 64 * Strict Standards: Non-static method ImportStreamSource::newFromInterwiki() should not be called statically in includes/SpecialImport.php on line 58<b * Strict Standards: Only variables should be assigned by reference in includes/SpecialUndelete.php on line 501 * Strict Standards: Non-static method Image::newFromName() should not be called statically in thumb.php on line 56 * Strict Standards: Non-static method CoreParserFunctions::numberoffiles() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Non-static method CoreParserFunctions::statisticsFunction() should not be called statically in includes/CoreParserFunctions.php on line 139 * Strict Standards: Non-static method CoreParserFunctions::isRaw() should not be called statically in includes/CoreParserFunctions.php on line 128 * Strict Standards: Non-static method CoreParserFunctions::grammar() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Undefined offset: 1 in includes/SpecialMIMEsearch.php on line 130 * Strict Standards: Undefined index: recentchangeslinked in skins/MonoBook.php on line 184 * Strict Standards: Declaration of DumpNotalkFilter::pass() should be compatible with that of DumpFilter::pass() in includes/Export.php on line 612 * Strict Standards: Declaration of DumpNamespaceFilter::pass() should be compatible with that of DumpFilter::pass() in includes/Export.php on line 665 * Strict Standards: Non-static method ImportStreamSource::newFromUpload() should not be called statically in includes/SpecialImport.php on line 46 * Strict Standards: Undefined offset: 5 in includes/Sanitizer.php on line 396 * Strict Standards: Undefined index: wikidbUserName in includes/SpecialUserlogin.php on line 562 * Strict Standards: Only variables should be assigned by reference in includes/api/ApiQueryBase.php on line 95 * Strict Standards: Only variables should be assigned by reference in includes/api/ApiQueryBase.php on line 116 * Strict Standards: Only variables should be assigned by reference in includes/api/ApiQueryWatchlist.php on line 128 * Strict Standards: Undefined property: stdClass::$rc_id in includes/api/ApiQueryBase.php on line 131 * Strict Standards: Undefined property: stdClass::$rc_last_oldid in includes/api/ApiQueryBase.php on line 164 * Strict Standards: Undefined property: stdClass::$rc_moved_to_ns in includes/api/ApiQueryBase.php on line 285 * Strict Standards: Undefined property: stdClass::$rc_patrolled in includes/api/ApiQueryBase.php on line 176 * Strict Standards: Undefined index: comment in includes/api/ApiFeedWatchlist.php on line 85 * Strict Standards: Undefined offset: 0 in includes/Skin.php on line 302 * Strict Standards: Non-static method User::SetupSession() should not be called statically in includes/SpecialUserlogin.php on line 15 ... There are certain to be other things too, so this is not intended to be comprehensive, rather the above just stops most of the notifications I observed.
2006-11-29 05:45:03 +00:00
public static function newFromUser( &$user ) {
2007-03-14 18:35:23 +00:00
$sk = $user->getSkin();
$list = NULL;
if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
} else {
return $list;
}
}
2005-07-01 20:36:04 +00:00
/**
* As we use the same small set of messages in various methods and that
* they are called often, we call them once and save them in $this->message
*/
2008-04-04 04:44:22 +00:00
private function preCacheMessages() {
// Precache various messages
if( !isset( $this->message ) ) {
2006-04-27 17:36:51 +00:00
foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
'blocklink history boteditletter semicolon-separator' ) as $msg ) {
2006-04-27 17:36:51 +00:00
$this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
}
}
}
/**
* Returns the appropriate flags for new page, minor change and patrolling
2008-04-04 04:44:22 +00:00
* @param bool $new
* @param bool $minor
* @param bool $patrolled
* @param string $nothing, string to use for empty space
* @param bool $bot
* @return string
*/
2008-04-04 04:44:22 +00:00
protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;', $bot = false ) {
2006-04-27 17:36:51 +00:00
$f = $new ? '<span class="newpage">' . $this->message['newpageletter'] . '</span>'
: $nothing;
2006-04-27 17:36:51 +00:00
$f .= $minor ? '<span class="minor">' . $this->message['minoreditletter'] . '</span>'
: $nothing;
$f .= $bot ? '<span class="bot">' . $this->message['boteditletter'] . '</span>' : $nothing;
$f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
2008-03-20 02:08:35 +00:00
return $f;
}
2005-07-01 20:36:04 +00:00
/**
2005-01-27 19:51:47 +00:00
* Returns text for the start of the tabular part of RC
2008-04-04 04:44:22 +00:00
* @return string
2005-01-27 19:51:47 +00:00
*/
2008-04-04 04:44:22 +00:00
public function beginRecentChangesList() {
$this->rc_cache = array();
$this->rcMoveIndex = 0;
$this->rcCacheIndex = 0;
$this->lastdate = '';
$this->rclistOpen = false;
return '';
}
/**
* Returns text for the end of RC
2008-04-04 04:44:22 +00:00
* @return string
*/
2008-04-04 04:44:22 +00:00
public function endRecentChangesList() {
if( $this->rclistOpen ) {
return "</ul>\n";
} else {
return '';
}
}
2005-09-06 20:04:38 +00:00
2008-04-04 04:44:22 +00:00
protected function insertMove( &$s, $rc ) {
# Diff
$s .= '(' . $this->message['diff'] . ') (';
# 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(), '' ) );
}
2008-04-04 04:44:22 +00:00
protected function insertDateHeader(&$s, $rc_timestamp) {
global $wgLang;
# Make date header if necessary
$date = $wgLang->date( $rc_timestamp, true, true );
$s = '';
if( $date != $this->lastdate ) {
if( '' != $this->lastdate ) {
$s .= "</ul>\n";
}
$s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
$this->lastdate = $date;
$this->rclistOpen = true;
}
}
2008-04-04 04:44:22 +00:00
protected function insertLog(&$s, $title, $logtype) {
$logname = LogPage::logName( $logtype );
$s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')';
}
2008-04-04 04:44:22 +00:00
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();
$diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
wfArrayToCGI( array(
'curid' => $rc->mAttribs['rc_cur_id'],
'diff' => $rc->mAttribs['rc_this_oldid'],
'oldid' => $rc->mAttribs['rc_last_oldid'] ),
$rcidparam ),
'', '', ' tabindex="'.$rc->counter.'"');
}
$s .= '('.$diffLink.') (';
# History link
$s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'],
wfArrayToCGI( array(
'curid' => $rc->mAttribs['rc_cur_id'],
'action' => 'history' ) ) );
$s .= ') . . ';
}
2008-04-04 04:44:22 +00:00
protected function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
# Article link
# 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']
: '';
if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
$articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
$articlelink = '<span class="history-deleted">'.$articlelink.'</span>';
} else {
$articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
}
if( $watched )
$articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
global $wgContLang;
$articlelink .= $wgContLang->getDirMark();
wfRunHooks('ChangesListInsertArticleLink',
array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched));
$s .= ' '.$articlelink;
}
2008-04-04 04:44:22 +00:00
protected function insertTimestamp(&$s, $rc) {
global $wgLang;
# Timestamp
$s .= $this->message['semicolon-separator'] . ' ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
}
/** Insert links to user page, user talk page and eventually a blocking link */
2008-04-04 04:44:22 +00:00
protected function insertUserRelatedLinks(&$s, &$rc) {
if ( $this->isDeleted($rc,Revision::DELETED_USER) ) {
$s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
} else {
$s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
$s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
}
}
/** insert a formatted action */
2008-04-04 04:44:22 +00:00
protected function insertAction(&$s, &$rc) {
# Add action
if( $rc->mAttribs['rc_type'] == RC_LOG ) {
// log action
if ( $this->isDeleted($rc,LogPage::DELETED_ACTION) ) {
$s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
} else {
$s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
$rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true );
}
}
}
/** insert a formatted comment */
2008-04-04 04:44:22 +00:00
protected function insertComment(&$s, &$rc) {
# Add comment
if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
// log comment
if ( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) {
$s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
} else {
$s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
}
}
}
2006-01-07 13:31:29 +00:00
/**
* Check whether to enable recent changes patrol features
* @return bool
*/
public static function usePatrol() {
global $wgUseRCPatrol, $wgUser;
return( $wgUseRCPatrol && ($wgUser->isAllowed('patrol') || $wgUser->isAllowed('patrolmarks')) );
}
2007-01-17 18:13:56 +00:00
/**
* Returns the string which indicates the number of watching users
*/
2008-04-04 04:44:22 +00:00
protected function numberofWatchingusers( $count ) {
2007-01-17 18:13:56 +00:00
global $wgLang;
static $cache = array();
if ( $count > 0 ) {
if ( !isset( $cache[$count] ) ) {
$cache[$count] = wfMsgExt('number_of_watching_users_RCview',
array('parsemag', 'escape'), $wgLang->formatNum($count));
}
return $cache[$count];
} else {
return '';
}
}
2008-04-04 04:44:22 +00:00
/**
* Determine if said field of a revision is hidden
* @param RCCacheEntry $rc
* @param int $field one of DELETED_* bitfield constants
* @return bool
*/
public static function isDeleted( $rc, $field ) {
return ($rc->mAttribs['rc_deleted'] & $field) == $field;
}
/**
* Determine if the current user is allowed to view a particular
* field of this revision, if it's marked as deleted.
* @param RCCacheEntry $rc
* @param int $field
* @return bool
*/
public static function userCan( $rc, $field ) {
if( ( $rc->mAttribs['rc_deleted'] & $field ) == $field ) {
global $wgUser;
$permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED
? 'hiderevision'
: 'deleterevision';
wfDebug( "Checking for $permission due to $field match on $rc->mAttribs['rc_deleted']\n" );
return $wgUser->isAllowed( $permission );
} else {
return true;
}
}
}
/**
* Generate a list of changes using the good old system (no javascript)
*/
class OldChangesList extends ChangesList {
2005-09-06 18:14:24 +00:00
/**
* Format a line using the old system (aka without any javascript).
*/
public function recentChangesLine( &$rc, $watched = false ) {
global $wgContLang, $wgRCShowChangedSize;
2005-09-06 17:08:32 +00:00
$fname = 'ChangesList::recentChangesLineOld';
wfProfileIn( $fname );
# Extract DB fields into local scope
2007-03-14 18:35:23 +00:00
// FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
extract( $rc->mAttribs );
# Should patrol-related stuff be shown?
$unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
2005-07-01 20:36:04 +00:00
$this->insertDateHeader($s,$rc_timestamp);
$s .= '<li>';
// Moved pages
if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
$this->insertMove( $s, $rc );
// Log entries
} elseif( $rc_log_type ) {
$logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
$this->insertLog( $s, $logtitle, $rc_log_type );
// Log entries (old format) or log targets, and special pages
} elseif( $rc_namespace == NS_SPECIAL ) {
list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
if ( $specialName == 'Log' ) {
$this->insertLog( $s, $rc->getTitle(), $specialSubpage );
} else {
wfDebug( "Unexpected special page in recentchanges\n" );
}
// Regular entries
} else {
wfProfileIn($fname.'-page');
$this->insertDiffHist($s, $rc, $unpatrolled);
# M, N, b and ! (minor, new, bot and unpatrolled)
2008-03-20 02:21:20 +00:00
$s .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot );
$this->insertArticleLink($s, $rc, $unpatrolled, $watched);
wfProfileOut($fname.'-page');
}
wfProfileIn( $fname.'-rest' );
$this->insertTimestamp($s,$rc);
if( $wgRCShowChangedSize ) {
$s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' );
}
# User tool links
$this->insertUserRelatedLinks($s,$rc);
# Log action text (if any)
$this->insertAction($s, $rc);
# Edit or log comment
$this->insertComment($s, $rc);
# Mark revision as deleted if so
if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) )
$s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
if($rc->numberofWatchingusers > 0) {
$s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers));
}
$s .= "</li>\n";
wfProfileOut( $fname.'-rest' );
wfProfileOut( $fname );
return $s;
}
}
/**
* Generate a list of changes using an Enhanced system (use javascript).
*/
class EnhancedChangesList extends ChangesList {
2005-09-06 18:14:24 +00:00
/**
* Format a line for enhanced recentchange (aka with javascript and block of lines).
*/
public function recentChangesLine( &$baseRC, $watched = false ) {
global $wgLang, $wgContLang;
2005-07-01 20:36:04 +00:00
# Create a specialised object
$rc = RCCacheEntry::newFromParent( $baseRC );
# Extract fields from DB into the function scope (rc_xxxx variables)
2007-03-14 18:35:23 +00:00
// FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
extract( $rc->mAttribs );
$curIdEq = 'curid=' . $rc_cur_id;
# If it's a new day, add the headline and flush the cache
$date = $wgLang->date( $rc_timestamp, true);
$ret = '';
if( $date != $this->lastdate ) {
# Process current cache
$ret = $this->recentChangesBlock();
$this->rc_cache = array();
$ret .= "<h4>{$date}</h4>\n";
$this->lastdate = $date;
}
2005-07-01 20:36:04 +00:00
# Should patrol-related stuff be shown?
if( $this->usePatrol() ) {
$rc->unpatrolled = !$rc_patrolled;
} else {
$rc->unpatrolled = false;
}
2005-07-01 20:36:04 +00:00
$showdifflinks = true;
# Make article link
// Page moves
if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
$msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
$clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
$this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
// Log entries (old format) and special pages
} elseif( $rc_namespace == NS_SPECIAL ) {
list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
if ( $specialName == 'Log' ) {
# Log updates, etc
$logname = LogPage::logName( $logtype );
$clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
} else {
wfDebug( "Unexpected special page in recentchanges\n" );
$clink = '';
}
// New unpatrolled pages
} else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
$clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
// Other edits or log entries
} else {
$clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
}
# Don't show unusable diff links
if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
$showdifflinks = false;
}
2006-12-14 22:30:42 +00:00
$time = $wgContLang->time( $rc_timestamp, true, true );
$rc->watched = $watched;
$rc->link = $clink;
$rc->timestamp = $time;
$rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
# Make "cur" and "diff" links
if( $rc->unpatrolled ) {
$rcIdQuery = "&rcid={$rc_id}";
} else {
$rcIdQuery = '';
}
$querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
$querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
$aprops = ' tabindex="'.$baseRC->counter.'"';
$curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops );
# Make "diff" an "cur" links
if( !$showdifflinks ) {
$curLink = $this->message['cur'];
$diffLink = $this->message['diff'];
} else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
if( $rc_type != RC_NEW ) {
$curLink = $this->message['cur'];
}
$diffLink = $this->message['diff'];
} else {
$diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops );
}
# Make "last" link
if( !$showdifflinks ) {
$lastLink = $this->message['last'];
} else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
$lastLink = $this->message['last'];
} else {
$lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
$curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
}
# Make user links
if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
$rc->userlink = ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
} else {
$rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
$rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
}
$rc->lastlink = $lastLink;
$rc->curlink = $curLink;
$rc->difflink = $diffLink;
# Put accumulated information into the cache, for later display
# Page moves go on their own line
$title = $rc->getTitle();
$secureName = $title->getPrefixedDBkey();
if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
# Use an @ character to prevent collision with page names
$this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
} else {
if( $rc_type == RC_LOG ){
$secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
}
if( !isset( $this->rc_cache[$secureName] ) ) {
$this->rc_cache[$secureName] = array();
}
array_push( $this->rc_cache[$secureName], $rc );
}
return $ret;
}
2006-01-07 13:31:29 +00:00
/**
* Enhanced RC group
*/
protected function recentChangesBlockGroup( $block ) {
global $wgLang, $wgContLang, $wgRCShowChangedSize;
$r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
# Collate list of users
2008-04-01 22:41:19 +00:00
$userlinks = array();
# Other properties
$unpatrolled = false;
$isnew = false;
2008-04-01 22:41:19 +00:00
$curId = $currentRevision = 0;
# Some catalyst variables...
$namehidden = true;
2008-04-01 22:41:19 +00:00
$alllogs = true;
foreach( $block as $rcObj ) {
$oldid = $rcObj->mAttribs['rc_last_oldid'];
if( $rcObj->mAttribs['rc_new'] ) {
$isnew = true;
}
// If all log actions to this page were hidden, then don't
// give the name of the affected page for this block!
if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
$namehidden = false;
}
$u = $rcObj->userlink;
if( !isset( $userlinks[$u] ) ) {
$userlinks[$u] = 0;
}
if( $rcObj->unpatrolled ) {
$unpatrolled = true;
}
2008-04-01 22:41:19 +00:00
if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
$alllogs = false;
}
# Get the latest entry with a page_id and oldid
# since logs may not have these.
if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
$curId = $rcObj->mAttribs['rc_cur_id'];
}
if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
$currentRevision = $rcObj->mAttribs['rc_this_oldid'];
}
$bot = $rcObj->mAttribs['rc_bot'];
$userlinks[$u]++;
}
# Sort the list and convert to text
krsort( $userlinks );
asort( $userlinks );
$users = array();
foreach( $userlinks as $userlink => $count) {
$text = $userlink;
$text .= $wgContLang->getDirMark();
if( $count > 1 ) {
$text .= ' ('.$count.'&times;)';
}
array_push( $users, $text );
}
$users = ' <span class="changedby">[' . implode( $this->message['semicolon-separator'] . ' ', $users ) . ']</span>';
# Arrow
$rci = 'RCI'.$this->rcCacheIndex;
$rcl = 'RCL'.$this->rcCacheIndex;
$rcm = 'RCM'.$this->rcCacheIndex;
$toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
$tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
$tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
$r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.'&nbsp;';
# Main line
$r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
# Timestamp
2008-03-20 02:08:35 +00:00
$r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</tt></td><td>';
# Article link
if( $alllogs ){
$logtype = $block[0]->mAttribs['rc_log_type'];
if( is_null( $logtype ) ){
//Old format
$r .= $block[0]->link;
} else {
$logname = LogPage::logName( $logtype );
$r .= ' (' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log', $logtype ), $logname ) . ')';
}
} else if( $namehidden ) {
$r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
2008-04-01 22:41:19 +00:00
} else {
$r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
2008-04-01 22:41:19 +00:00
}
2008-04-01 22:41:19 +00:00
$r .= $wgContLang->getDirMark();
2008-04-01 22:41:19 +00:00
$curIdEq = 'curid=' . $curId;
# Changes message
$n = count($block);
static $nchanges = array();
if ( !isset( $nchanges[$n] ) ) {
$nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
2008-04-01 22:41:19 +00:00
}
# Total change link
$r .= ' ';
if( !$alllogs ) {
$r .= '(';
if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
2008-04-01 22:41:19 +00:00
$r .= $nchanges[$n];
} else if( $isnew ) {
$r .= $nchanges[$n];
} else {
$r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
$nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
}
2008-04-01 22:41:19 +00:00
$r .= ') . . ';
}
# Character difference (does not apply if only log items)
if( $wgRCShowChangedSize && !$alllogs ) {
$last = 0;
$first = count($block) - 1;
# Some events (like logs) have an "empty" size, so we need to skip those...
while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) {
$last++;
}
while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) {
$first--;
}
# Get net change
$chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
$block[$last]->mAttribs['rc_new_len'] );
2008-04-01 22:41:19 +00:00
if( $chardiff == '' ) {
$r .= ' ';
} else {
$r .= ' ' . $chardiff. ' . . ';
}
}
2008-04-01 22:41:19 +00:00
# History
if( $namehidden || $alllogs ) {
$r .= '(' . $this->message['history'] . ')';
} else {
$r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
$this->message['history'], $curIdEq.'&action=history' ) . ')';
}
$r .= $users;
$r .=$this->numberofWatchingusers($block[0]->numberofWatchingusers);
$r .= "</td></tr></table>\n";
# Sub-entries
$r .= '<div id="'.$rci.'" style="display:none;"><table cellpadding="0" cellspacing="0" border="0" style="background: none">';
foreach( $block as $rcObj ) {
# Get rc_xxxx variables
2007-03-14 18:35:23 +00:00
// FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
extract( $rcObj->mAttribs );
#$r .= '<tr><td valign="top">'.$this->spacerArrow();
2008-03-20 02:08:35 +00:00
$r .= '<tr><td valign="top">';
$r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
$r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
2008-03-20 02:08:35 +00:00
$r .= '&nbsp;</tt></td><td valign="top">';
$o = '';
if( $rc_this_oldid != 0 ) {
$o = 'oldid='.$rc_this_oldid;
}
# Revision link
if( $rc_type == RC_LOG ) {
$link = '<tt>'.$rcObj->timestamp.'</tt> ';
} else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
$link = '<span class="history-deleted"><tt>'.$rcObj->timestamp.'</tt></span> ';
} else {
$link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp, $curIdEq.'&'.$o ).'</tt>';
if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
$link = '<span class="history-deleted">'.$link.'</span> ';
}
$r .= $link;
if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
$r .= ' (';
$r .= $rcObj->curlink;
$r .= $this->message['semicolon-separator'] . ' ';
$r .= $rcObj->lastlink;
$r .= ')';
}
$r .= ' . . ';
# Character diff
if( $wgRCShowChangedSize ) {
$r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
}
# User links
$r .= $rcObj->userlink;
$r .= $rcObj->usertalklink;
// log action
parent::insertAction( $r, $rcObj );
// log comment
parent::insertComment( $r, $rcObj );
# Mark revision as deleted
2008-04-04 04:44:22 +00:00
if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) {
$r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
2008-04-04 04:44:22 +00:00
}
$r .= "</td></tr>\n";
}
$r .= "</table></div>\n";
$this->rcCacheIndex++;
return $r;
}
2006-01-07 13:31:29 +00:00
protected function maybeWatchedLink( $link, $watched=false ) {
if( $watched ) {
// FIXME: css style might be more appropriate
return '<strong class="mw-watched">' . $link . '</strong>';
} else {
return $link;
}
}
2006-01-07 13:31:29 +00:00
/**
* Generate HTML for an arrow or placeholder graphic
* @param string $dir one of '', 'd', 'l', 'r'
* @param string $alt text
* @return string HTML <img> tag
*/
2008-04-04 16:02:10 +00:00
protected function arrow( $dir, $alt='' ) {
global $wgStylePath;
$encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
$encAlt = htmlspecialchars( $alt );
return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
}
2006-01-07 13:31:29 +00:00
/**
* Generate HTML for a right- or left-facing arrow,
* depending on language direction.
* @return string HTML <img> tag
*/
protected function sideArrow() {
global $wgContLang;
$dir = $wgContLang->isRTL() ? 'l' : 'r';
return $this->arrow( $dir, '+' );
}
2006-01-07 13:31:29 +00:00
/**
* Generate HTML for a down-facing arrow
* depending on language direction.
* @return string HTML <img> tag
*/
protected function downArrow() {
return $this->arrow( 'd', '-' );
}
2006-01-07 13:31:29 +00:00
/**
* Generate HTML for a spacer image
* @return string HTML <img> tag
*/
protected function spacerArrow() {
return $this->arrow( '', ' ' );
}
2008-03-20 02:08:35 +00:00
/**
* Add a set of spaces
* @return string HTML <td> tag
*/
protected function spacerIndent() {
return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
}
/**
* Enhanced RC ungrouped line.
* @return string a HTML formated line (generated using $r)
*/
protected function recentChangesBlockLine( $rcObj ) {
global $wgContLang, $wgRCShowChangedSize;
# Get rc_xxxx variables
2007-03-14 18:35:23 +00:00
// FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
extract( $rcObj->mAttribs );
$curIdEq = 'curid='.$rc_cur_id;
$r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
$r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . '&nbsp;';
# Flag and Timestamp
if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2008-03-20 02:08:35 +00:00
$r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
} else {
2008-03-20 02:08:35 +00:00
$r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
}
2008-03-20 02:08:35 +00:00
$r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</tt></td><td>';
# Article or log link
if( $rc_log_type ) {
$logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
$logname = LogPage::logName( $rc_log_type );
$r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
} else if( !$this->userCan($rcObj,Revision::DELETED_TEXT) ) {
$r .= '<span class="history-deleted">' . $rcObj->link . '</span>';
} else {
$r .= $this->maybeWatchedLink( $rcObj->link, $rcObj->watched );
}
# Diff and hist links
if ( $rc_type != RC_LOG ) {
$r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'] . ' ';
$r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')';
}
$r .= ' . . ';
# Character diff
if( $wgRCShowChangedSize ) {
$r .= ( $rcObj->getCharacterDifference() == '' ? '' : '&nbsp;' . $rcObj->getCharacterDifference() . ' . . ' ) ;
}
# User/talk
$r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
# Log action (if any)
if( $rc_log_type ) {
if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
$r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
} else {
$r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(), $this->skin, LogPage::extractParams($rc_params), true, true );
}
}
# Edit or log comment
if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
// log comment
if ( $this->isDeleted($rcObj,LogPage::DELETED_COMMENT) ) {
$r .= ' <span class="history-deleted">' . wfMsg('rev-deleted-comment') . '</span>';
} else {
$r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
}
}
# Show how many people are watching this if enabled
2007-03-14 18:35:23 +00:00
$r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
$r .= "</td></tr></table>\n";
return $r;
}
/**
* If enhanced RC is in use, this function takes the previously cached
* RC lines, arranges them, and outputs the HTML
*/
protected function recentChangesBlock() {
if( count ( $this->rc_cache ) == 0 ) {
return '';
}
$blockOut = '';
foreach( $this->rc_cache as $block ) {
if( count( $block ) < 2 ) {
$blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
} else {
$blockOut .= $this->recentChangesBlockGroup( $block );
}
}
return '<div>'.$blockOut.'</div>';
}
/**
* Returns text for the end of RC
* If enhanced RC is in use, returns pretty much all the text
*/
public function endRecentChangesList() {
return $this->recentChangesBlock() . parent::endRecentChangesList();
}
}