X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=a298a48d310449c053f38582bcb7463491d6f91e;hb=5a1eb2b96ad1dbf82a0878a1178c78137141b5cd;hp=dc659a9acdf8835d4455a99632e89eb4dcce26a8;hpb=537826a6741a04e9a494392607852edb4a686c1e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index dc659a9acd..a298a48d31 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2198,7 +2198,7 @@ class OutputPage { global $wgUser, $wgRequest, $wgLang; if ( $sk->commonPrintStylesheet() ) { - $this->addStyle( 'common/wikiprintable.css', 'print' ); + $this->addModuleStyles( 'mediawiki.legacy.wikiprintable' ); } $sk->setupUserCss( $this ); @@ -2281,21 +2281,46 @@ class OutputPage { } static function makeResourceLoaderLink( $skin, $modules, $only ) { - global $wgUser, $wgLang, $wgRequest, $wgScriptPath; + global $wgUser, $wgLang, $wgRequest, $wgLoadScript; // TODO: Should this be a static function of ResourceLoader instead? + // TODO: Divide off modules starting with "user", and add the user parameter to them $query = array( - 'modules' => implode( '|', array_unique( (array) $modules ) ), 'lang' => $wgLang->getCode(), - 'debug' => $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false', + 'debug' => ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) == 'true' ) ? 'true' : 'false', 'skin' => $wgUser->getSkin()->getSkinName(), 'only' => $only, ); - // Automatically select style/script elements - if ( $only === 'styles' ) { - return Html::linkedStyle( wfAppendQuery( wfScript( 'load' ), $query ) ); - } else { - return Html::linkedScript( wfAppendQuery( wfScript( 'load' ), $query ) ); + $moduleGroups = array( null => array(), 'user' => array() ); + foreach ( (array) $modules as $name ) { + $moduleGroups[strpos( $name, 'user' ) === 0 ? 'user' : null][] = $name; + } + $links = ''; + foreach ( $moduleGroups as $group => $modules ) { + if ( count( $modules ) ) { + sort( $modules ); + $query['modules'] = implode( '|', array_unique( (array) $modules ) ); + if ( $group === 'user' ) { + $query['user'] = $wgUser->getName(); + } + $context = new ResourceLoaderContext( new FauxRequest( $query ) ); + $timestamp = 0; + foreach ( $modules as $name ) { + if ( $module = ResourceLoader::getModule( $name ) ) { + $timestamp = max( $timestamp, $module->getModifiedTime( $context ) ); + } + } + $query['version'] = wfTimestamp( TS_ISO_8601, round( $timestamp, -2 ) ); + // Make queries uniform in order + ksort( $query ); + // Automatically select style/script elements + if ( $only === 'styles' ) { + $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ); + } else { + $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ); + } + } } + return $links; } /** @@ -2312,9 +2337,12 @@ class OutputPage { // Statup - this will immediately load jquery and mediawiki modules $scripts = self::makeResourceLoaderLink( $sk, 'startup', 'scripts' ); - // Configuration + + // Configuration -- This could be merged together with the load and go, but makeGlobalVariablesScript returns a + // whole script tag -- grumble grumble... $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; - // Support individual script requests in debug mode + + // Script and Messages "only" if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) { // Scripts foreach ( $this->getModuleScripts() as $name ) { @@ -2334,14 +2362,15 @@ class OutputPage { $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' ); } } + + // Modules - let the client calculate dependencies and batch requests as it likes if ( $this->getModules() ) { - // Modules - let the client calculate dependencies and batch requests as it likes $modules = FormatJson::encode( $this->getModules() ); $scripts .= Html::inlineScript( - "if ( mediaWiki !== undefined ) { mediaWiki.loader.load( {$modules} ); }" + "if ( mediaWiki !== undefined ) { mediaWiki.loader.load( {$modules} ); mediaWiki.loader.go(); }" ); } - // TODO: User Scripts should be included using the resource loader + // Add user JS if enabled if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) { $action = $wgRequest->getVal( 'action', 'view' ); @@ -2349,22 +2378,14 @@ class OutputPage { # XXX: additional security check/prompt? $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) ); } else { - $userpage = $wgUser->getUserPage(); - foreach( array( 'common', $sk->getSkinName() ) as $name ) { - $scriptpage = Title::makeTitleSafe( NS_USER, $userpage->getDBkey() . '/' . $name . '.js' ); - if ( $scriptpage && $scriptpage->exists() && ( $scriptpage->getLength() > 0 ) ) { - $userjs = $scriptpage->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType ); - $this->addScriptFile( $userjs, $scriptpage->getLatestRevID() ); - } - } + $scripts .= self::makeResourceLoaderLink( $sk, 'user', 'scripts' ); } } $scripts .= "\n" . $this->mScripts; - // This should be at the bottom of the body - below ALL other scripts - $scripts .= Html::inlineScript( "if ( mediaWiki !== undefined ) { mediaWiki.loader.go(); }" ); + // Add site JS if enabled if ( $wgUseSiteJs ) { - $scripts .= self::makeResourceLoaderLink( $sk, 'sitejs', 'scripts' ); + $scripts .= self::makeResourceLoaderLink( $sk, 'site', 'scripts' ); } return $scripts;