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 class RevDelRevisionItem
extends RevDelItem
{
31 public function __construct( $list, $row ) {
32 parent
::__construct( $list, $row );
33 $this->revision
= static::initRevision( $list, $row );
37 * Create revision object from $row sourced from $list
39 * @param RevisionListBase $list
43 protected static function initRevision( $list, $row ) {
44 return new Revision( $row );
47 public function getIdField() {
51 public function getTimestampField() {
52 return 'rev_timestamp';
55 public function getAuthorIdField() {
59 public function getAuthorNameField() {
60 return 'rev_user_text';
63 public function getAuthorActorField() {
67 public function canView() {
68 return $this->revision
->userCan(
69 RevisionRecord
::DELETED_RESTRICTED
, $this->list->getUser()
73 public function canViewContent() {
74 return $this->revision
->userCan(
75 RevisionRecord
::DELETED_TEXT
, $this->list->getUser()
79 public function getBits() {
80 return $this->revision
->getVisibility();
83 public function setBits( $bits ) {
84 $dbw = wfGetDB( DB_MASTER
);
85 // Update revision table
86 $dbw->update( 'revision',
87 [ 'rev_deleted' => $bits ],
89 'rev_id' => $this->revision
->getId(),
90 'rev_page' => $this->revision
->getPage(),
91 'rev_deleted' => $this->getBits() // cas
95 if ( !$dbw->affectedRows() ) {
99 // Update recentchanges table
100 $dbw->update( 'recentchanges',
102 'rc_deleted' => $bits,
103 'rc_patrolled' => RecentChange
::PRC_AUTOPATROLLED
106 'rc_this_oldid' => $this->revision
->getId(), // condition
107 // non-unique timestamp index
108 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
116 public function isDeleted() {
117 return $this->revision
->isDeleted( RevisionRecord
::DELETED_TEXT
);
120 public function isHideCurrentOp( $newBits ) {
121 return ( $newBits & RevisionRecord
::DELETED_TEXT
)
122 && $this->list->getCurrent() == $this->getId();
126 * Get the HTML link to the revision text.
127 * Overridden by RevDelArchiveItem.
130 protected function getRevisionLink() {
131 $date = $this->list->getLanguage()->userTimeAndDate(
132 $this->revision
->getTimestamp(), $this->list->getUser() );
134 if ( $this->isDeleted() && !$this->canViewContent() ) {
135 return htmlspecialchars( $date );
138 return $this->getLinkRenderer()->makeKnownLink(
143 'oldid' => $this->revision
->getId(),
150 * Get the HTML link to the diff.
151 * Overridden by RevDelArchiveItem
154 protected function getDiffLink() {
155 if ( $this->isDeleted() && !$this->canViewContent() ) {
156 return $this->list->msg( 'diff' )->escaped();
158 return $this->getLinkRenderer()->makeKnownLink(
160 $this->list->msg( 'diff' )->text(),
163 'diff' => $this->revision
->getId(),
172 * @return string A HTML <li> element representing this revision, showing
173 * change tags and everything
175 public function getHTML() {
176 $difflink = $this->list->msg( 'parentheses' )
177 ->rawParams( $this->getDiffLink() )->escaped();
178 $revlink = $this->getRevisionLink();
179 $userlink = Linker
::revUserLink( $this->revision
);
180 $comment = Linker
::revComment( $this->revision
);
181 if ( $this->isDeleted() ) {
182 $revlink = "<span class=\"history-deleted\">$revlink</span>";
184 $content = "$difflink $revlink $userlink $comment";
186 $tags = $this->getTags();
188 list( $tagSummary, $classes ) = ChangeTags
::formatSummaryRow(
191 $this->list->getContext()
193 $content .= " $tagSummary";
194 $attribs['class'] = implode( ' ', $classes );
196 return Xml
::tags( 'li', $attribs, $content );
200 * @return string Comma-separated list of tags
202 public function getTags() {
203 return $this->row
->ts_tags
;
206 public function getApiData( ApiResult
$result ) {
207 $rev = $this->revision
;
208 $user = $this->list->getUser();
210 'id' => $rev->getId(),
211 'timestamp' => wfTimestamp( TS_ISO_8601
, $rev->getTimestamp() ),
212 'userhidden' => (bool)$rev->isDeleted( RevisionRecord
::DELETED_USER
),
213 'commenthidden' => (bool)$rev->isDeleted( RevisionRecord
::DELETED_COMMENT
),
214 'texthidden' => (bool)$rev->isDeleted( RevisionRecord
::DELETED_TEXT
),
216 if ( $rev->userCan( RevisionRecord
::DELETED_USER
, $user ) ) {
218 'userid' => $rev->getUser( RevisionRecord
::FOR_THIS_USER
),
219 'user' => $rev->getUserText( RevisionRecord
::FOR_THIS_USER
),
222 if ( $rev->userCan( RevisionRecord
::DELETED_COMMENT
, $user ) ) {
224 'comment' => $rev->getComment( RevisionRecord
::FOR_THIS_USER
),