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