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