MediaWiki  1.23.2
RevisionList.php
Go to the documentation of this file.
1 <?php
26 abstract class RevisionListBase extends ContextSource {
30  var $title;
31 
32  var $ids, $res, $current;
33 
40  $this->setContext( $context );
41  $this->title = $title;
42  }
43 
48  function filterByIds( array $ids ) {
49  $this->ids = $ids;
50  }
51 
57  public function getType() {
58  return null;
59  }
60 
64  protected function initCurrent() {
65  $row = $this->res->current();
66  if ( $row ) {
67  $this->current = $this->newItem( $row );
68  } else {
69  $this->current = false;
70  }
71  }
72 
77  public function reset() {
78  if ( !$this->res ) {
79  $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
80  } else {
81  $this->res->rewind();
82  }
83  $this->initCurrent();
84  return $this->current;
85  }
86 
90  public function current() {
91  return $this->current;
92  }
93 
97  public function next() {
98  $this->res->next();
99  $this->initCurrent();
100  return $this->current;
101  }
102 
107  public function length() {
108  if ( !$this->res ) {
109  return 0;
110  } else {
111  return $this->res->numRows();
112  }
113  }
114 
119  abstract public function doQuery( $db );
120 
125  abstract public function newItem( $row );
126 }
127 
131 abstract class RevisionItemBase {
133  var $list;
134 
136  var $row;
137 
142  public function __construct( $list, $row ) {
143  $this->list = $list;
144  $this->row = $row;
145  }
146 
152  public function getIdField() {
153  return null;
154  }
155 
161  public function getTimestampField() {
162  return false;
163  }
164 
170  public function getAuthorIdField() {
171  return false;
172  }
173 
179  public function getAuthorNameField() {
180  return false;
181  }
182 
187  public function getId() {
188  $field = $this->getIdField();
189  return $this->row->$field;
190  }
191 
196  public function formatDate() {
197  return $this->list->getLanguage()->userDate( $this->getTimestamp(),
198  $this->list->getUser() );
199  }
200 
205  public function formatTime() {
206  return $this->list->getLanguage()->userTime( $this->getTimestamp(),
207  $this->list->getUser() );
208  }
209 
214  public function getTimestamp() {
215  $field = $this->getTimestampField();
216  return wfTimestamp( TS_MW, $this->row->$field );
217  }
218 
223  public function getAuthorId() {
224  $field = $this->getAuthorIdField();
225  return intval( $this->row->$field );
226  }
227 
232  public function getAuthorName() {
233  $field = $this->getAuthorNameField();
234  return strval( $this->row->$field );
235  }
236 
240  abstract public function canView();
241 
245  abstract public function canViewContent();
246 
251  abstract public function getHTML();
252 }
253 
255  public function getType() {
256  return 'revision';
257  }
258 
263  public function doQuery( $db ) {
264  $conds = array( 'rev_page' => $this->title->getArticleID() );
265  if ( $this->ids !== null ) {
266  $conds['rev_id'] = array_map( 'intval', $this->ids );
267  }
268  return $db->select(
269  array( 'revision', 'page', 'user' ),
271  $conds,
272  __METHOD__,
273  array( 'ORDER BY' => 'rev_id DESC' ),
274  array(
275  'page' => Revision::pageJoinCond(),
276  'user' => Revision::userJoinCond() )
277  );
278  }
279 
280  public function newItem( $row ) {
281  return new RevisionItem( $this, $row );
282  }
283 }
284 
289  var $revision, $context;
290 
291  public function __construct( $list, $row ) {
292  parent::__construct( $list, $row );
293  $this->revision = new Revision( $row );
294  $this->context = $list->getContext();
295  }
296 
297  public function getIdField() {
298  return 'rev_id';
299  }
300 
301  public function getTimestampField() {
302  return 'rev_timestamp';
303  }
304 
305  public function getAuthorIdField() {
306  return 'rev_user';
307  }
308 
309  public function getAuthorNameField() {
310  return 'user_name'; // see Revision::selectUserFields()
311  }
312 
313  public function canView() {
314  return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
315  }
316 
317  public function canViewContent() {
318  return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
319  }
320 
321  public function isDeleted() {
322  return $this->revision->isDeleted( Revision::DELETED_TEXT );
323  }
324 
330  protected function getRevisionLink() {
331  $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true );
332  if ( $this->isDeleted() && !$this->canViewContent() ) {
333  return $date;
334  }
335  return Linker::link(
336  $this->list->title,
337  $date,
338  array(),
339  array(
340  'oldid' => $this->revision->getId(),
341  'unhide' => 1
342  )
343  );
344  }
345 
351  protected function getDiffLink() {
352  if ( $this->isDeleted() && !$this->canViewContent() ) {
353  return $this->context->msg( 'diff' )->escaped();
354  } else {
355  return Linker::link(
356  $this->list->title,
357  $this->context->msg( 'diff' )->escaped(),
358  array(),
359  array(
360  'diff' => $this->revision->getId(),
361  'oldid' => 'prev',
362  'unhide' => 1
363  ),
364  array(
365  'known',
366  'noclasses'
367  )
368  );
369  }
370  }
371 
372  public function getHTML() {
373  $difflink = $this->context->msg( 'parentheses' )
374  ->rawParams( $this->getDiffLink() )->escaped();
375  $revlink = $this->getRevisionLink();
376  $userlink = Linker::revUserLink( $this->revision );
377  $comment = Linker::revComment( $this->revision );
378  if ( $this->isDeleted() ) {
379  $revlink = "<span class=\"history-deleted\">$revlink</span>";
380  }
381  return "<li>$difflink $revlink $userlink $comment</li>";
382  }
383 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:68
RevisionItemBase\getHTML
getHTML()
Get the HTML of the list item.
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
RevisionList\getType
getType()
Get the internal type name of this list.
Definition: RevisionList.php:254
Revision\pageJoinCond
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:396
RevisionListBase\filterByIds
filterByIds(array $ids)
Select items only where the ID is any of the specified values.
Definition: RevisionList.php:47
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1198
RevisionListBase
List for revision table items for a single page.
Definition: RevisionList.php:26
RevisionItemBase
Abstract base class for revision items.
Definition: RevisionList.php:130
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
RevisionItem\canView
canView()
Returns true if the current user can view the item.
Definition: RevisionList.php:312
RevisionItemBase\$list
$list
The parent RevisionListBase.
Definition: RevisionList.php:132
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
RevisionItemBase\__construct
__construct( $list, $row)
Definition: RevisionList.php:141
RevisionListBase\length
length()
Get the number of items in the list.
Definition: RevisionList.php:106
RevisionItem\isDeleted
isDeleted()
Definition: RevisionList.php:320
RevisionListBase\$current
$current
Definition: RevisionList.php:31
RevisionItemBase\getAuthorId
getAuthorId()
Get the author user ID.
Definition: RevisionList.php:222
RevisionList
Definition: RevisionList.php:253
RevisionItem\__construct
__construct( $list, $row)
Definition: RevisionList.php:290
RevisionItemBase\canView
canView()
Returns true if the current user can view the item.
true
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 true
Definition: hooks.txt:1530
RevisionItem\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevisionList.php:304
RevisionItemBase\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevisionList.php:178
RevisionItemBase\formatDate
formatDate()
Get the date, formatted in user's language.
Definition: RevisionList.php:195
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
RevisionListBase\$res
$res
Definition: RevisionList.php:31
Revision
Definition: Revision.php:26
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:2703
RevisionItemBase\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevisionList.php:160
RevisionItem\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
Definition: RevisionList.php:316
RevisionList\doQuery
doQuery( $db)
Definition: RevisionList.php:262
RevisionListBase\next
next()
Move the iteration pointer to the next list item, and return it.
Definition: RevisionList.php:96
RevisionListBase\doQuery
doQuery( $db)
Do the DB query to iterate through the objects.
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:204
RevisionListBase\current
current()
Get the current list item, or false if we are at the end.
Definition: RevisionList.php:89
RevisionListBase\$title
Title $title
Definition: RevisionList.php:29
RevisionItem\getAuthorNameField
getAuthorNameField()
Get the DB field name storing user names.
Definition: RevisionList.php:308
RevisionItem\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevisionList.php:296
RevisionList\newItem
newItem( $row)
Create an item object from a DB result row.
Definition: RevisionList.php:279
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$comment
$comment
Definition: importImages.php:107
RevisionItemBase\getAuthorName
getAuthorName()
Get the author user name.
Definition: RevisionList.php:231
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:57
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:76
RevisionListBase\newItem
newItem( $row)
Create an item object from a DB result row.
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2431
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:1578
RevisionItemBase\getId
getId()
Get the ID, as it would appear in the ids URL parameter.
Definition: RevisionList.php:186
RevisionListBase\$ids
$ids
Definition: RevisionList.php:31
RevisionItemBase\canViewContent
canViewContent()
Returns true if the current user can view the item text/file.
RevisionItemBase\$row
$row
The DB result row.
Definition: RevisionList.php:135
RevisionItem
Item class for a live revision table row.
Definition: RevisionList.php:287
RevisionItemBase\getTimestamp
getTimestamp()
Get the timestamp in MW 14-char form.
Definition: RevisionList.php:213
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
RevisionItem\getRevisionLink
getRevisionLink()
Get the HTML link to the revision text.
Definition: RevisionList.php:329
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:35
RevisionItem\$context
$context
Definition: RevisionList.php:288
RevisionItem\getDiffLink
getDiffLink()
Get the HTML link to the diff.
Definition: RevisionList.php:350
Revision\userJoinCond
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:386
RevisionItem\getTimestampField
getTimestampField()
Get the DB field name storing timestamps.
Definition: RevisionList.php:300
RevisionListBase\getType
getType()
Get the internal type name of this list.
Definition: RevisionList.php:56
RevisionListBase\initCurrent
initCurrent()
Initialise the current iteration pointer.
Definition: RevisionList.php:63
Revision\selectUserFields
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:493
RevisionItemBase\getIdField
getIdField()
Get the DB field name associated with the ID list.
Definition: RevisionList.php:151
RevisionListBase\__construct
__construct(IContextSource $context, Title $title)
Construct a revision list for a given title.
Definition: RevisionList.php:38
Revision\selectFields
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:405
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:65
RevisionItem\getHTML
getHTML()
Get the HTML of the list item.
Definition: RevisionList.php:371
RevisionItem\$revision
$revision
Definition: RevisionList.php:288
RevisionItemBase\getAuthorIdField
getAuthorIdField()
Get the DB field name storing user ids.
Definition: RevisionList.php:169