ParsoidParser: Record ParserOptions watcher on ParserOutput object
[mediawiki.git] / includes / logging / LegacyLogFormatter.php
blob60a748cc1427d8329106a2f3e4e1292b58d79358
1 <?php
2 /**
3 * Contains a class for formatting log legacy entries
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Niklas Laxström
22 * @license GPL-2.0-or-later
23 * @since 1.19
26 use MediaWiki\HookContainer\HookRunner;
27 use MediaWiki\MediaWikiServices;
29 /**
30 * This class formats all log entries for log types
31 * which have not been converted to the new system.
32 * This is not about old log entries which store
33 * parameters in a different format - the new
34 * LogFormatter classes have code to support formatting
35 * those too.
36 * @since 1.19
38 class LegacyLogFormatter extends LogFormatter {
39 /**
40 * Backward compatibility for extension changing the comment from
41 * the LogLine hook. This will be set by the first call on getComment(),
42 * then it might be modified by the hook when calling getActionLinks(),
43 * so that the modified value will be returned when calling getComment()
44 * a second time.
46 * @var string|null
48 private $comment = null;
50 /**
51 * Cache for the result of getActionLinks() so that it does not need to
52 * run multiple times depending on the order that getComment() and
53 * getActionLinks() are called.
55 * @var string|null
57 private $revert = null;
59 public function getComment() {
60 $this->comment ??= parent::getComment();
62 // Make sure we execute the LogLine hook so that we immediately return
63 // the correct value.
64 if ( $this->revert === null ) {
65 $this->getActionLinks();
68 return $this->comment;
71 /**
72 * @return string
73 * @return-taint onlysafefor_html
75 protected function getActionMessage() {
76 $entry = $this->entry;
77 $action = LogPage::actionText(
78 $entry->getType(),
79 $entry->getSubtype(),
80 $entry->getTarget(),
81 $this->plaintext ? null : $this->context->getSkin(),
82 (array)$entry->getParameters(),
83 !$this->plaintext // whether to filter [[]] links
86 $performer = $this->getPerformerElement();
87 if ( !$this->irctext ) {
88 $sep = $this->msg( 'word-separator' );
89 $sep = $this->plaintext ? $sep->text() : $sep->escaped();
90 $action = $performer . $sep . $action;
93 return $action;
96 public function getActionLinks() {
97 if ( $this->revert !== null ) {
98 return $this->revert;
101 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
102 $this->revert = '';
103 return $this->revert;
106 $title = $this->entry->getTarget();
107 $type = $this->entry->getType();
108 $subtype = $this->entry->getSubtype();
110 // Do nothing. The implementation is handled by the hook modifying the
111 // passed-by-ref parameters. This also changes the default value so that
112 // getComment() and getActionLinks() do not call them indefinitely.
113 $this->revert = '';
115 // This is to populate the $comment member of this instance so that it
116 // can be modified when calling the hook just below.
117 if ( $this->comment === null ) {
118 $this->getComment();
121 $params = $this->entry->getParameters();
123 ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onLogLine(
124 $type, $subtype, $title, $params, $this->comment, $this->revert, $this->entry->getTimestamp() );
126 return $this->revert;