MediaWiki 1.41.2
RevDelRevisionList.php
Go to the documentation of this file.
1<?php
33
44
46 private $lbFactory;
47
49 private $hookRunner;
50
52 private $htmlCacheUpdater;
53
55 private $revisionStore;
56
59
69 public function __construct(
70 IContextSource $context,
72 array $ids,
73 LBFactory $lbFactory,
74 HookContainer $hookContainer,
75 HtmlCacheUpdater $htmlCacheUpdater,
76 RevisionStore $revisionStore
77 ) {
78 parent::__construct( $context, $page, $ids, $lbFactory );
79 $this->lbFactory = $lbFactory;
80 $this->hookRunner = new HookRunner( $hookContainer );
81 $this->htmlCacheUpdater = $htmlCacheUpdater;
82 $this->revisionStore = $revisionStore;
83 }
84
85 public function getType() {
86 return 'revision';
87 }
88
89 public static function getRelationType() {
90 return 'rev_id';
91 }
92
93 public static function getRestriction() {
94 return 'deleterevision';
95 }
96
97 public static function getRevdelConstant() {
98 return RevisionRecord::DELETED_TEXT;
99 }
100
101 public static function suggestTarget( $target, array $ids ) {
102 $revisionRecord = MediaWikiServices::getInstance()
103 ->getRevisionLookup()
104 ->getRevisionById( $ids[0] );
105
106 if ( $revisionRecord ) {
107 return Title::newFromLinkTarget( $revisionRecord->getPageAsLinkTarget() );
108 }
109 return $target;
110 }
111
116 public function doQuery( $db ) {
117 $ids = array_map( 'intval', $this->ids );
118 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )
119 ->joinComment()
120 ->joinUser()
121 ->joinPage()
122 ->where( [ 'rev_page' => $this->page->getId(), 'rev_id' => $ids ] )
123 ->orderBy( 'rev_id', \Wikimedia\Rdbms\SelectQueryBuilder::SORT_DESC )
124 // workaround for MySQL bug (T104313)
125 ->useIndex( [ 'revision' => 'PRIMARY' ] );
126
127 MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQueryBuilder( $queryBuilder, 'revision' );
128
129 $live = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
130 if ( $live->numRows() >= count( $ids ) ) {
131 // All requested revisions are live, keeps things simple!
132 return $live;
133 }
134
135 $queryBuilder = $this->revisionStore->newArchiveSelectQueryBuilder( $db )
136 ->joinComment()
137 ->where( [ 'ar_rev_id' => $ids ] )
138 ->orderBy( 'ar_rev_id', \Wikimedia\Rdbms\SelectQueryBuilder::SORT_DESC );
139
140 MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQueryBuilder( $queryBuilder, 'archive' );
141
142 // Check if any requested revisions are available fully deleted.
143 $archived = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
144
145 if ( $archived->numRows() == 0 ) {
146 return $live;
147 } elseif ( $live->numRows() == 0 ) {
148 return $archived;
149 } else {
150 // Combine the two! Whee
151 $rows = [];
152 foreach ( $live as $row ) {
153 $rows[$row->rev_id] = $row;
154 }
155 foreach ( $archived as $row ) {
156 $rows[$row->ar_rev_id] = $row;
157 }
158 krsort( $rows );
159 return new FakeResultWrapper( array_values( $rows ) );
160 }
161 }
162
163 public function newItem( $row ) {
164 if ( isset( $row->rev_id ) ) {
165 return new RevDelRevisionItem( $this, $row );
166 } elseif ( isset( $row->ar_rev_id ) ) {
167 return new RevDelArchivedRevisionItem( $this, $row );
168 } else {
169 // This shouldn't happen. :)
170 throw new InvalidArgumentException( 'Invalid row type in RevDelRevisionList' );
171 }
172 }
173
174 public function getCurrent() {
175 if ( $this->currentRevId === null ) {
176 $dbw = $this->lbFactory->getPrimaryDatabase();
177 $this->currentRevId = $dbw->newSelectQueryBuilder()
178 ->select( 'page_latest' )
179 ->from( 'page' )
180 ->where( [ 'page_namespace' => $this->page->getNamespace(), 'page_title' => $this->page->getDBkey() ] )
181 ->caller( __METHOD__ )->fetchField();
182 }
183 return $this->currentRevId;
184 }
185
186 public function doPreCommitUpdates() {
187 Title::newFromPageIdentity( $this->page )->invalidateCache();
188 return Status::newGood();
189 }
190
191 public function doPostCommitUpdates( array $visibilityChangeMap ) {
192 $this->htmlCacheUpdater->purgeTitleUrls(
193 $this->page,
194 HtmlCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
195 );
196 // Extensions that require referencing previous revisions may need this
197 $this->hookRunner->onArticleRevisionVisibilitySet(
198 Title::newFromPageIdentity( $this->page ),
199 $this->ids,
200 $visibilityChangeMap
201 );
202
203 return Status::newGood();
204 }
205}
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:58
Represents a title within MediaWiki.
Definition Title.php:76
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...