MediaWiki  1.28.0
RevDelRevisionList.php
Go to the documentation of this file.
1 <?php
33  public $currentRevId;
34 
35  public function getType() {
36  return 'revision';
37  }
38 
39  public static function getRelationType() {
40  return 'rev_id';
41  }
42 
43  public static function getRestriction() {
44  return 'deleterevision';
45  }
46 
47  public static function getRevdelConstant() {
49  }
50 
51  public static function suggestTarget( $target, array $ids ) {
52  $rev = Revision::newFromId( $ids[0] );
53  return $rev ? $rev->getTitle() : $target;
54  }
55 
60  public function doQuery( $db ) {
61  $ids = array_map( 'intval', $this->ids );
62  $queryInfo = [
63  'tables' => [ 'revision', 'page', 'user' ],
64  'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
65  'conds' => [
66  'rev_page' => $this->title->getArticleID(),
67  'rev_id' => $ids,
68  ],
69  'options' => [
70  'ORDER BY' => 'rev_id DESC',
71  'USE INDEX' => [ 'revision' => 'PRIMARY' ] // workaround for MySQL bug (T104313)
72  ],
73  'join_conds' => [
74  'page' => Revision::pageJoinCond(),
75  'user' => Revision::userJoinCond(),
76  ],
77  ];
79  $queryInfo['tables'],
80  $queryInfo['fields'],
81  $queryInfo['conds'],
82  $queryInfo['join_conds'],
83  $queryInfo['options'],
84  ''
85  );
86 
87  $live = $db->select(
88  $queryInfo['tables'],
89  $queryInfo['fields'],
90  $queryInfo['conds'],
91  __METHOD__,
92  $queryInfo['options'],
93  $queryInfo['join_conds']
94  );
95  if ( $live->numRows() >= count( $ids ) ) {
96  // All requested revisions are live, keeps things simple!
97  return $live;
98  }
99 
100  $archiveQueryInfo = [
101  'tables' => [ 'archive' ],
102  'fields' => Revision::selectArchiveFields(),
103  'conds' => [
104  'ar_rev_id' => $ids,
105  ],
106  'options' => [ 'ORDER BY' => 'ar_rev_id DESC' ],
107  'join_conds' => [],
108  ];
109 
111  $archiveQueryInfo['tables'],
112  $archiveQueryInfo['fields'],
113  $archiveQueryInfo['conds'],
114  $archiveQueryInfo['join_conds'],
115  $archiveQueryInfo['options'],
116  ''
117  );
118 
119  // Check if any requested revisions are available fully deleted.
120  $archived = $db->select(
121  $archiveQueryInfo['tables'],
122  $archiveQueryInfo['fields'],
123  $archiveQueryInfo['conds'],
124  __METHOD__,
125  $archiveQueryInfo['options'],
126  $archiveQueryInfo['join_conds']
127  );
128 
129  if ( $archived->numRows() == 0 ) {
130  return $live;
131  } elseif ( $live->numRows() == 0 ) {
132  return $archived;
133  } else {
134  // Combine the two! Whee
135  $rows = [];
136  foreach ( $live as $row ) {
137  $rows[$row->rev_id] = $row;
138  }
139  foreach ( $archived as $row ) {
140  $rows[$row->ar_rev_id] = $row;
141  }
142  krsort( $rows );
143  return new FakeResultWrapper( array_values( $rows ) );
144  }
145  }
146 
147  public function newItem( $row ) {
148  if ( isset( $row->rev_id ) ) {
149  return new RevDelRevisionItem( $this, $row );
150  } elseif ( isset( $row->ar_rev_id ) ) {
151  return new RevDelArchivedRevisionItem( $this, $row );
152  } else {
153  // This shouldn't happen. :)
154  throw new MWException( 'Invalid row type in RevDelRevisionList' );
155  }
156  }
157 
158  public function getCurrent() {
159  if ( is_null( $this->currentRevId ) ) {
160  $dbw = wfGetDB( DB_MASTER );
161  $this->currentRevId = $dbw->selectField(
162  'page', 'page_latest', $this->title->pageCond(), __METHOD__ );
163  }
164  return $this->currentRevId;
165  }
166 
167  public function getSuppressBit() {
169  }
170 
171  public function doPreCommitUpdates() {
172  $this->title->invalidateCache();
173  return Status::newGood();
174  }
175 
176  public function doPostCommitUpdates( array $visibilityChangeMap ) {
177  $this->title->purgeSquid();
178  // Extensions that require referencing previous revisions may need this
179  Hooks::run( 'ArticleRevisionVisibilitySet', [ $this->title, $this->ids, $visibilityChangeMap ] );
180  return Status::newGood();
181  }
182 }
Abstract base class for a list of deletable items.
Definition: RevDelList.php:28
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
the array() calling protocol came about after MediaWiki 1.4rc1.
static suggestTarget($target, array $ids)
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
Definition: Revision.php:473
title
const DB_MASTER
Definition: defines.php:23
List for revision table items.
Item class for a archive table row by ar_rev_id – actually used via RevDelRevisionList.
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:442
const DELETED_RESTRICTED
Definition: Revision.php:88
static newGood($value=null)
Factory function for good results.
Definition: StatusValue.php:76
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1721
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
const DELETED_TEXT
Definition: Revision.php:85
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
Definition: ChangeTags.php:629
static newFromId($id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:110
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:433
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Item class for a live revision table row.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
doPostCommitUpdates(array $visibilityChangeMap)
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:423
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:530