r69341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69340‎ | r69341 | r69342 >
Date:19:26, 14 July 2010
Author:aaron
Status:ok
Tags:
Comment:
* findPendingTemplateChanges/findPendingFileChanges improvements to catch changes better.
* findPendingFileChanges timestamp handling fixes (effects non-mysql)
* some tab spacing cleanup
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -74,7 +74,7 @@
7575 throw new MWException( 'FlaggedRevision constructor passed invalid row format.' );
7676 }
7777 }
78 -
 78+
7979 /**
8080 * Get a FlaggedRevision for a title and rev ID.
8181 * Note: will return NULL if the revision is deleted.
@@ -326,7 +326,7 @@
327327 }
328328 return true;
329329 }
330 -
 330+
331331 /**
332332 * @return Array basic select fields (not including text/text flags)
333333 */
@@ -344,7 +344,7 @@
345345 public function getRevId() {
346346 return $this->mRevId;
347347 }
348 -
 348+
349349 /**
350350 * @return Title title
351351 */
@@ -369,7 +369,7 @@
370370 public function getTimestamp() {
371371 return wfTimestamp( TS_MW, $this->mTimestamp );
372372 }
373 -
 373+
374374 /**
375375 * Get the corresponding revision
376376 * @return Revision
@@ -383,7 +383,7 @@
384384 }
385385 return $this->mRevision;
386386 }
387 -
 387+
388388 /**
389389 * Get timestamp of the corresponding revision
390390 * @return string revision timestamp in MW format
@@ -401,7 +401,7 @@
402402 public function getComment() {
403403 return $this->mComment;
404404 }
405 -
 405+
406406 /**
407407 * @return integer the user ID of the reviewer
408408 */
@@ -422,7 +422,7 @@
423423 public function getTags() {
424424 return $this->mTags;
425425 }
426 -
 426+
