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