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 $context IContextSource
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 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
90 public function current() {
91 return $this->current
;
95 * Move the iteration pointer to the next list item, and return it.
97 public function next() {
100 return $this->current
;
104 * Get the number of items in the list.
107 public function length() {
111 return $this->res
->numRows();
116 * Do the DB query to iterate through the objects.
117 * @param $db DatabaseBase object to use for the query
119 abstract public function doQuery( $db );
122 * Create an item object from a DB result row
123 * @param $row stdclass
125 abstract public function newItem( $row );
129 * Abstract base class for revision items
131 abstract class RevisionItemBase
{
132 /** The parent RevisionListBase */
135 /** The DB result row */
139 * @param $list RevisionListBase
140 * @param $row DB result row
142 public function __construct( $list, $row ) {
148 * Get the DB field name associated with the ID list.
149 * Override this function.
152 public function getIdField() {
157 * Get the DB field name storing timestamps.
158 * Override this function.
161 public function getTimestampField() {
166 * Get the DB field name storing user ids.
167 * Override this function.
170 public function getAuthorIdField() {
175 * Get the DB field name storing user names.
176 * Override this function.
179 public function getAuthorNameField() {
184 * Get the ID, as it would appear in the ids URL parameter
187 public function getId() {
188 $field = $this->getIdField();
189 return $this->row
->$field;
193 * Get the date, formatted in user's language
196 public function formatDate() {
197 return $this->list->getLanguage()->userDate( $this->getTimestamp(),
198 $this->list->getUser() );
202 * Get the time, formatted in user's language
205 public function formatTime() {
206 return $this->list->getLanguage()->userTime( $this->getTimestamp(),
207 $this->list->getUser() );
211 * Get the timestamp in MW 14-char form
214 public function getTimestamp() {
215 $field = $this->getTimestampField();
216 return wfTimestamp( TS_MW
, $this->row
->$field );
220 * Get the author user ID
223 public function getAuthorId() {
224 $field = $this->getAuthorIdField();
225 return intval( $this->row
->$field );
229 * Get the author user name
232 public function getAuthorName() {
233 $field = $this->getAuthorNameField();
234 return strval( $this->row
->$field );
238 * Returns true if the current user can view the item
240 abstract public function canView();
243 * Returns true if the current user can view the item text/file
245 abstract public function canViewContent();
248 * Get the HTML of the list item. Should be include "<li></li>" tags.
249 * This is used to show the list in HTML form, by the special page.
251 abstract public function getHTML();
254 class RevisionList
extends RevisionListBase
{
255 public function getType() {
260 * @param $db DatabaseBase
263 public function doQuery( $db ) {
264 $conds = array( 'rev_page' => $this->title
->getArticleID() );
265 if ( $this->ids
!== null ) {
266 $conds['rev_id'] = array_map( 'intval', $this->ids
);
269 array( 'revision', 'page', 'user' ),
270 array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
273 array( 'ORDER BY' => 'rev_id DESC' ),
275 'page' => Revision
::pageJoinCond(),
276 'user' => Revision
::userJoinCond() )
280 public function newItem( $row ) {
281 return new RevisionItem( $this, $row );
286 * Item class for a live revision table row
288 class RevisionItem
extends RevisionItemBase
{
289 var $revision, $context;
291 public function __construct( $list, $row ) {
292 parent
::__construct( $list, $row );
293 $this->revision
= new Revision( $row );
294 $this->context
= $list->getContext();
297 public function getIdField() {
301 public function getTimestampField() {
302 return 'rev_timestamp';
305 public function getAuthorIdField() {
309 public function getAuthorNameField() {
310 return 'user_name'; // see Revision::selectUserFields()
313 public function canView() {
314 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
, $this->context
->getUser() );
317 public function canViewContent() {
318 return $this->revision
->userCan( Revision
::DELETED_TEXT
, $this->context
->getUser() );
321 public function isDeleted() {
322 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
326 * Get the HTML link to the revision text.
327 * Overridden by RevDel_ArchiveItem.
330 protected function getRevisionLink() {
331 $date = $this->list->getLanguage()->timeanddate( $this->revision
->getTimestamp(), true );
332 if ( $this->isDeleted() && !$this->canViewContent() ) {
340 'oldid' => $this->revision
->getId(),
347 * Get the HTML link to the diff.
348 * Overridden by RevDel_ArchiveItem
351 protected function getDiffLink() {
352 if ( $this->isDeleted() && !$this->canViewContent() ) {
353 return $this->context
->msg( 'diff' )->escaped();
357 $this->context
->msg( 'diff' )->escaped(),
360 'diff' => $this->revision
->getId(),
372 public function getHTML() {
373 $difflink = $this->context
->msg( 'parentheses' )
374 ->rawParams( $this->getDiffLink() )->escaped();
375 $revlink = $this->getRevisionLink();
376 $userlink = Linker
::revUserLink( $this->revision
);
377 $comment = Linker
::revComment( $this->revision
);
378 if ( $this->isDeleted() ) {
379 $revlink = "<span class=\"history-deleted\">$revlink</span>";
381 return "<li>$difflink $revlink $userlink $comment</li>";