bd8a6776ac3005f9df92931ec68d2bf19f7bc410
[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 public $skinname = 'cologneblue';
35 public $stylename = 'cologneblue';
36 public $template = 'CologneBlueTemplate';
37 public $useHeadElement = true;
38
39 /**
40 * @param OutputPage $out
41 */
42 function setupSkinUserCss( OutputPage $out ) {
43 parent::setupSkinUserCss( $out );
44 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
45 $out->addModuleStyles( 'skins.cologneblue' );
46 }
47
48 /**
49 * Override langlink formatting behavior not to uppercase the language names.
50 * See otherLanguages() in CologneBlueTemplate.
51 * @param string $name
52 * @return string
53 */
54 function formatLanguageName( $name ) {
55 return $name;
56 }
57 }
58
59 class CologneBlueTemplate extends BaseTemplate {
60 function execute() {
61 // Suppress warnings to prevent notices about missing indexes in $this->data
62 wfSuppressWarnings();
63 $this->html( 'headelement' );
64 echo $this->beforeContent();
65 $this->html( 'bodytext' );
66 echo "\n";
67 echo $this->afterContent();
68 $this->html( 'dataAfterContent' );
69 $this->printTrail();
70 echo "\n</body></html>";
71 wfRestoreWarnings();
72 }
73
74 /**
75 * Language/charset variant links for classic-style skins
76 * @return string
77 */
78 function variantLinks() {
79 $s = array();
80
81 $variants = $this->data['content_navigation']['variants'];
82
83 foreach ( $variants as $key => $link ) {
84 $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
85 }
86
87 return $this->getSkin()->getLanguage()->pipeList( $s );
88 }
89
90 function otherLanguages() {
91 global $wgHideInterlanguageLinks;
92 if ( $wgHideInterlanguageLinks ) {
93 return "";
94 }
95
96 $html = '';
97
98 // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
99 // not to capitalize the language names.
100 $language_urls = $this->data['language_urls'];
101 if ( !empty( $language_urls ) ) {
102 $s = array();
103 foreach ( $language_urls as $key => $data ) {
104 $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
105 }
106
107 $html = wfMessage( 'otherlanguages' )->text()
108 . wfMessage( 'colon-separator' )->text()
109 . $this->getSkin()->getLanguage()->pipeList( $s );
110 }
111
112 $html .= $this->renderAfterPortlet( 'lang' );
113
114 return $html;
115 }
116
117 /**
118 * @param string $name
119 */
120 protected function renderAfterPortlet( $name ) {
121 $content = '';
122 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
123
124 $html = $content !== '' ? "<div class='after-portlet after-portlet-$name'>$content</div>" : '';
125
126 return $html;
127 }
128
129 function pageTitleLinks() {
130 $s = array();
131 $footlinks = $this->getFooterLinks();
132
133 foreach ( $footlinks['places'] as $item ) {
134 $s[] = $this->data[$item];
135 }
136
137 return $this->getSkin()->getLanguage()->pipeList( $s );
138 }
139
140 /**
141 * Used in bottomLinks() to eliminate repetitive code.
142 *
143 * @param string $key Key to be passed to makeListItem()
144 * @param array $navlink Navlink suitable for processNavlinkForDocument()
145 * @param string $message Key of the message to use in place of standard text
146 *
147 * @return string
148 */
149 function processBottomLink( $key, $navlink, $message = null ) {
150 if ( !$navlink ) {
151 // Empty navlinks might be passed.
152 return null;
153 }
154
155 if ( $message ) {
156 $navlink['text'] = wfMessage( $message )->escaped();
157 }
158
159 return $this->makeListItem(
160 $key,
161 $this->processNavlinkForDocument( $navlink ),
162 array( 'tag' => 'span' )
163 );
164 }
165
166 function bottomLinks() {
167 $toolbox = $this->getToolbox();
168 $content_nav = $this->data['content_navigation'];
169
170 $lines = array();
171
172 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
173 // First row. Regular actions.
174 $element = array();
175
176 $editLinkMessage = $this->getSkin()->getTitle()->exists() ? 'editthispage' : 'create-this-page';
177 $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
178 $element[] = $this->processBottomLink(
179 'viewsource',
180 $content_nav['views']['viewsource'],
181 'viewsource'
182 );
183
184 $element[] = $this->processBottomLink(
185 'watch',
186 $content_nav['actions']['watch'],
187 'watchthispage'
188 );
189 $element[] = $this->processBottomLink(
190 'unwatch',
191 $content_nav['actions']['unwatch'],
192 'unwatchthispage'
193 );
194
195 $element[] = $this->talkLink();
196
197 $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
198 $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
199 $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
200 $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
201
202 $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
203 $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
204
205 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
206
207 // Second row. Privileged actions.
208 $element = array();
209
210 $element[] = $this->processBottomLink(
211 'delete',
212 $content_nav['actions']['delete'],
213 'deletethispage'
214 );
215 $element[] = $this->processBottomLink(
216 'undelete',
217 $content_nav['actions']['undelete'],
218 'undeletethispage'
219 );
220
221 $element[] = $this->processBottomLink(
222 'protect',
223 $content_nav['actions']['protect'],
224 'protectthispage'
225 );
226 $element[] = $this->processBottomLink(
227 'unprotect',
228 $content_nav['actions']['unprotect'],
229 'unprotectthispage'
230 );
231
232 $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
233
234 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
235
236 // Third row. Language links.
237 $lines[] = $this->otherLanguages();
238 }
239
240 return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
241 }
242
243 function talkLink() {
244 $title = $this->getSkin()->getTitle();
245
246 if ( $title->getNamespace() == NS_SPECIAL ) {
247 // No discussion links for special pages
248 return "";
249 }
250
251 $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
252 $companionNamespace = $companionTitle->getNamespace();
253
254 // TODO these messages are only be used by CologneBlue,
255 // kill and replace with something more sensibly named?
256 $nsToMessage = array(
257 NS_MAIN => 'articlepage',
258 NS_USER => 'userpage',
259 NS_PROJECT => 'projectpage',
260 NS_FILE => 'imagepage',
261 NS_MEDIAWIKI => 'mediawikipage',
262 NS_TEMPLATE => 'templatepage',
263 NS_HELP => 'viewhelppage',
264 NS_CATEGORY => 'categorypage',
265 NS_FILE => 'imagepage',
266 );
267
268 // Find out the message to use for link text. Use either the array above or,
269 // for non-talk pages, a generic "discuss this" message.
270 // Default is the same as for main namespace.
271 if ( isset( $nsToMessage[$companionNamespace] ) ) {
272 $message = $nsToMessage[$companionNamespace];
273 } else {
274 $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage';
275 }
276
277 // Obviously this can't be reasonable and just return the key for talk
278 // namespace, only for content ones. Thus we have to mangle it in
279 // exactly the same way SkinTemplate does. (bug 40805)
280 $key = $companionTitle->getNamespaceKey( '' );
281 if ( $companionTitle->isTalkPage() ) {
282 $key = ( $key == 'main' ? 'talk' : $key . "_talk" );
283 }
284
285 // Use the regular navigational link, but replace its text. Everything else stays unmodified.
286 $namespacesLinks = $this->data['content_navigation']['namespaces'];
287 return $this->processBottomLink( $message, $namespacesLinks[$key], $message );
288 }
289
290 /**
291 * Takes a navigational link generated by SkinTemplate in whichever way
292 * and mangles attributes unsuitable for repeated use. In particular, this
293 * modifies the ids and removes the accesskeys. This is necessary to be
294 * able to use the same navlink twice, e.g. in sidebar and in footer.
295 *
296 * @param array $navlink Navigational link generated by SkinTemplate
297 * @param mixed $idPrefix Prefix to add to id of this navlink. If false, id
298 * is removed entirely. Default is 'cb-'.
299 */
300 function processNavlinkForDocument( $navlink, $idPrefix = 'cb-' ) {
301 if ( $navlink['id'] ) {
302 $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
303 $navlink['tooltiponly'] = true; // but no accesskeys
304
305 // mangle or remove the id
306 if ( $idPrefix === false ) {
307 unset( $navlink['id'] );
308 } else {
309 $navlink['id'] = $idPrefix . $navlink['id'];
310 }
311 }
312
313 return $navlink;
314 }
315
316 /**
317 * @return string
318 */
319 function beforeContent() {
320 ob_start();
321 ?>
322 <div id="content">
323 <div id="topbar">
324 <p id="sitetitle" role="banner">
325 <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
326 <?php echo wfMessage( 'sitetitle' )->escaped() ?>
327 </a>
328 </p>
329 <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
330 <div id="linkcollection" role="navigation">
331 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
332 <?php echo $this->getSkin()->getCategories() ?>
333 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
334 <?php
335 if ( $this->data['newtalk'] ) {
336 ?>
337 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
338 <?php
339 }
340 ?>
341 </div>
342 </div>
343 <div id="article" class="mw-body" role="main">
344 <?php
345 if ( $this->getSkin()->getSiteNotice() ) {
346 ?>
347 <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
348 <?php
349 }
350 ?>
351 <h1 id="firstHeading" lang="<?php
352 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
353 $this->text( 'pageLanguage' );
354 ?>"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
355 <?php
356 if ( $this->translator->translate( 'tagline' ) ) {
357 ?>
358 <p class="tagline"><?php
359 echo htmlspecialchars( $this->translator->translate( 'tagline' ) )
360 ?></p>
361 <?php
362 }
363 ?>
364 <?php
365 if ( $this->getSkin()->getOutput()->getSubtitle() ) {
366 ?>
367 <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
368 <?php
369 }
370 ?>
371 <?php
372 if ( $this->getSkin()->subPageSubtitle() ) {
373 ?>
374 <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
375 <?php
376 }
377 ?>
378 <?php
379 $s = ob_get_contents();
380 ob_end_clean();
381
382 return $s;
383 }
384
385 /**
386 * @return string
387 */
388 function afterContent() {
389 ob_start();
390 ?>
391 </div>
392 <div id="footer">
393 <div id="footer-navigation" role="navigation">
394 <?php
395 // Page-related links
396 echo $this->bottomLinks();
397 echo "\n<br />";
398
399 // Footer and second searchbox
400 echo $this->getSkin()->getLanguage()->pipeList( array(
401 $this->getSkin()->mainPageLink(),
402 $this->getSkin()->aboutLink(),
403 $this->searchForm( 'footer' )
404 ) );
405 ?>
406 </div>
407 <div id="footer-info" role="contentinfo">
408 <?php
409 // Standard footer info
410 $footlinks = $this->getFooterLinks();
411 if ( $footlinks['info'] ) {
412 foreach ( $footlinks['info'] as $item ) {
413 echo $this->data[$item] . ' ';
414 }
415 }
416 ?>
417 </div>
418 </div>
419 </div>
420 <div id="mw-navigation">
421 <h2><?php echo wfMessage( 'navigation-heading' )->escaped() ?></h2>
422 <div id="toplinks" role="navigation">
423 <p id="syslinks"><?php echo $this->sysLinks() ?></p>
424 <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
425 </div>
426 <?php echo $this->quickBar() ?>
427 </div>
428 <?php
429 $s = ob_get_contents();
430 ob_end_clean();
431
432 return $s;
433 }
434
435 /**
436 * @return string
437 */
438 function sysLinks() {
439 $s = array(
440 $this->getSkin()->mainPageLink(),
441 Linker::linkKnown(
442 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
443 wfMessage( 'about' )->text()
444 ),
445 Linker::makeExternalLink(
446 Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ),
447 wfMessage( 'help' )->text(),
448 false
449 ),
450 Linker::linkKnown(
451 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
452 wfMessage( 'faq' )->text()
453 ),
454 );
455
456 $personalUrls = $this->getPersonalTools();
457 foreach ( array( 'logout', 'createaccount', 'login' ) as $key ) {
458 if ( $personalUrls[$key] ) {
459 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
460 }
461 }
462
463 return $this->getSkin()->getLanguage()->pipeList( $s );
464 }
465
466 /**
467 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
468 *
469 * @param array $bar Sidebar data
470 * @return array Modified sidebar data
471 */
472 function sidebarAdditions( $bar ) {
473 // "This page" and "Edit" menus
474 // We need to do some massaging here... we reuse all of the items,
475 // except for $...['views']['view'], as $...['namespaces']['main'] and
476 // $...['namespaces']['talk'] together serve the same purpose. We also
477 // don't use $...['variants'], these are displayed in the top menu.
478 $content_navigation = $this->data['content_navigation'];
479 $qbpageoptions = array_merge(
480 $content_navigation['namespaces'],
481 array(
482 'history' => $content_navigation['views']['history'],
483 'watch' => $content_navigation['actions']['watch'],
484 'unwatch' => $content_navigation['actions']['unwatch'],
485 )
486 );
487 $content_navigation['actions']['watch'] = null;
488 $content_navigation['actions']['unwatch'] = null;
489 $qbedit = array_merge(
490 array(
491 'edit' => $content_navigation['views']['edit'],
492 'addsection' => $content_navigation['views']['addsection'],
493 ),
494 $content_navigation['actions']
495 );
496
497 // Personal tools ("My pages")
498 $qbmyoptions = $this->getPersonalTools();
499 foreach ( array( 'logout', 'createaccount', 'login', ) as $key ) {
500 $qbmyoptions[$key] = null;
501 }
502
503 // Use the closest reasonable name
504 $bar['cactions'] = $qbedit;
505 $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
506 $bar['personal'] = $qbmyoptions;
507
508 return $bar;
509 }
510
511 /**
512 * Compute the sidebar
513 * @access private
514 *
515 * @return string
516 */
517 function quickBar() {
518 // Massage the sidebar. We want to:
519 // * place SEARCH at the beginning
520 // * add new portlets before TOOLBOX (or at the end, if it's missing)
521 // * remove LANGUAGES (langlinks are displayed elsewhere)
522 $orig_bar = $this->data['sidebar'];
523 $bar = array();
524 $hasToolbox = false;
525
526 // Always display search first
527 $bar['SEARCH'] = true;
528 // Copy everything except for langlinks, inserting new items before toolbox
529 foreach ( $orig_bar as $heading => $data ) {
530 if ( $heading == 'TOOLBOX' ) {
531 // Insert the stuff
532 $bar = $this->sidebarAdditions( $bar );
533 $hasToolbox = true;
534 }
535
536 if ( $heading != 'LANGUAGES' ) {
537 $bar[$heading] = $data;
538 }
539 }
540 // If toolbox is missing, add our items at the end
541 if ( !$hasToolbox ) {
542 $bar = $this->sidebarAdditions( $bar );
543 }
544
545 // Fill out special sidebar items with content
546 $orig_bar = $bar;
547 $bar = array();
548 foreach ( $orig_bar as $heading => $data ) {
549 if ( $heading == 'SEARCH' ) {
550 $bar['search'] = $this->searchForm( 'sidebar' );
551 } elseif ( $heading == 'TOOLBOX' ) {
552 $bar['tb'] = $this->getToolbox();
553 } else {
554 $bar[$heading] = $data;
555 }
556 }
557
558 // Output the sidebar
559 // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
560 $idToMessage = array(
561 'search' => 'qbfind',
562 'navigation' => 'qbbrowse',
563 'tb' => 'toolbox',
564 'cactions' => 'qbedit',
565 'personal' => 'qbmyoptions',
566 'pageoptions' => 'qbpageoptions',
567 );
568
569 $s = "<div id='quickbar'>\n";
570
571 foreach ( $bar as $heading => $data ) {
572 $portletId = Sanitizer::escapeId( "p-$heading" );
573 $headingMsg = wfMessage( $idToMessage[$heading] ? $idToMessage[$heading] : $heading );
574 $headingHTML = "<h3>";
575 $headingHTML .= $headingMsg->exists()
576 ? $headingMsg->escaped()
577 : htmlspecialchars( $heading );
578 $headingHTML .= "</h3>";
579 $listHTML = "";
580
581 if ( is_array( $data ) ) {
582 // $data is an array of links
583 foreach ( $data as $key => $link ) {
584 // Can be empty due to how the sidebar additions are done
585 if ( $link ) {
586 $listHTML .= $this->makeListItem( $key, $link );
587 }
588 }
589 if ( $listHTML ) {
590 $listHTML = "<ul>$listHTML</ul>";
591 }
592 } else {
593 // $data is a HTML <ul>-list string
594 $listHTML = $data;
595 }
596
597 if ( $listHTML ) {
598 $role = ( $heading == 'search' ) ? 'search' : 'navigation';
599 $s .= "<div class=\"portlet\" id=\"$portletId\" "
600 . "role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
601 }
602
603 $s .= $this->renderAfterPortlet( $heading );
604 }
605
606 $s .= "</div>\n";
607 return $s;
608 }
609
610 /**
611 * @param string $label
612 * @return string
613 */
614 function searchForm( $which ) {
615 global $wgUseTwoButtonsSearchForm;
616
617 $search = $this->getSkin()->getRequest()->getText( 'search' );
618 $action = $this->data['searchaction'];
619 $s = "<form id=\"searchform-" . htmlspecialchars( $which )
620 . "\" method=\"get\" class=\"inline\" action=\"$action\">";
621 if ( $which == 'footer' ) {
622 $s .= wfMessage( 'qbfind' )->text() . ": ";
623 }
624
625 $s .= $this->makeSearchInput( array(
626 'class' => 'mw-searchInput',
627 'type' => 'text',
628 'size' => '14'
629 ) );
630 $s .= ( $which == 'footer' ? " " : "<br />" );
631 $s .= $this->makeSearchButton( 'go', array( 'class' => 'searchButton' ) );
632
633 if ( $wgUseTwoButtonsSearchForm ) {
634 $s .= $this->makeSearchButton( 'fulltext', array( 'class' => 'searchButton' ) );
635 } else {
636 $s .= '<div><a href="' . $action . '" rel="search">'
637 . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
638 }
639
640 $s .= '</form>';
641
642 return $s;
643 }
644 }