Cenarium has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/226740

Change subject: Simple config
......................................................................

Simple config

This removes the need to specify numerous config variables when one just
wants a protection-based config.

Change-Id: I31d0081ebda3c521635dd3abb40ec4dd1aad57c2
---
M backend/FlaggedRevs.class.php
M backend/FlaggedRevsStats.php
M frontend/FlaggablePageView.php
M frontend/FlaggedRevsUI.hooks.php
M frontend/specialpages/reports/ValidationStatistics_body.php
5 files changed, 153 insertions(+), 114 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FlaggedRevs 
refs/changes/40/226740/1

diff --git a/backend/FlaggedRevs.class.php b/backend/FlaggedRevs.class.php
index 7020cc9..bf78cf8 100755
--- a/backend/FlaggedRevs.class.php
+++ b/backend/FlaggedRevs.class.php
@@ -24,7 +24,6 @@
        protected static $loaded = false;
 
        protected static function load() {
-               global $wgFlaggedRevsTags, $wgFlaggedRevTags;
                if ( self::$loaded ) {
                        return true;
                }
@@ -32,6 +31,47 @@
                        throw new Exception( 'FlaggedRevs config loaded too 
soon! Possibly before LocalSettings.php!' );
                }
                self::$loaded = true;
+
+               # Make sure that the restriction levels are unique
+               global $wgFlaggedRevsRestrictionLevels;
+               self::$restrictionLevels = array_unique( 
$wgFlaggedRevsRestrictionLevels );
+               self::$restrictionLevels = array_filter( 
self::$restrictionLevels, 'strlen' );
+
+               # Make sure no talk namespaces are in review namespace
+               global $wgFlaggedRevsNamespaces;
+               foreach ( $wgFlaggedRevsNamespaces as $ns ) {
+                       if ( MWNamespace::isTalk( $ns ) ) {
+                               throw new Exception( 'FlaggedRevs given talk 
namespace in $wgFlaggedRevsNamespaces!' );
+                       } elseif ( $ns == NS_MEDIAWIKI ) {
+                               throw new Exception( 'FlaggedRevs given 
NS_MEDIAWIKI in $wgFlaggedRevsNamespaces!' );
+                       }
+               }
+               self::$reviewNamespaces = $wgFlaggedRevsNamespaces;
+
+               # Handle $wgFlaggedRevsAutoReview settings
+               global $wgFlaggedRevsAutoReview, $wgFlaggedRevsAutoReviewNew;
+               if ( is_int( $wgFlaggedRevsAutoReview ) ) {
+                       self::$autoReviewConfig = $wgFlaggedRevsAutoReview;
+               } else { // b/c
+                       if ( $wgFlaggedRevsAutoReview ) {
+                               self::$autoReviewConfig = FR_AUTOREVIEW_CHANGES;
+                       }
+                       wfWarn( '$wgFlaggedRevsAutoReview is now a bitfield 
instead of a boolean.' );
+               }
+               if ( isset( $wgFlaggedRevsAutoReviewNew ) ) { // b/c
+                       self::$autoReviewConfig = ( $wgFlaggedRevsAutoReviewNew 
)
+                               ? self::$autoReviewConfig |= 
FR_AUTOREVIEW_CREATION
+                               : self::$autoReviewConfig & 
~FR_AUTOREVIEW_CREATION;
+                       wfWarn( '$wgFlaggedRevsAutoReviewNew is deprecated; use 
$wgFlaggedRevsAutoReview.' );
+               }
+
+               // When using a simple config, we don't need to initialize the 
other settings
+               if ( self::useSimpleConfig() ) {
+                       return true;
+               }
+
+               # Handle levelled tags
+               global $wgFlaggedRevsTags, $wgFlaggedRevTags;
                $flaggedRevsTags = null;
                if ( isset( $wgFlaggedRevTags ) ) {
                        $flaggedRevsTags = $wgFlaggedRevTags; // b/c
@@ -89,42 +129,14 @@
                        self::$minPL[$tag] = max( $minPL, 1 );
                        self::$minSL[$tag] = 1;
                }
+
+               # Handle restrictions on tags
                global $wgFlaggedRevsTagsRestrictions, $wgFlagRestrictions;
                if ( isset( $wgFlagRestrictions ) ) {
                        self::$tagRestrictions = $wgFlagRestrictions; // b/c
                        wfWarn( 'Please use $wgFlaggedRevsTagsRestrictions 
instead of $wgFlagRestrictions in config.' );
                } else {
                        self::$tagRestrictions = $wgFlaggedRevsTagsRestrictions;
-               }
-               # Make sure that the restriction levels are unique
-               global $wgFlaggedRevsRestrictionLevels;
-               self::$restrictionLevels = array_unique( 
$wgFlaggedRevsRestrictionLevels );
-               self::$restrictionLevels = array_filter( 
self::$restrictionLevels, 'strlen' );
-               # Make sure no talk namespaces are in review namespace
-               global $wgFlaggedRevsNamespaces;
-               foreach ( $wgFlaggedRevsNamespaces as $ns ) {
-                       if ( MWNamespace::isTalk( $ns ) ) {
-                               throw new Exception( 'FlaggedRevs given talk 
namespace in $wgFlaggedRevsNamespaces!' );
-                       } elseif ( $ns == NS_MEDIAWIKI ) {
-                               throw new Exception( 'FlaggedRevs given 
NS_MEDIAWIKI in $wgFlaggedRevsNamespaces!' );
-                       }
-               }
-               self::$reviewNamespaces = $wgFlaggedRevsNamespaces;
-               # Handle $wgFlaggedRevsAutoReview settings
-               global $wgFlaggedRevsAutoReview, $wgFlaggedRevsAutoReviewNew;
-               if ( is_int( $wgFlaggedRevsAutoReview ) ) {
-                       self::$autoReviewConfig = $wgFlaggedRevsAutoReview;
-               } else { // b/c
-                       if ( $wgFlaggedRevsAutoReview ) {
-                               self::$autoReviewConfig = FR_AUTOREVIEW_CHANGES;
-                       }
-                       wfWarn( '$wgFlaggedRevsAutoReview is now a bitfield 
instead of a boolean.' );
-               }
-               if ( isset( $wgFlaggedRevsAutoReviewNew ) ) { // b/c
-                       self::$autoReviewConfig = ( $wgFlaggedRevsAutoReviewNew 
)
-                               ? self::$autoReviewConfig |= 
FR_AUTOREVIEW_CREATION
-                               : self::$autoReviewConfig & 
~FR_AUTOREVIEW_CREATION;
-                       wfWarn( '$wgFlaggedRevsAutoReviewNew is deprecated; use 
$wgFlaggedRevsAutoReview.' );
                }
 
                return true;
@@ -237,7 +249,7 @@
         */
        public static function isStableShownByDefault() {
                global $wgFlaggedRevsOverride;
-               if ( self::useOnlyIfProtected() ) {
+               if ( self::useSimpleConfig() ) {
                        return false; // must be configured per-page
                }
                return (bool)$wgFlaggedRevsOverride;
@@ -254,11 +266,22 @@
        }
 
        /**
+        * Whether simple configuration settings should be used
+        * @return bool
+        */
+       public static function useSimpleConfig() {
+               return self::useOnlyIfProtected();
+       }
+
+       /**
         * Return the include handling configuration
         * @return int
         */
        public static function inclusionSetting() {
                global $wgFlaggedRevsHandleIncludes;
+               if ( self::useSimpleConfig() ) {
+                       return FR_INCLUDES_CURRENT;
+               }
                return $wgFlaggedRevsHandleIncludes;
        }
 
@@ -924,66 +947,76 @@
                # Get current stable version ID (for logging)
                $oldSv = FlaggedRevision::newFromStable( $title, FR_MASTER );
                $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
-               # Set the auto-review tags from the prior stable version.
-               # Normally, this should already be done and given here...
-               if ( !is_array( $flags ) ) {
-                       if ( $oldSv ) {
-                               # Use the last stable version if $flags not 
given
-                               if ( $user->isAllowed( 'bot' ) ) {
-                                       $flags = $oldSv->getTags(); // no 
change for bot edits
-                               } else {
-                                       # Account for perms/tags...
-                                       $flags = self::getAutoReviewTags( 
$user, $oldSv->getTags() );
-                               }
-                       } else { // new page?
-                               $flags = self::quickTags( FR_CHECKED ); // use 
minimal level
-                       }
-                       if ( !is_array( $flags ) ) {
-                               return false; // can't auto-review this revision
-                       }
-               }
-               # Get review property flags
-               $propFlags = $auto ? array( 'auto' ) : array();
 
-               # Note: this needs to match the prepareContentForEdit() call 
WikiPage::doEditContent.
-               # This is for consistency and also to avoid triggering a second 
parse otherwise.
-               $editInfo = $article->prepareContentForEdit(
-                       $rev->getContent(), null, $user, 
$rev->getContentFormat() );
-               $poutput  = $editInfo->output; // revision HTML output
-
-               # Get the "review time" versions of templates and files.
-               # This tries to make sure each template/file version either 
came from the stable
-               # version of that template/file or was a "review time" version 
used in the stable
-               # version of this page. If a pending version of a template/file 
is currently vandalism,
-               # we try to avoid storing its ID as the "review time" version 
so it won't show up when
-               # someone views the page. If not possible, this stores the 
current template/file.
-               if ( FlaggedRevs::inclusionSetting() === FR_INCLUDES_CURRENT ) {
-                       $tVersions = $poutput->getTemplateIds();
-                       $fVersions = $poutput->getFileSearchOptions();
+               if ( self::useSimpleConfig() ) {
+                       $flags = array();
+                       $quality = FR_CHECKED; 
+                       $tags = '';
+                       $tVersions = null;
+                       $fVersions = null;
                } else {
-                       $tVersions = $oldSv ? $oldSv->getTemplateVersions() : 
array();
-                       $fVersions = $oldSv ? $oldSv->getFileVersions() : 
array();
-                       foreach ( $poutput->getTemplateIds() as $ns => $pages ) 
{
-                               foreach ( $pages as $dbKey => $revId ) {
-                                       if ( !isset( $tVersions[$ns][$dbKey] ) 
) {
-                                               $srev = 
FlaggedRevision::newFromStable( Title::makeTitle( $ns, $dbKey ) );
-                                               if ( $srev ) { // use stable
-                                                       $tVersions[$ns][$dbKey] 
= $srev->getRevId();
-                                               } else { // use current
-                                                       $tVersions[$ns][$dbKey] 
= $revId;
+                       # Set the auto-review tags from the prior stable 
version.
+                       # Normally, this should already be done and given 
here...
+                       if ( !is_array( $flags ) ) {
+                               if ( $oldSv ) {
+                                       # Use the last stable version if $flags 
not given
+                                       if ( $user->isAllowed( 'bot' ) ) {
+                                               $flags = $oldSv->getTags(); // 
no change for bot edits
+                                       } else {
+                                               # Account for perms/tags...
+                                               $flags = 
self::getAutoReviewTags( $user, $oldSv->getTags() );
+                                       }
+                               } else { // new page?
+                                       $flags = self::quickTags( FR_CHECKED ); 
// use minimal level
+                               }
+                               if ( !is_array( $flags ) ) {
+                                       return false; // can't auto-review this 
revision
+                               }
+                       }
+
+                       $quality = FlaggedRevs::getQualityTier( $flags, 
FR_CHECKED /* sanity */ );
+                       $tags = FlaggedRevision::flattenRevisionTags( $flags );
+
+                       # Note: this needs to match the prepareContentForEdit() 
call WikiPage::doEditContent.
+                       # This is for consistency and also to avoid triggering 
a second parse otherwise.
+                       $editInfo = $article->prepareContentForEdit(
+                               $rev->getContent(), null, $user, 
$rev->getContentFormat() );
+                       $poutput  = $editInfo->output; // revision HTML output
+
+                       # Get the "review time" versions of templates and files.
+                       # This tries to make sure each template/file version 
either came from the stable
+                       # version of that template/file or was a "review time" 
version used in the stable
+                       # version of this page. If a pending version of a 
template/file is currently vandalism,
+                       # we try to avoid storing its ID as the "review time" 
version so it won't show up when
+                       # someone views the page. If not possible, this stores 
the current template/file.
+                       if ( FlaggedRevs::inclusionSetting() === 
FR_INCLUDES_CURRENT ) {
+                               $tVersions = $poutput->getTemplateIds();
+                               $fVersions = $poutput->getFileSearchOptions();
+                       } else {
+                               $tVersions = $oldSv ? 
$oldSv->getTemplateVersions() : array();
+                               $fVersions = $oldSv ? $oldSv->getFileVersions() 
: array();
+                               foreach ( $poutput->getTemplateIds() as $ns => 
$pages ) {
+                                       foreach ( $pages as $dbKey => $revId ) {
+                                               if ( !isset( 
$tVersions[$ns][$dbKey] ) ) {
+                                                       $srev = 
FlaggedRevision::newFromStable( Title::makeTitle( $ns, $dbKey ) );
+                                                       if ( $srev ) { // use 
stable
+                                                               
$tVersions[$ns][$dbKey] = $srev->getRevId();
+                                                       } else { // use current
+                                                               
$tVersions[$ns][$dbKey] = $revId;
+                                                       }
                                                }
                                        }
                                }
-                       }
-                       foreach ( $poutput->getFileSearchOptions() as $dbKey => 
$info ) {
-                               if ( !isset( $fVersions[$dbKey] ) ) {
-                                       $srev = FlaggedRevision::newFromStable( 
Title::makeTitle( NS_FILE, $dbKey ) );
-                                       if ( $srev && $srev->getFileTimestamp() 
) { // use stable
-                                               $fVersions[$dbKey]['time'] = 
$srev->getFileTimestamp();
-                                               $fVersions[$dbKey]['sha1'] = 
$srev->getFileSha1();
-                                       } else { // use current
-                                               $fVersions[$dbKey]['time'] = 
$info['time'];
-                                               $fVersions[$dbKey]['sha1'] = 
$info['sha1'];
+                               foreach ( $poutput->getFileSearchOptions() as 
$dbKey => $info ) {
+                                       if ( !isset( $fVersions[$dbKey] ) ) {
+                                               $srev = 
FlaggedRevision::newFromStable( Title::makeTitle( NS_FILE, $dbKey ) );
+                                               if ( $srev && 
$srev->getFileTimestamp() ) { // use stable
+                                                       
$fVersions[$dbKey]['time'] = $srev->getFileTimestamp();
+                                                       
$fVersions[$dbKey]['sha1'] = $srev->getFileSha1();
+                                               } else { // use current
+                                                       
$fVersions[$dbKey]['time'] = $info['time'];
+                                                       
$fVersions[$dbKey]['sha1'] = $info['sha1'];
+                                               }
                                        }
                                }
                        }
@@ -1008,14 +1041,14 @@
                        'rev'                   => $rev,
                        'user_id'               => $user->getId(),
                        'timestamp'             => $rev->getTimestamp(), // 
same as edit time
-                       'quality'               => FlaggedRevs::getQualityTier( 
$flags, 0 /* sanity */ ),
-                       'tags'                  => 
FlaggedRevision::flattenRevisionTags( $flags ),
+                       'quality'               => $quality,
+                       'tags'                  => $tags,
                        'img_name'              => $fileData['name'],
                        'img_timestamp'         => $fileData['timestamp'],
                        'img_sha1'              => $fileData['sha1'],
                        'templateVersions'      => $tVersions,
                        'fileVersions'          => $fVersions,
-                       'flags'             => implode( ',', $propFlags ),
+                       'flags'             => $auto ? 'auto' : '',
                ) );
                $flaggedRevision->insert();
                # Update the article review log
diff --git a/backend/FlaggedRevsStats.php b/backend/FlaggedRevsStats.php
index e9eb09d..c9d2fd7 100644
--- a/backend/FlaggedRevsStats.php
+++ b/backend/FlaggedRevsStats.php
@@ -250,7 +250,7 @@
                        'sampleStartTS' => null,
                        'sampleEndTS'   => null
                );
-               if ( FlaggedRevs::useOnlyIfProtected() ) {
+               if ( FlaggedRevs::useSimpleConfig() ) {
                        return $result; // disabled
                }
 
diff --git a/frontend/FlaggablePageView.php b/frontend/FlaggablePageView.php
index e7d180b..94e6bfb 100755
--- a/frontend/FlaggablePageView.php
+++ b/frontend/FlaggablePageView.php
@@ -745,10 +745,10 @@
 
        // Show icons for draft/stable/old reviewed versions
        protected function showRatingIcon() {
-               if ( FlaggedRevs::useOnlyIfProtected() ) {
+               if ( FlaggedRevs::useSimpleConfig() ) {
                        // If there is only one quality level and we have tabs 
to know
                        // which version we are looking at, then just use the 
lock icon...
-                       return FlaggedRevs::qualityVersions();
+                       return false;
                }
                return true;
        }
@@ -1099,7 +1099,7 @@
                if ( !$reqUser->isAllowed( 'review' ) ) {
                        return true;
                }
-               if ( !FlaggedRevs::useOnlyIfProtected() ) {
+               if ( !FlaggedRevs::useSimpleConfig() ) {
                        # Add links to lists of unreviewed pages and pending 
changes in this category
                        $category = $this->article->getTitle()->getText();
                        $this->out->addSubtitle(
@@ -1159,20 +1159,26 @@
 
                        # Set the file version we are viewing (for File: pages)
                        $form->setFileVersion( $this->out->getFileVersion() );
-                       # $wgOut might not have the inclusion IDs, such as for 
diffs with diffonly=1.
-                       # If they're lacking, then we use getRevIncludes() to 
get the draft inclusion versions.
-                       # Note: showStableVersion() already makes sure that 
$wgOut has the stable inclusion versions.
-                       if ( $this->out->getRevisionId() == $rev->getId() ) {
-                               $tmpVers = $this->out->getTemplateIds();
-                               $fileVers = $this->out->getFileSearchOptions();
-                       } elseif ( $this->oldRevIncludes ) { // e.g. 
diffonly=1, stable diff
-                               # We may have already fetched the inclusion IDs 
to get the template/file changes.
-                               list( $tmpVers, $fileVers ) = 
$this->oldRevIncludes; // reuse
-                       } else { // e.g. diffonly=1, other diffs
-                               # $wgOut may not already have the inclusion 
IDs, such as for diffonly=1.
-                               # RevisionReviewForm will fetch them as needed 
however.
-                               list( $tmpVers, $fileVers ) =
-                                       FRInclusionCache::getRevIncludes( 
$this->article, $rev, $reqUser );
+
+                       if ( FlaggedRevs::useSimpleConfig() ) {
+                               $tmpVers = array();
+                               $fileVers = array();
+                       } else {
+                               # $wgOut might not have the inclusion IDs, such 
as for diffs with diffonly=1.
+                               # If they're lacking, then we use 
getRevIncludes() to get the draft inclusion versions.
+                               # Note: showStableVersion() already makes sure 
that $wgOut has the stable inclusion versions.
+                               if ( $this->out->getRevisionId() == 
$rev->getId() ) {
+                                       $tmpVers = $this->out->getTemplateIds();
+                                       $fileVers = 
$this->out->getFileSearchOptions();
+                               } elseif ( $this->oldRevIncludes ) { // e.g. 
diffonly=1, stable diff
+                                       # We may have already fetched the 
inclusion IDs to get the template/file changes.
+                                       list( $tmpVers, $fileVers ) = 
$this->oldRevIncludes; // reuse
+                               } else { // e.g. diffonly=1, other diffs
+                                       # $wgOut may not already have the 
inclusion IDs, such as for diffonly=1.
+                                       # RevisionReviewForm will fetch them as 
needed however.
+                                       list( $tmpVers, $fileVers ) =
+                                               
FRInclusionCache::getRevIncludes( $this->article, $rev, $reqUser );
+                               }
                        }
                        $form->setIncludeVersions( $tmpVers, $fileVers );
 
@@ -1194,7 +1200,7 @@
        public function addStabilizationLink() {
                $request = $this->getRequest();
                $this->load();
-               if ( FlaggedRevs::useProtectionLevels() ) {
+               if ( FlaggedRevs::useSimpleConfig() ) {
                        return true; // simple custom levels set for 
action=protect
                }
                # Check only if the title is reviewable
@@ -1230,7 +1236,7 @@
        public function setActionTabs( $skin, array &$actions ) {
                $reqUser = $this->getUser();
                $this->load();
-               if ( FlaggedRevs::useProtectionLevels() ) {
+               if ( FlaggedRevs::useSimpleConfig() ) {
                        return true; // simple custom levels set for 
action=protect
                }
                $title = $this->article->getTitle()->getSubjectPage();
diff --git a/frontend/FlaggedRevsUI.hooks.php b/frontend/FlaggedRevsUI.hooks.php
index 9c5b538..966b49e 100644
--- a/frontend/FlaggedRevsUI.hooks.php
+++ b/frontend/FlaggedRevsUI.hooks.php
@@ -293,7 +293,7 @@
        }
 
        public static function addHideReviewedFilter( $specialPage, &$filters ) 
{
-               if ( !FlaggedRevs::useOnlyIfProtected() ) {
+               if ( !FlaggedRevs::useSimpleConfig() ) {
                        $filters['hideReviewed'] = array(
                                'msg' => 'flaggedrevs-hidereviewed', 'default' 
=> false );
                }
@@ -383,7 +383,7 @@
                $fields[] = 'fp_stable';
                $fields[] = 'fp_pending_since';
                $join_conds['flaggedpages'] = array( 'LEFT JOIN', 'fp_page_id = 
rc_cur_id' );
-               if ( $wgRequest->getBool( 'hideReviewed' ) && 
!FlaggedRevs::useOnlyIfProtected() ) {
+               if ( $wgRequest->getBool( 'hideReviewed' ) && 
!FlaggedRevs::useSimpleConfig() ) {
                        // Don't filter external changes as FlaggedRevisions 
doesn't apply to those
                        $conds[] = 'rc_timestamp >= fp_pending_since OR 
fp_stable IS NULL OR rc_type = ' . RC_EXTERNAL;
                }
@@ -533,7 +533,7 @@
                if ( $rc->mAttribs['fp_stable'] == null ) {
                        // Is this a config were pages start off reviewable?
                        // Hide notice from non-reviewers due to vandalism 
concerns (bug 24002).
-                       if ( !FlaggedRevs::useOnlyIfProtected() && 
$wgUser->isAllowed( 'review' ) ) {
+                       if ( !FlaggedRevs::useSimpleConfig() && 
$wgUser->isAllowed( 'review' ) ) {
                                $rlink = wfMessage( 'revreview-unreviewedpage' 
)->escaped();
                                $css = 'flaggedrevs-unreviewed';
                        }
diff --git a/frontend/specialpages/reports/ValidationStatistics_body.php 
b/frontend/specialpages/reports/ValidationStatistics_body.php
index 8d74b8b..88db6ef 100644
--- a/frontend/specialpages/reports/ValidationStatistics_body.php
+++ b/frontend/specialpages/reports/ValidationStatistics_body.php
@@ -63,7 +63,7 @@
                $out->addWikiMsg( 'validationstatistics-pndtime',
                        $lang->formatTimePeriod( $pt, 'avoidminutes' ) );
                # Show review time stats...
-               if ( !FlaggedRevs::useOnlyIfProtected() ) {
+               if ( !FlaggedRevs::useSimpleConfig() ) {
                        $out->addWikiMsg( 'validationstatistics-revtime',
                                $lang->formatTimePeriod( $mt, 'avoidminutes' ),
                                $lang->formatTimePeriod( $mdt, 'avoidminutes' ),

-- 
To view, visit https://gerrit.wikimedia.org/r/226740
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I31d0081ebda3c521635dd3abb40ec4dd1aad57c2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FlaggedRevs
Gerrit-Branch: master
Gerrit-Owner: Cenarium <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to