r32934 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32933‎ | r32934 | r32935 >
Date:23:53, 7 April 2008
Author:aaron
Status:old
Tags:
Comment:
* Populate rev_parent_id
* Mark off and document some functions
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Revision.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1368,7 +1368,8 @@
13691369 'page' => $this->getId(),
13701370 'comment' => $summary,
13711371 'minor_edit' => $isminor,
1372 - 'text' => $text
 1372+ 'text' => $text,
 1373+ 'parent_id' => $lastRevision
13731374 ) );
13741375
13751376 $dbw->begin();
Index: trunk/phase3/includes/Revision.php
@@ -225,21 +225,13 @@
226226 * @static
227227 */
228228 private static function fetchFromConds( $db, $conditions ) {
 229+ $fields = self::selectFields();
 230+ $fields[] = 'page_namespace';
 231+ $fields[] = 'page_title';
 232+ $fields[] = 'page_latest';
229233 $res = $db->select(
230234 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' ),
 235+ $fields,
244236 $conditions,
245237 'Revision::fetchRow',
246238 array( 'LIMIT' => 1 ) );
@@ -258,11 +250,12 @@
259251 'rev_text_id',
260252 'rev_timestamp',
261253 'rev_comment',
 254+ 'rev_user_text,'.
 255+ 'rev_user',
262256 'rev_minor_edit',
263 - 'rev_user',
264 - 'rev_user_text,'.
265257 'rev_deleted',
266 - 'rev_len'
 258+ 'rev_len',
 259+ 'rev_parent_id'
267260 );
268261 }
269262
@@ -281,6 +274,7 @@
282275 $this->mMinorEdit = intval( $row->rev_minor_edit );
283276 $this->mTimestamp = $row->rev_timestamp;
284277 $this->mDeleted = intval( $row->rev_deleted );
 278+ $this->mParentId = intval( $row->rev_parent_id );
285279
286280 if( !isset( $row->rev_len ) || is_null( $row->rev_len ) )
287281 $this->mSize = null;
@@ -317,6 +311,7 @@
318312 $this->mTimestamp = isset( $row['timestamp'] ) ? strval( $row['timestamp'] ) : wfTimestamp( TS_MW );
319313 $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0;
320314 $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null;
 315+ $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : 0;
