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