3 * List for revision table items for a single page
5 abstract class RevisionListBase
extends ContextSource
{
11 var $ids, $res, $current;
14 * Construct a revision list for a given title
15 * @param $context IContextSource
18 function __construct( IContextSource
$context, Title
$title ) {
19 $this->setContext( $context );
20 $this->title
= $title;
24 * Select items only where the ID is any of the specified values
27 function filterByIds( array $ids ) {
32 * Get the internal type name of this list. Equal to the table name.
33 * Override this function.
35 public function getType() {
40 * Initialise the current iteration pointer
42 protected function initCurrent() {
43 $row = $this->res
->current();
45 $this->current
= $this->newItem( $row );
47 $this->current
= false;
52 * Start iteration. This must be called before current() or next().
53 * @return First list item
55 public function reset() {
57 $this->res
= $this->doQuery( wfGetDB( DB_SLAVE
) );
62 return $this->current
;
66 * Get the current list item, or false if we are at the end
68 public function current() {
69 return $this->current
;
73 * Move the iteration pointer to the next list item, and return it.
75 public function next() {
78 return $this->current
;
82 * Get the number of items in the list.
84 public function length() {
88 return $this->res
->numRows();
93 * Do the DB query to iterate through the objects.
94 * @param $db DatabaseBase object to use for the query
96 abstract public function doQuery( $db );
99 * Create an item object from a DB result row
100 * @param $row stdclass
102 abstract public function newItem( $row );
106 * Abstract base class for revision items
108 abstract class RevisionItemBase
{
109 /** The parent RevisionListBase */
112 /** The DB result row */
116 * @param $list RevisionListBase
117 * @param $row DB result row
119 public function __construct( $list, $row ) {
125 * Get the DB field name associated with the ID list.
126 * Override this function.
128 public function getIdField() {
133 * Get the DB field name storing timestamps.
134 * Override this function.
136 public function getTimestampField() {
141 * Get the DB field name storing user ids.
142 * Override this function.
144 public function getAuthorIdField() {
149 * Get the DB field name storing user names.
150 * Override this function.
152 public function getAuthorNameField() {
157 * Get the ID, as it would appear in the ids URL parameter
159 public function getId() {
160 $field = $this->getIdField();
161 return $this->row
->$field;
165 * Get the date, formatted in user's languae
167 public function formatDate() {
168 return $this->list->getLanguage()->userDate( $this->getTimestamp(),
169 $this->list->getUser() );
173 * Get the time, formatted in user's languae
175 public function formatTime() {
176 return $this->list->getLanguage()->userTime( $this->getTimestamp(),
177 $this->list->getUser() );
181 * Get the timestamp in MW 14-char form
183 public function getTimestamp() {
184 $field = $this->getTimestampField();
185 return wfTimestamp( TS_MW
, $this->row
->$field );
189 * Get the author user ID
191 public function getAuthorId() {
192 $field = $this->getAuthorIdField();
193 return intval( $this->row
->$field );
197 * Get the author user name
199 public function getAuthorName() {
200 $field = $this->getAuthorNameField();
201 return strval( $this->row
->$field );
205 * Returns true if the current user can view the item
207 abstract public function canView();
210 * Returns true if the current user can view the item text/file
212 abstract public function canViewContent();
215 * Get the HTML of the list item. Should be include <li></li> tags.
216 * This is used to show the list in HTML form, by the special page.
218 abstract public function getHTML();
221 class RevisionList
extends RevisionListBase
{
222 public function getType() {
227 * @param $db DatabaseBase
230 public function doQuery( $db ) {
231 $conds = array( 'rev_page' => $this->title
->getArticleID() );
232 if ( $this->ids
!== null ) {
233 $conds['rev_id'] = array_map( 'intval', $this->ids
);
236 array( 'revision', 'page', 'user' ),
237 array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
240 array( 'ORDER BY' => 'rev_id DESC' ),
242 'page' => Revision
::pageJoinCond(),
243 'user' => Revision
::userJoinCond() )
247 public function newItem( $row ) {
248 return new RevisionItem( $this, $row );
253 * Item class for a live revision table row
255 class RevisionItem
extends RevisionItemBase
{
256 var $revision, $context;
258 public function __construct( $list, $row ) {
259 parent
::__construct( $list, $row );
260 $this->revision
= new Revision( $row );
261 $this->context
= $list->context
;
264 public function getIdField() {
268 public function getTimestampField() {
269 return 'rev_timestamp';
272 public function getAuthorIdField() {
276 public function getAuthorNameField() {
277 return 'user_name'; // see Revision::selectUserFields()
280 public function canView() {
281 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->context
->getUser() );
284 public function canViewContent() {
285 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->context
->getUser() );
288 public function isDeleted() {
289 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
293 * Get the HTML link to the revision text.
294 * Overridden by RevDel_ArchiveItem.
296 protected function getRevisionLink() {
297 $date = $this->list->getLanguage()->timeanddate( $this->revision
->getTimestamp(), true );
298 if ( $this->isDeleted() && !$this->canViewContent() ) {
306 'oldid' => $this->revision
->getId(),
313 * Get the HTML link to the diff.
314 * Overridden by RevDel_ArchiveItem
316 protected function getDiffLink() {
317 if ( $this->isDeleted() && !$this->canViewContent() ) {
318 return wfMsgHtml('diff');
326 'diff' => $this->revision
->getId(),
338 public function getHTML() {
339 $difflink = $this->getDiffLink();
340 $revlink = $this->getRevisionLink();
341 $userlink = Linker
::revUserLink( $this->revision
);
342 $comment = Linker
::revComment( $this->revision
);
343 if ( $this->isDeleted() ) {
344 $revlink = "<span class=\"history-deleted\">$revlink</span>";
346 return "<li>($difflink) $revlink $userlink $comment</li>";