Merge "Typography update to Vector skin"
[mediawiki.git] / skins / CologneBlue.php
blob7c2860eb7d607fa6ab7a4e5bcab7c1844f5fe09a
1 <?php
2 /**
3 * Cologne Blue: A nicer-looking alternative to Standard.
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.
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.
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
20 * @todo document
21 * @file
22 * @ingroup Skins
25 if ( !defined( 'MEDIAWIKI' ) ) {
26 die( -1 );
29 /**
30 * @todo document
31 * @ingroup Skins
33 class SkinCologneBlue extends SkinTemplate {
34 var $skinname = 'cologneblue', $stylename = 'cologneblue',
35 $template = 'CologneBlueTemplate';
36 var $useHeadElement = true;
38 /**
39 * @param $out OutputPage
41 function setupSkinUserCss( OutputPage $out ) {
42 parent::setupSkinUserCss( $out );
43 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
44 $out->addModuleStyles( 'skins.cologneblue' );
47 /**
48 * Override langlink formatting behavior not to uppercase the language names.
49 * See otherLanguages() in CologneBlueTemplate.
51 function formatLanguageName( $name ) {
52 return $name;
56 class CologneBlueTemplate extends BaseTemplate {
57 function execute() {
58 // Suppress warnings to prevent notices about missing indexes in $this->data
59 wfSuppressWarnings();
60 $this->html( 'headelement' );
61 echo $this->beforeContent();
62 $this->html( 'bodytext' );
63 echo "\n";
64 echo $this->afterContent();
65 $this->html( 'dataAfterContent' );
66 $this->printTrail();
67 echo "\n</body></html>";
68 wfRestoreWarnings();
71 /**
72 * Language/charset variant links for classic-style skins
73 * @return string
75 function variantLinks() {
76 $s = array();
78 $variants = $this->data['content_navigation']['variants'];
80 foreach ( $variants as $key => $link ) {
81 $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
84 return $this->getSkin()->getLanguage()->pipeList( $s );
87 function otherLanguages() {
88 global $wgHideInterlanguageLinks;
89 if ( $wgHideInterlanguageLinks ) {
90 return "";
93 $html = '';
95 // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
96 // not to capitalize the language names.
97 $language_urls = $this->data['language_urls'];
98 if ( !empty( $language_urls ) ) {
99 $s = array();
100 foreach ( $language_urls as $key => $data ) {
101 $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
104 $html = wfMessage( 'otherlanguages' )->text()
105 . wfMessage( 'colon-separator' )->text()
106 . $this->getSkin()->getLanguage()->pipeList( $s );
109 $html .= $this->renderAfterPortlet( 'lang' );
111 return $html;
115 * @param string $name
117 protected function renderAfterPortlet( $name ) {
118 $content = '';
119 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
121 $html = $content !== '' ? "<div class='after-portlet after-portlet-$name'>$content</div>" : '';
123 return $html;
126 function pageTitleLinks() {
127 $s = array();
128 $footlinks = $this->getFooterLinks();
130 foreach ( $footlinks['places'] as $item ) {
131 $s[] = $this->data[$item];
134 return $this->getSkin()->getLanguage()->pipeList( $s );
138 * Used in bottomLinks() to eliminate repetitive code.
140 * @param $key string Key to be passed to makeListItem()
141 * @param $navlink array Navlink suitable for processNavlinkForDocument()
142 * @param $message string Key of the message to use in place of standard text
144 * @return string
146 function processBottomLink( $key, $navlink, $message = null ) {
147 if ( !$navlink ) {
148 // Empty navlinks might be passed.
149 return null;
152 if ( $message ) {
153 $navlink['text'] = wfMessage( $message )->escaped();
156 return $this->makeListItem( $key, $this->processNavlinkForDocument( $navlink ), array( 'tag' => 'span' ) );
159 function bottomLinks() {
160 $toolbox = $this->getToolbox();
161 $content_nav = $this->data['content_navigation'];
163 $lines = array();
165 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
166 // First row. Regular actions.
167 $element = array();
169 $editLinkMessage = $this->getSkin()->getTitle()->exists() ? 'editthispage' : 'create-this-page';
170 $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
171 $element[] = $this->processBottomLink( 'viewsource', $content_nav['views']['viewsource'], 'viewsource' );
173 $element[] = $this->processBottomLink( 'watch', $content_nav['actions']['watch'], 'watchthispage' );
174 $element[] = $this->processBottomLink( 'unwatch', $content_nav['actions']['unwatch'], 'unwatchthispage' );
176 $element[] = $this->talkLink();
178 $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
179 $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
180 $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
181 $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
183 $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
184 $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
186 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
188 // Second row. Privileged actions.
189 $element = array();
191 $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
192 $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
194 $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
195 $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
197 $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
199 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
201 // Third row. Language links.
202 $lines[] = $this->otherLanguages();
205 return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
208 function talkLink() {
209 $title = $this->getSkin()->getTitle();
211 if ( $title->getNamespace() == NS_SPECIAL ) {
212 // No discussion links for special pages
213 return "";
216 $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
217 $companionNamespace = $companionTitle->getNamespace();
219 // TODO these messages are only be used by CologneBlue,
220 // kill and replace with something more sensibly named?
221 $nsToMessage = array(
222 NS_MAIN => 'articlepage',
223 NS_USER => 'userpage',
224 NS_PROJECT => 'projectpage',
225 NS_FILE => 'imagepage',
226 NS_MEDIAWIKI => 'mediawikipage',
227 NS_TEMPLATE => 'templatepage',
228 NS_HELP => 'viewhelppage',
229 NS_CATEGORY => 'categorypage',
230 NS_FILE => 'imagepage',
233 // Find out the message to use for link text. Use either the array above or,
234 // for non-talk pages, a generic "discuss this" message.
235 // Default is the same as for main namespace.
236 if ( isset( $nsToMessage[$companionNamespace] ) ) {
237 $message = $nsToMessage[$companionNamespace];
238 } else {
239 $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage';
242 // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones.
243 // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805)
244 $key = $companionTitle->getNamespaceKey( '' );
245 if ( $companionTitle->isTalkPage() ) {
246 $key = ( $key == 'main' ? 'talk' : $key . "_talk" );
249 // Use the regular navigational link, but replace its text. Everything else stays unmodified.
250 $namespacesLinks = $this->data['content_navigation']['namespaces'];
251 return $this->processBottomLink( $message, $namespacesLinks[$key], $message );
255 * Takes a navigational link generated by SkinTemplate in whichever way
256 * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids
257 * and removes the accesskeys. This is necessary to be able to use the same navlink twice,
258 * e.g. in sidebar and in footer.
260 * @param $navlink array Navigational link generated by SkinTemplate
261 * @param $idPrefix mixed Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'.
263 function processNavlinkForDocument( $navlink, $idPrefix = 'cb-' ) {
264 if ( $navlink['id'] ) {
265 $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
266 $navlink['tooltiponly'] = true; // but no accesskeys
268 // mangle or remove the id
269 if ( $idPrefix === false ) {
270 unset( $navlink['id'] );
271 } else {
272 $navlink['id'] = $idPrefix . $navlink['id'];
276 return $navlink;
280 * @return string
282 function beforeContent() {
283 ob_start();
285 <div id="content">
286 <div id="topbar">
287 <p id="sitetitle" role="banner">
288 <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
289 <?php echo wfMessage( 'sitetitle' )->escaped() ?>
290 </a>
291 </p>
292 <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
293 <div id="linkcollection" role="navigation">
294 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
295 <?php echo $this->getSkin()->getCategories() ?>
296 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
297 <?php if ( $this->data['newtalk'] ) { ?>
298 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
299 <?php } ?>
300 </div>
301 </div>
302 <div id="article" class="mw-body" role="main">
303 <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
304 <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
305 <?php } ?>
306 <h1 id="firstHeading" lang="<?php
307 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
308 $this->text( 'pageLanguage' );
309 ?>"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
310 <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
311 <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
312 <?php } ?>
313 <?php if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?>
314 <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
315 <?php } ?>
316 <?php if ( $this->getSkin()->subPageSubtitle() ) { ?>
317 <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
318 <?php } ?>
319 <?php
320 $s = ob_get_contents();
321 ob_end_clean();
323 return $s;
327 * @return string
329 function afterContent() {
330 ob_start();
332 </div>
333 <div id="footer">
334 <div id="footer-navigation" role="navigation">
335 <?php
336 // Page-related links
337 echo $this->bottomLinks();
338 echo "\n<br />";
340 // Footer and second searchbox
341 echo $this->getSkin()->getLanguage()->pipeList( array(
342 $this->getSkin()->mainPageLink(),
343 $this->getSkin()->aboutLink(),
344 $this->searchForm( 'footer' )
345 ) );
347 </div>
348 <div id="footer-info" role="contentinfo">
349 <?php
350 // Standard footer info
351 $footlinks = $this->getFooterLinks();
352 if ( $footlinks['info'] ) {
353 foreach ( $footlinks['info'] as $item ) {
354 echo $this->data[$item] . ' ';
358 </div>
359 </div>
360 </div>
361 <div id="mw-navigation">
362 <h2><?php echo wfMessage( 'navigation-heading' )->escaped() ?></h2>
363 <div id="toplinks" role="navigation">
364 <p id="syslinks"><?php echo $this->sysLinks() ?></p>
365 <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
366 </div>
367 <?php echo $this->quickBar() ?>
368 </div>
369 <?php
370 $s = ob_get_contents();
371 ob_end_clean();
373 return $s;
377 * @return string
379 function sysLinks() {
380 $s = array(
381 $this->getSkin()->mainPageLink(),
382 Linker::linkKnown(
383 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
384 wfMessage( 'about' )->text()
386 Linker::makeExternalLink(
387 Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ),
388 wfMessage( 'help' )->text(),
389 false
391 Linker::linkKnown(
392 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
393 wfMessage( 'faq' )->text()
397 $personalUrls = $this->getPersonalTools();
398 foreach ( array( 'logout', 'createaccount', 'login' ) as $key ) {
399 if ( $personalUrls[$key] ) {
400 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
404 return $this->getSkin()->getLanguage()->pipeList( $s );
408 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
410 * @param $bar sidebar data
411 * @return array modified sidebar data
413 function sidebarAdditions( $bar ) {
414 // "This page" and "Edit" menus
415 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
416 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
417 // We also don't use $...['variants'], these are displayed in the top menu.
418 $content_navigation = $this->data['content_navigation'];
419 $qbpageoptions = array_merge(
420 $content_navigation['namespaces'],
421 array(
422 'history' => $content_navigation['views']['history'],
423 'watch' => $content_navigation['actions']['watch'],
424 'unwatch' => $content_navigation['actions']['unwatch'],
427 $content_navigation['actions']['watch'] = null;
428 $content_navigation['actions']['unwatch'] = null;
429 $qbedit = array_merge(
430 array(
431 'edit' => $content_navigation['views']['edit'],
432 'addsection' => $content_navigation['views']['addsection'],
434 $content_navigation['actions']
437 // Personal tools ("My pages")
438 $qbmyoptions = $this->getPersonalTools();
439 foreach ( array( 'logout', 'createaccount', 'login', ) as $key ) {
440 $qbmyoptions[$key] = null;
443 // Use the closest reasonable name
444 $bar['cactions'] = $qbedit;
445 $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
446 $bar['personal'] = $qbmyoptions;
448 return $bar;
452 * Compute the sidebar
453 * @access private
455 * @return string
457 function quickBar() {
458 // Massage the sidebar. We want to:
459 // * place SEARCH at the beginning
460 // * add new portlets before TOOLBOX (or at the end, if it's missing)
461 // * remove LANGUAGES (langlinks are displayed elsewhere)
462 $orig_bar = $this->data['sidebar'];
463 $bar = array();
464 $hasToolbox = false;
466 // Always display search first
467 $bar['SEARCH'] = true;
468 // Copy everything except for langlinks, inserting new items before toolbox
469 foreach ( $orig_bar as $heading => $data ) {
470 if ( $heading == 'TOOLBOX' ) {
471 // Insert the stuff
472 $bar = $this->sidebarAdditions( $bar );
473 $hasToolbox = true;
476 if ( $heading != 'LANGUAGES' ) {
477 $bar[$heading] = $data;
480 // If toolbox is missing, add our items at the end
481 if ( !$hasToolbox ) {
482 $bar = $this->sidebarAdditions( $bar );
485 // Fill out special sidebar items with content
486 $orig_bar = $bar;
487 $bar = array();
488 foreach ( $orig_bar as $heading => $data ) {
489 if ( $heading == 'SEARCH' ) {
490 $bar['search'] = $this->searchForm( 'sidebar' );
491 } elseif ( $heading == 'TOOLBOX' ) {
492 $bar['tb'] = $this->getToolbox();
493 } else {
494 $bar[$heading] = $data;
498 // Output the sidebar
499 // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
500 $idToMessage = array(
501 'search' => 'qbfind',
502 'navigation' => 'qbbrowse',
503 'tb' => 'toolbox',
504 'cactions' => 'qbedit',
505 'personal' => 'qbmyoptions',
506 'pageoptions' => 'qbpageoptions',
509 $s = "<div id='quickbar'>\n";
511 foreach ( $bar as $heading => $data ) {
512 $portletId = Sanitizer::escapeId( "p-$heading" );
513 $headingMsg = wfMessage( $idToMessage[$heading] ? $idToMessage[$heading] : $heading );
514 $headingHTML = "<h3>" . ( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ) . "</h3>";
515 $listHTML = "";
517 if ( is_array( $data ) ) {
518 // $data is an array of links
519 foreach ( $data as $key => $link ) {
520 // Can be empty due to how the sidebar additions are done
521 if ( $link ) {
522 $listHTML .= $this->makeListItem( $key, $link );
525 if ( $listHTML ) {
526 $listHTML = "<ul>$listHTML</ul>";
528 } else {
529 // $data is a HTML <ul>-list string
530 $listHTML = $data;
533 if ( $listHTML ) {
534 $role = ( $heading == 'search' ) ? 'search' : 'navigation';
535 $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
538 $s .= $this->renderAfterPortlet( $heading );
541 $s .= "</div>\n";
542 return $s;
546 * @param $label string
547 * @return string
549 function searchForm( $which ) {
550 global $wgUseTwoButtonsSearchForm;
552 $search = $this->getSkin()->getRequest()->getText( 'search' );
553 $action = $this->data['searchaction'];
554 $s = "<form id=\"searchform-" . htmlspecialchars( $which ) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
555 if ( $which == 'footer' ) {
556 $s .= wfMessage( 'qbfind' )->text() . ": ";
559 $s .= $this->makeSearchInput( array( 'class' => 'mw-searchInput', 'type' => 'text', 'size' => '14' ) );
560 $s .= ( $which == 'footer' ? " " : "<br />" );
561 $s .= $this->makeSearchButton( 'go', array( 'class' => 'searchButton' ) );
563 if ( $wgUseTwoButtonsSearchForm ) {
564 $s .= $this->makeSearchButton( 'fulltext', array( 'class' => 'searchButton' ) );
565 } else {
566 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
569 $s .= '</form>';
571 return $s;