MediaWiki  1.27.1
RevisionList.php
Go to the documentation of this file.
1 <?php
26 abstract class RevisionListBase extends ContextSource {
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_SLAVE ) );
85  } else {
86  $this->res->rewind();
87  }
88  $this->initCurrent();
89  return $this->current;
90  }
91 
96  public function current() {
97  return $this->current;
98  }
99 
104  public function next() {
105  $this->res->next();
106  $this->initCurrent();
107  return $this->current;
108  }
109 
114  public function length() {
115  if ( !$this->res ) {
116  return 0;
117  } else {
118  return $this->res->numRows();
119  }
120  }
121 
126  abstract public function doQuery( $db );
127 
132  abstract public function newItem( $row );
133 }
134 
138 abstract class RevisionItemBase {
140  protected $list;
141 
143  protected $row;
144 
149  public function __construct( $list, $row ) {
150  $this->list = $list;
151  $this->row = $row;
152  }
153 
159  public function getIdField() {
160  return null;
161  }
162 
168  public function getTimestampField() {
169  return false;
170  }
171 
177  public function getAuthorIdField() {
178  return false;
179  }
180 
186  public function getAuthorNameField() {
187  return false;
188  }
189 
194  public function getId() {
195  $field = $this->getIdField();
196  return $this->row->$field;
197  }
198 
203  public function formatDate() {
204  return $this->list->getLanguage()->userDate( $this->getTimestamp(),
205  $this->list->getUser() );
206  }
207 
212  public function formatTime() {
213  return $this->list->getLanguage()->userTime( $this->getTimestamp(),
214  $this->list->getUser() );
215  }
216 
221  public function getTimestamp() {
222  $field = $this->getTimestampField();
223  return wfTimestamp( TS_MW, $this->row->$field );
224  }
225 
230  public function getAuthorId() {
231  $field = $this->getAuthorIdField();
232  return intval( $this->row->$field );
233  }
234 
239  public function getAuthorName() {
240  $field = $this->getAuthorNameField();
241  return strval( $this->row->$field );
242  }
243 
247  abstract public function canView();
248 
252  abstract public function canViewContent();
253 
258  abstract public function getHTML();
259 }
260 
262  public function getType() {
263  return 'revision';
264  }
265 
270  public function doQuery( $db ) {
271  $conds = [ 'rev_page' => $this->title->getArticleID() ];
272  if ( $this->ids !== null ) {
273  $conds['rev_id'] = array_map( 'intval', $this->ids );
274  }
275  return $db->select(
276  [ 'revision', 'page', 'user' ],
278  $conds,
279  __METHOD__,
280  [ 'ORDER BY' => 'rev_id DESC' ],
281  [
282  'page' => Revision::pageJoinCond(),
283  'user' => Revision::userJoinCond() ]
284  );
285  }
286 
287  public function newItem( $row ) {
288  return new RevisionItem( $this, $row );
289  }
290 }
291 
297  protected $revision;
298 
300  protected $context;
301 
302  public function __construct( $list, $row ) {
303  parent::__construct( $list, $row );
304  $this->revision = new Revision( $row );
305  $this->context = $list->getContext();
306  }
307 
308  public function getIdField() {
309  return 'rev_id';
310  }
311 
312  public function getTimestampField() {
313  return 'rev_timestamp';
314  }
315 
316  public function getAuthorIdField() {
317  return 'rev_user';
318  }
319 
320  public function getAuthorNameField() {
321  return 'rev_user_text';
322  }
323 
324  public function canView() {
325  return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->context->getUser() );
326  }
327 
328  public function canViewContent() {
329  return $this->revision->userCan( Revision::DELETED_TEXT, $this->context->getUser() );
330  }
331 
332  public function isDeleted() {
333  return $this->revision->isDeleted( Revision::DELETED_TEXT );
334  }
335 
343  protected function getRevisionLink() {
344  $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
345  $this->revision->getTimestamp(), $this->list->getUser() ) );
346 
347  if ( $this->isDeleted() && !$this->canViewContent() ) {
348  return $date;
349  }
350  return Linker::linkKnown(
351  $this->list->title,
352  $date,
353  [],
354  [
355  'oldid' => $this->revision->getId(),
356  'unhide' => 1
357  ]
358  );
359  }
360 
368  protected function getDiffLink() {
369  if ( $this->isDeleted() && !$this->canViewContent() ) {
370  return $this->context->msg( 'diff' )->escaped();
371  } else {
372  return Linker::linkKnown(
373  $this->list->title,
374  $this->list->msg( 'diff' )->escaped(),
375  [],
376  [
377  'diff' => $this->revision->getId(),
378  'oldid' => 'prev',
379  'unhide' => 1
380  ]
381  );
382  }
383  }
384 
391  public function getHTML() {
392  $difflink = $this->context->msg( 'parentheses' )
393  ->rawParams( $this->getDiffLink() )->escaped();
394  $revlink = $this->getRevisionLink();
395  $userlink = Linker::revUserLink( $this->revision );
396  $comment = Linker::revComment( $this->revision );
397  if ( $this->isDeleted() ) {
398  $revlink = "<span class=\"history-deleted\">$revlink</span>";
399  }
400  return "<li>$difflink $revlink $userlink $comment</li>";
401  }
402 }
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:1656
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.
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
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.
Represents a title within MediaWiki.
Definition: Title.php:34
IContextSource $context
canViewContent()
Returns true if the current user can view the item text/file.
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:429
title
const DELETED_RESTRICTED
Definition: Revision.php:79
const DB_SLAVE
Definition: Defines.php:46
static revUserLink($rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1231
const DELETED_TEXT
Definition: Revision.php:76
canView()
Returns true if the current user can view the item.
next()
Move the iteration pointer to the next list item, and return it.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:420
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.
!html< table >< tr >< tdstyle="color:red;"></td >< tdstyle="color:blue;"></td ></tr >< tr >< td ></td >< td ></td >< td ></td >< td ></td >< td ></td >< td ></td ></tr >< tr >< td ></td >< td ></td ></tr ></table >!end!test Table rowspan row</td >< tdrowspan="2"> row(and 2)</td >< td > Cell 3
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:410
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:517
doQuery($db)
Do the DB query to iterate through the objects.
formatDate()
Get the date, formatted in user's language.
Revision $revision