Index: trunk/phase3/includes/ResourceLoaderContext.php |
— | — | @@ -86,7 +86,7 @@ |
87 | 87 | } |
88 | 88 | |
89 | 89 | public function getUser() { |
90 | | - return $this->skin; |
| 90 | + return $this->user; |
91 | 91 | } |
92 | 92 | |
93 | 93 | public function getDebug() { |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -2360,7 +2360,6 @@ |
2361 | 2361 | ); |
2362 | 2362 | } |
2363 | 2363 | |
2364 | | - // TODO: User Scripts should be included using the resource loader |
2365 | 2364 | // Add user JS if enabled |
2366 | 2365 | if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) { |
2367 | 2366 | $action = $wgRequest->getVal( 'action', 'view' ); |
— | — | @@ -2368,14 +2367,7 @@ |
2369 | 2368 | # XXX: additional security check/prompt? |
2370 | 2369 | $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) ); |
2371 | 2370 | } else { |
2372 | | - $userpage = $wgUser->getUserPage(); |
2373 | | - foreach( array( 'common', $sk->getSkinName() ) as $name ) { |
2374 | | - $scriptpage = Title::makeTitleSafe( NS_USER, $userpage->getDBkey() . '/' . $name . '.js' ); |
2375 | | - if ( $scriptpage && $scriptpage->exists() && ( $scriptpage->getLength() > 0 ) ) { |
2376 | | - $userjs = $scriptpage->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType ); |
2377 | | - $this->addScriptFile( $userjs, $scriptpage->getLatestRevID() ); |
2378 | | - } |
2379 | | - } |
| 2371 | + $scripts .= self::makeResourceLoaderLink( $sk, 'user', 'scripts' ); |
2380 | 2372 | } |
2381 | 2373 | } |
2382 | 2374 | $scripts .= "\n" . $this->mScripts; |
Index: trunk/phase3/includes/ResourceLoaderModule.php |
— | — | @@ -703,29 +703,51 @@ |
704 | 704 | |
705 | 705 | abstract protected function getPages( ResourceLoaderContext $context ); |
706 | 706 | |
| 707 | + /* Protected Methods */ |
| 708 | + |
| 709 | + protected function getContent( $page, $ns ) { |
| 710 | + if ( $ns === NS_MEDIAWIKI ) { |
| 711 | + return wfMsgExt( $page, 'content' ); |
| 712 | + } |
| 713 | + if ( $title = Title::newFromText( $page, $ns ) ) { |
| 714 | + if ( $title->isValidCssJsSubpage() && $revision = Revision::newFromTitle( $title ) ) { |
| 715 | + return $revision->getRawText(); |
| 716 | + } |
| 717 | + } |
| 718 | + return null; |
| 719 | + } |
| 720 | + |
707 | 721 | /* Methods */ |
708 | 722 | |
709 | 723 | public function getScript( ResourceLoaderContext $context ) { |
| 724 | + global $wgCanonicalNamespaceNames; |
| 725 | + |
710 | 726 | $scripts = ''; |
711 | 727 | foreach ( $this->getPages( $context ) as $page => $options ) { |
712 | 728 | if ( $options['type'] === 'script' ) { |
713 | | - $script = wfMsgExt( $page, 'content' ); |
714 | | - $scripts .= "/* MediaWiki:$page */\n" . ( !wfEmptyMsg( $page, $script ) ? $script : '' ) . "\n"; |
| 729 | + if ( $script = $this->getContent( $page, $options['ns'] ) ) { |
| 730 | + $ns = $wgCanonicalNamespaceNames[$options['ns']]; |
| 731 | + $scripts .= "/*$ns:$page */\n$script\n"; |
| 732 | + } |
715 | 733 | } |
716 | 734 | } |
717 | 735 | return $scripts; |
718 | 736 | } |
719 | 737 | |
720 | 738 | public function getStyles( ResourceLoaderContext $context ) { |
| 739 | + global $wgCanonicalNamespaceNames; |
| 740 | + |
721 | 741 | $styles = array(); |
722 | 742 | foreach ( $this->getPages( $context ) as $page => $options ) { |
723 | 743 | if ( $options['type'] === 'style' ) { |
724 | 744 | $media = isset( $options['media'] ) ? $options['media'] : 'all'; |
725 | | - $style = wfMsgExt( $page, 'content' ); |
726 | | - if ( !isset( $styles[$media] ) ) { |
727 | | - $styles[$media] = ''; |
| 745 | + if ( $style = $this->getContent( $page, $options['ns'] ) ) { |
| 746 | + if ( !isset( $styles[$media] ) ) { |
| 747 | + $styles[$media] = ''; |
| 748 | + } |
| 749 | + $ns = $wgCanonicalNamespaceNames[$options['ns']]; |
| 750 | + $styles[$media] .= "/* $ns:$page */\n$style\n"; |
728 | 751 | } |
729 | | - $styles[$media] .= "/* MediaWiki:$page */\n" . ( !wfEmptyMsg( $page, $style ) ? $style : '' ) . "\n"; |
730 | 752 | } |
731 | 753 | } |
732 | 754 | return $styles; |
— | — | @@ -738,7 +760,7 @@ |
739 | 761 | } |
740 | 762 | $titles = array(); |
741 | 763 | foreach ( $this->getPages( $context ) as $page => $options ) { |
742 | | - $titles[] = Title::makeTitle( NS_MEDIAWIKI, $page ); |
| 764 | + $titles[] = Title::makeTitle( $options['ns'], $page ); |
743 | 765 | } |
744 | 766 | // Do batch existence check |
745 | 767 | // TODO: This would work better if page_touched were loaded by this as well |
— | — | @@ -765,14 +787,14 @@ |
766 | 788 | global $wgHandheldStyle; |
767 | 789 | |
768 | 790 | $pages = array( |
769 | | - 'Common.js' => array( 'type' => 'script' ), |
770 | | - 'Common.css' => array( 'type' => 'style' ), |
771 | | - ucfirst( $context->getSkin() ) . '.js' => array( 'type' => 'script' ), |
772 | | - ucfirst( $context->getSkin() ) . '.css' => array( 'type' => 'style' ), |
773 | | - 'Print.css' => array( 'type' => 'style', 'media' => 'print' ), |
| 791 | + 'Common.js' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'script' ), |
| 792 | + 'Common.css' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'style' ), |
| 793 | + ucfirst( $context->getSkin() ) . '.js' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'script' ), |
| 794 | + ucfirst( $context->getSkin() ) . '.css' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'style' ), |
| 795 | + 'Print.css' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'style', 'media' => 'print' ), |
774 | 796 | ); |
775 | 797 | if ( $wgHandheldStyle ) { |
776 | | - $pages['Handheld.css'] = array( 'type' => 'style', 'media' => 'handheld' ); |
| 798 | + $pages['Handheld.css'] = array( 'ns' => NS_MEDIAWIKI, 'type' => 'style', 'media' => 'handheld' ); |
777 | 799 | } |
778 | 800 | return $pages; |
779 | 801 | } |
— | — | @@ -789,11 +811,12 @@ |
790 | 812 | global $wgAllowUserCss; |
791 | 813 | |
792 | 814 | if ( $context->getUser() && $wgAllowUserCss ) { |
793 | | - $user = User::newFromName( $context->getUser() ); |
794 | | - $userPage = $user->getUserPage()->getPrefixedText(); |
| 815 | + $username = $context->getUser(); |
795 | 816 | return array( |
796 | | - "$userPage/common.css" => array( 'type' => 'style' ), |
797 | | - "$userPage/" . $context->getSkin() . '.css' => array( 'type' => 'style' ), |
| 817 | + "$username/common.js" => array( 'ns' => NS_USER, 'type' => 'script' ), |
| 818 | + "$username/" . $context->getSkin() . '.js' => array( 'ns' => NS_USER, 'type' => 'script' ), |
| 819 | + "$username/common.css" => array( 'ns' => NS_USER, 'type' => 'style' ), |
| 820 | + "$username/" . $context->getSkin() . '.css' => array( 'ns' => NS_USER, 'type' => 'style' ), |
798 | 821 | ); |
799 | 822 | } |
800 | 823 | return array(); |
— | — | @@ -816,8 +839,12 @@ |
817 | 840 | if ( isset( $this->modifiedTime[$hash] ) ) { |
818 | 841 | return $this->modifiedTime[$hash]; |
819 | 842 | } |
820 | | - $user = User::newFromName( $context->getUser() ); |
821 | | - return $this->modifiedTime[$hash] = $user->getTouched(); |
| 843 | + if ( $context->getUser() ) { |
| 844 | + $user = User::newFromName( $context->getUser() ); |
| 845 | + return $this->modifiedTime[$hash] = $user->getTouched(); |
| 846 | + } else { |
| 847 | + return 0; |
| 848 | + } |
822 | 849 | } |
823 | 850 | |
824 | 851 | public function getStyles( ResourceLoaderContext $context ) { |