Refactor diffs
[mediawiki.git] / includes / resourceloader / ResourceLoaderUserModule.php
blob7a04e473f1d5dbcda73857ae80e846f2a7c4116e
1 <?php
2 /**
3 * Resource loader module for user customizations.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Trevor Parscal
22 * @author Roan Kattouw
25 /**
26 * Module for user customizations
28 class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
30 /* Protected Methods */
31 protected $origin = self::ORIGIN_USER_INDIVIDUAL;
33 /**
34 * @param $context ResourceLoaderContext
35 * @return array
37 protected function getPages( ResourceLoaderContext $context ) {
38 global $wgAllowUserJs, $wgAllowUserCss;
39 $username = $context->getUser();
41 if ( $username === null ) {
42 return array();
44 if ( !$wgAllowUserJs && !$wgAllowUserCss ) {
45 return array();
48 // Get the normalized title of the user's user page
49 $userpageTitle = Title::makeTitleSafe( NS_USER, $username );
51 if ( !$userpageTitle instanceof Title ) {
52 return array();
55 $userpage = $userpageTitle->getPrefixedDBkey(); // Needed so $excludepages works
57 $pages = array();
58 if ( $wgAllowUserJs ) {
59 $pages["$userpage/common.js"] = array( 'type' => 'script' );
60 $pages["$userpage/" . $context->getSkin() . '.js'] = array( 'type' => 'script' );
62 if ( $wgAllowUserCss ) {
63 $pages["$userpage/common.css"] = array( 'type' => 'style' );
64 $pages["$userpage/" . $context->getSkin() . '.css'] = array( 'type' => 'style' );
67 // Hack for bug 26283: if we're on a preview page for a CSS/JS page,
68 // we need to exclude that page from this module. In that case, the excludepage
69 // parameter will be set to the name of the page we need to exclude.
70 $excludepage = $context->getRequest()->getVal( 'excludepage' );
71 if ( isset( $pages[$excludepage] ) ) {
72 // This works because $excludepage is generated with getPrefixedDBkey(),
73 // just like the keys in $pages[] above
74 unset( $pages[$excludepage] );
76 return $pages;
79 /* Methods */
81 /**
82 * @return string
84 public function getGroup() {
85 return 'user';