07a2e87801914f9cccee77af96fd4d1919d67556
[lhc/web/wiklou.git] / includes / skins / Skin.php
1 <?php
2 /**
3 * Base class for all skins.
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 * @file
21 */
22
23 /**
24 * @defgroup Skins Skins
25 */
26
27 /**
28 * The main skin class which provides methods and properties for all other skins.
29 *
30 * See docs/skin.txt for more information.
31 *
32 * @ingroup Skins
33 */
34 abstract class Skin extends ContextSource {
35 protected $skinname = null;
36 protected $mRelevantTitle = null;
37 protected $mRelevantUser = null;
38
39 /**
40 * @var string Stylesheets set to use. Subdirectory in skins/ where various stylesheets are
41 * located. Only needs to be set if you intend to use the getSkinStylePath() method.
42 */
43 public $stylename = null;
44
45 /**
46 * Fetch the set of available skins.
47 * @return array Associative array of strings
48 */
49 static function getSkinNames() {
50 return SkinFactory::getDefaultInstance()->getSkinNames();
51 }
52
53 /**
54 * Fetch the skinname messages for available skins.
55 * @return string[]
56 */
57 static function getSkinNameMessages() {
58 $messages = array();
59 foreach ( self::getSkinNames() as $skinKey => $skinName ) {
60 $messages[] = "skinname-$skinKey";
61 }
62 return $messages;
63 }
64
65 /**
66 * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
67 * Useful for Special:Preferences and other places where you
68 * only want to show skins users _can_ use.
69 * @return string[]
70 * @since 1.23
71 */
72 public static function getAllowedSkins() {
73 global $wgSkipSkins;
74
75 $allowedSkins = self::getSkinNames();
76
77 foreach ( $wgSkipSkins as $skip ) {
78 unset( $allowedSkins[$skip] );
79 }
80
81 return $allowedSkins;
82 }
83
84 /**
85 * @deprecated since 1.23, use getAllowedSkins
86 * @return string[]
87 */
88 public static function getUsableSkins() {
89 wfDeprecated( __METHOD__, '1.23' );
90 return self::getAllowedSkins();
91 }
92
93 /**
94 * Normalize a skin preference value to a form that can be loaded.
95 *
96 * If a skin can't be found, it will fall back to the configured default ($wgDefaultSkin), or the
97 * hardcoded default ($wgFallbackSkin) if the default skin is unavailable too.
98 *
99 * @param string $key 'monobook', 'vector', etc.
100 * @return string
101 */
102 static function normalizeKey( $key ) {
103 global $wgDefaultSkin, $wgFallbackSkin;
104
105 $skinNames = Skin::getSkinNames();
106
107 // Make keys lowercase for case-insensitive matching.
108 $skinNames = array_change_key_case( $skinNames, CASE_LOWER );
109 $key = strtolower( $key );
110 $defaultSkin = strtolower( $wgDefaultSkin );
111 $fallbackSkin = strtolower( $wgFallbackSkin );
112
113 if ( $key == '' || $key == 'default' ) {
114 // Don't return the default immediately;
115 // in a misconfiguration we need to fall back.
116 $key = $defaultSkin;
117 }
118
119 if ( isset( $skinNames[$key] ) ) {
120 return $key;
121 }
122
123 // Older versions of the software used a numeric setting
124 // in the user preferences.
125 $fallback = array(
126 0 => $defaultSkin,
127 2 => 'cologneblue'
128 );
129
130 if ( isset( $fallback[$key] ) ) {
131 $key = $fallback[$key];
132 }
133
134 if ( isset( $skinNames[$key] ) ) {
135 return $key;
136 } elseif ( isset( $skinNames[$defaultSkin] ) ) {
137 return $defaultSkin;
138 } else {
139 return $fallbackSkin;
140 }
141 }
142
143 /**
144 * Factory method for loading a skin of a given type
145 * @param string $key 'monobook', 'vector', etc.
146 * @return Skin
147 * @deprecated since 1.24; Use SkinFactory instead
148 */
149 static function &newFromKey( $key ) {
150 wfDeprecated( __METHOD__, '1.24' );
151
152 $key = Skin::normalizeKey( $key );
153 $factory = SkinFactory::getDefaultInstance();
154
155 // normalizeKey() guarantees that a skin with this key will exist.
156 $skin = $factory->makeSkin( $key );
157 return $skin;
158 }
159
160 /**
161 * @return string Skin name
162 */
163 public function getSkinName() {
164 return $this->skinname;
165 }
166
167 /**
168 * @param OutputPage $out
169 */
170 function initPage( OutputPage $out ) {
171
172 $this->preloadExistence();
173
174 }
175
176 /**
177 * Defines the ResourceLoader modules that should be added to the skin
178 * It is recommended that skins wishing to override call parent::getDefaultModules()
179 * and substitute out any modules they wish to change by using a key to look them up
180 * @return array Array of modules with helper keys for easy overriding
181 */
182 public function getDefaultModules() {
183 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
184 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
185
186 $out = $this->getOutput();
187 $user = $out->getUser();
188 $modules = array(
189 // modules that enhance the page content in some way
190 'content' => array(
191 'mediawiki.page.ready',
192 ),
193 // modules that exist for legacy reasons
194 'legacy' => array(),
195 // modules relating to search functionality
196 'search' => array(),
197 // modules relating to functionality relating to watching an article
198 'watch' => array(),
199 // modules which relate to the current users preferences
200 'user' => array(),
201 );
202 if ( $wgIncludeLegacyJavaScript ) {
203 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
204 }
205
206 if ( $wgPreloadJavaScriptMwUtil ) {
207 $modules['legacy'][] = 'mediawiki.util';
208 }
209
210 // Add various resources if required
211 if ( $wgUseAjax ) {
212 $modules['legacy'][] = 'mediawiki.legacy.ajax';
213
214 if ( $wgEnableAPI ) {
215 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
216 && $user->isAllowed( 'writeapi' )
217 ) {
218 $modules['watch'][] = 'mediawiki.page.watch.ajax';
219 }
220
221 $modules['search'][] = 'mediawiki.searchSuggest';
222 }
223 }
224
225 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
226 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
227 }
228
229 // Crazy edit-on-double-click stuff
230 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
231 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
232 }
233 return $modules;
234 }
235
236 /**
237 * Preload the existence of three commonly-requested pages in a single query
238 */
239 function preloadExistence() {
240 $titles = array();
241
242 $user = $this->getUser();
243 $title = $this->getRelevantTitle();
244
245 // User/talk link
246 if ( $user->isLoggedIn() || $this->showIPinHeader() ) {
247 $titles[] = $user->getUserPage();
248 $titles[] = $user->getTalkPage();
249 }
250
251 // Other tab link
252 if ( $title->isSpecialPage() ) {
253 // nothing
254 } elseif ( $title->isTalkPage() ) {
255 $titles[] = $title->getSubjectPage();
256 } else {
257 $titles[] = $title->getTalkPage();
258 }
259
260 Hooks::run( 'SkinPreloadExistence', array( &$titles, $this ) );
261
262 if ( count( $titles ) ) {
263 $lb = new LinkBatch( $titles );
264 $lb->setCaller( __METHOD__ );
265 $lb->execute();
266 }
267 }
268
269 /**
270 * Get the current revision ID
271 *
272 * @return int
273 */
274 public function getRevisionId() {
275 return $this->getOutput()->getRevisionId();
276 }
277
278 /**
279 * Whether the revision displayed is the latest revision of the page
280 *
281 * @return bool
282 */
283 public function isRevisionCurrent() {
284 $revID = $this->getRevisionId();
285 return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
286 }
287
288 /**
289 * Set the "relevant" title
290 * @see self::getRelevantTitle()
291 * @param Title $t
292 */
293 public function setRelevantTitle( $t ) {
294 $this->mRelevantTitle = $t;
295 }
296
297 /**
298 * Return the "relevant" title.
299 * A "relevant" title is not necessarily the actual title of the page.
300 * Special pages like Special:MovePage use set the page they are acting on
301 * as their "relevant" title, this allows the skin system to display things
302 * such as content tabs which belong to to that page instead of displaying
303 * a basic special page tab which has almost no meaning.
304 *
305 * @return Title
306 */
307 public function getRelevantTitle() {
308 if ( isset( $this->mRelevantTitle ) ) {
309 return $this->mRelevantTitle;
310 }
311 return $this->getTitle();
312 }
313
314 /**
315 * Set the "relevant" user
316 * @see self::getRelevantUser()
317 * @param User $u
318 */
319 public function setRelevantUser( $u ) {
320 $this->mRelevantUser = $u;
321 }
322
323 /**
324 * Return the "relevant" user.
325 * A "relevant" user is similar to a relevant title. Special pages like
326 * Special:Contributions mark the user which they are relevant to so that
327 * things like the toolbox can display the information they usually are only
328 * able to display on a user's userpage and talkpage.
329 * @return User
330 */
331 public function getRelevantUser() {
332 if ( isset( $this->mRelevantUser ) ) {
333 return $this->mRelevantUser;
334 }
335 $title = $this->getRelevantTitle();
336 if ( $title->hasSubjectNamespace( NS_USER ) ) {
337 $rootUser = $title->getRootText();
338 if ( User::isIP( $rootUser ) ) {
339 $this->mRelevantUser = User::newFromName( $rootUser, false );
340 } else {
341 $user = User::newFromName( $rootUser, false );
342
343 if ( $user ) {
344 $user->load( User::READ_NORMAL );
345
346 if ( $user->isLoggedIn() ) {
347 $this->mRelevantUser = $user;
348 }
349 }
350 }
351 return $this->mRelevantUser;
352 }
353 return null;
354 }
355
356 /**
357 * Outputs the HTML generated by other functions.
358 * @param OutputPage $out
359 */
360 abstract function outputPage( OutputPage $out = null );
361
362 /**
363 * @param array $data
364 * @return string
365 */
366 static function makeVariablesScript( $data ) {
367 if ( $data ) {
368 return ResourceLoader::makeInlineScript(
369 ResourceLoader::makeConfigSetScript( $data )
370 );
371 } else {
372 return '';
373 }
374 }
375
376 /**
377 * Get the query to generate a dynamic stylesheet
378 *
379 * @return array
380 */
381 public static function getDynamicStylesheetQuery() {
382 global $wgSquidMaxage;
383
384 return array(
385 'action' => 'raw',
386 'maxage' => $wgSquidMaxage,
387 'usemsgcache' => 'yes',
388 'ctype' => 'text/css',
389 'smaxage' => $wgSquidMaxage,
390 );
391 }
392
393 /**
394 * Add skin specific stylesheets
395 * Calling this method with an $out of anything but the same OutputPage
396 * inside ->getOutput() is deprecated. The $out arg is kept
397 * for compatibility purposes with skins.
398 * @param OutputPage $out
399 * @todo delete
400 */
401 abstract function setupSkinUserCss( OutputPage $out );
402
403 /**
404 * TODO: document
405 * @param Title $title
406 * @return string
407 */
408 function getPageClasses( $title ) {
409 $numeric = 'ns-' . $title->getNamespace();
410
411 if ( $title->isSpecialPage() ) {
412 $type = 'ns-special';
413 // bug 23315: provide a class based on the canonical special page name without subpages
414 list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
415 if ( $canonicalName ) {
416 $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
417 } else {
418 $type .= ' mw-invalidspecialpage';
419 }
420 } elseif ( $title->isTalkPage() ) {
421 $type = 'ns-talk';
422 } else {
423 $type = 'ns-subject';
424 }
425
426 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
427
428 return "$numeric $type $name";
429 }
430
431 /**
432 * Return values for <html> element
433 * @return array Array of associative name-to-value elements for <html> element
434 */
435 public function getHtmlElementAttributes() {
436 $lang = $this->getLanguage();
437 return array(
438 'lang' => $lang->getHtmlCode(),
439 'dir' => $lang->getDir(),
440 'class' => 'client-nojs',
441 );
442 }
443
444 /**
445 * This will be called by OutputPage::headElement when it is creating the
446 * "<body>" tag, skins can override it if they have a need to add in any
447 * body attributes or classes of their own.
448 * @param OutputPage $out
449 * @param array $bodyAttrs
450 */
451 function addToBodyAttributes( $out, &$bodyAttrs ) {
452 // does nothing by default
453 }
454
455 /**
456 * URL to the logo
457 * @return string
458 */
459 function getLogo() {
460 global $wgLogo;
461 return $wgLogo;
462 }
463
464 /**
465 * @return string
466 */
467 function getCategoryLinks() {
468 global $wgUseCategoryBrowser;
469
470 $out = $this->getOutput();
471 $allCats = $out->getCategoryLinks();
472
473 if ( !count( $allCats ) ) {
474 return '';
475 }
476
477 $embed = "<li>";
478 $pop = "</li>";
479
480 $s = '';
481 $colon = $this->msg( 'colon-separator' )->escaped();
482
483 if ( !empty( $allCats['normal'] ) ) {
484 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
485
486 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
487 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
488 $title = Title::newFromText( $linkPage );
489 $link = $title ? Linker::link( $title, $msg ) : $msg;
490 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
491 $link . $colon . '<ul>' . $t . '</ul>' . '</div>';
492 }
493
494 # Hidden categories
495 if ( isset( $allCats['hidden'] ) ) {
496 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
497 $class = ' mw-hidden-cats-user-shown';
498 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
499 $class = ' mw-hidden-cats-ns-shown';
500 } else {
501 $class = ' mw-hidden-cats-hidden';
502 }
503
504 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
505 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
506 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
507 '</div>';
508 }
509
510 # optional 'dmoz-like' category browser. Will be shown under the list
511 # of categories an article belong to
512 if ( $wgUseCategoryBrowser ) {
513 $s .= '<br /><hr />';
514
515 # get a big array of the parents tree
516 $parenttree = $this->getTitle()->getParentCategoryTree();
517 # Skin object passed by reference cause it can not be
518 # accessed under the method subfunction drawCategoryBrowser
519 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
520 # Clean out bogus first entry and sort them
521 unset( $tempout[0] );
522 asort( $tempout );
523 # Output one per line
524 $s .= implode( "<br />\n", $tempout );
525 }
526
527 return $s;
528 }
529
530 /**
531 * Render the array as a series of links.
532 * @param array $tree Categories tree returned by Title::getParentCategoryTree
533 * @return string Separated by &gt;, terminate with "\n"
534 */
535 function drawCategoryBrowser( $tree ) {
536 $return = '';
537
538 foreach ( $tree as $element => $parent ) {
539 if ( empty( $parent ) ) {
540 # element start a new list
541 $return .= "\n";
542 } else {
543 # grab the others elements
544 $return .= $this->drawCategoryBrowser( $parent ) . ' &gt; ';
545 }
546
547 # add our current element to the list
548 $eltitle = Title::newFromText( $element );
549 $return .= Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
550 }
551
552 return $return;
553 }
554
555 /**
556 * @return string
557 */
558 function getCategories() {
559 $out = $this->getOutput();
560
561 $catlinks = $this->getCategoryLinks();
562
563 $classes = 'catlinks';
564
565 // Check what we're showing
566 $allCats = $out->getCategoryLinks();
567 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
568 $this->getTitle()->getNamespace() == NS_CATEGORY;
569
570 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
571 $classes .= ' catlinks-allhidden';
572 }
573
574 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
575 }
576
577 /**
578 * This runs a hook to allow extensions placing their stuff after content
579 * and article metadata (e.g. categories).
580 * Note: This function has nothing to do with afterContent().
581 *
582 * This hook is placed here in order to allow using the same hook for all
583 * skins, both the SkinTemplate based ones and the older ones, which directly
584 * use this class to get their data.
585 *
586 * The output of this function gets processed in SkinTemplate::outputPage() for
587 * the SkinTemplate based skins, all other skins should directly echo it.
588 *
589 * @return string Empty by default, if not changed by any hook function.
590 */
591 protected function afterContentHook() {
592 $data = '';
593
594 if ( Hooks::run( 'SkinAfterContent', array( &$data, $this ) ) ) {
595 // adding just some spaces shouldn't toggle the output
596 // of the whole <div/>, so we use trim() here
597 if ( trim( $data ) != '' ) {
598 // Doing this here instead of in the skins to
599 // ensure that the div has the same ID in all
600 // skins
601 $data = "<div id='mw-data-after-content'>\n" .
602 "\t$data\n" .
603 "</div>\n";
604 }
605 } else {
606 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
607 }
608
609 return $data;
610 }
611
612 /**
613 * Generate debug data HTML for displaying at the bottom of the main content
614 * area.
615 * @return string HTML containing debug data, if enabled (otherwise empty).
616 */
617 protected function generateDebugHTML() {
618 return MWDebug::getHTMLDebugLog();
619 }
620
621 /**
622 * This gets called shortly before the "</body>" tag.
623 *
624 * @return string HTML-wrapped JS code to be put before "</body>"
625 */
626 function bottomScripts() {
627 // TODO and the suckage continues. This function is really just a wrapper around
628 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
629 // up at some point
630 $bottomScriptText = $this->getOutput()->getBottomScripts();
631 Hooks::run( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
632
633 return $bottomScriptText;
634 }
635
636 /**
637 * Text with the permalink to the source page,
638 * usually shown on the footer of a printed page
639 *
640 * @return string HTML text with an URL
641 */
642 function printSource() {
643 $oldid = $this->getRevisionId();
644 if ( $oldid ) {
645 $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
646 $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
647 } else {
648 // oldid not available for non existing pages
649 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
650 }
651
652 return $this->msg( 'retrievedfrom' )
653 ->rawParams( '<a dir="ltr" href="' . $url. '">' . $url . '</a>' )
654 ->parse();
655 }
656
657 /**
658 * @return string HTML
659 */
660 function getUndeleteLink() {
661 $action = $this->getRequest()->getVal( 'action', 'view' );
662
663 if ( $this->getTitle()->userCan( 'deletedhistory', $this->getUser() ) &&
664 ( !$this->getTitle()->exists() || $action == 'history' ) ) {
665 $n = $this->getTitle()->isDeleted();
666
667 if ( $n ) {
668 if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {
669 $msg = 'thisisdeleted';
670 } else {
671 $msg = 'viewdeleted';
672 }
673
674 return $this->msg( $msg )->rawParams(
675 Linker::linkKnown(
676 SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
677 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
678 )->escaped();
679 }
680 }
681
682 return '';
683 }
684
685 /**
686 * @return string
687 */
688 function subPageSubtitle() {
689 $out = $this->getOutput();
690 $subpages = '';
691
692 if ( !Hooks::run( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
693 return $subpages;
694 }
695
696 if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
697 $ptext = $this->getTitle()->getPrefixedText();
698 if ( preg_match( '/\//', $ptext ) ) {
699 $links = explode( '/', $ptext );
700 array_pop( $links );
701 $c = 0;
702 $growinglink = '';
703 $display = '';
704 $lang = $this->getLanguage();
705
706 foreach ( $links as $link ) {
707 $growinglink .= $link;
708 $display .= $link;
709 $linkObj = Title::newFromText( $growinglink );
710
711 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
712 $getlink = Linker::linkKnown(
713 $linkObj,
714 htmlspecialchars( $display )
715 );
716
717 $c++;
718
719 if ( $c > 1 ) {
720 $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
721 } else {
722 $subpages .= '&lt; ';
723 }
724
725 $subpages .= $getlink;
726 $display = '';
727 } else {
728 $display .= '/';
729 }
730 $growinglink .= '/';
731 }
732 }
733 }
734
735 return $subpages;
736 }
737
738 /**
739 * Returns true if the IP should be shown in the header
740 * @return bool
741 */
742 function showIPinHeader() {
743 global $wgShowIPinHeader;
744 return $wgShowIPinHeader && session_id() != '';
745 }
746
747 /**
748 * @return string
749 */
750 function getSearchLink() {
751 $searchPage = SpecialPage::getTitleFor( 'Search' );
752 return $searchPage->getLocalURL();
753 }
754
755 /**
756 * @return string
757 */
758 function escapeSearchLink() {
759 return htmlspecialchars( $this->getSearchLink() );
760 }
761
762 /**
763 * @param string $type
764 * @return string
765 */
766 function getCopyright( $type = 'detect' ) {
767 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
768
769 if ( $type == 'detect' ) {
770 if ( !$this->isRevisionCurrent()
771 && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
772 ) {
773 $type = 'history';
774 } else {
775 $type = 'normal';
776 }
777 }
778
779 if ( $type == 'history' ) {
780 $msg = 'history_copyright';
781 } else {
782 $msg = 'copyright';
783 }
784
785 if ( $wgRightsPage ) {
786 $title = Title::newFromText( $wgRightsPage );
787 $link = Linker::linkKnown( $title, $wgRightsText );
788 } elseif ( $wgRightsUrl ) {
789 $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
790 } elseif ( $wgRightsText ) {
791 $link = $wgRightsText;
792 } else {
793 # Give up now
794 return '';
795 }
796
797 // Allow for site and per-namespace customization of copyright notice.
798 // @todo Remove deprecated $forContent param from hook handlers and then remove here.
799 $forContent = true;
800
801 Hooks::run(
802 'SkinCopyrightFooter',
803 array( $this->getTitle(), $type, &$msg, &$link, &$forContent )
804 );
805
806 return $this->msg( $msg )->rawParams( $link )->text();
807 }
808
809 /**
810 * @return null|string
811 */
812 function getCopyrightIcon() {
813 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
814
815 $out = '';
816
817 if ( $wgCopyrightIcon ) {
818 $out = $wgCopyrightIcon;
819 } elseif ( $wgRightsIcon ) {
820 $icon = htmlspecialchars( $wgRightsIcon );
821
822 if ( $wgRightsUrl ) {
823 $url = htmlspecialchars( $wgRightsUrl );
824 $out .= '<a href="' . $url . '">';
825 }
826
827 $text = htmlspecialchars( $wgRightsText );
828 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
829
830 if ( $wgRightsUrl ) {
831 $out .= '</a>';
832 }
833 }
834
835 return $out;
836 }
837
838 /**
839 * Gets the powered by MediaWiki icon.
840 * @return string
841 */
842 function getPoweredBy() {
843 global $wgResourceBasePath;
844
845 $url1 = htmlspecialchars(
846 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
847 );
848 $url1_5 = htmlspecialchars(
849 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png"
850 );
851 $url2 = htmlspecialchars(
852 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png"
853 );
854 $text = '<a href="//www.mediawiki.org/"><img src="' . $url1
855 . '" srcset="' . $url1_5 . ' 1.5x, ' . $url2 . ' 2x" '
856 . 'height="31" width="88" alt="Powered by MediaWiki" /></a>';
857 Hooks::run( 'SkinGetPoweredBy', array( &$text, $this ) );
858 return $text;
859 }
860
861 /**
862 * Get the timestamp of the latest revision, formatted in user language
863 *
864 * @return string
865 */
866 protected function lastModified() {
867 $timestamp = $this->getOutput()->getRevisionTimestamp();
868
869 # No cached timestamp, load it from the database
870 if ( $timestamp === null ) {
871 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
872 }
873
874 if ( $timestamp ) {
875 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
876 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
877 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->parse();
878 } else {
879 $s = '';
880 }
881
882 if ( wfGetLB()->getLaggedSlaveMode() ) {
883 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
884 }
885
886 return $s;
887 }
888
889 /**
890 * @param string $align
891 * @return string
892 */
893 function logoText( $align = '' ) {
894 if ( $align != '' ) {
895 $a = " style='float: {$align};'";
896 } else {
897 $a = '';
898 }
899
900 $mp = $this->msg( 'mainpage' )->escaped();
901 $mptitle = Title::newMainPage();
902 $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
903
904 $logourl = $this->getLogo();
905 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
906
907 return $s;
908 }
909
910 /**
911 * Renders a $wgFooterIcons icon according to the method's arguments
912 * @param array $icon The icon to build the html for, see $wgFooterIcons
913 * for the format of this array.
914 * @param bool|string $withImage Whether to use the icon's image or output
915 * a text-only footericon.
916 * @return string HTML
917 */
918 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
919 if ( is_string( $icon ) ) {
920 $html = $icon;
921 } else { // Assuming array
922 $url = isset( $icon["url"] ) ? $icon["url"] : null;
923 unset( $icon["url"] );
924 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
925 // do this the lazy way, just pass icon data as an attribute array
926 $html = Html::element( 'img', $icon );
927 } else {
928 $html = htmlspecialchars( $icon["alt"] );
929 }
930 if ( $url ) {
931 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
932 }
933 }
934 return $html;
935 }
936
937 /**
938 * Gets the link to the wiki's main page.
939 * @return string
940 */
941 function mainPageLink() {
942 $s = Linker::linkKnown(
943 Title::newMainPage(),
944 $this->msg( 'mainpage' )->escaped()
945 );
946
947 return $s;
948 }
949
950 /**
951 * Returns an HTML link for use in the footer
952 * @param string $desc The i18n message key for the link text
953 * @param string $page The i18n message key for the page to link to
954 * @return string HTML anchor
955 */
956 public function footerLink( $desc, $page ) {
957 // if the link description has been set to "-" in the default language,
958 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
959 // then it is disabled, for all languages.
960 return '';
961 } else {
962 // Otherwise, we display the link for the user, described in their
963 // language (which may or may not be the same as the default language),
964 // but we make the link target be the one site-wide page.
965 $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
966
967 if ( !$title ) {
968 return '';
969 }
970
971 return Linker::linkKnown(
972 $title,
973 $this->msg( $desc )->escaped()
974 );
975 }
976 }
977
978 /**
979 * Gets the link to the wiki's privacy policy page.
980 * @return string HTML
981 */
982 function privacyLink() {
983 return $this->footerLink( 'privacy', 'privacypage' );
984 }
985
986 /**
987 * Gets the link to the wiki's about page.
988 * @return string HTML
989 */
990 function aboutLink() {
991 return $this->footerLink( 'aboutsite', 'aboutpage' );
992 }
993
994 /**
995 * Gets the link to the wiki's general disclaimers page.
996 * @return string HTML
997 */
998 function disclaimerLink() {
999 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1000 }
1001
1002 /**
1003 * Return URL options for the 'edit page' link.
1004 * This may include an 'oldid' specifier, if the current page view is such.
1005 *
1006 * @return array
1007 * @private
1008 */
1009 function editUrlOptions() {
1010 $options = array( 'action' => 'edit' );
1011
1012 if ( !$this->isRevisionCurrent() ) {
1013 $options['oldid'] = intval( $this->getRevisionId() );
1014 }
1015
1016 return $options;
1017 }
1018
1019 /**
1020 * @param User|int $id
1021 * @return bool
1022 */
1023 function showEmailUser( $id ) {
1024 if ( $id instanceof User ) {
1025 $targetUser = $id;
1026 } else {
1027 $targetUser = User::newFromId( $id );
1028 }
1029
1030 # The sending user must have a confirmed email address and the target
1031 # user must have a confirmed email address and allow emails from users.
1032 return $this->getUser()->canSendEmail() &&
1033 $targetUser->canReceiveEmail();
1034 }
1035
1036 /**
1037 * This function previously returned a fully resolved style path URL to images or styles stored in
1038 * the legacy skins/common/ directory.
1039 *
1040 * That directory has been removed in 1.24 and the function always returns an empty string.
1041 *
1042 * @deprecated since 1.24
1043 * @param string $name The name or path of a skin resource file
1044 * @return string Empty string
1045 */
1046 function getCommonStylePath( $name ) {
1047 wfDeprecated( __METHOD__, '1.24' );
1048 return '';
1049 }
1050
1051 /**
1052 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1053 * This method returns a url resolved using the configured skin style path
1054 * and includes the style version inside of the url.
1055 *
1056 * Requires $stylename to be set, otherwise throws MWException.
1057 *
1058 * @param string $name The name or path of a skin resource file
1059 * @return string The fully resolved style path url including styleversion
1060 * @throws MWException
1061 */
1062 function getSkinStylePath( $name ) {
1063 global $wgStylePath, $wgStyleVersion;
1064
1065 if ( $this->stylename === null ) {
1066 $class = get_class( $this );
1067 throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
1068 }
1069
1070 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1071 }
1072
1073 /* these are used extensively in SkinTemplate, but also some other places */
1074
1075 /**
1076 * @param string $urlaction
1077 * @return string
1078 */
1079 static function makeMainPageUrl( $urlaction = '' ) {
1080 $title = Title::newMainPage();
1081 self::checkTitle( $title, '' );
1082
1083 return $title->getLocalURL( $urlaction );
1084 }
1085
1086 /**
1087 * Make a URL for a Special Page using the given query and protocol.
1088 *
1089 * If $proto is set to null, make a local URL. Otherwise, make a full
1090 * URL with the protocol specified.
1091 *
1092 * @param string $name Name of the Special page
1093 * @param string $urlaction Query to append
1094 * @param string|null $proto Protocol to use or null for a local URL
1095 * @return string
1096 */
1097 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1098 $title = SpecialPage::getSafeTitleFor( $name );
1099 if ( is_null( $proto ) ) {
1100 return $title->getLocalURL( $urlaction );
1101 } else {
1102 return $title->getFullURL( $urlaction, false, $proto );
1103 }
1104 }
1105
1106 /**
1107 * @param string $name
1108 * @param string $subpage
1109 * @param string $urlaction
1110 * @return string
1111 */
1112 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1113 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1114 return $title->getLocalURL( $urlaction );
1115 }
1116
1117 /**
1118 * @param string $name
1119 * @param string $urlaction
1120 * @return string
1121 */
1122 static function makeI18nUrl( $name, $urlaction = '' ) {
1123 $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1124 self::checkTitle( $title, $name );
1125 return $title->getLocalURL( $urlaction );
1126 }
1127
1128 /**
1129 * @param string $name
1130 * @param string $urlaction
1131 * @return string
1132 */
1133 static function makeUrl( $name, $urlaction = '' ) {
1134 $title = Title::newFromText( $name );
1135 self::checkTitle( $title, $name );
1136
1137 return $title->getLocalURL( $urlaction );
1138 }
1139
1140 /**
1141 * If url string starts with http, consider as external URL, else
1142 * internal
1143 * @param string $name
1144 * @return string URL
1145 */
1146 static function makeInternalOrExternalUrl( $name ) {
1147 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1148 return $name;
1149 } else {
1150 return self::makeUrl( $name );
1151 }
1152 }
1153
1154 /**
1155 * this can be passed the NS number as defined in Language.php
1156 * @param string $name
1157 * @param string $urlaction
1158 * @param int $namespace
1159 * @return string
1160 */
1161 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1162 $title = Title::makeTitleSafe( $namespace, $name );
1163 self::checkTitle( $title, $name );
1164
1165 return $title->getLocalURL( $urlaction );
1166 }
1167
1168 /**
1169 * these return an array with the 'href' and boolean 'exists'
1170 * @param string $name
1171 * @param string $urlaction
1172 * @return array
1173 */
1174 static function makeUrlDetails( $name, $urlaction = '' ) {
1175 $title = Title::newFromText( $name );
1176 self::checkTitle( $title, $name );
1177
1178 return array(
1179 'href' => $title->getLocalURL( $urlaction ),
1180 'exists' => $title->isKnown(),
1181 );
1182 }
1183
1184 /**
1185 * Make URL details where the article exists (or at least it's convenient to think so)
1186 * @param string $name Article name
1187 * @param string $urlaction
1188 * @return array
1189 */
1190 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1191 $title = Title::newFromText( $name );
1192 self::checkTitle( $title, $name );
1193
1194 return array(
1195 'href' => $title->getLocalURL( $urlaction ),
1196 'exists' => true
1197 );
1198 }
1199
1200 /**
1201 * make sure we have some title to operate on
1202 *
1203 * @param Title $title
1204 * @param string $name
1205 */
1206 static function checkTitle( &$title, $name ) {
1207 if ( !is_object( $title ) ) {
1208 $title = Title::newFromText( $name );
1209 if ( !is_object( $title ) ) {
1210 $title = Title::newFromText( '--error: link target missing--' );
1211 }
1212 }
1213 }
1214
1215 /**
1216 * Build an array that represents the sidebar(s), the navigation bar among them.
1217 *
1218 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1219 *
1220 * The format of the returned array is array( heading => content, ... ), where:
1221 * - heading is the heading of a navigation portlet. It is either:
1222 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1223 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1224 * - plain text, which should be HTML-escaped by the skin
1225 * - content is the contents of the portlet. It is either:
1226 * - HTML text (<ul><li>...</li>...</ul>)
1227 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1228 * - (for a magic string as a key, any value)
1229 *
1230 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1231 * and can technically insert anything in here; skin creators are expected to handle
1232 * values described above.
1233 *
1234 * @return array
1235 */
1236 function buildSidebar() {
1237 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1238
1239 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1240
1241 if ( $wgEnableSidebarCache ) {
1242 $cachedsidebar = $wgMemc->get( $key );
1243 if ( $cachedsidebar ) {
1244 Hooks::run( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
1245
1246 return $cachedsidebar;
1247 }
1248 }
1249
1250 $bar = array();
1251 $this->addToSidebar( $bar, 'sidebar' );
1252
1253 Hooks::run( 'SkinBuildSidebar', array( $this, &$bar ) );
1254 if ( $wgEnableSidebarCache ) {
1255 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1256 }
1257
1258 Hooks::run( 'SidebarBeforeOutput', array( $this, &$bar ) );
1259
1260 return $bar;
1261 }
1262
1263 /**
1264 * Add content from a sidebar system message
1265 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1266 *
1267 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1268 *
1269 * @param array $bar
1270 * @param string $message
1271 */
1272 function addToSidebar( &$bar, $message ) {
1273 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1274 }
1275
1276 /**
1277 * Add content from plain text
1278 * @since 1.17
1279 * @param array $bar
1280 * @param string $text
1281 * @return array
1282 */
1283 function addToSidebarPlain( &$bar, $text ) {
1284 $lines = explode( "\n", $text );
1285
1286 $heading = '';
1287
1288 foreach ( $lines as $line ) {
1289 if ( strpos( $line, '*' ) !== 0 ) {
1290 continue;
1291 }
1292 $line = rtrim( $line, "\r" ); // for Windows compat
1293
1294 if ( strpos( $line, '**' ) !== 0 ) {
1295 $heading = trim( $line, '* ' );
1296 if ( !array_key_exists( $heading, $bar ) ) {
1297 $bar[$heading] = array();
1298 }
1299 } else {
1300 $line = trim( $line, '* ' );
1301
1302 if ( strpos( $line, '|' ) !== false ) { // sanity check
1303 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1304 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1305 if ( count( $line ) !== 2 ) {
1306 // Second sanity check, could be hit by people doing
1307 // funky stuff with parserfuncs... (bug 33321)
1308 continue;
1309 }
1310
1311 $extraAttribs = array();
1312
1313 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1314 if ( $msgLink->exists() ) {
1315 $link = $msgLink->text();
1316 if ( $link == '-' ) {
1317 continue;
1318 }
1319 } else {
1320 $link = $line[0];
1321 }
1322 $msgText = $this->msg( $line[1] );
1323 if ( $msgText->exists() ) {
1324 $text = $msgText->text();
1325 } else {
1326 $text = $line[1];
1327 }
1328
1329 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1330 $href = $link;
1331
1332 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1333 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1334 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1335 $extraAttribs['rel'] = 'nofollow';
1336 }
1337
1338 global $wgExternalLinkTarget;
1339 if ( $wgExternalLinkTarget ) {
1340 $extraAttribs['target'] = $wgExternalLinkTarget;
1341 }
1342 } else {
1343 $title = Title::newFromText( $link );
1344
1345 if ( $title ) {
1346 $title = $title->fixSpecialName();
1347 $href = $title->getLinkURL();
1348 } else {
1349 $href = 'INVALID-TITLE';
1350 }
1351 }
1352
1353 $bar[$heading][] = array_merge( array(
1354 'text' => $text,
1355 'href' => $href,
1356 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1357 'active' => false
1358 ), $extraAttribs );
1359 } else {
1360 continue;
1361 }
1362 }
1363 }
1364
1365 return $bar;
1366 }
1367
1368 /**
1369 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1370 * should be loaded by OutputPage. That module no longer exists and the return value of this
1371 * method is ignored.
1372 *
1373 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1374 * can be used instead (SkinTemplate-based skins do it automatically).
1375 *
1376 * @deprecated since 1.22
1377 * @return bool
1378 */
1379 public function commonPrintStylesheet() {
1380 wfDeprecated( __METHOD__, '1.22' );
1381 return false;
1382 }
1383
1384 /**
1385 * Gets new talk page messages for the current user and returns an
1386 * appropriate alert message (or an empty string if there are no messages)
1387 * @return string
1388 */
1389 function getNewtalks() {
1390
1391 $newMessagesAlert = '';
1392 $user = $this->getUser();
1393 $newtalks = $user->getNewMessageLinks();
1394 $out = $this->getOutput();
1395
1396 // Allow extensions to disable or modify the new messages alert
1397 if ( !Hooks::run( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1398 return '';
1399 }
1400 if ( $newMessagesAlert ) {
1401 return $newMessagesAlert;
1402 }
1403
1404 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1405 $uTalkTitle = $user->getTalkPage();
1406 $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
1407 $nofAuthors = 0;
1408 if ( $lastSeenRev !== null ) {
1409 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1410 $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
1411 if ( $latestRev !== null ) {
1412 // Singular if only 1 unseen revision, plural if several unseen revisions.
1413 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1414 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1415 $lastSeenRev, $latestRev, 10, 'include_new' );
1416 }
1417 } else {
1418 // Singular if no revision -> diff link will show latest change only in any case
1419 $plural = false;
1420 }
1421 $plural = $plural ? 999 : 1;
1422 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1423 // the number of revisions or authors is not necessarily the same as the number of
1424 // "messages".
1425 $newMessagesLink = Linker::linkKnown(
1426 $uTalkTitle,
1427 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1428 array(),
1429 array( 'redirect' => 'no' )
1430 );
1431
1432 $newMessagesDiffLink = Linker::linkKnown(
1433 $uTalkTitle,
1434 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1435 array(),
1436 $lastSeenRev !== null
1437 ? array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1438 : array( 'diff' => 'cur' )
1439 );
1440
1441 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1442 $newMessagesAlert = $this->msg(
1443 'youhavenewmessagesfromusers',
1444 $newMessagesLink,
1445 $newMessagesDiffLink
1446 )->numParams( $nofAuthors, $plural );
1447 } else {
1448 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1449 $newMessagesAlert = $this->msg(
1450 $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1451 $newMessagesLink,
1452 $newMessagesDiffLink
1453 )->numParams( $plural );
1454 }
1455 $newMessagesAlert = $newMessagesAlert->text();
1456 # Disable Squid cache
1457 $out->setSquidMaxage( 0 );
1458 } elseif ( count( $newtalks ) ) {
1459 $sep = $this->msg( 'newtalkseparator' )->escaped();
1460 $msgs = array();
1461
1462 foreach ( $newtalks as $newtalk ) {
1463 $msgs[] = Xml::element(
1464 'a',
1465 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1466 );
1467 }
1468 $parts = implode( $sep, $msgs );
1469 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1470 $out->setSquidMaxage( 0 );
1471 }
1472
1473 return $newMessagesAlert;
1474 }
1475
1476 /**
1477 * Get a cached notice
1478 *
1479 * @param string $name Message name, or 'default' for $wgSiteNotice
1480 * @return string|bool HTML fragment, or false to indicate that the caller
1481 * should fall back to the next notice in its sequence
1482 */
1483 private function getCachedNotice( $name ) {
1484 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1485
1486 $needParse = false;
1487
1488 if ( $name === 'default' ) {
1489 // special case
1490 global $wgSiteNotice;
1491 $notice = $wgSiteNotice;
1492 if ( empty( $notice ) ) {
1493 return false;
1494 }
1495 } else {
1496 $msg = $this->msg( $name )->inContentLanguage();
1497 if ( $msg->isBlank() ) {
1498 return '';
1499 } elseif ( $msg->isDisabled() ) {
1500 return false;
1501 }
1502 $notice = $msg->plain();
1503 }
1504
1505 // Use the extra hash appender to let eg SSL variants separately cache.
1506 $key = wfMemcKey( $name . $wgRenderHashAppend );
1507 $cachedNotice = $parserMemc->get( $key );
1508 if ( is_array( $cachedNotice ) ) {
1509 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1510 $notice = $cachedNotice['html'];
1511 } else {
1512 $needParse = true;
1513 }
1514 } else {
1515 $needParse = true;
1516 }
1517
1518 if ( $needParse ) {
1519 $parsed = $this->getOutput()->parse( $notice );
1520 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1521 $notice = $parsed;
1522 }
1523
1524 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1525 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1526 return $notice;
1527 }
1528
1529 /**
1530 * Get a notice based on page's namespace
1531 *
1532 * @return string HTML fragment
1533 */
1534 function getNamespaceNotice() {
1535
1536 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1537 $namespaceNotice = $this->getCachedNotice( $key );
1538 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1539 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1540 } else {
1541 $namespaceNotice = '';
1542 }
1543
1544 return $namespaceNotice;
1545 }
1546
1547 /**
1548 * Get the site notice
1549 *
1550 * @return string HTML fragment
1551 */
1552 function getSiteNotice() {
1553 $siteNotice = '';
1554
1555 if ( Hooks::run( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1556 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1557 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1558 } else {
1559 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1560 if ( $anonNotice === false ) {
1561 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1562 } else {
1563 $siteNotice = $anonNotice;
1564 }
1565 }
1566 if ( $siteNotice === false ) {
1567 $siteNotice = $this->getCachedNotice( 'default' );
1568 }
1569 }
1570
1571 Hooks::run( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1572 return $siteNotice;
1573 }
1574
1575 /**
1576 * Create a section edit link. This supersedes editSectionLink() and
1577 * editSectionLinkForOther().
1578 *
1579 * @param Title $nt The title being linked to (may not be the same as
1580 * the current page, if the section is included from a template)
1581 * @param string $section The designation of the section being pointed to,
1582 * to be included in the link, like "&section=$section"
1583 * @param string $tooltip The tooltip to use for the link: will be escaped
1584 * and wrapped in the 'editsectionhint' message
1585 * @param string $lang Language code
1586 * @return string HTML to use for edit link
1587 */
1588 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1589 // HTML generated here should probably have userlangattributes
1590 // added to it for LTR text on RTL pages
1591
1592 $lang = wfGetLangObj( $lang );
1593
1594 $attribs = array();
1595 if ( !is_null( $tooltip ) ) {
1596 # Bug 25462: undo double-escaping.
1597 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1598 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1599 ->inLanguage( $lang )->text();
1600 }
1601
1602 $links = array(
1603 'editsection' => array(
1604 'text' => wfMessage( 'editsection' )->inLanguage( $lang )->escaped(),
1605 'targetTitle' => $nt,
1606 'attribs' => $attribs,
1607 'query' => array( 'action' => 'edit', 'section' => $section ),
1608 'options' => array( 'noclasses', 'known' )
1609 )
1610 );
1611
1612 Hooks::run( 'SkinEditSectionLinks', array( $this, $nt, $section, $tooltip, &$links, $lang ) );
1613
1614 $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
1615
1616 $linksHtml = array();
1617 foreach ( $links as $k => $linkDetails ) {
1618 $linksHtml[] = Linker::link(
1619 $linkDetails['targetTitle'],
1620 $linkDetails['text'],
1621 $linkDetails['attribs'],
1622 $linkDetails['query'],
1623 $linkDetails['options']
1624 );
1625 }
1626
1627 $result .= implode(
1628 '<span class="mw-editsection-divider">'
1629 . wfMessage( 'pipe-separator' )->inLanguage( $lang )->text()
1630 . '</span>',
1631 $linksHtml
1632 );
1633
1634 $result .= '<span class="mw-editsection-bracket">]</span></span>';
1635 // Deprecated, use SkinEditSectionLinks hook instead
1636 Hooks::run(
1637 'DoEditSectionLink',
1638 array( $this, $nt, $section, $tooltip, &$result, $lang ),
1639 '1.25'
1640 );
1641 return $result;
1642 }
1643
1644 /**
1645 * Use PHP's magic __call handler to intercept legacy calls to the linker
1646 * for backwards compatibility.
1647 *
1648 * @param string $fname Name of called method
1649 * @param array $args Arguments to the method
1650 * @throws MWException
1651 * @return mixed
1652 */
1653 function __call( $fname, $args ) {
1654 $realFunction = array( 'Linker', $fname );
1655 if ( is_callable( $realFunction ) ) {
1656 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1657 return call_user_func_array( $realFunction, $args );
1658 } else {
1659 $className = get_class( $this );
1660 throw new MWException( "Call to undefined method $className::$fname" );
1661 }
1662 }
1663
1664 }