Major refactoring of site and user CSS, creating ResourceLoaderUserModule and Resourc...
[lhc/web/wiklou.git] / includes / ResourceLoaderContext.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @author Trevor Parscal
19 * @author Roan Kattouw
20 */
21
22 /**
23 * Object passed around to modules which contains information about the state of a specific loader request
24 */
25 class ResourceLoaderContext {
26 /* Protected Members */
27
28 protected $request;
29 protected $server;
30 protected $modules;
31 protected $language;
32 protected $direction;
33 protected $skin;
34 protected $user;
35 protected $debug;
36 protected $only;
37 protected $hash;
38
39 /* Methods */
40
41 public function __construct( WebRequest $request ) {
42 global $wgLang, $wgDefaultSkin;
43
44 $this->request = $request;
45 // Interperet request
46 $this->modules = explode( '|', $request->getVal( 'modules' ) );
47 $this->language = $request->getVal( 'lang' );
48 $this->direction = $request->getVal( 'dir' );
49 $this->skin = $request->getVal( 'skin' );
50 $this->user = $request->getVal( 'user' );
51 $this->debug = $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true';
52 $this->only = $request->getVal( 'only' );
53
54 // Fallback on system defaults
55 if ( !$this->language ) {
56 $this->language = $wgLang->getCode();
57 }
58
59 if ( !$this->direction ) {
60 $this->direction = Language::factory( $this->language )->getDir();
61 }
62
63 if ( !$this->skin ) {
64 $this->skin = $wgDefaultSkin;
65 }
66 }
67
68 public function getRequest() {
69 return $this->request;
70 }
71
72 public function getModules() {
73 return $this->modules;
74 }
75
76 public function getLanguage() {
77 return $this->language;
78 }
79
80 public function getDirection() {
81 return $this->direction;
82 }
83
84 public function getSkin() {
85 return $this->skin;
86 }
87
88 public function getUser() {
89 return $this->skin;
90 }
91
92 public function getDebug() {
93 return $this->debug;
94 }
95
96 public function getOnly() {
97 return $this->only;
98 }
99
100 public function shouldIncludeScripts() {
101 return is_null( $this->only ) || $this->only === 'scripts';
102 }
103
104 public function shouldIncludeStyles() {
105 return is_null( $this->only ) || $this->only === 'styles';
106 }
107
108 public function shouldIncludeMessages() {
109 return is_null( $this->only ) || $this->only === 'messages';
110 }
111
112 public function getHash() {
113 return isset( $this->hash ) ?
114 $this->hash : $this->hash =
115 implode( '|', array( $this->language, $this->skin, $this->user, $this->debug, $this->only ) );
116 }
117 }