MediaWiki REL1_35
RevDelRevisionList.php
Go to the documentation of this file.
1<?php
22use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
27
38 use ProtectedHookAccessorTrait;
39
42
43 public function getType() {
44 return 'revision';
45 }
46
47 public static function getRelationType() {
48 return 'rev_id';
49 }
50
51 public static function getRestriction() {
52 return 'deleterevision';
53 }
54
55 public static function getRevdelConstant() {
56 return RevisionRecord::DELETED_TEXT;
57 }
58
59 public static function suggestTarget( $target, array $ids ) {
60 $revisionRecord = MediaWikiServices::getInstance()
61 ->getRevisionLookup()
62 ->getRevisionById( $ids[0] );
63
64 if ( $revisionRecord ) {
65 return Title::newFromLinkTarget( $revisionRecord->getPageAsLinkTarget() );
66 }
67 return $target;
68 }
69
74 public function doQuery( $db ) {
75 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
76 $ids = array_map( 'intval', $this->ids );
77 $revQuery = $revisionStore->getQueryInfo( [ 'page', 'user' ] );
78 $queryInfo = [
79 'tables' => $revQuery['tables'],
80 'fields' => $revQuery['fields'],
81 'conds' => [
82 'rev_page' => $this->title->getArticleID(),
83 'rev_id' => $ids,
84 ],
85 'options' => [
86 'ORDER BY' => 'rev_id DESC',
87 'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
88 ],
89 'join_conds' => $revQuery['joins'],
90 ];
92 $queryInfo['tables'],
93 $queryInfo['fields'],
94 $queryInfo['conds'],
95 $queryInfo['join_conds'],
96 $queryInfo['options'],
97 ''
98 );
99
100 $live = $db->select(
101 $queryInfo['tables'],
102 $queryInfo['fields'],
103 $queryInfo['conds'],
104 __METHOD__,
105 $queryInfo['options'],
106 $queryInfo['join_conds']
107 );
108 if ( $live->numRows() >= count( $ids ) ) {
109 // All requested revisions are live, keeps things simple!
110 return $live;
111 }
112
113 $arQuery = $revisionStore->getArchiveQueryInfo();
114 $archiveQueryInfo = [
115 'tables' => $arQuery['tables'],
116 'fields' => $arQuery['fields'],
117 'conds' => [
118 'ar_rev_id' => $ids,
119 ],
120 'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
121 'join_conds' => $arQuery['joins'],
122 ];
123
125 $archiveQueryInfo['tables'],
126 $archiveQueryInfo['fields'],
127 $archiveQueryInfo['conds'],
128 $archiveQueryInfo['join_conds'],
129 $archiveQueryInfo['options'],
130 ''
131 );
132
133 // Check if any requested revisions are available fully deleted.
134 $archived = $db->select(
135 $archiveQueryInfo['tables'],
136 $archiveQueryInfo['fields'],
137 $archiveQueryInfo['conds'],
138 __METHOD__,
139 $archiveQueryInfo['options'],
140 $archiveQueryInfo['join_conds']
141 );
142
143 if ( $archived->numRows() == 0 ) {
144 return $live;
145 } elseif ( $live->numRows() == 0 ) {
146 return $archived;
147 } else {
148 // Combine the two! Whee
149 $rows = [];
150 foreach ( $live as $row ) {
151 $rows[$row->rev_id] = $row;
152 }
153 foreach ( $archived as $row ) {
154 $rows[$row->ar_rev_id] = $row;
155 }
156 krsort( $rows );
157 return new FakeResultWrapper( array_values( $rows ) );
158 }
159 }
160
161 public function newItem( $row ) {
162 if ( isset( $row->rev_id ) ) {
163 return new RevDelRevisionItem( $this, $row );
164 } elseif ( isset( $row->ar_rev_id ) ) {
165 return new RevDelArchivedRevisionItem( $this, $row );
166 } else {
167 // This shouldn't happen. :)
168 throw new MWException( 'Invalid row type in RevDelRevisionList' );
169 }
170 }
171
172 public function getCurrent() {
173 if ( $this->currentRevId === null ) {
174 $dbw = wfGetDB( DB_MASTER );
175 $this->currentRevId = $dbw->selectField(
176 'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
177 }
178 return $this->currentRevId;
179 }
180
181 public function getSuppressBit() {
182 return RevisionRecord::DELETED_RESTRICTED;
183 }
184
185 public function doPreCommitUpdates() {
186 $this->title->invalidateCache();
187 return Status::newGood();
188 }
189
190 public function doPostCommitUpdates( array $visibilityChangeMap ) {
191 $hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater();
192 $hcu->purgeTitleUrls( $this->title, $hcu::PURGE_INTENT_TXROUND_REFLECTED );
193 // Extensions that require referencing previous revisions may need this
194 $this->getHookRunner()->onArticleRevisionVisibilitySet(
195 $this->title, $this->ids, $visibilityChangeMap );
196 MediaWikiServices::getInstance()
197 ->getMainWANObjectCache()
198 ->touchCheckKey( "RevDelRevisionList:page:{$this->title->getArticleID()}}" );
199
200 return Status::newGood();
201 }
202}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
MediaWiki exception.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
Item class for a archive table row by ar_rev_id – actually used via RevDelRevisionList.
List for revision table items.
getSuppressBit()
Get the integer value of the flag used for suppression.
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.
static getRelationType()
Get the DB field name associated with the ID list.
static suggestTarget( $target, array $ids)
Suggest a target for the revision deletion Optionally override this function.
static getRestriction()
Get the user right required for this list type Override this function.
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
getType()
Get the internal type name of this list.
newItem( $row)
Create an item object from a DB result row.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
const DB_MASTER
Definition defines.php:29