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\MediaWikiServices
;
23 use MediaWiki\Storage\RevisionRecord
;
24 use Wikimedia\Rdbms\FakeResultWrapper
;
25 use Wikimedia\Rdbms\IDatabase
;
28 * List for revision table items
30 * This will check both the 'revision' table for live revisions and the
31 * 'archive' table for traditionally-deleted revisions that have an
34 * See RevDelRevisionItem and RevDelArchivedRevisionItem for items.
36 class RevDelRevisionList
extends RevDelList
{
40 public function getType() {
44 public static function getRelationType() {
48 public static function getRestriction() {
49 return 'deleterevision';
52 public static function getRevdelConstant() {
53 return RevisionRecord
::DELETED_TEXT
;
56 public static function suggestTarget( $target, array $ids ) {
57 $rev = Revision
::newFromId( $ids[0] );
58 return $rev ?
$rev->getTitle() : $target;
62 * @param IDatabase $db
65 public function doQuery( $db ) {
66 $ids = array_map( 'intval', $this->ids
);
67 $revQuery = Revision
::getQueryInfo( [ 'page', 'user' ] );
69 'tables' => $revQuery['tables'],
70 'fields' => $revQuery['fields'],
72 'rev_page' => $this->title
->getArticleID(),
76 'ORDER BY' => 'rev_id DESC',
77 'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
79 'join_conds' => $revQuery['joins'],
81 ChangeTags
::modifyDisplayQuery(
85 $queryInfo['join_conds'],
86 $queryInfo['options'],
95 $queryInfo['options'],
96 $queryInfo['join_conds']
98 if ( $live->numRows() >= count( $ids ) ) {
99 // All requested revisions are live, keeps things simple!
103 $arQuery = Revision
::getArchiveQueryInfo();
104 $archiveQueryInfo = [
105 'tables' => $arQuery['tables'],
106 'fields' => $arQuery['fields'],
110 'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
111 'join_conds' => $arQuery['joins'],
114 ChangeTags
::modifyDisplayQuery(
115 $archiveQueryInfo['tables'],
116 $archiveQueryInfo['fields'],
117 $archiveQueryInfo['conds'],
118 $archiveQueryInfo['join_conds'],
119 $archiveQueryInfo['options'],
123 // Check if any requested revisions are available fully deleted.
124 $archived = $db->select(
125 $archiveQueryInfo['tables'],
126 $archiveQueryInfo['fields'],
127 $archiveQueryInfo['conds'],
129 $archiveQueryInfo['options'],
130 $archiveQueryInfo['join_conds']
133 if ( $archived->numRows() == 0 ) {
135 } elseif ( $live->numRows() == 0 ) {
138 // Combine the two! Whee
140 foreach ( $live as $row ) {
141 $rows[$row->rev_id
] = $row;
143 foreach ( $archived as $row ) {
144 $rows[$row->ar_rev_id
] = $row;
147 return new FakeResultWrapper( array_values( $rows ) );
151 public function newItem( $row ) {
152 if ( isset( $row->rev_id
) ) {
153 return new RevDelRevisionItem( $this, $row );
154 } elseif ( isset( $row->ar_rev_id
) ) {
155 return new RevDelArchivedRevisionItem( $this, $row );
157 // This shouldn't happen. :)
158 throw new MWException( 'Invalid row type in RevDelRevisionList' );
162 public function getCurrent() {
163 if ( is_null( $this->currentRevId
) ) {
164 $dbw = wfGetDB( DB_MASTER
);
165 $this->currentRevId
= $dbw->selectField(
166 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
168 return $this->currentRevId
;
171 public function getSuppressBit() {
172 return RevisionRecord
::DELETED_RESTRICTED
;
175 public function doPreCommitUpdates() {
176 $this->title
->invalidateCache();
177 return Status
::newGood();
180 public function doPostCommitUpdates( array $visibilityChangeMap ) {
181 MediaWikiServices
::getInstance()->getHtmlCacheUpdater()->purge( $this->title
);
182 // Extensions that require referencing previous revisions may need this
183 Hooks
::run( 'ArticleRevisionVisibilitySet',
184 [ $this->title
, $this->ids
, $visibilityChangeMap ] );
185 return Status
::newGood();