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 $out OutputPage
41 function setupSkinUserCss( OutputPage
$out ){
42 $out->addModuleStyles( 'mediawiki.legacy.shared' );
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.
51 function formatLanguageName( $name ) {
56 class CologneBlueTemplate
extends BaseTemplate
{
58 // Suppress warnings to prevent notices about missing indexes in $this->data
60 $this->html( 'headelement' );
61 echo $this->beforeContent();
62 $this->html( 'bodytext' );
64 echo $this->afterContent();
65 $this->html( 'dataAfterContent' );
67 echo "\n</body></html>";
72 * 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 );
90 function otherLanguages() {
91 global $wgHideInterlanguageLinks;
92 if ( $wgHideInterlanguageLinks ) {
96 // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
97 // not to capitalize the language names.
98 $language_urls = $this->data
['language_urls'];
99 if ( empty( $language_urls ) ) {
104 foreach ( $language_urls as $key => $data ) {
105 $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
108 return wfMessage( 'otherlanguages' )->text()
109 . wfMessage( 'colon-separator' )->text()
110 . $this->getSkin()->getLanguage()->pipeList( $s );
114 function pageTitleLinks() {
116 $footlinks = $this->getFooterLinks();
118 foreach ( $footlinks['places'] as $item ) {
119 $s[] = $this->data
[$item];
122 return $this->getSkin()->getLanguage()->pipeList( $s );
126 * Used in bottomLinks() to eliminate repetitive code.
128 * @param $key string Key to be passed to makeListItem()
129 * @param $navlink array Navlink suitable for processNavlinkForDocument()
130 * @param $message string Key of the message to use in place of standard text
135 function processBottomLink( $key, $navlink, $message=null ) {
137 // Empty navlinks might be passed.
142 $navlink['text'] = wfMessage( $message )->escaped();
145 return $this->makeListItem( $key, $this->processNavlinkForDocument( $navlink ), array( 'tag' => 'span' ) );
149 function bottomLinks() {
150 $toolbox = $this->getToolbox();
151 $content_nav = $this->data
['content_navigation'];
155 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
156 // First row. Regular actions.
159 $editLinkMessage = $this->getSkin()->getTitle()->exists() ?
'editthispage' : 'create-this-page';
160 $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
161 $element[] = $this->processBottomLink( 'viewsource', $content_nav['views']['viewsource'], 'viewsource' );
163 $element[] = $this->processBottomLink( 'watch', $content_nav['actions']['watch'], 'watchthispage' );
164 $element[] = $this->processBottomLink( 'unwatch', $content_nav['actions']['unwatch'], 'unwatchthispage' );
166 $element[] = $this->talkLink();
168 $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
169 $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
170 $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
171 $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
173 $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
174 $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
176 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
179 // Second row. Privileged actions.
182 $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
183 $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
185 $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
186 $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
188 $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
190 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
193 // Third row. Language links.
194 $lines[] = $this->otherLanguages();
197 return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
201 function talkLink() {
202 $title = $this->getSkin()->getTitle();
204 if ( $title->getNamespace() == NS_SPECIAL
) {
205 // No discussion links for special pages
209 $companionTitle = $title->isTalkPage() ?
$title->getSubjectPage() : $title->getTalkPage();
210 $companionNamespace = $companionTitle->getNamespace();
212 // TODO these messages appear to only be used by CologneBlue and legacy skins,
213 // kill and replace with something more sensibly named?
214 $nsToMessage = array(
215 NS_MAIN
=> 'articlepage',
216 NS_USER
=> 'userpage',
217 NS_PROJECT
=> 'projectpage',
218 NS_FILE
=> 'imagepage',
219 NS_MEDIAWIKI
=> 'mediawikipage',
220 NS_TEMPLATE
=> 'templatepage',
221 NS_HELP
=> 'viewhelppage',
222 NS_CATEGORY
=> 'categorypage',
223 NS_FILE
=> 'imagepage',
226 // Find out the message to use for link text. Use either the array above or,
227 // for non-talk pages, a generic "discuss this" message.
228 // Default is the same as for main namespace.
229 if ( isset( $nsToMessage[$companionNamespace] ) ) {
230 $message = $nsToMessage[$companionNamespace];
232 $message = $companionTitle->isTalkPage() ?
'talkpage' : 'articlepage';
235 // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones.
236 // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805)
237 $key = $companionTitle->getNamespaceKey( '' );
238 if ( $companionTitle->isTalkPage() ) {
239 $key = ( $key == 'main' ?
'talk' : $key . "_talk" );
242 // Use the regular navigational link, but replace its text. Everything else stays unmodified.
243 $namespacesLinks = $this->data
['content_navigation']['namespaces'];
244 return $this->processBottomLink( $message, $namespacesLinks[$key], $message );
248 * Takes a navigational link generated by SkinTemplate in whichever way
249 * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids
250 * and removes the accesskeys. This is necessary to be able to use the same navlink twice,
251 * e.g. in sidebar and in footer.
253 * @param $navlink array Navigational link generated by SkinTemplate
254 * @param $idPrefix mixed Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'.
256 function processNavlinkForDocument( $navlink, $idPrefix='cb-' ) {
257 if ( $navlink['id'] ) {
258 $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
259 $navlink['tooltiponly'] = true; // but no accesskeys
261 // mangle or remove the id
262 if ( $idPrefix === false ) {
263 unset( $navlink['id'] );
265 $navlink['id'] = $idPrefix . $navlink['id'];
277 function beforeContent() {
282 <p id
="sitetitle" role
="banner">
283 <a href
="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
284 <?php
echo wfMessage( 'sitetitle' )->escaped() ?
>
287 <p id
="sitesub"><?php
echo wfMessage( 'sitesubtitle' )->escaped() ?
></p
>
288 <div id
="linkcollection" role
="navigation">
289 <div id
="langlinks"><?php
echo str_replace( '<br />', '', $this->otherLanguages() ) ?
></div
>
290 <?php
echo $this->getSkin()->getCategories() ?
>
291 <div id
="titlelinks"><?php
echo $this->pageTitleLinks() ?
></div
>
292 <?php
if ( $this->data
['newtalk'] ) { ?
>
293 <div
class="usermessage"><strong
><?php
echo $this->data
['newtalk'] ?
></strong
></div
>
297 <div id
="article" role
="main">
298 <?php
if ( $this->getSkin()->getSiteNotice() ) { ?
>
299 <div id
="siteNotice"><?php
echo $this->getSkin()->getSiteNotice() ?
></div
>
301 <h1 id
="firstHeading" lang
="<?php
302 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageLanguage()->getCode();
303 $this->html( 'pageLanguage' );
304 ?>"><span dir
="auto"><?php
echo $this->data
['title'] ?
></span
></h1
>
305 <?php
if ( $this->translator
->translate( 'tagline' ) ) { ?
>
306 <p
class="tagline"><?php
echo htmlspecialchars( $this->translator
->translate( 'tagline' ) ) ?
></p
>
308 <?php
if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?
>
309 <p
class="subtitle"><?php
echo $this->getSkin()->getOutput()->getSubtitle() ?
></p
>
311 <?php
if ( $this->getSkin()->subPageSubtitle() ) { ?
>
312 <p
class="subpages"><?php
echo $this->getSkin()->subPageSubtitle() ?
></p
>
315 $s = ob_get_contents();
326 function afterContent() {
330 <div id
="footer" role
="contentinfo">
332 // Page-related links
333 echo $this->bottomLinks();
336 // Footer and second searchbox
337 echo $this->getSkin()->getLanguage()->pipeList( array(
338 $this->getSkin()->mainPageLink(),
339 $this->getSkin()->aboutLink(),
340 $this->searchForm( 'footer' )
344 // Standard footer info
345 $footlinks = $this->getFooterLinks();
346 if ( $footlinks['info'] ) {
347 foreach ( $footlinks['info'] as $item ) {
348 echo $this->data
[$item] . ' ';
354 <div id
="mw-navigation">
355 <h2
><?php
echo wfMessage( 'navigation-heading' )->escaped() ?
></h2
>
356 <div id
="toplinks" role
="navigation">
357 <p id
="syslinks"><?php
echo $this->sysLinks() ?
></p
>
358 <p id
="variantlinks"><?php
echo $this->variantLinks() ?
></p
>
360 <?php
echo $this->quickBar() ?
>
363 $s = ob_get_contents();
374 function sysLinks() {
376 $this->getSkin()->mainPageLink(),
378 Title
::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
379 wfMessage( 'about' )->text()
382 Title
::newFromText( wfMessage( 'helppage' )->inContentLanguage()->text() ),
383 wfMessage( 'help' )->text()
386 Title
::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
387 wfMessage( 'faq' )->text()
391 $personalUrls = $this->getPersonalTools();
392 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
393 if ( $personalUrls[$key] ) {
394 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
398 return $this->getSkin()->getLanguage()->pipeList( $s );
402 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
404 * @param $bar sidebar data
405 * @return array modified sidebar data
409 function sidebarAdditions( $bar ) {
410 // "This page" and "Edit" menus
411 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
412 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
413 // We also don't use $...['variants'], these are displayed in the top menu.
414 $content_navigation = $this->data
['content_navigation'];
415 $qbpageoptions = array_merge(
416 $content_navigation['namespaces'],
418 'history' => $content_navigation['views']['history'],
419 'watch' => $content_navigation['actions']['watch'],
420 'unwatch' => $content_navigation['actions']['unwatch'],
423 $content_navigation['actions']['watch'] = null;
424 $content_navigation['actions']['unwatch'] = null;
425 $qbedit = array_merge(
427 'edit' => $content_navigation['views']['edit'],
428 'addsection' => $content_navigation['views']['addsection'],
430 $content_navigation['actions']
433 // Personal tools ("My pages")
434 $qbmyoptions = $this->getPersonalTools();
435 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
436 $qbmyoptions[$key] = null;
439 // Use the closest reasonable name
440 $bar['cactions'] = $qbedit;
441 $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
442 $bar['personal'] = $qbmyoptions;
448 * Compute the sidebar
455 function quickBar() {
456 // Massage the sidebar. We want to:
457 // * place SEARCH at the beginning
458 // * add new portlets before TOOLBOX (or at the end, if it's missing)
459 // * remove LANGUAGES (langlinks are displayed elsewhere)
460 $orig_bar = $this->data
['sidebar'];
464 // Always display search first
465 $bar['SEARCH'] = true;
466 // Copy everything except for langlinks, inserting new items before toolbox
467 foreach ( $orig_bar as $heading => $data ) {
468 if ( $heading == 'TOOLBOX' ) {
470 $bar = $this->sidebarAdditions( $bar );
474 if ( $heading != 'LANGUAGES' ) {
475 $bar[$heading] = $data;
478 // If toolbox is missing, add our items at the end
479 if ( !$hasToolbox ) {
480 $bar = $this->sidebarAdditions( $bar );
484 // Fill out special sidebar items with content
487 foreach ( $orig_bar as $heading => $data ) {
488 if ( $heading == 'SEARCH' ) {
489 $bar['search'] = $this->searchForm( 'sidebar' );
490 } elseif ( $heading == 'TOOLBOX' ) {
491 $bar['tb'] = $this->getToolbox();
493 $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',
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>";
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
522 $listHTML .= $this->makeListItem( $key, $link );
526 $listHTML = "<ul>$listHTML</ul>";
529 // $data is a HTML <ul>-list string
534 $role = ( $heading == 'search' ) ?
'search' : 'navigation';
535 $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
544 * @param $label 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 .= "<input type='text' class=\"mw-searchInput\" name=\"search\" size=\"14\" value=\""
560 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />"
561 . ($which == 'footer' ?
" " : "<br />")
562 . "<input type='submit' class=\"searchButton\" name=\"go\" value=\"" . wfMessage( 'searcharticle' )->escaped() . "\" />";
564 if( $wgUseTwoButtonsSearchForm ) {
565 $s .= " <input type='submit' class=\"searchButton\" name=\"fulltext\" value=\"" . wfMessage( 'searchbutton' )->escaped() . "\" />\n";
567 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";