SECURITY: Add permission check for user is permitted to view the log type
[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
24 /**
25 * Item class for a logging table row with its associated change tags.
26 * @todo Abstract out a base class for this and RevDelLogItem, similar to the
27 * RevisionItem class but specifically for log items.
28 * @since 1.25
29 */
30 class ChangeTagsLogItem extends RevisionItemBase {
31 public function getIdField() {
32 return 'log_id';
33 }
34
35 public function getTimestampField() {
36 return 'log_timestamp';
37 }
38
39 public function getAuthorIdField() {
40 return 'log_user';
41 }
42
43 public function getAuthorNameField() {
44 return 'log_user_text';
45 }
46
47 public function getAuthorActorField() {
48 return 'log_actor';
49 }
50
51 public function canView() {
52 return LogEventsList::userCan( $this->row, Revision::SUPPRESSED_ALL, $this->list->getUser() );
53 }
54
55 public function canViewContent() {
56 return true; // none
57 }
58
59 /**
60 * @return string Comma-separated list of tags
61 */
62 public function getTags() {
63 return $this->row->ts_tags;
64 }
65
66 /**
67 * @return string A HTML <li> element representing this revision, showing
68 * change tags and everything
69 */
70 public function getHTML() {
71 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
72 $this->row->log_timestamp, $this->list->getUser() ) );
73 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
74 $formatter = LogFormatter::newFromRow( $this->row );
75 $formatter->setContext( $this->list->getContext() );
76 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
77
78 // Log link for this page
79 $loglink = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
80 SpecialPage::getTitleFor( 'Log' ),
81 $this->list->msg( 'log' )->text(),
82 [],
83 [ 'page' => $title->getPrefixedText() ]
84 );
85 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
86 // User links and action text
87 $action = $formatter->getActionText();
88 // Comment
89 $comment = $this->list->getLanguage()->getDirMark() .
90 $formatter->getComment();
91
92 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
93 $comment = '<span class="history-deleted">' . $comment . '</span>';
94 }
95
96 $content = "$loglink $date $action $comment";
97 $attribs = [];
98 $tags = $this->getTags();
99 if ( $tags ) {
100 list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
101 $tags,
102 'edittags',
103 $this->list->getContext()
104 );
105 $content .= " $tagSummary";
106 $attribs['class'] = implode( ' ', $classes );
107 }
108 return Xml::tags( 'li', $attribs, $content );
109 }
110 }