5844a477a30de098ac340293f72ef73d2f43dc23
[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
49 class CologneBlueTemplate extends BaseTemplate {
50 function execute() {
51 $this->html( 'headelement' );
52 echo $this->beforeContent();
53 $this->html( 'bodytext' );
54 echo "\n";
55 echo $this->afterContent();
56 $this->html( 'dataAfterContent' );
57 $this->printTrail();
58 echo "\n</body></html>";
59 }
60
61
62 /**
63 * Language/charset variant links for classic-style skins
64 * @return string
65 */
66 function variantLinks() {
67 $s = '';
68
69 /* show links to different language variants */
70 global $wgDisableLangConversion, $wgLang;
71
72 $title = $this->getSkin()->getTitle();
73 $lang = $title->getPageLanguage();
74 $variants = $lang->getVariants();
75
76 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1
77 && !$title->isSpecialPage() ) {
78 foreach ( $variants as $code ) {
79 $varname = $lang->getVariantname( $code );
80
81 if ( $varname == 'disable' ) {
82 continue;
83 }
84 $s = $wgLang->pipeList( array(
85 $s,
86 '<a href="' . htmlspecialchars( $title->getLocalURL( 'variant=' . $code ) ) . '" lang="' . $code . '" hreflang="' . $code . '">' . htmlspecialchars( $varname ) . '</a>'
87 ) );
88 }
89 }
90
91 return $s;
92 }
93
94 /**
95 * Compatibility for extensions adding functionality through tabs.
96 * Eventually these old skins should be replaced with SkinTemplate-based
97 * versions, sigh...
98 * @return string
99 * @todo Exterminate! ...that, and replace it with normal SkinTemplate stuff
100 */
101 function extensionTabLinks() {
102 $tabs = array();
103 $out = '';
104 $s = array();
105 wfRunHooks( 'SkinTemplateTabs', array( $this->getSkin(), &$tabs ) );
106 foreach ( $tabs as $tab ) {
107 $s[] = Xml::element( 'a',
108 array( 'href' => $tab['href'] ),
109 $tab['text'] );
110 }
111
112 if ( count( $s ) ) {
113 global $wgLang;
114
115 $out = wfMessage( 'pipe-separator' )->escaped();
116 $out .= $wgLang->pipeList( $s );
117 }
118
119 return $out;
120 }
121
122 function otherLanguages() {
123 global $wgOut, $wgLang, $wgHideInterlanguageLinks;
124
125 if ( $wgHideInterlanguageLinks ) {
126 return '';
127 }
128
129 $a = $wgOut->getLanguageLinks();
130
131 if ( 0 == count( $a ) ) {
132 return '';
133 }
134
135 $s = wfMessage( 'otherlanguages' )->text() . wfMessage( 'colon-separator' )->text();
136 $first = true;
137
138 if ( $wgLang->isRTL() ) {
139 $s .= '<span dir="ltr">';
140 }
141
142 foreach ( $a as $l ) {
143 if ( !$first ) {
144 $s .= wfMessage( 'pipe-separator' )->escaped();
145 }
146
147 $first = false;
148
149 $nt = Title::newFromText( $l );
150 $text = Language::fetchLanguageName( $nt->getInterwiki() );
151
152 $s .= Html::element( 'a',
153 array( 'href' => $nt->getFullURL(), 'title' => $nt->getText(), 'class' => "external" ),
154 $text == '' ? $l : $text );
155 }
156
157 if ( $wgLang->isRTL() ) {
158 $s .= '</span>';
159 }
160
161 return $s;
162 }
163
164 // @fixed
165 function pageTitleLinks() {
166 global $wgLang;
167
168 $s = array();
169 $footlinks = $this->getFooterLinks();
170
171 foreach ( $footlinks['places'] as $item ) {
172 $s[] = $this->data[$item];
173 }
174
175 return $wgLang->pipeList( $s );
176 }
177
178 function bottomLinks() {
179 global $wgOut, $wgUser;
180 $sep = wfMessage( 'pipe-separator' )->escaped() . "\n";
181
182 $s = '';
183 if ( $wgOut->isArticleRelated() ) {
184 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
185
186 if ( $wgUser->isLoggedIn() ) {
187 $element[] = $this->watchThisPage();
188 }
189
190 $element[] = $this->talkLink();
191 $element[] = $this->historyLink();
192 $element[] = $this->whatLinksHere();
193 $element[] = $this->watchPageLinksLink();
194
195 $title = $this->getSkin()->getTitle();
196
197 if (
198 $title->getNamespace() == NS_USER ||
199 $title->getNamespace() == NS_USER_TALK
200 ) {
201 $id = User::idFromName( $title->getText() );
202 $ip = User::isIP( $title->getText() );
203
204 # Both anons and non-anons have contributions list
205 if ( $id || $ip ) {
206 $element[] = $this->userContribsLink();
207 }
208
209 if ( $this->getSkin()->showEmailUser( $id ) ) {
210 $element[] = $this->emailUserLink();
211 }
212 }
213
214 $s = implode( $element, $sep );
215
216 if ( $title->getArticleID() ) {
217 $s .= "\n<br />";
218
219 // Delete/protect/move links for privileged users
220 if ( $wgUser->isAllowed( 'delete' ) ) {
221 $s .= $this->deleteThisPage();
222 }
223
224 if ( $wgUser->isAllowed( 'protect' ) ) {
225 $s .= $sep . $this->protectThisPage();
226 }
227
228 if ( $wgUser->isAllowed( 'move' ) ) {
229 $s .= $sep . $this->moveThisPage();
230 }
231 }
232
233 $s .= "<br />\n" . $this->otherLanguages();
234 }
235
236 return $s;
237 }
238
239 function editThisPage() {
240 global $wgOut;
241
242 if ( !$wgOut->isArticleRelated() ) {
243 $s = wfMessage( 'protectedpage' )->text();
244 } else {
245 $title = $this->getSkin()->getTitle();
246 if ( $title->quickUserCan( 'edit' ) && $title->exists() ) {
247 $t = wfMessage( 'editthispage' )->text();
248 } elseif ( $title->quickUserCan( 'create' ) && !$title->exists() ) {
249 $t = wfMessage( 'create-this-page' )->text();
250 } else {
251 $t = wfMessage( 'viewsource' )->text();
252 }
253
254 $s = Linker::linkKnown(
255 $title,
256 $t,
257 array(),
258 $this->getSkin()->editUrlOptions()
259 );
260 }
261
262 return $s;
263 }
264
265 function deleteThisPage() {
266 global $wgUser, $wgRequest;
267
268 $diff = $wgRequest->getVal( 'diff' );
269 $title = $this->getSkin()->getTitle();
270
271 if ( $title->getArticleID() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
272 $t = wfMessage( 'deletethispage' )->text();
273
274 $s = Linker::linkKnown(
275 $title,
276 $t,
277 array(),
278 array( 'action' => 'delete' )
279 );
280 } else {
281 $s = '';
282 }
283
284 return $s;
285 }
286
287 function protectThisPage() {
288 global $wgUser, $wgRequest;
289
290 $diff = $wgRequest->getVal( 'diff' );
291 $title = $this->getSkin()->getTitle();
292
293 if ( $title->getArticleID() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
294 if ( $title->isProtected() ) {
295 $text = wfMessage( 'unprotectthispage' )->text();
296 $query = array( 'action' => 'unprotect' );
297 } else {
298 $text = wfMessage( 'protectthispage' )->text();
299 $query = array( 'action' => 'protect' );
300 }
301
302 $s = Linker::linkKnown(
303 $title,
304 $text,
305 array(),
306 $query
307 );
308 } else {
309 $s = '';
310 }
311
312 return $s;
313 }
314
315 function watchThisPage() {
316 global $wgOut, $wgUser;
317
318 // Cache
319 $title = $this->getSkin()->getTitle();
320
321 if ( $wgOut->isArticleRelated() ) {
322 if ( $wgUser->isWatched( $title ) ) {
323 $text = wfMessage( 'unwatchthispage' )->text();
324 $query = array(
325 'action' => 'unwatch',
326 'token' => UnwatchAction::getUnwatchToken( $title, $wgUser ),
327 );
328 $id = 'mw-unwatch-link';
329 } else {
330 $text = wfMessage( 'watchthispage' )->text();
331 $query = array(
332 'action' => 'watch',
333 'token' => WatchAction::getWatchToken( $title, $wgUser ),
334 );
335 $id = 'mw-watch-link';
336 }
337
338 $s = Linker::linkKnown(
339 $title,
340 $text,
341 array( 'id' => $id ),
342 $query
343 );
344 } else {
345 $s = wfMessage( 'notanarticle' )->text();
346 }
347
348 return $s;
349 }
350
351 function moveThisPage() {
352 if ( $this->getSkin()->getTitle()->quickUserCan( 'move' ) ) {
353 return Linker::linkKnown(
354 SpecialPage::getTitleFor( 'Movepage' ),
355 wfMessage( 'movethispage' )->text(),
356 array(),
357 array( 'target' => $this->getSkin()->getTitle()->getPrefixedDBkey() )
358 );
359 } else {
360 // no message if page is protected - would be redundant
361 return '';
362 }
363 }
364
365 function historyLink() {
366 return Linker::link(
367 $this->getSkin()->getTitle(),
368 wfMessage( 'history' )->escaped(),
369 array( 'rel' => 'archives' ),
370 array( 'action' => 'history' )
371 );
372 }
373
374 function whatLinksHere() {
375 return Linker::linkKnown(
376 SpecialPage::getTitleFor( 'Whatlinkshere', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
377 wfMessage( 'whatlinkshere' )->escaped()
378 );
379 }
380
381 function userContribsLink() {
382 return Linker::linkKnown(
383 SpecialPage::getTitleFor( 'Contributions', $this->getSkin()->getTitle()->getDBkey() ),
384 wfMessage( 'contributions' )->escaped()
385 );
386 }
387
388 function emailUserLink() {
389 return Linker::linkKnown(
390 SpecialPage::getTitleFor( 'Emailuser', $this->getSkin()->getTitle()->getDBkey() ),
391 wfMessage( 'emailuser' )->escaped()
392 );
393 }
394
395 function watchPageLinksLink() {
396 global $wgOut;
397
398 if ( !$wgOut->isArticleRelated() ) {
399 return wfMessage( 'parentheses', wfMessage( 'notanarticle' )->text() )->escaped();
400 } else {
401 return Linker::linkKnown(
402 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
403 wfMessage( 'recentchangeslinked-toolbox' )->escaped()
404 );
405 }
406 }
407
408 function talkLink() {
409 $title = $this->getSkin()->getTitle();
410 if ( NS_SPECIAL == $title->getNamespace() ) {
411 # No discussion links for special pages
412 return '';
413 }
414
415 $linkOptions = array();
416
417 if ( $title->isTalkPage() ) {
418 $link = $title->getSubjectPage();
419 switch( $link->getNamespace() ) {
420 case NS_MAIN:
421 $text = wfMessage( 'articlepage' );
422 break;
423 case NS_USER:
424 $text = wfMessage( 'userpage' );
425 break;
426 case NS_PROJECT:
427 $text = wfMessage( 'projectpage' );
428 break;
429 case NS_FILE:
430 $text = wfMessage( 'imagepage' );
431 # Make link known if image exists, even if the desc. page doesn't.
432 if ( wfFindFile( $link ) )
433 $linkOptions[] = 'known';
434 break;
435 case NS_MEDIAWIKI:
436 $text = wfMessage( 'mediawikipage' );
437 break;
438 case NS_TEMPLATE:
439 $text = wfMessage( 'templatepage' );
440 break;
441 case NS_HELP:
442 $text = wfMessage( 'viewhelppage' );
443 break;
444 case NS_CATEGORY:
445 $text = wfMessage( 'categorypage' );
446 break;
447 default:
448 $text = wfMessage( 'articlepage' );
449 }
450 } else {
451 $link = $title->getTalkPage();
452 $text = wfMessage( 'talkpage' );
453 }
454
455 $s = Linker::link( $link, $text->text(), array(), array(), $linkOptions );
456
457 return $s;
458 }
459
460 /**
461 * @return string
462 */
463 function beforeContent() {
464 $mainPageObj = Title::newMainPage();
465
466 $s = "\n<div id='content'>\n";
467 ob_start();
468 ?>
469 <div id="topbar">
470 <p id="sitetitle">
471 <a href="<?php echo htmlspecialchars( $mainPageObj->getLocalURL() ) ?>">
472 <?php echo wfMessage( 'sitetitle' )->escaped() ?>
473 </a>
474 </p>
475 <p id="sitesub">
476 <?php echo wfMessage( 'sitesubtitle' )->escaped() ?>
477 </p>
478
479 <p id="syslinks">
480 <span><?php echo $this->sysLinks() ?></span>
481 </p>
482 <div id="linkcollection">
483 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
484 <?php echo $this->getSkin()->getCategories() ?>
485 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
486 <?php if ( $this->data['newtalk'] ) { ?>
487 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
488 <?php } ?>
489 </div>
490 </div>
491 <?php
492 $s .= ob_get_contents();
493 ob_end_clean();
494
495 $s .= "\n<div id='article'>";
496
497 $notice = $this->getSkin()->getSiteNotice();
498 if( $notice ) {
499 $s .= "\n<div id='siteNotice'>$notice</div>\n";
500 }
501
502 $s .= '<h1 id="firstHeading"><span dir="auto">' . $this->data['title'] . '</span></h1>';
503
504 if ( $this->translator->translate( 'tagline' ) ) {
505 $s .= "<p class='tagline'>" . htmlspecialchars( $this->translator->translate( 'tagline' ) ) . "</p>";
506 }
507 if ( $this->getSkin()->getOutput()->getSubtitle() ) {
508 $s .= "<p class='subtitle'>" . $this->getSkin()->getOutput()->getSubtitle() . "</p>";
509 }
510 if ( $this->getSkin()->subPageSubtitle() ) {
511 $s .= "<p class='subpages'>" . $this->getSkin()->subPageSubtitle() . "</p>";
512 }
513
514 return $s;
515 }
516
517 /**
518 * @return string
519 */
520 function afterContent(){
521 $s = "\n</div>\n";
522
523 $s .= "\n<div id='footer'>";
524
525 $s .= $this->bottomLinks();
526 $s .= $this->getSkin()->getLanguage()->pipeList( array(
527 "\n<br />" . Linker::linkKnown(
528 Title::newMainPage()
529 ),
530 $this->getSkin()->aboutLink(),
531 $this->searchForm( 'afterContent' )
532 ) );
533
534 $s .= "\n<br />";
535 $footlinks = $this->getFooterLinks();
536 if ( $footlinks['info'] ) {
537 foreach ( $footlinks['info'] as $item ) {
538 $s .= $this->data[$item] . ' ';
539 }
540 }
541
542 $s .= "\n</div>\n</div>\n";
543
544 $s .= $this->quickBar();
545 return $s;
546 }
547
548 /**
549 * @return string
550 */
551 function sysLinks() {
552 $personalUrls = $this->data['personal_urls'];
553
554 $s = array(
555 $this->getSkin()->mainPageLink(),
556 Linker::linkKnown(
557 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
558 wfMessage( 'about' )->text()
559 ),
560 Linker::linkKnown(
561 Title::newFromText( wfMessage( 'helppage' )->inContentLanguage()->text() ),
562 wfMessage( 'help' )->text()
563 ),
564 Linker::linkKnown(
565 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
566 wfMessage( 'faq' )->text()
567 ),
568 Linker::specialLink( 'Specialpages' )
569 );
570
571 /* show links to different language variants */
572 if( $this->variantLinks() ) {
573 $s[] = $this->variantLinks();
574 }
575 if( $this->extensionTabLinks() ) {
576 $s[] = $this->extensionTabLinks();
577 }
578 if ( $this->data['loggedin'] ) {
579 $s[] = $this->makeLink( 'logout', $personalUrls['logout'] );
580 } else {
581 if ( $personalUrls['createaccount'] ) { // Controlled by $wgUseCombinedLoginLink
582 $s[] = $this->makeLink( 'createaccount', $personalUrls['createaccount'] );
583 }
584 if ( $personalUrls['login'] ) {
585 $s[] = $this->makeLink( 'login', $personalUrls['login'] );
586 }
587 if ( $personalUrls['anonlogin'] ) {
588 $s[] = $this->makeLink( 'anonlogin', $personalUrls['anonlogin'] );
589 }
590 }
591
592 return $this->getSkin()->getLanguage()->pipeList( $s );
593 }
594
595
596
597
598 /**
599 * @param $heading string
600 * @return string
601 *
602 * @fixed
603 */
604 function menuHead( $heading ) {
605 return "\n<h6>" . htmlspecialchars( $heading ) . "</h6>";
606 }
607
608 /**
609 * Compute the sidebar
610 * @access private
611 *
612 * @return string
613 *
614 * @fixed
615 */
616 function quickBar(){
617 $s = "\n<div id='quickbar'>";
618
619 $sep = "<br />\n";
620
621 $plain_bar = $this->data['sidebar'];
622 $bar = array();
623
624 // Massage the sidebar
625 // We want to place SEARCH at the beginning and a lot of stuff before TOOLBOX (or at the end, if it's missing)
626 $additions_done = false;
627 while ( !$additions_done ) {
628 $bar = array(); // Empty it out
629
630 // Always display search on top
631 $bar['SEARCH'] = true;
632
633 foreach ( $plain_bar as $heading => $links ) {
634 if ( $heading == 'TOOLBOX' ) {
635 if( $links !== NULL ) {
636 // If this is not a toolbox prosthetic we inserted outselves, fill it out
637 $plain_bar['TOOLBOX'] = $this->getToolbox();
638 }
639
640 // And insert the stuff
641
642 // "This page" and "Edit" menus
643 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
644 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
645 // We also don't use $...['variants'], these are displayed in the top menu.
646 $content_navigation = $this->data['content_navigation'];
647 $qbpageoptions = array_merge(
648 $content_navigation['namespaces'],
649 array(
650 'history' => $content_navigation['views']['history'],
651 'watch' => $content_navigation['actions']['watch'],
652 'unwatch' => $content_navigation['actions']['unwatch'],
653 )
654 );
655 $content_navigation['actions']['watch'] = null;
656 $content_navigation['actions']['unwatch'] = null;
657 $qbedit = array_merge(
658 array(
659 'edit' => $content_navigation['views']['edit'],
660 'addsection' => $content_navigation['views']['addsection'],
661 ),
662 $content_navigation['actions']
663 );
664 $bar['qbedit'] = $qbedit;
665 $bar['qbpageoptions'] = $qbpageoptions;
666
667 // Personal tools ("My pages")
668 $bar['qbmyoptions'] = $this->getPersonalTools();
669 $bar['qbmyoptions']['login'] = false;
670 $bar['qbmyoptions']['anonlogin'] = false;
671 $bar['qbmyoptions']['logout'] = false;
672 $bar['qbmyoptions']['createaccount'] = false;
673
674 $additions_done = true;
675 }
676
677 // Re-insert current heading, unless it's SEARCH
678 if ( $heading != 'SEARCH' ) {
679 $bar[$heading] = $plain_bar[$heading];
680 }
681 }
682
683 // If TOOLBOX is missing, $additions_done is still false
684 if ( !$additions_done ) {
685 $plain_bar['TOOLBOX'] = false;
686 }
687 }
688
689 foreach ( $bar as $heading => $links ) {
690 if ( $heading == 'SEARCH' ) {
691 $s .= $this->menuHead( wfMessage( 'qbfind' )->text() );
692 $s .= $this->searchForm( 'sidebar' );
693 } elseif ( $heading == 'LANGUAGES' ) {
694 // discard these; we display languages below page content
695 } else {
696 if ( $links ) {
697 // Use the navigation heading from standard sidebar as the "browse" section
698 if ( $heading == 'navigation' ) {
699 $heading = 'qbbrowse';
700 }
701 if ( $heading == 'TOOLBOX' ) {
702 $heading = 'toolbox';
703 }
704
705 $headingMsg = wfMessage( $heading );
706 $any_link = false;
707 $t = $this->menuHead( $headingMsg->exists() ? $headingMsg->text() : $heading );
708
709 foreach ( $links as $key => $link ) {
710 // Can be empty due to rampant sidebar massaging we're doing above
711 if ( $link ) {
712 $any_link = true;
713 $t .= $this->makeListItem( $key, $link, array( 'tag' => 'span' ) ) . $sep;
714 }
715 }
716
717 if ( $any_link ) {
718 $s .= $t;
719 }
720 }
721 }
722 }
723
724 $s .= $sep . "\n</div>\n";
725 return $s;
726 }
727
728 /**
729 * @param $label string
730 * @return string
731 *
732 * @fixed
733 */
734 function searchForm( $which ) {
735 global $wgUseTwoButtonsSearchForm;
736
737 $search = $this->getSkin()->getRequest()->getText( 'search' );
738 $action = $this->data['searchaction'];
739 $s = "<form id=\"searchform-" . htmlspecialchars($which) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
740 if( $which == 'afterContent' ) {
741 $s .= wfMessage( 'qbfind' )->text() . ": ";
742 }
743
744 $s .= "<input type='text' class=\"mw-searchInput\" name=\"search\" size=\"14\" value=\""
745 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />"
746 . ($which == 'afterContent' ? " " : "<br />")
747 . "<input type='submit' class=\"searchButton\" name=\"go\" value=\"" . wfMessage( 'searcharticle' )->escaped() . "\" />";
748
749 if( $wgUseTwoButtonsSearchForm ) {
750 $s .= " <input type='submit' class=\"searchButton\" name=\"fulltext\" value=\"" . wfMessage( 'search' )->escaped() . "\" />\n";
751 } else {
752 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
753 }
754
755 $s .= '</form>';
756
757 return $s;
758 }
759 }