MediaWiki  1.28.0
RevisionList.php
Go to the documentation of this file.
1 <?php
26 abstract class RevisionListBase extends ContextSource implements Iterator {
28  public $title;
29 
31  protected $ids;
32 
34  protected $res;
35 
37  protected $current;
38 
45  $this->setContext( $context );
46  $this->title = $title;
47  }
48 
53  function filterByIds( array $ids ) {
54  $this->ids = $ids;
55  }
56 
62  public function getType() {
63  return null;
64  }
65 
69  protected function initCurrent() {
70  $row = $this->res->current();
71  if ( $row ) {
72  $this->current = $this->newItem( $row );
73  } else {
74  $this->current = false;
75  }
76  }
77 
82  public function reset() {
83  if ( !$this->res ) {
84  $this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
85  } else {
86  $this->res->rewind();
87  }
88  $this->initCurrent();
89  return $this->current;
90  }
91 
92  public function rewind() {
93  $this->reset();
94  }
95 
100  public function current() {
101  return $this->current;
102  }
103 
108  public function next() {
109  $this->res->next();
110  $this->initCurrent();
111  return $this->current;
112  }
113 
114  public function key() {
115  return $this->res ? $this->res->key(): 0;
116  }
117 
118  public function valid() {
119  return $this->res ? $this->res->valid() : false;
120  }
121 
126  public function length() {
127  if ( !$this->res ) {
128  return 0;
129  } else {
130  return $this->res->numRows();
131  }
132  }
133 
138  abstract public function doQuery( $db );
139 
144  abstract public function newItem( $row );
145 }
146 
150 abstract class RevisionItemBase {
152  protected $list;
153 
155  protected $row;
156 
161  public function __construct( $list, $row ) {
162  $this->list = $list;
163  $this->row = $row;
164  }
165 
171  public function getIdField() {
172  return null;
173  }
174 
180  public function getTimestampField() {
181  return false;
182  }
183 
189  public function getAuthorIdField() {
190  return false;
191  }
192 
198  public function getAuthorNameField() {
199  return false;
200  }
201 
206  public function getId() {
207  $field = $this->getIdField();
208  return $this->row->$field;
209  }
210 
215  public function formatDate() {
216  return $this->list->getLanguage()->userDate( $this->getTimestamp(),
217  $this->list->getUser() );
218  }
219 
224  public function formatTime() {
225  return $this->list->getLanguage()->userTime( $this->getTimestamp(),
226  $this->list->getUser() );
227  }
228 
233  public function getTimestamp() {
234  $field = $this->getTimestampField();
235  return wfTimestamp( TS_MW, $this->row->$field );
236  }
237 
242  public function getAuthorId() {
243  $field = $this->getAuthorIdField();
244  return intval( $this->row->$field );
245  }
246 
251  public function getAuthorName() {
252  $field = $this->getAuthorNameField();
253  return strval( $this->row->$field );
254  }
255 
259  abstract public function canView();
260 
264  abstract public function canViewContent();
265 
270  abstract public function getHTML();
271 }
272 
274  public function getType() {
275  return 'revision';
276  }
277 
282  public function doQuery( $db ) {
283  $conds = [ 'rev_page' => $this->title->getArticleID() ];
284  if ( $this->ids !== null ) {
285  $conds['rev_id'] = array_map( 'intval', $this->ids );
286  }
287  return $db->select(
288  [ 'revision', 'page', 'user' ],
290  $conds,
291  __METHOD__,
292  [ 'ORDER BY' => 'rev_id DESC' ],
293  [
294  'page' => Revision::pageJoinCond(),
295  'user' => Revision::userJoinCond() ]
296  );
297  }
298 
299  public function newItem( $row ) {
300  return new RevisionItem( $this, $row );
301  }
302 }
303 
309  protected $revision;
310 
312  protected $context;
313 
314  public function __construct( $list, $row ) {
315  parent::__construct( $list, $row );
316  $this->revision = new Revision( $row );
317  $this->context = $list->getContext();
318  }
319 
320  public function getIdField() {
321  return 'rev_id';
322  }
323 
324  public function getTimestampField() {
325  return 'rev_timestamp';
326  }
327 
328  public function getAuthorIdField() {
329  return 'rev_user';
330  }
331 
332  public function getAuthorNameField() {
333  return 'rev_user_text';
334  }
335 
336  public function canView() {
337  return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
338  }
339 
340  public function canViewContent() {
341  return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
342  }
343 
344  public function isDeleted() {
345  return $this->revision->isDeleted( Revision::DELETED_TEXT );
346  }
347 
355  protected function getRevisionLink() {
356  $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
357  $this->revision->getTimestamp(), $this->list->getUser() ) );
358 
359  if ( $this->isDeleted() && !$this->canViewContent() ) {
360  return $date;
361  }
362  return Linker::linkKnown(
363  $this->list->title,
364  $date,
365  [],
366  [
367  'oldid' => $this->revision->getId(),
368  'unhide' => 1
369  ]
370  );
371  }
372 
380  protected function getDiffLink() {
381  if ( $this->isDeleted() && !$this->canViewContent() ) {
382  return $this->context->msg( 'diff' )->escaped();
383  } else {
384  return Linker::linkKnown(
385  $this->list->title,
386  $this->list->msg( 'diff' )->escaped(),
387  [],
388  [
389  'diff' => $this->revision->getId(),
390  'oldid' => 'prev',
391  'unhide' => 1
392  ]
393  );
394  }
395  }
396 
403  public function getHTML() {
404  $difflink = $this->context->msg( 'parentheses' )
405  ->rawParams( $this->getDiffLink() )->escaped();
406  $revlink = $this->getRevisionLink();
407  $userlink = Linker::revUserLink( $this->revision );
409  if ( $this->isDeleted() ) {
410  $revlink = "<span class=\"history-deleted\">$revlink</span>";
411  }
412  return "<li>$difflink $revlink $userlink $comment</li>";
413  }
414 }
setContext(IContextSource $context)
Set the IContextSource object.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
Interface for objects which can provide a MediaWiki context on request.
static revComment(Revision $rev, $local=false, $isPublic=false)
Wrap and format the given revision's comment block, if the current user is allowed to view it...
Definition: Linker.php:1550
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
getTimestamp()
Get the timestamp in MW 14-char form.
the array() calling protocol came about after MediaWiki 1.4rc1.
getAuthorNameField()
Get the DB field name storing user names.
RevisionListBase $list
The parent.
getType()
Get the internal type name of this list.
getTimestampField()
Get the DB field name storing timestamps.
initCurrent()
Initialise the current iteration pointer.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
ResultWrapper bool $res
newItem($row)
Create an item object from a DB result row.
bool object $current
reset()
Start iteration.
$comment
current()
Get the current list item, or false if we are at the end.
getRevisionLink()
Get the HTML link to the revision text.
__construct(IContextSource $context, Title $title)
Construct a revision list for a given title.
title
IContextSource $context
canViewContent()
Returns true if the current user can view the item text/file.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor'$rcid is used in generating this variable which contains information about the new revision
Definition: hooks.txt:1156
List for revision table items for a single page.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getId()
Get the ID, as it would appear in the ids URL parameter.
RequestContext $context
$row
The database result row.
__construct($list, $row)
getDiffLink()
Get the HTML link to the diff.
getContext()
Get the base IContextSource object.
getIdField()
Get the DB field name associated with the ID list.
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:442
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: defines.php:11
const DELETED_RESTRICTED
Definition: Revision.php:88
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
static revUserLink($rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1119
const DELETED_TEXT
Definition: Revision.php:85
canView()
Returns true if the current user can view the item.
next()
Move the iteration pointer to the next list item, and return it.
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:433
getHTML()
Get the HTML of the list item.
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
getAuthorIdField()
Get the DB field name storing user ids.
Item class for a live revision table row.
__construct($list, $row)
filterByIds(array $ids)
Select items only where the ID is any of the specified values.
formatTime()
Get the time, formatted in user's language.
getAuthorName()
Get the author user name.
Abstract base class for revision items.
const DB_REPLICA
Definition: defines.php:22
length()
Get the number of items in the list.
getAuthorId()
Get the author user ID.
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
doQuery($db)
Do the DB query to iterate through the objects.
formatDate()
Get the date, formatted in user's language.
Revision $revision