427427 /**
428428 * @return string, filename accosciated with this revision.
429429 * This returns NULL for non-image page revisions.
@@ -430,7 +430,7 @@
431431 public function getFileName() {
432432 return $this->mFileName;
433433 }
434 -
 434+
435435 /**
436436 * @return string, sha1 key accosciated with this revision.
437437 * This returns NULL for non-image page revisions.
@@ -438,7 +438,7 @@
439439 public function getFileSha1() {
440440 return $this->mFileSha1;
441441 }
442 -
 442+
443443 /**
444444 * @return string, timestamp accosciated with this revision.
445445 * This returns NULL for non-image page revisions.
@@ -446,7 +446,7 @@
447447 public function getFileTimestamp() {
448448 return wfTimestampOrNull( TS_MW, $this->mFileTimestamp );
449449 }
450 -
 450+
451451 /**
452452 * @param User $user
453453 * @return bool
@@ -480,7 +480,7 @@
481481 }
482482 return $this->mTemplates;
483483 }
484 -
 484+
485485 /**
486486 * Get original template versions at time of review
487487 * @param int $flags FR_MASTER
@@ -507,7 +507,7 @@
508508 }
509509 return $this->mFiles;
510510 }
511 -
 511+
512512 /**
513513 * Get the current stable version of the templates used at time of review
514514 * @param int $flags FR_MASTER
@@ -541,7 +541,7 @@
542542 }
543543 return $this->mStableTemplates;
544544 }
545 -
 545+
546546 /**
547547 * Get the current stable version of the files used at time of review
548548 * @param int $flags FR_MASTER
@@ -581,10 +581,10 @@
582582 }
583583 return $this->mStableFiles;
584584 }
585 -
 585+
586586 /*
587587 * Fetch pending template changes for this reviewed page version.
588 - * For each template, the "version used" is:
 588+ * For each template, the "version used" (for stable parsing) is:
589589 * (a) (the latest rev) if FR_INCLUDES_CURRENT. Might be non-existing.
590590 * (b) newest( stable rev, rev at time of review ) if FR_INCLUDES_STABLE
591591 * (c) ( rev at time of review ) if FR_INCLUDES_FREEZE
@@ -601,44 +601,51 @@
602602 return array(); // short-circuit
603603 }
604604 $dbr = wfGetDB( DB_SLAVE );
 605+ # Only get templates with stable or "review time" versions.
 606+ # Note: ft_tmp_rev_id is nullable (for deadlinks), so use ft_title
 607+ if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE ) {
 608+ $reviewed = "ft_title IS NOT NULL OR fp_stable IS NOT NULL";
 609+ } else {
 610+ $reviewed = "ft_title IS NOT NULL";
 611+ }
605612 $ret = $dbr->select(
606 - array( 'flaggedtemplates', 'templatelinks', 'page', 'flaggedpages' ),
607 - array( 'ft_namespace', 'ft_title', 'fp_stable', 'ft_tmp_rev_id', 'page_latest' ),
608 - array( 'ft_rev_id' => $this->getRevId() ), // template was in reviewed rev
 613+ array( 'templatelinks', 'flaggedtemplates', 'page', 'flaggedpages' ),
 614+ array( 'tl_namespace', 'tl_title', 'fp_stable', 'ft_tmp_rev_id', 'page_latest' ),
 615+ array( 'tl_from' => $this->getPage(), $reviewed ), // current version templates
609616 __METHOD__,
610617 array(), /* OPTIONS */
611618 array(
612 - 'templatelinks' => array( 'INNER JOIN', // used in current rev
613 - array( 'tl_from' => $this->getPage(),
614 - 'tl_namespace = ft_namespace AND tl_title = ft_title' ) ),
615 - 'page' => array( 'LEFT JOIN',
616 - 'page_namespace = ft_namespace AND page_title = ft_title' ),
617 - 'flaggedpages' => array( 'LEFT JOIN', 'fp_page_id = page_id' )
 619+ 'flaggedtemplates' => array( 'LEFT JOIN',
 620+ array( 'ft_rev_id' => $this->getRevId(),
 621+ 'ft_namespace = tl_namespace AND ft_title = tl_title' ) ),
 622+ 'page' => array( 'LEFT JOIN',
 623+ 'page_namespace = tl_namespace AND page_title = tl_title' ),
 624+ 'flaggedpages' => array( 'LEFT JOIN', 'fp_page_id = page_id' )
618625 )
619626 );
620627 $tmpChanges = array();
621628 while ( $row = $dbr->fetchObject( $ret ) ) {
622 - $title = Title::makeTitleSafe( $row->ft_namespace, $row->ft_title );
 629+ $title = Title::makeTitleSafe( $row->tl_namespace, $row->tl_title );
623630 $revIdDraft = (int)$row->page_latest; // may be NULL
624631 if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE ) {
625 - # Select newest of (stable rev, rev when reviewed) when parsing
 632+ # Select newest of (stable rev, rev when reviewed) as "version used"
626633 $revIdStable = max( $row->fp_stable, $row->ft_tmp_rev_id );
627634 } else {
628 - $revIdStable = (int)$row->ft_tmp_rev_id;
 635+ $revIdStable = (int)$row->ft_tmp_rev_id; // may be NULL
629636 }
630637 # Compare to current...
631638 $deleted = ( !$revIdDraft && $revIdStable ); // later deleted
632 - $updated = ( $revIdDraft && $revIdDraft > $revIdStable ); // updated/created
 639+ $updated = ( $revIdDraft && $revIdDraft > $revIdStable ); // edited/created
633640 if ( $deleted || $updated ) {
634641 $tmpChanges[] = array( $title, $revIdStable );
635642 }
636643 }
637644 return $tmpChanges;
638645 }
639 -
 646+
640647 /*
641648 * Fetch pending file changes for this reviewed page version.
642 - * For each file, the version used is:
 649+ * For each file, the "version used" (for stable parsing) is:
643650 * (a) (the latest rev) if FR_INCLUDES_CURRENT. Might be non-existing.
644651 * (b) newest( stable rev, rev at time of review ) if FR_INCLUDES_STABLE
645652 * (c) ( rev at time of review ) if FR_INCLUDES_FREEZE
@@ -648,7 +655,7 @@
649656 * (b) Current file exists and the "version used" was non-existing (created)
650657 * (c) Current file doesn't exist and the "version used" existed (deleted)
651658 *
652 - * @param string $noForeign Use 'noForeign' to skip Commons images (bug 15748)
 659+ * @param string $noForeign Using 'noForeign' skips new non-local file versions (bug 15748)
653660 * @return Array of (file title, MW file timestamp in reviewed version) tuples
654661 */
655662 public function findPendingFileChanges( $noForeign = false ) {
@@ -656,40 +663,55 @@
657664 return array(); // short-circuit
658665 }
659666 $dbr = wfGetDB( DB_SLAVE );
 667+ # Only get templates with stable or "review time" versions.
 668+ # Note: fi_img_timestamp is nullable (for deadlinks), so use fi_name
 669+ if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE ) {
 670+ $reviewed = "fi_name IS NOT NULL OR fr_img_timestamp IS NOT NULL";
 671+ } else {
 672+ $reviewed = "fi_name IS NOT NULL";
 673+ }
