177302c5b7e2feb6fdd176d7bdba8abad7ad517b
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderUserModule.php
1 <?php
2 /**
3 * Resource loader module for user customizations.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Trevor Parscal
22 * @author Roan Kattouw
23 */
24
25 /**
26 * Module for user customizations
27 */
28 class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
29
30 /* Protected Methods */
31 protected $origin = self::ORIGIN_USER_INDIVIDUAL;
32
33 /**
34 * @param $context ResourceLoaderContext
35 * @return array
36 */
37 protected function getPages( ResourceLoaderContext $context ) {
38 $username = $context->getUser();
39
40 if ( $username === null ) {
41 return array();
42 }
43
44 // Get the normalized title of the user's user page
45 $userpageTitle = Title::makeTitleSafe( NS_USER, $username );
46
47 if ( !$userpageTitle instanceof Title ) {
48 return array();
49 }
50
51 $userpage = $userpageTitle->getPrefixedDBkey(); // Needed so $excludepages works
52
53 $pages = array(
54 "$userpage/common.js" => array( 'type' => 'script' ),
55 "$userpage/" . $context->getSkin() . '.js' =>
56 array( 'type' => 'script' ),
57 "$userpage/common.css" => array( 'type' => 'style' ),
58 "$userpage/" . $context->getSkin() . '.css' =>
59 array( 'type' => 'style' ),
60 );
61
62 // Hack for bug 26283: if we're on a preview page for a CSS/JS page,
63 // we need to exclude that page from this module. In that case, the excludepage
64 // parameter will be set to the name of the page we need to exclude.
65 $excludepage = $context->getRequest()->getVal( 'excludepage' );
66 if ( isset( $pages[$excludepage] ) ) {
67 // This works because $excludepage is generated with getPrefixedDBkey(),
68 // just like the keys in $pages[] above
69 unset( $pages[$excludepage] );
70 }
71 return $pages;
72 }
73
74 /* Methods */
75
76 /**
77 * @return string
78 */
79 public function getGroup() {
80 return 'user';
81 }
82 }