Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 85 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
RevDelLogItem | |
0.00% |
0 / 85 |
|
0.00% |
0 / 12 |
306 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getIdField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTimestampField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthorIdField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthorNameField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthorActorField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
canView | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
canViewContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBits | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setBits | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
6 | |||
getHTML | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
6 | |||
getApiData | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 |
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\CommentStore\CommentStore; |
23 | use MediaWiki\SpecialPage\SpecialPage; |
24 | use MediaWiki\Title\Title; |
25 | use Wikimedia\Rdbms\IConnectionProvider; |
26 | |
27 | /** |
28 | * Item class for a logging table row |
29 | */ |
30 | class RevDelLogItem extends RevDelItem { |
31 | |
32 | /** @var CommentStore */ |
33 | private $commentStore; |
34 | private IConnectionProvider $dbProvider; |
35 | |
36 | /** |
37 | * @param RevisionListBase $list |
38 | * @param stdClass $row DB result row |
39 | * @param CommentStore $commentStore |
40 | * @param IConnectionProvider $dbProvider |
41 | */ |
42 | public function __construct( |
43 | RevisionListBase $list, |
44 | $row, |
45 | CommentStore $commentStore, |
46 | IConnectionProvider $dbProvider |
47 | ) { |
48 | parent::__construct( $list, $row ); |
49 | $this->commentStore = $commentStore; |
50 | $this->dbProvider = $dbProvider; |
51 | } |
52 | |
53 | public function getIdField() { |
54 | return 'log_id'; |
55 | } |
56 | |
57 | public function getTimestampField() { |
58 | return 'log_timestamp'; |
59 | } |
60 | |
61 | public function getAuthorIdField() { |
62 | return 'log_user'; |
63 | } |
64 | |
65 | public function getAuthorNameField() { |
66 | return 'log_user_text'; |
67 | } |
68 | |
69 | public function getAuthorActorField() { |
70 | return 'log_actor'; |
71 | } |
72 | |
73 | public function canView() { |
74 | return LogEventsList::userCan( |
75 | $this->row, LogPage::DELETED_RESTRICTED, $this->list->getAuthority() |
76 | ); |
77 | } |
78 | |
79 | public function canViewContent() { |
80 | return true; // none |
81 | } |
82 | |
83 | public function getBits() { |
84 | return (int)$this->row->log_deleted; |
85 | } |
86 | |
87 | public function setBits( $bits ) { |
88 | $dbw = $this->dbProvider->getPrimaryDatabase(); |
89 | |
90 | $dbw->newUpdateQueryBuilder() |
91 | ->update( 'logging' ) |
92 | ->set( [ 'log_deleted' => $bits ] ) |
93 | ->where( [ |
94 | 'log_id' => $this->row->log_id, |
95 | 'log_deleted' => $this->getBits() // cas |
96 | ] ) |
97 | ->caller( __METHOD__ )->execute(); |
98 | |
99 | if ( !$dbw->affectedRows() ) { |
100 | // Concurrent fail! |
101 | return false; |
102 | } |
103 | |
104 | $dbw->newUpdateQueryBuilder() |
105 | ->update( 'recentchanges' ) |
106 | ->set( [ |
107 | 'rc_deleted' => $bits, |
108 | 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED |
109 | ] ) |
110 | ->where( [ |
111 | 'rc_logid' => $this->row->log_id, |
112 | 'rc_timestamp' => $this->row->log_timestamp // index |
113 | ] ) |
114 | ->caller( __METHOD__ )->execute(); |
115 | |
116 | return true; |
117 | } |
118 | |
119 | public function getHTML() { |
120 | $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( |
121 | $this->row->log_timestamp, $this->list->getUser() ) ); |
122 | $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title ); |
123 | $formatter = LogFormatter::newFromRow( $this->row ); |
124 | $formatter->setContext( $this->list->getContext() ); |
125 | $formatter->setAudience( LogFormatter::FOR_THIS_USER ); |
126 | |
127 | // Log link for this page |
128 | $loglink = $this->getLinkRenderer()->makeLink( |
129 | SpecialPage::getTitleFor( 'Log' ), |
130 | $this->list->msg( 'log' )->text(), |
131 | [], |
132 | [ 'page' => $title->getPrefixedText() ] |
133 | ); |
134 | $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped(); |
135 | // User links and action text |
136 | $action = $formatter->getActionText(); |
137 | |
138 | $comment = $this->list->getLanguage()->getDirMark() . |
139 | $formatter->getComment(); |
140 | |
141 | $content = "$loglink $date $action $comment"; |
142 | $attribs = []; |
143 | if ( $this->row->ts_tags ) { |
144 | [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow( |
145 | $this->row->ts_tags, |
146 | 'revisiondelete', |
147 | $this->list->getContext() |
148 | ); |
149 | $content .= " $tagSummary"; |
150 | $attribs['class'] = implode( ' ', $classes ); |
151 | } |
152 | return Xml::tags( 'li', $attribs, $content ); |
153 | } |
154 | |
155 | public function getApiData( ApiResult $result ) { |
156 | $logEntry = DatabaseLogEntry::newFromRow( $this->row ); |
157 | $user = $this->list->getAuthority(); |
158 | $ret = [ |
159 | 'id' => $logEntry->getId(), |
160 | 'type' => $logEntry->getType(), |
161 | 'action' => $logEntry->getSubtype(), |
162 | 'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ), |
163 | 'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ), |
164 | 'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ), |
165 | ]; |
166 | |
167 | if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) { |
168 | $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi(); |
169 | } |
170 | if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) { |
171 | $ret += [ |
172 | 'userid' => $this->row->log_user ?? 0, |
173 | 'user' => $this->row->log_user_text, |
174 | ]; |
175 | } |
176 | if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) { |
177 | $ret += [ |
178 | 'comment' => $this->commentStore->getComment( 'log_comment', $this->row )->text, |
179 | ]; |
180 | } |
181 | |
182 | return $ret; |
183 | } |
184 | } |