<?php
/**
- * Classes to show various lists of changes:
+ * Classes to show lists of changes.
+ *
+ * These can be:
* - watchlist
* - related changes
* - recent changes
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
*/
if( !isset( $this->message ) ) {
foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
'semicolon-separator pipe-separator' ) as $msg ) {
- $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
+ $this->message[$msg] = $this->msg( $msg )->escaped();
}
}
}
* Show formatted char difference
* @param $old Integer: bytes
* @param $new Integer: bytes
+ * @param $context IContextSource context to use
* @return String
*/
- public static function showCharacterDifference( $old, $new ) {
- global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
+ public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
+ global $wgRCChangedSizeThreshold, $wgMiserMode;
+
+ if ( !$context ) {
+ $context = RequestContext::getMain();
+ }
+
$szdiff = $new - $old;
- $code = $wgLang->getCode();
+ $lang = $context->getLanguage();
+ $code = $lang->getCode();
static $fastCharDiff = array();
if ( !isset($fastCharDiff[$code]) ) {
- $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1';
+ $fastCharDiff[$code] = $wgMiserMode || $context->msg( 'rc-change-size' )->plain() === '$1';
}
- $formattedSize = $wgLang->formatNum($szdiff);
+ $formattedSize = $lang->formatNum( $szdiff );
if ( !$fastCharDiff[$code] ) {
- $formattedSize = wfMsgExt( 'rc-change-size', array( 'parsemag' ), $formattedSize );
+ $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
}
if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
$formattedSizeClass = 'mw-plusminus-neg';
}
- $formattedTotalSize = wfMsgExt( 'rc-change-size-new', 'parsemag', $wgLang->formatNum( $new ) );
+ $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
return Html::element( $tag,
array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
- wfMessage( 'parentheses', $formattedSize )->plain() ) . $wgLang->getDirMark();
+ $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
+ }
+
+ /**
+ * Format the character difference of one or several changes.
+ *
+ * @param $old RecentChange
+ * @param $new RecentChange last change to use, if not provided, $old will be used
+ * @return string HTML fragment
+ */
+ public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
+ $oldlen = $old->mAttribs['rc_old_len'];
+
+ if ( $new ) {
+ $newlen = $new->mAttribs['rc_new_len'];
+ } else {
+ $newlen = $old->mAttribs['rc_new_len'];
+ }
+
+ if( $oldlen === null || $newlen === null ) {
+ return '';
+ }
+
+ return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
}
/**
public function insertDateHeader( &$s, $rc_timestamp ) {
# Make date header if necessary
- $date = $this->getLanguage()->date( $rc_timestamp, true, true );
+ $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
if( $date != $this->lastdate ) {
if( $this->lastdate != '' ) {
$s .= "</ul>\n";
public function insertLog( &$s, $title, $logtype ) {
$page = new LogPage( $logtype );
$logname = $page->getName()->escaped();
- $s .= '(' . Linker::linkKnown( $title, $logname ) . ')';
+ $s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped();
}
/**
$query
);
}
- $s .= '(' . $diffLink . $this->message['pipe-separator'];
+ $diffhist = $diffLink . $this->message['pipe-separator'];
# History link
- $s .= Linker::linkKnown(
+ $diffhist .= Linker::linkKnown(
$rc->getTitle(),
$this->message['hist'],
array(),
'action' => 'history'
)
);
- $s .= ') . . ';
+ $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' . . ';
}
/**
*/
public function insertTimestamp( &$s, $rc ) {
$s .= $this->message['semicolon-separator'] .
- $this->getLanguage()->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
+ $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() ) . ' . . ';
}
/**
*/
public function insertUserRelatedLinks( &$s, &$rc ) {
if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
- $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
+ $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
} else {
$s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
$rc->mAttribs['rc_user_text'] );
*/
public function insertLogEntry( $rc ) {
$formatter = LogFormatter::newFromRow( $rc->mAttribs );
+ $formatter->setContext( $this->getContext() );
$formatter->setShowUserToolLinks( true );
$mark = $this->getLanguage()->getDirMark();
return $formatter->getActionText() . " $mark" . $formatter->getComment();
}
- /**
+ /**
* Insert a formatted comment
* @param $rc RecentChange
* @return string
public function insertComment( $rc ) {
if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
- return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
+ return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
} else {
return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
}
static $cache = array();
if( $count > 0 ) {
if( !isset( $cache[$count] ) ) {
- $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
- array('parsemag', 'escape' ), $this->getLanguage()->formatNum( $count ) );
+ $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
}
return $cache[$count];
} else {
# Edit/log timestamp
$this->insertTimestamp( $s, $rc );
# Bytes added or removed
- if( $wgRCShowChangedSize ) {
- $cd = $rc->getCharacterDifference();
- if( $cd != '' ) {
+ if ( $wgRCShowChangedSize ) {
+ $cd = $this->formatCharacterDifference( $rc );
+ if ( $cd !== '' ) {
$s .= "$cd . . ";
}
}
# How many users watch this page
if( $rc->numberofWatchingusers > 0 ) {
- $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
- array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $rc->numberofWatchingusers ) );
+ $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
}
if( $this->watchlist ) {
$curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
# If it's a new day, add the headline and flush the cache
- $date = $this->getLanguage()->date( $rc->mAttribs['rc_timestamp'], true );
+ $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() );
$ret = '';
if( $date != $this->lastdate ) {
# Process current cache
$logtitle = SpecialPage::getTitleFor( 'Log', $logType );
$logpage = new LogPage( $logType );
$logname = $logpage->getName()->escaped();
- $clink = '(' . Linker::linkKnown( $logtitle, $logname ) . ')';
+ $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
} else {
$clink = Linker::link( $rc->getTitle() );
}
$showdifflinks = false;
}
- $time = $this->getLanguage()->time( $rc->mAttribs['rc_timestamp'], true, true );
+ $time = $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() );
$rc->watched = $watched;
$rc->link = $clink;
$rc->timestamp = $time;
# Make user links
if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
- $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
+ $rc->userlink = ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
} else {
$rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
$rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
$text = $userlink;
$text .= $this->getLanguage()->getDirMark();
if( $count > 1 ) {
- $text .= ' (' . $this->getLanguage()->formatNum( $count ) . '×)';
+ $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
}
array_push( $users, $text );
}
- $users = ' <span class="changedby">[' .
- implode( $this->message['semicolon-separator'], $users ) . ']</span>';
+ $users = ' <span class="changedby">'
+ . $this->msg( 'brackets' )->rawParams(
+ implode( $this->message['semicolon-separator'], $users )
+ )->escaped() . '</span>';
$tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow"></span>';
$r .= "<td>$tl</td>";
# Article link
if( $namehidden ) {
- $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
+ $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
} elseif( $allLogs ) {
$r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
} else {
$n = count($block);
static $nchanges = array();
if ( !isset( $nchanges[$n] ) ) {
- $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) );
+ $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
}
# Total change link
$r .= ' ';
+ $logtext = '';
if( !$allLogs ) {
- $r .= '(';
if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
- $r .= $nchanges[$n];
+ $logtext .= $nchanges[$n];
} elseif( $isnew ) {
- $r .= $nchanges[$n];
+ $logtext .= $nchanges[$n];
} else {
$params = $queryParams;
$params['diff'] = $currentRevision;
$params['oldid'] = $oldid;
- $r .= Linker::link(
+ $logtext .= Linker::link(
$block[0]->getTitle(),
$nchanges[$n],
array(),
if( $allLogs ) {
// don't show history link for logs
} elseif( $namehidden || !$block[0]->getTitle()->exists() ) {
- $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')';
+ $logtext .= $this->message['pipe-separator'] . $this->message['hist'];
} else {
$params = $queryParams;
$params['action'] = 'history';
- $r .= $this->message['pipe-separator'] .
+ $logtext .= $this->message['pipe-separator'] .
Linker::linkKnown(
$block[0]->getTitle(),
$this->message['hist'],
array(),
$params
- ) . ')';
+ );
}
+
+ if( $logtext !== '' ) {
+ $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
+ }
+
$r .= ' . . ';
# Character difference (does not apply if only log items)
$first--;
}
# Get net change
- $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
- $block[$last]->mAttribs['rc_new_len'] );
+ $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
if( $chardiff == '' ) {
$r .= ' ';
$r .= $link . '</span>';
if ( !$type == RC_LOG || $type == RC_NEW ) {
- $r .= ' (';
- $r .= $rcObj->curlink;
- $r .= $this->message['pipe-separator'];
- $r .= $rcObj->lastlink;
- $r .= ')';
+ $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
}
$r .= ' . . ';
# Character diff
- if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
- $r .= $rcObj->getCharacterDifference() . ' . . ' ;
+ if ( $wgRCShowChangedSize ) {
+ $cd = $this->formatCharacterDifference( $rcObj );
+ if ( $cd !== '' ) {
+ $r .= "$cd . . ";
+ }
}
if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
* @return String: HTML <img> tag
*/
protected function sideArrow() {
- global $wgLang;
- $dir = $wgLang->isRTL() ? 'l' : 'r';
- return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
+ $dir = $this->getLanguage()->isRTL() ? 'l' : 'r';
+ return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
}
/**
* @return String: HTML <img> tag
*/
protected function downArrow() {
- return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
+ return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
}
/**
if( $logType ) {
$logtitle = SpecialPage::getTitleFor( 'Log', $logType );
$logname = LogPage::logName( $logType );
- $r .= '(' . Linker::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
+ $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, htmlspecialchars( $logname ) ) )->escaped();
} else {
$this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
}
# Diff and hist links
if ( $type != RC_LOG ) {
- $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator'];
$query['action'] = 'history';
- $r .= Linker::linkKnown(
+ $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
$rcObj->getTitle(),
$this->message['hist'],
array(),
$query
- ) . ')';
+ ) )->escaped();
}
$r .= ' . . ';
# Character diff
- if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
- $r .= "$cd . . ";
+ if ( $wgRCShowChangedSize ) {
+ $cd = $this->formatCharacterDifference( $rcObj );
+ if ( $cd !== '' ) {
+ $r .= "$cd . . ";
+ }
}
if ( $type == RC_LOG ) {
$r .= $this->insertLogEntry( $rcObj );
- } else {
+ } else {
$r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
$r .= $this->insertComment( $rcObj );
- $r .= $this->insertRollback( $r, $rcObj );
+ $this->insertRollback( $r, $rcObj );
}
# Tags