Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -317,6 +317,39 @@ |
318 | 318 | |
319 | 319 | return $flags; |
320 | 320 | } |
| 321 | + |
| 322 | + /** |
| 323 | + * static counterpart for getOverridingRev() |
| 324 | + */ |
| 325 | + public static function getOverridingPageRev( $article ) { |
| 326 | + if ( !is_object($article) ) |
| 327 | + return null; |
| 328 | + |
| 329 | + $title = $article->getTitle(); |
| 330 | + |
| 331 | + $dbr = wfGetDB( DB_SLAVE ); |
| 332 | + // Skip deleted revisions |
| 333 | + $result = $dbr->select( |
| 334 | + array('flaggedrevs', 'revision'), |
| 335 | + array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'), |
| 336 | + array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1', |
| 337 | + 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'), |
| 338 | + __METHOD__, |
| 339 | + array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) ); |
| 340 | + // Do we have one? |
| 341 | + if( !$row = $dbr->fetchObject($result) ) { |
| 342 | + $result = $dbr->select( |
| 343 | + array('flaggedrevs', 'revision'), |
| 344 | + array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'), |
| 345 | + array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1', |
| 346 | + 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'), |
| 347 | + __METHOD__, |
| 348 | + array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) ); |
| 349 | + if( !$row = $dbr->fetchObject($result) ) |
| 350 | + return null; |
| 351 | + } |
| 352 | + return $row; |
| 353 | + } |
321 | 354 | |
322 | 355 | public function addTagRatings( $flags ) { |
323 | 356 | global $wgFlaggedRevTags; |
— | — | @@ -354,6 +387,46 @@ |
355 | 388 | } |
356 | 389 | |
357 | 390 | /** |
| 391 | + * @param Array $flags |
| 392 | + * @output bool, is this revision at quality condition? |
| 393 | + */ |
| 394 | + public static function isQuality( $flags ) { |
| 395 | + global $wgFlaggedRevTags; |
| 396 | + |
| 397 | + foreach ( $wgFlaggedRevTags as $f => $v ) { |
| 398 | + if ( !isset($flags[$f]) || $v > $flags[$f] ) return false; |
| 399 | + } |
| 400 | + return true; |
| 401 | + } |
| 402 | + |
| 403 | + /** |
| 404 | + * @param Array $flags |
| 405 | + * @output bool, is this revision at optimal condition? |
| 406 | + */ |
| 407 | + public static function isPristine( $flags ) { |
| 408 | + global $wgFlaggedRevValues; |
| 409 | + |
| 410 | + foreach ( $flags as $f => $v ) { |
| 411 | + if ( $v < $wgFlaggedRevValues ) return false; |
| 412 | + } |
| 413 | + return true; |
| 414 | + } |
| 415 | + |
| 416 | + /** |
| 417 | + * @param Array $flags |
| 418 | + * @output integer, lowest rating level |
| 419 | + */ |
| 420 | + public static function getLCQuality( $flags ) { |
| 421 | + global $wgFlaggedRevValues; |
| 422 | + |
| 423 | + $min = false; |
| 424 | + foreach ( $flags as $f => $v ) { |
| 425 | + if ( $min==false || $v < $min ) $min = $v; |
| 426 | + } |
| 427 | + return $min; |
| 428 | + } |
| 429 | + |
| 430 | + /** |
358 | 431 | * @param Article $article |
359 | 432 | * Get the page cache for the top stable revision of an article |
360 | 433 | */ |
— | — | @@ -435,7 +508,81 @@ |
436 | 509 | |
437 | 510 | return true; |
438 | 511 | } |
| 512 | + |
| 513 | + function updateFromMove( &$movePageForm , &$oldtitle , &$newtitle ) { |
| 514 | + $dbw = wfGetDB( DB_MASTER ); |
| 515 | + $dbw->update( 'flaggedrevs', |
| 516 | + array('fr_namespace' => $newtitle->getNamespace(), 'fr_title' => $newtitle->getDBkey() ), |
| 517 | + array('fr_namespace' => $oldtitle->getNamespace(), 'fr_title' => $oldtitle->getDBkey() ), |
| 518 | + __METHOD__ ); |
| 519 | + } |
| 520 | + |
| 521 | + function extraLinksUpdate( &$article ) { |
| 522 | + $fname = 'FlaggedRevs::doIncrementalUpdate'; |
| 523 | + wfProfileIn( $fname ); |
| 524 | + # Check if this page has a stable version |
| 525 | + $sv = $this->getOverridingPageRev( $article ); |
| 526 | + if ( !$row ) return; |
| 527 | + # Retrieve the text |
| 528 | + $text = $this->getFlaggedRevText( $sv->fr_rev_id ); |
| 529 | + # Parse the revision |
| 530 | + $options = ParserOptions::newFromUser($wgUser); |
| 531 | + $poutput = $this->parseStableText( $article->mTitle, $text, $sv->fr_rev_id, $options, $sv->fr_timestamp ); |
| 532 | + |
| 533 | + # Update the links tables to include these |
| 534 | + # We want the UNION of links between the current |
| 535 | + # and stable version. Therefore, we only care about |
| 536 | + # links that are in the stable version and not the regular one. |
| 537 | + $u = new LinksUpdate( $article->mTitle, $poutput ); |
| 538 | + |
| 539 | + # Page links |
| 540 | + $existing = $u->getExistingLinks(); |
| 541 | + $u->incrTableUpdate( 'pagelinks', 'pl', array(), |
| 542 | + $u->getLinkInsertions( $existing ) ); |
439 | 543 | |
| 544 | + # Image links |
| 545 | + $existing = $u->getExistingImages(); |
| 546 | + $u->incrTableUpdate( 'imagelinks', 'il', array(), |
| 547 | + $u->getImageInsertions( $existing ) ); |
| 548 | + |
| 549 | + # Invalidate all image description pages which had links added |
| 550 | + $imageUpdates = array_diff_key( $u->mImages, $existing ); |
| 551 | + $u->invalidateImageDescriptions( $imageUpdates ); |
| 552 | + |
| 553 | + # External links |
| 554 | + $existing = $u->getExistingExternals(); |
| 555 | + $u->incrTableUpdate( 'externallinks', 'el', array(), |
| 556 | + $u->getExternalInsertions( $existing ) ); |
| 557 | + |
| 558 | + # Language links |
| 559 | + $existing = $u->getExistingInterlangs(); |
| 560 | + $u->incrTableUpdate( 'langlinks', 'll', array(), |
| 561 | + $u->getInterlangInsertions( $existing ) ); |
| 562 | + |
| 563 | + # Template links |
| 564 | + $existing = $u->getExistingTemplates(); |
| 565 | + $u->incrTableUpdate( 'templatelinks', 'tl', array(), |
| 566 | + $u->getTemplateInsertions( $existing ) ); |
| 567 | + |
| 568 | + # Category links |
| 569 | + $existing = $u->getExistingCategories(); |
| 570 | + $u->incrTableUpdate( 'categorylinks', 'cl', array(), |
| 571 | + $u->getCategoryInsertions( $existing ) ); |
| 572 | + |
| 573 | + # Invalidate all categories which were added, deleted or changed (set symmetric difference) |
| 574 | + $categoryUpdates = array_diff_assoc( $u->mCategories, $existing ); |
| 575 | + $u->invalidateCategories( $categoryUpdates ); |
| 576 | + |
| 577 | + # Refresh links of all pages including this page |
| 578 | + # This will be in a separate transaction |
| 579 | + if ( $u->mRecursive ) { |
| 580 | + $u->queueRecursiveJobs(); |
| 581 | + } |
| 582 | + |
| 583 | + wfProfileOut( $fname ); |
| 584 | + |
| 585 | + } |
| 586 | + |
440 | 587 | /** |
441 | 588 | * Callback that autopromotes user according to the setting in |
442 | 589 | * $wgFlaggedRevsAutopromote |
— | — | @@ -471,55 +618,6 @@ |
472 | 619 | } |
473 | 620 | } |
474 | 621 | } |
475 | | - |
476 | | - /** |
477 | | - * @param Array $flags |
478 | | - * @output bool, is this revision at quality condition? |
479 | | - */ |
480 | | - public static function isQuality( $flags ) { |
481 | | - global $wgFlaggedRevTags; |
482 | | - |
483 | | - foreach ( $wgFlaggedRevTags as $f => $v ) { |
484 | | - if ( !isset($flags[$f]) || $v > $flags[$f] ) return false; |
485 | | - } |
486 | | - return true; |
487 | | - } |
488 | | - |
489 | | - /** |
490 | | - * @param Array $flags |
491 | | - * @output bool, is this revision at optimal condition? |
492 | | - */ |
493 | | - public static function isPristine( $flags ) { |
494 | | - global $wgFlaggedRevValues; |
495 | | - |
496 | | - foreach ( $flags as $f => $v ) { |
497 | | - if ( $v < $wgFlaggedRevValues ) return false; |
498 | | - } |
499 | | - return true; |
500 | | - } |
501 | | - |
502 | | - /** |
503 | | - * @param Array $flags |
504 | | - * @output integer, lowest rating level |
505 | | - */ |
506 | | - public static function getLCQuality( $flags ) { |
507 | | - global $wgFlaggedRevValues; |
508 | | - |
509 | | - $min = false; |
510 | | - foreach ( $flags as $f => $v ) { |
511 | | - if ( $min==false || $v < $min ) $min = $v; |
512 | | - } |
513 | | - return $min; |
514 | | - } |
515 | | - |
516 | | - function updateFromMove( &$movePageForm , &$oldtitle , &$newtitle ) { |
517 | | - $dbw = wfGetDB( DB_MASTER ); |
518 | | - $dbw->update( 'flaggedrevs', |
519 | | - array('fr_namespace' => $newtitle->getNamespace(), 'fr_title' => $newtitle->getDBkey() ), |
520 | | - array('fr_namespace' => $oldtitle->getNamespace(), 'fr_title' => $oldtitle->getDBkey() ), |
521 | | - __METHOD__ ); |
522 | | - } |
523 | | - |
524 | 622 | } |
525 | 623 | |
526 | 624 | class FlaggedArticle extends FlaggedRevs { |
— | — | @@ -707,8 +805,8 @@ |
708 | 806 | * Get latest quality rev, if not, the latest reviewed one |
709 | 807 | */ |
710 | 808 | function getOverridingRev( $article=NULL ) { |
711 | | - if ( !$row = getLatestQualityRev( $article=NULL ) ) { |
712 | | - if ( !$row = getLatestStableRev( $article=NULL ) ) { |
| 809 | + if( !$row = $this->getLatestQualityRev() ) { |
| 810 | + if( !$row = $this->getLatestStableRev() ) { |
713 | 811 | return null; |
714 | 812 | } |
715 | 813 | } |
— | — | @@ -720,7 +818,7 @@ |
721 | 819 | * per the $wgFlaggedRevTags variable |
722 | 820 | * This passes rev_deleted revisions |
723 | 821 | * This is based on the current article and caches results |
724 | | - * @param Article $article |
| 822 | + * @param Article $article, used when in edit mode |
725 | 823 | * @output array ( rev, flags ) |
726 | 824 | */ |
727 | 825 | function getLatestQualityRev( $article=NULL ) { |
— | — | @@ -732,7 +830,7 @@ |
733 | 831 | $title = $article->getTitle(); |
734 | 832 | // Cached results available? |
735 | 833 | if ( isset($this->stablefound) ) { |
736 | | - return ( $this->stablefound ) ? $this->stablerev : null; |
| 834 | + return ( $this->stablerev ) ? $this->stablerev : null; |
737 | 835 | } |
738 | 836 | $dbr = wfGetDB( DB_SLAVE ); |
739 | 837 | // Skip deleted revisions |
— | — | @@ -773,7 +871,7 @@ |
774 | 872 | $title = $article->getTitle(); |
775 | 873 | // Cached results available? |
776 | 874 | if ( isset($this->latestfound) ) { |
777 | | - return ( $this->latestfound ) ? $this->latestrev : NULL; |
| 875 | + return ( $this->latestrev ) ? $this->latestrev : NULL; |
778 | 876 | } |
779 | 877 | $dbr = wfGetDB( DB_SLAVE ); |
780 | 878 | // Skip deleted revisions |
— | — | @@ -828,12 +926,12 @@ |
829 | 927 | // If we are viewing a page normally, and it was overrode |
830 | 928 | // change the edit tab to a "current revision" tab |
831 | 929 | if( !$wgRequest->getVal('oldid') ) { |
832 | | - $tfrev = $this->getLatestQualityRev(); |
| 930 | + $tfrev = $this->getOverridingRev( $wgArticle ); |
833 | 931 | // No quality revs? Find the last reviewed one |
834 | 932 | if ( !is_object($tfrev) ) |
835 | | - $tfrev = $this->getLatestStableRev(); |
| 933 | + return; |
836 | 934 | // Note that revisions may not be set to override for users |
837 | | - if( is_object($tfrev) && $this->pageOverride() ) { |
| 935 | + if( $this->pageOverride() ) { |
838 | 936 | # Remove edit option altogether |
839 | 937 | unset( $content_actions['edit']); |
840 | 938 | unset( $content_actions['viewsource']); |
— | — | @@ -959,5 +1057,6 @@ |
960 | 1058 | $wgHooks['PageHistoryLineEnding'][] = array($flaggedarticle, 'addToHistLine'); |
961 | 1059 | $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = array($flaggedarticle, 'setPermaLink'); |
962 | 1060 | $wgHooks['ArticleSaveComplete'][] = array($flaggedrevs, 'autoPromoteUser'); |
| 1061 | +$wgHooks['ArticleEditUpdatesDeleteFromRecentchanges'][] = array($flaggedrevs, 'extraLinksUpdate'); |
963 | 1062 | $wgHooks['SpecialMovepageAfterMove'][] = array($flaggedrevs, 'updateFromMove'); |
964 | 1063 | ?> |
Index: trunk/extensions/FlaggedRevs/flaggedrevs.css |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | background-repeat: no-repeat; |
54 | 54 | min-width: 16px; |
55 | 55 | width: 16px; |
56 | | - height: 16px |
| 56 | + height: 16px; |
57 | 57 | min-height: 16px; |
58 | 58 | padding: 3px 16px 0px 20px; |
59 | 59 | } |