Merge "CologneBlue rewrite: fix talkLink() to use generic nav links"
[lhc/web/wiklou.git] / skins / CologneBlue.php
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
25 if( !defined( 'MEDIAWIKI' ) ) {
26 die( -1 );
27 }
28
29 /**
30 * @todo document
31 * @ingroup Skins
32 */
33 class SkinCologneBlue extends SkinTemplate {
34 var $skinname = 'cologneblue', $stylename = 'cologneblue',
35 $template = 'CologneBlueTemplate';
36 var $useHeadElement = true;
37
38 /**
39 * @param $out OutputPage
40 */
41 function setupSkinUserCss( OutputPage $out ){
42 $out->addModuleStyles( 'mediawiki.legacy.shared' );
43 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
44 $out->addModuleStyles( 'skins.cologneblue' );
45 }
46
47 /**
48 * Override langlink formatting behavior not to uppercase the language names.
49 * See otherLanguages() in CologneBlueTemplate.
50 */
51 function formatLanguageName( $name ) {
52 return $name;
53 }
54 }
55
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();
69 }
70
71 /**
72 * Language/charset variant links for classic-style skins
73 * @return string
74 *
75 * @fixed
76 */
77 function variantLinks() {
78 $s = array();
79
80 $variants = $this->data['content_navigation']['variants'];
81
82 foreach ( $variants as $key => $link ) {
83 $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
84 }
85
86 return $this->getSkin()->getLanguage()->pipeList( $s );
87 }
88
89 // @fixed
90 function otherLanguages() {
91 global $wgHideInterlanguageLinks;
92 if ( $wgHideInterlanguageLinks ) {
93 return "";
94 }
95
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 ) ) {
100 return "";
101 }
102
103 $s = array();
104 foreach ( $language_urls as $key => $data ) {
105 $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
106 }
107
108 return wfMessage( 'otherlanguages' )->text()
109 . wfMessage( 'colon-separator' )->text()
110 . $this->getSkin()->getLanguage()->pipeList( $s );
111 }
112
113 // @fixed
114 function pageTitleLinks() {
115 $s = array();
116 $footlinks = $this->getFooterLinks();
117
118 foreach ( $footlinks['places'] as $item ) {
119 $s[] = $this->data[$item];
120 }
121
122 return $this->getSkin()->getLanguage()->pipeList( $s );
123 }
124
125 function bottomLinks() {
126 $sep = wfMessage( 'pipe-separator' )->escaped() . "\n";
127
128 $s = '';
129 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
130 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
131
132 if ( $this->getSkin()->getUser()->isLoggedIn() ) {
133 $element[] = $this->watchThisPage();
134 }
135
136 $element[] = $this->talkLink();
137 $element[] = $this->historyLink();
138 $element[] = $this->whatLinksHere();
139 $element[] = $this->watchPageLinksLink();
140
141 $title = $this->getSkin()->getTitle();
142
143 if (
144 $title->getNamespace() == NS_USER ||
145 $title->getNamespace() == NS_USER_TALK
146 ) {
147 $id = User::idFromName( $title->getText() );
148 $ip = User::isIP( $title->getText() );
149
150 # Both anons and non-anons have contributions list
151 if ( $id || $ip ) {
152 $element[] = $this->userContribsLink();
153 }
154
155 if ( $this->getSkin()->showEmailUser( $id ) ) {
156 $element[] = $this->emailUserLink();
157 }
158 }
159
160 $s = implode( $element, $sep );
161
162 if ( $title->getArticleID() ) {
163 $s .= "\n<br />";
164
165 // Delete/protect/move links for privileged users
166 if ( $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
167 $s .= $this->deleteThisPage();
168 }
169
170 if ( $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
171 $s .= $sep . $this->protectThisPage();
172 }
173
174 if ( $this->getSkin()->getUser()->isAllowed( 'move' ) ) {
175 $s .= $sep . $this->moveThisPage();
176 }
177 }
178
179 $s .= "<br />\n" . $this->otherLanguages();
180 }
181
182 return $s;
183 }
184
185 function editThisPage() {
186 if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
187 $s = wfMessage( 'protectedpage' )->text();
188 } else {
189 $title = $this->getSkin()->getTitle();
190 if ( $title->quickUserCan( 'edit' ) && $title->exists() ) {
191 $t = wfMessage( 'editthispage' )->text();
192 } elseif ( $title->quickUserCan( 'create' ) && !$title->exists() ) {
193 $t = wfMessage( 'create-this-page' )->text();
194 } else {
195 $t = wfMessage( 'viewsource' )->text();
196 }
197
198 $s = Linker::linkKnown(
199 $title,
200 $t,
201 array(),
202 $this->getSkin()->editUrlOptions()
203 );
204 }
205
206 return $s;
207 }
208
209 function deleteThisPage() {
210 $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
211 $title = $this->getSkin()->getTitle();
212
213 if ( $title->getArticleID() && ( !$diff ) && $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
214 $t = wfMessage( 'deletethispage' )->text();
215
216 $s = Linker::linkKnown(
217 $title,
218 $t,
219 array(),
220 array( 'action' => 'delete' )
221 );
222 } else {
223 $s = '';
224 }
225
226 return $s;
227 }
228
229 function protectThisPage() {
230 $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
231 $title = $this->getSkin()->getTitle();
232
233 if ( $title->getArticleID() && ( ! $diff ) && $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
234 if ( $title->isProtected() ) {
235 $text = wfMessage( 'unprotectthispage' )->text();
236 $query = array( 'action' => 'unprotect' );
237 } else {
238 $text = wfMessage( 'protectthispage' )->text();
239 $query = array( 'action' => 'protect' );
240 }
241
242 $s = Linker::linkKnown(
243 $title,
244 $text,
245 array(),
246 $query
247 );
248 } else {
249 $s = '';
250 }
251
252 return $s;
253 }
254
255 function watchThisPage() {
256 // Cache
257 $title = $this->getSkin()->getTitle();
258
259 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
260 if ( $this->getSkin()->getUser()->isWatched( $title ) ) {
261 $text = wfMessage( 'unwatchthispage' )->text();
262 $query = array(
263 'action' => 'unwatch',
264 'token' => UnwatchAction::getUnwatchToken( $title, $this->getSkin()->getUser() ),
265 );
266 $id = 'mw-unwatch-link';
267 } else {
268 $text = wfMessage( 'watchthispage' )->text();
269 $query = array(
270 'action' => 'watch',
271 'token' => WatchAction::getWatchToken( $title, $this->getSkin()->getUser() ),
272 );
273 $id = 'mw-watch-link';
274 }
275
276 $s = Linker::linkKnown(
277 $title,
278 $text,
279 array( 'id' => $id ),
280 $query
281 );
282 } else {
283 $s = wfMessage( 'notanarticle' )->text();
284 }
285
286 return $s;
287 }
288
289 function moveThisPage() {
290 if ( $this->getSkin()->getTitle()->quickUserCan( 'move' ) ) {
291 return Linker::linkKnown(
292 SpecialPage::getTitleFor( 'Movepage' ),
293 wfMessage( 'movethispage' )->text(),
294 array(),
295 array( 'target' => $this->getSkin()->getTitle()->getPrefixedDBkey() )
296 );
297 } else {
298 // no message if page is protected - would be redundant
299 return '';
300 }
301 }
302
303 function historyLink() {
304 return Linker::link(
305 $this->getSkin()->getTitle(),
306 wfMessage( 'history' )->escaped(),
307 array( 'rel' => 'archives' ),
308 array( 'action' => 'history' )
309 );
310 }
311
312 function whatLinksHere() {
313 return Linker::linkKnown(
314 SpecialPage::getTitleFor( 'Whatlinkshere', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
315 wfMessage( 'whatlinkshere' )->escaped()
316 );
317 }
318
319 function userContribsLink() {
320 return Linker::linkKnown(
321 SpecialPage::getTitleFor( 'Contributions', $this->getSkin()->getTitle()->getDBkey() ),
322 wfMessage( 'contributions' )->escaped()
323 );
324 }
325
326 function emailUserLink() {
327 return Linker::linkKnown(
328 SpecialPage::getTitleFor( 'Emailuser', $this->getSkin()->getTitle()->getDBkey() ),
329 wfMessage( 'emailuser' )->escaped()
330 );
331 }
332
333 function watchPageLinksLink() {
334 if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
335 return wfMessage( 'parentheses', wfMessage( 'notanarticle' )->text() )->escaped();
336 } else {
337 return Linker::linkKnown(
338 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
339 wfMessage( 'recentchangeslinked-toolbox' )->escaped()
340 );
341 }
342 }
343
344 // @fixed
345 function talkLink() {
346 $title = $this->getSkin()->getTitle();
347
348 if ( $title->getNamespace() == NS_SPECIAL ) {
349 // No discussion links for special pages
350 return "";
351 }
352
353 $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
354 $companionNamespace = $companionTitle->getNamespace();
355
356 // TODO these messages appear to only be used by CologneBlue and legacy skins,
357 // kill and replace with something more sensibly named?
358 $nsToMessage = array(
359 NS_MAIN => 'articlepage',
360 NS_USER => 'userpage',
361 NS_PROJECT => 'projectpage',
362 NS_FILE => 'imagepage',
363 NS_MEDIAWIKI => 'mediawikipage',
364 NS_TEMPLATE => 'templatepage',
365 NS_HELP => 'viewhelppage',
366 NS_CATEGORY => 'categorypage',
367 NS_FILE => 'imagepage',
368 );
369
370 // Find out the message to use for link text. Use either the array above or,
371 // for non-talk pages, a generic "discuss this" message.
372 // Default is the same as for main namespace.
373 if ( isset( $nsToMessage[$companionNamespace] ) ) {
374 $message = $nsToMessage[$companionNamespace];
375 } else {
376 $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage';
377 }
378
379 // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones.
380 // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805)
381 $key = $companionTitle->getNamespaceKey( '' );
382 if ( $companionTitle->isTalkPage() ) {
383 $key = ( $key == 'main' ? 'talk' : $key . "_talk" );
384 }
385
386 // Use the regular navigational link, but replace its text. Everything else stays unmodified.
387 $namespacesLinks = $this->data['content_navigation']['namespaces'];
388 $link = $this->processNavlinkForDocument( $namespacesLinks[ $key ] );
389 $link['text'] = wfMessage( $message )->text();
390
391 return $this->makeListItem( $message, $link, array( 'tag' => 'span' ) );
392 }
393
394 /**
395 * Takes a navigational link generated by SkinTemplate in whichever way
396 * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids
397 * and removes the accesskeys. This is necessary to be able to use the same navlink twice,
398 * e.g. in sidebar and in footer.
399 *
400 * @param $navlink array Navigational link generated by SkinTemplate
401 * @param $idPrefix mixed Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'.
402 */
403 function processNavlinkForDocument( $navlink, $idPrefix='cb-' ) {
404 if ( $navlink['id'] ) {
405 $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
406 $navlink['tooltiponly'] = true; // but no accesskeys
407
408 // mangle or remove the id
409 if ( $idPrefix === false ) {
410 unset( $navlink['id'] );
411 } else {
412 $navlink['id'] = $idPrefix . $navlink['id'];
413 }
414 }
415
416 return $navlink;
417 }
418
419 /**
420 * @return string
421 *
422 * @fixed
423 */
424 function beforeContent() {
425 ob_start();
426 ?>
427 <div id="content">
428 <div id="topbar">
429 <p id="sitetitle">
430 <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
431 <?php echo wfMessage( 'sitetitle' )->escaped() ?>
432 </a>
433 </p>
434 <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
435 <div id="toplinks">
436 <p id="syslinks"><?php echo $this->sysLinks() ?></p>
437 <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
438 </div>
439 <div id="linkcollection">
440 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
441 <?php echo $this->getSkin()->getCategories() ?>
442 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
443 <?php if ( $this->data['newtalk'] ) { ?>
444 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
445 <?php } ?>
446 </div>
447 </div>
448 <div id="article">
449 <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
450 <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
451 <?php } ?>
452 <h1 id="firstHeading"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
453 <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
454 <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
455 <?php } ?>
456 <?php if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?>
457 <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
458 <?php } ?>
459 <?php if ( $this->getSkin()->subPageSubtitle() ) { ?>
460 <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
461 <?php } ?>
462 <?php
463 $s = ob_get_contents();
464 ob_end_clean();
465
466 return $s;
467 }
468
469 /**
470 * @return string
471 *
472 * @fixed
473 */
474 function afterContent() {
475 ob_start();
476 ?>
477 </div>
478 <div id='footer'>
479 <?php
480 // Page-related links
481 echo $this->bottomLinks();
482 echo "\n<br />";
483
484 // Footer and second searchbox
485 echo $this->getSkin()->getLanguage()->pipeList( array(
486 $this->getSkin()->mainPageLink(),
487 $this->getSkin()->aboutLink(),
488 $this->searchForm( 'footer' )
489 ) );
490 echo "\n<br />";
491
492 // Standard footer info
493 $footlinks = $this->getFooterLinks();
494 if ( $footlinks['info'] ) {
495 foreach ( $footlinks['info'] as $item ) {
496 echo $this->data[$item] . ' ';
497 }
498 }
499 ?>
500 </div>
501 </div>
502 <?php echo $this->quickBar() ?>
503 <?php
504 $s = ob_get_contents();
505 ob_end_clean();
506
507 return $s;
508 }
509
510 /**
511 * @return string
512 *
513 * @fixed
514 */
515 function sysLinks() {
516 $s = array(
517 $this->getSkin()->mainPageLink(),
518 Linker::linkKnown(
519 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
520 wfMessage( 'about' )->text()
521 ),
522 Linker::linkKnown(
523 Title::newFromText( wfMessage( 'helppage' )->inContentLanguage()->text() ),
524 wfMessage( 'help' )->text()
525 ),
526 Linker::linkKnown(
527 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
528 wfMessage( 'faq' )->text()
529 ),
530 );
531
532 $personalUrls = $this->getPersonalTools();
533 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
534 if ( $personalUrls[$key] ) {
535 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
536 }
537 }
538
539 return $this->getSkin()->getLanguage()->pipeList( $s );
540 }
541
542 /**
543 * @param $heading string
544 * @return string
545 *
546 * @fixed
547 */
548 function menuHead( $heading ) {
549 return "\n<h6>" . htmlspecialchars( $heading ) . "</h6>";
550 }
551
552 /**
553 * Compute the sidebar
554 * @access private
555 *
556 * @return string
557 *
558 * @fixed
559 */
560 function quickBar(){
561 $s = "\n<div id='quickbar'>";
562
563 $sep = "<br />\n";
564
565 $plain_bar = $this->data['sidebar'];
566 $bar = array();
567
568 // Massage the sidebar
569 // We want to place SEARCH at the beginning and a lot of stuff before TOOLBOX (or at the end, if it's missing)
570 $additions_done = false;
571 while ( !$additions_done ) {
572 $bar = array(); // Empty it out
573
574 // Always display search on top
575 $bar['SEARCH'] = true;
576
577 foreach ( $plain_bar as $heading => $links ) {
578 if ( $heading == 'TOOLBOX' ) {
579 if( $links !== NULL ) {
580 // If this is not a toolbox prosthetic we inserted outselves, fill it out
581 $plain_bar['TOOLBOX'] = $this->getToolbox();
582 }
583
584 // And insert the stuff
585
586 // "This page" and "Edit" menus
587 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
588 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
589 // We also don't use $...['variants'], these are displayed in the top menu.
590 $content_navigation = $this->data['content_navigation'];
591 $qbpageoptions = array_merge(
592 $content_navigation['namespaces'],
593 array(
594 'history' => $content_navigation['views']['history'],
595 'watch' => $content_navigation['actions']['watch'],
596 'unwatch' => $content_navigation['actions']['unwatch'],
597 )
598 );
599 $content_navigation['actions']['watch'] = null;
600 $content_navigation['actions']['unwatch'] = null;
601 $qbedit = array_merge(
602 array(
603 'edit' => $content_navigation['views']['edit'],
604 'addsection' => $content_navigation['views']['addsection'],
605 ),
606 $content_navigation['actions']
607 );
608 $bar['qbedit'] = $qbedit;
609 $bar['qbpageoptions'] = $qbpageoptions;
610
611 // Personal tools ("My pages")
612 $bar['qbmyoptions'] = $this->getPersonalTools();
613 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
614 $bar['qbmyoptions'][$key] = null;
615 }
616
617 $additions_done = true;
618 }
619
620 // Re-insert current heading, unless it's SEARCH
621 if ( $heading != 'SEARCH' ) {
622 $bar[$heading] = $plain_bar[$heading];
623 }
624 }
625
626 // If TOOLBOX is missing, $additions_done is still false
627 if ( !$additions_done ) {
628 $plain_bar['TOOLBOX'] = false;
629 }
630 }
631
632 foreach ( $bar as $heading => $links ) {
633 if ( $heading == 'SEARCH' ) {
634 $s .= $this->menuHead( wfMessage( 'qbfind' )->text() );
635 $s .= $this->searchForm( 'sidebar' );
636 } elseif ( $heading == 'LANGUAGES' ) {
637 // discard these; we display languages below page content
638 } elseif ( $links ) {
639 if ( is_array( $links ) ) {
640 // Use the navigation heading from standard sidebar as the "browse" section
641 if ( $heading == 'navigation' ) {
642 $heading = 'qbbrowse';
643 }
644 if ( $heading == 'TOOLBOX' ) {
645 $heading = 'toolbox';
646 }
647
648 $headingMsg = wfMessage( $heading );
649 $any_link = false;
650 $t = $this->menuHead( $headingMsg->exists() ? $headingMsg->text() : $heading );
651
652 foreach ( $links as $key => $link ) {
653 // Can be empty due to rampant sidebar massaging we're doing above
654 if ( $link ) {
655 $any_link = true;
656 $t .= $this->makeListItem( $key, $link, array( 'tag' => 'span' ) ) . $sep;
657 }
658 }
659
660 if ( $any_link ) {
661 $s .= $t;
662 }
663 } else {
664 // $links can be a HTML string
665 $s .= $links;
666 }
667 }
668 }
669
670 $s .= $sep . "\n</div>\n";
671 return $s;
672 }
673
674 /**
675 * @param $label string
676 * @return string
677 *
678 * @fixed
679 */
680 function searchForm( $which ) {
681 global $wgUseTwoButtonsSearchForm;
682
683 $search = $this->getSkin()->getRequest()->getText( 'search' );
684 $action = $this->data['searchaction'];
685 $s = "<form id=\"searchform-" . htmlspecialchars($which) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
686 if( $which == 'footer' ) {
687 $s .= wfMessage( 'qbfind' )->text() . ": ";
688 }
689
690 $s .= "<input type='text' class=\"mw-searchInput\" name=\"search\" size=\"14\" value=\""
691 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />"
692 . ($which == 'footer' ? " " : "<br />")
693 . "<input type='submit' class=\"searchButton\" name=\"go\" value=\"" . wfMessage( 'searcharticle' )->escaped() . "\" />";
694
695 if( $wgUseTwoButtonsSearchForm ) {
696 $s .= " <input type='submit' class=\"searchButton\" name=\"fulltext\" value=\"" . wfMessage( 'searchbutton' )->escaped() . "\" />\n";
697 } else {
698 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
699 }
700
701 $s .= '</form>';
702
703 return $s;
704 }
705 }