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