| Index: trunk/phase3/includes/Article.php |
| — | — | @@ -1368,7 +1368,8 @@ |
| 1369 | 1369 | 'page' => $this->getId(), |
| 1370 | 1370 | 'comment' => $summary, |
| 1371 | 1371 | 'minor_edit' => $isminor, |
| 1372 | | - 'text' => $text |
| | 1372 | + 'text' => $text, |
| | 1373 | + 'parent_id' => $lastRevision |
| 1373 | 1374 | ) ); |
| 1374 | 1375 | |
| 1375 | 1376 | $dbw->begin(); |
| Index: trunk/phase3/includes/Revision.php |
| — | — | @@ -225,21 +225,13 @@ |
| 226 | 226 | * @static |
| 227 | 227 | */ |
| 228 | 228 | private static function fetchFromConds( $db, $conditions ) { |
| | 229 | + $fields = self::selectFields(); |
| | 230 | + $fields[] = 'page_namespace'; |
| | 231 | + $fields[] = 'page_title'; |
| | 232 | + $fields[] = 'page_latest'; |
| 229 | 233 | $res = $db->select( |
| 230 | 234 | 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, |
| 244 | 236 | $conditions, |
| 245 | 237 | 'Revision::fetchRow', |
| 246 | 238 | array( 'LIMIT' => 1 ) ); |
| — | — | @@ -258,11 +250,12 @@ |
| 259 | 251 | 'rev_text_id', |
| 260 | 252 | 'rev_timestamp', |
| 261 | 253 | 'rev_comment', |
| | 254 | + 'rev_user_text,'. |
| | 255 | + 'rev_user', |
| 262 | 256 | 'rev_minor_edit', |
| 263 | | - 'rev_user', |
| 264 | | - 'rev_user_text,'. |
| 265 | 257 | 'rev_deleted', |
| 266 | | - 'rev_len' |
| | 258 | + 'rev_len', |
| | 259 | + 'rev_parent_id' |
| 267 | 260 | ); |
| 268 | 261 | } |
| 269 | 262 | |
| — | — | @@ -281,6 +274,7 @@ |
| 282 | 275 | $this->mMinorEdit = intval( $row->rev_minor_edit ); |
| 283 | 276 | $this->mTimestamp = $row->rev_timestamp; |
| 284 | 277 | $this->mDeleted = intval( $row->rev_deleted ); |
| | 278 | + $this->mParentId = intval( $row->rev_parent_id ); |
| 285 | 279 | |
| 286 | 280 | if( !isset( $row->rev_len ) || is_null( $row->rev_len ) ) |
| 287 | 281 | $this->mSize = null; |
| — | — | @@ -317,6 +311,7 @@ |
| 318 | 312 | $this->mTimestamp = isset( $row['timestamp'] ) ? strval( $row['timestamp'] ) : wfTimestamp( TS_MW ); |
| 319 | 313 | $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0; |
| 320 | 314 | $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null; |
| | 315 | + $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : 0; |
| 321 | 316 | |
| 322 | 317 | // Enforce spacing trimming on supplied text |
| 323 | 318 | $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null; |
| — | — | @@ -338,23 +333,34 @@ |
| 339 | 334 | */ |
| 340 | 335 | |
| 341 | 336 | /** |
| | 337 | + * Get revision ID |
| 342 | 338 | * @return int |
| 343 | 339 | */ |
| 344 | | - function getId() { |
| | 340 | + public function getId() { |
| 345 | 341 | return $this->mId; |
| 346 | 342 | } |
| 347 | 343 | |
| 348 | 344 | /** |
| | 345 | + * Get text row ID |
| 349 | 346 | * @return int |
| 350 | 347 | */ |
| 351 | | - function getTextId() { |
| | 348 | + public function getTextId() { |
| 352 | 349 | return $this->mTextId; |
| 353 | 350 | } |
| | 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 | + } |
| 354 | 359 | |
| 355 | 360 | /** |
| 356 | 361 | * Returns the length of the text in this revision, or null if unknown. |
| | 362 | + * @return int |
| 357 | 363 | */ |
| 358 | | - function getSize() { |
| | 364 | + public function getSize() { |
| 359 | 365 | return $this->mSize; |
| 360 | 366 | } |
| 361 | 367 | |
| — | — | @@ -362,7 +368,7 @@ |
| 363 | 369 | * Returns the title of the page associated with this entry. |
| 364 | 370 | * @return Title |
| 365 | 371 | */ |
| 366 | | - function getTitle() { |
| | 372 | + public function getTitle() { |
| 367 | 373 | if( isset( $this->mTitle ) ) { |
| 368 | 374 | return $this->mTitle; |
| 369 | 375 | } |
| — | — | @@ -384,14 +390,15 @@ |
| 385 | 391 | * Set the title of the revision |
| 386 | 392 | * @param Title $title |
| 387 | 393 | */ |
| 388 | | - function setTitle( $title ) { |
| | 394 | + public function setTitle( $title ) { |
| 389 | 395 | $this->mTitle = $title; |
| 390 | 396 | } |
| 391 | 397 | |
| 392 | 398 | /** |
| | 399 | + * Get the page ID |
| 393 | 400 | * @return int |
| 394 | 401 | */ |
| 395 | | - function getPage() { |
| | 402 | + public function getPage() { |
| 396 | 403 | return $this->mPage; |
| 397 | 404 | } |
| 398 | 405 | |
| — | — | @@ -399,7 +406,7 @@ |
| 400 | 407 | * Fetch revision's user id if it's available to all users |
| 401 | 408 | * @return int |
| 402 | 409 | */ |
| 403 | | - function getUser() { |
| | 410 | + public function getUser() { |
| 404 | 411 | if( $this->isDeleted( self::DELETED_USER ) ) { |
| 405 | 412 | return 0; |
| 406 | 413 | } else { |
| — | — | @@ -411,7 +418,7 @@ |
| 412 | 419 | * Fetch revision's user id without regard for the current user's permissions |
| 413 | 420 | * @return string |
| 414 | 421 | */ |
| 415 | | - function getRawUser() { |
| | 422 | + public function getRawUser() { |
| 416 | 423 | return $this->mUser; |
| 417 | 424 | } |
| 418 | 425 | |
| — | — | @@ -419,7 +426,7 @@ |
| 420 | 427 | * Fetch revision's username if it's available to all users |
| 421 | 428 | * @return string |
| 422 | 429 | */ |
| 423 | | - function getUserText() { |
| | 430 | + public function getUserText() { |
| 424 | 431 | if( $this->isDeleted( self::DELETED_USER ) ) { |
| 425 | 432 | return ""; |
| 426 | 433 | } else { |
| — | — | @@ -431,7 +438,7 @@ |
| 432 | 439 | * Fetch revision's username without regard for view restrictions |
| 433 | 440 | * @return string |
| 434 | 441 | */ |
| 435 | | - function getRawUserText() { |
| | 442 | + public function getRawUserText() { |
| 436 | 443 | return $this->mUserText; |
| 437 | 444 | } |
| 438 | 445 | |
| — | — | @@ -451,14 +458,14 @@ |
| 452 | 459 | * Fetch revision comment without regard for the current user's permissions |
| 453 | 460 | * @return string |
| 454 | 461 | */ |
| 455 | | - function getRawComment() { |
| | 462 | + public function getRawComment() { |
| 456 | 463 | return $this->mComment; |
| 457 | 464 | } |
| 458 | 465 | |
| 459 | 466 | /** |
| 460 | 467 | * @return bool |
| 461 | 468 | */ |
| 462 | | - function isMinor() { |
| | 469 | + public function isMinor() { |
| 463 | 470 | return (bool)$this->mMinorEdit; |
| 464 | 471 | } |
| 465 | 472 | |
| — | — | @@ -466,7 +473,7 @@ |
| 467 | 474 | * int $field one of DELETED_* bitfield constants |
| 468 | 475 | * @return bool |
| 469 | 476 | */ |
| 470 | | - function isDeleted( $field ) { |
| | 477 | + public function isDeleted( $field ) { |
| 471 | 478 | return ($this->mDeleted & $field) == $field; |
| 472 | 479 | } |
| 473 | 480 | |
| — | — | @@ -474,7 +481,7 @@ |
| 475 | 482 | * Fetch revision text if it's available to all users |
| 476 | 483 | * @return string |
| 477 | 484 | */ |
| 478 | | - function getText() { |
| | 485 | + public function getText() { |
| 479 | 486 | if( $this->isDeleted( self::DELETED_TEXT ) ) { |
| 480 | 487 | return ""; |
| 481 | 488 | } else { |
| — | — | @@ -486,7 +493,7 @@ |
| 487 | 494 | * Fetch revision text without regard for view restrictions |
| 488 | 495 | * @return string |
| 489 | 496 | */ |
| 490 | | - function getRawText() { |
| | 497 | + public function getRawText() { |
| 491 | 498 | if( is_null( $this->mText ) ) { |
| 492 | 499 | // Revision text is immutable. Load on demand: |
| 493 | 500 | $this->mText = $this->loadText(); |
| — | — | @@ -498,7 +505,7 @@ |
| 499 | 506 | * Fetch revision text if it's available to THIS user |
| 500 | 507 | * @return string |
| 501 | 508 | */ |
| 502 | | - function revText() { |
| | 509 | + public function revText() { |
| 503 | 510 | if( !$this->userCan( self::DELETED_TEXT ) ) { |
| 504 | 511 | return ""; |
| 505 | 512 | } else { |
| — | — | @@ -509,23 +516,24 @@ |
| 510 | 517 | /** |
| 511 | 518 | * @return string |
| 512 | 519 | */ |
| 513 | | - function getTimestamp() { |
| | 520 | + public function getTimestamp() { |
| 514 | 521 | return wfTimestamp(TS_MW, $this->mTimestamp); |
| 515 | 522 | } |
| 516 | 523 | |
| 517 | 524 | /** |
| 518 | 525 | * @return bool |
| 519 | 526 | */ |
| 520 | | - function isCurrent() { |
| | 527 | + public function isCurrent() { |
| 521 | 528 | return $this->mCurrent; |
| 522 | 529 | } |
| 523 | 530 | |
| 524 | 531 | /** |
| | 532 | + * Get previous revision for this title |
| 525 | 533 | * @return Revision |
| 526 | 534 | */ |
| 527 | | - function getPrevious() { |
| | 535 | + public function getPrevious() { |
| 528 | 536 | $prev = $this->mTitle->getPreviousRevisionID( $this->mId ); |
| 529 | | - if ( $prev ) { |
| | 537 | + if( $prev ) { |
| 530 | 538 | return Revision::newFromTitle( $this->mTitle, $prev ); |
| 531 | 539 | } else { |
| 532 | 540 | return null; |
| — | — | @@ -535,7 +543,7 @@ |
| 536 | 544 | /** |
| 537 | 545 | * @return Revision |
| 538 | 546 | */ |
| 539 | | - function getNext() { |
| | 547 | + public function getNext() { |
| 540 | 548 | $next = $this->mTitle->getNextRevisionID( $this->mId ); |
| 541 | 549 | if ( $next ) { |
| 542 | 550 | return Revision::newFromTitle( $this->mTitle, $next ); |
| — | — | @@ -543,7 +551,35 @@ |
| 544 | 552 | return null; |
| 545 | 553 | } |
| 546 | 554 | } |
| 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 | + } |
| 548 | 584 | |
| 549 | 585 | /** |
| 550 | 586 | * Get revision text associated with an old or archive row |
| — | — | @@ -627,7 +663,7 @@ |
| 628 | 664 | * @param mixed $text reference to a text |
| 629 | 665 | * @return string |
| 630 | 666 | */ |
| 631 | | - static function compressRevisionText( &$text ) { |
| | 667 | + public static function compressRevisionText( &$text ) { |
| 632 | 668 | global $wgCompressRevisions; |
| 633 | 669 | $flags = array(); |
| 634 | 670 | |
| — | — | @@ -653,7 +689,7 @@ |
| 654 | 690 | * @param Database $dbw |
| 655 | 691 | * @return int |
| 656 | 692 | */ |
| 657 | | - function insertOn( &$dbw ) { |
| | 693 | + public function insertOn( &$dbw ) { |
| 658 | 694 | global $wgDefaultExternalStore; |
| 659 | 695 | |
| 660 | 696 | wfProfileIn( __METHOD__ ); |
| — | — | @@ -710,6 +746,7 @@ |
| 711 | 747 | 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ), |
| 712 | 748 | 'rev_deleted' => $this->mDeleted, |
| 713 | 749 | 'rev_len' => $this->mSize, |
| | 750 | + 'rev_parent_id' => $this->mParentId ? $this->mParentId : $this->getPreviousRevisionId( $dbw ) |
| 714 | 751 | ), __METHOD__ |
| 715 | 752 | ); |
| 716 | 753 | |
| — | — | @@ -723,9 +760,8 @@ |
| 724 | 761 | * Currently hardcoded to the 'text' table storage engine. |
| 725 | 762 | * |
| 726 | 763 | * @return string |
| 727 | | - * @access private |
| 728 | 764 | */ |
| 729 | | - function loadText() { |
| | 765 | + private function loadText() { |
| 730 | 766 | wfProfileIn( __METHOD__ ); |
| 731 | 767 | |
| 732 | 768 | // Caching may be beneficial for massive use of external storage |
| — | — | @@ -808,6 +844,7 @@ |
| 809 | 845 | 'comment' => $summary, |
| 810 | 846 | 'minor_edit' => $minor, |
| 811 | 847 | 'text_id' => $current->rev_text_id, |
| | 848 | + 'parent_id' => $current->page_latest |
| 812 | 849 | ) ); |
| 813 | 850 | } else { |
| 814 | 851 | $revision = null; |
| — | — | @@ -825,7 +862,7 @@ |
| 826 | 863 | * self::DELETED_USER |
| 827 | 864 | * @return bool |
| 828 | 865 | */ |
| 829 | | - function userCan( $field ) { |
| | 866 | + public function userCan( $field ) { |
| 830 | 867 | if( ( $this->mDeleted & $field ) == $field ) { |
| 831 | 868 | global $wgUser; |
| 832 | 869 | $permission = ( $this->mDeleted & self::DELETED_RESTRICTED ) == self::DELETED_RESTRICTED |
| — | — | @@ -856,6 +893,11 @@ |
| 857 | 894 | return $timestamp; |
| 858 | 895 | } |
| 859 | 896 | |
| | 897 | + /** |
| | 898 | + * Get count of revisions per page...not very efficient |
| | 899 | + * @param Database $db |
| | 900 | + * @param int $id, page id |
| | 901 | + */ |
| 860 | 902 | static function countByPageId( $db, $id ) { |
| 861 | 903 | $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount', |
| 862 | 904 | array( 'rev_page' => $id ), __METHOD__ ); |
| — | — | @@ -865,6 +907,11 @@ |
| 866 | 908 | return 0; |
| 867 | 909 | } |
| 868 | 910 | |
| | 911 | + /** |
| | 912 | + * Get count of revisions per page...not very efficient |
| | 913 | + * @param Database $db |
| | 914 | + * @param Title $title |
| | 915 | + */ |
| 869 | 916 | static function countByTitle( $db, $title ) { |
| 870 | 917 | $id = $title->getArticleId(); |
| 871 | 918 | if( $id ) { |