X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fchanges%2FEnhancedChangesList.php;h=03f63f673f5e8157927d6fe162025fc19781f1b0;hb=97c5bc0a1ea20ed4f6c3e26b97dcd5d6f360a8ce;hp=d02eec824a213809d87128189d7e130c792fb339;hpb=b4b57f6505f88a46eaea283737f8e9e15ae8a0e4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php index d02eec824a..30c6995008 100644 --- a/includes/changes/EnhancedChangesList.php +++ b/includes/changes/EnhancedChangesList.php @@ -32,11 +32,17 @@ class EnhancedChangesList extends ChangesList { */ protected $rc_cache; + /** + * @var TemplateParser + */ + protected $templateParser; + /** * @param IContextSource|Skin $obj + * @param array $filterGroups Array of ChangesListFilterGroup objects (currently optional) * @throws MWException */ - public function __construct( $obj ) { + public function __construct( $obj, array $filterGroups = [] ) { if ( $obj instanceof Skin ) { // @todo: deprecate constructing with Skin $context = $obj->getContext(); @@ -49,7 +55,7 @@ class EnhancedChangesList extends ChangesList { $context = $obj; } - parent::__construct( $context ); + parent::__construct( $context, $filterGroups ); // message is set by the parent ChangesList class $this->cacheEntryFactory = new RCCacheEntryFactory( @@ -57,6 +63,7 @@ class EnhancedChangesList extends ChangesList { $this->message, $this->linkRenderer ); + $this->templateParser = new TemplateParser(); } /** @@ -91,7 +98,6 @@ class EnhancedChangesList extends ChangesList { * @return string */ public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) { - $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() @@ -236,8 +242,7 @@ class EnhancedChangesList extends ChangesList { $text = $userlink; $text .= $this->getLanguage()->getDirMark(); if ( $count > 1 ) { - // @todo FIXME: Hardcoded '×'. Should be a message. - $formattedCount = $this->getLanguage()->formatNum( $count ) . '×'; + $formattedCount = $this->msg( 'ntimes' )->numParams( $count )->escaped(); $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped(); } array_push( $users, $text ); @@ -339,8 +344,7 @@ class EnhancedChangesList extends ChangesList { $this->rcCacheIndex++; - $templateParser = new TemplateParser(); - return $templateParser->processTemplate( + return $this->templateParser->processTemplate( 'EnhancedChangesListGroup', $templateParams ); @@ -441,13 +445,16 @@ class EnhancedChangesList extends ChangesList { # Tags $data['tags'] = $this->getTags( $rcObj, $classes ); + $attribs = $this->getDataAttributes( $rcObj ); + // give the hook a chance to modify the data $success = Hooks::run( 'EnhancedChangesListModifyLineData', - [ $this, &$data, $block, $rcObj, &$classes ] ); + [ $this, &$data, $block, $rcObj, &$classes, &$attribs ] ); if ( !$success ) { // skip entry if hook aborted it return []; } + $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] ); $lineParams['recentChangesFlagsRaw'] = []; if ( isset( $data['recentChangesFlags'] ) ) { @@ -463,6 +470,7 @@ class EnhancedChangesList extends ChangesList { } $lineParams['classes'] = array_values( $classes ); + $lineParams['attribs'] = Html::expandAttributes( $attribs ); // everything else: makes it easier for extensions to add or remove data $lineParams['data'] = array_values( $data ); @@ -531,7 +539,7 @@ class EnhancedChangesList extends ChangesList { $links['total-changes'] = $this->linkRenderer->makeKnownLink( $block0->getTitle(), new HtmlArmor( $nchanges[$n] ), - [], + [ 'class' => 'mw-changeslist-groupdiff' ], $queryParams + [ 'diff' => $currentRevision, 'oldid' => $last->mAttribs['rc_last_oldid'], @@ -541,7 +549,7 @@ class EnhancedChangesList extends ChangesList { $links['total-changes-since-last'] = $this->linkRenderer->makeKnownLink( $block0->getTitle(), new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ), - [], + [ 'class' => 'mw-changeslist-groupdiff' ], $queryParams + [ 'diff' => $currentRevision, 'oldid' => $unvisitedOldid, @@ -563,7 +571,7 @@ class EnhancedChangesList extends ChangesList { $links['history'] = $this->linkRenderer->makeKnownLink( $block0->getTitle(), new HtmlArmor( $this->message['enhancedrc-history'] ), - [], + [ 'class' => 'mw-changeslist-history' ], $params ); } @@ -665,6 +673,8 @@ class EnhancedChangesList extends ChangesList { # Show how many people are watching this if enabled $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers ); + $data['attribs'] = array_merge( $this->getDataAttributes( $rcObj ), [ 'class' => $classes ] ); + // give the hook a chance to modify the data $success = Hooks::run( 'EnhancedChangesListModifyBlockLineData', [ $this, &$data, $rcObj ] ); @@ -672,9 +682,13 @@ class EnhancedChangesList extends ChangesList { // skip entry if hook aborted it return ''; } + $attribs = $data['attribs']; + unset( $data['attribs'] ); + $attribs = wfArrayFilterByKey( $attribs, function ( $key ) { + return $key === 'class' || Sanitizer::isReservedDataAttribute( $key ); + } ); - $line = Html::openElement( 'table', [ 'class' => $classes ] ) . - Html::openElement( 'tr' ); + $line = Html::openElement( 'table', $attribs ) . Html::openElement( 'tr' ); $line .= ''; if ( isset( $data['recentChangesFlags'] ) ) { @@ -711,6 +725,11 @@ class EnhancedChangesList extends ChangesList { if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) { // For categorizations we must swap the category title with the page title! $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) ); + if ( !$pageTitle ) { + // The page has been deleted, but the RC entry + // deletion job has not run yet. Just skip. + return ''; + } } $retVal = ' ' . $this->msg( 'parentheses' ) @@ -718,7 +737,7 @@ class EnhancedChangesList extends ChangesList { . $this->linkRenderer->makeKnownLink( $pageTitle, new HtmlArmor( $this->message['hist'] ), - [], + [ 'class' => 'mw-changeslist-history' ], $query ) )->escaped(); return $retVal;