Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / revisiondelete / RevDelRevisionItem.php
blob7721fe6c957165713df1563878a1e10e174fa594
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.
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.
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
18 * @file
19 * @ingroup RevisionDelete
22 use MediaWiki\Api\ApiResult;
23 use MediaWiki\Linker\Linker;
24 use MediaWiki\MediaWikiServices;
25 use MediaWiki\Revision\RevisionRecord;
26 use MediaWiki\RevisionList\RevisionListBase;
27 use MediaWiki\Xml\Xml;
29 /**
30 * Item class for a live revision table row
32 * @property RevDelRevisionList $list
34 class RevDelRevisionItem extends RevDelItem {
35 /** @var RevisionRecord */
36 public $revisionRecord;
38 public function __construct( RevisionListBase $list, $row ) {
39 parent::__construct( $list, $row );
40 $this->revisionRecord = static::initRevisionRecord( $list, $row );
43 /**
44 * Create RevisionRecord object from $row sourced from $list
46 * @param RevisionListBase $list
47 * @param mixed $row
48 * @return RevisionRecord
50 protected static function initRevisionRecord( $list, $row ) {
51 return MediaWikiServices::getInstance()
52 ->getRevisionFactory()
53 ->newRevisionFromRow( $row );
56 /**
57 * Get the RevisionRecord for the item
59 * @return RevisionRecord
61 protected function getRevisionRecord(): RevisionRecord {
62 return $this->revisionRecord;
65 public function getIdField() {
66 return 'rev_id';
69 public function getTimestampField() {
70 return 'rev_timestamp';
73 public function getAuthorIdField() {
74 return 'rev_user';
77 public function getAuthorNameField() {
78 return 'rev_user_text';
81 public function getAuthorActorField() {
82 return 'rev_actor';
85 public function canView() {
86 return $this->getRevisionRecord()->userCan(
87 RevisionRecord::DELETED_RESTRICTED,
88 $this->list->getAuthority()
92 public function canViewContent() {
93 return $this->getRevisionRecord()->userCan(
94 RevisionRecord::DELETED_TEXT,
95 $this->list->getAuthority()
99 public function getBits() {
100 return $this->getRevisionRecord()->getVisibility();
103 public function setBits( $bits ) {
104 $revRecord = $this->getRevisionRecord();
106 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
107 // Update revision table
108 $dbw->newUpdateQueryBuilder()
109 ->update( 'revision' )
110 ->set( [ 'rev_deleted' => $bits ] )
111 ->where( [
112 'rev_id' => $revRecord->getId(),
113 'rev_page' => $revRecord->getPageId(),
114 'rev_deleted' => $this->getBits() // cas
116 ->caller( __METHOD__ )->execute();
118 if ( !$dbw->affectedRows() ) {
119 // Concurrent fail!
120 return false;
122 // Update recentchanges table
123 $dbw->newUpdateQueryBuilder()
124 ->update( 'recentchanges' )
125 ->set( [
126 'rc_deleted' => $bits,
127 'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
129 ->where( [ 'rc_this_oldid' => $revRecord->getId() ] )
130 ->caller( __METHOD__ )->execute();
132 return true;
135 public function isDeleted() {
136 return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
139 public function isHideCurrentOp( $newBits ) {
140 return ( $newBits & RevisionRecord::DELETED_TEXT )
141 && $this->list->getCurrent() == $this->getId();
145 * Get the HTML link to the revision text.
146 * Overridden by RevDelArchiveItem.
147 * @return string
149 protected function getRevisionLink() {
150 $date = $this->list->getLanguage()->userTimeAndDate(
151 $this->getRevisionRecord()->getTimestamp(),
152 $this->list->getUser()
155 if ( $this->isDeleted() && !$this->canViewContent() ) {
156 return htmlspecialchars( $date );
159 return $this->getLinkRenderer()->makeKnownLink(
160 $this->list->getPage(),
161 $date,
164 'oldid' => $this->getRevisionRecord()->getId(),
165 'unhide' => 1
171 * Get the HTML link to the diff.
172 * Overridden by RevDelArchiveItem
173 * @return string
175 protected function getDiffLink() {
176 if ( $this->isDeleted() && !$this->canViewContent() ) {
177 return $this->list->msg( 'diff' )->escaped();
178 } else {
179 return $this->getLinkRenderer()->makeKnownLink(
180 $this->list->getPage(),
181 $this->list->msg( 'diff' )->text(),
184 'diff' => $this->getRevisionRecord()->getId(),
185 'oldid' => 'prev',
186 'unhide' => 1
193 * @return string A HTML <li> element representing this revision, showing
194 * change tags and everything
196 public function getHTML() {
197 $revRecord = $this->getRevisionRecord();
199 $difflink = $this->list->msg( 'parentheses' )
200 ->rawParams( $this->getDiffLink() )->escaped();
201 $revlink = $this->getRevisionLink();
202 $userlink = Linker::revUserLink( $revRecord );
203 $comment = MediaWikiServices::getInstance()->getCommentFormatter()
204 ->formatRevision( $revRecord, $this->list->getAuthority() );
205 if ( $this->isDeleted() ) {
206 $class = Linker::getRevisionDeletedClass( $revRecord );
207 $revlink = "<span class=\"$class\">$revlink</span>";
209 $content = "$difflink $revlink $userlink $comment";
210 $attribs = [];
211 $tags = $this->getTags();
212 if ( $tags ) {
213 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
214 $tags,
215 'revisiondelete',
216 $this->list->getContext()
218 $content .= " $tagSummary";
219 $attribs['class'] = implode( ' ', $classes );
221 return Xml::tags( 'li', $attribs, $content );
225 * @return string Comma-separated list of tags
227 public function getTags() {
228 return $this->row->ts_tags;
231 public function getApiData( ApiResult $result ) {
232 $revRecord = $this->getRevisionRecord();
233 $authority = $this->list->getAuthority();
234 $ret = [
235 'id' => $revRecord->getId(),
236 'timestamp' => wfTimestamp( TS_ISO_8601, $revRecord->getTimestamp() ),
237 'userhidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_USER ),
238 'commenthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_COMMENT ),
239 'texthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_TEXT ),
241 if ( $revRecord->userCan( RevisionRecord::DELETED_USER, $authority ) ) {
242 $revUser = $revRecord->getUser( RevisionRecord::FOR_THIS_USER, $authority );
243 $ret += [
244 'userid' => $revUser ? $revUser->getId() : 0,
245 'user' => $revUser ? $revUser->getName() : '',
248 if ( $revRecord->userCan( RevisionRecord::DELETED_COMMENT, $authority ) ) {
249 $revComment = $revRecord->getComment( RevisionRecord::FOR_THIS_USER, $authority );
250 $ret += [
251 'comment' => $revComment ? $revComment->text : ''
255 return $ret;