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