X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flogging%2FLogFormatter.php;h=0f1e1f7f1e8f7cf5cf98b4b70ebe1f2eba79a73f;hb=c4145b2f087c0d8f46191456aa0e4cf83e7b1ba1;hp=e2d9946b83d65deff20e9e4a3fcf4a68298f1385;hpb=91d69e12e1d2e00953cae3c153e37f3d36e5903c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index e2d9946b83..0f1e1f7f1e 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. @@ -67,7 +69,7 @@ class LogFormatter { /** * Handy shortcut for constructing a formatter directly from * database row. - * @param object $row + * @param stdClass|array $row * @see DatabaseLogEntry::getSelectQueryData * @return LogFormatter */ @@ -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 @@ -167,7 +194,7 @@ class LogFormatter { /** * Even uglier hack to maintain backwards compatibilty with IRC bots - * (bug 34508). + * (T36508). * @see getActionText() * @return string Text */ @@ -188,7 +215,7 @@ class LogFormatter { /** * Even uglier hack to maintain backwards compatibilty with IRC bots - * (bug 34508). + * (T36508). * @see getActionText() * @return string Text */ @@ -237,7 +264,7 @@ class LogFormatter { // @codingStandardsIgnoreStart Long line //case 'revision': // Revision deletion //case 'event': // Log deletion - // see https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/LogPage.php?&pathrev=97044&r1=97043&r2=97044 + // see https://github.com/wikimedia/mediawiki/commit/a9c243b7b5289dad204278dbe7ed571fd914e395 //default: // @codingStandardsIgnoreEnd } @@ -245,7 +272,7 @@ class LogFormatter { case 'patrol': // @codingStandardsIgnoreStart Long line - // https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/PatrolLog.php?&pathrev=97495&r1=97494&r2=97495 + // https://github.com/wikimedia/mediawiki/commit/1a05f8faf78675dc85984f27f355b8825b43efff // @codingStandardsIgnoreEnd // Create a diff link to the patrolled revision if ( $entry->getSubtype() === 'patrol' ) { @@ -353,7 +380,11 @@ class LogFormatter { $rawDuration = $parameters['5::duration']; $rawFlags = $parameters['6::flags']; } - $duration = $wgContLang->translateBlockExpiry( $rawDuration ); + $duration = $wgContLang->translateBlockExpiry( + $rawDuration, + null, + wfTimestamp( TS_UNIX, $entry->getTimestamp() ) + ); $flags = BlockLogFormatter::formatBlockFlags( $rawFlags, $wgContLang ); $text = wfMessage( 'blocklogentry' ) ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped(); @@ -363,7 +394,11 @@ class LogFormatter { ->rawParams( $target )->inContentLanguage()->escaped(); break; case 'reblock': - $duration = $wgContLang->translateBlockExpiry( $parameters['5::duration'] ); + $duration = $wgContLang->translateBlockExpiry( + $parameters['5::duration'], + null, + wfTimestamp( TS_UNIX, $entry->getTimestamp() ) + ); $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $wgContLang ); $text = wfMessage( 'reblock-logentry' ) ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped(); @@ -462,7 +497,7 @@ class LogFormatter { */ protected function extractParameters() { $entry = $this->entry; - $params = array(); + $params = []; if ( $entry->isLegacy() ) { foreach ( $entry->getParameters() as $index => $value ) { @@ -608,9 +643,9 @@ class LogFormatter { * @throws MWException * @return string */ - protected function makePageLink( Title $title = null, $parameters = array(), $html = null ) { + protected function makePageLink( Title $title = null, $parameters = [], $html = null ) { if ( !$this->plaintext ) { - $link = Linker::link( $title, $html, array(), $parameters ); + $link = Linker::link( $title, $html, [], $parameters ); } else { if ( !$title instanceof Title ) { throw new MWException( "Expected title, got null" ); @@ -671,7 +706,7 @@ class LogFormatter { } $content = $this->msg( $message )->escaped(); - $attribs = array( 'class' => 'history-deleted' ); + $attribs = [ 'class' => 'history-deleted' ]; return Html::rawElement( 'span', $attribs, $content ); } @@ -685,7 +720,7 @@ class LogFormatter { if ( $this->plaintext ) { return $content; } - $attribs = array( 'class' => 'history-deleted' ); + $attribs = [ 'class' => 'history-deleted' ]; return Html::rawElement( 'span', $attribs, $content ); } @@ -726,7 +761,7 @@ class LogFormatter { * @return array Array of titles that should be preloaded with LinkBatch */ public function getPreloadTitles() { - return array(); + return []; } /** @@ -763,7 +798,7 @@ class LogFormatter { * @return array */ public function formatParametersForApi() { - $logParams = array(); + $logParams = []; foreach ( $this->getParametersForApi() as $key => $value ) { $vals = explode( ':', $key, 3 ); if ( count( $vals ) !== 3 ) { @@ -820,7 +855,7 @@ class LogFormatter { if ( $type === 'msg-content' ) { $msg->inContentLanguage(); } - $value = array(); + $value = []; $value["{$name}_key"] = $msg->getKey(); if ( $msg->getParams() ) { $value["{$name}_params"] = $msg->getParams(); @@ -831,10 +866,12 @@ class LogFormatter { case 'title': case 'title-link': $title = Title::newFromText( $value ); - if ( $title ) { - $value = array(); - ApiQueryBase::addTitleInfo( $value, $title, "{$name}_" ); + if ( !$title ) { + // Huh? Do something halfway sane. + $title = SpecialPage::getTitleFor( 'Badtitle', $value ); } + $value = []; + ApiQueryBase::addTitleInfo( $value, $title, "{$name}_" ); return $value; case 'user': @@ -850,7 +887,7 @@ class LogFormatter { break; } - return array( $name => $value ); + return [ $name => $value ]; } } @@ -946,8 +983,8 @@ class LegacyLogFormatter extends LogFormatter { $params = $this->entry->getParameters(); - Hooks::run( 'LogLine', array( $type, $subtype, $title, $params, - &$this->comment, &$this->revert, $this->entry->getTimestamp() ) ); + Hooks::run( 'LogLine', [ $type, $subtype, $title, $params, + &$this->comment, &$this->revert, $this->entry->getTimestamp() ] ); return $this->revert; }