MediaWiki  master
RevDelRevisionList.php
Go to the documentation of this file.
1 <?php
26 
38  public $currentRevId;
39 
40  public function getType() {
41  return 'revision';
42  }
43 
44  public static function getRelationType() {
45  return 'rev_id';
46  }
47 
48  public static function getRestriction() {
49  return 'deleterevision';
50  }
51 
52  public static function getRevdelConstant() {
53  return RevisionRecord::DELETED_TEXT;
54  }
55 
56  public static function suggestTarget( $target, array $ids ) {
57  $rev = Revision::newFromId( $ids[0] );
58  return $rev ? $rev->getTitle() : $target;
59  }
60 
65  public function doQuery( $db ) {
66  $ids = array_map( 'intval', $this->ids );
67  $revQuery = Revision::getQueryInfo( [ 'page', 'user' ] );
68  $queryInfo = [
69  'tables' => $revQuery['tables'],
70  'fields' => $revQuery['fields'],
71  'conds' => [
72  'rev_page' => $this->title->getArticleID(),
73  'rev_id' => $ids,
74  ],
75  'options' => [
76  'ORDER BY' => 'rev_id DESC',
77  'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
78  ],
79  'join_conds' => $revQuery['joins'],
80  ];
82  $queryInfo['tables'],
83  $queryInfo['fields'],
84  $queryInfo['conds'],
85  $queryInfo['join_conds'],
86  $queryInfo['options'],
87  ''
88  );
89 
90  $live = $db->select(
91  $queryInfo['tables'],
92  $queryInfo['fields'],
93  $queryInfo['conds'],
94  __METHOD__,
95  $queryInfo['options'],
96  $queryInfo['join_conds']
97  );
98  if ( $live->numRows() >= count( $ids ) ) {
99  // All requested revisions are live, keeps things simple!
100  return $live;
101  }
102 
103  $arQuery = Revision::getArchiveQueryInfo();
104  $archiveQueryInfo = [
105  'tables' => $arQuery['tables'],
106  'fields' => $arQuery['fields'],
107  'conds' => [
108  'ar_rev_id' => $ids,
109  ],
110  'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
111  'join_conds' => $arQuery['joins'],
112  ];
113 
115  $archiveQueryInfo['tables'],
116  $archiveQueryInfo['fields'],
117  $archiveQueryInfo['conds'],
118  $archiveQueryInfo['join_conds'],
119  $archiveQueryInfo['options'],
120  ''
121  );
122 
123  // Check if any requested revisions are available fully deleted.
124  $archived = $db->select(
125  $archiveQueryInfo['tables'],
126  $archiveQueryInfo['fields'],
127  $archiveQueryInfo['conds'],
128  __METHOD__,
129  $archiveQueryInfo['options'],
130  $archiveQueryInfo['join_conds']
131  );
132 
133  if ( $archived->numRows() == 0 ) {
134  return $live;
135  } elseif ( $live->numRows() == 0 ) {
136  return $archived;
137  } else {
138  // Combine the two! Whee
139  $rows = [];
140  foreach ( $live as $row ) {
141  $rows[$row->rev_id] = $row;
142  }
143  foreach ( $archived as $row ) {
144  $rows[$row->ar_rev_id] = $row;
145  }
146  krsort( $rows );
147  return new FakeResultWrapper( array_values( $rows ) );
148  }
149  }
150 
151  public function newItem( $row ) {
152  if ( isset( $row->rev_id ) ) {
153  return new RevDelRevisionItem( $this, $row );
154  } elseif ( isset( $row->ar_rev_id ) ) {
155  return new RevDelArchivedRevisionItem( $this, $row );
156  } else {
157  // This shouldn't happen. :)
158  throw new MWException( 'Invalid row type in RevDelRevisionList' );
159  }
160  }
161 
162  public function getCurrent() {
163  if ( is_null( $this->currentRevId ) ) {
164  $dbw = wfGetDB( DB_MASTER );
165  $this->currentRevId = $dbw->selectField(
166  'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
167  }
168  return $this->currentRevId;
169  }
170 
171  public function getSuppressBit() {
172  return RevisionRecord::DELETED_RESTRICTED;
173  }
174 
175  public function doPreCommitUpdates() {
176  $this->title->invalidateCache();
177  return Status::newGood();
178  }
179 
180  public function doPostCommitUpdates( array $visibilityChangeMap ) {
181  $this->title->purgeSquid();
182  // Extensions that require referencing previous revisions may need this
183  Hooks::run( 'ArticleRevisionVisibilitySet', [ $this->title, $this->ids, $visibilityChangeMap ] );
184  MediaWikiServices::getInstance()
185  ->getMainWANObjectCache()
186  ->touchCheckKey( "RevDelRevisionList:page:{$this->title->getArticleID()}}" );
187  return Status::newGood();
188  }
189 }
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:776
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const DB_MASTER
Definition: defines.php:26
List for revision table items.
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
Item class for a archive table row by ar_rev_id – actually used via RevDelRevisionList.
static suggestTarget( $target, array $ids)
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
Definition: Revision.php:330
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object...
Definition: Revision.php:316
doPostCommitUpdates(array $visibilityChangeMap)
Overloads the relevant methods of the real ResultsWrapper so it doesn&#39;t go anywhere near an actual da...
$revQuery
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:120
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200