Merge "Add wfSuppressWarnings(); to CologneBlue."
[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 function talkLink() {
345 $title = $this->getSkin()->getTitle();
346 if ( NS_SPECIAL == $title->getNamespace() ) {
347 # No discussion links for special pages
348 return '';
349 }
350
351 $linkOptions = array();
352
353 if ( $title->isTalkPage() ) {
354 $link = $title->getSubjectPage();
355 switch( $link->getNamespace() ) {
356 case NS_MAIN:
357 $text = wfMessage( 'articlepage' );
358 break;
359 case NS_USER:
360 $text = wfMessage( 'userpage' );
361 break;
362 case NS_PROJECT:
363 $text = wfMessage( 'projectpage' );
364 break;
365 case NS_FILE:
366 $text = wfMessage( 'imagepage' );
367 # Make link known if image exists, even if the desc. page doesn't.
368 if ( wfFindFile( $link ) )
369 $linkOptions[] = 'known';
370 break;
371 case NS_MEDIAWIKI:
372 $text = wfMessage( 'mediawikipage' );
373 break;
374 case NS_TEMPLATE:
375 $text = wfMessage( 'templatepage' );
376 break;
377 case NS_HELP:
378 $text = wfMessage( 'viewhelppage' );
379 break;
380 case NS_CATEGORY:
381 $text = wfMessage( 'categorypage' );
382 break;
383 default:
384 $text = wfMessage( 'articlepage' );
385 }
386 } else {
387 $link = $title->getTalkPage();
388 $text = wfMessage( 'talkpage' );
389 }
390
391 $s = Linker::link( $link, $text->text(), array(), array(), $linkOptions );
392
393 return $s;
394 }
395
396 /**
397 * @return string
398 *
399 * @fixed
400 */
401 function beforeContent() {
402 ob_start();
403 ?>
404 <div id="content">
405 <div id="topbar">
406 <p id="sitetitle">
407 <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
408 <?php echo wfMessage( 'sitetitle' )->escaped() ?>
409 </a>
410 </p>
411 <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
412 <div id="toplinks">
413 <p id="syslinks"><?php echo $this->sysLinks() ?></p>
414 <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
415 </div>
416 <div id="linkcollection">
417 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
418 <?php echo $this->getSkin()->getCategories() ?>
419 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
420 <?php if ( $this->data['newtalk'] ) { ?>
421 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
422 <?php } ?>
423 </div>
424 </div>
425 <div id="article">
426 <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
427 <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
428 <?php } ?>
429 <h1 id="firstHeading"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
430 <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
431 <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
432 <?php } ?>
433 <?php if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?>
434 <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
435 <?php } ?>
436 <?php if ( $this->getSkin()->subPageSubtitle() ) { ?>
437 <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
438 <?php } ?>
439 <?php
440 $s = ob_get_contents();
441 ob_end_clean();
442
443 return $s;
444 }
445
446 /**
447 * @return string
448 *
449 * @fixed
450 */
451 function afterContent() {
452 ob_start();
453 ?>
454 </div>
455 <div id='footer'>
456 <?php
457 // Page-related links
458 echo $this->bottomLinks();
459 echo "\n<br />";
460
461 // Footer and second searchbox
462 echo $this->getSkin()->getLanguage()->pipeList( array(
463 $this->getSkin()->mainPageLink(),
464 $this->getSkin()->aboutLink(),
465 $this->searchForm( 'footer' )
466 ) );
467 echo "\n<br />";
468
469 // Standard footer info
470 $footlinks = $this->getFooterLinks();
471 if ( $footlinks['info'] ) {
472 foreach ( $footlinks['info'] as $item ) {
473 echo $this->data[$item] . ' ';
474 }
475 }
476 ?>
477 </div>
478 </div>
479 <?php echo $this->quickBar() ?>
480 <?php
481 $s = ob_get_contents();
482 ob_end_clean();
483
484 return $s;
485 }
486
487 /**
488 * @return string
489 *
490 * @fixed
491 */
492 function sysLinks() {
493 $s = array(
494 $this->getSkin()->mainPageLink(),
495 Linker::linkKnown(
496 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
497 wfMessage( 'about' )->text()
498 ),
499 Linker::linkKnown(
500 Title::newFromText( wfMessage( 'helppage' )->inContentLanguage()->text() ),
501 wfMessage( 'help' )->text()
502 ),
503 Linker::linkKnown(
504 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
505 wfMessage( 'faq' )->text()
506 ),
507 );
508
509 $personalUrls = $this->getPersonalTools();
510 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
511 if ( $personalUrls[$key] ) {
512 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
513 }
514 }
515
516 return $this->getSkin()->getLanguage()->pipeList( $s );
517 }
518
519 /**
520 * @param $heading string
521 * @return string
522 *
523 * @fixed
524 */
525 function menuHead( $heading ) {
526 return "\n<h6>" . htmlspecialchars( $heading ) . "</h6>";
527 }
528
529 /**
530 * Compute the sidebar
531 * @access private
532 *
533 * @return string
534 *
535 * @fixed
536 */
537 function quickBar(){
538 $s = "\n<div id='quickbar'>";
539
540 $sep = "<br />\n";
541
542 $plain_bar = $this->data['sidebar'];
543 $bar = array();
544
545 // Massage the sidebar
546 // We want to place SEARCH at the beginning and a lot of stuff before TOOLBOX (or at the end, if it's missing)
547 $additions_done = false;
548 while ( !$additions_done ) {
549 $bar = array(); // Empty it out
550
551 // Always display search on top
552 $bar['SEARCH'] = true;
553
554 foreach ( $plain_bar as $heading => $links ) {
555 if ( $heading == 'TOOLBOX' ) {
556 if( $links !== NULL ) {
557 // If this is not a toolbox prosthetic we inserted outselves, fill it out
558 $plain_bar['TOOLBOX'] = $this->getToolbox();
559 }
560
561 // And insert the stuff
562
563 // "This page" and "Edit" menus
564 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
565 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
566 // We also don't use $...['variants'], these are displayed in the top menu.
567 $content_navigation = $this->data['content_navigation'];
568 $qbpageoptions = array_merge(
569 $content_navigation['namespaces'],
570 array(
571 'history' => $content_navigation['views']['history'],
572 'watch' => $content_navigation['actions']['watch'],
573 'unwatch' => $content_navigation['actions']['unwatch'],
574 )
575 );
576 $content_navigation['actions']['watch'] = null;
577 $content_navigation['actions']['unwatch'] = null;
578 $qbedit = array_merge(
579 array(
580 'edit' => $content_navigation['views']['edit'],
581 'addsection' => $content_navigation['views']['addsection'],
582 ),
583 $content_navigation['actions']
584 );
585 $bar['qbedit'] = $qbedit;
586 $bar['qbpageoptions'] = $qbpageoptions;
587
588 // Personal tools ("My pages")
589 $bar['qbmyoptions'] = $this->getPersonalTools();
590 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
591 $bar['qbmyoptions'][$key] = null;
592 }
593
594 $additions_done = true;
595 }
596
597 // Re-insert current heading, unless it's SEARCH
598 if ( $heading != 'SEARCH' ) {
599 $bar[$heading] = $plain_bar[$heading];
600 }
601 }
602
603 // If TOOLBOX is missing, $additions_done is still false
604 if ( !$additions_done ) {
605 $plain_bar['TOOLBOX'] = false;
606 }
607 }
608
609 foreach ( $bar as $heading => $links ) {
610 if ( $heading == 'SEARCH' ) {
611 $s .= $this->menuHead( wfMessage( 'qbfind' )->text() );
612 $s .= $this->searchForm( 'sidebar' );
613 } elseif ( $heading == 'LANGUAGES' ) {
614 // discard these; we display languages below page content
615 } elseif ( $links ) {
616 if ( is_array( $links ) ) {
617 // Use the navigation heading from standard sidebar as the "browse" section
618 if ( $heading == 'navigation' ) {
619 $heading = 'qbbrowse';
620 }
621 if ( $heading == 'TOOLBOX' ) {
622 $heading = 'toolbox';
623 }
624
625 $headingMsg = wfMessage( $heading );
626 $any_link = false;
627 $t = $this->menuHead( $headingMsg->exists() ? $headingMsg->text() : $heading );
628
629 foreach ( $links as $key => $link ) {
630 // Can be empty due to rampant sidebar massaging we're doing above
631 if ( $link ) {
632 $any_link = true;
633 $t .= $this->makeListItem( $key, $link, array( 'tag' => 'span' ) ) . $sep;
634 }
635 }
636
637 if ( $any_link ) {
638 $s .= $t;
639 }
640 } else {
641 // $links can be a HTML string
642 $s .= $links;
643 }
644 }
645 }
646
647 $s .= $sep . "\n</div>\n";
648 return $s;
649 }
650
651 /**
652 * @param $label string
653 * @return string
654 *
655 * @fixed
656 */
657 function searchForm( $which ) {
658 global $wgUseTwoButtonsSearchForm;
659
660 $search = $this->getSkin()->getRequest()->getText( 'search' );
661 $action = $this->data['searchaction'];
662 $s = "<form id=\"searchform-" . htmlspecialchars($which) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
663 if( $which == 'footer' ) {
664 $s .= wfMessage( 'qbfind' )->text() . ": ";
665 }
666
667 $s .= "<input type='text' class=\"mw-searchInput\" name=\"search\" size=\"14\" value=\""
668 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />"
669 . ($which == 'footer' ? " " : "<br />")
670 . "<input type='submit' class=\"searchButton\" name=\"go\" value=\"" . wfMessage( 'searcharticle' )->escaped() . "\" />";
671
672 if( $wgUseTwoButtonsSearchForm ) {
673 $s .= " <input type='submit' class=\"searchButton\" name=\"fulltext\" value=\"" . wfMessage( 'searchbutton' )->escaped() . "\" />\n";
674 } else {
675 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
676 }
677
678 $s .= '</form>';
679
680 return $s;
681 }
682 }