Finish cross-skin unification of <head>
[lhc/web/wiklou.git] / skins / Vector.php
1 <?php
2 /**
3 * Vector - Branch of MonoBook which has many usability improvements and
4 * somewhat cleaner code.
5 *
6 * @todo document
7 * @file
8 * @ingroup Skins
9 */
10
11 if( !defined( 'MEDIAWIKI' ) )
12 die( -1 );
13
14 /**
15 * SkinTemplate class for Vector skin
16 * @ingroup Skins
17 */
18 class SkinVector extends SkinTemplate {
19
20 /* Functions */
21
22 /**
23 * Initializes output page and sets up skin-specific parameters
24 * @param object $out Output page object to initialize
25 */
26 public function initPage( OutputPage $out ) {
27 parent::initPage( $out );
28 $this->skinname = 'vector';
29 $this->stylename = 'vector';
30 $this->template = 'VectorTemplate';
31 }
32
33 /**
34 * Defines CSS files to be included
35 * @param object $out Output page to add styles to
36 */
37 public function setupSkinUserCss( OutputPage $out ) {
38 global $wgContLang;
39 // Append to the default screen common & print styles...
40 if ( $wgContLang->isRTL() ) {
41 $out->addStyle( 'vector/main-rtl.css', 'screen' );
42 } else {
43 $out->addStyle( 'vector/main-ltr.css', 'screen' );
44 }
45 // Add common styles
46 parent::setupSkinUserCss( $out );
47 }
48
49 }
50
51 /**
52 * QuickTemplate class for Vector skin
53 * @ingroup Skins
54 */
55 class VectorTemplate extends QuickTemplate {
56
57 /* Members */
58
59 /**
60 * @var Cached skin object
61 */
62 var $skin;
63
64 /* Functions */
65
66 /**
67 * Outputs the entire contents of the XHTML page
68 */
69 public function execute() {
70 global $wgRequest, $wgUseTwoButtonsSearchForm, $wgOut;
71
72 $this->skin = $this->data['skin'];
73 $action = $wgRequest->getText( 'action' );
74
75 // Suppress warnings to prevent notices about missing indexes in
76 // $this->data (is this really the best way to handle this?)
77 wfSuppressWarnings();
78
79 // Build additional attributes for navigation urls
80 $nav = $this->skin->buildNavigationUrls();
81 foreach ( $nav as $section => $links ) {
82 foreach ( $links as $key => $link ) {
83 $xmlID = $key;
84 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
85 $xmlID = 'ca-nstab-' . $xmlID;
86 } else if ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
87 $xmlID = 'ca-talk';
88 } else {
89 $xmlID = 'ca-' . $xmlID;
90 }
91 $nav[$section][$key]['attributes'] =
92 ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
93 if ( $nav[$section][$key]['class'] ) {
94 $nav[$section][$key]['attributes'] .=
95 ' class="' . htmlspecialchars( $link['class'] ) . '"';
96 unset( $nav[$section][$key]['class'] );
97 }
98
99 // We don't want to give the watch tab an accesskey if the page is
100 // being edited, because that conflicts with the accesskey on the
101 // watch checkbox. We also don't want to give the edit tab an
102 // accesskey, because that's fairly superfluous and conflicts with
103 // an accesskey (Ctrl-E) often used for editing in Safari.
104 if (
105 in_array( $action, array( 'edit', 'submit' ) ) &&
106 in_array( $key, array( 'edit', 'watch', 'unwatch' ) )
107 ) {
108 $nav[$section][$key]['key'] =
109 $this->skin->tooltip( $xmlID );
110 } else {
111 $nav[$section][$key]['key'] =
112 $this->skin->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 // Build additional attributes for personal_urls
122 foreach ( $this->data['personal_urls'] as $key => $item) {
123 $this->data['personal_urls'][$key]['attributes'] =
124 ' id="' . Sanitizer::escapeId( "pt-$key" ) . '"';
125 if ( $item['active'] ) {
126 $this->data['personal_urls'][$key]['attributes'] .=
127 ' class="active"';
128 }
129 $this->data['personal_urls'][$key]['key'] =
130 $this->skin->tooltipAndAccesskey('pt-'.$key);
131 }
132
133 // Generate additional footer links
134 $footerlinks = array(
135 'info' => array(
136 'lastmod',
137 'viewcount',
138 'numberofwatchingusers',
139 'credits',
140 'copyright',
141 'tagline',
142 ),
143 'places' => array(
144 'privacy',
145 'about',
146 'disclaimer',
147 ),
148 );
149
150 // Build list of valid footer links
151 $validFooterLinks = array();
152 foreach( $footerlinks as $category => $links ) {
153 $validFooterLinks[$category] = array();
154 foreach( $links as $link ) {
155 if( isset( $this->data[$link] ) && $this->data[$link] ) {
156 $validFooterLinks[$category][] = $link;
157 }
158 }
159 }
160
161 // Begin content output
162
163 echo $wgOut->headElement( $this->skin );
164 ?> <body<?php if($this->data['body_ondblclick']): ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php endif; ?> <?php if($this->data['body_onload']): ?> onload="<?php $this->text('body_onload') ?>"<?php endif; ?> class="mediawiki <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
165 <div id="page-base" class="noprint"></div>
166 <div id="head-base" class="noprint"></div>
167 <!-- content -->
168 <div id="content">
169 <a name="top" id="top"></a>
170 <div id="mw-js-message" style="display:none;"></div>
171 <!-- sitenotice -->
172 <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
173 <!-- /sitenotice -->
174 <!-- firstHeading -->
175 <h1 id="firstHeading" class="firstHeading"><?php $this->html('title') ?></h1>
176 <!-- /firstHeading -->
177 <!-- bodyContent -->
178 <div id="bodyContent">
179 <!-- tagline -->
180 <h3 id="siteSub"><?php $this->msg('tagline') ?></h3>
181 <!-- /tagline -->
182 <!-- subtitle -->
183 <div id="contentSub"><?php $this->html('subtitle') ?></div>
184 <!-- /subtitle -->
185 <?php if($this->data['undelete']): ?>
186 <!-- undelete -->
187 <div id="contentSub2"><?php $this->html('undelete') ?></div>
188 <!-- /undelete -->
189 <?php endif; ?>
190 <?php if($this->data['newtalk'] ): ?>
191 <!-- newtalk -->
192 <div class="usermessage"><?php $this->html('newtalk') ?></div>
193 <!-- /newtalk -->
194 <?php endif; ?>
195 <?php if($this->data['showjumplinks']): ?>
196 <!-- jumpto -->
197 <div id="jump-to-nav">
198 <?php $this->msg('jumpto') ?> <a href="#head"><?php $this->msg('jumptonavigation') ?></a>,
199 <a href="#search"><?php $this->msg('jumptosearch') ?></a>
200 </div>
201 <!-- /jumpto -->
202 <?php endif; ?>
203 <!-- bodytext -->
204 <?php $this->html('bodytext') ?>
205 <!-- /bodytext -->
206 <!-- catlinks -->
207 <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
208 <!-- /catlinks -->
209 <!-- dataAfterContent -->
210 <?php if($this->data['dataAfterContent']) { $this->html('dataAfterContent'); } ?>
211 <!-- /dataAfterContent -->
212 <div class="visualClear"></div>
213 </div>
214 <!-- /bodyContent -->
215 </div>
216 <!-- /content -->
217 <!-- header -->
218 <div id="head" class="noprint">
219 <!-- personal -->
220 <?php if ( count( $this->data['personal_urls'] ) > 0 ): ?>
221 <div id="p-personal">
222 <h5><?php $this->msg('personaltools') ?></h5>
223 <ul <?php $this->html('userlangattributes') ?>>
224 <?php foreach($this->data['personal_urls'] as $key => $item): ?>
225 <li <?php echo $item['attributes'] ?>><a href="<?php echo htmlspecialchars($item['href']) ?>"<?php echo $item['key'] ?><?php if(!empty($item['class'])): ?> class="<?php echo htmlspecialchars($item['class']) ?>"<?php endif; ?>><?php echo htmlspecialchars($item['text']) ?></a></li>
226 <?php endforeach; ?>
227 </ul>
228 </div>
229 <?php endif; ?>
230 <!-- /personal -->
231 <div id="left-navigation">
232 <!-- namespaces -->
233 <?php if ( count( $this->data['namespace_urls'] ) > 0 ): ?>
234 <div id="namespaces" class="vectorTabs">
235 <h5><?php $this->msg('namespaces') ?></h5>
236 <ul <?php $this->html('userlangattributes') ?>>
237 <?php foreach ($this->data['namespace_urls'] as $key => $link ): ?>
238 <li <?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><span><?php echo htmlspecialchars( $link['text'] ) ?></span></a></li>
239 <?php endforeach; ?>
240 </ul>
241 </div>
242 <?php endif; ?>
243 <!-- /namespaces -->
244 <!-- variants -->
245 <?php if ( count( $this->data['variant_urls'] ) > 0 ): ?>
246 <div id="variants" class="vectorMenu">
247 <h5><span><?php $this->msg('variants') ?></span><a href="#">&nbsp;</a></h5>
248 <div class="menu">
249 <ul <?php $this->html('userlangattributes') ?>>
250 <?php foreach ($this->data['variant_urls'] as $key => $link ): ?>
251 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
252 <?php endforeach; ?>
253 </ul>
254 </div>
255 </div>
256 <?php endif; ?>
257 <!-- /variants -->
258 </div>
259 <div id="right-navigation">
260 <!-- views -->
261 <?php if ( count( $this->data['view_urls'] ) > 0 ): ?>
262 <div id="views" class="vectorTabs">
263 <h5><?php $this->msg('views') ?></h5>
264 <ul <?php $this->html('userlangattributes') ?>>
265 <?php foreach ($this->data['view_urls'] as $key => $link ): ?>
266 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><span><?php echo htmlspecialchars( $link['text'] ) ?></span></a></li>
267 <?php endforeach; ?>
268 </ul>
269 </div>
270 <?php endif; ?>
271 <!-- /views -->
272 <!-- actions -->
273 <?php if ( count( $this->data['action_urls'] ) > 0 ): ?>
274 <div id="p-cactions" class="vectorMenu">
275 <h5><span><?php $this->msg('actions') ?></span><a href="#">&nbsp;</a></h5>
276 <div class="menu">
277 <ul <?php $this->html('userlangattributes') ?>>
278 <?php foreach ($this->data['action_urls'] as $key => $link ): ?>
279 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
280 <?php endforeach; ?>
281 </ul>
282 </div>
283 </div>
284 <?php endif; ?>
285 <!-- /actions -->
286 <!-- search -->
287 <div id="p-search">
288 <h5 <?php $this->html('userlangattributes') ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
289 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
290 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
291 <input id="searchInput" name="search" type="text" <?php echo $this->skin->tooltipAndAccesskey( 'search' ); ?> <?php if( isset( $this->data['search'] ) ): ?> value="<?php $this->text( 'search' ) ?>"<?php endif; ?> />
292 <input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg( 'searcharticle' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> />
293 <?php if ( $wgUseTwoButtonsSearchForm ): ?>
294 <input type="submit" name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg( 'searchbutton' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> />
295 <?php else: ?>
296 <div><a href="<?php $this->text( 'searchaction' ) ?>" rel="search"><?php $this->msg( 'powersearch-legend' ) ?></a></div>
297 <?php endif; ?>
298 </form>
299 </div>
300 <!-- /search -->
301 </div>
302 </div>
303 <!-- /header -->
304 <!-- panel -->
305 <div id="panel" class="noprint">
306 <!-- sidebar -->
307 <?php
308 $sidebar = $this->data['sidebar'];
309 $sidebar['TOOLBOX'] = ( !isset( $sidebar['TOOLBOX'] ) );
310 $sidebar['LANGUAGES'] = ( !isset( $sidebar['LANGUAGES'] ) );
311 foreach ( $sidebar as $name => $content ) {
312 switch( $name ) {
313 case 'SEARCH':
314 break;
315 case 'TOOLBOX':
316 $this->toolBox();
317 break;
318 case 'LANGUAGES':
319 $this->languageBox();
320 break;
321 default:
322 $this->customBox( $name, $content );
323 break;
324 }
325 }
326 ?>
327 <!-- /sidebar -->
328 </div>
329 <!-- /panel -->
330 <div class="break"></div>
331 <!-- foot -->
332 <div id="foot">
333 <?php foreach( $validFooterLinks as $category => $links ): ?>
334 <?php if ( count( $links ) > 0 ): ?>
335 <ul id="foot-<?php echo $category ?>">
336 <?php foreach( $links as $link ): ?>
337 <?php if( isset( $this->data[$link] ) && $this->data[$link] ): ?>
338 <li id="foot-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
339 <?php endif; ?>
340 <?php endforeach; ?>
341 </ul>
342 <?php endif; ?>
343 <?php endforeach; ?>
344 <ul id="foot-icons" class="noprint">
345 <?php if( $this->data['poweredbyico'] ): ?>
346 <li id="foot-icon-poweredby"><?php $this->html( 'poweredbyico' ) ?></li>
347 <?php endif; ?>
348 <?php if( $this->data['copyrightico'] ): ?>
349 <li id="foot-icon-copyright"><?php $this->html( 'copyrightico' ) ?></li>
350 <?php endif; ?>
351 </ul>
352 <div style="clear:both"></div>
353 </div>
354 <!-- /foot -->
355 <!-- logo -->
356 <div id="p-logo">
357 <a style="background-image: url(<?php $this->text('logopath') ?>);" href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>" <?php echo $this->skin->tooltipAndAccesskey('p-logo') ?>></a>
358 </div>
359 <!-- /logo -->
360 <!-- fixalpha -->
361 <script type="<?php $this->text('jsmimetype') ?>"> if (window.isMSIE55) fixalpha( 'p-logo' ); </script>
362 <!-- /fixalpha -->
363 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
364 <?php $this->html( 'reporttime' ) ?>
365 <?php if ( $this->data['debug'] ): ?>
366 <!-- Debug output:
367 <?php $this->text( 'debug' ); ?>
368 -->
369 <?php endif; ?>
370 </body>
371 </html>
372 <?php
373 // We're done with abusing arrays now...
374 wfRestoreWarnings();
375 }
376
377 /**
378 * Outputs a box with a list of tools
379 */
380 private function toolBox() {
381 ?>
382 <div class="portal" id="p-tb">
383 <h5 <?php $this->html('userlangattributes') ?>><?php $this->msg( 'toolbox' ) ?></h5>
384 <div class="body">
385 <ul>
386 <?php if( $this->data['notspecialpage'] ): ?>
387 <li id="t-whatlinkshere"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['whatlinkshere']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-whatlinkshere' ) ?>><?php $this->msg( 'whatlinkshere' ) ?></a></li>
388 <?php if( $this->data['nav_urls']['recentchangeslinked'] ): ?>
389 <li id="t-recentchangeslinked"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['recentchangeslinked']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-recentchangeslinked' ) ?>><?php $this->msg( 'recentchangeslinked-toolbox' ) ?></a></li>
390 <?php endif; ?>
391 <?php endif; ?>
392 <?php if( isset( $this->data['nav_urls']['trackbacklink'] ) ): ?>
393 <li id="t-trackbacklink"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['trackbacklink']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-trackbacklink' ) ?>><?php $this->msg( 'trackbacklink' ) ?></a></li>
394 <?php endif; ?>
395 <?php if( $this->data['feeds']): ?>
396 <li id="feedlinks">
397 <?php foreach( $this->data['feeds'] as $key => $feed ): ?>
398 <a id="<?php echo Sanitizer::escapeId( "feed-$key" ) ?>" href="<?php echo htmlspecialchars( $feed['href'] ) ?>" rel="alternate" type="application/<?php echo $key ?>+xml" class="feedlink"<?php echo $this->skin->tooltipAndAccesskey( 'feed-' . $key ) ?>><?php echo htmlspecialchars( $feed['text'] ) ?></a>
399 <?php endforeach; ?>
400 </li>
401 <?php endif; ?>
402 <?php foreach( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ): ?>
403 <?php if( $this->data['nav_urls'][$special]): ?>
404 <li id="t-<?php echo $special ?>"><a href="<?php echo htmlspecialchars( $this->data['nav_urls'][$special]['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-' . $special ) ?>><?php $this->msg( $special ) ?></a></li>
405 <?php endif; ?>
406 <?php endforeach; ?>
407 <?php if( !empty( $this->data['nav_urls']['print']['href'] ) ): ?>
408 <li id="t-print"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['print']['href'] ) ?>" rel="alternate"<?php echo $this->skin->tooltipAndAccesskey( 't-print' ) ?>><?php $this->msg( 'printableversion' ) ?></a></li>
409 <?php endif; ?>
410 <?php if ( !empty( $this->data['nav_urls']['permalink']['href'] ) ): ?>
411 <li id="t-permalink"><a href="<?php echo htmlspecialchars( $this->data['nav_urls']['permalink']['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 't-permalink' ) ?>><?php $this->msg( 'permalink' ) ?></a></li>
412 <?php elseif ( $this->data['nav_urls']['permalink']['href'] === '' ): ?>
413 <li id="t-ispermalink"<?php echo $this->skin->tooltip( 't-ispermalink' ) ?>><?php $this->msg( 'permalink' ) ?></li>
414 <?php endif; ?>
415 <?php wfRunHooks( 'VectorTemplateToolboxEnd', array( &$this ) ); ?>
416 <?php wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) ); ?>
417 </ul>
418 </div>
419 </div>
420 <?php
421 }
422
423 /**
424 * Outputs a box with a list of alternative languages for this page
425 */
426 private function languageBox() {
427 if( $this->data['language_urls'] ) {
428 ?>
429 <div class="portal" id="p-lang">
430 <h5 <?php $this->html('userlangattributes') ?>><?php $this->msg( 'otherlanguages' ) ?></h5>
431 <div class="body">
432 <ul>
433 <?php foreach ( $this->data['language_urls'] as $langlink ): ?>
434 <li class="<?php echo htmlspecialchars( $langlink['class'] ) ?>"><a href="<?php echo htmlspecialchars( $langlink['href'] ) ?>"><?php echo $langlink['text'] ?></a></li>
435 <?php endforeach; ?>
436 </ul>
437 </div>
438 </div>
439 <?php
440 }
441 }
442
443 /**
444 * Outputs a box with a custom list of items or HTML content
445 * @param string $bar Message name for title of box
446 * @param mixed $content HTML or array of items to build a list from
447 */
448 private function customBox( $bar, $content ) {
449 ?>
450 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$bar" ) ?>'<?php echo $this->skin->tooltip( 'p-' . $bar ) ?>>
451 <h5 <?php $this->html('userlangattributes') ?>><?php $out = wfMsg( $bar ); if ( wfEmptyMsg( $bar, $out ) ) echo htmlspecialchars( $bar ); else echo htmlspecialchars( $out ); ?></h5>
452 <div class="body">
453 <?php if ( is_array( $content ) ): ?>
454 <ul>
455 <?php foreach( $content as $key => $val ): ?>
456 <li id="<?php echo Sanitizer::escapeId( $val['id'] ) ?>"<?php if ( $val['active'] ): ?> class="active" <?php endif; ?>><a href="<?php echo htmlspecialchars( $val['href'] ) ?>"<?php echo $this->skin->tooltipAndAccesskey( $val['id'] ) ?>><?php echo htmlspecialchars( $val['text'] ) ?></a></li>
457 <?php endforeach; ?>
458 </ul>
459 <?php else: ?>
460 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
461 <?php endif; ?>
462 </div>
463 </div>
464 <?php
465 }
466 }