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