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