MediaWiki  1.30.0
RevisionList.php
Go to the documentation of this file.
1 <?php
26 
30 abstract class RevisionListBase extends ContextSource implements Iterator {
32  public $title;
33 
35  protected $ids;
36 
38  protected $res;
39 
41  protected $current;
42 
49  $this->setContext( $context );
50  $this->title = $title;
51  }
52 
57  function filterByIds( array $ids ) {
58  $this->ids = $ids;
59  }
60 
66  public function getType() {
67  return null;
68  }
69 
73  protected function initCurrent() {
74  $row = $this->res->current();
75  if ( $row ) {
76  $this->current = $this->newItem( $row );
77  } else {
78  $this->current = false;
79  }
80  }
81 
86  public function reset() {
87  if ( !$this->res ) {
88  $this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
89  } else {
90  $this->res->rewind();
91  }
92  $this->initCurrent();
93  return $this->current;
94  }
95 
96  public function rewind() {
97  $this->reset();
98  }
99 
104  public function current() {
105  return $this->current;
106  }
107 
112  public function next() {
113  $this->res->next();
114  $this->initCurrent();
115  return $this->current;
116  }
117 
118  public function key() {
119  return $this->res ? $this->res->key() : 0;
120  }
121 
122  public function valid() {
123  return $this->res ? $this->res->valid() : false;
124  }
125 
130  public function length() {
131  if ( !$this->res ) {
132  return 0;
133  } else {
134  return $this->res->numRows();
135  }
136  }
137 
142  abstract public function doQuery( $db );
143 
148  abstract public function newItem( $row );
149 }
150 
154 abstract class RevisionItemBase {
156  protected $list;
157 
159  protected $row;
160 
165  public function __construct( $list, $row ) {
166  $this->list = $list;
167  $this->row = $row;
168  }
169 
175  public function getIdField() {
176  return null;
177  }
178 
184  public function getTimestampField() {
185  return false;
186  }
187 
193  public function getAuthorIdField() {
194  return false;
195  }
196 
202  public function getAuthorNameField() {
203  return false;
204  }
205 
210  public function getId() {
211  $field = $this->getIdField();
212  return $this->row->$field;
213  }
214 
219  public function formatDate() {
220  return $this->list->getLanguage()->userDate( $this->getTimestamp(),
221  $this->list->getUser() );
222  }
223 
228  public function formatTime() {
229  return $this->list->getLanguage()->userTime( $this->getTimestamp(),
230  $this->list->getUser() );
231  }
232 
237  public function getTimestamp() {
238  $field = $this->getTimestampField();
239  return wfTimestamp( TS_MW, $this->row->$field );
240  }
241 
246  public function getAuthorId() {
247  $field = $this->getAuthorIdField();
248  return intval( $this->row->$field );
249  }
250 
255  public function getAuthorName() {
256  $field = $this->getAuthorNameField();
257  return strval( $this->row->$field );
258  }
259 
263  abstract public function canView();
264 
268  abstract public function canViewContent();
269 
274  abstract public function getHTML();
275 
280  protected function getLinkRenderer() {
281  return MediaWikiServices::getInstance()->getLinkRenderer();
282  }
283 }
284 
286  public function getType() {
287  return 'revision';
288  }
289 
294  public function doQuery( $db ) {
295  $conds = [ 'rev_page' => $this->title->getArticleID() ];
296  if ( $this->ids !== null ) {
297  $conds['rev_id'] = array_map( 'intval', $this->ids );
298  }
299  return $db->select(
300  [ 'revision', 'page', 'user' ],
302  $conds,
303  __METHOD__,
304  [ 'ORDER BY' => 'rev_id DESC' ],
305  [
306  'page' => Revision::pageJoinCond(),
307  'user' => Revision::userJoinCond() ]
308  );
309  }
310 
311  public function newItem( $row ) {
312  return new RevisionItem( $this, $row );
313  }
314 }
315 
321  protected $revision;
322 
324  protected $context;
325 
326  public function __construct( $list, $row ) {
327  parent::__construct( $list, $row );
328  $this->revision = new Revision( $row );
329  $this->context = $list->getContext();
330  }
331 
332  public function getIdField() {
333  return 'rev_id';
334  }
335 
336  public function getTimestampField() {
337  return 'rev_timestamp';
338  }
339 
340  public function getAuthorIdField() {
341  return 'rev_user';
342  }
343 
344  public function getAuthorNameField() {
345  return 'rev_user_text';
346  }
347 
348  public function canView() {
349  return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
350  }
351 
352  public function canViewContent() {
353  return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
354  }
355 
356  public function isDeleted() {
357  return $this->revision->isDeleted( Revision::DELETED_TEXT );
358  }
359 
367  protected function getRevisionLink() {
368  $date = $this->list->getLanguage()->userTimeAndDate(
369  $this->revision->getTimestamp(), $this->list->getUser() );
370 
371  if ( $this->isDeleted() && !$this->canViewContent() ) {
372  return htmlspecialchars( $date );
373  }
374  $linkRenderer = $this->getLinkRenderer();
375  return $linkRenderer->makeKnownLink(
376  $this->list->title,
377  $date,
378  [],
379  [
380  'oldid' => $this->revision->getId(),
381  'unhide' => 1
382  ]
383  );
384  }
385 
393  protected function getDiffLink() {
394  if ( $this->isDeleted() && !$this->canViewContent() ) {
395  return $this->context->msg( 'diff' )->escaped();
396  } else {
397  $linkRenderer = $this->getLinkRenderer();
398  return $linkRenderer->makeKnownLink(
399  $this->list->title,
400  $this->list->msg( 'diff' )->text(),
401  [],
402  [
403  'diff' => $this->revision->getId(),
404  'oldid' => 'prev',
405  'unhide' => 1
406  ]
407  );
408  }
409  }
410 
417  public function getHTML() {
418  $difflink = $this->context->msg( 'parentheses' )
419  ->rawParams( $this->getDiffLink() )->escaped();
420  $revlink = $this->getRevisionLink();
421  $userlink = Linker::revUserLink( $this->revision );
422  $comment = Linker::revComment( $this->revision );
423  if ( $this->isDeleted() ) {
424  $revlink = "<span class=\"history-deleted\">$revlink</span>";
425  }
426  return "<li>$difflink $revlink $userlink $comment</li>";
427  }
428 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:93
RevisionItemBase\getHTML
getHTML()
Get the HTML of the list item.
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
RevisionList\getType
getType()
Get the internal type name of this list.
Definition: RevisionList.php:286
Revision\pageJoinCond
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:441
RevisionListBase\filterByIds
filterByIds(array $ids)
Select items only where the ID is any of the specified values.
Definition: RevisionList.php:57
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1038
RevisionListBase
List for revision table items for a single page.
Definition: RevisionList.php:30
RevisionItemBase
Abstract base class for revision items.
Definition: RevisionList.php:154
RevisionItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevisionList.php:348
RevisionListBase\valid
valid()
Definition: RevisionList.php:122
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
RevisionItemBase\__construct
__construct( $list, $row)
Definition: RevisionList.php:165
RevisionListBase\length
length()
Get the number of items in the list.
Definition: RevisionList.php:130
RevisionItem\isDeleted
isDeleted()
Definition: RevisionList.php:356
$linkRenderer
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1965
RevisionItemBase\getAuthorId
getAuthorId()
Get the author user ID.
Definition: RevisionList.php:246
Wikimedia\Rdbms\ResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: ResultWrapper.php:24
RevisionList
Definition: RevisionList.php:285
RevisionItem\__construct
__construct( $list, $row)
Definition: RevisionList.php:326
RevisionItemBase\canView
canView()
Returns true if the current user can view the item.
php
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
RevisionItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevisionList.php:340
RevisionItemBase\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevisionList.php:202
RevisionItemBase\$list
RevisionListBase $list
The parent.
Definition: RevisionList.php:156
RevisionItemBase\formatDate
formatDate()
Get the date, formatted in user's language.
Definition: RevisionList.php:219
Revision
Definition: Revision.php:33
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
RevisionItemBase\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevisionList.php:184
RevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevisionList.php:352
RevisionList\doQuery
doQuery( $db)
Definition: RevisionList.php:294
RevisionListBase\next
next()
Move the iteration pointer to the next list item, and return it.
Definition: RevisionList.php:112
RevisionItemBase\getLinkRenderer
getLinkRenderer()
Returns an instance of LinkRenderer.
Definition: RevisionList.php:280
RevisionListBase\doQuery
doQuery( $db)
Do the DB query to iterate through the objects.
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
RevisionItemBase\formatTime
formatTime()
Get the time, formatted in user's language.
Definition: RevisionList.php:228
RevisionListBase\current
current()
Get the current list item, or false if we are at the end.
Definition: RevisionList.php:104
RevisionListBase\$title
Title $title
Definition: RevisionList.php:32
RevisionItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevisionList.php:344
RevisionItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevisionList.php:332
RevisionList\newItem
newItem( $row)
Create an item object from a DB result row.
Definition: RevisionList.php:311
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:33
RevisionItemBase\getAuthorName
getAuthorName()
Get the author user name.
Definition: RevisionList.php:255
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
list
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
RevisionListBase\reset
reset()
Start iteration.
Definition: RevisionList.php:86
RevisionItem\$revision
Revision $revision
Definition: RevisionList.php:321
RevisionListBase\newItem
newItem( $row)
Create an item object from a DB result row.
Linker\revComment
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:1470
RevisionItemBase\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevisionList.php:210
RevisionItemBase\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
RevisionListBase\$ids
array $ids
Definition: RevisionList.php:35
RevisionItemBase\$row
$row
The database result row.
Definition: RevisionList.php:159
RevisionItem
Item class for a live revision table row.
Definition: RevisionList.php:319
RevisionItemBase\getTimestamp
getTimestamp()
Get the timestamp in MW 14-char form.
Definition: RevisionList.php:237
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
RevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevisionList.php:367
Title
Represents a title within MediaWiki.
Definition: Title.php:39
RevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevisionList.php:393
RevisionListBase\$res
ResultWrapper bool $res
Definition: RevisionList.php:38
Revision\userJoinCond
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:431
RevisionItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevisionList.php:336
RevisionListBase\getType
getType()
Get the internal type name of this list.
Definition: RevisionList.php:66
RevisionListBase\initCurrent
initCurrent()
Initialise the current iteration pointer.
Definition: RevisionList.php:73
RevisionItem\$context
RequestContext $context
Definition: RevisionList.php:324
Revision\selectUserFields
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:544
RevisionItemBase\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevisionList.php:175
RevisionListBase\__construct
__construct(IContextSource $context, Title $title)
Construct a revision list for a given title.
Definition: RevisionList.php:48
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
Revision\selectFields
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:452
RevisionListBase\$current
bool Revision $current
Definition: RevisionList.php:41
RevisionListBase\rewind
rewind()
Definition: RevisionList.php:96
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:90
array
the array() calling protocol came about after MediaWiki 1.4rc1.
RevisionListBase\key
key()
Definition: RevisionList.php:118
RevisionItem\getHTML
getHTML()
Definition: RevisionList.php:417
RevisionItemBase\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevisionList.php:193