thumb_handler.php doesn't seem to extract path_info correctly
[mediawiki.git] / skins / Vector.php
blobd0305f0093e79da2ec02006e13504b92471d5f4e
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 * @todo document
22 * @file
23 * @ingroup Skins
26 if ( !defined( 'MEDIAWIKI' ) ) {
27 die( -1 );
30 /**
31 * SkinTemplate class for Vector skin
32 * @ingroup Skins
34 class SkinVector extends SkinTemplate {
36 protected static $bodyClasses = array( 'vector-animateLayout' );
38 var $skinname = 'vector', $stylename = 'vector',
39 $template = 'VectorTemplate', $useHeadElement = true;
41 /**
42 * Initializes output page and sets up skin-specific parameters
43 * @param $out OutputPage object to initialize
45 public function initPage( OutputPage $out ) {
46 global $wgLocalStylePath;
48 parent::initPage( $out );
50 // Append CSS which includes IE only behavior fixes for hover support -
51 // this is better than including this in a CSS file since it doesn't
52 // wait for the CSS file to load before fetching the HTC file.
53 $min = $this->getRequest()->getFuzzyBool( 'debug' ) ? '' : '.min';
54 $out->addHeadItem( 'csshover',
55 '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
56 htmlspecialchars( $wgLocalStylePath ) .
57 "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->"
60 $out->addModules( 'skins.vector.js' );
63 /**
64 * Loads skin and user CSS files.
65 * @param $out OutputPage object
67 function setupSkinUserCss( OutputPage $out ) {
68 parent::setupSkinUserCss( $out );
69 $out->addModuleStyles( 'skins.vector' );
72 /**
73 * Adds classes to the body element.
75 * @param $out OutputPage object
76 * @param &$bodyAttrs Array of attributes that will be set on the body element
78 function addToBodyAttributes( $out, &$bodyAttrs ) {
79 if ( isset( $bodyAttrs['class'] ) && strlen( $bodyAttrs['class'] ) > 0 ) {
80 $bodyAttrs['class'] .= ' ' . implode( ' ', static::$bodyClasses );
81 } else {
82 $bodyAttrs['class'] = implode( ' ', static::$bodyClasses );
87 /**
88 * QuickTemplate class for Vector skin
89 * @ingroup Skins
91 class VectorTemplate extends BaseTemplate {
93 /* Functions */
95 /**
96 * Outputs the entire contents of the (X)HTML page
98 public function execute() {
99 global $wgVectorUseIconWatch;
101 // Build additional attributes for navigation urls
102 $nav = $this->data['content_navigation'];
104 if ( $wgVectorUseIconWatch ) {
105 $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() ) ? 'unwatch' : 'watch';
106 if ( isset( $nav['actions'][$mode] ) ) {
107 $nav['views'][$mode] = $nav['actions'][$mode];
108 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
109 $nav['views'][$mode]['primary'] = true;
110 unset( $nav['actions'][$mode] );
114 $xmlID = '';
115 foreach ( $nav as $section => $links ) {
116 foreach ( $links as $key => $link ) {
117 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
118 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
121 $xmlID = isset( $link['id'] ) ? $link['id'] : 'ca-' . $xmlID;
122 $nav[$section][$key]['attributes'] =
123 ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
124 if ( $link['class'] ) {
125 $nav[$section][$key]['attributes'] .=
126 ' class="' . htmlspecialchars( $link['class'] ) . '"';
127 unset( $nav[$section][$key]['class'] );
129 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
130 $nav[$section][$key]['key'] =
131 Linker::tooltip( $xmlID );
132 } else {
133 $nav[$section][$key]['key'] =
134 Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
138 $this->data['namespace_urls'] = $nav['namespaces'];
139 $this->data['view_urls'] = $nav['views'];
140 $this->data['action_urls'] = $nav['actions'];
141 $this->data['variant_urls'] = $nav['variants'];
143 // Reverse horizontally rendered navigation elements
144 if ( $this->data['rtl'] ) {
145 $this->data['view_urls'] =
146 array_reverse( $this->data['view_urls'] );
147 $this->data['namespace_urls'] =
148 array_reverse( $this->data['namespace_urls'] );
149 $this->data['personal_urls'] =
150 array_reverse( $this->data['personal_urls'] );
152 // Output HTML Page
153 $this->html( 'headelement' );
155 <div id="mw-page-base" class="noprint"></div>
156 <div id="mw-head-base" class="noprint"></div>
157 <div id="content" class="mw-body" role="main">
158 <a id="top"></a>
159 <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
160 <?php if ( $this->data['sitenotice'] ) { ?>
161 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
162 <?php } ?>
163 <h1 id="firstHeading" class="firstHeading" lang="<?php
164 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getCode();
165 $this->html( 'pageLanguage' );
166 ?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
167 <div id="bodyContent">
168 <?php if ( $this->data['isarticle'] ) { ?>
169 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
170 <?php } ?>
171 <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
172 <?php if ( $this->data['undelete'] ) { ?>
173 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
174 <?php } ?>
175 <?php if ( $this->data['newtalk'] ) { ?>
176 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
177 <?php } ?>
178 <?php if ( $this->data['showjumplinks'] ) { ?>
179 <div id="jump-to-nav" class="mw-jump">
180 <?php $this->msg( 'jumpto' ) ?>
181 <a href="#mw-navigation"><?php $this->msg( 'jumptonavigation' ) ?></a><?php $this->msg( 'comma-separator' ) ?>
182 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
183 </div>
184 <?php } ?>
185 <?php $this->html( 'bodycontent' ) ?>
186 <?php if ( $this->data['printfooter'] ) { ?>
187 <div class="printfooter">
188 <?php $this->html( 'printfooter' ); ?>
189 </div>
190 <?php } ?>
191 <?php if ( $this->data['catlinks'] ) { ?>
192 <?php $this->html( 'catlinks' ); ?>
193 <?php } ?>
194 <?php if ( $this->data['dataAfterContent'] ) { ?>
195 <?php $this->html( 'dataAfterContent' ); ?>
196 <?php } ?>
197 <div class="visualClear"></div>
198 <?php $this->html( 'debughtml' ); ?>
199 </div>
200 </div>
201 <div id="mw-navigation">
202 <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
203 <div id="mw-head">
204 <?php $this->renderNavigation( 'PERSONAL' ); ?>
205 <div id="left-navigation">
206 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
207 </div>
208 <div id="right-navigation">
209 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
210 </div>
211 </div>
212 <div id="mw-panel">
213 <div id="p-logo" role="banner"><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>
214 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
215 </div>
216 </div>
217 <div id="footer" role="contentinfo"<?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 } ?>
223 </ul>
224 <?php } ?>
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 ); ?>
233 <?php } ?>
234 </li>
235 <?php } ?>
236 </ul>
237 <?php } ?>
238 <div style="clear:both"></div>
239 </div>
240 <?php $this->printTrail(); ?>
242 </body>
243 </html>
244 <?php
248 * Render a series of portals
250 * @param $portals array
252 protected function renderPortals( $portals ) {
253 // Force the rendering of the following portals
254 if ( !isset( $portals['SEARCH'] ) ) {
255 $portals['SEARCH'] = true;
257 if ( !isset( $portals['TOOLBOX'] ) ) {
258 $portals['TOOLBOX'] = true;
260 if ( !isset( $portals['LANGUAGES'] ) ) {
261 $portals['LANGUAGES'] = true;
263 // Render portals
264 foreach ( $portals as $name => $content ) {
265 if ( $content === false ) {
266 continue;
269 switch ( $name ) {
270 case 'SEARCH':
271 break;
272 case 'TOOLBOX':
273 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
274 break;
275 case 'LANGUAGES':
276 if ( $this->data['language_urls'] ) {
277 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
279 break;
280 default:
281 $this->renderPortal( $name, $content );
282 break;
288 * @param $name string
289 * @param $content array
290 * @param $msg null|string
291 * @param $hook null|string|array
293 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
294 if ( $msg === null ) {
295 $msg = $name;
297 $msgObj = wfMessage( $msg );
299 <div class="portal" role="navigation" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?>>
300 <h3<?php $this->html( 'userlangattributes' ) ?>><?php echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg ); ?></h3>
301 <div class="body">
302 <?php
303 if ( is_array( $content ) ) { ?>
304 <ul>
305 <?php
306 foreach ( $content as $key => $val ) { ?>
307 <?php echo $this->makeListItem( $key, $val ); ?>
309 <?php
311 if ( $hook !== null ) {
312 wfRunHooks( $hook, array( &$this, true ) );
315 </ul>
316 <?php
317 } else { ?>
318 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
319 <?php
320 } ?>
321 </div>
322 </div>
323 <?php
327 * Render one or more navigations elements by name, automatically reveresed
328 * when UI is in RTL mode
330 * @param $elements array
332 protected function renderNavigation( $elements ) {
333 global $wgVectorUseSimpleSearch;
335 // If only one element was given, wrap it in an array, allowing more
336 // flexible arguments
337 if ( !is_array( $elements ) ) {
338 $elements = array( $elements );
339 // If there's a series of elements, reverse them when in RTL mode
340 } elseif ( $this->data['rtl'] ) {
341 $elements = array_reverse( $elements );
343 // Render elements
344 foreach ( $elements as $name => $element ) {
345 switch ( $element ) {
346 case 'NAMESPACES':
348 <div id="p-namespaces" role="navigation" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
349 <h3><?php $this->msg( 'namespaces' ) ?></h3>
350 <ul<?php $this->html( 'userlangattributes' ) ?>>
351 <?php foreach ( $this->data['namespace_urls'] as $link ) { ?>
352 <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>
353 <?php } ?>
354 </ul>
355 </div>
356 <?php
357 break;
358 case 'VARIANTS':
360 <div id="p-variants" role="navigation" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
361 <h3 id="mw-vector-current-variant">
362 <?php foreach ( $this->data['variant_urls'] as $link ) { ?>
363 <?php if ( stripos( $link['attributes'], 'selected' ) !== false ) { ?>
364 <?php echo htmlspecialchars( $link['text'] ) ?>
365 <?php } ?>
366 <?php } ?>
367 </h3>
368 <h3><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h3>
369 <div class="menu">
370 <ul>
371 <?php foreach ( $this->data['variant_urls'] as $link ) { ?>
372 <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>
373 <?php } ?>
374 </ul>
375 </div>
376 </div>
377 <?php
378 break;
379 case 'VIEWS':
381 <div id="p-views" role="navigation" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
382 <h3><?php $this->msg( 'views' ) ?></h3>
383 <ul<?php $this->html( 'userlangattributes' ) ?>>
384 <?php foreach ( $this->data['view_urls'] as $link ) { ?>
385 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
386 // $link['text'] can be undefined - bug 27764
387 if ( array_key_exists( 'text', $link ) ) {
388 echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
390 ?></a></span></li>
391 <?php } ?>
392 </ul>
393 </div>
394 <?php
395 break;
396 case 'ACTIONS':
398 <div id="p-cactions" role="navigation" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
399 <h3><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h3>
400 <div class="menu">
401 <ul<?php $this->html( 'userlangattributes' ) ?>>
402 <?php foreach ( $this->data['action_urls'] as $link ) { ?>
403 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
404 <?php } ?>
405 </ul>
406 </div>
407 </div>
408 <?php
409 break;
410 case 'PERSONAL':
412 <div id="p-personal" role="navigation" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
413 <h3><?php $this->msg( 'personaltools' ) ?></h3>
414 <ul<?php $this->html( 'userlangattributes' ) ?>>
415 <?php
416 $personalTools = $this->getPersonalTools();
417 foreach ( $personalTools as $key => $item ) {
418 echo $this->makeListItem( $key, $item );
421 </ul>
422 </div>
423 <?php
424 break;
425 case 'SEARCH':
427 <div id="p-search" role="search">
428 <h3<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
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 } ?>
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 } ?>
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 } ?>
445 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
446 </div>
447 </form>
448 </div>
449 <?php
451 break;