1 | <?php |
||
42 | class SetupAfterCache { |
||
43 | |||
44 | protected $bootstrapManager = null; |
||
45 | protected $configuration = array(); |
||
46 | protected $request; |
||
47 | |||
48 | /** |
||
49 | * @since 1.0 |
||
50 | * |
||
51 | * @param BootstrapManager $bootstrapManager |
||
52 | * @param array $configuration |
||
53 | * @param \WebRequest $request |
||
54 | */ |
||
55 | 1 | public function __construct( BootstrapManager $bootstrapManager, array &$configuration, \WebRequest $request ) { |
|
56 | 1 | $this->bootstrapManager = $bootstrapManager; |
|
57 | 1 | $this->configuration = &$configuration; |
|
58 | 1 | $this->request = $request; |
|
59 | 1 | } |
|
60 | |||
61 | /** |
||
62 | * @since 1.0 |
||
63 | * |
||
64 | * @return self |
||
65 | */ |
||
66 | 13 | public function process() { |
|
67 | |||
68 | 13 | $this->setInstallPaths(); |
|
69 | 13 | $this->addLateSettings(); |
|
70 | 13 | $this->registerCommonBootstrapModules(); |
|
71 | 13 | $this->registerExternalLessModules(); |
|
72 | 12 | $this->registerExternalLessVariables(); |
|
73 | |||
74 | 12 | return $this; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * @since 1.0 |
||
79 | * |
||
80 | * @param array $configuration |
||
81 | */ |
||
82 | 1 | public function adjustConfiguration( array &$configuration ) { |
|
88 | |||
89 | /** |
||
90 | * Set local and remote base path of the Chameleon skin |
||
91 | */ |
||
92 | 13 | protected function setInstallPaths() { |
|
93 | |||
94 | 13 | $this->configuration[ 'chameleonLocalPath' ] = $this->configuration['wgStyleDirectory'] . '/chameleon'; |
|
95 | 13 | $this->configuration[ 'chameleonRemotePath' ] = $this->configuration['wgStylePath'] . '/chameleon'; |
|
96 | 13 | } |
|
97 | |||
98 | 13 | protected function addLateSettings() { |
|
99 | |||
100 | 13 | $this->addChameleonToVisualEditorSupportedSkins(); |
|
101 | 13 | $this->addResourceModules(); |
|
102 | 13 | $this->setLayoutFile(); |
|
103 | 13 | } |
|
104 | |||
105 | 13 | protected function registerCommonBootstrapModules() { |
|
106 | |||
107 | 13 | $this->bootstrapManager->addAllBootstrapModules(); |
|
108 | |||
109 | 13 | if ( file_exists( $this->configuration[ 'wgStyleDirectory' ] . '/common/shared.css' ) ) { // MW < 1.24 |
|
110 | $this->bootstrapManager->addExternalModule( |
||
111 | $this->configuration[ 'wgStyleDirectory' ] . '/common/shared.css', |
||
112 | $this->configuration[ 'wgStylePath' ] . '/common/' |
||
113 | ); |
||
114 | } else { |
||
115 | 13 | if ( file_exists( $this->configuration[ 'IP' ] . '/resources/src/mediawiki.legacy/shared.css' ) ) { // MW >= 1.24 |
|
116 | 6 | $this->bootstrapManager->addExternalModule( |
|
117 | 6 | $this->configuration[ 'IP' ] . '/resources/src/mediawiki.legacy/shared.css', |
|
118 | 6 | $this->configuration[ 'wgScriptPath' ] . '/resources/src/mediawiki.legacy/' |
|
119 | 6 | ); |
|
120 | 6 | } |
|
121 | } |
||
122 | |||
123 | 13 | $this->bootstrapManager->addExternalModule( |
|
124 | 13 | $this->configuration[ 'chameleonLocalPath' ] . '/resources/styles/core.less', |
|
125 | 13 | $this->configuration[ 'chameleonRemotePath' ] . '/resources/styles/' |
|
126 | 13 | ); |
|
127 | 13 | } |
|
128 | |||
129 | 13 | protected function registerExternalLessModules() { |
|
130 | |||
131 | 13 | if ( $this->hasConfigurationOfTypeArray( 'egChameleonExternalStyleModules' ) ) { |
|
132 | |||
133 | 2 | foreach ( $this->configuration[ 'egChameleonExternalStyleModules' ] as $localFile => $remotePath ) { |
|
134 | |||
135 | 2 | list( $localFile, $remotePath ) = $this->matchAssociativeElement( $localFile, $remotePath ); |
|
136 | |||
137 | 2 | $this->bootstrapManager->addExternalModule( |
|
138 | 2 | $this->isReadableFile( $localFile ), |
|
139 | $remotePath |
||
140 | 1 | ); |
|
141 | 1 | } |
|
142 | 1 | } |
|
143 | 12 | } |
|
144 | |||
145 | 12 | protected function registerExternalLessVariables() { |
|
146 | |||
147 | 12 | if ( $this->hasConfigurationOfTypeArray( 'egChameleonExternalLessVariables' ) ) { |
|
148 | |||
149 | 1 | foreach ( $this->configuration[ 'egChameleonExternalLessVariables' ] as $key => $value ) { |
|
150 | 1 | $this->bootstrapManager->setLessVariable( $key, $value ); |
|
151 | 1 | } |
|
152 | 1 | } |
|
153 | 12 | } |
|
154 | |||
155 | /** |
||
156 | * @param $id |
||
157 | * @return bool |
||
158 | */ |
||
159 | 13 | private function hasConfiguration( $id ) { |
|
162 | |||
163 | /** |
||
164 | * @param string $id |
||
165 | * @return bool |
||
166 | */ |
||
167 | 13 | private function hasConfigurationOfTypeArray( $id ) { |
|
170 | |||
171 | /** |
||
172 | * @param $localFile |
||
173 | * @param $remotePath |
||
174 | * @return array |
||
175 | */ |
||
176 | 2 | private function matchAssociativeElement( $localFile, $remotePath ) { |
|
177 | |||
178 | 2 | if ( is_integer( $localFile ) ) { |
|
179 | 2 | return array( $remotePath, '' ); |
|
180 | } |
||
181 | |||
182 | 1 | return array( $localFile, $remotePath ); |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * @param string $file |
||
187 | * @return string |
||
188 | */ |
||
189 | 2 | private function isReadableFile( $file ) { |
|
197 | |||
198 | 13 | protected function addChameleonToVisualEditorSupportedSkins() { |
|
199 | |||
200 | // if Visual Editor is installed and there is a setting to enable or disable it |
||
201 | 13 | if ( $this->hasConfiguration( 'wgVisualEditorSupportedSkins' ) && $this->hasConfiguration( 'egChameleonEnableVisualEditor' ) ) { |
|
202 | |||
203 | // if VE should be enabled |
||
204 | 3 | if ( $this->configuration[ 'egChameleonEnableVisualEditor' ] === true ) { |
|
205 | |||
220 | |||
221 | 13 | protected function addResourceModules() { |
|
229 | |||
230 | 13 | protected function setLayoutFile() { |
|
241 | |||
242 | } |
||
243 |