<?php
/**
- * Contains classes for formatting log entries
+ * Contains a class for formatting log entries
*
* 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
global $wgLogActionsHandlers;
$fulltype = $entry->getFullType();
$wildcard = $entry->getType() . '/*';
- $handler = '';
-
- if ( isset( $wgLogActionsHandlers[$fulltype] ) ) {
- $handler = $wgLogActionsHandlers[$fulltype];
- } elseif ( isset( $wgLogActionsHandlers[$wildcard] ) ) {
- $handler = $wgLogActionsHandlers[$wildcard];
- }
+ $handler = $wgLogActionsHandlers[$fulltype] ?? $wgLogActionsHandlers[$wildcard] ?? '';
if ( $handler !== '' && is_string( $handler ) && class_exists( $handler ) ) {
return new $handler( $entry );
* @return string Text
*/
public function getIRCActionText() {
- global $wgContLang;
-
$this->plaintext = true;
$this->irctext = true;
// Text of title the action is aimed at.
$target = $entry->getTarget()->getPrefixedText();
$text = null;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
switch ( $entry->getType() ) {
case 'move':
switch ( $entry->getSubtype() ) {
->rawParams( $target )->inContentLanguage()->escaped();
break;
case 'overwrite':
+ case 'revert':
$text = wfMessage( 'overwroteimage' )
->rawParams( $target )->inContentLanguage()->escaped();
break;
$rawDuration = $parameters['5::duration'];
$rawFlags = $parameters['6::flags'];
}
- $duration = $wgContLang->translateBlockExpiry(
+ $duration = $contLang->translateBlockExpiry(
$rawDuration,
null,
wfTimestamp( TS_UNIX, $entry->getTimestamp() )
);
- $flags = BlockLogFormatter::formatBlockFlags( $rawFlags, $wgContLang );
+ $flags = BlockLogFormatter::formatBlockFlags( $rawFlags, $contLang );
$text = wfMessage( 'blocklogentry' )
->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
break;
->rawParams( $target )->inContentLanguage()->escaped();
break;
case 'reblock':
- $duration = $wgContLang->translateBlockExpiry(
+ $duration = $contLang->translateBlockExpiry(
$parameters['5::duration'],
null,
wfTimestamp( TS_UNIX, $entry->getTimestamp() )
);
- $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $wgContLang );
+ $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'],
+ $contLang );
$text = wfMessage( 'reblock-logentry' )
->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
break;
* @param Title|null $title The page
* @param array $parameters Query parameters
* @param string|null $html Linktext of the link as raw html
- * @throws MWException
* @return string
*/
protected function makePageLink( Title $title = null, $parameters = [], $html = null ) {
if ( !$title instanceof Title ) {
- throw new MWException( 'Expected title, got null' );
+ $msg = $this->msg( 'invalidtitle' )->text();
+ if ( $this->plaintext ) {
+ return $msg;
+ } else {
+ return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ], $msg );
+ }
}
- if ( !$this->plaintext ) {
+
+ if ( $this->plaintext ) {
+ $link = '[[' . $title->getPrefixedText() . ']]';
+ } else {
$html = $html !== null ? new HtmlArmor( $html ) : $html;
$link = $this->getLinkRenderer()->makeLink( $title, $html, [], $parameters );
- } else {
- $link = '[[' . $title->getPrefixedText() . ']]';
}
return $link;
$user->getName(),
true, // redContribsWhenNoEdits
$toolFlags,
- $user->getEditCount()
+ $user->getEditCount(),
+ // do not render parenthesises in the HTML markup (CSS will provide)
+ false
);
}
}
foreach ( $this->getParametersForApi() as $key => $value ) {
$vals = explode( ':', $key, 3 );
if ( count( $vals ) !== 3 ) {
+ if ( $value instanceof __PHP_Incomplete_Class ) {
+ wfLogWarning( 'Log entry of type ' . $this->entry->getFullType() .
+ ' contains unrecoverable extra parameters.' );
+ continue;
+ }
$logParams[$key] = $value;
continue;
}
return [ $name => $value ];
}
}
-
-/**
- * This class formats all log entries for log types
- * which have not been converted to the new system.
- * This is not about old log entries which store
- * parameters in a different format - the new
- * LogFormatter classes have code to support formatting
- * those too.
- * @since 1.19
- */
-class LegacyLogFormatter extends LogFormatter {
- /**
- * Backward compatibility for extension changing the comment from
- * the LogLine hook. This will be set by the first call on getComment(),
- * then it might be modified by the hook when calling getActionLinks(),
- * so that the modified value will be returned when calling getComment()
- * a second time.
- *
- * @var string|null
- */
- private $comment = null;
-
- /**
- * Cache for the result of getActionLinks() so that it does not need to
- * run multiple times depending on the order that getComment() and
- * getActionLinks() are called.
- *
- * @var string|null
- */
- private $revert = null;
-
- public function getComment() {
- if ( $this->comment === null ) {
- $this->comment = parent::getComment();
- }
-
- // Make sure we execute the LogLine hook so that we immediately return
- // the correct value.
- if ( $this->revert === null ) {
- $this->getActionLinks();
- }
-
- return $this->comment;
- }
-
- /**
- * @return string
- * @return-taint onlysafefor_html
- */
- protected function getActionMessage() {
- $entry = $this->entry;
- $action = LogPage::actionText(
- $entry->getType(),
- $entry->getSubtype(),
- $entry->getTarget(),
- $this->plaintext ? null : $this->context->getSkin(),
- (array)$entry->getParameters(),
- !$this->plaintext // whether to filter [[]] links
- );
-
- $performer = $this->getPerformerElement();
- if ( !$this->irctext ) {
- $sep = $this->msg( 'word-separator' );
- $sep = $this->plaintext ? $sep->text() : $sep->escaped();
- $action = $performer . $sep . $action;
- }
-
- return $action;
- }
-
- public function getActionLinks() {
- if ( $this->revert !== null ) {
- return $this->revert;
- }
-
- if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
- $this->revert = '';
- return $this->revert;
- }
-
- $title = $this->entry->getTarget();
- $type = $this->entry->getType();
- $subtype = $this->entry->getSubtype();
-
- // Do nothing. The implementation is handled by the hook modifiying the
- // passed-by-ref parameters. This also changes the default value so that
- // getComment() and getActionLinks() do not call them indefinitely.
- $this->revert = '';
-
- // This is to populate the $comment member of this instance so that it
- // can be modified when calling the hook just below.
- if ( $this->comment === null ) {
- $this->getComment();
- }
-
- $params = $this->entry->getParameters();
-
- Hooks::run( 'LogLine', [ $type, $subtype, $title, $params,
- &$this->comment, &$this->revert, $this->entry->getTimestamp() ] );
-
- return $this->revert;
- }
-}