PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / revisiondelete / RevDelRevisionList.php
blobebce50411a8d7ea1f312a17d762e988cc198b7d1
1 <?php
2 /**
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
18 * @file
19 * @ingroup RevisionDelete
22 /**
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
27 * ar_rev_id saved.
29 * See RevDelRevisionItem and RevDelArchivedRevisionItem for items.
31 class RevDelRevisionList extends RevDelList {
32 /** @var int */
33 public $currentRevId;
35 public function getType() {
36 return 'revision';
39 public static function getRelationType() {
40 return 'rev_id';
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;
56 /**
57 * @param IDatabase $db
58 * @return mixed
60 public function doQuery( $db ) {
61 $ids = array_map( 'intval', $this->ids );
62 $queryInfo = array(
63 'tables' => array( 'revision', 'user' ),
64 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
65 'conds' => array(
66 'rev_page' => $this->title->getArticleID(),
67 'rev_id' => $ids,
69 'options' => array( 'ORDER BY' => 'rev_id DESC' ),
70 'join_conds' => array(
71 'page' => Revision::pageJoinCond(),
72 'user' => Revision::userJoinCond(),
75 ChangeTags::modifyDisplayQuery(
76 $queryInfo['tables'],
77 $queryInfo['fields'],
78 $queryInfo['conds'],
79 $queryInfo['join_conds'],
80 $queryInfo['options'],
84 $live = $db->select(
85 $queryInfo['tables'],
86 $queryInfo['fields'],
87 $queryInfo['conds'],
88 __METHOD__,
89 $queryInfo['options'],
90 $queryInfo['join_conds']
92 if ( $live->numRows() >= count( $ids ) ) {
93 // All requested revisions are live, keeps things simple!
94 return $live;
97 // Check if any requested revisions are available fully deleted.
98 $archived = $db->select( array( 'archive' ), Revision::selectArchiveFields(),
99 array(
100 'ar_rev_id' => $ids
102 __METHOD__,
103 array( 'ORDER BY' => 'ar_rev_id DESC' )
106 if ( $archived->numRows() == 0 ) {
107 return $live;
108 } elseif ( $live->numRows() == 0 ) {
109 return $archived;
110 } else {
111 // Combine the two! Whee
112 $rows = array();
113 foreach ( $live as $row ) {
114 $rows[$row->rev_id] = $row;
116 foreach ( $archived as $row ) {
117 $rows[$row->ar_rev_id] = $row;
119 krsort( $rows );
120 return new FakeResultWrapper( array_values( $rows ) );
124 public function newItem( $row ) {
125 if ( isset( $row->rev_id ) ) {
126 return new RevDelRevisionItem( $this, $row );
127 } elseif ( isset( $row->ar_rev_id ) ) {
128 return new RevDelArchivedRevisionItem( $this, $row );
129 } else {
130 // This shouldn't happen. :)
131 throw new MWException( 'Invalid row type in RevDelRevisionList' );
135 public function getCurrent() {
136 if ( is_null( $this->currentRevId ) ) {
137 $dbw = wfGetDB( DB_MASTER );
138 $this->currentRevId = $dbw->selectField(
139 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
141 return $this->currentRevId;
144 public function getSuppressBit() {
145 return Revision::DELETED_RESTRICTED;
148 public function doPreCommitUpdates() {
149 $this->title->invalidateCache();
150 return Status::newGood();
153 public function doPostCommitUpdates() {
154 $this->title->purgeSquid();
155 // Extensions that require referencing previous revisions may need this
156 Hooks::run( 'ArticleRevisionVisibilitySet', array( $this->title, $this->ids ) );
157 return Status::newGood();