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' ),
263 array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ),
264 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) )
268 public function newItem( $row ) {
269 return new RevisionItem( $this, $row );
274 * Item class for a live revision table row
276 class RevisionItem
extends RevisionItemBase
{
277 var $revision, $context;
279 public function __construct( $list, $row ) {
280 parent
::__construct( $list, $row );
281 $this->revision
= new Revision( $row );
282 $this->context
= $list->context
;
285 public function getIdField() {
289 public function getTimestampField() {
290 return 'rev_timestamp';
293 public function getAuthorIdField() {
297 public function getAuthorNameField() {
298 return 'user_name'; // see Revision::selectUserFields()
301 public function canView() {
302 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->context
->getUser() );
305 public function canViewContent() {
306 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->context
->getUser() );
309 public function isDeleted() {
310 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
314 * Get the HTML link to the revision text.
315 * Overridden by RevDel_ArchiveItem.
317 protected function getRevisionLink() {
318 $date = $this->list->getLang()->timeanddate( $this->revision
->getTimestamp(), true );
319 if ( $this->isDeleted() && !$this->canViewContent() ) {
327 'oldid' => $this->revision
->getId(),
334 * Get the HTML link to the diff.
335 * Overridden by RevDel_ArchiveItem
337 protected function getDiffLink() {
338 if ( $this->isDeleted() && !$this->canViewContent() ) {
339 return wfMsgHtml('diff');
347 'diff' => $this->revision
->getId(),
359 public function getHTML() {
360 $difflink = $this->getDiffLink();
361 $revlink = $this->getRevisionLink();
362 $userlink = Linker
::revUserLink( $this->revision
);
363 $comment = Linker
::revComment( $this->revision
);
364 if ( $this->isDeleted() ) {
365 $revlink = "<span class=\"history-deleted\">$revlink</span>";
367 return "<li>($difflink) $revlink $userlink $comment</li>";