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