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