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
|
|
|
|
|
*/
|
|
|
|
|
|
2017-02-19 05:03:13 +00:00
|
|
|
use Wikimedia\Rdbms\FakeResultWrapper;
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2017-02-19 05:03:13 +00:00
|
|
|
|
2014-08-07 20:43:55 +00:00
|
|
|
/**
|
|
|
|
|
* List for revision table items
|
|
|
|
|
*
|
|
|
|
|
* This will check both the 'revision' table for live revisions and the
|
|
|
|
|
* 'archive' table for traditionally-deleted revisions that have an
|
|
|
|
|
* ar_rev_id saved.
|
|
|
|
|
*
|
|
|
|
|
* See RevDelRevisionItem and RevDelArchivedRevisionItem for items.
|
|
|
|
|
*/
|
|
|
|
|
class RevDelRevisionList extends RevDelList {
|
|
|
|
|
/** @var int */
|
2014-08-11 20:58:31 +00:00
|
|
|
public $currentRevId;
|
2014-08-07 20:43:55 +00:00
|
|
|
|
|
|
|
|
public function getType() {
|
|
|
|
|
return 'revision';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getRelationType() {
|
|
|
|
|
return 'rev_id';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getRestriction() {
|
|
|
|
|
return 'deleterevision';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getRevdelConstant() {
|
|
|
|
|
return Revision::DELETED_TEXT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function suggestTarget( $target, array $ids ) {
|
|
|
|
|
$rev = Revision::newFromId( $ids[0] );
|
|
|
|
|
return $rev ? $rev->getTitle() : $target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-12-09 09:05:22 +00:00
|
|
|
* @param IDatabase $db
|
2014-08-07 20:43:55 +00:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function doQuery( $db ) {
|
|
|
|
|
$ids = array_map( 'intval', $this->ids );
|
2017-10-06 17:03:55 +00:00
|
|
|
$revQuery = Revision::getQueryInfo( [ 'page', 'user' ] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$queryInfo = [
|
2017-10-06 17:03:55 +00:00
|
|
|
'tables' => $revQuery['tables'],
|
|
|
|
|
'fields' => $revQuery['fields'],
|
2016-02-17 09:09:32 +00:00
|
|
|
'conds' => [
|
2014-08-07 20:43:55 +00:00
|
|
|
'rev_page' => $this->title->getArticleID(),
|
|
|
|
|
'rev_id' => $ids,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
Force primary index for RevDelRevisionList query
To work around an optimizer bug in MySQL where the
index on (rev_page, rev_id) is picked which mysteriously
leads to very slow execution times and timeouts.
In theory, the index being forced here is (rev_id),
which is fine for this query. In WMF production,
it can also be (rev_id, rev_user) (still fine), or
(rev_page, rev_id) (the index we're trying to avoid).
Mysteriously, the optimizer bug doesn't happen if
(rev_page, rev_id) is the primary key, so this still
behaves OK.
Bug: T104313
Change-Id: I15c68ba29309dca8dea274f19389d139a82784aa
2016-04-11 18:08:10 +00:00
|
|
|
'options' => [
|
|
|
|
|
'ORDER BY' => 'rev_id DESC',
|
|
|
|
|
'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
|
|
|
|
|
],
|
2017-10-06 17:03:55 +00:00
|
|
|
'join_conds' => $revQuery['joins'],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-12-15 19:17:47 +00:00
|
|
|
ChangeTags::modifyDisplayQuery(
|
|
|
|
|
$queryInfo['tables'],
|
|
|
|
|
$queryInfo['fields'],
|
|
|
|
|
$queryInfo['conds'],
|
|
|
|
|
$queryInfo['join_conds'],
|
|
|
|
|
$queryInfo['options'],
|
|
|
|
|
''
|
2014-08-07 20:43:55 +00:00
|
|
|
);
|
|
|
|
|
|
2015-12-15 19:17:47 +00:00
|
|
|
$live = $db->select(
|
|
|
|
|
$queryInfo['tables'],
|
|
|
|
|
$queryInfo['fields'],
|
|
|
|
|
$queryInfo['conds'],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
$queryInfo['options'],
|
|
|
|
|
$queryInfo['join_conds']
|
|
|
|
|
);
|
2014-08-07 20:43:55 +00:00
|
|
|
if ( $live->numRows() >= count( $ids ) ) {
|
|
|
|
|
// All requested revisions are live, keeps things simple!
|
|
|
|
|
return $live;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-06 17:03:55 +00:00
|
|
|
$arQuery = Revision::getArchiveQueryInfo();
|
2016-05-19 21:10:35 +00:00
|
|
|
$archiveQueryInfo = [
|
2017-10-06 17:03:55 +00:00
|
|
|
'tables' => $arQuery['tables'],
|
|
|
|
|
'fields' => $arQuery['fields'],
|
2016-05-19 21:10:35 +00:00
|
|
|
'conds' => [
|
|
|
|
|
'ar_rev_id' => $ids,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-05-19 21:10:35 +00:00
|
|
|
'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
|
2017-10-06 17:03:55 +00:00
|
|
|
'join_conds' => $arQuery['joins'],
|
2016-05-19 21:10:35 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
ChangeTags::modifyDisplayQuery(
|
|
|
|
|
$archiveQueryInfo['tables'],
|
|
|
|
|
$archiveQueryInfo['fields'],
|
|
|
|
|
$archiveQueryInfo['conds'],
|
|
|
|
|
$archiveQueryInfo['join_conds'],
|
|
|
|
|
$archiveQueryInfo['options'],
|
|
|
|
|
''
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Check if any requested revisions are available fully deleted.
|
|
|
|
|
$archived = $db->select(
|
|
|
|
|
$archiveQueryInfo['tables'],
|
|
|
|
|
$archiveQueryInfo['fields'],
|
|
|
|
|
$archiveQueryInfo['conds'],
|
2014-08-07 20:43:55 +00:00
|
|
|
__METHOD__,
|
2016-05-19 21:10:35 +00:00
|
|
|
$archiveQueryInfo['options'],
|
|
|
|
|
$archiveQueryInfo['join_conds']
|
2014-08-07 20:43:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( $archived->numRows() == 0 ) {
|
|
|
|
|
return $live;
|
|
|
|
|
} elseif ( $live->numRows() == 0 ) {
|
|
|
|
|
return $archived;
|
|
|
|
|
} else {
|
|
|
|
|
// Combine the two! Whee
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows = [];
|
2014-08-07 20:43:55 +00:00
|
|
|
foreach ( $live as $row ) {
|
|
|
|
|
$rows[$row->rev_id] = $row;
|
|
|
|
|
}
|
|
|
|
|
foreach ( $archived as $row ) {
|
|
|
|
|
$rows[$row->ar_rev_id] = $row;
|
|
|
|
|
}
|
|
|
|
|
krsort( $rows );
|
|
|
|
|
return new FakeResultWrapper( array_values( $rows ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function newItem( $row ) {
|
|
|
|
|
if ( isset( $row->rev_id ) ) {
|
|
|
|
|
return new RevDelRevisionItem( $this, $row );
|
|
|
|
|
} elseif ( isset( $row->ar_rev_id ) ) {
|
|
|
|
|
return new RevDelArchivedRevisionItem( $this, $row );
|
|
|
|
|
} else {
|
|
|
|
|
// This shouldn't happen. :)
|
|
|
|
|
throw new MWException( 'Invalid row type in RevDelRevisionList' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCurrent() {
|
|
|
|
|
if ( is_null( $this->currentRevId ) ) {
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
$this->currentRevId = $dbw->selectField(
|
|
|
|
|
'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
return $this->currentRevId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSuppressBit() {
|
|
|
|
|
return Revision::DELETED_RESTRICTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doPreCommitUpdates() {
|
|
|
|
|
$this->title->invalidateCache();
|
|
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-10 20:07:34 +00:00
|
|
|
public function doPostCommitUpdates( array $visibilityChangeMap ) {
|
2014-08-07 20:43:55 +00:00
|
|
|
$this->title->purgeSquid();
|
|
|
|
|
// Extensions that require referencing previous revisions may need this
|
2016-06-10 20:07:34 +00:00
|
|
|
Hooks::run( 'ArticleRevisionVisibilitySet', [ $this->title, $this->ids, $visibilityChangeMap ] );
|
2014-08-07 20:43:55 +00:00
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
}
|