3 * List for revision table items for a single page
5 abstract class RevisionListBase
{
15 var $ids, $res, $current;
18 * Construct a revision list for a given title
19 * @param $context IContextSource
22 function __construct( IContextSource
$context, Title
$title ) {
23 $this->context
= $context;
24 $this->title
= $title;
28 * Select items only where the ID is any of the specified values
31 function filterByIds( array $ids ) {
36 * Get the internal type name of this list. Equal to the table name.
37 * Override this function.
39 public function getType() {
44 * Initialise the current iteration pointer
46 protected function initCurrent() {
47 $row = $this->res
->current();
49 $this->current
= $this->newItem( $row );
51 $this->current
= false;
56 * Start iteration. This must be called before current() or next().
57 * @return First list item
59 public function reset() {
61 $this->res
= $this->doQuery( wfGetDB( DB_SLAVE
) );
66 return $this->current
;
70 * Get the current list item, or false if we are at the end
72 public function current() {
73 return $this->current
;
77 * Move the iteration pointer to the next list item, and return it.
79 public function next() {
82 return $this->current
;
86 * Get the number of items in the list.
88 public function length() {
92 return $this->res
->numRows();
97 * Do the DB query to iterate through the objects.
98 * @param $db DatabaseBase object to use for the query
100 abstract public function doQuery( $db );
103 * Create an item object from a DB result row
104 * @param $row stdclass
106 abstract public function newItem( $row );
109 * Get the language of the user doing the action
111 * @return Language object
113 public function getLang() {
114 return $this->context
->getLang();
118 * Get the user doing the action
120 * @return User object
122 public function getUser() {
123 return $this->context
->getUser();
128 * Abstract base class for revision items
130 abstract class RevisionItemBase
{
131 /** The parent RevisionListBase */
134 /** The DB result row */
138 * @param $list RevisionListBase
139 * @param $row DB result row
141 public function __construct( $list, $row ) {
147 * Get the DB field name associated with the ID list.
148 * Override this function.
150 public function getIdField() {
155 * Get the DB field name storing timestamps.
156 * Override this function.
158 public function getTimestampField() {
163 * Get the DB field name storing user ids.
164 * Override this function.
166 public function getAuthorIdField() {
171 * Get the DB field name storing user names.
172 * Override this function.
174 public function getAuthorNameField() {
179 * Get the ID, as it would appear in the ids URL parameter
181 public function getId() {
182 $field = $this->getIdField();
183 return $this->row
->$field;
187 * Get the date, formatted in user's languae
189 public function formatDate() {
190 return $this->list->context
->getLang()->userDate( $this->getTimestamp(),
191 $this->list->context
->getUser() );
195 * Get the time, formatted in user's languae
197 public function formatTime() {
198 return $this->list->context
->getLang()->userTime( $this->getTimestamp(),
199 $this->list->context
->getUser() );
203 * Get the timestamp in MW 14-char form
205 public function getTimestamp() {
206 $field = $this->getTimestampField();
207 return wfTimestamp( TS_MW
, $this->row
->$field );
211 * Get the author user ID
213 public function getAuthorId() {
214 $field = $this->getAuthorIdField();
215 return intval( $this->row
->$field );
219 * Get the author user name
221 public function getAuthorName() {
222 $field = $this->getAuthorNameField();
223 return strval( $this->row
->$field );
227 * Returns true if the current user can view the item
229 abstract public function canView();
232 * Returns true if the current user can view the item text/file
234 abstract public function canViewContent();
237 * Get the HTML of the list item. Should be include <li></li> tags.
238 * This is used to show the list in HTML form, by the special page.
240 abstract public function getHTML();
243 class RevisionList
extends RevisionListBase
{
244 public function getType() {
249 * @param $db DatabaseBase
252 public function doQuery( $db ) {
253 $conds = array( 'rev_page' => $this->title
->getArticleID() );
254 if ( $this->ids
!== null ) {
255 $conds['rev_id'] = array_map( 'intval', $this->ids
);
258 array( 'revision', 'page', 'user' ),
259 array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
262 array( 'ORDER BY' => 'rev_id DESC' ),
264 'page' => Revision
::pageJoinCond(),
265 'user' => Revision
::userJoinCond() )
269 public function newItem( $row ) {
270 return new RevisionItem( $this, $row );
275 * Item class for a live revision table row
277 class RevisionItem
extends RevisionItemBase
{
278 var $revision, $context;
280 public function __construct( $list, $row ) {
281 parent
::__construct( $list, $row );
282 $this->revision
= new Revision( $row );
283 $this->context
= $list->context
;
286 public function getIdField() {
290 public function getTimestampField() {
291 return 'rev_timestamp';
294 public function getAuthorIdField() {
298 public function getAuthorNameField() {
299 return 'user_name'; // see Revision::selectUserFields()
302 public function canView() {
303 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->context
->getUser() );
306 public function canViewContent() {
307 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->context
->getUser() );
310 public function isDeleted() {
311 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
315 * Get the HTML link to the revision text.
316 * Overridden by RevDel_ArchiveItem.
318 protected function getRevisionLink() {
319 $date = $this->list->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
320 if ( $this->isDeleted() && !$this->canViewContent() ) {
328 'oldid' => $this->revision
->getId(),
335 * Get the HTML link to the diff.
336 * Overridden by RevDel_ArchiveItem
338 protected function getDiffLink() {
339 if ( $this->isDeleted() && !$this->canViewContent() ) {
340 return wfMsgHtml('diff');
348 'diff' => $this->revision
->getId(),
360 public function getHTML() {
361 $difflink = $this->getDiffLink();
362 $revlink = $this->getRevisionLink();
363 $userlink = Linker
::revUserLink( $this->revision
);
364 $comment = Linker
::revComment( $this->revision
);
365 if ( $this->isDeleted() ) {
366 $revlink = "<span class=\"history-deleted\">$revlink</span>";
368 return "<li>($difflink) $revlink $userlink $comment</li>";