Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 116 |
|
0.00% |
0 / 19 |
CRAP | |
0.00% |
0 / 1 |
RevDelRevisionItem | |
0.00% |
0 / 116 |
|
0.00% |
0 / 19 |
1056 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
initRevisionRecord | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getRevisionRecord | |
0.00% |
0 / 1 |
|
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 / 4 |
|
0.00% |
0 / 1 |
2 | |||
canViewContent | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getBits | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setBits | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 | |||
isDeleted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isHideCurrentOp | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getRevisionLink | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
getDiffLink | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
getHTML | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
12 | |||
getTags | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getApiData | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 |
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\Linker\Linker; |
23 | use MediaWiki\MediaWikiServices; |
24 | use MediaWiki\Revision\RevisionRecord; |
25 | |
26 | /** |
27 | * Item class for a live revision table row |
28 | * |
29 | * @property RevDelRevisionList $list |
30 | */ |
31 | class RevDelRevisionItem extends RevDelItem { |
32 | /** @var RevisionRecord */ |
33 | public $revisionRecord; |
34 | |
35 | public function __construct( RevisionListBase $list, $row ) { |
36 | parent::__construct( $list, $row ); |
37 | $this->revisionRecord = static::initRevisionRecord( $list, $row ); |
38 | } |
39 | |
40 | /** |
41 | * Create RevisionRecord object from $row sourced from $list |
42 | * |
43 | * @param RevisionListBase $list |
44 | * @param mixed $row |
45 | * @return RevisionRecord |
46 | */ |
47 | protected static function initRevisionRecord( $list, $row ) { |
48 | return MediaWikiServices::getInstance() |
49 | ->getRevisionFactory() |
50 | ->newRevisionFromRow( $row ); |
51 | } |
52 | |
53 | /** |
54 | * Get the RevisionRecord for the item |
55 | * |
56 | * @return RevisionRecord |
57 | */ |
58 | protected function getRevisionRecord(): RevisionRecord { |
59 | return $this->revisionRecord; |
60 | } |
61 | |
62 | public function getIdField() { |
63 | return 'rev_id'; |
64 | } |
65 | |
66 | public function getTimestampField() { |
67 | return 'rev_timestamp'; |
68 | } |
69 | |
70 | public function getAuthorIdField() { |
71 | return 'rev_user'; |
72 | } |
73 | |
74 | public function getAuthorNameField() { |
75 | return 'rev_user_text'; |
76 | } |
77 | |
78 | public function getAuthorActorField() { |
79 | return 'rev_actor'; |
80 | } |
81 | |
82 | public function canView() { |
83 | return $this->getRevisionRecord()->userCan( |
84 | RevisionRecord::DELETED_RESTRICTED, |
85 | $this->list->getAuthority() |
86 | ); |
87 | } |
88 | |
89 | public function canViewContent() { |
90 | return $this->getRevisionRecord()->userCan( |
91 | RevisionRecord::DELETED_TEXT, |
92 | $this->list->getAuthority() |
93 | ); |
94 | } |
95 | |
96 | public function getBits() { |
97 | return $this->getRevisionRecord()->getVisibility(); |
98 | } |
99 | |
100 | public function setBits( $bits ) { |
101 | $revRecord = $this->getRevisionRecord(); |
102 | |
103 | $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
104 | // Update revision table |
105 | $dbw->newUpdateQueryBuilder() |
106 | ->update( 'revision' ) |
107 | ->set( [ 'rev_deleted' => $bits ] ) |
108 | ->where( [ |
109 | 'rev_id' => $revRecord->getId(), |
110 | 'rev_page' => $revRecord->getPageId(), |
111 | 'rev_deleted' => $this->getBits() // cas |
112 | ] ) |
113 | ->caller( __METHOD__ )->execute(); |
114 | |
115 | if ( !$dbw->affectedRows() ) { |
116 | // Concurrent fail! |
117 | return false; |
118 | } |
119 | // Update recentchanges table |
120 | $dbw->newUpdateQueryBuilder() |
121 | ->update( 'recentchanges' ) |
122 | ->set( [ |
123 | 'rc_deleted' => $bits, |
124 | 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED |
125 | ] ) |
126 | ->where( [ 'rc_this_oldid' => $revRecord->getId() ] ) |
127 | ->caller( __METHOD__ )->execute(); |
128 | |
129 | return true; |
130 | } |
131 | |
132 | public function isDeleted() { |
133 | return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT ); |
134 | } |
135 | |
136 | public function isHideCurrentOp( $newBits ) { |
137 | return ( $newBits & RevisionRecord::DELETED_TEXT ) |
138 | && $this->list->getCurrent() == $this->getId(); |
139 | } |
140 | |
141 | /** |
142 | * Get the HTML link to the revision text. |
143 | * Overridden by RevDelArchiveItem. |
144 | * @return string |
145 | */ |
146 | protected function getRevisionLink() { |
147 | $date = $this->list->getLanguage()->userTimeAndDate( |
148 | $this->getRevisionRecord()->getTimestamp(), |
149 | $this->list->getUser() |
150 | ); |
151 | |
152 | if ( $this->isDeleted() && !$this->canViewContent() ) { |
153 | return htmlspecialchars( $date ); |
154 | } |
155 | |
156 | return $this->getLinkRenderer()->makeKnownLink( |
157 | $this->list->getPage(), |
158 | $date, |
159 | [], |
160 | [ |
161 | 'oldid' => $this->getRevisionRecord()->getId(), |
162 | 'unhide' => 1 |
163 | ] |
164 | ); |
165 | } |
166 | |
167 | /** |
168 | * Get the HTML link to the diff. |
169 | * Overridden by RevDelArchiveItem |
170 | * @return string |
171 | */ |
172 | protected function getDiffLink() { |
173 | if ( $this->isDeleted() && !$this->canViewContent() ) { |
174 | return $this->list->msg( 'diff' )->escaped(); |
175 | } else { |
176 | return $this->getLinkRenderer()->makeKnownLink( |
177 | $this->list->getPage(), |
178 | $this->list->msg( 'diff' )->text(), |
179 | [], |
180 | [ |
181 | 'diff' => $this->getRevisionRecord()->getId(), |
182 | 'oldid' => 'prev', |
183 | 'unhide' => 1 |
184 | ] |
185 | ); |
186 | } |
187 | } |
188 | |
189 | /** |
190 | * @return string A HTML <li> element representing this revision, showing |
191 | * change tags and everything |
192 | */ |
193 | public function getHTML() { |
194 | $revRecord = $this->getRevisionRecord(); |
195 | |
196 | $difflink = $this->list->msg( 'parentheses' ) |
197 | ->rawParams( $this->getDiffLink() )->escaped(); |
198 | $revlink = $this->getRevisionLink(); |
199 | $userlink = Linker::revUserLink( $revRecord ); |
200 | $comment = MediaWikiServices::getInstance()->getCommentFormatter() |
201 | ->formatRevision( $revRecord, $this->list->getAuthority() ); |
202 | if ( $this->isDeleted() ) { |
203 | $class = Linker::getRevisionDeletedClass( $revRecord ); |
204 | $revlink = "<span class=\"$class\">$revlink</span>"; |
205 | } |
206 | $content = "$difflink $revlink $userlink $comment"; |
207 | $attribs = []; |
208 | $tags = $this->getTags(); |
209 | if ( $tags ) { |
210 | [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow( |
211 | $tags, |
212 | 'revisiondelete', |
213 | $this->list->getContext() |
214 | ); |
215 | $content .= " $tagSummary"; |
216 | $attribs['class'] = implode( ' ', $classes ); |
217 | } |
218 | return Xml::tags( 'li', $attribs, $content ); |
219 | } |
220 | |
221 | /** |
222 | * @return string Comma-separated list of tags |
223 | */ |
224 | public function getTags() { |
225 | return $this->row->ts_tags; |
226 | } |
227 | |
228 | public function getApiData( ApiResult $result ) { |
229 | $revRecord = $this->getRevisionRecord(); |
230 | $authority = $this->list->getAuthority(); |
231 | $ret = [ |
232 | 'id' => $revRecord->getId(), |
233 | 'timestamp' => wfTimestamp( TS_ISO_8601, $revRecord->getTimestamp() ), |
234 | 'userhidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_USER ), |
235 | 'commenthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_COMMENT ), |
236 | 'texthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_TEXT ), |
237 | ]; |
238 | if ( $revRecord->userCan( RevisionRecord::DELETED_USER, $authority ) ) { |
239 | $revUser = $revRecord->getUser( RevisionRecord::FOR_THIS_USER, $authority ); |
240 | $ret += [ |
241 | 'userid' => $revUser ? $revUser->getId() : 0, |
242 | 'user' => $revUser ? $revUser->getName() : '', |
243 | ]; |
244 | } |
245 | if ( $revRecord->userCan( RevisionRecord::DELETED_COMMENT, $authority ) ) { |
246 | $revComment = $revRecord->getComment( RevisionRecord::FOR_THIS_USER, $authority ); |
247 | $ret += [ |
248 | 'comment' => $revComment ? $revComment->text : '' |
249 | ]; |
250 | } |
251 | |
252 | return $ret; |
253 | } |
254 | } |