r59618 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59617‎ | r59618 | r59619 >
Date:05:41, 1 December 2009
Author:aaron
Status:ok
Tags:
Comment:
* Added getReviewNamespaces()/getPatrolNamespaces()
* Moved some config validation further up
* Code cleanups
* Added/changed some comments
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -1,16 +1,27 @@
22 <?php
3 -
 3+/**
 4+ * Class containing utility functions for a FlaggedRevs environment
 5+ *
 6+ * Class is lazily-initialized, calling load() as needed
 7+ */
48 class FlaggedRevs {
 9+ # Tag name/level config
510 protected static $dimensions = array();
611 protected static $minSL = array();
712 protected static $minQL = array();
813 protected static $minPL = array();
9 - protected static $loaded = false;
1014 protected static $qualityVersions = false;
1115 protected static $pristineVersions = false;
 16+ # Namespace config
 17+ protected static $reviewNamespaces = array();
 18+ protected static $patrolNamespaces = array();
 19+ # Restriction levels/config
1220 protected static $restrictionLevels = array();
13 -
 21+ protected static $protectionLevels = array();
 22+ # Temporary process cache variable
1423 protected static $includeVersionCache = array();
 24+
 25+ protected static $loaded = false;
1526
1627 public static function load() {
1728 global $wgFlaggedRevTags;
@@ -60,15 +71,18 @@
6172 }
6273 global $wgFlaggedRevsProtectLevels;
6374 $wgFlaggedRevsProtectLevels = (array)$wgFlaggedRevsProtectLevels;
64 - foreach( $wgFlaggedRevsProtectLevels as $level => &$config ) {
 75+ foreach( $wgFlaggedRevsProtectLevels as $level => $config ) {
6576 # Sanity check that the config is complete
66 - if( !isset($config['select']) || !isset($config['override']) || !isset($config['autoreview']) ) {
 77+ if( !isset($config['select']) || !isset($config['override'])
 78+ || !isset($config['autoreview'])
 79+ ) {
6780 throw new MWException( 'FlaggedRevs given incomplete $wgFlaggedRevsProtectLevels value!' );
6881 # Disallow reserved level names
6982 } else if( $level == 'invalid' || $level == 'none' ) {
7083 throw new MWException( 'FlaggedRevs given reserved $wgFlaggedRevsProtectLevels key!' );
7184 }
7285 $config['override'] = intval( $config['override'] ); // Type cleanup
 86+ self::$protectionLevels[$level] = $config;
7387 }
7488 global $wgFlaggedRevsRestrictionLevels;
7589 # Make sure that there is a "none" level
@@ -76,6 +90,22 @@
7791 if( !in_array('',self::$restrictionLevels) ) {
7892 self::$restrictionLevels = array('') + self::$restrictionLevels;
7993 }
 94+ # Make sure no talk namespaces are in review namespace
 95+ global $wgFlaggedRevsNamespaces;
 96+ foreach( $wgFlaggedRevsNamespaces as $ns ) {
 97+ if( MWNamespace::isTalk($ns) ) {
 98+ throw new MWException( 'FlaggedRevs given talk namespace in $wgFlaggedRevsNamespaces!' );
 99+ } else if( $ns == NS_MEDIAWIKI ) {
 100+ throw new MWException( 'FlaggedRevs given NS_MEDIAWIKI in $wgFlaggedRevsNamespaces!' );
 101+ }
 102+ }
 103+ self::$reviewNamespaces = $wgFlaggedRevsNamespaces;
 104+ # Reviewable namespaces override patrolable ones
 105+ global $wgFlaggedRevsPatrolNamespaces;
 106+ self::$patrolNamespaces = array_diff(
 107+ $wgFlaggedRevsPatrolNamespaces, $wgFlaggedRevsNamespaces
 108+ );
 109+
80110 self::$loaded = true;
81111 }
82112
@@ -195,9 +225,8 @@
196226 * @returns array (associative)
197227 */
198228 public static function getProtectionLevels() {
199 - global $wgFlaggedRevsProtectLevels;
200229 self::load(); // validates levels
201 - return $wgFlaggedRevsProtectLevels;
 230+ return self::$protectionLevels;
202231 }
203232
204233 /**
@@ -1075,12 +1104,16 @@
10761105 # Get the highest quality revision (not necessarily this one).
10771106 $oldid = $dbr->selectField( array('flaggedrevs','revision'),
10781107 'fr_rev_id',
1079 - array( 'fr_page_id' => $article->getId(),
 1108+ array(
 1109+ 'fr_page_id' => $article->getId(),
10801110 'rev_page = fr_page_id',
1081 - 'rev_id = fr_rev_id'),
 1111+ 'rev_id = fr_rev_id'
 1112+ ),
10821113 __METHOD__,
1083 - array( 'ORDER BY' => 'fr_quality DESC, fr_rev_id DESC',
1084 - 'USE INDEX' => array('flaggedrevs' => 'page_qal_rev','revision' => 'PRIMARY') )
 1114+ array(
 1115+ 'ORDER BY' => 'fr_quality DESC, fr_rev_id DESC',
 1116+ 'USE INDEX' => array('flaggedrevs' => 'page_qal_rev','revision' => 'PRIMARY')
 1117+ )
10851118 );
10861119 return $oldid;
10871120 }
@@ -1216,21 +1249,42 @@
12171250 else
12181251 return 0;
12191252 }
 1253+
 1254+ /**
 1255+ * Get the list of reviewable namespaces
 1256+ * @return array
 1257+ */
 1258+ public static function getReviewNamespaces() {
 1259+ self::load(); // validates namespaces
 1260+ return self::$reviewNamespaces;
 1261+ }
12201262
12211263 /**
 1264+ * Get the list of patrolable namespaces
 1265+ * @return array
 1266+ */
 1267+ public static function getPatrolNamespaces() {
 1268+ self::load(); // validates namespaces
 1269+ return self::$patrolNamespaces;
 1270+ }
 1271+
 1272+
 1273+ /**
12221274 * Is this page in reviewable namespace?
 1275+ * Note: this checks $wgFlaggedRevsWhitelist
12231276 * @param Title, $title
12241277 * @return bool
12251278 */
12261279 public static function isPageReviewable( $title ) {
1227 - global $wgFlaggedRevsNamespaces, $wgFlaggedRevsWhitelist;
1228 - # FIXME: Treat NS_MEDIA as NS_FILE
1229 - $ns = ( $title->getNamespace() == NS_MEDIA ) ? NS_FILE : $title->getNamespace();
 1280+ global $wgFlaggedRevsWhitelist;
 1281+ $namespaces = self::getReviewNamespaces();
 1282+ $ns = ( $title->getNamespace() == NS_MEDIA ) ?
 1283+ NS_FILE : $title->getNamespace(); // Treat NS_MEDIA as NS_FILE
12301284 # Check for MW: pages and whitelist for exempt pages
1231 - if( $ns == NS_MEDIAWIKI || in_array( $title->getPrefixedDBKey(), $wgFlaggedRevsWhitelist ) ) {
 1285+ if( in_array( $title->getPrefixedDBKey(), $wgFlaggedRevsWhitelist ) ) {
12321286 return false;
12331287 }
1234 - return ( in_array($ns,$wgFlaggedRevsNamespaces) && !$title->isTalkPage() );
 1288+ return ( in_array($ns,$namespaces) );
12351289 }
12361290
12371291 /**
@@ -1239,14 +1293,10 @@
12401294 * @return bool
12411295 */
12421296 public static function isPagePatrollable( $title ) {
1243 - global $wgFlaggedRevsPatrolNamespaces;
1244 - # No collisions!
1245 - if( self::isPageReviewable($title) ) {
1246 - return false;
1247 - }
1248 - # FIXME: Treat NS_MEDIA as NS_FILE
1249 - $ns = ( $title->getNamespace() == NS_MEDIA ) ? NS_FILE : $title->getNamespace();
1250 - return ( in_array($ns,$wgFlaggedRevsPatrolNamespaces) );
 1297+ $namespaces = self::getPatrolNamespaces();
 1298+ $ns = ( $title->getNamespace() == NS_MEDIA ) ?
 1299+ NS_FILE : $title->getNamespace(); // Treat NS_MEDIA as NS_FILE
 1300+ return ( in_array($ns,$namespaces) );
12511301 }
12521302
12531303 /**

Status & tagging log