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 Wikimedia\Rdbms\FakeResultWrapper
;
23 use Wikimedia\Rdbms\IDatabase
;
26 * List for revision table items
28 * This will check both the 'revision' table for live revisions and the
29 * 'archive' table for traditionally-deleted revisions that have an
32 * See RevDelRevisionItem and RevDelArchivedRevisionItem for items.
34 class RevDelRevisionList
extends RevDelList
{
38 public function getType() {
42 public static function getRelationType() {
46 public static function getRestriction() {
47 return 'deleterevision';
50 public static function getRevdelConstant() {
51 return Revision
::DELETED_TEXT
;
54 public static function suggestTarget( $target, array $ids ) {
55 $rev = Revision
::newFromId( $ids[0] );
56 return $rev ?
$rev->getTitle() : $target;
60 * @param IDatabase $db
63 public function doQuery( $db ) {
64 $ids = array_map( 'intval', $this->ids
);
66 'tables' => [ 'revision', 'page', 'user' ],
67 'fields' => array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
69 'rev_page' => $this->title
->getArticleID(),
73 'ORDER BY' => 'rev_id DESC',
74 'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
77 'page' => Revision
::pageJoinCond(),
78 'user' => Revision
::userJoinCond(),
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 $archiveQueryInfo = [
104 'tables' => [ 'archive' ],
105 'fields' => Revision
::selectArchiveFields(),
109 'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
113 ChangeTags
::modifyDisplayQuery(
114 $archiveQueryInfo['tables'],
115 $archiveQueryInfo['fields'],
116 $archiveQueryInfo['conds'],
117 $archiveQueryInfo['join_conds'],
118 $archiveQueryInfo['options'],
122 // Check if any requested revisions are available fully deleted.
123 $archived = $db->select(
124 $archiveQueryInfo['tables'],
125 $archiveQueryInfo['fields'],
126 $archiveQueryInfo['conds'],
128 $archiveQueryInfo['options'],
129 $archiveQueryInfo['join_conds']
132 if ( $archived->numRows() == 0 ) {
134 } elseif ( $live->numRows() == 0 ) {
137 // Combine the two! Whee
139 foreach ( $live as $row ) {
140 $rows[$row->rev_id
] = $row;
142 foreach ( $archived as $row ) {
143 $rows[$row->ar_rev_id
] = $row;
146 return new FakeResultWrapper( array_values( $rows ) );
150 public function newItem( $row ) {
151 if ( isset( $row->rev_id
) ) {
152 return new RevDelRevisionItem( $this, $row );
153 } elseif ( isset( $row->ar_rev_id
) ) {
154 return new RevDelArchivedRevisionItem( $this, $row );
156 // This shouldn't happen. :)
157 throw new MWException( 'Invalid row type in RevDelRevisionList' );
161 public function getCurrent() {
162 if ( is_null( $this->currentRevId
) ) {
163 $dbw = wfGetDB( DB_MASTER
);
164 $this->currentRevId
= $dbw->selectField(
165 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
167 return $this->currentRevId
;
170 public function getSuppressBit() {
171 return Revision
::DELETED_RESTRICTED
;
174 public function doPreCommitUpdates() {
175 $this->title
->invalidateCache();
176 return Status
::newGood();
179 public function doPostCommitUpdates( array $visibilityChangeMap ) {
180 $this->title
->purgeSquid();
181 // Extensions that require referencing previous revisions may need this
182 Hooks
::run( 'ArticleRevisionVisibilitySet', [ $this->title
, $this->ids
, $visibilityChangeMap ] );
183 return Status
::newGood();