Remove AjaxAddScript hook
[mediawiki.git] / skins / Vector / VectorTemplate.php
blob7dc376ae77ad0c63a3100f56cccdb0177310bc59
1 <?php
2 /**
3 * Vector - Modern version of MonoBook with fresh look and many usability
4 * improvements.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @file
22 * @ingroup Skins
25 /**
26 * QuickTemplate class for Vector skin
27 * @ingroup Skins
29 class VectorTemplate extends BaseTemplate {
30 /* Functions */
32 /**
33 * Outputs the entire contents of the (X)HTML page
35 public function execute() {
36 global $wgVectorUseIconWatch;
38 // Build additional attributes for navigation urls
39 $nav = $this->data['content_navigation'];
41 if ( $wgVectorUseIconWatch ) {
42 $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() )
43 ? 'unwatch'
44 : 'watch';
46 if ( isset( $nav['actions'][$mode] ) ) {
47 $nav['views'][$mode] = $nav['actions'][$mode];
48 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
49 $nav['views'][$mode]['primary'] = true;
50 unset( $nav['actions'][$mode] );
54 $xmlID = '';
55 foreach ( $nav as $section => $links ) {
56 foreach ( $links as $key => $link ) {
57 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
58 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
61 $xmlID = isset( $link['id'] ) ? $link['id'] : 'ca-' . $xmlID;
62 $nav[$section][$key]['attributes'] =
63 ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
64 if ( $link['class'] ) {
65 $nav[$section][$key]['attributes'] .=
66 ' class="' . htmlspecialchars( $link['class'] ) . '"';
67 unset( $nav[$section][$key]['class'] );
69 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
70 $nav[$section][$key]['key'] =
71 Linker::tooltip( $xmlID );
72 } else {
73 $nav[$section][$key]['key'] =
74 Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
78 $this->data['namespace_urls'] = $nav['namespaces'];
79 $this->data['view_urls'] = $nav['views'];
80 $this->data['action_urls'] = $nav['actions'];
81 $this->data['variant_urls'] = $nav['variants'];
83 // Reverse horizontally rendered navigation elements
84 if ( $this->data['rtl'] ) {
85 $this->data['view_urls'] =
86 array_reverse( $this->data['view_urls'] );
87 $this->data['namespace_urls'] =
88 array_reverse( $this->data['namespace_urls'] );
89 $this->data['personal_urls'] =
90 array_reverse( $this->data['personal_urls'] );
92 // Output HTML Page
93 $this->html( 'headelement' );
95 <div id="mw-page-base" class="noprint"></div>
96 <div id="mw-head-base" class="noprint"></div>
97 <div id="content" class="mw-body" role="main">
98 <a id="top"></a>
100 <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
101 <?php
102 if ( $this->data['sitenotice'] ) {
104 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
105 <?php
108 <h1 id="firstHeading" class="firstHeading" lang="<?php
109 $this->data['pageLanguage'] =
110 $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
111 $this->text( 'pageLanguage' );
112 ?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
113 <?php $this->html( 'prebodyhtml' ) ?>
114 <div id="bodyContent" class="mw-body-content">
115 <?php
116 if ( $this->data['isarticle'] ) {
118 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
119 <?php
122 <div id="contentSub"<?php
123 $this->html( 'userlangattributes' )
124 ?>><?php $this->html( 'subtitle' ) ?></div>
125 <?php
126 if ( $this->data['undelete'] ) {
128 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
129 <?php
132 <?php
133 if ( $this->data['newtalk'] ) {
135 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
136 <?php
139 <div id="jump-to-nav" class="mw-jump">
140 <?php $this->msg( 'jumpto' ) ?>
141 <a href="#mw-navigation"><?php
142 $this->msg( 'jumptonavigation' )
143 ?></a><?php
144 $this->msg( 'comma-separator' )
146 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
147 </div>
148 <?php $this->html( 'bodycontent' ) ?>
149 <?php
150 if ( $this->data['printfooter'] ) {
152 <div class="printfooter">
153 <?php $this->html( 'printfooter' ); ?>
154 </div>
155 <?php
158 <?php
159 if ( $this->data['catlinks'] ) {
161 <?php
162 $this->html( 'catlinks' );
164 <?php
167 <?php
168 if ( $this->data['dataAfterContent'] ) {
170 <?php
171 $this->html( 'dataAfterContent' );
173 <?php
176 <div class="visualClear"></div>
177 <?php $this->html( 'debughtml' ); ?>
178 </div>
179 </div>
180 <div id="mw-navigation">
181 <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
183 <div id="mw-head">
184 <?php $this->renderNavigation( 'PERSONAL' ); ?>
185 <div id="left-navigation">
186 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
187 </div>
188 <div id="right-navigation">
189 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
190 </div>
191 </div>
192 <div id="mw-panel">
193 <div id="p-logo" role="banner"><a style="background-image: url(<?php
194 $this->text( 'logopath' )
195 ?>);" href="<?php
196 echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] )
197 ?>" <?php
198 echo Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) )
199 ?>></a></div>
200 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
201 </div>
202 </div>
203 <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
204 <?php
205 foreach ( $this->getFooterLinks() as $category => $links ) {
207 <ul id="footer-<?php
208 echo $category
209 ?>">
210 <?php
211 foreach ( $links as $link ) {
213 <li id="footer-<?php
214 echo $category
215 ?>-<?php
216 echo $link
217 ?>"><?php
218 $this->html( $link )
219 ?></li>
220 <?php
223 </ul>
224 <?php
227 <?php $footericons = $this->getFooterIcons( "icononly" );
228 if ( count( $footericons ) > 0 ) {
230 <ul id="footer-icons" class="noprint">
231 <?php
232 foreach ( $footericons as $blockName => $footerIcons ) {
234 <li id="footer-<?php
235 echo htmlspecialchars( $blockName ); ?>ico">
236 <?php
237 foreach ( $footerIcons as $icon ) {
239 <?php
240 echo $this->getSkin()->makeFooterIcon( $icon );
243 <?php
246 </li>
247 <?php
250 </ul>
251 <?php
254 <div style="clear:both"></div>
255 </div>
256 <?php $this->printTrail(); ?>
258 </body>
259 </html>
260 <?php
264 * Render a series of portals
266 * @param array $portals
268 protected function renderPortals( $portals ) {
269 // Force the rendering of the following portals
270 if ( !isset( $portals['SEARCH'] ) ) {
271 $portals['SEARCH'] = true;
273 if ( !isset( $portals['TOOLBOX'] ) ) {
274 $portals['TOOLBOX'] = true;
276 if ( !isset( $portals['LANGUAGES'] ) ) {
277 $portals['LANGUAGES'] = true;
279 // Render portals
280 foreach ( $portals as $name => $content ) {
281 if ( $content === false ) {
282 continue;
285 switch ( $name ) {
286 case 'SEARCH':
287 break;
288 case 'TOOLBOX':
289 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
290 break;
291 case 'LANGUAGES':
292 if ( $this->data['language_urls'] !== false ) {
293 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
295 break;
296 default:
297 $this->renderPortal( $name, $content );
298 break;
304 * @param string $name
305 * @param array $content
306 * @param null|string $msg
307 * @param null|string|array $hook
309 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
310 if ( $msg === null ) {
311 $msg = $name;
313 $msgObj = wfMessage( $msg );
315 <div class="portal" role="navigation" id='<?php
316 echo Sanitizer::escapeId( "p-$name" )
317 ?>'<?php
318 echo Linker::tooltip( 'p-' . $name )
319 ?> aria-labelledby='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'>
320 <h3<?php
321 $this->html( 'userlangattributes' )
322 ?> id='<?php
323 echo Sanitizer::escapeId( "p-$name-label" )
324 ?>'><?php
325 echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg );
326 ?></h3>
328 <div class="body">
329 <?php
330 if ( is_array( $content ) ) {
332 <ul>
333 <?php
334 foreach ( $content as $key => $val ) {
336 <?php echo $this->makeListItem( $key, $val ); ?>
338 <?php
340 if ( $hook !== null ) {
341 wfRunHooks( $hook, array( &$this, true ) );
344 </ul>
345 <?php
346 } else {
348 <?php
349 echo $content; /* Allow raw HTML block to be defined by extensions */
352 $this->renderAfterPortlet( $name );
354 </div>
355 </div>
356 <?php
360 * Render one or more navigations elements by name, automatically reveresed
361 * when UI is in RTL mode
363 * @param array $elements
365 protected function renderNavigation( $elements ) {
366 global $wgVectorUseSimpleSearch;
368 // If only one element was given, wrap it in an array, allowing more
369 // flexible arguments
370 if ( !is_array( $elements ) ) {
371 $elements = array( $elements );
372 // If there's a series of elements, reverse them when in RTL mode
373 } elseif ( $this->data['rtl'] ) {
374 $elements = array_reverse( $elements );
376 // Render elements
377 foreach ( $elements as $name => $element ) {
378 switch ( $element ) {
379 case 'NAMESPACES':
381 <div id="p-namespaces" role="navigation" class="vectorTabs<?php
382 if ( count( $this->data['namespace_urls'] ) == 0 ) {
383 echo ' emptyPortlet';
385 ?>" aria-labelledby="p-namespaces-label">
386 <h3 id="p-namespaces-label"><?php $this->msg( 'namespaces' ) ?></h3>
387 <ul<?php $this->html( 'userlangattributes' ) ?>>
388 <?php
389 foreach ( $this->data['namespace_urls'] as $link ) {
391 <li <?php
392 echo $link['attributes']
393 ?>><span><a href="<?php
394 echo htmlspecialchars( $link['href'] )
395 ?>" <?php
396 echo $link['key']
397 ?>><?php
398 echo htmlspecialchars( $link['text'] )
399 ?></a></span></li>
400 <?php
403 </ul>
404 </div>
405 <?php
406 break;
407 case 'VARIANTS':
409 <div id="p-variants" role="navigation" class="vectorMenu<?php
410 if ( count( $this->data['variant_urls'] ) == 0 ) {
411 echo ' emptyPortlet';
413 ?>" aria-labelledby="p-variants-label">
414 <h3 id="mw-vector-current-variant">
415 <?php
416 foreach ( $this->data['variant_urls'] as $link ) {
418 <?php
419 if ( stripos( $link['attributes'], 'selected' ) !== false ) {
421 <?php
422 echo htmlspecialchars( $link['text'] )
424 <?php
427 <?php
430 </h3>
432 <h3 id="p-variants-label"><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h3>
434 <div class="menu">
435 <ul>
436 <?php
437 foreach ( $this->data['variant_urls'] as $link ) {
439 <li<?php
440 echo $link['attributes']
441 ?>><a href="<?php
442 echo htmlspecialchars( $link['href'] )
443 ?>" lang="<?php
444 echo htmlspecialchars( $link['lang'] )
445 ?>" hreflang="<?php
446 echo htmlspecialchars( $link['hreflang'] )
447 ?>" <?php
448 echo $link['key']
449 ?>><?php
450 echo htmlspecialchars( $link['text'] )
451 ?></a></li>
452 <?php
455 </ul>
456 </div>
457 </div>
458 <?php
459 break;
460 case 'VIEWS':
462 <div id="p-views" role="navigation" class="vectorTabs<?php
463 if ( count( $this->data['view_urls'] ) == 0 ) {
464 echo ' emptyPortlet';
466 ?>" aria-labelledby="p-views-label">
467 <h3 id="p-views-label"><?php $this->msg( 'views' ) ?></h3>
468 <ul<?php
469 $this->html( 'userlangattributes' )
471 <?php
472 foreach ( $this->data['view_urls'] as $link ) {
474 <li<?php
475 echo $link['attributes']
476 ?>><span><a href="<?php
477 echo htmlspecialchars( $link['href'] )
478 ?>" <?php
479 echo $link['key']
480 ?>><?php
481 // $link['text'] can be undefined - bug 27764
482 if ( array_key_exists( 'text', $link ) ) {
483 echo array_key_exists( 'img', $link )
484 ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />'
485 : htmlspecialchars( $link['text'] );
487 ?></a></span></li>
488 <?php
491 </ul>
492 </div>
493 <?php
494 break;
495 case 'ACTIONS':
497 <div id="p-cactions" role="navigation" class="vectorMenu<?php
498 if ( count( $this->data['action_urls'] ) == 0 ) {
499 echo ' emptyPortlet';
501 ?>" aria-labelledby="p-cactions-label">
502 <h3 id="p-cactions-label"><span><?php $this->msg( 'vector-more-actions' ) ?></span><a href="#"></a></h3>
504 <div class="menu">
505 <ul<?php $this->html( 'userlangattributes' ) ?>>
506 <?php
507 foreach ( $this->data['action_urls'] as $link ) {
509 <li<?php
510 echo $link['attributes']
512 <a href="<?php
513 echo htmlspecialchars( $link['href'] )
514 ?>" <?php
515 echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] )
516 ?></a>
517 </li>
518 <?php
521 </ul>
522 </div>
523 </div>
524 <?php
525 break;
526 case 'PERSONAL':
528 <div id="p-personal" role="navigation" class="<?php
529 if ( count( $this->data['personal_urls'] ) == 0 ) {
530 echo ' emptyPortlet';
532 ?>" aria-labelledby="p-personal-label">
533 <h3 id="p-personal-label"><?php $this->msg( 'personaltools' ) ?></h3>
534 <ul<?php $this->html( 'userlangattributes' ) ?>>
535 <?php
536 $personalTools = $this->getPersonalTools();
537 foreach ( $personalTools as $key => $item ) {
538 echo $this->makeListItem( $key, $item );
541 </ul>
542 </div>
543 <?php
544 break;
545 case 'SEARCH':
547 <div id="p-search" role="search">
548 <h3<?php $this->html( 'userlangattributes' ) ?>>
549 <label for="searchInput"><?php $this->msg( 'search' ) ?></label>
550 </h3>
552 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
553 <?php
554 if ($wgVectorUseSimpleSearch) {
556 <div id="simpleSearch">
557 <?php
558 } else {
560 <div>
561 <?php
564 <?php
565 echo $this->makeSearchInput( array( 'id' => 'searchInput' ) );
566 echo Html::hidden( 'title', $this->get( 'searchtitle' ) );
567 // We construct two buttons (for 'go' and 'fulltext' search modes),
568 // but only one will be visible and actionable at a time (they are
569 // overlaid on top of each other in CSS).
570 // * Browsers will use the 'fulltext' one by default (as it's the
571 // first in tree-order), which is desirable when they are unable
572 // to show search suggestions (either due to being broken or
573 // having JavaScript turned off).
574 // * The mediawiki.searchSuggest module, after doing tests for the
575 // broken browsers, removes the 'fulltext' button and handles
576 // 'fulltext' search itself; this will reveal the 'go' button and
577 // cause it to be used.
578 echo $this->makeSearchButton(
579 'fulltext',
580 array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' )
582 echo $this->makeSearchButton(
583 'go',
584 array( 'id' => 'searchButton', 'class' => 'searchButton' )
587 </div>
588 </form>
589 </div>
590 <?php
592 break;