Manybubbles has uploaded a new change for review.
https://gerrit.wikimedia.org/r/100999
Change subject: More BetaFeatures check to hooks called later
......................................................................
More BetaFeatures check to hooks called later
The BetaFeatures check was breaking some api calls because it was being
done before the request was fully initialized. Now we wait until the
last possible second to perform the BetaFeatures check and the user is
good and ready.
Requires I0a167faaa4166da381194c53373d82e038848924 in mediawiki core to
function for api requests.
Bug: 58380
Change-Id: I3d6f43846f8086d7aa41d2c43150a7fa8d612d59
---
M CirrusSearch.php
M includes/CirrusSearch.body.php
2 files changed, 43 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/99/100999/1
diff --git a/CirrusSearch.php b/CirrusSearch.php
index dd76f4a..b951168 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -197,25 +197,13 @@
/**
* Hooks
*/
+$wgHooks[ 'ApiBeforeMain' ][] = 'CirrusSearch::apiBeforeMainHook';
$wgHooks[ 'ArticleDeleteComplete' ][] =
'CirrusSearch::articleDeleteCompleteHook';
+$wgHooks[ 'BeforeInitialize' ][] = 'CirrusSearch::beforeInitializeHook';
+$wgHooks[ 'GetBetaFeaturePreferences' ][] = 'CirrusSearch::getPreferencesHook';
$wgHooks[ 'LinksUpdateComplete' ][] =
'CirrusSearchUpdater::linksUpdateCompletedHook';
$wgHooks[ 'SoftwareInfo' ][] = 'CirrusSearch::softwareInfoHook';
$wgHooks[ 'SpecialSearchResultsPrepend' ][] =
'CirrusSearch::specialSearchResultsPrependHook';
-$wgHooks[ 'GetBetaFeaturePreferences' ][] = 'CirrusSearch::getPreferencesHook';
-// Install our prefix search hook only if we're enabled.
-$wgExtensionFunctions[] = function() {
- global $wgSearchType, $wgHooks, $wgCirrusSearchEnablePref;
- $user = RequestContext::getMain()->getUser();
- if ( $wgCirrusSearchEnablePref && $user->isLoggedIn() && class_exists(
'BetaFeatures' )
- && BetaFeatures::isFeatureEnabled( $user,
'cirrussearch-default' )
- ) {
- // If the user has the BetaFeature enabled, use Cirrus as
default
- $wgSearchType = 'CirrusSearch';
- }
- if ( $wgSearchType === 'CirrusSearch' ) {
- $wgHooks['PrefixSearchBackend'][] =
'CirrusSearch::prefixSearch';
- }
-};
/**
* i18n
diff --git a/includes/CirrusSearch.body.php b/includes/CirrusSearch.body.php
index b11290f..43da983 100644
--- a/includes/CirrusSearch.body.php
+++ b/includes/CirrusSearch.body.php
@@ -152,4 +152,44 @@
return true;
}
+ /**
+ * Hooked to call initialize after the user is set up.
+ */
+ public static function beforeInitializeHook( $title, $unused,
$outputPage, $user, $request, $mediaWiki ) {
+ self::initialize( $user );
+
+ return true;
+ }
+
+ /**
+ * Hooked to call initialize after the user is set up.
+ */
+ public static function apiBeforeMainHook( $apiMain ) {
+ self::initialize( RequestContext::getMain()->getUser() );
+
+ return true;
+ }
+
+ /**
+ * Initializes the portions of Cirrus that require the $user to be
fully initialized and therefore
+ * cannot be done in $wgExtensionFunctions. Specifically this means
the beta features check and
+ * installing the prefix search hook, because it needs information from
the beta features check.
+ */
+ private static function initialize( $user ) {
+ global $wgCirrusSearchEnablePref;
+ global $wgSearchType;
+ global $wgHooks;
+
+ // If the user has the BetaFeature enabled, use Cirrus as
default.
+ if ( $wgCirrusSearchEnablePref && $user->isLoggedIn() &&
class_exists( 'BetaFeatures' )
+ && BetaFeatures::isFeatureEnabled( $user,
'cirrussearch-default' )
+ ) {
+ $wgSearchType = 'CirrusSearch';
+ }
+
+ // Install our prefix search hook only if we're enabled.
+ if ( $wgSearchType === 'CirrusSearch' ) {
+ $wgHooks['PrefixSearchBackend'][] =
'CirrusSearch::prefixSearch';
+ }
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/100999
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d6f43846f8086d7aa41d2c43150a7fa8d612d59
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits