CologneBlue.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <?php
  2. /**
  3. * Cologne Blue: A nicer-looking alternative to Standard.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @todo document
  21. * @file
  22. * @ingroup Skins
  23. */
  24. if ( !defined( 'MEDIAWIKI' ) ) {
  25. die( -1 );
  26. }
  27. /**
  28. * @todo document
  29. * @ingroup Skins
  30. */
  31. class SkinCologneBlue extends SkinTemplate {
  32. var $skinname = 'cologneblue', $stylename = 'cologneblue',
  33. $template = 'CologneBlueTemplate';
  34. var $useHeadElement = true;
  35. /**
  36. * @param $out OutputPage
  37. */
  38. function setupSkinUserCss( OutputPage $out ) {
  39. parent::setupSkinUserCss( $out );
  40. $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
  41. $out->addModuleStyles( 'skins.cologneblue' );
  42. }
  43. /**
  44. * Override langlink formatting behavior not to uppercase the language names.
  45. * See otherLanguages() in CologneBlueTemplate.
  46. */
  47. function formatLanguageName( $name ) {
  48. return $name;
  49. }
  50. }
  51. class CologneBlueTemplate extends BaseTemplate {
  52. function execute() {
  53. // Suppress warnings to prevent notices about missing indexes in $this->data
  54. wfSuppressWarnings();
  55. $this->html( 'headelement' );
  56. echo $this->beforeContent();
  57. $this->html( 'bodytext' );
  58. echo "\n";
  59. echo $this->afterContent();
  60. $this->html( 'dataAfterContent' );
  61. $this->printTrail();
  62. echo "\n</body></html>";
  63. wfRestoreWarnings();
  64. }
  65. /**
  66. * Language/charset variant links for classic-style skins
  67. * @return string
  68. */
  69. function variantLinks() {
  70. $s = array();
  71. $variants = $this->data['content_navigation']['variants'];
  72. foreach ( $variants as $key => $link ) {
  73. $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
  74. }
  75. return $this->getSkin()->getLanguage()->pipeList( $s );
  76. }
  77. function otherLanguages() {
  78. global $wgHideInterlanguageLinks;
  79. if ( $wgHideInterlanguageLinks ) {
  80. return "";
  81. }
  82. $html = '';
  83. // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
  84. // not to capitalize the language names.
  85. $language_urls = $this->data['language_urls'];
  86. if ( !empty( $language_urls ) ) {
  87. $s = array();
  88. foreach ( $language_urls as $key => $data ) {
  89. $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
  90. }
  91. $html = wfMessage( 'otherlanguages' )->text()
  92. . wfMessage( 'colon-separator' )->text()
  93. . $this->getSkin()->getLanguage()->pipeList( $s );
  94. }
  95. $html .= $this->renderAfterPortlet( 'lang' );
  96. return $html;
  97. }
  98. /**
  99. * @param string $name
  100. */
  101. protected function renderAfterPortlet( $name ) {
  102. $content = '';
  103. wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
  104. $html = $content !== '' ? "<div class='after-portlet after-portlet-$name'>$content</div>" : '';
  105. return $html;
  106. }
  107. function pageTitleLinks() {
  108. $s = array();
  109. $footlinks = $this->getFooterLinks();
  110. foreach ( $footlinks['places'] as $item ) {
  111. $s[] = $this->data[$item];
  112. }
  113. return $this->getSkin()->getLanguage()->pipeList( $s );
  114. }
  115. /**
  116. * Used in bottomLinks() to eliminate repetitive code.
  117. *
  118. * @param $key string Key to be passed to makeListItem()
  119. * @param $navlink array Navlink suitable for processNavlinkForDocument()
  120. * @param $message string Key of the message to use in place of standard text
  121. *
  122. * @return string
  123. */
  124. function processBottomLink( $key, $navlink, $message = null ) {
  125. if ( !$navlink ) {
  126. // Empty navlinks might be passed.
  127. return null;
  128. }
  129. if ( $message ) {
  130. $navlink['text'] = wfMessage( $message )->escaped();
  131. }
  132. return $this->makeListItem( $key, $this->processNavlinkForDocument( $navlink ), array( 'tag' => 'span' ) );
  133. }
  134. function bottomLinks() {
  135. $toolbox = $this->getToolbox();
  136. $content_nav = $this->data['content_navigation'];
  137. $lines = array();
  138. if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
  139. // First row. Regular actions.
  140. $element = array();
  141. $editLinkMessage = $this->getSkin()->getTitle()->exists() ? 'editthispage' : 'create-this-page';
  142. $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
  143. $element[] = $this->processBottomLink( 'viewsource', $content_nav['views']['viewsource'], 'viewsource' );
  144. $element[] = $this->processBottomLink( 'watch', $content_nav['actions']['watch'], 'watchthispage' );
  145. $element[] = $this->processBottomLink( 'unwatch', $content_nav['actions']['unwatch'], 'unwatchthispage' );
  146. $element[] = $this->talkLink();
  147. $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
  148. $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
  149. $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
  150. $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
  151. $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
  152. $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
  153. $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
  154. // Second row. Privileged actions.
  155. $element = array();
  156. $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
  157. $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
  158. $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
  159. $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
  160. $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
  161. $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
  162. // Third row. Language links.
  163. $lines[] = $this->otherLanguages();
  164. }
  165. return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
  166. }
  167. function talkLink() {
  168. $title = $this->getSkin()->getTitle();
  169. if ( $title->getNamespace() == NS_SPECIAL ) {
  170. // No discussion links for special pages
  171. return "";
  172. }
  173. $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
  174. $companionNamespace = $companionTitle->getNamespace();
  175. // TODO these messages are only be used by CologneBlue,
  176. // kill and replace with something more sensibly named?
  177. $nsToMessage = array(
  178. NS_MAIN => 'articlepage',
  179. NS_USER => 'userpage',
  180. NS_PROJECT => 'projectpage',
  181. NS_FILE => 'imagepage',
  182. NS_MEDIAWIKI => 'mediawikipage',
  183. NS_TEMPLATE => 'templatepage',
  184. NS_HELP => 'viewhelppage',
  185. NS_CATEGORY => 'categorypage',
  186. NS_FILE => 'imagepage',
  187. );
  188. // Find out the message to use for link text. Use either the array above or,
  189. // for non-talk pages, a generic "discuss this" message.
  190. // Default is the same as for main namespace.
  191. if ( isset( $nsToMessage[$companionNamespace] ) ) {
  192. $message = $nsToMessage[$companionNamespace];
  193. } else {
  194. $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage';
  195. }
  196. // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones.
  197. // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805)
  198. $key = $companionTitle->getNamespaceKey( '' );
  199. if ( $companionTitle->isTalkPage() ) {
  200. $key = ( $key == 'main' ? 'talk' : $key . "_talk" );
  201. }
  202. // Use the regular navigational link, but replace its text. Everything else stays unmodified.
  203. $namespacesLinks = $this->data['content_navigation']['namespaces'];
  204. return $this->processBottomLink( $message, $namespacesLinks[$key], $message );
  205. }
  206. /**
  207. * Takes a navigational link generated by SkinTemplate in whichever way
  208. * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids
  209. * and removes the accesskeys. This is necessary to be able to use the same navlink twice,
  210. * e.g. in sidebar and in footer.
  211. *
  212. * @param $navlink array Navigational link generated by SkinTemplate
  213. * @param $idPrefix mixed Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'.
  214. */
  215. function processNavlinkForDocument( $navlink, $idPrefix = 'cb-' ) {
  216. if ( $navlink['id'] ) {
  217. $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
  218. $navlink['tooltiponly'] = true; // but no accesskeys
  219. // mangle or remove the id
  220. if ( $idPrefix === false ) {
  221. unset( $navlink['id'] );
  222. } else {
  223. $navlink['id'] = $idPrefix . $navlink['id'];
  224. }
  225. }
  226. return $navlink;
  227. }
  228. /**
  229. * @return string
  230. */
  231. function beforeContent() {
  232. ob_start();
  233. ?>
  234. <div id="content">
  235. <div id="topbar">
  236. <p id="sitetitle" role="banner">
  237. <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
  238. <?php echo wfMessage( 'sitetitle' )->escaped() ?>
  239. </a>
  240. </p>
  241. <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
  242. <div id="linkcollection" role="navigation">
  243. <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
  244. <?php echo $this->getSkin()->getCategories() ?>
  245. <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
  246. <?php if ( $this->data['newtalk'] ) { ?>
  247. <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
  248. <?php } ?>
  249. </div>
  250. </div>
  251. <div id="article" class="mw-body" role="main">
  252. <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
  253. <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
  254. <?php } ?>
  255. <h1 id="firstHeading" lang="<?php
  256. $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
  257. $this->text( 'pageLanguage' );
  258. ?>"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
  259. <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
  260. <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
  261. <?php } ?>
  262. <?php if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?>
  263. <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
  264. <?php } ?>
  265. <?php if ( $this->getSkin()->subPageSubtitle() ) { ?>
  266. <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
  267. <?php } ?>
  268. <?php
  269. $s = ob_get_contents();
  270. ob_end_clean();
  271. return $s;
  272. }
  273. /**
  274. * @return string
  275. */
  276. function afterContent() {
  277. ob_start();
  278. ?>
  279. </div>
  280. <div id="footer">
  281. <div id="footer-navigation" role="navigation">
  282. <?php
  283. // Page-related links
  284. echo $this->bottomLinks();
  285. echo "\n<br />";
  286. // Footer and second searchbox
  287. echo $this->getSkin()->getLanguage()->pipeList( array(
  288. $this->getSkin()->mainPageLink(),
  289. $this->getSkin()->aboutLink(),
  290. $this->searchForm( 'footer' )
  291. ) );
  292. ?>
  293. </div>
  294. <div id="footer-info" role="contentinfo">
  295. <?php
  296. // Standard footer info
  297. $footlinks = $this->getFooterLinks();
  298. if ( $footlinks['info'] ) {
  299. foreach ( $footlinks['info'] as $item ) {
  300. echo $this->data[$item] . ' ';
  301. }
  302. }
  303. ?>
  304. </div>
  305. </div>
  306. </div>
  307. <div id="mw-navigation">
  308. <h2><?php echo wfMessage( 'navigation-heading' )->escaped() ?></h2>
  309. <div id="toplinks" role="navigation">
  310. <p id="syslinks"><?php echo $this->sysLinks() ?></p>
  311. <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
  312. </div>
  313. <?php echo $this->quickBar() ?>
  314. </div>
  315. <?php
  316. $s = ob_get_contents();
  317. ob_end_clean();
  318. return $s;
  319. }
  320. /**
  321. * @return string
  322. */
  323. function sysLinks() {
  324. $s = array(
  325. $this->getSkin()->mainPageLink(),
  326. Linker::linkKnown(
  327. Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
  328. wfMessage( 'about' )->text()
  329. ),
  330. Linker::makeExternalLink(
  331. Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ),
  332. wfMessage( 'help' )->text(),
  333. false
  334. ),
  335. Linker::linkKnown(
  336. Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
  337. wfMessage( 'faq' )->text()
  338. ),
  339. );
  340. $personalUrls = $this->getPersonalTools();
  341. foreach ( array( 'logout', 'createaccount', 'login' ) as $key ) {
  342. if ( $personalUrls[$key] ) {
  343. $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
  344. }
  345. }
  346. return $this->getSkin()->getLanguage()->pipeList( $s );
  347. }
  348. /**
  349. * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
  350. *
  351. * @param $bar sidebar data
  352. * @return array modified sidebar data
  353. */
  354. function sidebarAdditions( $bar ) {
  355. // "This page" and "Edit" menus
  356. // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
  357. // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
  358. // We also don't use $...['variants'], these are displayed in the top menu.
  359. $content_navigation = $this->data['content_navigation'];
  360. $qbpageoptions = array_merge(
  361. $content_navigation['namespaces'],
  362. array(
  363. 'history' => $content_navigation['views']['history'],
  364. 'watch' => $content_navigation['actions']['watch'],
  365. 'unwatch' => $content_navigation['actions']['unwatch'],
  366. )
  367. );
  368. $content_navigation['actions']['watch'] = null;
  369. $content_navigation['actions']['unwatch'] = null;
  370. $qbedit = array_merge(
  371. array(
  372. 'edit' => $content_navigation['views']['edit'],
  373. 'addsection' => $content_navigation['views']['addsection'],
  374. ),
  375. $content_navigation['actions']
  376. );
  377. // Personal tools ("My pages")
  378. $qbmyoptions = $this->getPersonalTools();
  379. foreach ( array( 'logout', 'createaccount', 'login', ) as $key ) {
  380. $qbmyoptions[$key] = null;
  381. }
  382. // Use the closest reasonable name
  383. $bar['cactions'] = $qbedit;
  384. $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
  385. $bar['personal'] = $qbmyoptions;
  386. return $bar;
  387. }
  388. /**
  389. * Compute the sidebar
  390. * @access private
  391. *
  392. * @return string
  393. */
  394. function quickBar() {
  395. // Massage the sidebar. We want to:
  396. // * place SEARCH at the beginning
  397. // * add new portlets before TOOLBOX (or at the end, if it's missing)
  398. // * remove LANGUAGES (langlinks are displayed elsewhere)
  399. $orig_bar = $this->data['sidebar'];
  400. $bar = array();
  401. $hasToolbox = false;
  402. // Always display search first
  403. $bar['SEARCH'] = true;
  404. // Copy everything except for langlinks, inserting new items before toolbox
  405. foreach ( $orig_bar as $heading => $data ) {
  406. if ( $heading == 'TOOLBOX' ) {
  407. // Insert the stuff
  408. $bar = $this->sidebarAdditions( $bar );
  409. $hasToolbox = true;
  410. }
  411. if ( $heading != 'LANGUAGES' ) {
  412. $bar[$heading] = $data;
  413. }
  414. }
  415. // If toolbox is missing, add our items at the end
  416. if ( !$hasToolbox ) {
  417. $bar = $this->sidebarAdditions( $bar );
  418. }
  419. // Fill out special sidebar items with content
  420. $orig_bar = $bar;
  421. $bar = array();
  422. foreach ( $orig_bar as $heading => $data ) {
  423. if ( $heading == 'SEARCH' ) {
  424. $bar['search'] = $this->searchForm( 'sidebar' );
  425. } elseif ( $heading == 'TOOLBOX' ) {
  426. $bar['tb'] = $this->getToolbox();
  427. } else {
  428. $bar[$heading] = $data;
  429. }
  430. }
  431. // Output the sidebar
  432. // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
  433. $idToMessage = array(
  434. 'search' => 'qbfind',
  435. 'navigation' => 'qbbrowse',
  436. 'tb' => 'toolbox',
  437. 'cactions' => 'qbedit',
  438. 'personal' => 'qbmyoptions',
  439. 'pageoptions' => 'qbpageoptions',
  440. );
  441. $s = "<div id='quickbar'>\n";
  442. foreach ( $bar as $heading => $data ) {
  443. $portletId = Sanitizer::escapeId( "p-$heading" );
  444. $headingMsg = wfMessage( $idToMessage[$heading] ? $idToMessage[$heading] : $heading );
  445. $headingHTML = "<h3>" . ( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ) . "</h3>";
  446. $listHTML = "";
  447. if ( is_array( $data ) ) {
  448. // $data is an array of links
  449. foreach ( $data as $key => $link ) {
  450. // Can be empty due to how the sidebar additions are done
  451. if ( $link ) {
  452. $listHTML .= $this->makeListItem( $key, $link );
  453. }
  454. }
  455. if ( $listHTML ) {
  456. $listHTML = "<ul>$listHTML</ul>";
  457. }
  458. } else {
  459. // $data is a HTML <ul>-list string
  460. $listHTML = $data;
  461. }
  462. if ( $listHTML ) {
  463. $role = ( $heading == 'search' ) ? 'search' : 'navigation';
  464. $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
  465. }
  466. $s .= $this->renderAfterPortlet( $heading );
  467. }
  468. $s .= "</div>\n";
  469. return $s;
  470. }
  471. /**
  472. * @param $label string
  473. * @return string
  474. */
  475. function searchForm( $which ) {
  476. global $wgUseTwoButtonsSearchForm;
  477. $search = $this->getSkin()->getRequest()->getText( 'search' );
  478. $action = $this->data['searchaction'];
  479. $s = "<form id=\"searchform-" . htmlspecialchars( $which ) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
  480. if ( $which == 'footer' ) {
  481. $s .= wfMessage( 'qbfind' )->text() . ": ";
  482. }
  483. $s .= $this->makeSearchInput( array( 'class' => 'mw-searchInput', 'type' => 'text', 'size' => '14' ) );
  484. $s .= ( $which == 'footer' ? " " : "<br />" );
  485. $s .= $this->makeSearchButton( 'go', array( 'class' => 'searchButton' ) );
  486. if ( $wgUseTwoButtonsSearchForm ) {
  487. $s .= $this->makeSearchButton( 'fulltext', array( 'class' => 'searchButton' ) );
  488. } else {
  489. $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
  490. }
  491. $s .= '</form>';
  492. return $s;
  493. }
  494. }