2010-10-19 18:25:42 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2015-10-28 03:24:40 +00:00
|
|
|
* ResourceLoader module for user customizations.
|
2012-04-30 07:16:10 +00:00
|
|
|
*
|
2010-10-19 18:25:42 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Module for user customizations
|
|
|
|
|
*/
|
|
|
|
|
class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
|
|
|
|
|
|
2011-02-04 16:39:17 +00:00
|
|
|
protected $origin = self::ORIGIN_USER_INDIVIDUAL;
|
2010-10-19 18:25:42 +00:00
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2014-10-21 00:43:26 +00:00
|
|
|
* Get list of pages used by this module
|
|
|
|
|
*
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2014-10-21 00:43:26 +00:00
|
|
|
* @return array List of pages
|
2011-05-21 17:45:20 +00:00
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
protected function getPages( ResourceLoaderContext $context ) {
|
2014-08-07 10:25:56 +00:00
|
|
|
$allowUserJs = $this->getConfig()->get( 'AllowUserJs' );
|
|
|
|
|
$allowUserCss = $this->getConfig()->get( 'AllowUserCss' );
|
|
|
|
|
if ( !$allowUserJs && !$allowUserCss ) {
|
2013-04-03 20:50:08 +00:00
|
|
|
return array();
|
|
|
|
|
}
|
2012-04-09 08:30:50 +00:00
|
|
|
|
2015-03-01 15:25:39 +00:00
|
|
|
$user = $context->getUserObj();
|
|
|
|
|
if ( !$user || $user->isAnon() ) {
|
2012-04-09 08:30:50 +00:00
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-01 15:25:39 +00:00
|
|
|
// Needed so $excludepages works
|
|
|
|
|
$userPage = $user->getUserPage()->getPrefixedDBkey();
|
2012-04-09 08:30:50 +00:00
|
|
|
|
2013-04-03 20:50:08 +00:00
|
|
|
$pages = array();
|
2014-08-07 10:25:56 +00:00
|
|
|
if ( $allowUserJs ) {
|
2015-03-01 15:25:39 +00:00
|
|
|
$pages["$userPage/common.js"] = array( 'type' => 'script' );
|
|
|
|
|
$pages["$userPage/" . $context->getSkin() . '.js'] = array( 'type' => 'script' );
|
2013-04-03 20:50:08 +00:00
|
|
|
}
|
2014-08-07 10:25:56 +00:00
|
|
|
if ( $allowUserCss ) {
|
2015-03-01 15:25:39 +00:00
|
|
|
$pages["$userPage/common.css"] = array( 'type' => 'style' );
|
|
|
|
|
$pages["$userPage/" . $context->getSkin() . '.css'] = array( 'type' => 'style' );
|
2013-04-03 20:50:08 +00:00
|
|
|
}
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2012-04-09 08:30:50 +00:00
|
|
|
// Hack for bug 26283: if we're on a preview page for a CSS/JS page,
|
|
|
|
|
// we need to exclude that page from this module. In that case, the excludepage
|
|
|
|
|
// parameter will be set to the name of the page we need to exclude.
|
|
|
|
|
$excludepage = $context->getRequest()->getVal( 'excludepage' );
|
|
|
|
|
if ( isset( $pages[$excludepage] ) ) {
|
|
|
|
|
// This works because $excludepage is generated with getPrefixedDBkey(),
|
|
|
|
|
// just like the keys in $pages[] above
|
|
|
|
|
unset( $pages[$excludepage] );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2012-04-09 08:30:50 +00:00
|
|
|
return $pages;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2011-05-21 17:45:20 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-10-21 00:43:26 +00:00
|
|
|
* Get group name
|
|
|
|
|
*
|
2011-05-21 17:45:20 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getGroup() {
|
|
|
|
|
return 'user';
|
|
|
|
|
}
|
|
|
|
|
}
|