MediaWiki master
RevDelRevisionList.php
Go to the documentation of this file.
1<?php
35
46
48 private $lbFactory;
49
51 private $hookRunner;
52
54 private $htmlCacheUpdater;
55
57 private $revisionStore;
58
61
71 public function __construct(
72 IContextSource $context,
74 array $ids,
75 LBFactory $lbFactory,
76 HookContainer $hookContainer,
77 HTMLCacheUpdater $htmlCacheUpdater,
78 RevisionStore $revisionStore
79 ) {
80 parent::__construct( $context, $page, $ids, $lbFactory );
81 $this->lbFactory = $lbFactory;
82 $this->hookRunner = new HookRunner( $hookContainer );
83 $this->htmlCacheUpdater = $htmlCacheUpdater;
84 $this->revisionStore = $revisionStore;
85 }
86
87 public function getType() {
88 return 'revision';
89 }
90
91 public static function getRelationType() {
92 return 'rev_id';
93 }
94
95 public static function getRestriction() {
96 return 'deleterevision';
97 }
98
99 public static function getRevdelConstant() {
100 return RevisionRecord::DELETED_TEXT;
101 }
102
103 public static function suggestTarget( $target, array $ids ) {
104 $revisionRecord = MediaWikiServices::getInstance()
105 ->getRevisionLookup()
106 ->getRevisionById( $ids[0] );
107
108 if ( $revisionRecord ) {
109 return Title::newFromLinkTarget( $revisionRecord->getPageAsLinkTarget() );
110 }
111 return $target;
112 }
113
118 public function doQuery( $db ) {
119 $ids = array_map( 'intval', $this->ids );
120 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )
121 ->joinComment()
122 ->joinUser()
123 ->joinPage()
124 ->where( [ 'rev_page' => $this->page->getId(), 'rev_id' => $ids ] )
125 ->orderBy( 'rev_id', \Wikimedia\Rdbms\SelectQueryBuilder::SORT_DESC )
126 // workaround for MySQL bug (T104313)
127 ->useIndex( [ 'revision' => 'PRIMARY' ] );
128
129 MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQueryBuilder( $queryBuilder, 'revision' );
130
131 $live = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
132 if ( $live->numRows() >= count( $ids ) ) {
133 // All requested revisions are live, keeps things simple!
134 return $live;
135 }
136
137 $queryBuilder = $this->revisionStore->newArchiveSelectQueryBuilder( $db )
138 ->joinComment()
139 ->where( [ 'ar_rev_id' => $ids ] )
140 ->orderBy( 'ar_rev_id', \Wikimedia\Rdbms\SelectQueryBuilder::SORT_DESC );
141
142 MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQueryBuilder( $queryBuilder, 'archive' );
143
144 // Check if any requested revisions are available fully deleted.
145 $archived = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
146
147 if ( $archived->numRows() == 0 ) {
148 return $live;
149 } elseif ( $live->numRows() == 0 ) {
150 return $archived;
151 } else {
152 // Combine the two! Whee
153 $rows = [];
154 foreach ( $live as $row ) {
155 $rows[$row->rev_id] = $row;
156 }
157 foreach ( $archived as $row ) {
158 $rows[$row->ar_rev_id] = $row;
159 }
160 krsort( $rows );
161 return new FakeResultWrapper( array_values( $rows ) );
162 }
163 }
164
165 public function newItem( $row ) {
166 if ( isset( $row->rev_id ) ) {
167 return new RevDelRevisionItem( $this, $row );
168 } elseif ( isset( $row->ar_rev_id ) ) {
169 return new RevDelArchivedRevisionItem( $this, $row, $this->lbFactory );
170 } else {
171 // This shouldn't happen. :)
172 throw new InvalidArgumentException( 'Invalid row type in RevDelRevisionList' );
173 }
174 }
175
176 public function getCurrent() {
177 if ( $this->currentRevId === null ) {
178 $dbw = $this->lbFactory->getPrimaryDatabase();
179 $this->currentRevId = $dbw->newSelectQueryBuilder()
180 ->select( 'page_latest' )
181 ->from( 'page' )
182 ->where( [ 'page_namespace' => $this->page->getNamespace(), 'page_title' => $this->page->getDBkey() ] )
183 ->caller( __METHOD__ )->fetchField();
184 }
185 return $this->currentRevId;
186 }
187
188 public function doPreCommitUpdates() {
189 Title::newFromPageIdentity( $this->page )->invalidateCache();
190 return Status::newGood();
191 }
192
193 public function doPostCommitUpdates( array $visibilityChangeMap ) {
194 $this->htmlCacheUpdater->purgeTitleUrls(
195 $this->page,
196 HTMLCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
197 );
198 // Extensions that require referencing previous revisions may need this
199 $this->hookRunner->onArticleRevisionVisibilitySet(
200 Title::newFromPageIdentity( $this->page ),
201 $this->ids,
202 $visibilityChangeMap
203 );
204
205 return Status::newGood();
206 }
207}
Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Service locator for MediaWiki core services.
Page revision base class.
Service for looking up page revisions.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Represents a title within MediaWiki.
Definition Title.php:78
Item class for a archive table row by ar_rev_id – actually used via RevDelRevisionList.
List for revision table items.
__construct(IContextSource $context, PageIdentity $page, array $ids, LBFactory $lbFactory, HookContainer $hookContainer, HTMLCacheUpdater $htmlCacheUpdater, RevisionStore $revisionStore)
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 ResultWrapper so it doesn't go anywhere near an actual dat...
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.
Result wrapper for grabbing data queried from an IDatabase object.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...