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.
36 public function getType() {
41 * Initialise the current iteration pointer
43 protected function initCurrent() {
44 $row = $this->res
->current();
46 $this->current
= $this->newItem( $row );
48 $this->current
= false;
53 * Start iteration. This must be called before current() or next().
54 * @return First list item
56 public function reset() {
58 $this->res
= $this->doQuery( wfGetDB( DB_SLAVE
) );
63 return $this->current
;
67 * Get the current list item, or false if we are at the end
69 public function current() {
70 return $this->current
;
74 * Move the iteration pointer to the next list item, and return it.
76 public function next() {
79 return $this->current
;
83 * Get the number of items in the list.
86 public function length() {
90 return $this->res
->numRows();
95 * Do the DB query to iterate through the objects.
96 * @param $db DatabaseBase object to use for the query
98 abstract public function doQuery( $db );
101 * Create an item object from a DB result row
102 * @param $row stdclass
104 abstract public function newItem( $row );
108 * Abstract base class for revision items
110 abstract class RevisionItemBase
{
111 /** The parent RevisionListBase */
114 /** The DB result row */
118 * @param $list RevisionListBase
119 * @param $row DB result row
121 public function __construct( $list, $row ) {
127 * Get the DB field name associated with the ID list.
128 * Override this function.
131 public function getIdField() {
136 * Get the DB field name storing timestamps.
137 * Override this function.
140 public function getTimestampField() {
145 * Get the DB field name storing user ids.
146 * Override this function.
149 public function getAuthorIdField() {
154 * Get the DB field name storing user names.
155 * Override this function.
158 public function getAuthorNameField() {
163 * Get the ID, as it would appear in the ids URL parameter
166 public function getId() {
167 $field = $this->getIdField();
168 return $this->row
->$field;
172 * Get the date, formatted in user's languae
175 public function formatDate() {
176 return $this->list->getLanguage()->userDate( $this->getTimestamp(),
177 $this->list->getUser() );
181 * Get the time, formatted in user's languae
184 public function formatTime() {
185 return $this->list->getLanguage()->userTime( $this->getTimestamp(),
186 $this->list->getUser() );
190 * 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
202 public function getAuthorId() {
203 $field = $this->getAuthorIdField();
204 return intval( $this->row
->$field );
208 * Get the author user name
211 public function getAuthorName() {
212 $field = $this->getAuthorNameField();
213 return strval( $this->row
->$field );
217 * Returns true if the current user can view the item
219 abstract public function canView();
222 * Returns true if the current user can view the item text/file
224 abstract public function canViewContent();
227 * Get the HTML of the list item. Should be include <li></li> tags.
228 * This is used to show the list in HTML form, by the special page.
230 abstract public function getHTML();
233 class RevisionList
extends RevisionListBase
{
234 public function getType() {
239 * @param $db DatabaseBase
242 public function doQuery( $db ) {
243 $conds = array( 'rev_page' => $this->title
->getArticleID() );
244 if ( $this->ids
!== null ) {
245 $conds['rev_id'] = array_map( 'intval', $this->ids
);
248 array( 'revision', 'page', 'user' ),
249 array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
252 array( 'ORDER BY' => 'rev_id DESC' ),
254 'page' => Revision
::pageJoinCond(),
255 'user' => Revision
::userJoinCond() )
259 public function newItem( $row ) {
260 return new RevisionItem( $this, $row );
265 * Item class for a live revision table row
267 class RevisionItem
extends RevisionItemBase
{
268 var $revision, $context;
270 public function __construct( $list, $row ) {
271 parent
::__construct( $list, $row );
272 $this->revision
= new Revision( $row );
273 $this->context
= $list->getContext();
276 public function getIdField() {
280 public function getTimestampField() {
281 return 'rev_timestamp';
284 public function getAuthorIdField() {
288 public function getAuthorNameField() {
289 return 'user_name'; // see Revision::selectUserFields()
292 public function canView() {
293 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->context
->getUser() );
296 public function canViewContent() {
297 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->context
->getUser() );
300 public function isDeleted() {
301 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
305 * Get the HTML link to the revision text.
306 * Overridden by RevDel_ArchiveItem.
309 protected function getRevisionLink() {
310 $date = $this->list->getLanguage()->timeanddate( $this->revision
->getTimestamp(), true );
311 if ( $this->isDeleted() && !$this->canViewContent() ) {
319 'oldid' => $this->revision
->getId(),
326 * Get the HTML link to the diff.
327 * Overridden by RevDel_ArchiveItem
330 protected function getDiffLink() {
331 if ( $this->isDeleted() && !$this->canViewContent() ) {
332 return wfMsgHtml('diff');
340 'diff' => $this->revision
->getId(),
352 public function getHTML() {
353 $difflink = $this->getDiffLink();
354 $revlink = $this->getRevisionLink();
355 $userlink = Linker
::revUserLink( $this->revision
);
356 $comment = Linker
::revComment( $this->revision
);
357 if ( $this->isDeleted() ) {
358 $revlink = "<span class=\"history-deleted\">$revlink</span>";
360 return "<li>($difflink) $revlink $userlink $comment</li>";