MediaWiki  master
RevDelRevisionList.php
Go to the documentation of this file.
1 <?php
31 
42 
44  private $lbFactory;
45 
47  private $hookRunner;
48 
51 
53  private $revisionStore;
54 
56  private $wanObjectCache;
57 
59  public $currentRevId;
60 
71  public function __construct(
73  PageIdentity $page,
74  array $ids,
76  HookContainer $hookContainer,
80  ) {
81  parent::__construct( $context, $page, $ids, $lbFactory );
82  $this->lbFactory = $lbFactory;
83  $this->hookRunner = new HookRunner( $hookContainer );
84  $this->htmlCacheUpdater = $htmlCacheUpdater;
85  $this->revisionStore = $revisionStore;
86  $this->wanObjectCache = $wanObjectCache;
87  }
88 
89  public function getType() {
90  return 'revision';
91  }
92 
93  public static function getRelationType() {
94  return 'rev_id';
95  }
96 
97  public static function getRestriction() {
98  return 'deleterevision';
99  }
100 
101  public static function getRevdelConstant() {
102  return RevisionRecord::DELETED_TEXT;
103  }
104 
105  public static function suggestTarget( $target, array $ids ) {
106  $revisionRecord = MediaWikiServices::getInstance()
107  ->getRevisionLookup()
108  ->getRevisionById( $ids[0] );
109 
110  if ( $revisionRecord ) {
111  return Title::newFromLinkTarget( $revisionRecord->getPageAsLinkTarget() );
112  }
113  return $target;
114  }
115 
120  public function doQuery( $db ) {
121  $ids = array_map( 'intval', $this->ids );
122  $revQuery = $this->revisionStore->getQueryInfo( [ 'page', 'user' ] );
123  $queryInfo = [
124  'tables' => $revQuery['tables'],
125  'fields' => $revQuery['fields'],
126  'conds' => [
127  'rev_page' => $this->title->getArticleID(),
128  'rev_id' => $ids,
129  ],
130  'options' => [
131  'ORDER BY' => 'rev_id DESC',
132  'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
133  ],
134  'join_conds' => $revQuery['joins'],
135  ];
137  $queryInfo['tables'],
138  $queryInfo['fields'],
139  $queryInfo['conds'],
140  $queryInfo['join_conds'],
141  $queryInfo['options'],
142  ''
143  );
144 
145  $live = $db->select(
146  $queryInfo['tables'],
147  $queryInfo['fields'],
148  $queryInfo['conds'],
149  __METHOD__,
150  $queryInfo['options'],
151  $queryInfo['join_conds']
152  );
153  if ( $live->numRows() >= count( $ids ) ) {
154  // All requested revisions are live, keeps things simple!
155  return $live;
156  }
157 
158  $arQuery = $this->revisionStore->getArchiveQueryInfo();
159  $archiveQueryInfo = [
160  'tables' => $arQuery['tables'],
161  'fields' => $arQuery['fields'],
162  'conds' => [
163  'ar_rev_id' => $ids,
164  ],
165  'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
166  'join_conds' => $arQuery['joins'],
167  ];
168 
170  $archiveQueryInfo['tables'],
171  $archiveQueryInfo['fields'],
172  $archiveQueryInfo['conds'],
173  $archiveQueryInfo['join_conds'],
174  $archiveQueryInfo['options'],
175  ''
176  );
177 
178  // Check if any requested revisions are available fully deleted.
179  $archived = $db->select(
180  $archiveQueryInfo['tables'],
181  $archiveQueryInfo['fields'],
182  $archiveQueryInfo['conds'],
183  __METHOD__,
184  $archiveQueryInfo['options'],
185  $archiveQueryInfo['join_conds']
186  );
187 
188  if ( $archived->numRows() == 0 ) {
189  return $live;
190  } elseif ( $live->numRows() == 0 ) {
191  return $archived;
192  } else {
193  // Combine the two! Whee
194  $rows = [];
195  foreach ( $live as $row ) {
196  $rows[$row->rev_id] = $row;
197  }
198  foreach ( $archived as $row ) {
199  $rows[$row->ar_rev_id] = $row;
200  }
201  krsort( $rows );
202  return new FakeResultWrapper( array_values( $rows ) );
203  }
204  }
205 
206  public function newItem( $row ) {
207  if ( isset( $row->rev_id ) ) {
208  return new RevDelRevisionItem( $this, $row );
209  } elseif ( isset( $row->ar_rev_id ) ) {
210  return new RevDelArchivedRevisionItem( $this, $row );
211  } else {
212  // This shouldn't happen. :)
213  throw new MWException( 'Invalid row type in RevDelRevisionList' );
214  }
215  }
216 
217  public function getCurrent() {
218  if ( $this->currentRevId === null ) {
219  $dbw = $this->lbFactory->getMainLB()->getConnectionRef( DB_PRIMARY );
220  $this->currentRevId = $dbw->selectField(
221  'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
222  }
223  return $this->currentRevId;
224  }
225 
226  public function getSuppressBit() {
227  return RevisionRecord::DELETED_RESTRICTED;
228  }
229 
230  public function doPreCommitUpdates() {
231  $this->title->invalidateCache();
232  return Status::newGood();
233  }
234 
235  public function doPostCommitUpdates( array $visibilityChangeMap ) {
236  $this->htmlCacheUpdater->purgeTitleUrls(
237  $this->title,
238  HtmlCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
239  );
240  // Extensions that require referencing previous revisions may need this
241  $this->hookRunner->onArticleRevisionVisibilitySet(
242  $this->title,
243  $this->ids,
244  $visibilityChangeMap
245  );
246  $this->wanObjectCache->touchCheckKey(
247  "RevDelRevisionList:page:{$this->title->getArticleID()}}"
248  );
249 
250  return Status::newGood();
251  }
252 }
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:38
RevDelRevisionList\doPreCommitUpdates
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
Definition: RevDelRevisionList.php:230
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
RevDelRevisionList\$wanObjectCache
WANObjectCache $wanObjectCache
Definition: RevDelRevisionList.php:56
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:180
MediaWiki\Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:88
RevDelRevisionList\doPostCommitUpdates
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.
Definition: RevDelRevisionList.php:235
Wikimedia\Rdbms\FakeResultWrapper
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Definition: FakeResultWrapper.php:11
RevDelRevisionList\getType
getType()
Get the internal type name of this list.
Definition: RevDelRevisionList.php:89
$revQuery
$revQuery
Definition: testCompression.php:56
RevDelRevisionList\$currentRevId
int $currentRevId
Definition: RevDelRevisionList.php:59
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:878
MWException
MediaWiki exception.
Definition: MWException.php:29
RevDelRevisionList\getCurrent
getCurrent()
Definition: RevDelRevisionList.php:217
RevDelRevisionList\__construct
__construct(IContextSource $context, PageIdentity $page, array $ids, LBFactory $lbFactory, HookContainer $hookContainer, HtmlCacheUpdater $htmlCacheUpdater, RevisionStore $revisionStore, WANObjectCache $wanObjectCache)
Definition: RevDelRevisionList.php:71
RevDelRevisionList\getRelationType
static getRelationType()
Get the DB field name associated with the ID list.
Definition: RevDelRevisionList.php:93
RevDelRevisionList
List for revision table items.
Definition: RevDelRevisionList.php:41
RevDelList
Definition: RevDelList.php:37
RevDelRevisionList\$htmlCacheUpdater
HtmlCacheUpdater $htmlCacheUpdater
Definition: RevDelRevisionList.php:50
RevDelRevisionList\getRevdelConstant
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.
Definition: RevDelRevisionList.php:101
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
RevDelRevisionList\$lbFactory
LBFactory $lbFactory
Definition: RevDelRevisionList.php:44
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:129
RevDelRevisionList\getSuppressBit
getSuppressBit()
Get the integer value of the flag used for suppression.
Definition: RevDelRevisionList.php:226
RevisionListBase\$ids
int[] null $ids
Definition: RevisionListBase.php:37
HtmlCacheUpdater
Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles.
Definition: HtmlCacheUpdater.php:32
RevDelRevisionList\doQuery
doQuery( $db)
Definition: RevDelRevisionList.php:120
RevDelRevisionList\getRestriction
static getRestriction()
Get the user right required for this list type Override this function.
Definition: RevDelRevisionList.php:97
RevDelArchivedRevisionItem
Item class for a archive table row by ar_rev_id – actually used via RevDelRevisionList.
Definition: RevDelArchivedRevisionItem.php:26
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:297
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:57
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:42
RevDelRevisionList\$hookRunner
HookRunner $hookRunner
Definition: RevDelRevisionList.php:47
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
RevDelRevisionItem
Definition: RevDelRevisionItem.php:30
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:558
RevDelRevisionList\newItem
newItem( $row)
Create an item object from a DB result row.
Definition: RevDelRevisionList.php:206
RevDelRevisionList\$revisionStore
RevisionStore $revisionStore
Definition: RevDelRevisionList.php:53
RevDelRevisionList\suggestTarget
static suggestTarget( $target, array $ids)
Suggest a target for the revision deletion Optionally override this function.
Definition: RevDelRevisionList.php:105