2014-08-07 20:43:55 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup RevisionDelete
|
|
|
|
|
*/
|
|
|
|
|
|
2020-05-01 18:03:43 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-09-12 19:40:57 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2019-07-21 13:18:14 +00:00
|
|
|
|
2014-08-07 20:43:55 +00:00
|
|
|
/**
|
|
|
|
|
* Item class for a live revision table row
|
2019-08-31 16:14:38 +00:00
|
|
|
*
|
|
|
|
|
* @property RevDelRevisionList $list
|
2014-08-07 20:43:55 +00:00
|
|
|
*/
|
|
|
|
|
class RevDelRevisionItem extends RevDelItem {
|
2020-05-01 18:03:43 +00:00
|
|
|
/** @var RevisionRecord */
|
|
|
|
|
public $revisionRecord;
|
2014-08-07 20:43:55 +00:00
|
|
|
|
2019-10-09 07:36:26 +00:00
|
|
|
public function __construct( RevisionListBase $list, $row ) {
|
2014-08-07 20:43:55 +00:00
|
|
|
parent::__construct( $list, $row );
|
2020-05-01 18:03:43 +00:00
|
|
|
$this->revisionRecord = static::initRevisionRecord( $list, $row );
|
2018-06-08 20:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-02 23:55:07 +00:00
|
|
|
* Create RevisionRecord object from $row sourced from $list
|
2018-06-08 20:51:44 +00:00
|
|
|
*
|
|
|
|
|
* @param RevisionListBase $list
|
|
|
|
|
* @param mixed $row
|
2020-05-01 18:03:43 +00:00
|
|
|
* @return RevisionRecord
|
2018-06-08 20:51:44 +00:00
|
|
|
*/
|
2020-05-01 18:03:43 +00:00
|
|
|
protected static function initRevisionRecord( $list, $row ) {
|
|
|
|
|
return MediaWikiServices::getInstance()
|
|
|
|
|
->getRevisionFactory()
|
|
|
|
|
->newRevisionFromRow( $row );
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-30 21:47:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get the RevisionRecord for the item
|
|
|
|
|
*
|
|
|
|
|
* @return RevisionRecord
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function getRevisionRecord(): RevisionRecord {
|
2020-05-01 18:03:43 +00:00
|
|
|
return $this->revisionRecord;
|
2020-04-30 21:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-07 20:43:55 +00:00
|
|
|
public function getIdField() {
|
|
|
|
|
return 'rev_id';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTimestampField() {
|
|
|
|
|
return 'rev_timestamp';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAuthorIdField() {
|
|
|
|
|
return 'rev_user';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAuthorNameField() {
|
|
|
|
|
return 'rev_user_text';
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-12 17:12:29 +00:00
|
|
|
public function getAuthorActorField() {
|
|
|
|
|
return 'rev_actor';
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 20:43:55 +00:00
|
|
|
public function canView() {
|
2021-02-24 15:46:13 +00:00
|
|
|
return $this->getRevisionRecord()->userCan(
|
2020-03-11 01:41:49 +00:00
|
|
|
RevisionRecord::DELETED_RESTRICTED,
|
2021-02-24 15:46:13 +00:00
|
|
|
$this->list->getAuthority()
|
2019-07-21 13:18:14 +00:00
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function canViewContent() {
|
2021-02-24 15:46:13 +00:00
|
|
|
return $this->getRevisionRecord()->userCan(
|
2020-03-11 01:41:49 +00:00
|
|
|
RevisionRecord::DELETED_TEXT,
|
2021-02-24 15:46:13 +00:00
|
|
|
$this->list->getAuthority()
|
2019-07-21 13:18:14 +00:00
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBits() {
|
2020-04-30 21:47:26 +00:00
|
|
|
return $this->getRevisionRecord()->getVisibility();
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setBits( $bits ) {
|
2020-04-30 21:47:26 +00:00
|
|
|
$revRecord = $this->getRevisionRecord();
|
|
|
|
|
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2014-08-07 20:43:55 +00:00
|
|
|
// Update revision table
|
2014-08-08 13:55:19 +00:00
|
|
|
$dbw->update( 'revision',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'rev_deleted' => $bits ],
|
|
|
|
|
[
|
2020-04-30 21:47:26 +00:00
|
|
|
'rev_id' => $revRecord->getId(),
|
|
|
|
|
'rev_page' => $revRecord->getPageId(),
|
2015-05-22 23:39:05 +00:00
|
|
|
'rev_deleted' => $this->getBits() // cas
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-08-08 13:55:19 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
if ( !$dbw->affectedRows() ) {
|
|
|
|
|
// Concurrent fail!
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Update recentchanges table
|
2014-08-08 13:55:19 +00:00
|
|
|
$dbw->update( 'recentchanges',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-08-08 13:55:19 +00:00
|
|
|
'rc_deleted' => $bits,
|
2018-04-26 18:23:32 +00:00
|
|
|
'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2020-04-30 21:47:26 +00:00
|
|
|
'rc_this_oldid' => $revRecord->getId(), // condition
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-08-08 13:55:19 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isDeleted() {
|
2020-04-30 21:47:26 +00:00
|
|
|
return $this->getRevisionRecord()->isDeleted( RevisionRecord::DELETED_TEXT );
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isHideCurrentOp( $newBits ) {
|
2019-07-21 13:18:14 +00:00
|
|
|
return ( $newBits & RevisionRecord::DELETED_TEXT )
|
2014-08-08 13:55:19 +00:00
|
|
|
&& $this->list->getCurrent() == $this->getId();
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the HTML link to the revision text.
|
|
|
|
|
* Overridden by RevDelArchiveItem.
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getRevisionLink() {
|
2016-12-05 19:23:28 +00:00
|
|
|
$date = $this->list->getLanguage()->userTimeAndDate(
|
2020-04-30 21:47:26 +00:00
|
|
|
$this->getRevisionRecord()->getTimestamp(),
|
|
|
|
|
$this->list->getUser()
|
|
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
|
|
|
|
|
if ( $this->isDeleted() && !$this->canViewContent() ) {
|
2016-12-05 19:23:28 +00:00
|
|
|
return htmlspecialchars( $date );
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
2016-12-05 19:23:28 +00:00
|
|
|
return $this->getLinkRenderer()->makeKnownLink(
|
2021-05-13 20:46:06 +00:00
|
|
|
$this->list->getPage(),
|
2014-08-08 13:55:19 +00:00
|
|
|
$date,
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[
|
2020-04-30 21:47:26 +00:00
|
|
|
'oldid' => $this->getRevisionRecord()->getId(),
|
2014-08-08 13:55:19 +00:00
|
|
|
'unhide' => 1
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2014-08-08 13:55:19 +00:00
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the HTML link to the diff.
|
|
|
|
|
* Overridden by RevDelArchiveItem
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getDiffLink() {
|
|
|
|
|
if ( $this->isDeleted() && !$this->canViewContent() ) {
|
|
|
|
|
return $this->list->msg( 'diff' )->escaped();
|
|
|
|
|
} else {
|
2016-12-05 19:23:28 +00:00
|
|
|
return $this->getLinkRenderer()->makeKnownLink(
|
2021-05-13 20:46:06 +00:00
|
|
|
$this->list->getPage(),
|
2020-04-30 21:47:26 +00:00
|
|
|
$this->list->msg( 'diff' )->text(),
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'diff' => $this->getRevisionRecord()->getId(),
|
|
|
|
|
'oldid' => 'prev',
|
|
|
|
|
'unhide' => 1
|
|
|
|
|
]
|
|
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 19:17:47 +00:00
|
|
|
/**
|
|
|
|
|
* @return string A HTML <li> element representing this revision, showing
|
|
|
|
|
* change tags and everything
|
|
|
|
|
*/
|
2014-08-07 20:43:55 +00:00
|
|
|
public function getHTML() {
|
2020-04-30 21:47:26 +00:00
|
|
|
$revRecord = $this->getRevisionRecord();
|
|
|
|
|
|
2014-08-07 20:43:55 +00:00
|
|
|
$difflink = $this->list->msg( 'parentheses' )
|
|
|
|
|
->rawParams( $this->getDiffLink() )->escaped();
|
|
|
|
|
$revlink = $this->getRevisionLink();
|
2020-04-30 21:47:26 +00:00
|
|
|
$userlink = Linker::revUserLink( $revRecord );
|
|
|
|
|
$comment = Linker::revComment( $revRecord );
|
2014-08-07 20:43:55 +00:00
|
|
|
if ( $this->isDeleted() ) {
|
2021-04-13 06:27:39 +00:00
|
|
|
$class = Linker::getRevisionDeletedClass( $revRecord );
|
|
|
|
|
$revlink = "<span class=\"$class\">$revlink</span>";
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
2015-12-15 19:17:47 +00:00
|
|
|
$content = "$difflink $revlink $userlink $comment";
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs = [];
|
2015-12-15 19:17:47 +00:00
|
|
|
$tags = $this->getTags();
|
|
|
|
|
if ( $tags ) {
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
|
2016-01-29 13:03:41 +00:00
|
|
|
$tags,
|
|
|
|
|
'revisiondelete',
|
|
|
|
|
$this->list->getContext()
|
|
|
|
|
);
|
2015-12-15 19:17:47 +00:00
|
|
|
$content .= " $tagSummary";
|
|
|
|
|
$attribs['class'] = implode( ' ', $classes );
|
|
|
|
|
}
|
|
|
|
|
return Xml::tags( 'li', $attribs, $content );
|
|
|
|
|
}
|
2014-08-07 20:43:55 +00:00
|
|
|
|
2015-12-15 19:17:47 +00:00
|
|
|
/**
|
|
|
|
|
* @return string Comma-separated list of tags
|
|
|
|
|
*/
|
|
|
|
|
public function getTags() {
|
|
|
|
|
return $this->row->ts_tags;
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getApiData( ApiResult $result ) {
|
2020-04-30 21:47:26 +00:00
|
|
|
$revRecord = $this->getRevisionRecord();
|
2021-02-24 15:46:13 +00:00
|
|
|
$authority = $this->list->getAuthority();
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret = [
|
2020-04-30 21:47:26 +00:00
|
|
|
'id' => $revRecord->getId(),
|
|
|
|
|
'timestamp' => wfTimestamp( TS_ISO_8601, $revRecord->getTimestamp() ),
|
|
|
|
|
'userhidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_USER ),
|
|
|
|
|
'commenthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_COMMENT ),
|
|
|
|
|
'texthidden' => (bool)$revRecord->isDeleted( RevisionRecord::DELETED_TEXT ),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2021-02-24 15:46:13 +00:00
|
|
|
if ( $revRecord->userCan( RevisionRecord::DELETED_USER, $authority ) ) {
|
|
|
|
|
$revUser = $revRecord->getUser( RevisionRecord::FOR_THIS_USER, $authority );
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret += [
|
2020-04-30 21:47:26 +00:00
|
|
|
'userid' => $revUser ? $revUser->getId() : 0,
|
|
|
|
|
'user' => $revUser ? $revUser->getName() : '',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
2021-02-24 15:46:13 +00:00
|
|
|
if ( $revRecord->userCan( RevisionRecord::DELETED_COMMENT, $authority ) ) {
|
|
|
|
|
$revComment = $revRecord->getComment( RevisionRecord::FOR_THIS_USER, $authority );
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret += [
|
2020-04-30 21:47:26 +00:00
|
|
|
'comment' => $revComment ? $revComment->text : ''
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-08-07 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
2014-08-08 13:55:19 +00:00
|
|
|
}
|