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
25 if ( !defined( 'MEDIAWIKI' ) ) {
33 class SkinCologneBlue
extends SkinTemplate
{
34 var $skinname = 'cologneblue', $stylename = 'cologneblue',
35 $template = 'CologneBlueTemplate';
36 var $useHeadElement = true;
39 * @param OutputPage $out
41 function setupSkinUserCss( OutputPage
$out ) {
42 parent
::setupSkinUserCss( $out );
43 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
44 $out->addModuleStyles( 'skins.cologneblue' );
48 * Override langlink formatting behavior not to uppercase the language names.
49 * See otherLanguages() in CologneBlueTemplate.
53 function formatLanguageName( $name ) {
58 class CologneBlueTemplate
extends BaseTemplate
{
60 // Suppress warnings to prevent notices about missing indexes in $this->data
62 $this->html( 'headelement' );
63 echo $this->beforeContent();
64 $this->html( 'bodytext' );
66 echo $this->afterContent();
67 $this->html( 'dataAfterContent' );
69 echo "\n</body></html>";
74 * Language/charset variant links for classic-style skins
77 function variantLinks() {
80 $variants = $this->data
['content_navigation']['variants'];
82 foreach ( $variants as $key => $link ) {
83 $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
86 return $this->getSkin()->getLanguage()->pipeList( $s );
89 function otherLanguages() {
90 global $wgHideInterlanguageLinks;
91 if ( $wgHideInterlanguageLinks ) {
97 // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
98 // not to capitalize the language names.
99 $language_urls = $this->data
['language_urls'];
100 if ( !empty( $language_urls ) ) {
102 foreach ( $language_urls as $key => $data ) {
103 $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
106 $html = wfMessage( 'otherlanguages' )->text()
107 . wfMessage( 'colon-separator' )->text()
108 . $this->getSkin()->getLanguage()->pipeList( $s );
111 $html .= $this->renderAfterPortlet( 'lang' );
117 * @param string $name
119 protected function renderAfterPortlet( $name ) {
121 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
123 $html = $content !== '' ?
"<div class='after-portlet after-portlet-$name'>$content</div>" : '';
128 function pageTitleLinks() {
130 $footlinks = $this->getFooterLinks();
132 foreach ( $footlinks['places'] as $item ) {
133 $s[] = $this->data
[$item];
136 return $this->getSkin()->getLanguage()->pipeList( $s );
140 * Used in bottomLinks() to eliminate repetitive code.
142 * @param string $key Key to be passed to makeListItem()
143 * @param array $navlink Navlink suitable for processNavlinkForDocument()
144 * @param string $message Key of the message to use in place of standard text
148 function processBottomLink( $key, $navlink, $message = null ) {
150 // Empty navlinks might be passed.
155 $navlink['text'] = wfMessage( $message )->escaped();
158 return $this->makeListItem( $key, $this->processNavlinkForDocument( $navlink ), array( 'tag' => 'span' ) );
161 function bottomLinks() {
162 $toolbox = $this->getToolbox();
163 $content_nav = $this->data
['content_navigation'];
167 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
168 // First row. Regular actions.
171 $editLinkMessage = $this->getSkin()->getTitle()->exists() ?
'editthispage' : 'create-this-page';
172 $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
173 $element[] = $this->processBottomLink( 'viewsource', $content_nav['views']['viewsource'], 'viewsource' );
175 $element[] = $this->processBottomLink( 'watch', $content_nav['actions']['watch'], 'watchthispage' );
176 $element[] = $this->processBottomLink( 'unwatch', $content_nav['actions']['unwatch'], 'unwatchthispage' );
178 $element[] = $this->talkLink();
180 $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
181 $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
182 $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
183 $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
185 $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
186 $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
188 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
190 // Second row. Privileged actions.
193 $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
194 $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
196 $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
197 $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
199 $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
201 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
203 // Third row. Language links.
204 $lines[] = $this->otherLanguages();
207 return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
210 function talkLink() {
211 $title = $this->getSkin()->getTitle();
213 if ( $title->getNamespace() == NS_SPECIAL
) {
214 // No discussion links for special pages
218 $companionTitle = $title->isTalkPage() ?
$title->getSubjectPage() : $title->getTalkPage();
219 $companionNamespace = $companionTitle->getNamespace();
221 // TODO these messages are only be used by CologneBlue,
222 // kill and replace with something more sensibly named?
223 $nsToMessage = array(
224 NS_MAIN
=> 'articlepage',
225 NS_USER
=> 'userpage',
226 NS_PROJECT
=> 'projectpage',
227 NS_FILE
=> 'imagepage',
228 NS_MEDIAWIKI
=> 'mediawikipage',
229 NS_TEMPLATE
=> 'templatepage',
230 NS_HELP
=> 'viewhelppage',
231 NS_CATEGORY
=> 'categorypage',
232 NS_FILE
=> 'imagepage',
235 // Find out the message to use for link text. Use either the array above or,
236 // for non-talk pages, a generic "discuss this" message.
237 // Default is the same as for main namespace.
238 if ( isset( $nsToMessage[$companionNamespace] ) ) {
239 $message = $nsToMessage[$companionNamespace];
241 $message = $companionTitle->isTalkPage() ?
'talkpage' : 'articlepage';
244 // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones.
245 // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805)
246 $key = $companionTitle->getNamespaceKey( '' );
247 if ( $companionTitle->isTalkPage() ) {
248 $key = ( $key == 'main' ?
'talk' : $key . "_talk" );
251 // Use the regular navigational link, but replace its text. Everything else stays unmodified.
252 $namespacesLinks = $this->data
['content_navigation']['namespaces'];
253 return $this->processBottomLink( $message, $namespacesLinks[$key], $message );
257 * Takes a navigational link generated by SkinTemplate in whichever way
258 * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids
259 * and removes the accesskeys. This is necessary to be able to use the same navlink twice,
260 * e.g. in sidebar and in footer.
262 * @param array $navlink Navigational link generated by SkinTemplate
263 * @param mixed $idPrefix Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'.
265 function processNavlinkForDocument( $navlink, $idPrefix = 'cb-' ) {
266 if ( $navlink['id'] ) {
267 $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
268 $navlink['tooltiponly'] = true; // but no accesskeys
270 // mangle or remove the id
271 if ( $idPrefix === false ) {
272 unset( $navlink['id'] );
274 $navlink['id'] = $idPrefix . $navlink['id'];
284 function beforeContent() {
289 <p id
="sitetitle" role
="banner">
290 <a href
="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
291 <?php
echo wfMessage( 'sitetitle' )->escaped() ?
>
294 <p id
="sitesub"><?php
echo wfMessage( 'sitesubtitle' )->escaped() ?
></p
>
295 <div id
="linkcollection" role
="navigation">
296 <div id
="langlinks"><?php
echo str_replace( '<br />', '', $this->otherLanguages() ) ?
></div
>
297 <?php
echo $this->getSkin()->getCategories() ?
>
298 <div id
="titlelinks"><?php
echo $this->pageTitleLinks() ?
></div
>
299 <?php
if ( $this->data
['newtalk'] ) { ?
>
300 <div
class="usermessage"><strong
><?php
echo $this->data
['newtalk'] ?
></strong
></div
>
304 <div id
="article" class="mw-body" role
="main">
305 <?php
if ( $this->getSkin()->getSiteNotice() ) { ?
>
306 <div id
="siteNotice"><?php
echo $this->getSkin()->getSiteNotice() ?
></div
>
308 <h1 id
="firstHeading" lang
="<?php
309 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
310 $this->text( 'pageLanguage' );
311 ?>"><span dir
="auto"><?php
echo $this->data
['title'] ?
></span
></h1
>
312 <?php
if ( $this->translator
->translate( 'tagline' ) ) { ?
>
313 <p
class="tagline"><?php
echo htmlspecialchars( $this->translator
->translate( 'tagline' ) ) ?
></p
>
315 <?php
if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?
>
316 <p
class="subtitle"><?php
echo $this->getSkin()->getOutput()->getSubtitle() ?
></p
>
318 <?php
if ( $this->getSkin()->subPageSubtitle() ) { ?
>
319 <p
class="subpages"><?php
echo $this->getSkin()->subPageSubtitle() ?
></p
>
322 $s = ob_get_contents();
331 function afterContent() {
336 <div id
="footer-navigation" role
="navigation">
338 // Page-related links
339 echo $this->bottomLinks();
342 // Footer and second searchbox
343 echo $this->getSkin()->getLanguage()->pipeList( array(
344 $this->getSkin()->mainPageLink(),
345 $this->getSkin()->aboutLink(),
346 $this->searchForm( 'footer' )
350 <div id
="footer-info" role
="contentinfo">
352 // Standard footer info
353 $footlinks = $this->getFooterLinks();
354 if ( $footlinks['info'] ) {
355 foreach ( $footlinks['info'] as $item ) {
356 echo $this->data
[$item] . ' ';
363 <div id
="mw-navigation">
364 <h2
><?php
echo wfMessage( 'navigation-heading' )->escaped() ?
></h2
>
365 <div id
="toplinks" role
="navigation">
366 <p id
="syslinks"><?php
echo $this->sysLinks() ?
></p
>
367 <p id
="variantlinks"><?php
echo $this->variantLinks() ?
></p
>
369 <?php
echo $this->quickBar() ?
>
372 $s = ob_get_contents();
381 function sysLinks() {
383 $this->getSkin()->mainPageLink(),
385 Title
::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
386 wfMessage( 'about' )->text()
388 Linker
::makeExternalLink(
389 Skin
::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ),
390 wfMessage( 'help' )->text(),
394 Title
::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
395 wfMessage( 'faq' )->text()
399 $personalUrls = $this->getPersonalTools();
400 foreach ( array( 'logout', 'createaccount', 'login' ) as $key ) {
401 if ( $personalUrls[$key] ) {
402 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
406 return $this->getSkin()->getLanguage()->pipeList( $s );
410 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
412 * @param array $bar Sidebar data
413 * @return array Modified sidebar data
415 function sidebarAdditions( $bar ) {
416 // "This page" and "Edit" menus
417 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
418 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
419 // We also don't use $...['variants'], these are displayed in the top menu.
420 $content_navigation = $this->data
['content_navigation'];
421 $qbpageoptions = array_merge(
422 $content_navigation['namespaces'],
424 'history' => $content_navigation['views']['history'],
425 'watch' => $content_navigation['actions']['watch'],
426 'unwatch' => $content_navigation['actions']['unwatch'],
429 $content_navigation['actions']['watch'] = null;
430 $content_navigation['actions']['unwatch'] = null;
431 $qbedit = array_merge(
433 'edit' => $content_navigation['views']['edit'],
434 'addsection' => $content_navigation['views']['addsection'],
436 $content_navigation['actions']
439 // Personal tools ("My pages")
440 $qbmyoptions = $this->getPersonalTools();
441 foreach ( array( 'logout', 'createaccount', 'login', ) as $key ) {
442 $qbmyoptions[$key] = null;
445 // Use the closest reasonable name
446 $bar['cactions'] = $qbedit;
447 $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
448 $bar['personal'] = $qbmyoptions;
454 * Compute the sidebar
459 function quickBar() {
460 // Massage the sidebar. We want to:
461 // * place SEARCH at the beginning
462 // * add new portlets before TOOLBOX (or at the end, if it's missing)
463 // * remove LANGUAGES (langlinks are displayed elsewhere)
464 $orig_bar = $this->data
['sidebar'];
468 // Always display search first
469 $bar['SEARCH'] = true;
470 // Copy everything except for langlinks, inserting new items before toolbox
471 foreach ( $orig_bar as $heading => $data ) {
472 if ( $heading == 'TOOLBOX' ) {
474 $bar = $this->sidebarAdditions( $bar );
478 if ( $heading != 'LANGUAGES' ) {
479 $bar[$heading] = $data;
482 // If toolbox is missing, add our items at the end
483 if ( !$hasToolbox ) {
484 $bar = $this->sidebarAdditions( $bar );
487 // Fill out special sidebar items with content
490 foreach ( $orig_bar as $heading => $data ) {
491 if ( $heading == 'SEARCH' ) {
492 $bar['search'] = $this->searchForm( 'sidebar' );
493 } elseif ( $heading == 'TOOLBOX' ) {
494 $bar['tb'] = $this->getToolbox();
496 $bar[$heading] = $data;
500 // Output the sidebar
501 // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
502 $idToMessage = array(
503 'search' => 'qbfind',
504 'navigation' => 'qbbrowse',
506 'cactions' => 'qbedit',
507 'personal' => 'qbmyoptions',
508 'pageoptions' => 'qbpageoptions',
511 $s = "<div id='quickbar'>\n";
513 foreach ( $bar as $heading => $data ) {
514 $portletId = Sanitizer
::escapeId( "p-$heading" );
515 $headingMsg = wfMessage( $idToMessage[$heading] ?
$idToMessage[$heading] : $heading );
516 $headingHTML = "<h3>" . ( $headingMsg->exists() ?
$headingMsg->escaped() : htmlspecialchars( $heading ) ) . "</h3>";
519 if ( is_array( $data ) ) {
520 // $data is an array of links
521 foreach ( $data as $key => $link ) {
522 // Can be empty due to how the sidebar additions are done
524 $listHTML .= $this->makeListItem( $key, $link );
528 $listHTML = "<ul>$listHTML</ul>";
531 // $data is a HTML <ul>-list string
536 $role = ( $heading == 'search' ) ?
'search' : 'navigation';
537 $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
540 $s .= $this->renderAfterPortlet( $heading );
548 * @param string $label
551 function searchForm( $which ) {
552 global $wgUseTwoButtonsSearchForm;
554 $search = $this->getSkin()->getRequest()->getText( 'search' );
555 $action = $this->data
['searchaction'];
556 $s = "<form id=\"searchform-" . htmlspecialchars( $which ) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
557 if ( $which == 'footer' ) {
558 $s .= wfMessage( 'qbfind' )->text() . ": ";
561 $s .= $this->makeSearchInput( array( 'class' => 'mw-searchInput', 'type' => 'text', 'size' => '14' ) );
562 $s .= ( $which == 'footer' ?
" " : "<br />" );
563 $s .= $this->makeSearchButton( 'go', array( 'class' => 'searchButton' ) );
565 if ( $wgUseTwoButtonsSearchForm ) {
566 $s .= $this->makeSearchButton( 'fulltext', array( 'class' => 'searchButton' ) );
568 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";