MonoBook.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <?php
  2. /**
  3. * MonoBook nouveau.
  4. *
  5. * Translated from gwicke's previous TAL template version to remove
  6. * dependency on PHPTAL.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. * http://www.gnu.org/copyleft/gpl.html
  22. *
  23. * @todo document
  24. * @file
  25. * @ingroup Skins
  26. */
  27. if ( !defined( 'MEDIAWIKI' ) ) {
  28. die( -1 );
  29. }
  30. /**
  31. * Inherit main code from SkinTemplate, set the CSS and template filter.
  32. * @todo document
  33. * @ingroup Skins
  34. */
  35. class SkinMonoBook extends SkinTemplate {
  36. /** Using monobook. */
  37. var $skinname = 'monobook', $stylename = 'monobook',
  38. $template = 'MonoBookTemplate', $useHeadElement = true;
  39. /**
  40. * @param $out OutputPage
  41. */
  42. function setupSkinUserCss( OutputPage $out ) {
  43. parent::setupSkinUserCss( $out );
  44. $out->addModuleStyles( array( 'mediawiki.skinning.interface', 'skins.monobook.styles' ) );
  45. // TODO: Migrate all of these
  46. $out->addStyle( 'monobook/IE60Fixes.css', 'screen', 'IE 6' );
  47. $out->addStyle( 'monobook/IE70Fixes.css', 'screen', 'IE 7' );
  48. }
  49. }
  50. /**
  51. * @todo document
  52. * @ingroup Skins
  53. */
  54. class MonoBookTemplate extends BaseTemplate {
  55. /**
  56. * Template filter callback for MonoBook skin.
  57. * Takes an associative array of data set from a SkinTemplate-based
  58. * class, and a wrapper for MediaWiki's localization database, and
  59. * outputs a formatted page.
  60. *
  61. * @access private
  62. */
  63. function execute() {
  64. // Suppress warnings to prevent notices about missing indexes in $this->data
  65. wfSuppressWarnings();
  66. $this->html( 'headelement' );
  67. ?><div id="globalWrapper">
  68. <div id="column-content"><div id="content" class="mw-body-primary" role="main">
  69. <a id="top"></a>
  70. <?php if ( $this->data['sitenotice'] ) { ?><div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div><?php } ?>
  71. <h1 id="firstHeading" class="firstHeading" lang="<?php
  72. $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
  73. $this->text( 'pageLanguage' );
  74. ?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
  75. <div id="bodyContent" class="mw-body">
  76. <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
  77. <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
  78. <?php if ( $this->data['undelete'] ) { ?>
  79. <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
  80. <?php } ?><?php if ( $this->data['newtalk'] ) { ?>
  81. <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
  82. <?php } ?>
  83. <div id="jump-to-nav" class="mw-jump"><?php $this->msg( 'jumpto' ) ?> <a href="#column-one"><?php $this->msg( 'jumptonavigation' ) ?></a><?php $this->msg( 'comma-separator' ) ?><a href="#searchInput"><?php $this->msg( 'jumptosearch' ) ?></a></div>
  84. <!-- start content -->
  85. <?php $this->html( 'bodytext' ) ?>
  86. <?php if ( $this->data['catlinks'] ) { $this->html( 'catlinks' ); } ?>
  87. <!-- end content -->
  88. <?php if ( $this->data['dataAfterContent'] ) { $this->html( 'dataAfterContent' ); } ?>
  89. <div class="visualClear"></div>
  90. </div>
  91. </div></div>
  92. <div id="column-one"<?php $this->html( 'userlangattributes' ) ?>>
  93. <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
  94. <?php $this->cactions(); ?>
  95. <div class="portlet" id="p-personal" role="navigation">
  96. <h3><?php $this->msg( 'personaltools' ) ?></h3>
  97. <div class="pBody">
  98. <ul<?php $this->html( 'userlangattributes' ) ?>>
  99. <?php foreach ( $this->getPersonalTools() as $key => $item ) { ?>
  100. <?php echo $this->makeListItem( $key, $item ); ?>
  101. <?php } ?>
  102. </ul>
  103. </div>
  104. </div>
  105. <div class="portlet" id="p-logo" role="banner">
  106. <?php
  107. echo Html::element( 'a', array(
  108. 'href' => $this->data['nav_urls']['mainpage']['href'],
  109. 'style' => "background-image: url({$this->data['logopath']});" )
  110. + Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) ); ?>
  111. </div>
  112. <?php
  113. $this->renderPortals( $this->data['sidebar'] );
  114. ?>
  115. </div><!-- end of the left (by default at least) column -->
  116. <div class="visualClear"></div>
  117. <?php
  118. $validFooterIcons = $this->getFooterIcons( "icononly" );
  119. $validFooterLinks = $this->getFooterLinks( "flat" ); // Additional footer links
  120. if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) { ?>
  121. <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
  122. <?php
  123. $footerEnd = '</div>';
  124. } else {
  125. $footerEnd = '';
  126. }
  127. foreach ( $validFooterIcons as $blockName => $footerIcons ) { ?>
  128. <div id="f-<?php echo htmlspecialchars( $blockName ); ?>ico">
  129. <?php foreach ( $footerIcons as $icon ) { ?>
  130. <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
  131. <?php }
  132. ?>
  133. </div>
  134. <?php }
  135. if ( count( $validFooterLinks ) > 0 ) {
  136. ?> <ul id="f-list">
  137. <?php
  138. foreach ( $validFooterLinks as $aLink ) { ?>
  139. <li id="<?php echo $aLink ?>"><?php $this->html( $aLink ) ?></li>
  140. <?php
  141. }
  142. ?>
  143. </ul>
  144. <?php }
  145. echo $footerEnd;
  146. ?>
  147. </div>
  148. <?php
  149. $this->printTrail();
  150. echo Html::closeElement( 'body' );
  151. echo Html::closeElement( 'html' );
  152. wfRestoreWarnings();
  153. } // end of execute() method
  154. /*************************************************************************************************/
  155. /**
  156. * @param $sidebar array
  157. */
  158. protected function renderPortals( $sidebar ) {
  159. if ( !isset( $sidebar['SEARCH'] ) ) {
  160. $sidebar['SEARCH'] = true;
  161. }
  162. if ( !isset( $sidebar['TOOLBOX'] ) ) {
  163. $sidebar['TOOLBOX'] = true;
  164. }
  165. if ( !isset( $sidebar['LANGUAGES'] ) ) {
  166. $sidebar['LANGUAGES'] = true;
  167. }
  168. foreach ( $sidebar as $boxName => $content ) {
  169. if ( $content === false ) {
  170. continue;
  171. }
  172. if ( $boxName == 'SEARCH' ) {
  173. $this->searchBox();
  174. } elseif ( $boxName == 'TOOLBOX' ) {
  175. $this->toolbox();
  176. } elseif ( $boxName == 'LANGUAGES' ) {
  177. $this->languageBox();
  178. } else {
  179. $this->customBox( $boxName, $content );
  180. }
  181. }
  182. }
  183. function searchBox() {
  184. global $wgUseTwoButtonsSearchForm;
  185. ?>
  186. <div id="p-search" class="portlet" role="search">
  187. <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
  188. <div id="searchBody" class="pBody">
  189. <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
  190. <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
  191. <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ); ?>
  192. <?php echo $this->makeSearchButton( "go", array( "id" => "searchGoButton", "class" => "searchButton" ) );
  193. if ( $wgUseTwoButtonsSearchForm ) { ?>&#160;
  194. <?php echo $this->makeSearchButton( "fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" ) );
  195. } else { ?>
  196. <div><a href="<?php $this->text( 'searchaction' ) ?>" rel="search"><?php $this->msg( 'powersearch-legend' ) ?></a></div><?php
  197. } ?>
  198. </form>
  199. <?php $this->renderAfterPortlet( 'search' ); ?>
  200. </div>
  201. </div>
  202. <?php
  203. }
  204. /**
  205. * Prints the cactions bar.
  206. * Shared between MonoBook and Modern
  207. */
  208. function cactions() {
  209. ?>
  210. <div id="p-cactions" class="portlet" role="navigation">
  211. <h3><?php $this->msg( 'views' ) ?></h3>
  212. <div class="pBody">
  213. <ul><?php
  214. foreach ( $this->data['content_actions'] as $key => $tab ) {
  215. echo '
  216. ' . $this->makeListItem( $key, $tab );
  217. } ?>
  218. </ul>
  219. <?php $this->renderAfterPortlet( 'cactions' ); ?>
  220. </div>
  221. </div>
  222. <?php
  223. }
  224. /*************************************************************************************************/
  225. function toolbox() {
  226. ?>
  227. <div class="portlet" id="p-tb" role="navigation">
  228. <h3><?php $this->msg( 'toolbox' ) ?></h3>
  229. <div class="pBody">
  230. <ul>
  231. <?php
  232. foreach ( $this->getToolbox() as $key => $tbitem ) { ?>
  233. <?php echo $this->makeListItem( $key, $tbitem ); ?>
  234. <?php
  235. }
  236. wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
  237. wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
  238. ?>
  239. </ul>
  240. <?php $this->renderAfterPortlet( 'tb' ); ?>
  241. </div>
  242. </div>
  243. <?php
  244. }
  245. /*************************************************************************************************/
  246. function languageBox() {
  247. if ( $this->data['language_urls'] !== false ) {
  248. ?>
  249. <div id="p-lang" class="portlet" role="navigation">
  250. <h3<?php $this->html( 'userlangattributes' ) ?>><?php $this->msg( 'otherlanguages' ) ?></h3>
  251. <div class="pBody">
  252. <ul>
  253. <?php foreach ( $this->data['language_urls'] as $key => $langlink ) { ?>
  254. <?php echo $this->makeListItem( $key, $langlink ); ?>
  255. <?php } ?>
  256. </ul>
  257. <?php $this->renderAfterPortlet( 'lang' ); ?>
  258. </div>
  259. </div>
  260. <?php
  261. }
  262. }
  263. /*************************************************************************************************/
  264. /**
  265. * @param $bar string
  266. * @param $cont array|string
  267. */
  268. function customBox( $bar, $cont ) {
  269. $portletAttribs = array( 'class' => 'generated-sidebar portlet', 'id' => Sanitizer::escapeId( "p-$bar" ), 'role' => 'navigation' );
  270. $tooltip = Linker::titleAttrib( "p-$bar" );
  271. if ( $tooltip !== false ) {
  272. $portletAttribs['title'] = $tooltip;
  273. }
  274. echo ' ' . Html::openElement( 'div', $portletAttribs );
  275. $msgObj = wfMessage( $bar );
  276. ?>
  277. <h3><?php echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $bar ); ?></h3>
  278. <div class='pBody'>
  279. <?php if ( is_array( $cont ) ) { ?>
  280. <ul>
  281. <?php foreach ( $cont as $key => $val ) { ?>
  282. <?php echo $this->makeListItem( $key, $val ); ?>
  283. <?php } ?>
  284. </ul>
  285. <?php } else {
  286. # allow raw HTML block to be defined by extensions
  287. print $cont;
  288. }
  289. $this->renderAfterPortlet( $bar );
  290. ?>
  291. </div>
  292. </div>
  293. <?php
  294. }
  295. } // end of class