From 80847dcb32f4f6ecf198d3ff4c8bc71333832c75 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 30 Jun 2017 02:05:29 -0700 Subject: [PATCH] Expose LinkRenderer for LogFormatter instances Pass a LinkRenderer instance from SpecialLog, through LogEventsList, onto LogFormatter instances, which tend to make many links. Bug: T168924 Change-Id: I264da6f63678917c7335adee5a0b64cbcded66f3 --- includes/logging/LogEventsList.php | 35 +++++++++++++++++++++++++----- includes/logging/LogFormatter.php | 27 +++++++++++++++++++++++ includes/specials/SpecialLog.php | 2 +- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/includes/logging/LogEventsList.php b/includes/logging/LogEventsList.php index 1463499874..a9679bf384 100644 --- a/includes/logging/LogEventsList.php +++ b/includes/logging/LogEventsList.php @@ -23,6 +23,7 @@ * @file */ +use MediaWiki\Linker\LinkRenderer; use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IDatabase; @@ -48,6 +49,11 @@ class LogEventsList extends ContextSource { */ protected $allowedActions = null; + /** + * @var LinkRenderer|null + */ + private $linkRenderer; + /** * Constructor. * The first two parameters used to be $skin and $out, but now only a context @@ -55,11 +61,11 @@ class LogEventsList extends ContextSource { * * @param IContextSource|Skin $context Context to use; formerly it was * a Skin object. Use of Skin is deprecated. - * @param null $unused Unused; used to be an OutputPage object. + * @param LinkRenderer|null $linkRenderer, previously unused * @param int $flags Can be a combination of self::NO_ACTION_LINK, * self::NO_EXTRA_USER_LINKS or self::USE_CHECKBOXES. */ - public function __construct( $context, $unused = null, $flags = 0 ) { + public function __construct( $context, $linkRenderer = null, $flags = 0 ) { if ( $context instanceof IContextSource ) { $this->setContext( $context ); } else { @@ -69,6 +75,21 @@ class LogEventsList extends ContextSource { $this->flags = $flags; $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() ); + if ( $linkRenderer instanceof LinkRenderer ) { + $this->linkRenderer = $linkRenderer; + } + } + + /** + * @since 1.30 + * @return LinkRenderer + */ + protected function getLinkRenderer() { + if ( $this->linkRenderer !== null ) { + return $this->linkRenderer; + } else { + return MediaWikiServices::getInstance()->getLinkRenderer(); + } } /** @@ -149,7 +170,7 @@ class LogEventsList extends ContextSource { // Option value -> message mapping $links = []; $hiddens = ''; // keep track for "go" button - $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); + $linkRenderer = $this->getLinkRenderer(); foreach ( $filter as $type => $val ) { // Should the below assignment be outside the foreach? // Then it would have to be copied. Not certain what is more expensive. @@ -359,6 +380,7 @@ class LogEventsList extends ContextSource { $entry = DatabaseLogEntry::newFromRow( $row ); $formatter = LogFormatter::newFromEntry( $entry ); $formatter->setContext( $this->getContext() ); + $formatter->setLinkRenderer( $this->getLinkRenderer() ); $formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) ); $time = htmlspecialchars( $this->getLanguage()->userTimeAndDate( @@ -607,8 +629,11 @@ class LogEventsList extends ContextSource { $context = RequestContext::getMain(); } + // FIXME: Figure out how to inject this + $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); + # Insert list of top 50 (or top $lim) items - $loglist = new LogEventsList( $context, null, $flags ); + $loglist = new LogEventsList( $context, $linkRenderer, $flags ); $pager = new LogPager( $loglist, $types, $user, $page, '', $conds ); if ( !$useRequestParams ) { # Reset vars that may have been taken from the request @@ -686,7 +711,7 @@ class LogEventsList extends ContextSource { $urlParam = array_merge( $urlParam, $extraUrlParams ); } - $s .= MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink( + $s .= $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'Log' ), $context->msg( 'log-fulllog' )->text(), [], diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 68404bfcea..2a47943a03 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * @since 1.19 */ +use MediaWiki\Linker\LinkRenderer; +use MediaWiki\MediaWikiServices; /** * Implements the default log formatting. @@ -101,6 +103,11 @@ class LogFormatter { /** @var string */ protected $irctext = false; + /** + * @var LinkRenderer|null + */ + private $linkRenderer; + protected function __construct( LogEntry $entry ) { $this->entry = $entry; $this->context = RequestContext::getMain(); @@ -114,6 +121,26 @@ class LogFormatter { $this->context = $context; } + /** + * @since 1.30 + * @param LinkRenderer $linkRenderer + */ + public function setLinkRenderer( LinkRenderer $linkRenderer ) { + $this->linkRenderer = $linkRenderer; + } + + /** + * @since 1.30 + * @return LinkRenderer + */ + public function getLinkRenderer() { + if ( $this->linkRenderer !== null ) { + return $this->linkRenderer; + } else { + return MediaWikiServices::getInstance()->getLinkRenderer(); + } + } + /** * Set the visibility restrictions for displaying content. * If set to public, and an item is deleted, then it will be replaced diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index 1710b3991c..511cfbf5d0 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -165,7 +165,7 @@ class SpecialLog extends SpecialPage { # Create a LogPager item to get the results and a LogEventsList item to format them... $loglist = new LogEventsList( $this->getContext(), - null, + $this->getLinkRenderer(), LogEventsList::USE_CHECKBOXES ); -- 2.20.1