3 * Holders of revision list for a single page
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * List for revision table items for a single page
26 abstract class RevisionListBase
extends ContextSource
{
32 var $ids, $res, $current;
35 * Construct a revision list for a given title
36 * @param IContextSource $context
39 function __construct( IContextSource
$context, Title
$title ) {
40 $this->setContext( $context );
41 $this->title
= $title;
45 * Select items only where the ID is any of the specified values
48 function filterByIds( array $ids ) {
53 * Get the internal type name of this list. Equal to the table name.
54 * Override this function.
57 public function getType() {
62 * Initialise the current iteration pointer
64 protected function initCurrent() {
65 $row = $this->res
->current();
67 $this->current
= $this->newItem( $row );
69 $this->current
= false;
74 * Start iteration. This must be called before current() or next().
75 * @return Revision First list item
77 public function reset() {
79 $this->res
= $this->doQuery( wfGetDB( DB_SLAVE
) );
84 return $this->current
;
88 * Get the current list item, or false if we are at the end
91 public function current() {
92 return $this->current
;
96 * Move the iteration pointer to the next list item, and return it.
99 public function next() {
101 $this->initCurrent();
102 return $this->current
;
106 * Get the number of items in the list.
109 public function length() {
113 return $this->res
->numRows();
118 * Do the DB query to iterate through the objects.
119 * @param DatabaseBase $db DatabaseBase object to use for the query
121 abstract public function doQuery( $db );
124 * Create an item object from a DB result row
127 abstract public function newItem( $row );
131 * Abstract base class for revision items
133 abstract class RevisionItemBase
{
134 /** The parent RevisionListBase */
137 /** The DB result row */
141 * @param RevisionListBase $list
142 * @param object $row DB result row
144 public function __construct( $list, $row ) {
150 * Get the DB field name associated with the ID list.
151 * Override this function.
154 public function getIdField() {
159 * Get the DB field name storing timestamps.
160 * Override this function.
163 public function getTimestampField() {
168 * Get the DB field name storing user ids.
169 * Override this function.
172 public function getAuthorIdField() {
177 * Get the DB field name storing user names.
178 * Override this function.
181 public function getAuthorNameField() {
186 * Get the ID, as it would appear in the ids URL parameter
189 public function getId() {
190 $field = $this->getIdField();
191 return $this->row
->$field;
195 * Get the date, formatted in user's language
198 public function formatDate() {
199 return $this->list->getLanguage()->userDate( $this->getTimestamp(),
200 $this->list->getUser() );
204 * Get the time, formatted in user's language
207 public function formatTime() {
208 return $this->list->getLanguage()->userTime( $this->getTimestamp(),
209 $this->list->getUser() );
213 * Get the timestamp in MW 14-char form
216 public function getTimestamp() {
217 $field = $this->getTimestampField();
218 return wfTimestamp( TS_MW
, $this->row
->$field );
222 * Get the author user ID
225 public function getAuthorId() {
226 $field = $this->getAuthorIdField();
227 return intval( $this->row
->$field );
231 * Get the author user name
234 public function getAuthorName() {
235 $field = $this->getAuthorNameField();
236 return strval( $this->row
->$field );
240 * Returns true if the current user can view the item
242 abstract public function canView();
245 * Returns true if the current user can view the item text/file
247 abstract public function canViewContent();
250 * Get the HTML of the list item. Should be include "<li></li>" tags.
251 * This is used to show the list in HTML form, by the special page.
253 abstract public function getHTML();
256 class RevisionList
extends RevisionListBase
{
257 public function getType() {
262 * @param DatabaseBase $db
265 public function doQuery( $db ) {
266 $conds = array( 'rev_page' => $this->title
->getArticleID() );
267 if ( $this->ids
!== null ) {
268 $conds['rev_id'] = array_map( 'intval', $this->ids
);
271 array( 'revision', 'page', 'user' ),
272 array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
275 array( 'ORDER BY' => 'rev_id DESC' ),
277 'page' => Revision
::pageJoinCond(),
278 'user' => Revision
::userJoinCond() )
282 public function newItem( $row ) {
283 return new RevisionItem( $this, $row );
288 * Item class for a live revision table row
290 class RevisionItem
extends RevisionItemBase
{
291 var $revision, $context;
293 public function __construct( $list, $row ) {
294 parent
::__construct( $list, $row );
295 $this->revision
= new Revision( $row );
296 $this->context
= $list->getContext();
299 public function getIdField() {
303 public function getTimestampField() {
304 return 'rev_timestamp';
307 public function getAuthorIdField() {
311 public function getAuthorNameField() {
312 return 'user_name'; // see Revision::selectUserFields()
315 public function canView() {
316 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->context
->getUser() );
319 public function canViewContent() {
320 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->context
->getUser() );
323 public function isDeleted() {
324 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
328 * Get the HTML link to the revision text.
329 * Overridden by RevDel_ArchiveItem.
332 protected function getRevisionLink() {
333 $date = $this->list->getLanguage()->timeanddate( $this->revision
->getTimestamp(), true );
334 if ( $this->isDeleted() && !$this->canViewContent() ) {
342 'oldid' => $this->revision
->getId(),
349 * Get the HTML link to the diff.
350 * Overridden by RevDel_ArchiveItem
353 protected function getDiffLink() {
354 if ( $this->isDeleted() && !$this->canViewContent() ) {
355 return $this->context
->msg( 'diff' )->escaped();
359 $this->context
->msg( 'diff' )->escaped(),
362 'diff' => $this->revision
->getId(),
374 public function getHTML() {
375 $difflink = $this->context
->msg( 'parentheses' )
376 ->rawParams( $this->getDiffLink() )->escaped();
377 $revlink = $this->getRevisionLink();
378 $userlink = Linker
::revUserLink( $this->revision
);
379 $comment = Linker
::revComment( $this->revision
);
380 if ( $this->isDeleted() ) {
381 $revlink = "<span class=\"history-deleted\">$revlink</span>";
383 return "<li>$difflink $revlink $userlink $comment</li>";