http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72776
Revision: 72776
Author: tparscal
Date: 2010-09-11 07:33:16 +0000 (Sat, 11 Sep 2010)
Log Message:
-----------
Fixed user scripts/styles and site scripts/styles - they were totally broken in
r72772 - but now the refactoring is paying off.
Modified Paths:
--------------
trunk/phase3/includes/OutputPage.php
trunk/phase3/includes/ResourceLoaderContext.php
trunk/phase3/includes/ResourceLoaderModule.php
Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php 2010-09-11 07:21:18 UTC (rev
72775)
+++ trunk/phase3/includes/OutputPage.php 2010-09-11 07:33:16 UTC (rev
72776)
@@ -2360,7 +2360,6 @@
);
}
- // 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' );
@@ -2368,14 +2367,7 @@
# 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;
Modified: trunk/phase3/includes/ResourceLoaderContext.php
===================================================================
--- trunk/phase3/includes/ResourceLoaderContext.php 2010-09-11 07:21:18 UTC
(rev 72775)
+++ trunk/phase3/includes/ResourceLoaderContext.php 2010-09-11 07:33:16 UTC
(rev 72776)
@@ -86,7 +86,7 @@
}
public function getUser() {
- return $this->skin;
+ return $this->user;
}
public function getDebug() {
Modified: trunk/phase3/includes/ResourceLoaderModule.php
===================================================================
--- trunk/phase3/includes/ResourceLoaderModule.php 2010-09-11 07:21:18 UTC
(rev 72775)
+++ trunk/phase3/includes/ResourceLoaderModule.php 2010-09-11 07:33:16 UTC
(rev 72776)
@@ -703,29 +703,51 @@
abstract protected function getPages( ResourceLoaderContext $context );
+ /* Protected Methods */
+
+ protected function getContent( $page, $ns ) {
+ if ( $ns === NS_MEDIAWIKI ) {
+ return wfMsgExt( $page, 'content' );
+ }
+ if ( $title = Title::newFromText( $page, $ns ) ) {
+ if ( $title->isValidCssJsSubpage() && $revision =
Revision::newFromTitle( $title ) ) {
+ return $revision->getRawText();
+ }
+ }
+ return null;
+ }
+
/* Methods */
public function getScript( ResourceLoaderContext $context ) {
+ global $wgCanonicalNamespaceNames;
+
$scripts = '';
foreach ( $this->getPages( $context ) as $page => $options ) {
if ( $options['type'] === 'script' ) {
- $script = wfMsgExt( $page, 'content' );
- $scripts .= "/* MediaWiki:$page */\n" . (
!wfEmptyMsg( $page, $script ) ? $script : '' ) . "\n";
+ if ( $script = $this->getContent( $page,
$options['ns'] ) ) {
+ $ns =
$wgCanonicalNamespaceNames[$options['ns']];
+ $scripts .= "/*$ns:$page */\n$script\n";
+ }
}
}
return $scripts;
}
public function getStyles( ResourceLoaderContext $context ) {
+ global $wgCanonicalNamespaceNames;
+
$styles = array();
foreach ( $this->getPages( $context ) as $page => $options ) {
if ( $options['type'] === 'style' ) {
$media = isset( $options['media'] ) ?
$options['media'] : 'all';
- $style = wfMsgExt( $page, 'content' );
- if ( !isset( $styles[$media] ) ) {
- $styles[$media] = '';
+ if ( $style = $this->getContent( $page,
$options['ns'] ) ) {
+ if ( !isset( $styles[$media] ) ) {
+ $styles[$media] = '';
+ }
+ $ns =
$wgCanonicalNamespaceNames[$options['ns']];
+ $styles[$media] .= "/* $ns:$page
*/\n$style\n";
}
- $styles[$media] .= "/* MediaWiki:$page */\n" .
( !wfEmptyMsg( $page, $style ) ? $style : '' ) . "\n";
}
}
return $styles;
@@ -738,7 +760,7 @@
}
$titles = array();
foreach ( $this->getPages( $context ) as $page => $options ) {
- $titles[] = Title::makeTitle( NS_MEDIAWIKI, $page );
+ $titles[] = Title::makeTitle( $options['ns'], $page );
}
// Do batch existence check
// TODO: This would work better if page_touched were loaded by
this as well
@@ -765,14 +787,14 @@
global $wgHandheldStyle;
$pages = array(
- 'Common.js' => array( 'type' => 'script' ),
- 'Common.css' => array( 'type' => 'style' ),
- ucfirst( $context->getSkin() ) . '.js' => array( 'type'
=> 'script' ),
- ucfirst( $context->getSkin() ) . '.css' => array(
'type' => 'style' ),
- 'Print.css' => array( 'type' => 'style', 'media' =>
'print' ),
+ 'Common.js' => array( 'ns' => NS_MEDIAWIKI, 'type' =>
'script' ),
+ 'Common.css' => array( 'ns' => NS_MEDIAWIKI, 'type' =>
'style' ),
+ ucfirst( $context->getSkin() ) . '.js' => array( 'ns'
=> NS_MEDIAWIKI, 'type' => 'script' ),
+ ucfirst( $context->getSkin() ) . '.css' => array( 'ns'
=> NS_MEDIAWIKI, 'type' => 'style' ),
+ 'Print.css' => array( 'ns' => NS_MEDIAWIKI, 'type' =>
'style', 'media' => 'print' ),
);
if ( $wgHandheldStyle ) {
- $pages['Handheld.css'] = array( 'type' => 'style',
'media' => 'handheld' );
+ $pages['Handheld.css'] = array( 'ns' => NS_MEDIAWIKI,
'type' => 'style', 'media' => 'handheld' );
}
return $pages;
}
@@ -789,11 +811,12 @@
global $wgAllowUserCss;
if ( $context->getUser() && $wgAllowUserCss ) {
- $user = User::newFromName( $context->getUser() );
- $userPage = $user->getUserPage()->getPrefixedText();
+ $username = $context->getUser();
return array(
- "$userPage/common.css" => array( 'type' =>
'style' ),
- "$userPage/" . $context->getSkin() . '.css' =>
array( 'type' => 'style' ),
+ "$username/common.js" => array( 'ns' =>
NS_USER, 'type' => 'script' ),
+ "$username/" . $context->getSkin() . '.js' =>
array( 'ns' => NS_USER, 'type' => 'script' ),
+ "$username/common.css" => array( 'ns' =>
NS_USER, 'type' => 'style' ),
+ "$username/" . $context->getSkin() . '.css' =>
array( 'ns' => NS_USER, 'type' => 'style' ),
);
}
return array();
@@ -816,8 +839,12 @@
if ( isset( $this->modifiedTime[$hash] ) ) {
return $this->modifiedTime[$hash];
}
- $user = User::newFromName( $context->getUser() );
- return $this->modifiedTime[$hash] = $user->getTouched();
+ if ( $context->getUser() ) {
+ $user = User::newFromName( $context->getUser() );
+ return $this->modifiedTime[$hash] = $user->getTouched();
+ } else {
+ return 0;
+ }
}
public function getStyles( ResourceLoaderContext $context ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs