Let's just kill $wgUpdates since OpenID was converted in r72798.
[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 $modules;
30 protected $language;
31 protected $direction;
32 protected $skin;
33 protected $user;
34 protected $debug;
35 protected $only;
36 protected $hash;
37
38 /* Methods */
39
40 public function __construct( WebRequest $request ) {
41 global $wgLang, $wgDefaultSkin;
42
43 $this->request = $request;
44 // Interperet request
45 $this->modules = explode( '|', $request->getVal( 'modules' ) );
46 $this->language = $request->getVal( 'lang' );
47 $this->direction = $request->getVal( 'dir' );
48 $this->skin = $request->getVal( 'skin' );
49 $this->user = $request->getVal( 'user' );
50 $this->debug = $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true';
51 $this->only = $request->getVal( 'only' );
52
53 // Fallback on system defaults
54 if ( !$this->language ) {
55 $this->language = $wgLang->getCode();
56 }
57
58 if ( !$this->direction ) {
59 $this->direction = Language::factory( $this->language )->getDir();
60 }
61
62 if ( !$this->skin ) {
63 $this->skin = $wgDefaultSkin;
64 }
65 }
66
67 public function getRequest() {
68 return $this->request;
69 }
70
71 public function getModules() {
72 return $this->modules;
73 }
74
75 public function getLanguage() {
76 return $this->language;
77 }
78
79 public function getDirection() {
80 return $this->direction;
81 }
82
83 public function getSkin() {
84 return $this->skin;
85 }
86
87 public function getUser() {
88 return $this->user;
89 }
90
91 public function getDebug() {
92 return $this->debug;
93 }
94
95 public function getOnly() {
96 return $this->only;
97 }
98
99 public function shouldIncludeScripts() {
100 return is_null( $this->only ) || $this->only === 'scripts';
101 }
102
103 public function shouldIncludeStyles() {
104 return is_null( $this->only ) || $this->only === 'styles';
105 }
106
107 public function shouldIncludeMessages() {
108 return is_null( $this->only ) || $this->only === 'messages';
109 }
110
111 public function getHash() {
112 return isset( $this->hash ) ?
113 $this->hash : $this->hash = implode( '|', array(
114 $this->language, $this->direction, $this->skin, $this->user, $this->debug, $this->only
115 ) );
116 }
117 }