Fix php notice in vector from r79383.
[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 /**
16 * SkinTemplate class for Vector skin
17 * @ingroup Skins
18 */
19 class SkinVector extends SkinTemplate {
20
21 /* Functions */
22 var $skinname = 'vector', $stylename = 'vector',
23 $template = 'VectorTemplate', $useHeadElement = true;
24
25 /**
26 * Initializes output page and sets up skin-specific parameters
27 * @param $out OutputPage object to initialize
28 */
29 public function initPage( OutputPage $out ) {
30 global $wgLocalStylePath;
31
32 parent::initPage( $out );
33
34 // Append CSS which includes IE only behavior fixes for hover support -
35 // this is better than including this in a CSS fille since it doesn't
36 // wait for the CSS file to load before fetching the HTC file.
37 $out->addScript(
38 '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
39 htmlspecialchars( $wgLocalStylePath ) .
40 "/{$this->stylename}/csshover.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 Cached skin object
65 */
66 var $skin;
67
68 /* Functions */
69
70 /**
71 * Outputs the entire contents of the XHTML page
72 */
73 public function execute() {
74 global $wgRequest, $wgLang, $wgVectorUseIconWatch;
75
76 $this->skin = $this->data['skin'];
77 $action = $wgRequest->getText( 'action' );
78
79 // Build additional attributes for navigation urls
80 //$nav = $this->skin->buildNavigationUrls();
81 $nav = $this->data['content_navigation'];
82
83 if ( $wgVectorUseIconWatch ) {
84 $mode = $this->skin->mTitle->userIsWatching() ? 'unwatch' : 'watch';
85 if ( isset($nav['actions'][$mode]) ) {
86 $nav['views'][$mode] = $nav['actions'][$mode];
87 $nav['views'][$mode]['class'] = rtrim('icon ' . $nav['views'][$mode]['class'], ' ');
88 $nav['views'][$mode]['primary'] = true;
89 unset($nav['actions'][$mode]);
90 }
91 }
92
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 $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 // 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 <!-- tagline -->
150 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
151 <!-- /tagline -->
152 <!-- subtitle -->
153 <div id="contentSub"<?php $this->html('userlangattributes') ?>><?php $this->html( 'subtitle' ) ?></div>
154 <!-- /subtitle -->
155 <?php if ( $this->data['undelete'] ): ?>
156 <!-- undelete -->
157 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
158 <!-- /undelete -->
159 <?php endif; ?>
160 <?php if($this->data['newtalk'] ): ?>
161 <!-- newtalk -->
162 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
163 <!-- /newtalk -->
164 <?php endif; ?>
165 <?php if ( $this->data['showjumplinks'] ): ?>
166 <!-- jumpto -->
167 <div id="jump-to-nav">
168 <?php $this->msg( 'jumpto' ) ?> <a href="#mw-head"><?php $this->msg( 'jumptonavigation' ) ?></a>,
169 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
170 </div>
171 <!-- /jumpto -->
172 <?php endif; ?>
173 <!-- bodytext -->
174 <?php $this->html( 'bodytext' ) ?>
175 <!-- /bodytext -->
176 <?php if ( $this->data['catlinks'] ): ?>
177 <!-- catlinks -->
178 <?php $this->html( 'catlinks' ); ?>
179 <!-- /catlinks -->
180 <?php endif; ?>
181 <?php if ( $this->data['dataAfterContent'] ): ?>
182 <!-- dataAfterContent -->
183 <?php $this->html( 'dataAfterContent' ); ?>
184 <!-- /dataAfterContent -->
185 <?php endif; ?>
186 <div class="visualClear"></div>
187 </div>
188 <!-- /bodyContent -->
189 </div>
190 <!-- /content -->
191 <!-- header -->
192 <div id="mw-head" class="noprint">
193 <?php $this->renderNavigation( 'PERSONAL' ); ?>
194 <div id="left-navigation">
195 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
196 </div>
197 <div id="right-navigation">
198 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
199 </div>
200 </div>
201 <!-- /header -->
202 <!-- panel -->
203 <div id="mw-panel" class="noprint">
204 <!-- logo -->
205 <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 $this->skin->tooltipAndAccesskey( 'p-logo' ) ?>></a></div>
206 <!-- /logo -->
207 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
208 </div>
209 <!-- /panel -->
210 <!-- footer -->
211 <div id="footer"<?php $this->html('userlangattributes') ?>>
212 <?php foreach( $this->getFooterLinks() as $category => $links ): ?>
213 <ul id="footer-<?php echo $category ?>">
214 <?php foreach( $links as $link ): ?>
215 <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
216 <?php endforeach; ?>
217 </ul>
218 <?php endforeach; ?>
219 <?php $footericons = $this->getFooterIcons("icononly");
220 if ( count( $footericons ) > 0 ): ?>
221 <ul id="footer-icons" class="noprint">
222 <?php foreach ( $footericons as $blockName => $footerIcons ): ?>
223 <li id="footer-<?php echo htmlspecialchars($blockName); ?>ico">
224 <?php foreach ( $footerIcons as $icon ): ?>
225 <?php echo $this->skin->makeFooterIcon( $icon ); ?>
226
227 <?php endforeach; ?>
228 </li>
229 <?php endforeach; ?>
230 </ul>
231 <?php endif; ?>
232 <div style="clear:both"></div>
233 </div>
234 <!-- /footer -->
235 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
236 <!-- fixalpha -->
237 <script type="<?php $this->text('jsmimetype') ?>"> if ( window.isMSIE55 ) fixalpha(); </script>
238 <!-- /fixalpha -->
239 <?php $this->html( 'reporttime' ) ?>
240 <?php if ( $this->data['debug'] ): ?>
241 <!-- Debug output: <?php $this->text( 'debug' ); ?> -->
242 <?php endif; ?>
243 </body>
244 </html>
245 <?php
246 }
247
248 /**
249 * Render a series of portals
250 */
251 private function renderPortals( $portals ) {
252 // Force the rendering of the following portals
253 if ( !isset( $portals['SEARCH'] ) ) $portals['SEARCH'] = true;
254 if ( !isset( $portals['TOOLBOX'] ) ) $portals['TOOLBOX'] = true;
255 if ( !isset( $portals['LANGUAGES'] ) ) $portals['LANGUAGES'] = true;
256 // Render portals
257 foreach ( $portals as $name => $content ) {
258 echo "\n<!-- {$name} -->\n";
259 switch( $name ) {
260 case 'SEARCH':
261 break;
262 case 'TOOLBOX':
263 $this->renderPortal( "tb", $this->getToolbox(), "toolbox", "SkinTemplateToolboxEnd" );
264 break;
265 case 'LANGUAGES':
266 if ( $this->data['language_urls'] ) {
267 $this->renderPortal("lang", $this->data['language_urls'], "otherlanguages");
268 }
269 break;
270 default:
271 $this->renderPortal($name, $content);
272 break;
273 }
274 echo "\n<!-- /{$name} -->\n";
275 }
276 }
277
278 private function renderPortal($name, $content, $msg=null, $hook=null) {
279 if ( !isset($msg) ) {
280 $msg = $name;
281 }
282 ?>
283 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo $this->skin->tooltip( 'p-' . $name ) ?>>
284 <h5<?php $this->html('userlangattributes') ?>><?php $out = wfMsg( $msg ); if ( wfEmptyMsg( $msg, $out ) ) echo htmlspecialchars( $msg ); else echo htmlspecialchars( $out ); ?></h5>
285 <div class="body">
286 <?php
287 if ( is_array( $content ) ): ?>
288 <ul>
289 <?php
290 foreach( $content as $key => $val ): ?>
291 <?php echo $this->makeListItem($key, $val); ?>
292
293 <?php
294 endforeach;
295 if ( isset($hook) ) {
296 wfRunHooks( $hook, array( &$this ) );
297 }
298 ?>
299 </ul>
300 <?php
301 else: ?>
302 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
303 <?php
304 endif; ?>
305 </div>
306 </div>
307 <?php
308 }
309
310 /**
311 * Render one or more navigations elements by name, automatically reveresed
312 * when UI is in RTL mode
313 */
314 private function renderNavigation( $elements ) {
315 global $wgVectorUseSimpleSearch, $wgVectorShowVariantName, $wgUser;
316
317 // If only one element was given, wrap it in an array, allowing more
318 // flexible arguments
319 if ( !is_array( $elements ) ) {
320 $elements = array( $elements );
321 // If there's a series of elements, reverse them when in RTL mode
322 } else if ( wfUILang()->isRTL() ) {
323 $elements = array_reverse( $elements );
324 }
325 // Render elements
326 foreach ( $elements as $name => $element ) {
327 echo "\n<!-- {$name} -->\n";
328 switch ( $element ) {
329 case 'NAMESPACES':
330 ?>
331 <div id="p-namespaces" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
332 <h5><?php $this->msg('namespaces') ?></h5>
333 <ul<?php $this->html('userlangattributes') ?>>
334 <?php foreach ($this->data['namespace_urls'] as $link ): ?>
335 <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>
336 <?php endforeach; ?>
337 </ul>
338 </div>
339 <?php
340 break;
341 case 'VARIANTS':
342 ?>
343 <div id="p-variants" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
344 <?php if ( $wgVectorShowVariantName ): ?>
345 <h4>
346 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
347 <?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
348 <?php echo htmlspecialchars( $link['text'] ) ?>
349 <?php endif; ?>
350 <?php endforeach; ?>
351 </h4>
352 <?php endif; ?>
353 <h5><span><?php $this->msg('variants') ?></span><a href="#"></a></h5>
354 <div class="menu">
355 <ul<?php $this->html('userlangattributes') ?>>
356 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
357 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
358 <?php endforeach; ?>
359 </ul>
360 </div>
361 </div>
362 <?php
363 break;
364 case 'VIEWS':
365 ?>
366 <div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
367 <h5><?php $this->msg('views') ?></h5>
368 <ul<?php $this->html('userlangattributes') ?>>
369 <?php foreach ( $this->data['view_urls'] as $link ): ?>
370 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo (array_key_exists('img',$link) ? '<img src="'.$link['img'].'" alt="'.$link['text'].'" />' : htmlspecialchars( $link['text'] ) ) ?></a></span></li>
371 <?php endforeach; ?>
372 </ul>
373 </div>
374 <?php
375 break;
376 case 'ACTIONS':
377 ?>
378 <div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
379 <h5><span><?php $this->msg('actions') ?></span><a href="#"></a></h5>
380 <div class="menu">
381 <ul<?php $this->html('userlangattributes') ?>>
382 <?php foreach ($this->data['action_urls'] as $link ): ?>
383 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
384 <?php endforeach; ?>
385 </ul>
386 </div>
387 </div>
388 <?php
389 break;
390 case 'PERSONAL':
391 ?>
392 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
393 <h5><?php $this->msg('personaltools') ?></h5>
394 <ul<?php $this->html('userlangattributes') ?>>
395 <?php foreach($this->getPersonalTools() as $key => $item) { ?>
396 <?php echo $this->makeListItem($key, $item); ?>
397
398 <?php } ?>
399 </ul>
400 </div>
401 <?php
402 break;
403 case 'SEARCH':
404 ?>
405 <div id="p-search">
406 <h5<?php $this->html('userlangattributes') ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
407 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
408 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
409 <?php if ( $wgVectorUseSimpleSearch && $wgUser->getOption( 'vector-simplesearch' ) ): ?>
410 <div id="simpleSearch">
411 <?php if ( $this->data['rtl'] ): ?>
412 <?php echo $this->makeSearchButton("image", array( "id" => "searchButton", "src" => $this->skin->getSkinStylePath('images/search-rtl.png') )); ?>
413 <?php endif; ?>
414 <?php echo $this->makeSearchInput(array( "id" => "searchInput", "type" => "text" )); ?>
415 <?php if ( !$this->data['rtl'] ): ?>
416 <?php echo $this->makeSearchButton("image", array( "id" => "searchButton", "src" => $this->skin->getSkinStylePath('images/search-ltr.png') )); ?>
417 <?php endif; ?>
418 </div>
419 <?php else: ?>
420 <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
421 <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" )); ?>
422 <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" )); ?>
423 <?php endif; ?>
424 </form>
425 </div>
426 <?php
427
428 break;
429 }
430 echo "\n<!-- /{$name} -->\n";
431 }
432 }
433 }