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