3 * List for revision table items for a single page
5 abstract class Rev_List
{
15 var $ids, $res, $current;
17 function __construct( RequestContext
$context, Title
$title, array $ids ) {
18 $this->context
= $context;
19 $this->title
= $title;
24 * Get the internal type name of this list. Equal to the table name.
25 * Override this function.
27 public function getType() {
32 * Initialise the current iteration pointer
34 protected function initCurrent() {
35 $row = $this->res
->current();
37 $this->current
= $this->newItem( $row );
39 $this->current
= false;
44 * Start iteration. This must be called before current() or next().
45 * @return First list item
47 public function reset() {
49 $this->res
= $this->doQuery( wfGetDB( DB_SLAVE
) );
54 return $this->current
;
58 * Get the current list item, or false if we are at the end
60 public function current() {
61 return $this->current
;
65 * Move the iteration pointer to the next list item, and return it.
67 public function next() {
70 return $this->current
;
74 * Get the number of items in the list.
76 public function length() {
80 return $this->res
->numRows();
85 * Do the DB query to iterate through the objects.
86 * @param $db DatabaseBase object to use for the query
88 abstract public function doQuery( $db );
91 * Create an item object from a DB result row
92 * @param $row stdclass
94 abstract public function newItem( $row );
97 * Get the language of the user doing the action
99 * @return Language object
101 public function getLang() {
102 return $this->context
->getLang();
106 * Get the user doing the action
108 * @return User object
110 public function getUser() {
111 return $this->context
->getUser();
116 * Abstract base class for revision items
118 abstract class Rev_Item
{
119 /** The parent Rev_List */
122 /** The DB result row */
126 * @param $list Rev_List
127 * @param $row DB result row
129 public function __construct( $list, $row ) {
135 * Get the DB field name associated with the ID list.
136 * Override this function.
138 public function getIdField() {
143 * Get the DB field name storing timestamps.
144 * Override this function.
146 public function getTimestampField() {
151 * Get the DB field name storing user ids.
152 * Override this function.
154 public function getAuthorIdField() {
159 * Get the DB field name storing user names.
160 * Override this function.
162 public function getAuthorNameField() {
167 * Get the ID, as it would appear in the ids URL parameter
169 public function getId() {
170 $field = $this->getIdField();
171 return $this->row
->$field;
175 * Get the date, formatted with $wgLang
177 public function formatDate() {
179 return $wgLang->date( $this->getTimestamp() );
183 * Get the time, formatted with $wgLang
185 public function formatTime() {
187 return $wgLang->time( $this->getTimestamp() );
191 * Get the timestamp in MW 14-char form
193 public function getTimestamp() {
194 $field = $this->getTimestampField();
195 return wfTimestamp( TS_MW
, $this->row
->$field );
199 * Get the author user ID
201 public function getAuthorId() {
202 $field = $this->getAuthorIdField();
203 return intval( $this->row
->$field );
207 * Get the author user name
209 public function getAuthorName() {
210 $field = $this->getAuthorNameField();
211 return strval( $this->row
->$field );
215 * Returns true if the current user can view the item
217 abstract public function canView();
220 * Returns true if the current user can view the item text/file
222 abstract public function canViewContent();
225 * Get the HTML of the list item. Should be include <li></li> tags.
226 * This is used to show the list in HTML form, by the special page.
228 abstract public function getHTML();
231 class RevisionList
extends Rev_List
{
232 public function getType() {
237 * @param $db DatabaseBase
240 public function doQuery( $db ) {
241 $ids = array_map( 'intval', $this->ids
);
242 return $db->select( array('revision','page'), '*',
244 'rev_page' => $this->title
->getArticleID(),
245 'rev_id' => array_map( 'intval', $this->ids
),
249 array( 'ORDER BY' => 'rev_id DESC' )
253 public function newItem( $row ) {
254 return new RevisionItem( $this, $row );
259 * Item class for a live revision table row
261 class RevisionItem
extends Rev_Item
{
262 var $revision, $context;
264 public function __construct( $list, $row ) {
265 parent
::__construct( $list, $row );
266 $this->revision
= new Revision( $row );
267 $this->context
= $list->context
;
270 public function getIdField() {
274 public function getTimestampField() {
275 return 'rev_timestamp';
278 public function getAuthorIdField() {
282 public function getAuthorNameField() {
283 return 'rev_user_text';
286 public function canView() {
287 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
);
290 public function canViewContent() {
291 return $this->revision
->userCan( Revision
::DELETED_TEXT
);
294 public function isDeleted() {
295 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
299 * Get the HTML link to the revision text.
300 * Overridden by RevDel_ArchiveItem.
302 protected function getRevisionLink() {
303 $date = $this->list->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
304 if ( $this->isDeleted() && !$this->canViewContent() ) {
312 'oldid' => $this->revision
->getId(),
319 * Get the HTML link to the diff.
320 * Overridden by RevDel_ArchiveItem
322 protected function getDiffLink() {
323 if ( $this->isDeleted() && !$this->canViewContent() ) {
324 return wfMsgHtml('diff');
332 'diff' => $this->revision
->getId(),
344 public function getHTML() {
345 $difflink = $this->getDiffLink();
346 $revlink = $this->getRevisionLink();
347 $userlink = Linker
::revUserLink( $this->revision
);
348 $comment = Linker
::revComment( $this->revision
);
349 if ( $this->isDeleted() ) {
350 $revlink = "<span class=\"history-deleted\">$revlink</span>";
352 return "<li>($difflink) $revlink $userlink $comment</li>";