MarkTraceur has uploaded a new change for review.

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


Change subject: Add convenience function for checking preferences
......................................................................

Add convenience function for checking preferences

Extensions shouldn't need to deal with our implementation details like
enable-all or the beta-feature- prefix, so let's just abstract all of
that out for them.

Change-Id: I705b9d70efdda277e843c355286da0fa34554e90
---
M BetaFeatures.php
A includes/BetaFeaturesUtils.php
2 files changed, 51 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BetaFeatures 
refs/changes/90/74290/1

diff --git a/BetaFeatures.php b/BetaFeatures.php
index 27b6572..ea25514 100644
--- a/BetaFeatures.php
+++ b/BetaFeatures.php
@@ -21,17 +21,25 @@
  * @copyright Copyright © 2013, Mark Holmquist
  */
 
+// Custom field type for beta features - most of the HTML is in here
 $wgAutoloadClasses['HTMLBetaFeatureField'] = __DIR__ . 
'/includes/HTMLBetaFeatureField.php';
-$wgAutoloadClasses['BetaFeaturesHooks'] = __DIR__ . '/BetaFeaturesHooks.php';
-$wgAutoloadClasses['SpecialBetaFeatures'] = __DIR__ . 
'/SpecialBetaFeatures.php';
 
+// Utility functions for, e.g., checking whether a preference is enabled
+$wgAutoloadClasses['BetaFeatures'] = __DIR__ . 
'/includes/BetaFeaturesUtils.php';
+
+// Hooks
+$wgAutoloadClasses['BetaFeaturesHooks'] = __DIR__ . '/BetaFeaturesHooks.php';
+$wgHooks['GetPreferences'][] = 'BetaFeaturesHooks::getPreferences';
+
+// Special page
+$wgAutoloadClasses['SpecialBetaFeatures'] = __DIR__ . 
'/SpecialBetaFeatures.php';
+$wgSpecialPages['BetaFeatures'] = 'SpecialBetaFeatures';
+
+// i18n
 $wgExtensionMessagesFiles['BetaFeatures'] = __DIR__ . '/BetaFeatures.i18n.php';
 $wgExtensionMessagesFiles[ 'BetaFeaturesAlias' ] = __DIR__ . 
'/BetaFeatures.alias.php';
 
-$wgSpecialPages['BetaFeatures'] = 'SpecialBetaFeatures';
-
-$wgHooks['GetPreferences'][] = 'BetaFeaturesHooks::getPreferences';
-
+// Credits
 $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'BetaFeatures',
@@ -43,6 +51,7 @@
        'url' => 'https://mediawiki.org/wiki/Extension:BetaFeatures',
 );
 
+// Registering modules for special page
 $wgResourceModules['ext.betaFeatures'] = array(
        'styles' => array(
                'css/betafeatures.css',
diff --git a/includes/BetaFeaturesUtils.php b/includes/BetaFeaturesUtils.php
new file mode 100644
index 0000000..e97b5c1
--- /dev/null
+++ b/includes/BetaFeaturesUtils.php
@@ -0,0 +1,36 @@
+<?php
+/*
+ * This file is part of the MediaWiki extension BetaFeatures.
+ *
+ * BetaFeatures is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * BetaFeatures is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with BetaFeatures.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @file
+ * @ingroup extensions
+ * @author Mark Holmquist <[email protected]>
+ * @copyright Copyright © 2013, Mark Holmquist
+ */
+
+class BetaFeatures {
+
+       /**
+        * Check if a user has a feature enabled.
+        *
+        * @param $user User The user to check
+        * @param $feature string The name of the feature preference to check
+        * @return bool
+        */
+       static function isFeatureEnabled( $user, $feature ) {
+               return $user->getOption( 'enable-all-beta' ) || 
$user-getOption( 'beta-feature-' . $feature );
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I705b9d70efdda277e843c355286da0fa34554e90
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BetaFeatures
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>

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

Reply via email to