Emit $wgSearchType as JavaScript config variable
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderStartUpModule.php
index 93c5d1b..d34fb5c 100644 (file)
@@ -42,7 +42,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        $wgEnableAPI, $wgEnableWriteAPI, $wgDBname,
                        $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath,
                        $wgCookiePrefix, $wgResourceLoaderMaxQueryLength,
-                       $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion;
+                       $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion,
+                       $wgSearchType;
 
                $mainPage = Title::newMainPage();
 
@@ -71,6 +72,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        'wgScriptPath' => $wgScriptPath,
                        'wgScriptExtension' => $wgScriptExtension,
                        'wgScript' => $wgScript,
+                       'wgSearchType' => $wgSearchType,
                        'wgVariantArticlePath' => $wgVariantArticlePath,
                        // Force object to avoid "empty" associative array from
                        // becoming [] instead of {} in JS (bug 34604)
@@ -185,6 +187,43 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                return true;
        }
 
+       /**
+        * Get the load URL of the startup modules.
+        *
+        * This is a helper for getScript(), but can also be called standalone, such
+        * as when generating an AppCache manifest.
+        *
+        * @param $context ResourceLoaderContext
+        * @return string
+        */
+       public static function getStartupModulesUrl( ResourceLoaderContext $context ) {
+               // The core modules:
+               $moduleNames = array( 'jquery', 'mediawiki' );
+               wfRunHooks( 'ResourceLoaderGetStartupModules', array( &$moduleNames ) );
+
+               // Get the latest version
+               $loader = $context->getResourceLoader();
+               $version = 0;
+               foreach ( $moduleNames as $moduleName ) {
+                       $version = max( $version,
+                               $loader->getModule( $moduleName )->getModifiedTime( $context )
+                       );
+               }
+
+               $query = array(
+                       'modules' => ResourceLoader::makePackedModulesString( $moduleNames ),
+                       'only' => 'scripts',
+                       'lang' => $context->getLanguage(),
+                       'skin' => $context->getSkin(),
+                       'debug' => $context->getDebug() ? 'true' : 'false',
+                       'version' => wfTimestamp( TS_ISO_8601_BASIC, $version )
+               );
+               // Ensure uniform query order
+               ksort( $query );
+               return  wfAppendQuery( wfScript( 'load' ), $query );
+       }
+
+
        /**
         * @param $context ResourceLoaderContext
         * @return string
@@ -195,30 +234,6 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                $out = file_get_contents( "$IP/resources/startup.js" );
                if ( $context->getOnly() === 'scripts' ) {
 
-                       // The core modules:
-                       $moduleNames = array( 'jquery', 'mediawiki' );
-                       wfRunHooks( 'ResourceLoaderGetStartupModules', array( &$moduleNames ) );
-
-                       // Get the latest version
-                       $loader = $context->getResourceLoader();
-                       $version = 0;
-                       foreach ( $moduleNames as $moduleName ) {
-                               $version = max( $version,
-                                       $loader->getModule( $moduleName )->getModifiedTime( $context )
-                               );
-                       }
-                       // Build load query for StartupModules
-                       $query = array(
-                               'modules' => ResourceLoader::makePackedModulesString( $moduleNames ),
-                               'only' => 'scripts',
-                               'lang' => $context->getLanguage(),
-                               'skin' => $context->getSkin(),
-                               'debug' => $context->getDebug() ? 'true' : 'false',
-                               'version' => wfTimestamp( TS_ISO_8601_BASIC, $version )
-                       );
-                       // Ensure uniform query order
-                       ksort( $query );
-
                        // Startup function
                        $configuration = $this->getConfig( $context );
                        $registrations = self::getModuleRegistrations( $context );
@@ -230,7 +245,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                                "};\n";
 
                        // Conditional script injection
-                       $scriptTag = Html::linkedScript( wfAppendQuery( wfScript( 'load' ), $query ) );
+                       $scriptTag = Html::linkedScript( self::getStartupModulesUrl( $context ) );
                        $out .= "if ( isCompatible() ) {\n" .
                                "\t" . Xml::encodeJsCall( 'document.write', array( $scriptTag ) ) .
                                "}\n" .
@@ -273,7 +288,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        $module = $loader->getModule( $name );
                        $time = max( $time, $module->getModifiedTime( $context ) );
                }
-               return $this->modifiedTime[$hash] = $time;
+               $this->modifiedTime[$hash] = $time;
+               return $this->modifiedTime[$hash];
        }
 
        /* Methods */