Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / includes / changetags / ChangeTagsLogItem.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Change tagging
20 */
21
22 use MediaWiki\MediaWikiServices;
23 use MediaWiki\Storage\RevisionRecord;
24
25 /**
26 * Item class for a logging table row with its associated change tags.
27 * @todo Abstract out a base class for this and RevDelLogItem, similar to the
28 * RevisionItem class but specifically for log items.
29 * @since 1.25
30 */
31 class ChangeTagsLogItem extends RevisionItemBase {
32 public function getIdField() {
33 return 'log_id';
34 }
35
36 public function getTimestampField() {
37 return 'log_timestamp';
38 }
39
40 public function getAuthorIdField() {
41 return 'log_user';
42 }
43
44 public function getAuthorNameField() {
45 return 'log_user_text';
46 }
47
48 public function getAuthorActorField() {
49 return 'log_actor';
50 }
51
52 public function canView() {
53 return LogEventsList::userCan(
54 $this->row, RevisionRecord::SUPPRESSED_ALL, $this->list->getUser()
55 );
56 }
57
58 public function canViewContent() {
59 return true; // none
60 }
61
62 /**
63 * @return string Comma-separated list of tags
64 */
65 public function getTags() {
66 return $this->row->ts_tags;
67 }
68
69 /**
70 * @return string A HTML <li> element representing this revision, showing
71 * change tags and everything
72 */
73 public function getHTML() {
74 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
75 $this->row->log_timestamp, $this->list->getUser() ) );
76 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
77 $formatter = LogFormatter::newFromRow( $this->row );
78 $formatter->setContext( $this->list->getContext() );
79 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
80
81 // Log link for this page
82 $loglink = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
83 SpecialPage::getTitleFor( 'Log' ),
84 $this->list->msg( 'log' )->text(),
85 [],
86 [ 'page' => $title->getPrefixedText() ]
87 );
88 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
89 // User links and action text
90 $action = $formatter->getActionText();
91
92 $comment = $this->list->getLanguage()->getDirMark() .
93 $formatter->getComment();
94
95 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
96 $comment = '<span class="history-deleted">' . $comment . '</span>';
97 }
98
99 $content = "$loglink $date $action $comment";
100 $attribs = [];
101 $tags = $this->getTags();
102 if ( $tags ) {
103 list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
104 $tags,
105 'edittags',
106 $this->list->getContext()
107 );
108 $content .= " $tagSummary";
109 $attribs['class'] = implode( ' ', $classes );
110 }
111 return Xml::tags( 'li', $attribs, $content );
112 }
113 }