$this->skin = $obj;
}
$this->preCacheMessages();
- $this->watchMsgCache = new HashBagOStuff( array( 'maxKeys' => 50 ) );
+ $this->watchMsgCache = new HashBagOStuff( [ 'maxKeys' => 50 ] );
}
/**
$user = $context->getUser();
$sk = $context->getSkin();
$list = null;
- if ( Hooks::run( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
+ if ( Hooks::run( 'FetchChangesList', [ $user, &$sk, &$list ] ) ) {
$new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context );
*/
private function preCacheMessages() {
if ( !isset( $this->message ) ) {
- foreach ( array(
+ foreach ( [
'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
- 'semicolon-separator', 'pipe-separator' ) as $msg
+ 'semicolon-separator', 'pipe-separator' ] as $msg
) {
$this->message[$msg] = $this->msg( $msg )->escaped();
}
$f = '';
foreach ( array_keys( $this->getConfig()->get( 'RecentChangesFlags' ) ) as $flag ) {
$f .= isset( $flags[$flag] ) && $flags[$flag]
- ? self::flag( $flag )
+ ? self::flag( $flag, $this->getContext() )
: $nothing;
}
}
/**
- * Provide the "<abbr>" element appropriate to a given abbreviated flag,
- * namely the flag indicating a new page, a minor edit, a bot edit, or an
- * unpatrolled edit. By default in English it will contain "N", "m", "b",
- * "!" respectively, plus it will have an appropriate title and class.
+ * Get an array of default HTML class attributes for the change.
+ *
+ * @param RecentChange|RCCacheEntry $rc
+ * @param string|bool $watched Optionally timestamp for adding watched class
+ *
+ * @return array of classes
+ */
+ protected function getHTMLClasses( $rc, $watched ) {
+ $classes = [];
+ $logType = $rc->mAttribs['rc_log_type'];
+
+ if ( $logType ) {
+ $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType );
+ } else {
+ $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
+ $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
+ }
+
+ // Indicate watched status on the line to allow for more
+ // comprehensive styling.
+ $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
+ ? 'mw-changeslist-line-watched'
+ : 'mw-changeslist-line-not-watched';
+
+ return $classes;
+ }
+
+ /**
+ * Make an "<abbr>" element for a given change flag. The flag indicating a new page, minor edit,
+ * bot edit, or unpatrolled edit. In English it typically contains "N", "m", "b", or "!".
*
* @param string $flag One key of $wgRecentChangesFlags
- * @return string Raw HTML
+ * @param IContextSource $context
+ * @return string HTML
*/
- public static function flag( $flag ) {
+ public static function flag( $flag, IContextSource $context = null ) {
+ static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
static $flagInfos = null;
+
if ( is_null( $flagInfos ) ) {
global $wgRecentChangesFlags;
- $flagInfos = array();
+ $flagInfos = [];
foreach ( $wgRecentChangesFlags as $key => $value ) {
- $flagInfos[$key]['letter'] = wfMessage( $value['letter'] )->escaped();
- $flagInfos[$key]['title'] = wfMessage( $value['title'] )->escaped();
+ $flagInfos[$key]['letter'] = $value['letter'];
+ $flagInfos[$key]['title'] = $value['title'];
// Allow customized class name, fall back to flag name
- $flagInfos[$key]['class'] = Sanitizer::escapeClass(
- isset( $value['class'] ) ? $value['class'] : $key );
+ $flagInfos[$key]['class'] = isset( $value['class'] ) ? $value['class'] : $key;
}
}
- // Inconsistent naming, bleh, kepted for b/c
- $map = array(
- 'minoredit' => 'minor',
- 'botedit' => 'bot',
- );
+ $context = $context ?: RequestContext::getMain();
+
+ // Inconsistent naming, kepted for b/c
if ( isset( $map[$flag] ) ) {
$flag = $map[$flag];
}
- return "<abbr class='" . $flagInfos[$flag]['class'] . "' title='" .
- $flagInfos[$flag]['title'] . "'>" . $flagInfos[$flag]['letter'] .
- '</abbr>';
+ $info = $flagInfos[$flag];
+ return Html::element( 'abbr', [
+ 'class' => $info['class'],
+ 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
+ ], wfMessage( $info['letter'] )->setContext( $context )->text() );
}
/**
* @return string
*/
public function beginRecentChangesList() {
- $this->rc_cache = array();
+ $this->rc_cache = [];
$this->rcMoveIndex = 0;
$this->rcCacheIndex = 0;
$this->lastdate = '';
* @param ResultWrapper|array $rows
*/
public function initChangesListRows( $rows ) {
- Hooks::run( 'ChangesListInitRows', array( $this, $rows ) );
+ Hooks::run( 'ChangesListInitRows', [ $this, $rows ] );
}
/**
$lang = $context->getLanguage();
$config = $context->getConfig();
$code = $lang->getCode();
- static $fastCharDiff = array();
+ static $fastCharDiff = [];
if ( !isset( $fastCharDiff[$code] ) ) {
$fastCharDiff[$code] = $config->get( 'MiserMode' )
|| $context->msg( 'rc-change-size' )->plain() === '$1';
$formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
return Html::element( $tag,
- array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
+ [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
$context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
}
*/
public function insertLog( &$s, $title, $logtype ) {
$page = new LogPage( $logtype );
- $logname = $page->getName()->escaped();
+ $logname = $page->getName()->setContext( $this->getContext() )->escaped();
$s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped();
}
/**
* @param string $s HTML to update
* @param RecentChange $rc
- * @param bool $unpatrolled
+ * @param bool|null $unpatrolled Unused variable, since 1.27.
*/
- public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
+ public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
# Diff link
if (
$rc->mAttribs['rc_type'] == RC_NEW ||
} elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
$diffLink = $this->message['diff'];
} else {
- $query = array(
+ $query = [
'curid' => $rc->mAttribs['rc_cur_id'],
'diff' => $rc->mAttribs['rc_this_oldid'],
'oldid' => $rc->mAttribs['rc_last_oldid']
- );
+ ];
$diffLink = Linker::linkKnown(
$rc->getTitle(),
$this->message['diff'],
- array( 'tabindex' => $rc->counter ),
+ [ 'tabindex' => $rc->counter ],
$query
);
}
$diffhist .= Linker::linkKnown(
$rc->getTitle(),
$this->message['hist'],
- array(),
- array(
+ [],
+ [
'curid' => $rc->mAttribs['rc_cur_id'],
'action' => 'history'
- )
+ ]
);
}
* @since 1.26
*/
public function getArticleLink( &$rc, $unpatrolled, $watched ) {
- $params = array();
+ $params = [];
if ( $rc->getTitle()->isRedirect() ) {
- $params = array( 'redirect' => 'no' );
+ $params = [ 'redirect' => 'no' ];
}
- $articlelink = Linker::linkKnown(
+ $articlelink = Linker::link(
$rc->getTitle(),
null,
- array( 'class' => 'mw-changeslist-title' ),
+ [ 'class' => 'mw-changeslist-title' ],
$params
);
if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
# TODO: Deprecate the $s argument, it seems happily unused.
$s = '';
Hooks::run( 'ChangesListInsertArticleLink',
- array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
+ [ &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] );
return "{$s} {$articlelink}";
}
if ( $this->getUser()->isAllowed( 'rollback' )
&& $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']
) {
- $rev = new Revision( array(
+ $rev = new Revision( [
'title' => $page,
'id' => $rc->mAttribs['rc_this_oldid'],
'user' => $rc->mAttribs['rc_user'],
'user_text' => $rc->mAttribs['rc_user_text'],
'deleted' => $rc->mAttribs['rc_deleted']
- ) );
+ ] );
$s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
}
}
list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
$rc->mAttribs['ts_tags'],
- 'changeslist'
+ 'changeslist',
+ $this->getContext()
);
$classes = array_merge( $classes, $newClasses );
$s .= ' ' . $tagSummary;
*/
public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
- $classes = array();
+ $classes = $this->getHTMLClasses( $rc, $watched );
// use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
if ( $linenumber ) {
if ( $linenumber & 1 ) {
}
}
- // Indicate watched status on the line to allow for more
- // comprehensive styling.
- $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
- ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
-
$html = $this->formatChangeLine( $rc, $classes, $watched );
if ( $this->watchlist ) {
$rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
}
- if ( !Hooks::run( 'OldChangesListRecentChangesLine', array( &$this, &$html, $rc, &$classes ) ) ) {
+ if ( !Hooks::run( 'OldChangesListRecentChangesLine', [ &$this, &$html, $rc, &$classes ] ) ) {
return false;
}
if ( $rc->mAttribs['rc_log_type'] ) {
$logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
$this->insertLog( $html, $logtitle, $rc->mAttribs['rc_log_type'] );
- $flags = $this->recentChangesFlags( array( 'unpatrolled' =>$unpatrolled,
- 'bot' => $rc->mAttribs['rc_bot'] ), '' );
+ $flags = $this->recentChangesFlags( [ 'unpatrolled' =>$unpatrolled,
+ 'bot' => $rc->mAttribs['rc_bot'] ], '' );
if ( $flags !== '' ) {
$html .= ' ' . $flags;
}
}
// Regular entries
} else {
- $this->insertDiffHist( $html, $rc, $unpatrolled );
+ $this->insertDiffHist( $html, $rc );
# M, N, b and ! (minor, new, bot and unpatrolled)
$html .= $this->recentChangesFlags(
- array(
+ [
'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
'minor' => $rc->mAttribs['rc_minor'],
'unpatrolled' => $unpatrolled,
'bot' => $rc->mAttribs['rc_bot']
- ),
+ ],
''
);
$html .= $this->getArticleLink( $rc, $unpatrolled, $watched );