MediaWiki REL1_32
RevisionList.php
Go to the documentation of this file.
1<?php
26
30abstract 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
154abstract 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
212 public function getAuthorActorField() {
213 return false;
214 }
215
220 public function getId() {
221 $field = $this->getIdField();
222 return $this->row->$field;
223 }
224
229 public function formatDate() {
230 return $this->list->getLanguage()->userDate( $this->getTimestamp(),
231 $this->list->getUser() );
232 }
233
238 public function formatTime() {
239 return $this->list->getLanguage()->userTime( $this->getTimestamp(),
240 $this->list->getUser() );
241 }
242
247 public function getTimestamp() {
248 $field = $this->getTimestampField();
249 return wfTimestamp( TS_MW, $this->row->$field );
250 }
251
256 public function getAuthorId() {
257 $field = $this->getAuthorIdField();
258 return intval( $this->row->$field );
259 }
260
265 public function getAuthorName() {
266 $field = $this->getAuthorNameField();
267 return strval( $this->row->$field );
268 }
269
275 public function getAuthorActor() {
276 $field = $this->getAuthorActorField();
277 return strval( $this->row->$field );
278 }
279
283 abstract public function canView();
284
288 abstract public function canViewContent();
289
294 abstract public function getHTML();
295
300 protected function getLinkRenderer() {
301 return MediaWikiServices::getInstance()->getLinkRenderer();
302 }
303}
304
306 public function getType() {
307 return 'revision';
308 }
309
314 public function doQuery( $db ) {
315 $conds = [ 'rev_page' => $this->title->getArticleID() ];
316 if ( $this->ids !== null ) {
317 $conds['rev_id'] = array_map( 'intval', $this->ids );
318 }
319 $revQuery = Revision::getQueryInfo( [ 'page', 'user' ] );
320 return $db->select(
321 $revQuery['tables'],
322 $revQuery['fields'],
323 $conds,
324 __METHOD__,
325 [ 'ORDER BY' => 'rev_id DESC' ],
326 $revQuery['joins']
327 );
328 }
329
330 public function newItem( $row ) {
331 return new RevisionItem( $this, $row );
332 }
333}
334
340 protected $revision;
341
343 protected $context;
344
345 public function __construct( $list, $row ) {
346 parent::__construct( $list, $row );
347 $this->revision = new Revision( $row );
348 $this->context = $list->getContext();
349 }
350
351 public function getIdField() {
352 return 'rev_id';
353 }
354
355 public function getTimestampField() {
356 return 'rev_timestamp';
357 }
358
359 public function getAuthorIdField() {
360 return 'rev_user';
361 }
362
363 public function getAuthorNameField() {
364 return 'rev_user_text';
365 }
366
367 public function canView() {
368 return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
369 }
370
371 public function canViewContent() {
372 return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
373 }
374
375 public function isDeleted() {
376 return $this->revision->isDeleted( Revision::DELETED_TEXT );
377 }
378
386 protected function getRevisionLink() {
387 $date = $this->list->getLanguage()->userTimeAndDate(
388 $this->revision->getTimestamp(), $this->list->getUser() );
389
390 if ( $this->isDeleted() && !$this->canViewContent() ) {
391 return htmlspecialchars( $date );
392 }
394 return $linkRenderer->makeKnownLink(
395 $this->list->title,
396 $date,
397 [],
398 [
399 'oldid' => $this->revision->getId(),
400 'unhide' => 1
401 ]
402 );
403 }
404
412 protected function getDiffLink() {
413 if ( $this->isDeleted() && !$this->canViewContent() ) {
414 return $this->context->msg( 'diff' )->escaped();
415 } else {
417 return $linkRenderer->makeKnownLink(
418 $this->list->title,
419 $this->list->msg( 'diff' )->text(),
420 [],
421 [
422 'diff' => $this->revision->getId(),
423 'oldid' => 'prev',
424 'unhide' => 1
425 ]
426 );
427 }
428 }
429
436 public function getHTML() {
437 $difflink = $this->context->msg( 'parentheses' )
438 ->rawParams( $this->getDiffLink() )->escaped();
439 $revlink = $this->getRevisionLink();
440 $userlink = Linker::revUserLink( $this->revision );
441 $comment = Linker::revComment( $this->revision );
442 if ( $this->isDeleted() ) {
443 $revlink = "<span class=\"history-deleted\">$revlink</span>";
444 }
445 return "<li>$difflink $revlink $userlink $comment</li>";
446 }
447}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
IContextSource $context
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
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:1466
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition Linker.php:1031
MediaWikiServices is the service locator for the application scope of MediaWiki.
Group all the pieces relevant to the context of a request into one instance.
Abstract base class for revision items.
$row
The database result row.
formatTime()
Get the time, formatted in user's language.
getAuthorIdField()
Get the DB field name storing user ids.
getTimestampField()
Get the DB field name storing timestamps.
canViewContent()
Returns true if the current user can view the item text/file.
getAuthorActorField()
Get the DB field name storing actor ids.
getAuthorActor()
Get the author actor ID.
getAuthorNameField()
Get the DB field name storing user names.
getHTML()
Get the HTML of the list item.
canView()
Returns true if the current user can view the item.
getAuthorId()
Get the author user ID.
getIdField()
Get the DB field name associated with the ID list.
getAuthorName()
Get the author user name.
getTimestamp()
Get the timestamp in MW 14-char form.
RevisionListBase $list
The parent.
formatDate()
Get the date, formatted in user's language.
getId()
Get the ID, as it would appear in the ids URL parameter.
__construct( $list, $row)
getLinkRenderer()
Returns an instance of LinkRenderer.
Item class for a live revision table row.
canViewContent()
Returns true if the current user can view the item text/file.
Revision $revision
getAuthorIdField()
Get the DB field name storing user ids.
getRevisionLink()
Get the HTML link to the revision text.
__construct( $list, $row)
getDiffLink()
Get the HTML link to the diff.
RequestContext $context
getTimestampField()
Get the DB field name storing timestamps.
getIdField()
Get the DB field name associated with the ID list.
canView()
Returns true if the current user can view the item.
getAuthorNameField()
Get the DB field name storing user names.
List for revision table items for a single page.
__construct(IContextSource $context, Title $title)
Construct a revision list for a given title.
getType()
Get the internal type name of this list.
reset()
Start iteration.
newItem( $row)
Create an item object from a DB result row.
bool Revision $current
current()
Get the current list item, or false if we are at the end.
filterByIds(array $ids)
Select items only where the ID is any of the specified values.
length()
Get the number of items in the list.
doQuery( $db)
Do the DB query to iterate through the objects.
initCurrent()
Initialise the current iteration pointer.
ResultWrapper bool $res
next()
Move the iteration pointer to the next list item, and return it.
newItem( $row)
Create an item object from a DB result row.
getType()
Get the internal type name of this list.
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition Revision.php:521
const DELETED_TEXT
Definition Revision.php:47
const DELETED_RESTRICTED
Definition Revision.php:50
Represents a title within MediaWiki.
Definition Title.php:39
Result wrapper for grabbing data queried from an IDatabase 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
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:2105
Interface for objects which can provide a MediaWiki context on request.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
const DB_REPLICA
Definition defines.php:25