321316
322317 // Enforce spacing trimming on supplied text
323318 $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
@@ -338,23 +333,34 @@
339334 */
340335
341336 /**
 337+ * Get revision ID
342338 * @return int
343339 */
344 - function getId() {
 340+ public function getId() {
345341 return $this->mId;
346342 }
347343
348344 /**
 345+ * Get text row ID
349346 * @return int
350347 */
351 - function getTextId() {
 348+ public function getTextId() {
352349 return $this->mTextId;
353350 }
 351+
 352+ /**
 353+ * Get parent revision ID (the original previous page revision)
 354+ * @return int
 355+ */
 356+ public function getParentId() {
 357+ return $this->mParentId;
 358+ }
354359
355360 /**
356361 * Returns the length of the text in this revision, or null if unknown.
 362+ * @return int
357363 */
358 - function getSize() {
 364+ public function getSize() {
359365 return $this->mSize;
360366 }
361367
@@ -362,7 +368,7 @@
363369 * Returns the title of the page associated with this entry.
364370 * @return Title
365371 */
366 - function getTitle() {
 372+ public function getTitle() {
367373 if( isset( $this->mTitle ) ) {
368374 return $this->mTitle;
369375 }
@@ -384,14 +390,15 @@
385391 * Set the title of the revision
386392 * @param Title $title
387393 */
388 - function setTitle( $title ) {
 394+ public function setTitle( $title ) {
389395 $this->mTitle = $title;
390396 }
391397
392398 /**
 399+ * Get the page ID
393400 * @return int
394401 */
395 - function getPage() {
 402+ public function getPage() {
396403 return $this->mPage;
397404 }
398405
@@ -399,7 +406,7 @@
400407 * Fetch revision's user id if it's available to all users
401408 * @return int
402409 */
403 - function getUser() {
 410+ public function getUser() {
404411 if( $this->isDeleted( self::DELETED_USER ) ) {
405412 return 0;
406413 } else {
@@ -411,7 +418,7 @@
412419 * Fetch revision's user id without regard for the current user's permissions
413420 * @return string
414421 */
415 - function getRawUser() {
 422+ public function getRawUser() {
416423 return $this->mUser;
417424 }
418425
@@ -419,7 +426,7 @@
420427 * Fetch revision's username if it's available to all users
421428 * @return string
422429 */
423 - function getUserText() {
 430+ public function getUserText() {
424431 if( $this->isDeleted( self::DELETED_USER ) ) {
425432 return "";
426433 } else {
@@ -431,7 +438,7 @@
432439 * Fetch revision's username without regard for view restrictions
433440 * @return string
434441 */
435 - function getRawUserText() {
 442+ public function getRawUserText() {
436443 return $this->mUserText;
437444 }
438445
@@ -451,14 +458,14 @@
452459 * Fetch revision comment without regard for the current user's permissions
453460 * @return string
454461 */
455 - function getRawComment() {
 462+ public function getRawComment() {
456463 return $this->mComment;
457464 }
458465
459466 /**
460467 * @return bool
461468 */
462 - function isMinor() {
 469+ public function isMinor() {
463470 return (bool)$this->mMinorEdit;
464471 }
465472
@@ -466,7 +473,7 @@
467474 * int $field one of DELETED_* bitfield constants
468475 * @return bool
469476 */
470 - function isDeleted( $field ) {
 477+ public function isDeleted( $field ) {
471478 return ($this->mDeleted & $field) == $field;
472479 }
473480
@@ -474,7 +481,7 @@
475482 * Fetch revision text if it's available to all users
476483 * @return string
477484 */
478 - function getText() {
 485+ public function getText() {
479486 if( $this->isDeleted( self::DELETED_TEXT ) ) {
480487 return "";
481488 } else {
@@ -486,7 +493,7 @@
487494 * Fetch revision text without regard for view restrictions
488495 * @return string
489496 */
490 - function getRawText() {
 497+ public function getRawText() {
491498 if( is_null( $this->mText ) ) {
492499 // Revision text is immutable. Load on demand:
493500 $this->mText = $this->loadText();
@@ -498,7 +505,7 @@
499506 * Fetch revision text if it's available to THIS user
500507 * @return string
501508 */
502 - function revText() {
 509+ public function revText() {
503510 if( !$this->userCan( self::DELETED_TEXT ) ) {
504511 return "";
505512 } else {
@@ -509,23 +516,24 @@
510517 /**
511518 * @return string
512519 */
513 - function getTimestamp() {
 520+ public function getTimestamp() {
514521 return wfTimestamp(TS_MW, $this->mTimestamp);
515522 }
516523
517524 /**
518525 * @return bool
519526 */
520 - function isCurrent() {
 527+ public function isCurrent() {
521528 return $this->mCurrent;
522529 }
523530
524531 /**
 532+ * Get previous revision for this title
525533 * @return Revision
526534 */
527 - function getPrevious() {
 535+ public function getPrevious() {
528536 $prev = $this->mTitle->getPreviousRevisionID( $this->mId );
529 - if ( $prev ) {
 537+ if( $prev ) {
530538 return Revision::newFromTitle( $this->mTitle, $prev );
531539 } else {
532540 return null;
@@ -535,7 +543,7 @@
536544 /**
537545 * @return Revision
538546 */
539 - function getNext() {
 547+ public function getNext() {
540548 $next = $this->mTitle->getNextRevisionID( $this->mId );
541549 if ( $next ) {
542550 return Revision::newFromTitle( $this->mTitle, $next );
@@ -543,7 +551,35 @@
544552 return null;
545553 }
546554 }
547 - /**#@-*/
 555+
 556+ /**
 557+ * Get previous revision Id for this page_id
 558+ * This is used to populate rev_parent_id on save
 559+ * @param Database $db
 560+ * @return int
 561+ */
 562+ private function getPreviousRevisionId( $db ) {
 563+ if( is_null($this->mPage) ) {
 564+ return 0;
 565+ }
 566+ # Use page_latest if ID is not given
 567+ if( !$this->mId ) {
 568+ $revID = $db->selectField( 'page', 'page_latest',
 569+ array( 'page_id' => $this->mPage ),
 570+ __METHOD__ );
 571+ } else {
 572+ $revID = $this->mId;
 573+ }
 574+ if( !$revID ) {
 575+ return 0;
 576+ }
 577+ $prevId = $db->selectField( 'revision', 'rev_id',
 578+ array( 'rev_page' => $this->mPage, 'rev_id < ' . $revID ),
 579+ __METHOD__,
 580+ array( 'ORDER BY' => 'rev_id DESC' ) );
 581+ # Always return an integer
 582+ return intval($prevId);
 583+ }
548584
549585 /**
550586 * Get revision text associated with an old or archive row
@@ -627,7 +663,7 @@
628664 * @param mixed $text reference to a text
629665 * @return string
630666 */
631 - static function compressRevisionText( &$text ) {
 667+ public static function compressRevisionText( &$text ) {
632668 global $wgCompressRevisions;
633669 $flags = array();
634670
@@ -653,7 +689,7 @@
654690 * @param Database $dbw
655691 * @return int
656692 */
657 - function insertOn( &$dbw ) {
 693+ public function insertOn( &$dbw ) {
658694 global $wgDefaultExternalStore;
659695
660696 wfProfileIn( __METHOD__ );
@@ -710,6 +746,7 @@
711747 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ),
712748 'rev_deleted' => $this->mDeleted,
713749 'rev_len' => $this->mSize,
 750+ 'rev_parent_id' => $this->mParentId ? $this->mParentId : $this->getPreviousRevisionId( $dbw )
714751 ), __METHOD__
715752 );
716753
@@ -723,9 +760,8 @@
724761 * Currently hardcoded to the 'text' table storage engine.
725762 *
726763 * @return string
727 - * @access private
728764 */
729 - function loadText() {
 765+ private function loadText() {
730766 wfProfileIn( __METHOD__ );
731767
732768 // Caching may be beneficial for massive use of external storage
@@ -808,6 +844,7 @@
809845 'comment' => $summary,
810846 'minor_edit' => $minor,
811847 'text_id' => $current->rev_text_id,
 848+ 'parent_id' => $current->page_latest
812849 ) );
813850 } else {
814851 $revision = null;
@@ -825,7 +862,7 @@
826863 * self::DELETED_USER
827864 * @return bool
828865 */
829 - function userCan( $field ) {
 866+ public function userCan( $field ) {
830867 if( ( $this->mDeleted & $field ) == $field ) {
831868 global $wgUser;
832869 $permission = ( $this->mDeleted & self::DELETED_RESTRICTED ) == self::DELETED_RESTRICTED
@@ -856,6 +893,11 @@
857894 return $timestamp;
858895 }
859896
 897+ /**
 898+ * Get count of revisions per page...not very efficient
 899+ * @param Database $db
 900+ * @param int $id, page id
 901+ */
860902 static function countByPageId( $db, $id ) {
861903 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
862904 array( 'rev_page' => $id ), __METHOD__ );
@@ -865,6 +907,11 @@
866908 return 0;
867909 }
868910
 911+ /**
 912+ * Get count of revisions per page...not very efficient
 913+ * @param Database $db
 914+ * @param Title $title
 915+ */
869916 static function countByTitle( $db, $title ) {
870917 $id = $title->getArticleId();
871918 if( $id ) {

Status & tagging log