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