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