Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / includes / revisiondelete / RevDelLogItem.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 RevisionDelete
20 */
21
22 use MediaWiki\Storage\RevisionRecord;
23
24 /**
25 * Item class for a logging table row
26 */
27 class RevDelLogItem extends RevDelItem {
28 public function getIdField() {
29 return 'log_id';
30 }
31
32 public function getTimestampField() {
33 return 'log_timestamp';
34 }
35
36 public function getAuthorIdField() {
37 return 'log_user';
38 }
39
40 public function getAuthorNameField() {
41 return 'log_user_text';
42 }
43
44 public function getAuthorActorField() {
45 return 'log_actor';
46 }
47
48 public function canView() {
49 return LogEventsList::userCan(
50 $this->row, RevisionRecord::DELETED_RESTRICTED, $this->list->getUser()
51 );
52 }
53
54 public function canViewContent() {
55 return true; // none
56 }
57
58 public function getBits() {
59 return (int)$this->row->log_deleted;
60 }
61
62 public function setBits( $bits ) {
63 $dbw = wfGetDB( DB_MASTER );
64
65 $dbw->update( 'logging',
66 [ 'log_deleted' => $bits ],
67 [
68 'log_id' => $this->row->log_id,
69 'log_deleted' => $this->getBits() // cas
70 ],
71 __METHOD__
72 );
73
74 if ( !$dbw->affectedRows() ) {
75 // Concurrent fail!
76 return false;
77 }
78
79 $dbw->update( 'recentchanges',
80 [
81 'rc_deleted' => $bits,
82 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
83 ],
84 [
85 'rc_logid' => $this->row->log_id,
86 'rc_timestamp' => $this->row->log_timestamp // index
87 ],
88 __METHOD__
89 );
90
91 return true;
92 }
93
94 public function getHTML() {
95 $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
96 $this->row->log_timestamp, $this->list->getUser() ) );
97 $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
98 $formatter = LogFormatter::newFromRow( $this->row );
99 $formatter->setContext( $this->list->getContext() );
100 $formatter->setAudience( LogFormatter::FOR_THIS_USER );
101
102 // Log link for this page
103 $loglink = $this->getLinkRenderer()->makeLink(
104 SpecialPage::getTitleFor( 'Log' ),
105 $this->list->msg( 'log' )->text(),
106 [],
107 [ 'page' => $title->getPrefixedText() ]
108 );
109 $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
110 // User links and action text
111 $action = $formatter->getActionText();
112
113 $comment = CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
114 $comment = $this->list->getLanguage()->getDirMark()
115 . Linker::commentBlock( $comment );
116
117 if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
118 $comment = '<span class="history-deleted">' . $comment . '</span>';
119 }
120
121 return "<li>$loglink $date $action $comment</li>";
122 }
123
124 public function getApiData( ApiResult $result ) {
125 $logEntry = DatabaseLogEntry::newFromRow( $this->row );
126 $user = $this->list->getUser();
127 $ret = [
128 'id' => $logEntry->getId(),
129 'type' => $logEntry->getType(),
130 'action' => $logEntry->getSubtype(),
131 'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
132 'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
133 'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
134 ];
135
136 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
137 $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
138 }
139 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
140 $ret += [
141 'userid' => $this->row->log_user,
142 'user' => $this->row->log_user_text,
143 ];
144 }
145 if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
146 $ret += [
147 'comment' => CommentStore::getStore()->getComment( 'log_comment', $this->row )
148 ->text,
149 ];
150 }
151
152 return $ret;
153 }
154 }