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
23 * List for revision table items
25 * This will check both the 'revision' table for live revisions and the
26 * 'archive' table for traditionally-deleted revisions that have an
29 * See RevDelRevisionItem and RevDelArchivedRevisionItem for items.
31 class RevDelRevisionList
extends RevDelList
{
35 public function getType() {
39 public static function getRelationType() {
43 public static function getRestriction() {
44 return 'deleterevision';
47 public static function getRevdelConstant() {
48 return Revision
::DELETED_TEXT
;
51 public static function suggestTarget( $target, array $ids ) {
52 $rev = Revision
::newFromId( $ids[0] );
53 return $rev ?
$rev->getTitle() : $target;
57 * @param IDatabase $db
60 public function doQuery( $db ) {
61 $ids = array_map( 'intval', $this->ids
);
63 'tables' => [ 'revision', 'user' ],
64 'fields' => array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
66 'rev_page' => $this->title
->getArticleID(),
69 'options' => [ 'ORDER BY' => 'rev_id DESC' ],
71 'page' => Revision
::pageJoinCond(),
72 'user' => Revision
::userJoinCond(),
75 ChangeTags
::modifyDisplayQuery(
79 $queryInfo['join_conds'],
80 $queryInfo['options'],
89 $queryInfo['options'],
90 $queryInfo['join_conds']
92 if ( $live->numRows() >= count( $ids ) ) {
93 // All requested revisions are live, keeps things simple!
98 'tables' => [ 'archive' ],
99 'fields' => Revision
::selectArchiveFields(),
103 'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
107 ChangeTags
::modifyDisplayQuery(
108 $archiveQueryInfo['tables'],
109 $archiveQueryInfo['fields'],
110 $archiveQueryInfo['conds'],
111 $archiveQueryInfo['join_conds'],
112 $archiveQueryInfo['options'],
116 // Check if any requested revisions are available fully deleted.
117 $archived = $db->select(
118 $archiveQueryInfo['tables'],
119 $archiveQueryInfo['fields'],
120 $archiveQueryInfo['conds'],
122 $archiveQueryInfo['options'],
123 $archiveQueryInfo['join_conds']
126 if ( $archived->numRows() == 0 ) {
128 } elseif ( $live->numRows() == 0 ) {
131 // Combine the two! Whee
133 foreach ( $live as $row ) {
134 $rows[$row->rev_id
] = $row;
136 foreach ( $archived as $row ) {
137 $rows[$row->ar_rev_id
] = $row;
140 return new FakeResultWrapper( array_values( $rows ) );
144 public function newItem( $row ) {
145 if ( isset( $row->rev_id
) ) {
146 return new RevDelRevisionItem( $this, $row );
147 } elseif ( isset( $row->ar_rev_id
) ) {
148 return new RevDelArchivedRevisionItem( $this, $row );
150 // This shouldn't happen. :)
151 throw new MWException( 'Invalid row type in RevDelRevisionList' );
155 public function getCurrent() {
156 if ( is_null( $this->currentRevId
) ) {
157 $dbw = wfGetDB( DB_MASTER
);
158 $this->currentRevId
= $dbw->selectField(
159 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
161 return $this->currentRevId
;
164 public function getSuppressBit() {
165 return Revision
::DELETED_RESTRICTED
;
168 public function doPreCommitUpdates() {
169 $this->title
->invalidateCache();
170 return Status
::newGood();
173 public function doPostCommitUpdates() {
174 $this->title
->purgeSquid();
175 // Extensions that require referencing previous revisions may need this
176 Hooks
::run( 'ArticleRevisionVisibilitySet', [ $this->title
, $this->ids
] );
177 return Status
::newGood();