MediaWiki  1.34.0
RevDelRevisionList.php
Go to the documentation of this file.
1 <?php
25 
37  public $currentRevId;
38 
39  public function getType() {
40  return 'revision';
41  }
42 
43  public static function getRelationType() {
44  return 'rev_id';
45  }
46 
47  public static function getRestriction() {
48  return 'deleterevision';
49  }
50 
51  public static function getRevdelConstant() {
52  return RevisionRecord::DELETED_TEXT;
53  }
54 
55  public static function suggestTarget( $target, array $ids ) {
56  $rev = Revision::newFromId( $ids[0] );
57  return $rev ? $rev->getTitle() : $target;
58  }
59 
64  public function doQuery( $db ) {
65  $ids = array_map( 'intval', $this->ids );
66  $revQuery = Revision::getQueryInfo( [ 'page', 'user' ] );
67  $queryInfo = [
68  'tables' => $revQuery['tables'],
69  'fields' => $revQuery['fields'],
70  'conds' => [
71  'rev_page' => $this->title->getArticleID(),
72  'rev_id' => $ids,
73  ],
74  'options' => [
75  'ORDER BY' => 'rev_id DESC',
76  'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
77  ],
78  'join_conds' => $revQuery['joins'],
79  ];
81  $queryInfo['tables'],
82  $queryInfo['fields'],
83  $queryInfo['conds'],
84  $queryInfo['join_conds'],
85  $queryInfo['options'],
86  ''
87  );
88 
89  $live = $db->select(
90  $queryInfo['tables'],
91  $queryInfo['fields'],
92  $queryInfo['conds'],
93  __METHOD__,
94  $queryInfo['options'],
95  $queryInfo['join_conds']
96  );
97  if ( $live->numRows() >= count( $ids ) ) {
98  // All requested revisions are live, keeps things simple!
99  return $live;
100  }
101 
102  $arQuery = Revision::getArchiveQueryInfo();
103  $archiveQueryInfo = [
104  'tables' => $arQuery['tables'],
105  'fields' => $arQuery['fields'],
106  'conds' => [
107  'ar_rev_id' => $ids,
108  ],
109  'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
110  'join_conds' => $arQuery['joins'],
111  ];
112 
114  $archiveQueryInfo['tables'],
115  $archiveQueryInfo['fields'],
116  $archiveQueryInfo['conds'],
117  $archiveQueryInfo['join_conds'],
118  $archiveQueryInfo['options'],
119  ''
120  );
121 
122  // Check if any requested revisions are available fully deleted.
123  $archived = $db->select(
124  $archiveQueryInfo['tables'],
125  $archiveQueryInfo['fields'],
126  $archiveQueryInfo['conds'],
127  __METHOD__,
128  $archiveQueryInfo['options'],
129  $archiveQueryInfo['join_conds']
130  );
131 
132  if ( $archived->numRows() == 0 ) {
133  return $live;
134  } elseif ( $live->numRows() == 0 ) {
135  return $archived;
136  } else {
137  // Combine the two! Whee
138  $rows = [];
139  foreach ( $live as $row ) {
140  $rows[$row->rev_id] = $row;
141  }
142  foreach ( $archived as $row ) {
143  $rows[$row->ar_rev_id] = $row;
144  }
145  krsort( $rows );
146  return new FakeResultWrapper( array_values( $rows ) );
147  }
148  }
149 
150  public function newItem( $row ) {
151  if ( isset( $row->rev_id ) ) {
152  return new RevDelRevisionItem( $this, $row );
153  } elseif ( isset( $row->ar_rev_id ) ) {
154  return new RevDelArchivedRevisionItem( $this, $row );
155  } else {
156  // This shouldn't happen. :)
157  throw new MWException( 'Invalid row type in RevDelRevisionList' );
158  }
159  }
160 
161  public function getCurrent() {
162  if ( is_null( $this->currentRevId ) ) {
163  $dbw = wfGetDB( DB_MASTER );
164  $this->currentRevId = $dbw->selectField(
165  'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
166  }
167  return $this->currentRevId;
168  }
169 
170  public function getSuppressBit() {
171  return RevisionRecord::DELETED_RESTRICTED;
172  }
173 
174  public function doPreCommitUpdates() {
175  $this->title->invalidateCache();
176  return Status::newGood();
177  }
178 
179  public function doPostCommitUpdates( array $visibilityChangeMap ) {
180  $this->title->purgeSquid();
181  // Extensions that require referencing previous revisions may need this
182  Hooks::run( 'ArticleRevisionVisibilitySet', [ $this->title, $this->ids, $visibilityChangeMap ] );
183  return Status::newGood();
184  }
185 }
RevDelRevisionList\doPreCommitUpdates
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
Definition: RevDelRevisionList.php:174
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:119
RevDelRevisionList\doPostCommitUpdates
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.
Definition: RevDelRevisionList.php:179
Revision\getArchiveQueryInfo
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
Definition: Revision.php:329
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:39
$revQuery
$revQuery
Definition: testCompression.php:51
RevDelRevisionList\$currentRevId
int $currentRevId
Definition: RevDelRevisionList.php:37
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:772
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:315
MWException
MediaWiki exception.
Definition: MWException.php:26
RevDelRevisionList\getCurrent
getCurrent()
Definition: RevDelRevisionList.php:161
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2575
RevDelRevisionList\getRelationType
static getRelationType()
Get the DB field name associated with the ID list.
Definition: RevDelRevisionList.php:43
RevDelRevisionList
List for revision table items.
Definition: RevDelRevisionList.php:35
RevDelList
Definition: RevDelList.php:37
DB_MASTER
const DB_MASTER
Definition: defines.php:26
RevDelRevisionList\getRevdelConstant
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.
Definition: RevDelRevisionList.php:51
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
RevisionListBase\$ids
array $ids
Definition: RevisionListBase.php:34
RevDelRevisionList\getSuppressBit
getSuppressBit()
Get the integer value of the flag used for suppression.
Definition: RevDelRevisionList.php:170
RevDelRevisionList\doQuery
doQuery( $db)
Definition: RevDelRevisionList.php:64
RevDelRevisionList\getRestriction
static getRestriction()
Get the user right required for this list type Override this function.
Definition: RevDelRevisionList.php:47
RevDelArchivedRevisionItem
Item class for a archive table row by ar_rev_id – actually used via RevDelRevisionList.
Definition: RevDelArchivedRevisionItem.php:26
RevDelRevisionItem
Definition: RevDelRevisionItem.php:29
RevDelRevisionList\newItem
newItem( $row)
Create an item object from a DB result row.
Definition: RevDelRevisionList.php:150
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
RevDelRevisionList\suggestTarget
static suggestTarget( $target, array $ids)
Suggest a target for the revision deletion Optionally override this function.
Definition: RevDelRevisionList.php:55