Sync up with Parsoid parserTests.txt
[mediawiki.git] / includes / logging / LegacyLogFormatter.php
blob14a7d828221a41e6ae6edbef8b3a878dd15d0c39
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 /**
27 * This class formats all log entries for log types
28 * which have not been converted to the new system.
29 * This is not about old log entries which store
30 * parameters in a different format - the new
31 * LogFormatter classes have code to support formatting
32 * those too.
33 * @since 1.19
35 class LegacyLogFormatter extends LogFormatter {
36 /**
37 * Backward compatibility for extension changing the comment from
38 * the LogLine hook. This will be set by the first call on getComment(),
39 * then it might be modified by the hook when calling getActionLinks(),
40 * so that the modified value will be returned when calling getComment()
41 * a second time.
43 * @var string|null
45 private $comment = null;
47 /**
48 * Cache for the result of getActionLinks() so that it does not need to
49 * run multiple times depending on the order that getComment() and
50 * getActionLinks() are called.
52 * @var string|null
54 private $revert = null;
56 public function getComment() {
57 if ( $this->comment === null ) {
58 $this->comment = parent::getComment();
61 // Make sure we execute the LogLine hook so that we immediately return
62 // the correct value.
63 if ( $this->revert === null ) {
64 $this->getActionLinks();
67 return $this->comment;
70 /**
71 * @return string
72 * @return-taint onlysafefor_html
74 protected function getActionMessage() {
75 $entry = $this->entry;
76 $action = LogPage::actionText(
77 $entry->getType(),
78 $entry->getSubtype(),
79 $entry->getTarget(),
80 $this->plaintext ? null : $this->context->getSkin(),
81 (array)$entry->getParameters(),
82 !$this->plaintext // whether to filter [[]] links
85 $performer = $this->getPerformerElement();
86 if ( !$this->irctext ) {
87 $sep = $this->msg( 'word-separator' );
88 $sep = $this->plaintext ? $sep->text() : $sep->escaped();
89 $action = $performer . $sep . $action;
92 return $action;
95 public function getActionLinks() {
96 if ( $this->revert !== null ) {
97 return $this->revert;
100 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
101 $this->revert = '';
102 return $this->revert;
105 $title = $this->entry->getTarget();
106 $type = $this->entry->getType();
107 $subtype = $this->entry->getSubtype();
109 // Do nothing. The implementation is handled by the hook modifying the
110 // passed-by-ref parameters. This also changes the default value so that
111 // getComment() and getActionLinks() do not call them indefinitely.
112 $this->revert = '';
114 // This is to populate the $comment member of this instance so that it
115 // can be modified when calling the hook just below.
116 if ( $this->comment === null ) {
117 $this->getComment();
120 $params = $this->entry->getParameters();
122 Hooks::runner()->onLogLine( $type, $subtype, $title, $params, $this->comment,
123 $this->revert, $this->entry->getTimestamp() );
125 return $this->revert;