MediaWiki  REL1_22
ResourceLoaderUserModule.php
Go to the documentation of this file.
00001 <?php
00028 class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
00029 
00030     /* Protected Methods */
00031     protected $origin = self::ORIGIN_USER_INDIVIDUAL;
00032 
00037     protected function getPages( ResourceLoaderContext $context ) {
00038         global $wgAllowUserJs, $wgAllowUserCss;
00039         $username = $context->getUser();
00040 
00041         if ( $username === null ) {
00042             return array();
00043         }
00044         if ( !$wgAllowUserJs && !$wgAllowUserCss ) {
00045             return array();
00046         }
00047 
00048         // Get the normalized title of the user's user page
00049         $userpageTitle = Title::makeTitleSafe( NS_USER, $username );
00050 
00051         if ( !$userpageTitle instanceof Title ) {
00052             return array();
00053         }
00054 
00055         $userpage = $userpageTitle->getPrefixedDBkey(); // Needed so $excludepages works
00056 
00057         $pages = array();
00058         if ( $wgAllowUserJs ) {
00059             $pages["$userpage/common.js"] = array( 'type' => 'script' );
00060             $pages["$userpage/" . $context->getSkin() . '.js'] = array( 'type' => 'script' );
00061         }
00062         if ( $wgAllowUserCss ) {
00063             $pages["$userpage/common.css"] = array( 'type' => 'style' );
00064             $pages["$userpage/" . $context->getSkin() . '.css'] = array( 'type' => 'style' );
00065         }
00066 
00067         // Hack for bug 26283: if we're on a preview page for a CSS/JS page,
00068         // we need to exclude that page from this module. In that case, the excludepage
00069         // parameter will be set to the name of the page we need to exclude.
00070         $excludepage = $context->getRequest()->getVal( 'excludepage' );
00071         if ( isset( $pages[$excludepage] ) ) {
00072             // This works because $excludepage is generated with getPrefixedDBkey(),
00073             // just like the keys in $pages[] above
00074             unset( $pages[$excludepage] );
00075         }
00076         return $pages;
00077     }
00078 
00079     /* Methods */
00080 
00084     public function getGroup() {
00085         return 'user';
00086     }
00087 }