660674 $ret = $dbr->select(
661 - array( 'flaggedimages', 'imagelinks', 'page', 'flaggedpages', 'flaggedrevs' ),
662 - array( 'fi_name', 'fi_img_timestamp', 'fr_img_timestamp' ),
663 - array( 'fi_rev_id' => $this->getRevId() ), // template was in reviewed rev
 675+ array( 'imagelinks', 'flaggedimages', 'page', 'flaggedpages', 'flaggedrevs' ),
 676+ array( 'il_to', 'fi_img_timestamp', 'fr_img_timestamp' ),
 677+ array( 'il_from' => $this->getPage(), $reviewed ), // current version files
664678 __METHOD__,
665679 array(), /* OPTIONS */
666680 array(
667 - 'imagelinks' => array( 'INNER JOIN', // used in current rev
668 - array( 'il_from' => $this->getPage(), 'il_to = fi_name' ) ),
 681+ 'flaggedimages' => array( 'LEFT JOIN',
 682+ array( 'fi_rev_id' => $this->getRevId(), 'fi_name = il_to' ) ),
669683 'page' => array( 'LEFT JOIN',
670 - 'page_namespace = ' . NS_FILE . ' AND page_title = fi_name' ),
 684+ 'page_namespace = ' . NS_FILE . ' AND page_title = il_to' ),
671685 'flaggedpages' => array( 'LEFT JOIN', 'fp_page_id = page_id' ),
672686 'flaggedrevs' => array( 'LEFT JOIN',
673 - 'fr_page_id = fp_page_id AND fr_rev_id = fp_stable' ) )
 687+ 'fr_page_id = fp_page_id AND fr_rev_id = fp_stable' )
 688+ )
674689 );
675690 $fileChanges = array();
676691 while ( $row = $dbr->fetchObject( $ret ) ) {
677 - $title = Title::makeTitleSafe( NS_FILE, $row->fi_name );
 692+ $title = Title::makeTitleSafe( NS_FILE, $row->il_to );
678693 $reviewedTS = trim( $row->fi_img_timestamp ); // may be ''/NULL
 694+ $reviewedTS = $reviewedTS ? wfTimestamp( TS_MW, $reviewedTS ) : null;
679695 if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE ) {
680 - # Select newest of (stable rev, rev when reviewed) when parsing
681 - $tsStable = $row->fr_img_timestamp >= $reviewedTS
682 - ? $row->fr_img_timestamp
683 - : $reviewedTS;
 696+ $stableTS = wfTimestampOrNull( TS_MW, $row->fr_img_timestamp );
 697+ # Select newest of (stable rev, rev when reviewed) as "version used"
 698+ $tsStable = ( $stableTS >= $reviewedTS )
 699+ ? $stableTS
 700+ : $reviewedTS;
684701 } else {
685702 $tsStable = $reviewedTS;
686703 }
687704 # Compare to current...
688705 $file = wfFindFile( $title ); // current file version
689 - $deleted = ( !$file && $tsStable ); // later deleted
690 - if ( $file && ( $noForeign !== 'noForeign' || $file->isLocal() ) ) {
691 - $updated = ( $file->getTimestamp() > $tsStable ); // updated/created
692 - } else {
 706+ if ( $file ) { // file exists
 707+ if ( $noForeign === 'noForeign' && !$file->isLocal() ) {
 708+ $updated = !$tsStable; // created (ignore new versions)
 709+ } else {
 710+ $updated = ( $file->getTimestamp() > $tsStable ); // edited/created
 711+ }
 712+ $deleted = false;
 713+ } else { // file doesn't exists
693714 $updated = false;
 715+ $deleted = (bool)$tsStable; // later deleted
694716 }
695717 if ( $deleted || $updated ) {
696718 $fileChanges[] = array( $title, $tsStable );
@@ -697,7 +719,7 @@
698720 }
699721 return $fileChanges;
700722 }
701 -
 723+
702724 /**
703725 * Get text of the corresponding revision
704726 * @return mixed (string/false) revision timestamp in MW format
@@ -708,7 +730,7 @@
709731 $text = $rev ? $rev->getText() : false;
710732 return $text;
711733 }
712 -
 734+
713735 /**
714736 * Get flags for a revision
715737 * @param string $tags

Status & tagging log