Vector.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <?php
  2. /**
  3. * Vector - Modern version of MonoBook with fresh look and many usability
  4. * improvements.
  5. *
  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.
  10. *
  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.
  15. *
  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
  20. *
  21. * @todo document
  22. * @file
  23. * @ingroup Skins
  24. */
  25. if ( !defined( 'MEDIAWIKI' ) ) {
  26. die( -1 );
  27. }
  28. /**
  29. * SkinTemplate class for Vector skin
  30. * @ingroup Skins
  31. */
  32. class SkinVector extends SkinTemplate {
  33. protected static $bodyClasses = array( 'vector-animateLayout' );
  34. var $skinname = 'vector', $stylename = 'vector',
  35. $template = 'VectorTemplate', $useHeadElement = true;
  36. /**
  37. * Initializes output page and sets up skin-specific parameters
  38. * @param $out OutputPage object to initialize
  39. */
  40. public function initPage( OutputPage $out ) {
  41. global $wgLocalStylePath;
  42. parent::initPage( $out );
  43. // Append CSS which includes IE only behavior fixes for hover support -
  44. // this is better than including this in a CSS file since it doesn't
  45. // wait for the CSS file to load before fetching the HTC file.
  46. $min = $this->getRequest()->getFuzzyBool( 'debug' ) ? '' : '.min';
  47. $out->addHeadItem( 'csshover',
  48. '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
  49. htmlspecialchars( $wgLocalStylePath ) .
  50. "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->"
  51. );
  52. $out->addModules( array( 'skins.vector.js', 'skins.vector.collapsibleNav' ) );
  53. }
  54. /**
  55. * Loads skin and user CSS files.
  56. * @param $out OutputPage object
  57. */
  58. function setupSkinUserCss( OutputPage $out ) {
  59. parent::setupSkinUserCss( $out );
  60. $styles = array( 'mediawiki.skinning.interface', 'skins.vector.styles' );
  61. wfRunHooks( 'SkinVectorStyleModules', array( $this, &$styles ) );
  62. $out->addModuleStyles( $styles );
  63. }
  64. /**
  65. * Adds classes to the body element.
  66. *
  67. * @param $out OutputPage object
  68. * @param &$bodyAttrs Array of attributes that will be set on the body element
  69. */
  70. function addToBodyAttributes( $out, &$bodyAttrs ) {
  71. if ( isset( $bodyAttrs['class'] ) && strlen( $bodyAttrs['class'] ) > 0 ) {
  72. $bodyAttrs['class'] .= ' ' . implode( ' ', static::$bodyClasses );
  73. } else {
  74. $bodyAttrs['class'] = implode( ' ', static::$bodyClasses );
  75. }
  76. }
  77. }
  78. /**
  79. * QuickTemplate class for Vector skin
  80. * @ingroup Skins
  81. */
  82. class VectorTemplate extends BaseTemplate {
  83. /* Functions */
  84. /**
  85. * Outputs the entire contents of the (X)HTML page
  86. */
  87. public function execute() {
  88. global $wgVectorUseIconWatch;
  89. // Build additional attributes for navigation urls
  90. $nav = $this->data['content_navigation'];
  91. if ( $wgVectorUseIconWatch ) {
  92. $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() ) ? 'unwatch' : 'watch';
  93. if ( isset( $nav['actions'][$mode] ) ) {
  94. $nav['views'][$mode] = $nav['actions'][$mode];
  95. $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
  96. $nav['views'][$mode]['primary'] = true;
  97. unset( $nav['actions'][$mode] );
  98. }
  99. }
  100. $xmlID = '';
  101. foreach ( $nav as $section => $links ) {
  102. foreach ( $links as $key => $link ) {
  103. if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
  104. $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
  105. }
  106. $xmlID = isset( $link['id'] ) ? $link['id'] : 'ca-' . $xmlID;
  107. $nav[$section][$key]['attributes'] =
  108. ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
  109. if ( $link['class'] ) {
  110. $nav[$section][$key]['attributes'] .=
  111. ' class="' . htmlspecialchars( $link['class'] ) . '"';
  112. unset( $nav[$section][$key]['class'] );
  113. }
  114. if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
  115. $nav[$section][$key]['key'] =
  116. Linker::tooltip( $xmlID );
  117. } else {
  118. $nav[$section][$key]['key'] =
  119. Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
  120. }
  121. }
  122. }
  123. $this->data['namespace_urls'] = $nav['namespaces'];
  124. $this->data['view_urls'] = $nav['views'];
  125. $this->data['action_urls'] = $nav['actions'];
  126. $this->data['variant_urls'] = $nav['variants'];
  127. // Reverse horizontally rendered navigation elements
  128. if ( $this->data['rtl'] ) {
  129. $this->data['view_urls'] =
  130. array_reverse( $this->data['view_urls'] );
  131. $this->data['namespace_urls'] =
  132. array_reverse( $this->data['namespace_urls'] );
  133. $this->data['personal_urls'] =
  134. array_reverse( $this->data['personal_urls'] );
  135. }
  136. // Output HTML Page
  137. $this->html( 'headelement' );
  138. ?>
  139. <div id="mw-page-base" class="noprint"></div>
  140. <div id="mw-head-base" class="noprint"></div>
  141. <div id="content" class="mw-body" role="main">
  142. <a id="top"></a>
  143. <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
  144. <?php if ( $this->data['sitenotice'] ) { ?>
  145. <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
  146. <?php } ?>
  147. <h1 id="firstHeading" class="firstHeading" lang="<?php
  148. $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
  149. $this->text( 'pageLanguage' );
  150. ?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
  151. <?php $this->html( 'prebodyhtml' ) ?>
  152. <div id="bodyContent">
  153. <?php if ( $this->data['isarticle'] ) { ?>
  154. <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
  155. <?php } ?>
  156. <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
  157. <?php if ( $this->data['undelete'] ) { ?>
  158. <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
  159. <?php } ?>
  160. <?php if ( $this->data['newtalk'] ) { ?>
  161. <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
  162. <?php } ?>
  163. <div id="jump-to-nav" class="mw-jump">
  164. <?php $this->msg( 'jumpto' ) ?>
  165. <a href="#mw-navigation"><?php $this->msg( 'jumptonavigation' ) ?></a><?php $this->msg( 'comma-separator' ) ?>
  166. <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
  167. </div>
  168. <?php $this->html( 'bodycontent' ) ?>
  169. <?php if ( $this->data['printfooter'] ) { ?>
  170. <div class="printfooter">
  171. <?php $this->html( 'printfooter' ); ?>
  172. </div>
  173. <?php } ?>
  174. <?php if ( $this->data['catlinks'] ) { ?>
  175. <?php $this->html( 'catlinks' ); ?>
  176. <?php } ?>
  177. <?php if ( $this->data['dataAfterContent'] ) { ?>
  178. <?php $this->html( 'dataAfterContent' ); ?>
  179. <?php } ?>
  180. <div class="visualClear"></div>
  181. <?php $this->html( 'debughtml' ); ?>
  182. </div>
  183. </div>
  184. <div id="mw-navigation">
  185. <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
  186. <div id="mw-head">
  187. <?php $this->renderNavigation( 'PERSONAL' ); ?>
  188. <div id="left-navigation">
  189. <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
  190. </div>
  191. <div id="right-navigation">
  192. <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
  193. </div>
  194. </div>
  195. <div id="mw-panel">
  196. <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>
  197. <?php $this->renderPortals( $this->data['sidebar'] ); ?>
  198. </div>
  199. </div>
  200. <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
  201. <?php foreach ( $this->getFooterLinks() as $category => $links ) { ?>
  202. <ul id="footer-<?php echo $category ?>">
  203. <?php foreach ( $links as $link ) { ?>
  204. <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
  205. <?php } ?>
  206. </ul>
  207. <?php } ?>
  208. <?php $footericons = $this->getFooterIcons( "icononly" );
  209. if ( count( $footericons ) > 0 ) { ?>
  210. <ul id="footer-icons" class="noprint">
  211. <?php foreach ( $footericons as $blockName => $footerIcons ) { ?>
  212. <li id="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
  213. <?php foreach ( $footerIcons as $icon ) { ?>
  214. <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
  215. <?php } ?>
  216. </li>
  217. <?php } ?>
  218. </ul>
  219. <?php } ?>
  220. <div style="clear:both"></div>
  221. </div>
  222. <?php $this->printTrail(); ?>
  223. </body>
  224. </html>
  225. <?php
  226. }
  227. /**
  228. * Render a series of portals
  229. *
  230. * @param $portals array
  231. */
  232. protected function renderPortals( $portals ) {
  233. // Force the rendering of the following portals
  234. if ( !isset( $portals['SEARCH'] ) ) {
  235. $portals['SEARCH'] = true;
  236. }
  237. if ( !isset( $portals['TOOLBOX'] ) ) {
  238. $portals['TOOLBOX'] = true;
  239. }
  240. if ( !isset( $portals['LANGUAGES'] ) ) {
  241. $portals['LANGUAGES'] = true;
  242. }
  243. // Render portals
  244. foreach ( $portals as $name => $content ) {
  245. if ( $content === false ) {
  246. continue;
  247. }
  248. switch ( $name ) {
  249. case 'SEARCH':
  250. break;
  251. case 'TOOLBOX':
  252. $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
  253. break;
  254. case 'LANGUAGES':
  255. if ( $this->data['language_urls'] !== false ) {
  256. $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
  257. }
  258. break;
  259. default:
  260. $this->renderPortal( $name, $content );
  261. break;
  262. }
  263. }
  264. }
  265. /**
  266. * @param $name string
  267. * @param $content array
  268. * @param $msg null|string
  269. * @param $hook null|string|array
  270. */
  271. protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
  272. if ( $msg === null ) {
  273. $msg = $name;
  274. }
  275. $msgObj = wfMessage( $msg );
  276. ?>
  277. <div class="portal" role="navigation" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?> aria-labelledby='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'>
  278. <h3<?php $this->html( 'userlangattributes' ) ?> id='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'><?php echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg ); ?></h3>
  279. <div class="body">
  280. <?php
  281. if ( is_array( $content ) ) { ?>
  282. <ul>
  283. <?php
  284. foreach ( $content as $key => $val ) { ?>
  285. <?php echo $this->makeListItem( $key, $val ); ?>
  286. <?php
  287. }
  288. if ( $hook !== null ) {
  289. wfRunHooks( $hook, array( &$this, true ) );
  290. }
  291. ?>
  292. </ul>
  293. <?php
  294. } else { ?>
  295. <?php
  296. echo $content; /* Allow raw HTML block to be defined by extensions */
  297. }
  298. $this->renderAfterPortlet( $name );
  299. ?>
  300. </div>
  301. </div>
  302. <?php
  303. }
  304. /**
  305. * Render one or more navigations elements by name, automatically reveresed
  306. * when UI is in RTL mode
  307. *
  308. * @param $elements array
  309. */
  310. protected function renderNavigation( $elements ) {
  311. global $wgVectorUseSimpleSearch;
  312. // If only one element was given, wrap it in an array, allowing more
  313. // flexible arguments
  314. if ( !is_array( $elements ) ) {
  315. $elements = array( $elements );
  316. // If there's a series of elements, reverse them when in RTL mode
  317. } elseif ( $this->data['rtl'] ) {
  318. $elements = array_reverse( $elements );
  319. }
  320. // Render elements
  321. foreach ( $elements as $name => $element ) {
  322. switch ( $element ) {
  323. case 'NAMESPACES':
  324. ?>
  325. <div id="p-namespaces" role="navigation" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-namespaces-label">
  326. <h3 id="p-namespaces-label"><?php $this->msg( 'namespaces' ) ?></h3>
  327. <ul<?php $this->html( 'userlangattributes' ) ?>>
  328. <?php foreach ( $this->data['namespace_urls'] as $link ) { ?>
  329. <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>
  330. <?php } ?>
  331. </ul>
  332. </div>
  333. <?php
  334. break;
  335. case 'VARIANTS':
  336. ?>
  337. <div id="p-variants" role="navigation" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-variants-label">
  338. <h3 id="mw-vector-current-variant">
  339. <?php foreach ( $this->data['variant_urls'] as $link ) { ?>
  340. <?php if ( stripos( $link['attributes'], 'selected' ) !== false ) { ?>
  341. <?php echo htmlspecialchars( $link['text'] ) ?>
  342. <?php } ?>
  343. <?php } ?>
  344. </h3>
  345. <h3 id="p-variants-label"><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h3>
  346. <div class="menu">
  347. <ul>
  348. <?php foreach ( $this->data['variant_urls'] as $link ) { ?>
  349. <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>
  350. <?php } ?>
  351. </ul>
  352. </div>
  353. </div>
  354. <?php
  355. break;
  356. case 'VIEWS':
  357. ?>
  358. <div id="p-views" role="navigation" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-views-label">
  359. <h3 id="p-views-label"><?php $this->msg( 'views' ) ?></h3>
  360. <ul<?php $this->html( 'userlangattributes' ) ?>>
  361. <?php foreach ( $this->data['view_urls'] as $link ) { ?>
  362. <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
  363. // $link['text'] can be undefined - bug 27764
  364. if ( array_key_exists( 'text', $link ) ) {
  365. echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
  366. }
  367. ?></a></span></li>
  368. <?php } ?>
  369. </ul>
  370. </div>
  371. <?php
  372. break;
  373. case 'ACTIONS':
  374. ?>
  375. <div id="p-cactions" role="navigation" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-cactions-label">
  376. <h3 id="p-cactions-label"><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h3>
  377. <div class="menu">
  378. <ul<?php $this->html( 'userlangattributes' ) ?>>
  379. <?php foreach ( $this->data['action_urls'] as $link ) { ?>
  380. <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
  381. <?php } ?>
  382. </ul>
  383. </div>
  384. </div>
  385. <?php
  386. break;
  387. case 'PERSONAL':
  388. ?>
  389. <div id="p-personal" role="navigation" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-personal-label">
  390. <h3 id="p-personal-label"><?php $this->msg( 'personaltools' ) ?></h3>
  391. <ul<?php $this->html( 'userlangattributes' ) ?>>
  392. <?php
  393. $personalTools = $this->getPersonalTools();
  394. foreach ( $personalTools as $key => $item ) {
  395. echo $this->makeListItem( $key, $item );
  396. }
  397. ?>
  398. </ul>
  399. </div>
  400. <?php
  401. break;
  402. case 'SEARCH':
  403. ?>
  404. <div id="p-search" role="search">
  405. <h3<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
  406. <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
  407. <?php if ( $wgVectorUseSimpleSearch ) { ?>
  408. <div id="simpleSearch">
  409. <?php } else { ?>
  410. <div>
  411. <?php } ?>
  412. <?php
  413. echo $this->makeSearchInput( array( 'id' => 'searchInput' ) );
  414. echo Html::hidden( 'title', $this->get( 'searchtitle' ) );
  415. // We construct two buttons (for 'go' and 'fulltext' search modes), but only one will be
  416. // visible and actionable at a time (they are overlaid on top of each other in CSS).
  417. // * Browsers will use the 'fulltext' one by default (as it's the first in tree-order), which
  418. // is desirable when they are unable to show search suggestions (either due to being broken
  419. // or having JavaScript turned off).
  420. // * The mediawiki.searchSuggest module, after doing tests for the broken browsers, removes
  421. // the 'fulltext' button and handles 'fulltext' search itself; this will reveal the 'go'
  422. // button and cause it to be used.
  423. echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ) );
  424. echo $this->makeSearchButton( 'go', array( 'id' => 'searchButton', 'class' => 'searchButton' ) );
  425. ?>
  426. </div>
  427. </form>
  428. </div>
  429. <?php
  430. break;
  431. }
  432. }
  433. }
  434. }