http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82884
Revision: 82884
Author: aaron
Date: 2011-02-27 08:13:01 +0000 (Sun, 27 Feb 2011)
Log Message:
-----------
* Split off FlaggedPageConfig class from FlaggedRevs
* Added selectFields() to said class
Modified Paths:
--------------
trunk/extensions/FlaggedRevs/FlaggedArticle.php
trunk/extensions/FlaggedRevs/FlaggedRevision.php
trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
trunk/extensions/FlaggedRevs/FlaggedRevs.php
trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php
trunk/extensions/FlaggedRevs/specialpages/ConfiguredPages_body.php
trunk/extensions/FlaggedRevs/specialpages/StablePages_body.php
Added Paths:
-----------
trunk/extensions/FlaggedRevs/FlaggedPageConfig.php
Modified: trunk/extensions/FlaggedRevs/FlaggedArticle.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedArticle.php 2011-02-27 07:43:48 UTC
(rev 82883)
+++ trunk/extensions/FlaggedRevs/FlaggedArticle.php 2011-02-27 08:13:01 UTC
(rev 82884)
@@ -324,7 +324,7 @@
*/
protected function loadStableRevAndConfig( $flags = 0 ) {
$this->stableRev = false; // false => "found nothing"
- $this->pageConfig =
FlaggedRevs::getDefaultVisibilitySettings(); // default
+ $this->pageConfig =
FlaggedPageConfig::getDefaultVisibilitySettings(); // default
if ( !FlaggedRevs::inReviewNamespace( $this->getTitle() ) ) {
return; // short-circuit
}
@@ -333,8 +333,7 @@
wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
$row = $db->selectRow(
array( 'page', 'flaggedpages', 'flaggedrevs',
'flaggedpage_config' ),
- array_merge( FlaggedRevision::selectFields(),
- array( 'fpc_override', 'fpc_level',
'fpc_expiry' ) ),
+ array_merge( FlaggedRevision::selectFields(),
FlaggedPageConfig::selectFields() ),
array( 'page_id' => $this->getID() ),
__METHOD__,
array(),
@@ -348,7 +347,7 @@
return; // no page found at all
}
if ( $row->fpc_override !== null ) { // page config row found
- $this->pageConfig =
FlaggedRevs::getVisibilitySettingsFromRow( $row );
+ $this->pageConfig =
FlaggedPageConfig::getVisibilitySettingsFromRow( $row );
}
if ( $row->fr_rev_id !== null ) { // stable rev row found
// Page may not reviewable, which implies no stable
version
Added: trunk/extensions/FlaggedRevs/FlaggedPageConfig.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedPageConfig.php
(rev 0)
+++ trunk/extensions/FlaggedRevs/FlaggedPageConfig.php 2011-02-27 08:13:01 UTC
(rev 82884)
@@ -0,0 +1,173 @@
+<?php
+/*
+* Page stability configuration functions
+*/
+class FlaggedPageConfig {
+ /**
+ * Get visibility settings/restrictions for a page
+ * @param Title $title, page title
+ * @param int $flags, FR_MASTER
+ * @returns array (associative) (select,override,autoreview,expiry)
+ */
+ public static function getPageStabilitySettings( Title $title, $flags =
0 ) {
+ $db = ( $flags & FR_MASTER ) ?
+ wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
+ $row = $db->selectRow( 'flaggedpage_config',
+ self::selectFields(),
+ array( 'fpc_page_id' => $title->getArticleID() ),
+ __METHOD__
+ );
+ return self::getVisibilitySettingsFromRow( $row );
+ }
+
+ /**
+ * @return Array basic select fields for FlaggedPageConfig DB row
+ */
+ public static function selectFields() {
+ return array( 'fpc_override', 'fpc_level', 'fpc_expiry' );
+ }
+
+ /**
+ * Get page configuration settings from a DB row
+ */
+ public static function getVisibilitySettingsFromRow( $row ) {
+ if ( $row ) {
+ # This code should be refactored, now that it's being
used more generally.
+ $expiry = Block::decodeExpiry( $row->fpc_expiry );
+ # Only apply the settings if they haven't expired
+ if ( !$expiry || $expiry < wfTimestampNow() ) {
+ $row = null; // expired
+ self::purgeExpiredConfigurations();
+ }
+ }
+ // Is there a non-expired row?
+ if ( $row ) {
+ $level = $row->fpc_level;
+ if ( !self::isValidRestriction( $row->fpc_level ) ) {
+ $level = ''; // site default; ignore fpc_level
+ }
+ $config = array(
+ 'override' => $row->fpc_override ? 1 : 0,
+ 'autoreview' => $level,
+ 'expiry' => Block::decodeExpiry(
$row->fpc_expiry ) // TS_MW
+ );
+ # If there are protection levels defined check if this
is valid...
+ if ( FlaggedRevs::useProtectionLevels() ) {
+ $level = self::getProtectionLevel( $config );
+ if ( $level == 'invalid' || $level == 'none' ) {
+ // If 'none', make sure expiry is
'infinity'
+ $config =
self::getDefaultVisibilitySettings(); // revert to default (none)
+ }
+ }
+ } else {
+ # Return the default config if this page doesn't have
its own
+ $config = self::getDefaultVisibilitySettings();
+ }
+ return $config;
+ }
+
+ /**
+ * Get default page configuration settings
+ */
+ public static function getDefaultVisibilitySettings() {
+ return array(
+ # Keep this consistent: 1 => override, 0 => don't
+ 'override' => FlaggedRevs::isStableShownByDefault() ?
1 : 0,
+ 'autoreview' => '',
+ 'expiry' => 'infinity'
+ );
+ }
+
+
+ /**
+ * Find what protection level a config is in
+ * @param array $config
+ * @returns string
+ */
+ public static function getProtectionLevel( array $config ) {
+ if ( !FlaggedRevs::useProtectionLevels() ) {
+ throw new MWException( '$wgFlaggedRevsProtection is
disabled' );
+ }
+ $defaultConfig = self::getDefaultVisibilitySettings();
+ # Check if the page is not protected at all...
+ if ( $config['override'] == $defaultConfig['override']
+ && $config['autoreview'] == '' )
+ {
+ return "none"; // not protected
+ }
+ # All protection levels have 'override' on
+ if ( $config['override'] ) {
+ # The levels are defined by the 'autoreview' settings
+ if ( in_array( $config['autoreview'],
FlaggedRevs::getRestrictionLevels() ) ) {
+ return $config['autoreview'];
+ }
+ }
+ return "invalid";
+ }
+
+ /**
+ * Check if an fpc_level value is valid
+ * @param string $right
+ */
+ protected static function isValidRestriction( $right ) {
+ if ( $right == '' ) {
+ return true; // no restrictions (none)
+ }
+ return in_array( $right, FlaggedRevs::getRestrictionLevels(),
true );
+ }
+
+ /**
+ * Purge expired restrictions from the flaggedpage_config table.
+ * The stable version of pages may change and invalidation may be
required.
+ */
+ public static function purgeExpiredConfigurations() {
+ if ( wfReadOnly() ) return;
+
+ $dbw = wfGetDB( DB_MASTER );
+ $config = self::getDefaultVisibilitySettings(); // config is to
be reset
+ $encCutoff = $dbw->addQuotes( $dbw->timestamp() );
+ $ret = $dbw->select(
+ array( 'flaggedpage_config', 'page' ),
+ array( 'fpc_page_id', 'page_namespace', 'page_title' ),
+ array( 'page_id = fpc_page_id', 'fpc_expiry < ' .
$encCutoff ),
+ __METHOD__
+ // array( 'FOR UPDATE' )
+ );
+ $pagesClearConfig = array();
+ $pagesClearTracking = $titlesClearTracking = array();
+ foreach ( $ret as $row ) {
+ # If FlaggedRevs got "turned off" (in protection config)
+ # for this page, then clear it from the tracking
tables...
+ if ( FlaggedRevs::useOnlyIfProtected() &&
!$config['override'] ) {
+ $pagesClearTracking[] = $row->fpc_page_id; //
no stable version
+ $titlesClearTracking[] = Title::newFromRow(
$row ); // no stable version
+ }
+ $pagesClearConfig[] = $row->fpc_page_id; // page with
expired config
+ }
+ # Clear the expired config for these pages...
+ if ( count( $pagesClearConfig ) ) {
+ $dbw->delete( 'flaggedpage_config',
+ array( 'fpc_page_id' => $pagesClearConfig,
'fpc_expiry < ' . $encCutoff ),
+ __METHOD__
+ );
+ }
+ # Clear the tracking rows and update page_touched for the
+ # pages in $pagesClearConfig that do now have a stable
version...
+ if ( count( $pagesClearTracking ) ) {
+ FlaggedRevs::clearTrackingRows( $pagesClearTracking );
+ $dbw->update( 'page',
+ array( 'page_touched' => $dbw->timestamp() ),
+ array( 'page_id' => $pagesClearTracking ),
+ __METHOD__
+ );
+ }
+ # Also, clear their squid caches and purge other pages that use
this page.
+ # NOTE: all of these updates are deferred via
$wgDeferredUpdateList.
+ foreach ( $titlesClearTracking as $title ) {
+ FlaggedRevs::purgeSquid( $title );
+ if ( FlaggedRevs::inclusionSetting() ==
FR_INCLUDES_STABLE ) {
+ FlaggedRevs::HTMLCacheUpdates( $title ); //
purge pages that use this page
+ }
+ }
+ }
+}
Property changes on: trunk/extensions/FlaggedRevs/FlaggedPageConfig.php
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/extensions/FlaggedRevs/FlaggedRevision.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevision.php 2011-02-27 07:43:48 UTC
(rev 82883)
+++ trunk/extensions/FlaggedRevs/FlaggedRevision.php 2011-02-27 08:13:01 UTC
(rev 82884)
@@ -193,7 +193,7 @@
}
# Get visiblity settings...
if ( empty( $config ) ) {
- $config = FlaggedRevs::getPageStabilitySettings( $title,
$flags );
+ $config = FlaggedPageConfig::getPageStabilitySettings(
$title, $flags );
}
if ( !$config['override'] && FlaggedRevs::useOnlyIfProtected()
) {
return null; // page is not reviewable; no stable
version
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.class.php 2011-02-27 07:43:48 UTC
(rev 82883)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.class.php 2011-02-27 08:13:01 UTC
(rev 82884)
@@ -951,170 +951,6 @@
return false;
}
- # ################ Page configuration functions #################
-
- /**
- * Get visibility settings/restrictions for a page
- * @param Title $title, page title
- * @param int $flags, FR_MASTER
- * @returns array (associative) (select,override,autoreview,expiry)
- */
- public static function getPageStabilitySettings( Title $title, $flags =
0 ) {
- $db = ( $flags & FR_MASTER ) ?
- wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
- $row = $db->selectRow( 'flaggedpage_config',
- array( 'fpc_override', 'fpc_level', 'fpc_expiry' ),
- array( 'fpc_page_id' => $title->getArticleID() ),
- __METHOD__
- );
- return self::getVisibilitySettingsFromRow( $row );
- }
-
- /**
- * Get page configuration settings from a DB row
- */
- public static function getVisibilitySettingsFromRow( $row ) {
- if ( $row ) {
- # This code should be refactored, now that it's being
used more generally.
- $expiry = Block::decodeExpiry( $row->fpc_expiry );
- # Only apply the settings if they haven't expired
- if ( !$expiry || $expiry < wfTimestampNow() ) {
- $row = null; // expired
- self::purgeExpiredConfigurations();
- }
- }
- // Is there a non-expired row?
- if ( $row ) {
- $level = $row->fpc_level;
- if ( !self::isValidRestriction( $row->fpc_level ) ) {
- $level = ''; // site default; ignore fpc_level
- }
- $config = array(
- 'override' => $row->fpc_override ? 1 : 0,
- 'autoreview' => $level,
- 'expiry' => Block::decodeExpiry(
$row->fpc_expiry ) // TS_MW
- );
- # If there are protection levels defined check if this
is valid...
- if ( self::useProtectionLevels() ) {
- $level = self::getProtectionLevel( $config );
- if ( $level == 'invalid' || $level == 'none' ) {
- // If 'none', make sure expiry is
'infinity'
- $config =
self::getDefaultVisibilitySettings(); // revert to default (none)
- }
- }
- } else {
- # Return the default config if this page doesn't have
its own
- $config = self::getDefaultVisibilitySettings();
- }
- return $config;
- }
-
- /**
- * Get default page configuration settings
- */
- public static function getDefaultVisibilitySettings() {
- return array(
- # Keep this consistent across settings:
- # # 1 -> override, 0 -> don't
- 'override' => self::isStableShownByDefault() ? 1 : 0,
- 'autoreview' => '',
- 'expiry' => 'infinity'
- );
- }
-
-
- /**
- * Find what protection level a config is in
- * @param array $config
- * @returns string
- */
- public static function getProtectionLevel( array $config ) {
- if ( !self::useProtectionLevels() ) {
- throw new MWException( 'getProtectionLevel() called
with $wgFlaggedRevsProtection off' );
- }
- $defaultConfig = self::getDefaultVisibilitySettings();
- # Check if the page is not protected at all...
- if ( $config['override'] == $defaultConfig['override']
- && $config['autoreview'] == '' )
- {
- return "none"; // not protected
- }
- # All protection levels have 'override' on
- if ( $config['override'] ) {
- # The levels are defined by the 'autoreview' settings
- if ( in_array( $config['autoreview'],
self::getRestrictionLevels() ) ) {
- return $config['autoreview'];
- }
- }
- return "invalid";
- }
-
- /**
- * Check if an fpc_level value is valid
- * @param string $right
- */
- public static function isValidRestriction( $right ) {
- if ( $right == '' ) {
- return true; // no restrictions (none)
- }
- return in_array( $right, self::getRestrictionLevels(), true );
- }
-
- /**
- * Purge expired restrictions from the flaggedpage_config table.
- * The stable version of pages may change and invalidation may be
required.
- */
- public static function purgeExpiredConfigurations() {
- if ( wfReadOnly() ) return;
-
- $dbw = wfGetDB( DB_MASTER );
- $config = self::getDefaultVisibilitySettings(); // config is to
be reset
- $encCutoff = $dbw->addQuotes( $dbw->timestamp() );
- $ret = $dbw->select(
- array( 'flaggedpage_config', 'page' ),
- array( 'fpc_page_id', 'page_namespace', 'page_title' ),
- array( 'page_id = fpc_page_id', 'fpc_expiry < ' .
$encCutoff ),
- __METHOD__
- // array( 'FOR UPDATE' )
- );
- $pagesClearConfig = array();
- $pagesClearTracking = $titlesClearTracking = array();
- foreach ( $ret as $row ) {
- # If FlaggedRevs got "turned off" (in protection config)
- # for this page, then clear it from the tracking
tables...
- if ( self::useOnlyIfProtected() && !$config['override']
) {
- $pagesClearTracking[] = $row->fpc_page_id; //
no stable version
- $titlesClearTracking[] = Title::newFromRow(
$row ); // no stable version
- }
- $pagesClearConfig[] = $row->fpc_page_id; // page with
expired config
- }
- # Clear the expired config for these pages...
- if ( count( $pagesClearConfig ) ) {
- $dbw->delete( 'flaggedpage_config',
- array( 'fpc_page_id' => $pagesClearConfig,
'fpc_expiry < ' . $encCutoff ),
- __METHOD__
- );
- }
- # Clear the tracking rows and update page_touched for the
- # pages in $pagesClearConfig that do now have a stable
version...
- if ( count( $pagesClearTracking ) ) {
- self::clearTrackingRows( $pagesClearTracking );
- $dbw->update( 'page',
- array( 'page_touched' => $dbw->timestamp() ),
- array( 'page_id' => $pagesClearTracking ),
- __METHOD__
- );
- }
- # Also, clear their squid caches and purge other pages that use
this page.
- # NOTE: all of these updates are deferred via
$wgDeferredUpdateList.
- foreach ( $titlesClearTracking as $title ) {
- self::purgeSquid( $title );
- if ( FlaggedRevs::inclusionSetting() ==
FR_INCLUDES_STABLE ) {
- FlaggedRevs::HTMLCacheUpdates( $title ); //
purge pages that use this page
- }
- }
- }
-
# ################ Other utility functions #################
/**
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php 2011-02-27 07:43:48 UTC
(rev 82883)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php 2011-02-27 08:13:01 UTC
(rev 82884)
@@ -488,7 +488,7 @@
if( !FlaggedRevs::inReviewNamespace( $title ) ) {
$ret = '';
} else {
- $config =
FlaggedRevs::getPageStabilitySettings( $title );
+ $config =
FlaggedPageConfig::getPageStabilitySettings( $title );
$ret = $config['autoreview'];
}
}
@@ -1777,12 +1777,12 @@
array() : array( 'disabled' => 'disabled' );
# Get the current config/expiry
- $config = FlaggedRevs::getPageStabilitySettings(
$article->getTitle(), FR_MASTER );
+ $config = FlaggedPageConfig::getPageStabilitySettings(
$article->getTitle(), FR_MASTER );
$oldExpirySelect = ( $config['expiry'] == 'infinity' ) ?
'infinite' : 'existing';
# Load requested restriction level, default to current level...
$restriction = $wgRequest->getVal( 'mwStabilityLevel',
- FlaggedRevs::getProtectionLevel( $config ) );
+ FlaggedPageConfig::getProtectionLevel( $config ) );
# Load the requested expiry time (dropdown)
$expirySelect = $wgRequest->getVal(
'mwStabilizeExpirySelection', $oldExpirySelect );
# Load the requested expiry time (field)
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.php 2011-02-27 07:43:48 UTC
(rev 82883)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.php 2011-02-27 08:13:01 UTC
(rev 82884)
@@ -268,6 +268,8 @@
$wgAutoloadClasses['FlaggedArticleView'] = $dir . 'FlaggedArticleView.php';
# Load FlaggedArticle object class
$wgAutoloadClasses['FlaggedArticle'] = $dir . 'FlaggedArticle.php';
+# Load FlaggedPageConfig object class
+$wgAutoloadClasses['FlaggedPageConfig'] = $dir . 'FlaggedPageConfig.php';
# Load FlaggedRevision object class
$wgAutoloadClasses['FlaggedRevision'] = $dir . 'FlaggedRevision.php';
Modified: trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php
===================================================================
--- trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php 2011-02-27
07:43:48 UTC (rev 82883)
+++ trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php 2011-02-27
08:13:01 UTC (rev 82884)
@@ -237,7 +237,7 @@
protected function loadOldConfig() {
# Get the current page config
- $this->oldConfig = FlaggedRevs::getPageStabilitySettings(
$this->page, FR_MASTER );
+ $this->oldConfig = FlaggedPageConfig::getPageStabilitySettings(
$this->page, FR_MASTER );
}
/*
@@ -309,7 +309,7 @@
# Apply watchlist checkbox value (may be NULL)
$this->updateWatchlist();
# Take this opportunity to purge out expired configurations
- FlaggedRevs::purgeExpiredConfigurations();
+ FlaggedPageConfig::purgeExpiredConfigurations();
return true;
}
@@ -340,7 +340,7 @@
$settings = ''; // no level, expiry info
} else {
$params = $this->getLogParams();
- $action = ( $this->oldConfig ===
FlaggedRevs::getDefaultVisibilitySettings() )
+ $action = ( $this->oldConfig ===
FlaggedPageConfig::getDefaultVisibilitySettings() )
? 'config' // set a custom configuration
: 'modify'; // modified an existing custom
configuration
$log->addEntry( $action, $this->page, $reason,
@@ -542,7 +542,7 @@
global $wgFlaggedRevsProtectQuota;
if ( isset( $wgFlaggedRevsProtectQuota ) // quota exists
&& $this->autoreview != '' // and we are protecting
- && FlaggedRevs::getProtectionLevel( $this->oldConfig )
== 'none' ) // page unprotected
+ && FlaggedPageConfig::getProtectionLevel(
$this->oldConfig ) == 'none' ) // page unprotected
{
$dbw = wfGetDB( DB_MASTER );
$count = $dbw->selectField( 'flaggedpage_config',
'COUNT(*)', '', __METHOD__ );
@@ -551,7 +551,7 @@
}
}
# Autoreview only when protecting currently unprotected pages
- $this->reviewThis = ( FlaggedRevs::getProtectionLevel(
$this->oldConfig ) == 'none' );
+ $this->reviewThis = ( FlaggedPageConfig::getProtectionLevel(
$this->oldConfig ) == 'none' );
# Autoreview restriction => use stable
# No autoreview restriction => site default
$this->override = ( $this->autoreview != '' )
@@ -562,7 +562,7 @@
'override' => $this->override,
'autoreview' => $this->autoreview
);
- if ( FlaggedRevs::getProtectionLevel( $newConfig ) == 'invalid'
) {
+ if ( FlaggedPageConfig::getProtectionLevel( $newConfig ) ==
'invalid' ) {
return 'stabilize_invalid_level'; // double-check
configuration
}
# Check autoreview restriction setting
Modified: trunk/extensions/FlaggedRevs/specialpages/ConfiguredPages_body.php
===================================================================
--- trunk/extensions/FlaggedRevs/specialpages/ConfiguredPages_body.php
2011-02-27 07:43:48 UTC (rev 82883)
+++ trunk/extensions/FlaggedRevs/specialpages/ConfiguredPages_body.php
2011-02-27 08:13:01 UTC (rev 82884)
@@ -64,7 +64,7 @@
$wgOut->addWikiMsg( 'configuredpages-none' );
}
# Take this opportunity to purge out expired configurations
- FlaggedRevs::purgeExpiredConfigurations();
+ FlaggedPageConfig::purgeExpiredConfigurations();
}
public function formatRow( $row ) {
Modified: trunk/extensions/FlaggedRevs/specialpages/StablePages_body.php
===================================================================
--- trunk/extensions/FlaggedRevs/specialpages/StablePages_body.php
2011-02-27 07:43:48 UTC (rev 82883)
+++ trunk/extensions/FlaggedRevs/specialpages/StablePages_body.php
2011-02-27 08:13:01 UTC (rev 82884)
@@ -65,7 +65,7 @@
$wgOut->addWikiMsg( 'stablepages-none' );
}
# Take this opportunity to purge out expired configurations
- FlaggedRevs::purgeExpiredConfigurations();
+ FlaggedPageConfig::purgeExpiredConfigurations();
}
public function formatRow( $row ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs