Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/154984
Change subject: [WIP] Convert to use Config instead of globals
......................................................................
[WIP] Convert to use Config instead of globals
I got about halfway through...
Change-Id: I1307d9693abc584286ef2c3da931cc26fb50bd6b
---
M BasePageFilter.php
M GettingStarted.php
M Hooks.php
M MoreLikePageSuggester.php
M PageFilterFactory.php
M api/ApiGettingStartedGetPages.php
6 files changed, 56 insertions(+), 29 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GettingStarted
refs/changes/84/154984/1
diff --git a/BasePageFilter.php b/BasePageFilter.php
index 7ad1d2e..096c219 100644
--- a/BasePageFilter.php
+++ b/BasePageFilter.php
@@ -2,7 +2,7 @@
namespace GettingStarted;
-use Title, User;
+use Config, Title, User;
/**
Approve or reject a given page for suitability with GettingStarted.
@@ -11,6 +11,9 @@
class BasePageFilter {
/** @var User */
protected $user;
+
+ /** @var Config $config */
+ protected $config;
/** @var Title */
protected $excludedTitle;
@@ -21,17 +24,19 @@
/**
* Constructor.
*
+ * @param Config $config
* @param User $user user object, for permissions checks
* @param Title $excludedTitle optional title to exclude, to avoid
consecutive duplicates
*/
- public function __construct( User $user, Title $excludedTitle = null ) {
+ public function __construct( Config $config, User $user, Title
$excludedTitle = null ) {
+ $this->config = $config;
$this->user = $user;
$this->excludedTitle = $excludedTitle;
}
protected function inExcludedCategories( Title $title ) {
$articleID = $title->getArticleID();
- $excludedCategories = self::getExcludedCategories();
+ $excludedCategories = $this->getExcludedCategories();
$dbr = wfGetDB( DB_SLAVE );
foreach( $excludedCategories as $cat ) {
$res = $dbr->selectRow( 'categorylinks', '1', array(
@@ -47,15 +52,15 @@
return false;
}
- protected static function getExcludedCategories() {
- global $wgGettingStartedExcludedCategories;
+ protected function getExcludedCategories() {
+ $excludedCategories = $this->config->get(
'GettingStartedExcludedCategories' );
if ( self::$excludedCategories === null ) {
// TODO (phuedx 2014-02-010) Create a collection class
// for categories, which could be generalised in the
// future, i.e. CategoryCollection.
self::$excludedCategories = array();
- foreach( $wgGettingStartedExcludedCategories as
$rawCategory ) {
+ foreach( $excludedCategories as $rawCategory ) {
// Canonicalize the category name.
$title = Title::newFromText( $rawCategory );
if ( !$title || !$title->inNamespace(
NS_CATEGORY ) ) {
diff --git a/GettingStarted.php b/GettingStarted.php
index e3666e4..e38b645 100644
--- a/GettingStarted.php
+++ b/GettingStarted.php
@@ -76,6 +76,8 @@
*/
$wgGettingStartedRunTest = false;
+$wgConfigRegistry['gettingstarted'] = 'GlobalVarConfig::newInstance';
+
$wgAutoloadClasses += array(
'GettingStarted\Hooks' => __DIR__ . '/Hooks.php',
'GettingStarted\RedisCategorySync' => __DIR__ .
'/RedisCategorySync.php',
@@ -93,7 +95,13 @@
$wgExtensionMessagesFiles[ 'GettingStarted' ] = __DIR__ .
'/GettingStarted.i18n.php';
// APIs
-$wgAPIListModules['gettingstartedgetpages'] =
'GettingStarted\ApiGettingStartedGetPages';
+$wgAPIListModules['gettingstartedgetpages'] = array(
+ 'class' => 'GettingStarted\ApiGettingStartedGetPages',
+ 'factory' => function( $apiQuery, $moduleName ) {
+ $config =
ConfigFactory::getDefaultInstance()->makeConfig( 'gettingstarted' );
+ return new \GettingStarted\ApiGettingStartedGetpages(
$apiQuery, $moduleName, $config );
+ },
+);
// Modules
diff --git a/Hooks.php b/Hooks.php
index 87cdb9d..7a455df 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -2,7 +2,7 @@
namespace GettingStarted;
-use FormatJson, Title, WebRequest, OutputPage, User;
+use ConfigFactory, FormatJson, Title, WebRequest, OutputPage, User;
/**
* Hooks for GettingStarted extension
@@ -189,7 +189,8 @@
* @return bool
*/
public static function onMakeGlobalVariablesScript( &$vars, OutputPage
$out ) {
- global $wgGettingStartedTasks;
+ $tasks = ConfigFactory::getDefaultInstance()->makeConfig(
'gettingstarted' )
+ ->get( 'GettingStartedTasks' );
$user = $out->getUser();
@@ -199,7 +200,7 @@
if ( self::shouldLoadToolbar( $out, $user ) ) {
$request = $out->getRequest();
$taskName = self::getUnprefixedGettingStartedTask(
$request, $out->getTitle() );
- $task = $wgGettingStartedTasks[ $taskName ];
+ $task = $tasks[ $taskName ];
if ( $user->isAnon() ) {
// Anons can't change preferences, and the HTML
is cached,
@@ -238,9 +239,11 @@
* @return bool
*/
public static function onResourceLoaderGetConfigVars( array &$vars ) {
- global $wgGettingStartedCategoriesForTaskTypes;
-
- $categoryCount = count( $wgGettingStartedCategoriesForTaskTypes
);
+ $categoryCount = count(
+ ConfigFactory::getDefaultInstance()
+ ->makeConfig( 'gettingstarted' )
+ ->get( 'GettingStartedCategoriesForTaskTypes' )
+ );
$vars['wgGettingStartedConfig'] = array(
'hasCategories' => ( $categoryCount > 0 ),
@@ -253,11 +256,12 @@
* Adds applicable modules to the page
*
* @param OutputPage $out output page
- * @param Skin $skin current skin
+ * @param \Skin $skin current skin
* @return bool
*/
public static function onBeforePageDisplay( OutputPage $out, \Skin
$skin ) {
- global $wgGettingStartedRunTest;
+ $runTest = ConfigFactory::getDefaultInstance()->makeConfig(
'gettingstarted' )
+ ->get( 'GettingStartedRunTest' );
$user = $out->getUser();
@@ -286,7 +290,7 @@
self::addReturnToModules( $out, $skin );
}
- if ( $wgGettingStartedRunTest && $user->isLoggedIn() ) {
+ if ( $runTest && $user->isLoggedIn() ) {
$out->addModules(
'ext.gettingstarted.lightbulb.postEdit' );
if ( $user->getEditCount() > 0 ) {
$out->addModules(
'ext.gettingstarted.lightbulb.flyout' );
@@ -300,7 +304,7 @@
* Look for page edits where there's an item in the user's openTask
cookie
* matching the title whose task is 'gettingstarted'
* Approach comes from AbuseFilter and MobileFrontend extensions.
- * @param RecentChange $recentChange RecentChanges entry
+ * @param \RecentChange $recentChange RecentChanges entry
* @return bool
*/
public static function onRecentChange_save( \RecentChange $recentChange
) {
@@ -367,6 +371,7 @@
*
* @param User $user user to check
* @return boolean true if recent, false otherwise
+ * @todo is this unused?
*/
protected static function isRecentSignup( User $user ) {
global $wgGettingStartedRecentPeriodInSeconds;
@@ -397,6 +402,7 @@
* @param User $user user object of the now-anonymous user
* @param string $inject_html reference that can be used to inject HTML
into logout page.
* @param string $old_name name of user that just logged out
+ * @return bool
*/
public static function onUserLogoutComplete( &$user, &$inject_html,
$old_name ) {
global $wgRequest;
@@ -416,6 +422,7 @@
* @param array $returnToQuery key value pairs of url parameters
* @param boolean $stickHTTPS Keep redirect link on HTTPs
* @param string $type login redirect condition
+ * @return bool
*/
public static function onCentralAuthPostLoginRedirect( &$returnTo,
&$returnToQuery, $stickHTTPS, $type ) {
$returnToQueryArray = wfCgiToArray( $returnToQuery );
@@ -437,6 +444,7 @@
* @param string $returnTo page name to redirect to
* @param array $returnToQuery key value pairs of url parameters
* @param string $type login redirect condition
+ * @return bool
*/
public static function onPostLoginRedirect( &$returnTo,
&$returnToQuery, &$type ) {
// Abort if we should not show getting started
@@ -492,8 +500,6 @@
*/
public static function onPageContentSaveComplete( $article, $user,
$content, $summary,
$isMinor, $isWatch, $section, $flags, $revision, $status,
$baseRevId ) {
-
- global $wgRequest;
if ( $revision === null ) {
return true;
diff --git a/MoreLikePageSuggester.php b/MoreLikePageSuggester.php
index 76688a2..979ccbb 100644
--- a/MoreLikePageSuggester.php
+++ b/MoreLikePageSuggester.php
@@ -5,7 +5,7 @@
use Title;
class MoreLikePageSuggester implements PageSuggester {
- /** @var WebRequest */
+ /** @var \WebRequest */
protected $request;
/** @var Title */
@@ -15,7 +15,7 @@
* Constructs a MoreLikePageSuggester with the given
* request and base title
*
- * @param WebRequest $request Original web request
+ * @param \WebRequest $request Original web request
* @param Title $baseTitle Title to base suggestions on
*/
public function __construct( \WebRequest $request, Title $baseTitle ) {
diff --git a/PageFilterFactory.php b/PageFilterFactory.php
index 12a6bb4..0498dfe 100644
--- a/PageFilterFactory.php
+++ b/PageFilterFactory.php
@@ -7,16 +7,17 @@
* Gets the PageFilter object for a given type
*
* @param string $taskName Task name
- * @param User $user User getting suggestions
- * @param Title $excludedTitle Title to exclude (optional)
+ * @param \Config $config
+ * @param \User $user User getting suggestions
+ * @param \Title $excludedTitle Title to exclude (optional)
*/
- public static function getPageFilter( $taskName, \User $user, \Title
$excludedTitle = null ) {
- global $wgGettingStartedCategoriesForTaskTypes;
+ public static function getPageFilter( $taskName, \Config $config, \User
$user, \Title $excludedTitle = null ) {
+ $categoriesForTaskTypes = $config->get(
'GettingStartedCategoriesForTaskTypes' );
- if ( isset( $wgGettingStartedCategoriesForTaskTypes[$taskName]
) ) {
+ if ( isset( $categoriesForTaskTypes[$taskName] ) ) {
return new CategoryPageFilter( $user, $excludedTitle );
} else {
- return new BasePageFilter( $user, $excludedTitle );
+ return new BasePageFilter( $config, $user,
$excludedTitle );
}
}
}
diff --git a/api/ApiGettingStartedGetPages.php
b/api/ApiGettingStartedGetPages.php
index c260c8a..a43994d 100644
--- a/api/ApiGettingStartedGetPages.php
+++ b/api/ApiGettingStartedGetPages.php
@@ -2,13 +2,20 @@
namespace GettingStarted;
-use ApiBase, Category, Title;
+use ApiBase, Config, Title;
class ApiGettingStartedGetPages extends \ApiQueryGeneratorBase {
+
+ /**
+ * @var Config
+ */
+ private $gsConfig;
+
const MAX_SUGGESTER_CALLS = 10;
- public function __construct( \ApiQuery $queryModule, $moduleName ) {
+ public function __construct( \ApiQuery $queryModule, $moduleName,
Config $config ) {
parent::__construct( $queryModule, $moduleName, 'gsgp' );
+ $this->gsConfig = $config;
}
public function execute() {
--
To view, visit https://gerrit.wikimedia.org/r/154984
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1307d9693abc584286ef2c3da931cc26fb50bd6b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GettingStarted
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits