Non-word characters don't terminate tag names.
[mediawiki.git] / skins / CologneBlue.php
blob5ae8843413a03b42d12bcbe8f97e42ea239c4fcd
1 <?php
2 /**
3 * Cologne Blue: A nicer-looking alternative to Standard.
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.
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.
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
20 * @todo document
21 * @file
22 * @ingroup Skins
25 if ( !defined( 'MEDIAWIKI' ) ) {
26 die( -1 );
29 /**
30 * @todo document
31 * @ingroup Skins
33 class SkinCologneBlue extends SkinTemplate {
34 var $skinname = 'cologneblue', $stylename = 'cologneblue',
35 $template = 'CologneBlueTemplate';
36 var $useHeadElement = true;
38 /**
39 * @param $out OutputPage
41 function setupSkinUserCss( OutputPage $out ) {
42 parent::setupSkinUserCss( $out );
43 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
44 $out->addModuleStyles( 'skins.cologneblue' );
47 /**
48 * Override langlink formatting behavior not to uppercase the language names.
49 * See otherLanguages() in CologneBlueTemplate.
51 function formatLanguageName( $name ) {
52 return $name;
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();
71 /**
72 * Language/charset variant links for classic-style skins
73 * @return string
75 function variantLinks() {
76 $s = array();
78 $variants = $this->data['content_navigation']['variants'];
80 foreach ( $variants as $key => $link ) {
81 $s[] = $this->makeListItem( $key, $link, array( 'tag' => 'span' ) );
84 return $this->getSkin()->getLanguage()->pipeList( $s );
87 function otherLanguages() {
88 global $wgHideInterlanguageLinks;
89 if ( $wgHideInterlanguageLinks ) {
90 return "";
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 "";
100 $s = array();
101 foreach ( $language_urls as $key => $data ) {
102 $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
105 return wfMessage( 'otherlanguages' )->text()
106 . wfMessage( 'colon-separator' )->text()
107 . $this->getSkin()->getLanguage()->pipeList( $s );
110 function pageTitleLinks() {
111 $s = array();
112 $footlinks = $this->getFooterLinks();
114 foreach ( $footlinks['places'] as $item ) {
115 $s[] = $this->data[$item];
118 return $this->getSkin()->getLanguage()->pipeList( $s );
122 * Used in bottomLinks() to eliminate repetitive code.
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
128 * @return string
130 function processBottomLink( $key, $navlink, $message = null ) {
131 if ( !$navlink ) {
132 // Empty navlinks might be passed.
133 return null;
136 if ( $message ) {
137 $navlink['text'] = wfMessage( $message )->escaped();
140 return $this->makeListItem( $key, $this->processNavlinkForDocument( $navlink ), array( 'tag' => 'span' ) );
143 function bottomLinks() {
144 $toolbox = $this->getToolbox();
145 $content_nav = $this->data['content_navigation'];
147 $lines = array();
149 if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
150 // First row. Regular actions.
151 $element = array();
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' );
157 $element[] = $this->processBottomLink( 'watch', $content_nav['actions']['watch'], 'watchthispage' );
158 $element[] = $this->processBottomLink( 'unwatch', $content_nav['actions']['unwatch'], 'unwatchthispage' );
160 $element[] = $this->talkLink();
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'] );
167 $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
168 $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
170 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
173 // Second row. Privileged actions.
174 $element = array();
176 $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
177 $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
179 $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
180 $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
182 $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
184 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
187 // Third row. Language links.
188 $lines[] = $this->otherLanguages();
191 return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
194 function talkLink() {
195 $title = $this->getSkin()->getTitle();
197 if ( $title->getNamespace() == NS_SPECIAL ) {
198 // No discussion links for special pages
199 return "";
202 $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
203 $companionNamespace = $companionTitle->getNamespace();
205 // TODO these messages are only be used by CologneBlue,
206 // kill and replace with something more sensibly named?
207 $nsToMessage = array(
208 NS_MAIN => 'articlepage',
209 NS_USER => 'userpage',
210 NS_PROJECT => 'projectpage',
211 NS_FILE => 'imagepage',
212 NS_MEDIAWIKI => 'mediawikipage',
213 NS_TEMPLATE => 'templatepage',
214 NS_HELP => 'viewhelppage',
215 NS_CATEGORY => 'categorypage',
216 NS_FILE => 'imagepage',
219 // Find out the message to use for link text. Use either the array above or,
220 // for non-talk pages, a generic "discuss this" message.
221 // Default is the same as for main namespace.
222 if ( isset( $nsToMessage[$companionNamespace] ) ) {
223 $message = $nsToMessage[$companionNamespace];
224 } else {
225 $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage';
228 // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones.
229 // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805)
230 $key = $companionTitle->getNamespaceKey( '' );
231 if ( $companionTitle->isTalkPage() ) {
232 $key = ( $key == 'main' ? 'talk' : $key . "_talk" );
235 // Use the regular navigational link, but replace its text. Everything else stays unmodified.
236 $namespacesLinks = $this->data['content_navigation']['namespaces'];
237 return $this->processBottomLink( $message, $namespacesLinks[$key], $message );
241 * Takes a navigational link generated by SkinTemplate in whichever way
242 * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids
243 * and removes the accesskeys. This is necessary to be able to use the same navlink twice,
244 * e.g. in sidebar and in footer.
246 * @param $navlink array Navigational link generated by SkinTemplate
247 * @param $idPrefix mixed Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'.
249 function processNavlinkForDocument( $navlink, $idPrefix = 'cb-' ) {
250 if ( $navlink['id'] ) {
251 $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation
252 $navlink['tooltiponly'] = true; // but no accesskeys
254 // mangle or remove the id
255 if ( $idPrefix === false ) {
256 unset( $navlink['id'] );
257 } else {
258 $navlink['id'] = $idPrefix . $navlink['id'];
262 return $navlink;
266 * @return string
268 function beforeContent() {
269 ob_start();
271 <div id="content">
272 <div id="topbar">
273 <p id="sitetitle" role="banner">
274 <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
275 <?php echo wfMessage( 'sitetitle' )->escaped() ?>
276 </a>
277 </p>
278 <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
279 <div id="linkcollection" role="navigation">
280 <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
281 <?php echo $this->getSkin()->getCategories() ?>
282 <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
283 <?php if ( $this->data['newtalk'] ) { ?>
284 <div class="usermessage"><strong><?php echo $this->data['newtalk'] ?></strong></div>
285 <?php } ?>
286 </div>
287 </div>
288 <div id="article" role="main">
289 <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
290 <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
291 <?php } ?>
292 <h1 id="firstHeading" lang="<?php
293 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getCode();
294 $this->html( 'pageLanguage' );
295 ?>"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
296 <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
297 <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
298 <?php } ?>
299 <?php if ( $this->getSkin()->getOutput()->getSubtitle() ) { ?>
300 <p class="subtitle"><?php echo $this->getSkin()->getOutput()->getSubtitle() ?></p>
301 <?php } ?>
302 <?php if ( $this->getSkin()->subPageSubtitle() ) { ?>
303 <p class="subpages"><?php echo $this->getSkin()->subPageSubtitle() ?></p>
304 <?php } ?>
305 <?php
306 $s = ob_get_contents();
307 ob_end_clean();
309 return $s;
313 * @return string
315 function afterContent() {
316 ob_start();
318 </div>
319 <div id="footer">
320 <div id="footer-navigation" role="navigation">
321 <?php
322 // Page-related links
323 echo $this->bottomLinks();
324 echo "\n<br />";
326 // Footer and second searchbox
327 echo $this->getSkin()->getLanguage()->pipeList( array(
328 $this->getSkin()->mainPageLink(),
329 $this->getSkin()->aboutLink(),
330 $this->searchForm( 'footer' )
331 ) );
333 </div>
334 <div id="footer-info" role="contentinfo">
335 <?php
336 // Standard footer info
337 $footlinks = $this->getFooterLinks();
338 if ( $footlinks['info'] ) {
339 foreach ( $footlinks['info'] as $item ) {
340 echo $this->data[$item] . ' ';
344 </div>
345 </div>
346 </div>
347 <div id="mw-navigation">
348 <h2><?php echo wfMessage( 'navigation-heading' )->escaped() ?></h2>
349 <div id="toplinks" role="navigation">
350 <p id="syslinks"><?php echo $this->sysLinks() ?></p>
351 <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
352 </div>
353 <?php echo $this->quickBar() ?>
354 </div>
355 <?php
356 $s = ob_get_contents();
357 ob_end_clean();
359 return $s;
363 * @return string
365 function sysLinks() {
366 $s = array(
367 $this->getSkin()->mainPageLink(),
368 Linker::linkKnown(
369 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
370 wfMessage( 'about' )->text()
372 Linker::linkKnown(
373 Title::newFromText( wfMessage( 'helppage' )->inContentLanguage()->text() ),
374 wfMessage( 'help' )->text()
376 Linker::linkKnown(
377 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
378 wfMessage( 'faq' )->text()
382 $personalUrls = $this->getPersonalTools();
383 foreach ( array( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
384 if ( $personalUrls[$key] ) {
385 $s[] = $this->makeListItem( $key, $personalUrls[$key], array( 'tag' => 'span' ) );
389 return $this->getSkin()->getLanguage()->pipeList( $s );
393 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
395 * @param $bar sidebar data
396 * @return array modified sidebar data
398 function sidebarAdditions( $bar ) {
399 // "This page" and "Edit" menus
400 // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
401 // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
402 // We also don't use $...['variants'], these are displayed in the top menu.
403 $content_navigation = $this->data['content_navigation'];
404 $qbpageoptions = array_merge(
405 $content_navigation['namespaces'],
406 array(
407 'history' => $content_navigation['views']['history'],
408 'watch' => $content_navigation['actions']['watch'],
409 'unwatch' => $content_navigation['actions']['unwatch'],
412 $content_navigation['actions']['watch'] = null;
413 $content_navigation['actions']['unwatch'] = null;
414 $qbedit = array_merge(
415 array(
416 'edit' => $content_navigation['views']['edit'],
417 'addsection' => $content_navigation['views']['addsection'],
419 $content_navigation['actions']
422 // Personal tools ("My pages")
423 $qbmyoptions = $this->getPersonalTools();
424 foreach ( array( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
425 $qbmyoptions[$key] = null;
428 // Use the closest reasonable name
429 $bar['cactions'] = $qbedit;
430 $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
431 $bar['personal'] = $qbmyoptions;
433 return $bar;
437 * Compute the sidebar
438 * @access private
440 * @return string
442 function quickBar() {
443 // Massage the sidebar. We want to:
444 // * place SEARCH at the beginning
445 // * add new portlets before TOOLBOX (or at the end, if it's missing)
446 // * remove LANGUAGES (langlinks are displayed elsewhere)
447 $orig_bar = $this->data['sidebar'];
448 $bar = array();
449 $hasToolbox = false;
451 // Always display search first
452 $bar['SEARCH'] = true;
453 // Copy everything except for langlinks, inserting new items before toolbox
454 foreach ( $orig_bar as $heading => $data ) {
455 if ( $heading == 'TOOLBOX' ) {
456 // Insert the stuff
457 $bar = $this->sidebarAdditions( $bar );
458 $hasToolbox = true;
461 if ( $heading != 'LANGUAGES' ) {
462 $bar[$heading] = $data;
465 // If toolbox is missing, add our items at the end
466 if ( !$hasToolbox ) {
467 $bar = $this->sidebarAdditions( $bar );
471 // Fill out special sidebar items with content
472 $orig_bar = $bar;
473 $bar = array();
474 foreach ( $orig_bar as $heading => $data ) {
475 if ( $heading == 'SEARCH' ) {
476 $bar['search'] = $this->searchForm( 'sidebar' );
477 } elseif ( $heading == 'TOOLBOX' ) {
478 $bar['tb'] = $this->getToolbox();
479 } else {
480 $bar[$heading] = $data;
485 // Output the sidebar
486 // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
487 $idToMessage = array(
488 'search' => 'qbfind',
489 'navigation' => 'qbbrowse',
490 'tb' => 'toolbox',
491 'cactions' => 'qbedit',
492 'personal' => 'qbmyoptions',
493 'pageoptions' => 'qbpageoptions',
496 $s = "<div id='quickbar'>\n";
498 foreach ( $bar as $heading => $data ) {
499 $portletId = Sanitizer::escapeId( "p-$heading" );
500 $headingMsg = wfMessage( $idToMessage[$heading] ? $idToMessage[$heading] : $heading );
501 $headingHTML = "<h3>" . ( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ) . "</h3>";
502 $listHTML = "";
504 if ( is_array( $data ) ) {
505 // $data is an array of links
506 foreach ( $data as $key => $link ) {
507 // Can be empty due to how the sidebar additions are done
508 if ( $link ) {
509 $listHTML .= $this->makeListItem( $key, $link );
512 if ( $listHTML ) {
513 $listHTML = "<ul>$listHTML</ul>";
515 } else {
516 // $data is a HTML <ul>-list string
517 $listHTML = $data;
520 if ( $listHTML ) {
521 $role = ( $heading == 'search' ) ? 'search' : 'navigation';
522 $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
526 $s .= "</div>\n";
527 return $s;
531 * @param $label string
532 * @return string
534 function searchForm( $which ) {
535 global $wgUseTwoButtonsSearchForm;
537 $search = $this->getSkin()->getRequest()->getText( 'search' );
538 $action = $this->data['searchaction'];
539 $s = "<form id=\"searchform-" . htmlspecialchars( $which ) . "\" method=\"get\" class=\"inline\" action=\"$action\">";
540 if ( $which == 'footer' ) {
541 $s .= wfMessage( 'qbfind' )->text() . ": ";
544 $s .= $this->makeSearchInput( array( 'class' => 'mw-searchInput', 'type' => 'text', 'size' => '14' ) );
545 $s .= ( $which == 'footer' ? " " : "<br />" );
546 $s .= $this->makeSearchButton( 'go', array( 'class' => 'searchButton' ) );
548 if ( $wgUseTwoButtonsSearchForm ) {
549 $s .= $this->makeSearchButton( 'fulltext', array( 'class' => 'searchButton' ) );
550 } else {
551 $s .= '<div><a href="' . $action . '" rel="search">' . wfMessage( 'powersearch-legend' )->escaped() . "</a></div>\n";
554 $s .= '</form>';
556 return $s;