FU: r87041: Oops
[lhc/web/wiklou.git] / skins / Vector.php
1 <?php
2 /**
3 * Vector - Modern version of MonoBook with fresh look and many usability
4 * improvements.
5 *
6 * @todo document
7 * @file
8 * @ingroup Skins
9 */
10
11 if( !defined( 'MEDIAWIKI' ) ) {
12 die( -1 );
13 }
14
15 /**
16 * SkinTemplate class for Vector skin
17 * @ingroup Skins
18 */
19 class SkinVector extends SkinTemplate {
20
21 var $skinname = 'vector', $stylename = 'vector',
22 $template = 'VectorTemplate', $useHeadElement = true;
23
24 /**
25 * Initializes output page and sets up skin-specific parameters
26 * @param $out OutputPage object to initialize
27 */
28 public function initPage( OutputPage $out ) {
29 global $wgLocalStylePath, $wgRequest;
30
31 parent::initPage( $out );
32
33 // Append CSS which includes IE only behavior fixes for hover support -
34 // this is better than including this in a CSS fille since it doesn't
35 // wait for the CSS file to load before fetching the HTC file.
36 $min = $wgRequest->getFuzzyBool( 'debug' ) ? '' : '.min';
37 $out->addHeadItem( 'csshover',
38 '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
39 htmlspecialchars( $wgLocalStylePath ) .
40 "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->"
41 );
42
43 $out->addModuleScripts( 'skins.vector' );
44 }
45
46 /**
47 * Load skin and user CSS files in the correct order
48 * fixes bug 22916
49 * @param $out OutputPage object
50 */
51 function setupSkinUserCss( OutputPage $out ){
52 parent::setupSkinUserCss( $out );
53 $out->addModuleStyles( 'skins.vector' );
54 }
55 }
56
57 /**
58 * QuickTemplate class for Vector skin
59 * @ingroup Skins
60 */
61 class VectorTemplate extends BaseTemplate {
62
63 /* Members */
64
65 /**
66 * @var Skin Cached skin object
67 */
68 var $skin;
69
70 /* Functions */
71
72 /**
73 * Outputs the entire contents of the (X)HTML page
74 */
75 public function execute() {
76 global $wgLang, $wgVectorUseIconWatch;
77
78 $this->skin = $this->data['skin'];
79
80 // Build additional attributes for navigation urls
81 //$nav = $this->skin->buildNavigationUrls();
82 $nav = $this->data['content_navigation'];
83
84 if ( $wgVectorUseIconWatch ) {
85 $mode = $this->skin->getTitle()->userIsWatching() ? 'unwatch' : 'watch';
86 if ( isset($nav['actions'][$mode]) ) {
87 $nav['views'][$mode] = $nav['actions'][$mode];
88 $nav['views'][$mode]['class'] = rtrim('icon ' . $nav['views'][$mode]['class'], ' ');
89 $nav['views'][$mode]['primary'] = true;
90 unset($nav['actions'][$mode]);
91 }
92 }
93
94 $xmlID = '';
95 foreach ( $nav as $section => $links ) {
96 foreach ( $links as $key => $link ) {
97 if ( $section == "views" && !(isset($link["primary"]) && $link["primary"]) ) {
98 $link['class'] = rtrim('collapsible ' . $link['class'], ' ');
99 }
100
101 $xmlID = isset($link["id"]) ? $link["id"] : 'ca-' . $xmlID;
102 $nav[$section][$key]['attributes'] =
103 ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
104 if ( $link['class'] ) {
105 $nav[$section][$key]['attributes'] .=
106 ' class="' . htmlspecialchars( $link['class'] ) . '"';
107 unset( $nav[$section][$key]['class'] );
108 }
109 if ( isset($link['tooltiponly']) && $link['tooltiponly'] ) {
110 $nav[$section][$key]['key'] =
111 Linker::tooltip( $xmlID );
112 } else {
113 $nav[$section][$key]['key'] =
114 Linker::tooltipAndAccesskey( $xmlID );
115 }
116 }
117 }
118 $this->data['namespace_urls'] = $nav['namespaces'];
119 $this->data['view_urls'] = $nav['views'];
120 $this->data['action_urls'] = $nav['actions'];
121 $this->data['variant_urls'] = $nav['variants'];
122
123 // Reverse horizontally rendered navigation elements
124 if ( $wgLang->isRTL() ) {
125 $this->data['view_urls'] =
126 array_reverse( $this->data['view_urls'] );
127 $this->data['namespace_urls'] =
128 array_reverse( $this->data['namespace_urls'] );
129 $this->data['personal_urls'] =
130 array_reverse( $this->data['personal_urls'] );
131 }
132 // Output HTML Page
133 $this->html( 'headelement' );
134 ?>
135 <div id="mw-page-base" class="noprint"></div>
136 <div id="mw-head-base" class="noprint"></div>
137 <!-- content -->
138 <div id="content"<?php $this->html('specialpageattributes') ?>>
139 <a id="top"></a>
140 <div id="mw-js-message" style="display:none;"<?php $this->html('userlangattributes') ?>></div>
141 <?php if ( $this->data['sitenotice'] ): ?>
142 <!-- sitenotice -->
143 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
144 <!-- /sitenotice -->
145 <?php endif; ?>
146 <!-- firstHeading -->
147 <h1 id="firstHeading" class="firstHeading"><?php $this->html( 'title' ) ?></h1>
148 <!-- /firstHeading -->
149 <!-- bodyContent -->
150 <div id="bodyContent">
151 <?php if ( $this->data['isarticle'] ): ?>
152 <!-- tagline -->
153 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
154 <!-- /tagline -->
155 <?php endif; ?>
156 <!-- subtitle -->
157 <div id="contentSub"<?php $this->html('userlangattributes') ?>><?php $this->html( 'subtitle' ) ?></div>
158 <!-- /subtitle -->
159 <?php if ( $this->data['undelete'] ): ?>
160 <!-- undelete -->
161 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
162 <!-- /undelete -->
163 <?php endif; ?>
164 <?php if($this->data['newtalk'] ): ?>
165 <!-- newtalk -->
166 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
167 <!-- /newtalk -->
168 <?php endif; ?>
169 <?php if ( $this->data['showjumplinks'] ): ?>
170 <!-- jumpto -->
171 <div id="jump-to-nav">
172 <?php $this->msg( 'jumpto' ) ?> <a href="#mw-head"><?php $this->msg( 'jumptonavigation' ) ?></a>,
173 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
174 </div>
175 <!-- /jumpto -->
176 <?php endif; ?>
177 <!-- bodytext -->
178 <?php $this->html( 'bodytext' ) ?>
179 <!-- /bodytext -->
180 <?php if ( $this->data['catlinks'] ): ?>
181 <!-- catlinks -->
182 <?php $this->html( 'catlinks' ); ?>
183 <!-- /catlinks -->
184 <?php endif; ?>
185 <?php if ( $this->data['dataAfterContent'] ): ?>
186 <!-- dataAfterContent -->
187 <?php $this->html( 'dataAfterContent' ); ?>
188 <!-- /dataAfterContent -->
189 <?php endif; ?>
190 <div class="visualClear"></div>
191 </div>
192 <!-- /bodyContent -->
193 </div>
194 <!-- /content -->
195 <!-- header -->
196 <div id="mw-head" class="noprint">
197 <?php $this->renderNavigation( 'PERSONAL' ); ?>
198 <div id="left-navigation">
199 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
200 </div>
201 <div id="right-navigation">
202 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
203 </div>
204 </div>
205 <!-- /header -->
206 <!-- panel -->
207 <div id="mw-panel" class="noprint">
208 <!-- logo -->
209 <div id="p-logo"><a style="background-image: url(<?php $this->text( 'logopath' ) ?>);" href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>" <?php echo Linker::tooltipAndAccesskey( 'p-logo' ) ?>></a></div>
210 <!-- /logo -->
211 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
212 </div>
213 <!-- /panel -->
214 <!-- footer -->
215 <div id="footer"<?php $this->html('userlangattributes') ?>>
216 <?php foreach( $this->getFooterLinks() as $category => $links ): ?>
217 <ul id="footer-<?php echo $category ?>">
218 <?php foreach( $links as $link ): ?>
219 <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
220 <?php endforeach; ?>
221 </ul>
222 <?php endforeach; ?>
223 <?php $footericons = $this->getFooterIcons("icononly");
224 if ( count( $footericons ) > 0 ): ?>
225 <ul id="footer-icons" class="noprint">
226 <?php foreach ( $footericons as $blockName => $footerIcons ): ?>
227 <li id="footer-<?php echo htmlspecialchars($blockName); ?>ico">
228 <?php foreach ( $footerIcons as $icon ): ?>
229 <?php echo $this->skin->makeFooterIcon( $icon ); ?>
230
231 <?php endforeach; ?>
232 </li>
233 <?php endforeach; ?>
234 </ul>
235 <?php endif; ?>
236 <div style="clear:both"></div>
237 </div>
238 <!-- /footer -->
239 <!-- fixalpha -->
240 <script type="<?php $this->text('jsmimetype') ?>"> if ( window.isMSIE55 ) fixalpha(); </script>
241 <!-- /fixalpha -->
242 <?php $this->printTrail(); ?>
243
244 </body>
245 </html>
246 <?php
247 }
248
249 /**
250 * Render a series of portals
251 */
252 private function renderPortals( $portals ) {
253 // Force the rendering of the following portals
254 if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;
255 if ( !isset( $portals['TOOLBOX'] ) ) $portals['TOOLBOX'] = true;
256 if ( !isset( $portals['LANGUAGES'] ) ) $portals['LANGUAGES'] = true;
257 // Render portals
258 foreach ( $portals as $name => $content ) {
259 echo "\n<!-- {$name} -->\n";
260 switch( $name ) {
261 case 'SEARCH':
262 break;
263 case 'TOOLBOX':
264 $this->renderPortal( "tb", $this->getToolbox(), "toolbox", "SkinTemplateToolboxEnd" );
265 break;
266 case 'LANGUAGES':
267 if ( $this->data['language_urls'] ) {
268 $this->renderPortal("lang", $this->data['language_urls'], "otherlanguages");
269 }
270 break;
271 default:
272 $this->renderPortal($name, $content);
273 break;
274 }
275 echo "\n<!-- /{$name} -->\n";
276 }
277 }
278
279 private function renderPortal($name, $content, $msg=null, $hook=null) {
280 if ( !isset($msg) ) {
281 $msg = $name;
282 }
283 ?>
284 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?>>
285 <h5<?php $this->html('userlangattributes') ?>><?php $out = wfMsg( $msg ); if ( wfEmptyMsg( $msg ) ) echo htmlspecialchars( $msg ); else echo htmlspecialchars( $out ); ?></h5>
286 <div class="body">
287 <?php
288 if ( is_array( $content ) ): ?>
289 <ul>
290 <?php
291 foreach( $content as $key => $val ): ?>
292 <?php echo $this->makeListItem($key, $val); ?>
293
294 <?php
295 endforeach;
296 if ( isset($hook) ) {
297 wfRunHooks( $hook, array( &$this ) );
298 }
299 ?>
300 </ul>
301 <?php
302 else: ?>
303 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
304 <?php
305 endif; ?>
306 </div>
307 </div>
308 <?php
309 }
310
311 /**
312 * Render one or more navigations elements by name, automatically reveresed
313 * when UI is in RTL mode
314 */
315 private function renderNavigation( $elements ) {
316 global $wgVectorUseSimpleSearch, $wgVectorShowVariantName, $wgUser;
317
318 // If only one element was given, wrap it in an array, allowing more
319 // flexible arguments
320 if ( !is_array( $elements ) ) {
321 $elements = array( $elements );
322 // If there's a series of elements, reverse them when in RTL mode
323 } else if ( wfUILang()->isRTL() ) {
324 $elements = array_reverse( $elements );
325 }
326 // Render elements
327 foreach ( $elements as $name => $element ) {
328 echo "\n<!-- {$name} -->\n";
329 switch ( $element ) {
330 case 'NAMESPACES':
331 ?>
332 <div id="p-namespaces" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
333 <h5><?php $this->msg('namespaces') ?></h5>
334 <ul<?php $this->html('userlangattributes') ?>>
335 <?php foreach ($this->data['namespace_urls'] as $link ): ?>
336 <li <?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></span></li>
337 <?php endforeach; ?>
338 </ul>
339 </div>
340 <?php
341 break;
342 case 'VARIANTS':
343 ?>
344 <div id="p-variants" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
345 <?php if ( $wgVectorShowVariantName ): ?>
346 <h4>
347 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
348 <?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
349 <?php echo htmlspecialchars( $link['text'] ) ?>
350 <?php endif; ?>
351 <?php endforeach; ?>
352 </h4>
353 <?php endif; ?>
354 <h5><span><?php $this->msg('variants') ?></span><a href="#"></a></h5>
355 <div class="menu">
356 <ul<?php $this->html('userlangattributes') ?>>
357 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
358 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
359 <?php endforeach; ?>
360 </ul>
361 </div>
362 </div>
363 <?php
364 break;
365 case 'VIEWS':
366 ?>
367 <div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
368 <h5><?php $this->msg('views') ?></h5>
369 <ul<?php $this->html('userlangattributes') ?>>
370 <?php foreach ( $this->data['view_urls'] as $link ): ?>
371 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
372 // $link['text'] can be undefined - bug 27764
373 if ( array_key_exists( 'text', $link ) ) {
374 echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
375 }
376 ?></a></span></li>
377 <?php endforeach; ?>
378 </ul>
379 </div>
380 <?php
381 break;
382 case 'ACTIONS':
383 ?>
384 <div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
385 <h5><span><?php $this->msg('actions') ?></span><a href="#"></a></h5>
386 <div class="menu">
387 <ul<?php $this->html('userlangattributes') ?>>
388 <?php foreach ($this->data['action_urls'] as $link ): ?>
389 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
390 <?php endforeach; ?>
391 </ul>
392 </div>
393 </div>
394 <?php
395 break;
396 case 'PERSONAL':
397 ?>
398 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
399 <h5><?php $this->msg('personaltools') ?></h5>
400 <ul<?php $this->html('userlangattributes') ?>>
401 <?php foreach($this->getPersonalTools() as $key => $item) { ?>
402 <?php echo $this->makeListItem($key, $item); ?>
403
404 <?php } ?>
405 </ul>
406 </div>
407 <?php
408 break;
409 case 'SEARCH':
410 ?>
411 <div id="p-search">
412 <h5<?php $this->html('userlangattributes') ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
413 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
414 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
415 <?php if ( $wgVectorUseSimpleSearch && $wgUser->getOption( 'vector-simplesearch' ) ): ?>
416 <div id="simpleSearch">
417 <?php if ( $this->data['rtl'] ): ?>
418 <?php echo $this->makeSearchButton("image", array( "id" => "searchButton", "src" => $this->skin->getSkinStylePath('images/search-rtl.png') )); ?>
419 <?php endif; ?>
420 <?php echo $this->makeSearchInput(array( "id" => "searchInput", "type" => "text" )); ?>
421 <?php if ( !$this->data['rtl'] ): ?>
422 <?php echo $this->makeSearchButton("image", array( "id" => "searchButton", "src" => $this->skin->getSkinStylePath('images/search-ltr.png') )); ?>
423 <?php endif; ?>
424 </div>
425 <?php else: ?>
426 <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
427 <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" )); ?>
428 <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" )); ?>
429 <?php endif; ?>
430 </form>
431 </div>
432 <?php
433
434 break;
435 }
436 echo "\n<!-- /{$name} -->\n";
437 }
438 }
439 }