Store boolean values as integers with SQLite
[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
173 // Second row. Privileged actions.
174 $element = array();
175
176 $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
177 $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
178
179 $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
180 $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
181
182 $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
183
184 $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
185
186
187 // Third row. Language links.
188 $lines[] = $this->otherLanguages();
189 }
190
191 return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
192 }
193
194 function talkLink() {
195 $title = $this->getSkin()->getTitle();
196
197 if ( $title->getNamespace() == NS_SPECIAL ) {
198 // No discussion links for special pages
199 return "";
200 }
201
202 $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
203 $companionNamespace = $companionTitle->getNamespace();
204
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',
217 );
218
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';
226 }
227
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" );
233 }
234
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 );
238 }
239
240 /**
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.
245 *
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-'.
248 */
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
253
254 // mangle or remove the id
255 if ( $idPrefix === false ) {
256 unset( $navlink['id'] );
257 } else {
258 $navlink['id'] = $idPrefix . $navlink['id'];
259 }
260 }
261
262 return $navlink;
263 }
264
265 /**
266 * @return string
267 */
268 function beforeContent() {
269 ob_start();
270 ?>
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()->getHtmlCode();
294 $this->text( '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();
308
309 return $s;
310 }
311
312 /**
313 * @return string
314 */
315 function afterContent() {
316 ob_start();
317 ?>
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 />";
325
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 ) );
332 ?>
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] . ' ';
341 }
342 }
343 ?>
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();
358
359 return $s;
360 }
361
362 /**
363 * @return string
364 */
365 function sysLinks() {
366 $s = array(
367 $this->getSkin()->mainPageLink(),
368 Linker::linkKnown(
369 Title::newFromText( wfMessage( 'aboutpage' )->inContentLanguage()->text() ),
370 wfMessage( 'about' )->text()
371 ),
372 Linker::linkKnown(
373 Title::newFromText( wfMessage( 'helppage' )->inContentLanguage()->text() ),
374 wfMessage( 'help' )->text()
375 ),
376 Linker::linkKnown(
377 Title::newFromText( wfMessage( 'faqpage' )->inContentLanguage()->text() ),
378 wfMessage( 'faq' )->text()
379 ),
380 );
381
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' ) );
386 }
387 }
388
389 return $this->getSkin()->getLanguage()->pipeList( $s );
390 }
391
392 /**
393 * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus.
394 *
395 * @param $bar sidebar data
396 * @return array modified sidebar data
397 */
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'],
410 )
411 );
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'],
418 ),
419 $content_navigation['actions']
420 );
421
422 // Personal tools ("My pages")
423 $qbmyoptions = $this->getPersonalTools();
424 foreach ( array( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
425 $qbmyoptions[$key] = null;
426 }
427
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;
432
433 return $bar;
434 }
435
436 /**
437 * Compute the sidebar
438 * @access private
439 *
440 * @return string
441 */
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;
450
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;
459 }
460
461 if ( $heading != 'LANGUAGES' ) {
462 $bar[$heading] = $data;
463 }
464 }
465 // If toolbox is missing, add our items at the end
466 if ( !$hasToolbox ) {
467 $bar = $this->sidebarAdditions( $bar );
468 }
469
470
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;
481 }
482 }
483
484
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',
494 );
495
496 $s = "<div id='quickbar'>\n";
497
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 = "";
503
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 );
510 }
511 }
512 if ( $listHTML ) {
513 $listHTML = "<ul>$listHTML</ul>";
514 }
515 } else {
516 // $data is a HTML <ul>-list string
517 $listHTML = $data;
518 }
519
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";
523 }
524 }
525
526 $s .= "</div>\n";
527 return $s;
528 }
529
530 /**
531 * @param $label string
532 * @return string
533 */
534 function searchForm( $which ) {
535 global $wgUseTwoButtonsSearchForm;
536
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() . ": ";
542 }
543
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' ) );
547
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";
552 }
553
554 $s .= '</form>';
555
556 return $s;
557 }
558 }