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