Implement static public Parser::getExternalLinkRel
[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="toplinks" role="navigation">
289 <p id="syslinks"><?php echo $this->sysLinks() ?></p>
290 <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
291 </div>
292 <div id="linkcollection" role="navigation">
293 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
294 <?php echo $this->getSkin()->getCategories() ?>
295 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
296 <?php if ( $this->data['newtalk'] ) { ?>
297 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
298 <?php } ?>
299 </div>
300 </div>
301 <div id="article" role="main">
302 <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
303 <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
304 <?php } ?>
305 <h1 id="firstHeading"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
306 <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
307 <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
308 <?php } ?>
309 <?php if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?>
310 <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
311 <?php } ?>
312 <?php if ( $this->getSkin()->subPageSubtitle() ) { ?>
313 <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
314 <?php } ?>
315 <?php
316 $s = ob_get_contents();
317 ob_end_clean();
318
319 return $s;
320 }
321
322 /**
323 * @return string
324 *
325 * @fixed
326 */
327 function afterContent() {
328 ob_start();
329 ?>
330 </div>
331 <div id="footer" role="contentinfo">
332 <?php
333 // Page-related links
334 echo $this->bottomLinks();
335 echo "\n<br />";
336
337 // Footer and second searchbox
338 echo $this->getSkin()->getLanguage()->pipeList( array(
339 $this->getSkin()->mainPageLink(),
340 $this->getSkin()->aboutLink(),
341 $this->searchForm( 'footer' )
342 ) );
343 echo "\n<br />";
344
345 // Standard footer info
346 $footlinks = $this->getFooterLinks();
347 if ( $footlinks['info'] ) {
348 foreach ( $footlinks['info'] as $item ) {
349 echo $this->data[$item] . ' ';
350 }
351 }
352 ?>
353 </div>
354 </div>
355 <?php echo $this->quickBar() ?>
356 <?php
357 $s = ob_get_contents();
358 ob_end_clean();
359
360 return $s;
361 }
362
363 /**
364 * @return string
365 *
366 * @fixed
367 */
368 function sysLinks() {
369 $s = array(
370 $this->getSkin()->mainPageLink(),
371 Linker::linkKnown(
372 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
373 wfMessage( 'about' )->text()
374 ),
375 Linker::linkKnown(
376 Title::newFromText( wfMessage( 'helppage' )->inContentLanguage()->text() ),
377 wfMessage( 'help' )->text()
378 ),
379 Linker::linkKnown(
380 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
381 wfMessage( 'faq' )->text()
382 ),
383 );
384
385 $personalUrls = $this->getPersonalTools();
386 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
387 if ( $personalUrls[$key] ) {
388 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
389 }
390 }
391
392 return $this->getSkin()->getLanguage()->pipeList( $s );
393 }
394
395 /**
396 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
397 *
398 * @param $bar sidebar data
399 * @return array modified sidebar data
400 *
401 * @fixed
402 */
403 function sidebarAdditions( $bar ) {
404 // "This page" and "Edit" menus
405 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
406 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
407 // We also don't use $...['variants'], these are displayed in the top menu.
408 $content_navigation = $this->data['content_navigation'];
409 $qbpageoptions = array_merge(
410 $content_navigation['namespaces'],
411 array(
412 'history' => $content_navigation['views']['history'],
413 'watch' => $content_navigation['actions']['watch'],
414 'unwatch' => $content_navigation['actions']['unwatch'],
415 )
416 );
417 $content_navigation['actions']['watch'] = null;
418 $content_navigation['actions']['unwatch'] = null;
419 $qbedit = array_merge(
420 array(
421 'edit' => $content_navigation['views']['edit'],
422 'addsection' => $content_navigation['views']['addsection'],
423 ),
424 $content_navigation['actions']
425 );
426
427 // Personal tools ("My pages")
428 $qbmyoptions = $this->getPersonalTools();
429 foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
430 $qbmyoptions[$key] = null;
431 }
432
433 // Use the closest reasonable name
434 $bar['cactions'] = $qbedit;
435 $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
436 $bar['personal'] = $qbmyoptions;
437
438 return $bar;
439 }
440
441 /**
442 * Compute the sidebar
443 * @access private
444 *
445 * @return string
446 *
447 * @fixed
448 */
449 function quickBar() {
450 // Massage the sidebar. We want to:
451 // * place SEARCH at the beginning
452 // * add new portlets before TOOLBOX (or at the end, if it's missing)
453 // * remove LANGUAGES (langlinks are displayed elsewhere)
454 $orig_bar = $this->data['sidebar'];
455 $bar = array();
456 $hasToolbox = false;
457
458 // Always display search first
459 $bar['SEARCH'] = true;
460 // Copy everything except for langlinks, inserting new items before toolbox
461 foreach ( $orig_bar as $heading => $data ) {
462 if ( $heading == 'TOOLBOX' ) {
463 // Insert the stuff
464 $bar = $this->sidebarAdditions( $bar );
465 $hasToolbox = true;
466 }
467
468 if ( $heading != 'LANGUAGES' ) {
469 $bar[$heading] = $data;
470 }
471 }
472 // If toolbox is missing, add our items at the end
473 if ( !$hasToolbox ) {
474 $bar = $this->sidebarAdditions( $bar );
475 }
476
477
478 // Fill out special sidebar items with content
479 $orig_bar = $bar;
480 $bar = array();
481 foreach ( $orig_bar as $heading => $data ) {
482 if ( $heading == 'SEARCH' ) {
483 $bar['search'] = $this->searchForm( 'sidebar' );
484 } elseif ( $heading == 'TOOLBOX' ) {
485 $bar['tb'] = $this->getToolbox();
486 } else {
487 $bar[$heading] = $data;
488 }
489 }
490
491
492 // Output the sidebar
493 // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
494 $idToMessage = array(
495 'search' => 'qbfind',
496 'navigation' => 'qbbrowse',
497 'tb' => 'toolbox',
498 'cactions' => 'qbedit',
499 'personal' => 'qbmyoptions',
500 'pageoptions' => 'qbpageoptions',
501 );
502
503 $s = "<div id='quickbar'>\n";
504
505 foreach ( $bar as $heading => $data ) {
506 $portletId = Sanitizer::escapeId( "p-$heading" );
507 $headingMsg = wfMessage( $idToMessage[$heading] ? $idToMessage[$heading] : $heading );
508 $headingHTML = "<h6>" . ( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ) . "</h6>";
509 $listHTML = "";
510
511 if ( is_array( $data ) ) {
512 // $data is an array of links
513 foreach ( $data as $key => $link ) {
514 // Can be empty due to how the sidebar additions are done
515 if ( $link ) {
516 $listHTML .= $this->makeListItem( $key, $link );
517 }
518 }
519 if ( $listHTML ) {
520 $listHTML = "<ul>$listHTML</ul>";
521 }
522 } else {
523 // $data is a HTML <ul>-list string
524 $listHTML = $data;
525 }
526
527 if ( $listHTML ) {
528 $role = ( $heading == 'search' ) ? 'search' : 'navigation';
529 $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
530 }
531 }
532
533 $s .= "</div>\n";
534 return $s;
535 }
536
537 /**
538 * @param $label string
539 * @return string
540 *
541 * @fixed
542 */
543 function searchForm( $which ) {
544 global $wgUseTwoButtonsSearchForm;
545
546 $search = $this->getSkin()->getRequest()->getText( 'search' );
547 $action = $this->data['searchaction'];
548 $s = "<form id=\"searchform-" . htmlspecialchars($which) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
549 if( $which == 'footer' ) {
550 $s .= wfMessage( 'qbfind' )->text() . ": ";
551 }
552
553 $s .= "<input type='text' class=\"mw-searchInput\" name=\"search\" size=\"14\" value=\""
554 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />"
555 . ($which == 'footer' ? " " : "<br />")
556 . "<input type='submit' class=\"searchButton\" name=\"go\" value=\"" . wfMessage( 'searcharticle' )->escaped() . "\" />";
557
558 if( $wgUseTwoButtonsSearchForm ) {
559 $s .= " <input type='submit' class=\"searchButton\" name=\"fulltext\" value=\"" . wfMessage( 'searchbutton' )->escaped() . "\" />\n";
560 } else {
561 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
562 }
563
564 $s .= '</form>';
565
566 return $s;
567 }
568 }