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