Remove silly 'm' prefix from StubObject/DeprecatedGlobal members
[mediawiki.git] / skins / CologneBlue.php
blobad500ea42287237fe100a36f63211405b6fe4da3
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 public $skinname = 'cologneblue';
35 public $stylename = 'cologneblue';
36 public $template = 'CologneBlueTemplate';
37 public $useHeadElement = true;
39 /**
40 * @param OutputPage $out
42 function setupSkinUserCss( OutputPage $out ) {
43 parent::setupSkinUserCss( $out );
44 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
45 $out->addModuleStyles( 'skins.cologneblue' );
48 /**
49 * Override langlink formatting behavior not to uppercase the language names.
50 * See otherLanguages() in CologneBlueTemplate.
51 * @param string $name
52 * @return string
54 function formatLanguageName( $name ) {
55 return $name;
59 class CologneBlueTemplate extends BaseTemplate {
60 function execute() {
61 // Suppress warnings to prevent notices about missing indexes in $this->data
62 wfSuppressWarnings();
63 $this->html( 'headelement' );
64 echo $this->beforeContent();
65 $this->html( 'bodytext' );
66 echo "\n";
67 echo $this->afterContent();
68 $this->html( 'dataAfterContent' );
69 $this->printTrail();
70 echo "\n</body></html>";
71 wfRestoreWarnings();
74 /**
75 * Language/charset variant links for classic-style skins
76 * @return string
78 function variantLinks() {
79 $s = array();
81 $variants = $this->data['content_navigation']['variants'];
83 foreach ( $variants as $key => $link ) {
84 $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
87 return $this->getSkin()->getLanguage()->pipeList( $s );
90 function otherLanguages() {
91 global $wgHideInterlanguageLinks;
92 if ( $wgHideInterlanguageLinks ) {
93 return "";
96 $html = '';
98 // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
99 // not to capitalize the language names.
100 $language_urls = $this->data['language_urls'];
101 if ( !empty( $language_urls ) ) {
102 $s = array();
103 foreach ( $language_urls as $key => $data ) {
104 $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
107 $html = wfMessage( 'otherlanguages' )->text()
108 . wfMessage( 'colon-separator' )->text()
109 . $this->getSkin()->getLanguage()->pipeList( $s );
112 $html .= $this->renderAfterPortlet( 'lang' );
114 return $html;
118 * @param string $name
120 protected function renderAfterPortlet( $name ) {
121 $content = '';
122 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
124 $html = $content !== '' ? "<div class='after-portlet after-portlet-$name'>$content</div>" : '';
126 return $html;
129 function pageTitleLinks() {
130 $s = array();
131 $footlinks = $this->getFooterLinks();
133 foreach ( $footlinks['places'] as $item ) {
134 $s[] = $this->data[$item];
137 return $this->getSkin()->getLanguage()->pipeList( $s );
141 * Used in bottomLinks() to eliminate repetitive code.
143 * @param string $key Key to be passed to makeListItem()
144 * @param array $navlink Navlink suitable for processNavlinkForDocument()
145 * @param string $message Key of the message to use in place of standard text
147 * @return string
149 function processBottomLink( $key, $navlink, $message = null ) {
150 if ( !$navlink ) {
151 // Empty navlinks might be passed.
152 return null;
155 if ( $message ) {
156 $navlink['text'] = wfMessage( $message )->escaped();
159 return $this->makeListItem(
160 $key,
161 $this->processNavlinkForDocument( $navlink ),
162 array( 'tag' => 'span' )
166 function bottomLinks() {
167 $toolbox = $this->getToolbox();
168 $content_nav = $this->data['content_navigation'];
170 $lines = array();
172 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
173 // First row. Regular actions.
174 $element = array();
176 $editLinkMessage = $this->getSkin()->getTitle()->exists() ? 'editthispage' : 'create-this-page';
177 $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
178 $element[] = $this->processBottomLink(
179 'viewsource',
180 $content_nav['views']['viewsource'],
181 'viewsource'
184 $element[] = $this->processBottomLink(
185 'watch',
186 $content_nav['actions']['watch'],
187 'watchthispage'
189 $element[] = $this->processBottomLink(
190 'unwatch',
191 $content_nav['actions']['unwatch'],
192 'unwatchthispage'
195 $element[] = $this->talkLink();
197 $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
198 $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
199 $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
200 $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
202 $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
203 $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
205 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
207 // Second row. Privileged actions.
208 $element = array();
210 $element[] = $this->processBottomLink(
211 'delete',
212 $content_nav['actions']['delete'],
213 'deletethispage'
215 $element[] = $this->processBottomLink(
216 'undelete',
217 $content_nav['actions']['undelete'],
218 'undeletethispage'
221 $element[] = $this->processBottomLink(
222 'protect',
223 $content_nav['actions']['protect'],
224 'protectthispage'
226 $element[] = $this->processBottomLink(
227 'unprotect',
228 $content_nav['actions']['unprotect'],
229 'unprotectthispage'
232 $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
234 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
236 // Third row. Language links.
237 $lines[] = $this->otherLanguages();
240 return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
243 function talkLink() {
244 $title = $this->getSkin()->getTitle();
246 if ( $title->getNamespace() == NS_SPECIAL ) {
247 // No discussion links for special pages
248 return "";
251 $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
252 $companionNamespace = $companionTitle->getNamespace();
254 // TODO these messages are only be used by CologneBlue,
255 // kill and replace with something more sensibly named?
256 $nsToMessage = array(
257 NS_MAIN => 'articlepage',
258 NS_USER => 'userpage',
259 NS_PROJECT => 'projectpage',
260 NS_FILE => 'imagepage',
261 NS_MEDIAWIKI => 'mediawikipage',
262 NS_TEMPLATE => 'templatepage',
263 NS_HELP => 'viewhelppage',
264 NS_CATEGORY => 'categorypage',
265 NS_FILE => 'imagepage',
268 // Find out the message to use for link text. Use either the array above or,
269 // for non-talk pages, a generic "discuss this" message.
270 // Default is the same as for main namespace.
271 if ( isset( $nsToMessage[$companionNamespace] ) ) {
272 $message = $nsToMessage[$companionNamespace];
273 } else {
274 $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage';
277 // Obviously this can't be reasonable and just return the key for talk
278 // namespace, only for content ones. Thus we have to mangle it in
279 // exactly the same way SkinTemplate does. (bug 40805)
280 $key = $companionTitle->getNamespaceKey( '' );
281 if ( $companionTitle->isTalkPage() ) {
282 $key = ( $key == 'main' ? 'talk' : $key . "_talk" );
285 // Use the regular navigational link, but replace its text. Everything else stays unmodified.
286 $namespacesLinks = $this->data['content_navigation']['namespaces'];
288 return $this->processBottomLink( $message, $namespacesLinks[$key], $message );
292 * Takes a navigational link generated by SkinTemplate in whichever way
293 * and mangles attributes unsuitable for repeated use. In particular, this
294 * modifies the ids and removes the accesskeys. This is necessary to be
295 * able to use the same navlink twice, e.g. in sidebar and in footer.
297 * @param array $navlink Navigational link generated by SkinTemplate
298 * @param mixed $idPrefix Prefix to add to id of this navlink. If false, id
299 * is removed entirely. Default is 'cb-'.
301 function processNavlinkForDocument( $navlink, $idPrefix = 'cb-' ) {
302 if ( $navlink['id'] ) {
303 $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
304 $navlink['tooltiponly'] = true; // but no accesskeys
306 // mangle or remove the id
307 if ( $idPrefix === false ) {
308 unset( $navlink['id'] );
309 } else {
310 $navlink['id'] = $idPrefix . $navlink['id'];
314 return $navlink;
318 * @return string
320 function beforeContent() {
321 ob_start();
323 <div id="content">
324 <div id="topbar">
325 <p id="sitetitle" role="banner">
326 <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
327 <?php echo wfMessage( 'sitetitle' )->escaped() ?>
328 </a>
329 </p>
331 <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
333 <div id="linkcollection" role="navigation">
334 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
335 <?php echo $this->getSkin()->getCategories() ?>
336 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
337 <?php
338 if ( $this->data['newtalk'] ) {
340 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
341 <?php
344 </div>
345 </div>
346 <div id="article" class="mw-body" role="main">
347 <?php
348 if ( $this->getSkin()->getSiteNotice() ) {
350 <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
351 <?php
354 <h1 id="firstHeading" lang="<?php
355 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
356 $this->text( 'pageLanguage' );
357 ?>"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
358 <?php
359 if ( $this->translator->translate( 'tagline' ) ) {
361 <p class="tagline"><?php
362 echo htmlspecialchars( $this->translator->translate( 'tagline' ) )
363 ?></p>
364 <?php
367 <?php
368 if ( $this->getSkin()->getOutput()->getSubtitle() ) {
370 <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
371 <?php
374 <?php
375 if ( $this->getSkin()->subPageSubtitle() ) {
377 <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
378 <?php
381 <?php
382 $s = ob_get_contents();
383 ob_end_clean();
385 return $s;
389 * @return string
391 function afterContent() {
392 ob_start();
394 </div>
395 <div id="footer">
396 <div id="footer-navigation" role="navigation">
397 <?php
398 // Page-related links
399 echo $this->bottomLinks();
400 echo "\n<br />";
402 // Footer and second searchbox
403 echo $this->getSkin()->getLanguage()->pipeList( array(
404 $this->getSkin()->mainPageLink(),
405 $this->getSkin()->aboutLink(),
406 $this->searchForm( 'footer' )
407 ) );
409 </div>
410 <div id="footer-info" role="contentinfo">
411 <?php
412 // Standard footer info
413 $footlinks = $this->getFooterLinks();
414 if ( $footlinks['info'] ) {
415 foreach ( $footlinks['info'] as $item ) {
416 echo $this->data[$item] . ' ';
420 </div>
421 </div>
422 </div>
423 <div id="mw-navigation">
424 <h2><?php echo wfMessage( 'navigation-heading' )->escaped() ?></h2>
426 <div id="toplinks" role="navigation">
427 <p id="syslinks"><?php echo $this->sysLinks() ?></p>
429 <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
430 </div>
431 <?php echo $this->quickBar() ?>
432 </div>
433 <?php
434 $s = ob_get_contents();
435 ob_end_clean();
437 return $s;
441 * @return string
443 function sysLinks() {
444 $s = array(
445 $this->getSkin()->mainPageLink(),
446 Linker::linkKnown(
447 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
448 wfMessage( 'about' )->text()
450 Linker::makeExternalLink(
451 Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ),
452 wfMessage( 'help' )->text(),
453 false
455 Linker::linkKnown(
456 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
457 wfMessage( 'faq' )->text()
461 $personalUrls = $this->getPersonalTools();
462 foreach ( array( 'logout', 'createaccount', 'login' ) as $key ) {
463 if ( $personalUrls[$key] ) {
464 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
468 return $this->getSkin()->getLanguage()->pipeList( $s );
472 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
474 * @param array $bar Sidebar data
475 * @return array Modified sidebar data
477 function sidebarAdditions( $bar ) {
478 // "This page" and "Edit" menus
479 // We need to do some massaging here... we reuse all of the items,
480 // except for $...['views']['view'], as $...['namespaces']['main'] and
481 // $...['namespaces']['talk'] together serve the same purpose. We also
482 // don't use $...['variants'], these are displayed in the top menu.
483 $content_navigation = $this->data['content_navigation'];
484 $qbpageoptions = array_merge(
485 $content_navigation['namespaces'],
486 array(
487 'history' => $content_navigation['views']['history'],
488 'watch' => $content_navigation['actions']['watch'],
489 'unwatch' => $content_navigation['actions']['unwatch'],
492 $content_navigation['actions']['watch'] = null;
493 $content_navigation['actions']['unwatch'] = null;
494 $qbedit = array_merge(
495 array(
496 'edit' => $content_navigation['views']['edit'],
497 'addsection' => $content_navigation['views']['addsection'],
499 $content_navigation['actions']
502 // Personal tools ("My pages")
503 $qbmyoptions = $this->getPersonalTools();
504 foreach ( array( 'logout', 'createaccount', 'login', ) as $key ) {
505 $qbmyoptions[$key] = null;
508 // Use the closest reasonable name
509 $bar['cactions'] = $qbedit;
510 $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
511 $bar['personal'] = $qbmyoptions;
513 return $bar;
517 * Compute the sidebar
518 * @access private
520 * @return string
522 function quickBar() {
523 // Massage the sidebar. We want to:
524 // * place SEARCH at the beginning
525 // * add new portlets before TOOLBOX (or at the end, if it's missing)
526 // * remove LANGUAGES (langlinks are displayed elsewhere)
527 $orig_bar = $this->data['sidebar'];
528 $bar = array();
529 $hasToolbox = false;
531 // Always display search first
532 $bar['SEARCH'] = true;
533 // Copy everything except for langlinks, inserting new items before toolbox
534 foreach ( $orig_bar as $heading => $data ) {
535 if ( $heading == 'TOOLBOX' ) {
536 // Insert the stuff
537 $bar = $this->sidebarAdditions( $bar );
538 $hasToolbox = true;
541 if ( $heading != 'LANGUAGES' ) {
542 $bar[$heading] = $data;
545 // If toolbox is missing, add our items at the end
546 if ( !$hasToolbox ) {
547 $bar = $this->sidebarAdditions( $bar );
550 // Fill out special sidebar items with content
551 $orig_bar = $bar;
552 $bar = array();
553 foreach ( $orig_bar as $heading => $data ) {
554 if ( $heading == 'SEARCH' ) {
555 $bar['search'] = $this->searchForm( 'sidebar' );
556 } elseif ( $heading == 'TOOLBOX' ) {
557 $bar['tb'] = $this->getToolbox();
558 } else {
559 $bar[$heading] = $data;
563 // Output the sidebar
564 // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
565 $idToMessage = array(
566 'search' => 'qbfind',
567 'navigation' => 'qbbrowse',
568 'tb' => 'toolbox',
569 'cactions' => 'qbedit',
570 'personal' => 'qbmyoptions',
571 'pageoptions' => 'qbpageoptions',
574 $s = "<div id='quickbar'>\n";
576 foreach ( $bar as $heading => $data ) {
577 $portletId = Sanitizer::escapeId( "p-$heading" );
578 $headingMsg = wfMessage( $idToMessage[$heading] ? $idToMessage[$heading] : $heading );
579 $headingHTML = "<h3>";
580 $headingHTML .= $headingMsg->exists()
581 ? $headingMsg->escaped()
582 : htmlspecialchars( $heading );
583 $headingHTML .= "</h3>";
584 $listHTML = "";
586 if ( is_array( $data ) ) {
587 // $data is an array of links
588 foreach ( $data as $key => $link ) {
589 // Can be empty due to how the sidebar additions are done
590 if ( $link ) {
591 $listHTML .= $this->makeListItem( $key, $link );
594 if ( $listHTML ) {
595 $listHTML = "<ul>$listHTML</ul>";
597 } else {
598 // $data is a HTML <ul>-list string
599 $listHTML = $data;
602 if ( $listHTML ) {
603 $role = ( $heading == 'search' ) ? 'search' : 'navigation';
604 $s .= "<div class=\"portlet\" id=\"$portletId\" "
605 . "role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
608 $s .= $this->renderAfterPortlet( $heading );
611 $s .= "</div>\n";
613 return $s;
617 * @param string $label
618 * @return string
620 function searchForm( $which ) {
621 global $wgUseTwoButtonsSearchForm;
623 $search = $this->getSkin()->getRequest()->getText( 'search' );
624 $action = $this->data['searchaction'];
625 $s = "<form id=\"searchform-" . htmlspecialchars( $which )
626 . "\" method=\"get\" class=\"inline\" action=\"$action\">";
627 if ( $which == 'footer' ) {
628 $s .= wfMessage( 'qbfind' )->text() . ": ";
631 $s .= $this->makeSearchInput( array(
632 'class' => 'mw-searchInput',
633 'type' => 'text',
634 'size' => '14'
635 ) );
636 $s .= ( $which == 'footer' ? " " : "<br />" );
637 $s .= $this->makeSearchButton( 'go', array( 'class' => 'searchButton' ) );
639 if ( $wgUseTwoButtonsSearchForm ) {
640 $s .= $this->makeSearchButton( 'fulltext', array( 'class' => 'searchButton' ) );
641 } else {
642 $s .= '<div><a href="' . $action . '" rel="search">'
643 . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
646 $s .= '</form>';
648 return $s;