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
19 * @ingroup RevisionDelete
22 use MediaWiki\Storage\RevisionRecord
;
25 * Item class for a live revision table row
27 * @property RevDelRevisionList $list
29 class RevDelRevisionItem
extends RevDelItem
{
33 public function __construct( $list, $row ) {
34 parent
::__construct( $list, $row );
35 $this->revision
= static::initRevision( $list, $row );
39 * Create revision object from $row sourced from $list
41 * @param RevisionListBase $list
45 protected static function initRevision( $list, $row ) {
46 return new Revision( $row );
49 public function getIdField() {
53 public function getTimestampField() {
54 return 'rev_timestamp';
57 public function getAuthorIdField() {
61 public function getAuthorNameField() {
62 return 'rev_user_text';
65 public function getAuthorActorField() {
69 public function canView() {
70 return $this->revision
->userCan(
71 RevisionRecord
::DELETED_RESTRICTED
, $this->list->getUser()
75 public function canViewContent() {
76 return $this->revision
->userCan(
77 RevisionRecord
::DELETED_TEXT
, $this->list->getUser()
81 public function getBits() {
82 return $this->revision
->getVisibility();
85 public function setBits( $bits ) {
86 $dbw = wfGetDB( DB_MASTER
);
87 // Update revision table
88 $dbw->update( 'revision',
89 [ 'rev_deleted' => $bits ],
91 'rev_id' => $this->revision
->getId(),
92 'rev_page' => $this->revision
->getPage(),
93 'rev_deleted' => $this->getBits() // cas
97 if ( !$dbw->affectedRows() ) {
101 // Update recentchanges table
102 $dbw->update( 'recentchanges',
104 'rc_deleted' => $bits,
105 'rc_patrolled' => RecentChange
::PRC_AUTOPATROLLED
108 'rc_this_oldid' => $this->revision
->getId(), // condition
109 // non-unique timestamp index
110 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
118 public function isDeleted() {
119 return $this->revision
->isDeleted( RevisionRecord
::DELETED_TEXT
);
122 public function isHideCurrentOp( $newBits ) {
123 return ( $newBits & RevisionRecord
::DELETED_TEXT
)
124 && $this->list->getCurrent() == $this->getId();
128 * Get the HTML link to the revision text.
129 * Overridden by RevDelArchiveItem.
132 protected function getRevisionLink() {
133 $date = $this->list->getLanguage()->userTimeAndDate(
134 $this->revision
->getTimestamp(), $this->list->getUser() );
136 if ( $this->isDeleted() && !$this->canViewContent() ) {
137 return htmlspecialchars( $date );
140 return $this->getLinkRenderer()->makeKnownLink(
145 'oldid' => $this->revision
->getId(),
152 * Get the HTML link to the diff.
153 * Overridden by RevDelArchiveItem
156 protected function getDiffLink() {
157 if ( $this->isDeleted() && !$this->canViewContent() ) {
158 return $this->list->msg( 'diff' )->escaped();
160 return $this->getLinkRenderer()->makeKnownLink(
162 $this->list->msg( 'diff' )->text(),
165 'diff' => $this->revision
->getId(),
174 * @return string A HTML <li> element representing this revision, showing
175 * change tags and everything
177 public function getHTML() {
178 $difflink = $this->list->msg( 'parentheses' )
179 ->rawParams( $this->getDiffLink() )->escaped();
180 $revlink = $this->getRevisionLink();
181 $userlink = Linker
::revUserLink( $this->revision
);
182 $comment = Linker
::revComment( $this->revision
);
183 if ( $this->isDeleted() ) {
184 $revlink = "<span class=\"history-deleted\">$revlink</span>";
186 $content = "$difflink $revlink $userlink $comment";
188 $tags = $this->getTags();
190 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
193 $this->list->getContext()
195 $content .= " $tagSummary";
196 $attribs['class'] = implode( ' ', $classes );
198 return Xml
::tags( 'li', $attribs, $content );
202 * @return string Comma-separated list of tags
204 public function getTags() {
205 return $this->row
->ts_tags
;
208 public function getApiData( ApiResult
$result ) {
209 $rev = $this->revision
;
210 $user = $this->list->getUser();
212 'id' => $rev->getId(),
213 'timestamp' => wfTimestamp( TS_ISO_8601
, $rev->getTimestamp() ),
214 'userhidden' => (bool)$rev->isDeleted( RevisionRecord
::DELETED_USER
),
215 'commenthidden' => (bool)$rev->isDeleted( RevisionRecord
::DELETED_COMMENT
),
216 'texthidden' => (bool)$rev->isDeleted( RevisionRecord
::DELETED_TEXT
),
218 if ( $rev->userCan( RevisionRecord
::DELETED_USER
, $user ) ) {
220 'userid' => $rev->getUser( RevisionRecord
::FOR_THIS_USER
),
221 'user' => $rev->getUserText( RevisionRecord
::FOR_THIS_USER
),
224 if ( $rev->userCan( RevisionRecord
::DELETED_COMMENT
, $user ) ) {
226 'comment' => $rev->getComment( RevisionRecord
::FOR_THIS_USER
),