update relnotes
[lhc/web/wiklou.git] / includes / Revision.php
1 <?php
2 /**
3 * @todo document
4 */
5
6 /**
7 * @todo document
8 */
9 class Revision {
10 const DELETED_TEXT = 1;
11 const DELETED_COMMENT = 2;
12 const DELETED_USER = 4;
13 const DELETED_RESTRICTED = 8;
14 const DELETED_NAME = 16;
15
16 /**
17 * Load a page revision from a given revision ID number.
18 * Returns null if no such revision can be found.
19 *
20 * @param int $id
21 * @access public
22 * @static
23 */
24 public static function newFromId( $id ) {
25 return Revision::newFromConds(
26 array( 'page_id=rev_page',
27 'rev_id' => intval( $id ) ) );
28 }
29
30 /**
31 * Load either the current, or a specified, revision
32 * that's attached to a given title. If not attached
33 * to that title, will return null.
34 *
35 * @param Title $title
36 * @param int $id
37 * @return Revision
38 * @access public
39 * @static
40 */
41 public static function newFromTitle( &$title, $id = 0 ) {
42 if( $id ) {
43 $matchId = intval( $id );
44 } else {
45 $matchId = 'page_latest';
46 }
47 return Revision::newFromConds(
48 array( "rev_id=$matchId",
49 'page_id=rev_page',
50 'page_namespace' => $title->getNamespace(),
51 'page_title' => $title->getDbkey() ) );
52 }
53
54 /**
55 * Load a page revision from a given revision ID number.
56 * Returns null if no such revision can be found.
57 *
58 * @param Database $db
59 * @param int $id
60 * @access public
61 * @static
62 */
63 public static function loadFromId( &$db, $id ) {
64 return Revision::loadFromConds( $db,
65 array( 'page_id=rev_page',
66 'rev_id' => intval( $id ) ) );
67 }
68
69 /**
70 * Load either the current, or a specified, revision
71 * that's attached to a given page. If not attached
72 * to that page, will return null.
73 *
74 * @param Database $db
75 * @param int $pageid
76 * @param int $id
77 * @return Revision
78 * @access public
79 * @static
80 */
81 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
82 $conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid ));
83 if( $id ) {
84 $conds['rev_id']=intval($id);
85 } else {
86 $conds[]='rev_id=page_latest';
87 }
88 return Revision::loadFromConds( $db, $conds );
89 }
90
91 /**
92 * Load either the current, or a specified, revision
93 * that's attached to a given page. If not attached
94 * to that page, will return null.
95 *
96 * @param Database $db
97 * @param Title $title
98 * @param int $id
99 * @return Revision
100 * @access public
101 * @static
102 */
103 public static function loadFromTitle( &$db, $title, $id = 0 ) {
104 if( $id ) {
105 $matchId = intval( $id );
106 } else {
107 $matchId = 'page_latest';
108 }
109 return Revision::loadFromConds(
110 $db,
111 array( "rev_id=$matchId",
112 'page_id=rev_page',
113 'page_namespace' => $title->getNamespace(),
114 'page_title' => $title->getDbkey() ) );
115 }
116
117 /**
118 * Load the revision for the given title with the given timestamp.
119 * WARNING: Timestamps may in some circumstances not be unique,
120 * so this isn't the best key to use.
121 *
122 * @param Database $db
123 * @param Title $title
124 * @param string $timestamp
125 * @return Revision
126 * @access public
127 * @static
128 */
129 public static function loadFromTimestamp( &$db, &$title, $timestamp ) {
130 return Revision::loadFromConds(
131 $db,
132 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
133 'page_id=rev_page',
134 'page_namespace' => $title->getNamespace(),
135 'page_title' => $title->getDbkey() ) );
136 }
137
138 /**
139 * Given a set of conditions, fetch a revision.
140 *
141 * @param array $conditions
142 * @return Revision
143 * @access private
144 * @static
145 */
146 private static function newFromConds( $conditions ) {
147 $db = wfGetDB( DB_SLAVE );
148 $row = Revision::loadFromConds( $db, $conditions );
149 if( is_null( $row ) ) {
150 $dbw = wfGetDB( DB_MASTER );
151 $row = Revision::loadFromConds( $dbw, $conditions );
152 }
153 return $row;
154 }
155
156 /**
157 * Given a set of conditions, fetch a revision from
158 * the given database connection.
159 *
160 * @param Database $db
161 * @param array $conditions
162 * @return Revision
163 * @access private
164 * @static
165 */
166 private static function loadFromConds( $db, $conditions ) {
167 $res = Revision::fetchFromConds( $db, $conditions );
168 if( $res ) {
169 $row = $res->fetchObject();
170 $res->free();
171 if( $row ) {
172 $ret = new Revision( $row );
173 return $ret;
174 }
175 }
176 $ret = null;
177 return $ret;
178 }
179
180 /**
181 * Return a wrapper for a series of database rows to
182 * fetch all of a given page's revisions in turn.
183 * Each row can be fed to the constructor to get objects.
184 *
185 * @param Title $title
186 * @return ResultWrapper
187 * @access public
188 * @static
189 */
190 public static function fetchAllRevisions( &$title ) {
191 return Revision::fetchFromConds(
192 wfGetDB( DB_SLAVE ),
193 array( 'page_namespace' => $title->getNamespace(),
194 'page_title' => $title->getDbkey(),
195 'page_id=rev_page' ) );
196 }
197
198 /**
199 * Return a wrapper for a series of database rows to
200 * fetch all of a given page's revisions in turn.
201 * Each row can be fed to the constructor to get objects.
202 *
203 * @param Title $title
204 * @return ResultWrapper
205 * @access public
206 * @static
207 */
208 public static function fetchRevision( &$title ) {
209 return Revision::fetchFromConds(
210 wfGetDB( DB_SLAVE ),
211 array( 'rev_id=page_latest',
212 'page_namespace' => $title->getNamespace(),
213 'page_title' => $title->getDbkey(),
214 'page_id=rev_page' ) );
215 }
216
217 /**
218 * Given a set of conditions, return a ResultWrapper
219 * which will return matching database rows with the
220 * fields necessary to build Revision objects.
221 *
222 * @param Database $db
223 * @param array $conditions
224 * @return ResultWrapper
225 * @access private
226 * @static
227 */
228 private static function fetchFromConds( $db, $conditions ) {
229 $res = $db->select(
230 array( 'page', 'revision' ),
231 array( 'page_namespace',
232 'page_title',
233 'page_latest',
234 'rev_id',
235 'rev_page',
236 'rev_text_id',
237 'rev_comment',
238 'rev_user_text',
239 'rev_user',
240 'rev_minor_edit',
241 'rev_timestamp',
242 'rev_deleted',
243 'rev_len' ),
244 $conditions,
245 'Revision::fetchRow',
246 array( 'LIMIT' => 1 ) );
247 $ret = $db->resultObject( $res );
248 return $ret;
249 }
250
251 /**
252 * Return the list of revision fields that should be selected to create
253 * a new revision.
254 */
255 static function selectFields() {
256 return array(
257 'rev_id',
258 'rev_page',
259 'rev_text_id',
260 'rev_timestamp',
261 'rev_comment',
262 'rev_minor_edit',
263 'rev_user',
264 'rev_user_text,'.
265 'rev_deleted',
266 'rev_len'
267 );
268 }
269
270 /**
271 * @param object $row
272 * @access private
273 */
274 function Revision( $row ) {
275 if( is_object( $row ) ) {
276 $this->mId = intval( $row->rev_id );
277 $this->mPage = intval( $row->rev_page );
278 $this->mTextId = intval( $row->rev_text_id );
279 $this->mComment = $row->rev_comment;
280 $this->mUserText = $row->rev_user_text;
281 $this->mUser = intval( $row->rev_user );
282 $this->mMinorEdit = intval( $row->rev_minor_edit );
283 $this->mTimestamp = $row->rev_timestamp;
284 $this->mDeleted = intval( $row->rev_deleted );
285
286 if( is_null( $row->rev_len ) )
287 $this->mSize = null;
288 else
289 $this->mSize = intval( $row->rev_len );
290
291 if( isset( $row->page_latest ) ) {
292 $this->mCurrent = ( $row->rev_id == $row->page_latest );
293 $this->mTitle = Title::makeTitle( $row->page_namespace,
294 $row->page_title );
295 } else {
296 $this->mCurrent = false;
297 $this->mTitle = null;
298 }
299
300 // Lazy extraction...
301 $this->mText = null;
302 if( isset( $row->old_text ) ) {
303 $this->mTextRow = $row;
304 } else {
305 // 'text' table row entry will be lazy-loaded
306 $this->mTextRow = null;
307 }
308 } elseif( is_array( $row ) ) {
309 // Build a new revision to be saved...
310 global $wgUser;
311
312 $this->mId = isset( $row['id'] ) ? intval( $row['id'] ) : null;
313 $this->mPage = isset( $row['page'] ) ? intval( $row['page'] ) : null;
314 $this->mTextId = isset( $row['text_id'] ) ? intval( $row['text_id'] ) : null;
315 $this->mUserText = isset( $row['user_text'] ) ? strval( $row['user_text'] ) : $wgUser->getName();
316 $this->mUser = isset( $row['user'] ) ? intval( $row['user'] ) : $wgUser->getId();
317 $this->mMinorEdit = isset( $row['minor_edit'] ) ? intval( $row['minor_edit'] ) : 0;
318 $this->mTimestamp = isset( $row['timestamp'] ) ? strval( $row['timestamp'] ) : wfTimestamp( TS_MW );
319 $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0;
320
321 // Enforce spacing trimming on supplied text
322 $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
323 $this->mText = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null;
324 $this->mTextRow = null;
325
326 $this->mTitle = null; # Load on demand if needed
327 $this->mCurrent = false;
328
329 $this->mSize = is_null($this->mText) ? null : strlen($this->mText);
330 } else {
331 throw new MWException( 'Revision constructor passed invalid row format.' );
332 }
333 }
334
335 /**#@+
336 * @access public
337 */
338
339 /**
340 * @return int
341 */
342 function getId() {
343 return $this->mId;
344 }
345
346 /**
347 * @return int
348 */
349 function getTextId() {
350 return $this->mTextId;
351 }
352
353 /**
354 * Returns the length of the text in this revision, or null if unknown.
355 */
356 function getSize() {
357 return $this->mSize;
358 }
359
360 /**
361 * Returns the title of the page associated with this entry.
362 * @return Title
363 */
364 function getTitle() {
365 if( isset( $this->mTitle ) ) {
366 return $this->mTitle;
367 }
368 $dbr = wfGetDB( DB_SLAVE );
369 $row = $dbr->selectRow(
370 array( 'page', 'revision' ),
371 array( 'page_namespace', 'page_title' ),
372 array( 'page_id=rev_page',
373 'rev_id' => $this->mId ),
374 'Revision::getTitle' );
375 if( $row ) {
376 $this->mTitle = Title::makeTitle( $row->page_namespace,
377 $row->page_title );
378 }
379 return $this->mTitle;
380 }
381
382 /**
383 * Set the title of the revision
384 * @param Title $title
385 */
386 function setTitle( $title ) {
387 $this->mTitle = $title;
388 }
389
390 /**
391 * @return int
392 */
393 function getPage() {
394 return $this->mPage;
395 }
396
397 /**
398 * Fetch revision's user id if it's available to all users
399 * @return int
400 */
401 function getUser() {
402 if( $this->isDeleted( self::DELETED_USER ) ) {
403 return 0;
404 } else {
405 return $this->mUser;
406 }
407 }
408
409 /**
410 * Fetch revision's user id without regard for the current user's permissions
411 * @return string
412 */
413 function getRawUser() {
414 return $this->mUser;
415 }
416
417 /**
418 * Fetch revision's username if it's available to all users
419 * @return string
420 */
421 function getUserText() {
422 if( $this->isDeleted( self::DELETED_USER ) ) {
423 return "";
424 } else {
425 return $this->mUserText;
426 }
427 }
428
429 /**
430 * Fetch revision's username without regard for view restrictions
431 * @return string
432 */
433 function getRawUserText() {
434 return $this->mUserText;
435 }
436
437 /**
438 * Fetch revision comment if it's available to all users
439 * @return string
440 */
441 function getComment() {
442 if( $this->isDeleted( self::DELETED_COMMENT ) ) {
443 return "";
444 } else {
445 return $this->mComment;
446 }
447 }
448
449 /**
450 * Fetch revision comment without regard for the current user's permissions
451 * @return string
452 */
453 function getRawComment() {
454 return $this->mComment;
455 }
456
457 /**
458 * @return bool
459 */
460 function isMinor() {
461 return (bool)$this->mMinorEdit;
462 }
463
464 /**
465 * int $field one of DELETED_* bitfield constants
466 * @return bool
467 */
468 function isDeleted( $field ) {
469 return ($this->mDeleted & $field) == $field;
470 }
471
472 /**
473 * Fetch revision text if it's available to all users
474 * @return string
475 */
476 function getText() {
477 if( $this->isDeleted( self::DELETED_TEXT ) ) {
478 return "";
479 } else {
480 return $this->getRawText();
481 }
482 }
483
484 /**
485 * Fetch revision text without regard for view restrictions
486 * @return string
487 */
488 function getRawText() {
489 if( is_null( $this->mText ) ) {
490 // Revision text is immutable. Load on demand:
491 $this->mText = $this->loadText();
492 }
493 return $this->mText;
494 }
495
496 /**
497 * Fetch revision text if it's available to THIS user
498 * @return string
499 */
500 function revText() {
501 if( !$this->userCan( self::DELETED_TEXT ) ) {
502 return "";
503 } else {
504 return $this->getRawText();
505 }
506 }
507
508 /**
509 * @return string
510 */
511 function getTimestamp() {
512 return wfTimestamp(TS_MW, $this->mTimestamp);
513 }
514
515 /**
516 * @return bool
517 */
518 function isCurrent() {
519 return $this->mCurrent;
520 }
521
522 /**
523 * @return Revision
524 */
525 function getPrevious() {
526 $prev = $this->mTitle->getPreviousRevisionID( $this->mId );
527 if ( $prev ) {
528 return Revision::newFromTitle( $this->mTitle, $prev );
529 } else {
530 return null;
531 }
532 }
533
534 /**
535 * @return Revision
536 */
537 function getNext() {
538 $next = $this->mTitle->getNextRevisionID( $this->mId );
539 if ( $next ) {
540 return Revision::newFromTitle( $this->mTitle, $next );
541 } else {
542 return null;
543 }
544 }
545 /**#@-*/
546
547 /**
548 * Get revision text associated with an old or archive row
549 * $row is usually an object from wfFetchRow(), both the flags and the text
550 * field must be included
551 * @static
552 * @param integer $row Id of a row
553 * @param string $prefix table prefix (default 'old_')
554 * @return string $text|false the text requested
555 */
556 public static function getRevisionText( $row, $prefix = 'old_' ) {
557 $fname = 'Revision::getRevisionText';
558 wfProfileIn( $fname );
559
560 # Get data
561 $textField = $prefix . 'text';
562 $flagsField = $prefix . 'flags';
563
564 if( isset( $row->$flagsField ) ) {
565 $flags = explode( ',', $row->$flagsField );
566 } else {
567 $flags = array();
568 }
569
570 if( isset( $row->$textField ) ) {
571 $text = $row->$textField;
572 } else {
573 wfProfileOut( $fname );
574 return false;
575 }
576
577 # Use external methods for external objects, text in table is URL-only then
578 if ( in_array( 'external', $flags ) ) {
579 $url=$text;
580 @list(/* $proto */,$path)=explode('://',$url,2);
581 if ($path=="") {
582 wfProfileOut( $fname );
583 return false;
584 }
585 $text=ExternalStore::fetchFromURL($url);
586 }
587
588 // If the text was fetched without an error, convert it
589 if ( $text !== false ) {
590 if( in_array( 'gzip', $flags ) ) {
591 # Deal with optional compression of archived pages.
592 # This can be done periodically via maintenance/compressOld.php, and
593 # as pages are saved if $wgCompressRevisions is set.
594 $text = gzinflate( $text );
595 }
596
597 if( in_array( 'object', $flags ) ) {
598 # Generic compressed storage
599 $obj = unserialize( $text );
600 if ( !is_object( $obj ) ) {
601 // Invalid object
602 wfProfileOut( $fname );
603 return false;
604 }
605 $text = $obj->getText();
606 }
607
608 global $wgLegacyEncoding;
609 if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) {
610 # Old revisions kept around in a legacy encoding?
611 # Upconvert on demand.
612 global $wgInputEncoding, $wgContLang;
613 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding . '//IGNORE', $text );
614 }
615 }
616 wfProfileOut( $fname );
617 return $text;
618 }
619
620 /**
621 * If $wgCompressRevisions is enabled, we will compress data.
622 * The input string is modified in place.
623 * Return value is the flags field: contains 'gzip' if the
624 * data is compressed, and 'utf-8' if we're saving in UTF-8
625 * mode.
626 *
627 * @static
628 * @param mixed $text reference to a text
629 * @return string
630 */
631 function compressRevisionText( &$text ) {
632 global $wgCompressRevisions;
633 $flags = array();
634
635 # Revisions not marked this way will be converted
636 # on load if $wgLegacyCharset is set in the future.
637 $flags[] = 'utf-8';
638
639 if( $wgCompressRevisions ) {
640 if( function_exists( 'gzdeflate' ) ) {
641 $text = gzdeflate( $text );
642 $flags[] = 'gzip';
643 } else {
644 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
645 }
646 }
647 return implode( ',', $flags );
648 }
649
650 /**
651 * Insert a new revision into the database, returning the new revision ID
652 * number on success and dies horribly on failure.
653 *
654 * @param Database $dbw
655 * @return int
656 */
657 function insertOn( &$dbw ) {
658 global $wgDefaultExternalStore;
659
660 $fname = 'Revision::insertOn';
661 wfProfileIn( $fname );
662
663 $data = $this->mText;
664 $flags = Revision::compressRevisionText( $data );
665
666 # Write to external storage if required
667 if ( $wgDefaultExternalStore ) {
668 if ( is_array( $wgDefaultExternalStore ) ) {
669 // Distribute storage across multiple clusters
670 $store = $wgDefaultExternalStore[mt_rand(0, count( $wgDefaultExternalStore ) - 1)];
671 } else {
672 $store = $wgDefaultExternalStore;
673 }
674 // Store and get the URL
675 $data = ExternalStore::insert( $store, $data );
676 if ( !$data ) {
677 # This should only happen in the case of a configuration error, where the external store is not valid
678 throw new MWException( "Unable to store text to external storage $store" );
679 }
680 if ( $flags ) {
681 $flags .= ',';
682 }
683 $flags .= 'external';
684 }
685
686 # Record the text (or external storage URL) to the text table
687 if( !isset( $this->mTextId ) ) {
688 $old_id = $dbw->nextSequenceValue( 'text_old_id_val' );
689 $dbw->insert( 'text',
690 array(
691 'old_id' => $old_id,
692 'old_text' => $data,
693 'old_flags' => $flags,
694 ), $fname
695 );
696 $this->mTextId = $dbw->insertId();
697 }
698
699 # Record the edit in revisions
700 $rev_id = isset( $this->mId )
701 ? $this->mId
702 : $dbw->nextSequenceValue( 'rev_rev_id_val' );
703 $dbw->insert( 'revision',
704 array(
705 'rev_id' => $rev_id,
706 'rev_page' => $this->mPage,
707 'rev_text_id' => $this->mTextId,
708 'rev_comment' => $this->mComment,
709 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0,
710 'rev_user' => $this->mUser,
711 'rev_user_text' => $this->mUserText,
712 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ),
713 'rev_deleted' => $this->mDeleted,
714 'rev_len' => strlen($this->mText),
715 ), $fname
716 );
717
718 $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
719 wfProfileOut( $fname );
720 return $this->mId;
721 }
722
723 /**
724 * Lazy-load the revision's text.
725 * Currently hardcoded to the 'text' table storage engine.
726 *
727 * @return string
728 * @access private
729 */
730 function loadText() {
731 $fname = 'Revision::loadText';
732 wfProfileIn( $fname );
733
734 // Caching may be beneficial for massive use of external storage
735 global $wgRevisionCacheExpiry, $wgMemc;
736 $key = wfMemcKey( 'revisiontext', 'textid', $this->getTextId() );
737 if( $wgRevisionCacheExpiry ) {
738 $text = $wgMemc->get( $key );
739 if( is_string( $text ) ) {
740 wfProfileOut( $fname );
741 return $text;
742 }
743 }
744
745 // If we kept data for lazy extraction, use it now...
746 if ( isset( $this->mTextRow ) ) {
747 $row = $this->mTextRow;
748 $this->mTextRow = null;
749 } else {
750 $row = null;
751 }
752
753 if( !$row ) {
754 // Text data is immutable; check slaves first.
755 $dbr = wfGetDB( DB_SLAVE );
756 $row = $dbr->selectRow( 'text',
757 array( 'old_text', 'old_flags' ),
758 array( 'old_id' => $this->getTextId() ),
759 $fname);
760 }
761
762 if( !$row ) {
763 // Possible slave lag!
764 $dbw = wfGetDB( DB_MASTER );
765 $row = $dbw->selectRow( 'text',
766 array( 'old_text', 'old_flags' ),
767 array( 'old_id' => $this->getTextId() ),
768 $fname);
769 }
770
771 $text = Revision::getRevisionText( $row );
772
773 if( $wgRevisionCacheExpiry ) {
774 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
775 }
776
777 wfProfileOut( $fname );
778
779 return $text;
780 }
781
782 /**
783 * Create a new null-revision for insertion into a page's
784 * history. This will not re-save the text, but simply refer
785 * to the text from the previous version.
786 *
787 * Such revisions can for instance identify page rename
788 * operations and other such meta-modifications.
789 *
790 * @param Database $dbw
791 * @param int $pageId ID number of the page to read from
792 * @param string $summary
793 * @param bool $minor
794 * @return Revision
795 */
796 function newNullRevision( &$dbw, $pageId, $summary, $minor ) {
797 $fname = 'Revision::newNullRevision';
798 wfProfileIn( $fname );
799
800 $current = $dbw->selectRow(
801 array( 'page', 'revision' ),
802 array( 'page_latest', 'rev_text_id' ),
803 array(
804 'page_id' => $pageId,
805 'page_latest=rev_id',
806 ),
807 $fname );
808
809 if( $current ) {
810 $revision = new Revision( array(
811 'page' => $pageId,
812 'comment' => $summary,
813 'minor_edit' => $minor,
814 'text_id' => $current->rev_text_id,
815 ) );
816 } else {
817 $revision = null;
818 }
819
820 wfProfileOut( $fname );
821 return $revision;
822 }
823
824 /**
825 * Determine if the current user is allowed to view a particular
826 * field of this revision, if it's marked as deleted.
827 * @param int $field one of self::DELETED_TEXT,
828 * self::DELETED_COMMENT,
829 * self::DELETED_USER
830 * @return bool
831 */
832 function userCan( $field ) {
833 if( ( $this->mDeleted & $field ) == $field ) {
834 global $wgUser;
835 $permission = ( $this->mDeleted & self::DELETED_RESTRICTED ) == self::DELETED_RESTRICTED
836 ? 'hiderevision'
837 : 'deleterevision';
838 wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
839 return $wgUser->isAllowed( $permission );
840 } else {
841 return true;
842 }
843 }
844
845
846 /**
847 * Get rev_timestamp from rev_id, without loading the rest of the row
848 * @param integer $id
849 */
850 static function getTimestampFromID( $id ) {
851 $dbr = wfGetDB( DB_SLAVE );
852 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp',
853 array( 'rev_id' => $id ), __METHOD__ );
854 if ( $timestamp === false ) {
855 # Not in slave, try master
856 $dbw = wfGetDB( DB_MASTER );
857 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp',
858 array( 'rev_id' => $id ), __METHOD__ );
859 }
860 return $timestamp;
861 }
862
863 static function countByPageId( $db, $id ) {
864 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
865 array( 'rev_page' => $id ), __METHOD__ );
866 if( $row ) {
867 return $row->revCount;
868 }
869 return 0;
870 }
871
872 static function countByTitle( $db, $title ) {
873 $id = $title->getArticleId();
874 if( $id ) {
875 return Revision::countByPageId( $db, $id );
876 }
877 return 0;
878 }
879 }
880
881 /**
882 * Aliases for backwards compatibility with 1.6
883 */
884 define( 'MW_REV_DELETED_TEXT', Revision::DELETED_TEXT );
885 define( 'MW_REV_DELETED_COMMENT', Revision::DELETED_COMMENT );
886 define( 'MW_REV_DELETED_USER', Revision::DELETED_USER );
887 define( 'MW_REV_DELETED_RESTRICTED', Revision::DELETED_RESTRICTED );
888
889
890 ?>