MediaWiki master
RevDelRevisionList.php
Go to the documentation of this file.
1<?php
7
8namespace MediaWiki\RevisionDelete;
9
10use InvalidArgumentException;
11use MediaWiki\Cache\HTMLCacheUpdater;
12use MediaWiki\ChangeTags\ChangeTagsFormatter;
13use MediaWiki\Context\IContextSource;
14use MediaWiki\DomainEvent\DomainEventDispatcher;
15use MediaWiki\HookContainer\HookContainer;
16use MediaWiki\HookContainer\HookRunner;
17use MediaWiki\Logging\LogEntry;
18use MediaWiki\MediaWikiServices;
19use MediaWiki\Page\Event\PageHistoryVisibilityChangedEvent;
20use MediaWiki\Page\PageIdentity;
21use MediaWiki\Page\ProperPageIdentity;
22use MediaWiki\Revision\RevisionRecord;
23use MediaWiki\Revision\RevisionStore;
24use MediaWiki\Status\Status;
25use MediaWiki\Title\Title;
26use Wikimedia\Rdbms\FakeResultWrapper;
27use Wikimedia\Rdbms\IResultWrapper;
28use Wikimedia\Rdbms\LBFactory;
29
40
42 private $hookRunner;
43
46
47 public function __construct(
48 IContextSource $context,
50 array $ids,
51 private readonly LBFactory $lbFactory,
52 HookContainer $hookContainer,
53 private readonly HTMLCacheUpdater $htmlCacheUpdater,
54 private readonly RevisionStore $revisionStore,
55 private readonly DomainEventDispatcher $eventDispatcher,
56 private readonly ChangeTagsFormatter $changeTagsFormatter,
57 ) {
58 parent::__construct( $context, $page, $ids, $this->lbFactory );
59 $this->hookRunner = new HookRunner( $hookContainer );
60 }
61
63 public function getType() {
64 return 'revision';
65 }
66
68 public static function getRelationType() {
69 return 'rev_id';
70 }
71
73 public static function getRestriction() {
74 return 'deleterevision';
75 }
76
78 public static function getRevdelConstant() {
79 return RevisionRecord::DELETED_TEXT;
80 }
81
83 public static function suggestTarget( $target, array $ids ) {
84 $revisionRecord = MediaWikiServices::getInstance()
85 ->getRevisionLookup()
86 ->getRevisionById( $ids[0] );
87
88 if ( $revisionRecord ) {
89 return Title::newFromPageIdentity( $revisionRecord->getPage() );
90 }
91 return $target;
92 }
93
98 public function doQuery( $db ) {
99 $ids = array_map( intval( ... ), $this->ids );
100 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )
101 ->joinComment()
102 ->joinUser()
103 ->joinPage()
104 ->where( [ 'rev_page' => $this->page->getId(), 'rev_id' => $ids ] )
105 ->orderBy( 'rev_id', \Wikimedia\Rdbms\SelectQueryBuilder::SORT_DESC )
106 // workaround for MySQL bug (T104313)
107 ->useIndex( [ 'revision' => 'PRIMARY' ] );
108
109 MediaWikiServices::getInstance()->getChangeTagsStore()
110 ->addTagsToDisplayQuery( $queryBuilder, 'revision', $this->getAuthority() );
111
112 $live = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
113 if ( $live->numRows() >= count( $ids ) ) {
114 // All requested revisions are live, keeps things simple!
115 return $live;
116 }
117
118 $queryBuilder = $this->revisionStore->newArchiveSelectQueryBuilder( $db )
119 ->joinComment()
120 ->where( [ 'ar_rev_id' => $ids ] )
121 ->orderBy( 'ar_rev_id', \Wikimedia\Rdbms\SelectQueryBuilder::SORT_DESC );
122
123 MediaWikiServices::getInstance()->getChangeTagsStore()
124 ->addTagsToDisplayQuery( $queryBuilder, 'archive', $this->getAuthority() );
125
126 // Check if any requested revisions are available fully deleted.
127 $archived = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
128
129 if ( $archived->numRows() == 0 ) {
130 return $live;
131 } elseif ( $live->numRows() == 0 ) {
132 return $archived;
133 } else {
134 // Combine the two! Whee
135 $rows = [];
136 foreach ( $live as $row ) {
137 $rows[$row->rev_id] = $row;
138 }
139 foreach ( $archived as $row ) {
140 $rows[$row->ar_rev_id] = $row;
141 }
142 krsort( $rows );
143 return new FakeResultWrapper( array_values( $rows ) );
144 }
145 }
146
148 public function newItem( $row ) {
149 if ( isset( $row->rev_id ) ) {
150 return new RevDelRevisionItem( $this, $row, $this->changeTagsFormatter );
151 } elseif ( isset( $row->ar_rev_id ) ) {
152 return new RevDelArchivedRevisionItem( $this, $row, $this->lbFactory, $this->changeTagsFormatter );
153 } else {
154 // This shouldn't happen. :)
155 throw new InvalidArgumentException( 'Invalid row type in RevDelRevisionList' );
156 }
157 }
158
160 public function getCurrent() {
161 if ( $this->currentRevId === null ) {
162 $dbw = $this->lbFactory->getPrimaryDatabase();
163 $this->currentRevId = $dbw->newSelectQueryBuilder()
164 ->select( 'page_latest' )
165 ->from( 'page' )
166 ->where( [ 'page_namespace' => $this->page->getNamespace(), 'page_title' => $this->page->getDBkey() ] )
167 ->caller( __METHOD__ )->fetchField();
168 }
169 return $this->currentRevId;
170 }
171
179 protected function emitEvents(
180 array $bitPars,
181 array $visibilityChangeMap,
182 array $tags,
183 LogEntry $logEntry,
184 bool $suppressed
185 ) {
186 // Figure out which bits got set, and which got unset.
187 $bitsSet = RevisionDeleter::extractBitfield( $bitPars, 0 );
188 $bitsUnset = RevisionRecord::SUPPRESSED_ALL &
189 ( ~ RevisionDeleter::extractBitfield( $bitPars, RevisionRecord::SUPPRESSED_ALL ) );
190
191 $page = $this->getPage();
192 $performer = $this->getUser();
193
194 // Hack: make sure we have a *proper* PageIdentity
195 if ( !$page instanceof ProperPageIdentity ) {
196 if ( !$page instanceof Title ) {
197 $page = Title::newFromPageIdentity( $page );
198 }
199
200 $page = $page->toPageIdentity();
201 }
202
203 $flags = [
205 ];
206
207 $this->eventDispatcher->dispatch(
209 $page,
210 $performer,
211 $this->getCurrent(),
212 $bitsSet,
213 $bitsUnset,
214 $visibilityChangeMap,
215 $logEntry->getComment(),
216 $tags,
217 $flags,
218 $logEntry->getTimestamp()
219 ),
220 $this->lbFactory
221 );
222 }
223
225 public function doPreCommitUpdates() {
226 Title::newFromPageIdentity( $this->page )->invalidateCache();
227 return Status::newGood();
228 }
229
231 public function doPostCommitUpdates( array $visibilityChangeMap ) {
232 $this->htmlCacheUpdater->purgeTitleUrls(
233 $this->page,
234 HTMLCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
235 );
236 // Extensions that require referencing previous revisions may need this
237 $this->hookRunner->onArticleRevisionVisibilitySet(
238 Title::newFromPageIdentity( $this->page ),
239 $this->ids,
240 $visibilityChangeMap
241 );
242
243 return Status::newGood();
244 }
245}
246
248class_alias( RevDelRevisionList::class, 'RevDelRevisionList' );
Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles.
Formats change tags for display in HTML and use filter dropdown menus.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
static getInstance()
Returns the global default instance of the top level service locator.
Domain event representing a change to the visibility attributes of one of the page's revisions.
Item class for a archive table row by ar_rev_id – actually used via RevDelRevisionList.
emitEvents(array $bitPars, array $visibilityChangeMap, array $tags, LogEntry $logEntry, bool $suppressed)
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.1.22 int|null
newItem( $row)
Create an item object from a DB result row.RevisionItemBase
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.STUB Status
getType()
Get the internal type name of this list.Equal to the table name. Override this function....
__construct(IContextSource $context, PageIdentity $page, array $ids, private readonly LBFactory $lbFactory, HookContainer $hookContainer, private readonly HTMLCacheUpdater $htmlCacheUpdater, private readonly RevisionStore $revisionStore, private readonly DomainEventDispatcher $eventDispatcher, private readonly ChangeTagsFormatter $changeTagsFormatter,)
static suggestTarget( $target, array $ids)
Suggest a target for the revision deletion Optionally override this function.1.22 Title|null
static getRelationType()
Get the DB field name associated with the ID list.This used to populate the log_search table for find...
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.STUB Status
static getRestriction()
Get the user right required for this list type Override this function.1.22 string|null
static extractBitfield(array $bitPars, $oldfield)
Put together a rev_deleted bitfield.
Service for looking up page revisions.
Represents a title within MediaWiki.
Definition Title.php:69
Overloads the relevant methods of the real ResultWrapper so it doesn't go anywhere near an actual dat...
Interface for objects which can provide a MediaWiki context on request.
Service for sending domain events to registered listeners.
An individual log entry.
Definition LogEntry.php:24
getTimestamp()
Get the timestamp when the action was executed.
getComment()
Get the user provided comment.
Interface for objects (potentially) representing an editable wiki page.
Interface for a page that is (or could be, or used to be) an editable wiki page.