r21998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r21997‎ | r21998 | r21999 >
Date:16:51, 8 May 2007
Author:aaron
Status:old
Tags:
Comment:
*Add hooked function extraLinksUpdate() to solve link table issues, fix some bad syntax
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/flaggedrevs.css (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -317,6 +317,39 @@
318318
319319 return $flags;
320320 }
 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+ }
321354
322355 public function addTagRatings( $flags ) {
323356 global $wgFlaggedRevTags;
@@ -354,6 +387,46 @@
355388 }
356389
357390 /**
 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+ /**
358431 * @param Article $article
359432 * Get the page cache for the top stable revision of an article
360433 */
@@ -435,7 +508,81 @@
436509
437510 return true;
438511 }
 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 ) );
439543
 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+
440587 /**
441588 * Callback that autopromotes user according to the setting in
442589 * $wgFlaggedRevsAutopromote
@@ -471,55 +618,6 @@
472619 }
473620 }
474621 }
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 -
524622 }
525623
526624 class FlaggedArticle extends FlaggedRevs {
@@ -707,8 +805,8 @@
708806 * Get latest quality rev, if not, the latest reviewed one
709807 */
710808 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() ) {
713811 return null;
714812 }
715813 }
@@ -720,7 +818,7 @@
721819 * per the $wgFlaggedRevTags variable
722820 * This passes rev_deleted revisions
723821 * This is based on the current article and caches results
724 - * @param Article $article
 822+ * @param Article $article, used when in edit mode
725823 * @output array ( rev, flags )
726824 */
727825 function getLatestQualityRev( $article=NULL ) {
@@ -732,7 +830,7 @@
733831 $title = $article->getTitle();
734832 // Cached results available?
735833 if ( isset($this->stablefound) ) {
736 - return ( $this->stablefound ) ? $this->stablerev : null;
 834+ return ( $this->stablerev ) ? $this->stablerev : null;
737835 }
738836 $dbr = wfGetDB( DB_SLAVE );
739837 // Skip deleted revisions
@@ -773,7 +871,7 @@
774872 $title = $article->getTitle();
775873 // Cached results available?
776874 if ( isset($this->latestfound) ) {
777 - return ( $this->latestfound ) ? $this->latestrev : NULL;
 875+ return ( $this->latestrev ) ? $this->latestrev : NULL;
778876 }
779877 $dbr = wfGetDB( DB_SLAVE );
780878 // Skip deleted revisions
@@ -828,12 +926,12 @@
829927 // If we are viewing a page normally, and it was overrode
830928 // change the edit tab to a "current revision" tab
831929 if( !$wgRequest->getVal('oldid') ) {
832 - $tfrev = $this->getLatestQualityRev();
 930+ $tfrev = $this->getOverridingRev( $wgArticle );
833931 // No quality revs? Find the last reviewed one
834932 if ( !is_object($tfrev) )
835 - $tfrev = $this->getLatestStableRev();
 933+ return;
836934 // Note that revisions may not be set to override for users
837 - if( is_object($tfrev) && $this->pageOverride() ) {
 935+ if( $this->pageOverride() ) {
838936 # Remove edit option altogether
839937 unset( $content_actions['edit']);
840938 unset( $content_actions['viewsource']);
@@ -959,5 +1057,6 @@
9601058 $wgHooks['PageHistoryLineEnding'][] = array($flaggedarticle, 'addToHistLine');
9611059 $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = array($flaggedarticle, 'setPermaLink');
9621060 $wgHooks['ArticleSaveComplete'][] = array($flaggedrevs, 'autoPromoteUser');
 1061+$wgHooks['ArticleEditUpdatesDeleteFromRecentchanges'][] = array($flaggedrevs, 'extraLinksUpdate');
9631062 $wgHooks['SpecialMovepageAfterMove'][] = array($flaggedrevs, 'updateFromMove');
9641063 ?>
Index: trunk/extensions/FlaggedRevs/flaggedrevs.css
@@ -52,7 +52,7 @@
5353 background-repeat: no-repeat;
5454 min-width: 16px;
5555 width: 16px;
56 - height: 16px
 56+ height: 16px;
5757 min-height: 16px;
5858 padding: 3px 16px 0px 20px;
5959 }