Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderUserModule.php
1 <?php
2 /**
3 * ResourceLoader 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 $origin = self::ORIGIN_USER_INDIVIDUAL;
31
32 /**
33 * Get list of pages used by this module
34 *
35 * @param ResourceLoaderContext $context
36 * @return array List of pages
37 */
38 protected function getPages( ResourceLoaderContext $context ) {
39 $allowUserJs = $this->getConfig()->get( 'AllowUserJs' );
40 $allowUserCss = $this->getConfig()->get( 'AllowUserCss' );
41 if ( !$allowUserJs && !$allowUserCss ) {
42 return [];
43 }
44
45 $user = $context->getUserObj();
46 if ( !$user || $user->isAnon() ) {
47 return [];
48 }
49
50 // Needed so $excludepages works
51 $userPage = $user->getUserPage()->getPrefixedDBkey();
52
53 $pages = [];
54 if ( $allowUserJs ) {
55 $pages["$userPage/common.js"] = [ 'type' => 'script' ];
56 $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
57 }
58 if ( $allowUserCss ) {
59 $pages["$userPage/common.css"] = [ 'type' => 'style' ];
60 $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
61 }
62
63 // Hack for bug 26283: if we're on a preview page for a CSS/JS page,
64 // we need to exclude that page from this module. In that case, the excludepage
65 // parameter will be set to the name of the page we need to exclude.
66 $excludepage = $context->getRequest()->getVal( 'excludepage' );
67 if ( isset( $pages[$excludepage] ) ) {
68 // This works because $excludepage is generated with getPrefixedDBkey(),
69 // just like the keys in $pages[] above
70 unset( $pages[$excludepage] );
71 }
72 return $pages;
73 }
74
75 /**
76 * Get group name
77 *
78 * @return string
79 */
80 public function getGroup() {
81 return 'user';
82 }
83 }