Merge "Drop index oi_name_archive_name on table oldimage"
[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 * Normalize a skin preference value to a form that can be loaded.
86 *
87 * If a skin can't be found, it will fall back to the configured default ($wgDefaultSkin), or the
88 * hardcoded default ($wgFallbackSkin) if the default skin is unavailable too.
89 *
90 * @param string $key 'monobook', 'vector', etc.
91 * @return string
92 */
93 static function normalizeKey( $key ) {
94 global $wgDefaultSkin, $wgFallbackSkin;
95
96 $skinNames = Skin::getSkinNames();
97
98 // Make keys lowercase for case-insensitive matching.
99 $skinNames = array_change_key_case( $skinNames, CASE_LOWER );
100 $key = strtolower( $key );
101 $defaultSkin = strtolower( $wgDefaultSkin );
102 $fallbackSkin = strtolower( $wgFallbackSkin );
103
104 if ( $key == '' || $key == 'default' ) {
105 // Don't return the default immediately;
106 // in a misconfiguration we need to fall back.
107 $key = $defaultSkin;
108 }
109
110 if ( isset( $skinNames[$key] ) ) {
111 return $key;
112 }
113
114 // Older versions of the software used a numeric setting
115 // in the user preferences.
116 $fallback = [
117 0 => $defaultSkin,
118 2 => 'cologneblue'
119 ];
120
121 if ( isset( $fallback[$key] ) ) {
122 $key = $fallback[$key];
123 }
124
125 if ( isset( $skinNames[$key] ) ) {
126 return $key;
127 } elseif ( isset( $skinNames[$defaultSkin] ) ) {
128 return $defaultSkin;
129 } else {
130 return $fallbackSkin;
131 }
132 }
133
134 /**
135 * @return string Skin name
136 */
137 public function getSkinName() {
138 return $this->skinname;
139 }
140
141 /**
142 * @param OutputPage $out
143 */
144 public function initPage( OutputPage $out ) {
145 $this->preloadExistence();
146 }
147
148 /**
149 * Defines the ResourceLoader modules that should be added to the skin
150 * It is recommended that skins wishing to override call parent::getDefaultModules()
151 * and substitute out any modules they wish to change by using a key to look them up
152 * @return array Array of modules with helper keys for easy overriding
153 */
154 public function getDefaultModules() {
155 global $wgUseAjax, $wgEnableAPI, $wgEnableWriteAPI;
156
157 $out = $this->getOutput();
158 $user = $out->getUser();
159 $modules = [
160 // modules that enhance the page content in some way
161 'content' => [
162 'mediawiki.page.ready',
163 ],
164 // modules that exist for legacy reasons
165 'legacy' => ResourceLoaderStartUpModule::getLegacyModules(),
166 // modules relating to search functionality
167 'search' => [],
168 // modules relating to functionality relating to watching an article
169 'watch' => [],
170 // modules which relate to the current users preferences
171 'user' => [],
172 ];
173
174 // Add various resources if required
175 if ( $wgUseAjax && $wgEnableAPI ) {
176 if ( $wgEnableWriteAPI && $user->isLoggedIn()
177 && $user->isAllowedAll( 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
178 && $this->getRelevantTitle()->canExist()
179 ) {
180 $modules['watch'][] = 'mediawiki.page.watch.ajax';
181 }
182
183 $modules['search'][] = 'mediawiki.searchSuggest';
184 }
185
186 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
187 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
188 }
189
190 // Crazy edit-on-double-click stuff
191 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
192 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
193 }
194 return $modules;
195 }
196
197 /**
198 * Preload the existence of three commonly-requested pages in a single query
199 */
200 protected function preloadExistence() {
201 $titles = [];
202
203 // User/talk link
204 $user = $this->getUser();
205 if ( $user->isLoggedIn() ) {
206 $titles[] = $user->getUserPage();
207 $titles[] = $user->getTalkPage();
208 }
209
210 // Check, if the page can hold some kind of content, otherwise do nothing
211 $title = $this->getRelevantTitle();
212 if ( $title->canExist() ) {
213 if ( $title->isTalkPage() ) {
214 $titles[] = $title->getSubjectPage();
215 } else {
216 $titles[] = $title->getTalkPage();
217 }
218 }
219
220 // Footer links (used by SkinTemplate::prepareQuickTemplate)
221 foreach ( [
222 $this->footerLinkTitle( 'privacy', 'privacypage' ),
223 $this->footerLinkTitle( 'aboutsite', 'aboutpage' ),
224 $this->footerLinkTitle( 'disclaimers', 'disclaimerpage' ),
225 ] as $title ) {
226 if ( $title ) {
227 $titles[] = $title;
228 }
229 }
230
231 Hooks::run( 'SkinPreloadExistence', [ &$titles, $this ] );
232
233 if ( $titles ) {
234 $lb = new LinkBatch( $titles );
235 $lb->setCaller( __METHOD__ );
236 $lb->execute();
237 }
238 }
239
240 /**
241 * Get the current revision ID
242 *
243 * @return int
244 */
245 public function getRevisionId() {
246 return $this->getOutput()->getRevisionId();
247 }
248
249 /**
250 * Whether the revision displayed is the latest revision of the page
251 *
252 * @return bool
253 */
254 public function isRevisionCurrent() {
255 $revID = $this->getRevisionId();
256 return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
257 }
258
259 /**
260 * Set the "relevant" title
261 * @see self::getRelevantTitle()
262 * @param Title $t
263 */
264 public function setRelevantTitle( $t ) {
265 $this->mRelevantTitle = $t;
266 }
267
268 /**
269 * Return the "relevant" title.
270 * A "relevant" title is not necessarily the actual title of the page.
271 * Special pages like Special:MovePage use set the page they are acting on
272 * as their "relevant" title, this allows the skin system to display things
273 * such as content tabs which belong to to that page instead of displaying
274 * a basic special page tab which has almost no meaning.
275 *
276 * @return Title
277 */
278 public function getRelevantTitle() {
279 if ( isset( $this->mRelevantTitle ) ) {
280 return $this->mRelevantTitle;
281 }
282 return $this->getTitle();
283 }
284
285 /**
286 * Set the "relevant" user
287 * @see self::getRelevantUser()
288 * @param User $u
289 */
290 public function setRelevantUser( $u ) {
291 $this->mRelevantUser = $u;
292 }
293
294 /**
295 * Return the "relevant" user.
296 * A "relevant" user is similar to a relevant title. Special pages like
297 * Special:Contributions mark the user which they are relevant to so that
298 * things like the toolbox can display the information they usually are only
299 * able to display on a user's userpage and talkpage.
300 * @return User
301 */
302 public function getRelevantUser() {
303 if ( isset( $this->mRelevantUser ) ) {
304 return $this->mRelevantUser;
305 }
306 $title = $this->getRelevantTitle();
307 if ( $title->hasSubjectNamespace( NS_USER ) ) {
308 $rootUser = $title->getRootText();
309 if ( User::isIP( $rootUser ) ) {
310 $this->mRelevantUser = User::newFromName( $rootUser, false );
311 } else {
312 $user = User::newFromName( $rootUser, false );
313
314 if ( $user ) {
315 $user->load( User::READ_NORMAL );
316
317 if ( $user->isLoggedIn() ) {
318 $this->mRelevantUser = $user;
319 }
320 }
321 }
322 return $this->mRelevantUser;
323 }
324 return null;
325 }
326
327 /**
328 * Outputs the HTML generated by other functions.
329 * @param OutputPage $out
330 */
331 abstract function outputPage( OutputPage $out = null );
332
333 /**
334 * @param array $data
335 * @return string
336 */
337 static function makeVariablesScript( $data ) {
338 if ( $data ) {
339 return ResourceLoader::makeInlineScript(
340 ResourceLoader::makeConfigSetScript( $data )
341 );
342 } else {
343 return '';
344 }
345 }
346
347 /**
348 * Get the query to generate a dynamic stylesheet
349 *
350 * @return array
351 */
352 public static function getDynamicStylesheetQuery() {
353 global $wgSquidMaxage;
354
355 return [
356 'action' => 'raw',
357 'maxage' => $wgSquidMaxage,
358 'usemsgcache' => 'yes',
359 'ctype' => 'text/css',
360 'smaxage' => $wgSquidMaxage,
361 ];
362 }
363
364 /**
365 * Add skin specific stylesheets
366 * Calling this method with an $out of anything but the same OutputPage
367 * inside ->getOutput() is deprecated. The $out arg is kept
368 * for compatibility purposes with skins.
369 * @param OutputPage $out
370 * @todo delete
371 */
372 abstract function setupSkinUserCss( OutputPage $out );
373
374 /**
375 * TODO: document
376 * @param Title $title
377 * @return string
378 */
379 function getPageClasses( $title ) {
380 $numeric = 'ns-' . $title->getNamespace();
381
382 if ( $title->isSpecialPage() ) {
383 $type = 'ns-special';
384 // T25315: provide a class based on the canonical special page name without subpages
385 list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
386 if ( $canonicalName ) {
387 $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
388 } else {
389 $type .= ' mw-invalidspecialpage';
390 }
391 } elseif ( $title->isTalkPage() ) {
392 $type = 'ns-talk';
393 } else {
394 $type = 'ns-subject';
395 }
396
397 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
398 $root = Sanitizer::escapeClass( 'rootpage-' . $title->getRootTitle()->getPrefixedText() );
399
400 return "$numeric $type $name $root";
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 * @param OutputPage $out Defaults to $this->getOutput() if left as null
661 * @return string
662 */
663 function subPageSubtitle( $out = null ) {
664 if ( $out === null ) {
665 $out = $this->getOutput();
666 }
667 $title = $out->getTitle();
668 $subpages = '';
669
670 if ( !Hooks::run( 'SkinSubPageSubtitle', [ &$subpages, $this, $out ] ) ) {
671 return $subpages;
672 }
673
674 if ( $out->isArticle() && MWNamespace::hasSubpages( $title->getNamespace() ) ) {
675 $ptext = $title->getPrefixedText();
676 if ( strpos( $ptext, '/' ) !== false ) {
677 $links = explode( '/', $ptext );
678 array_pop( $links );
679 $c = 0;
680 $growinglink = '';
681 $display = '';
682 $lang = $this->getLanguage();
683
684 foreach ( $links as $link ) {
685 $growinglink .= $link;
686 $display .= $link;
687 $linkObj = Title::newFromText( $growinglink );
688
689 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
690 $getlink = Linker::linkKnown(
691 $linkObj,
692 htmlspecialchars( $display )
693 );
694
695 $c++;
696
697 if ( $c > 1 ) {
698 $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
699 } else {
700 $subpages .= '&lt; ';
701 }
702
703 $subpages .= $getlink;
704 $display = '';
705 } else {
706 $display .= '/';
707 }
708 $growinglink .= '/';
709 }
710 }
711 }
712
713 return $subpages;
714 }
715
716 /**
717 * @deprecated since 1.27, feature removed
718 * @return bool Always false
719 */
720 function showIPinHeader() {
721 wfDeprecated( __METHOD__, '1.27' );
722 return false;
723 }
724
725 /**
726 * @return string
727 */
728 function getSearchLink() {
729 $searchPage = SpecialPage::getTitleFor( 'Search' );
730 return $searchPage->getLocalURL();
731 }
732
733 /**
734 * @return string
735 */
736 function escapeSearchLink() {
737 return htmlspecialchars( $this->getSearchLink() );
738 }
739
740 /**
741 * @param string $type
742 * @return string
743 */
744 function getCopyright( $type = 'detect' ) {
745 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
746
747 if ( $type == 'detect' ) {
748 if ( !$this->isRevisionCurrent()
749 && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
750 ) {
751 $type = 'history';
752 } else {
753 $type = 'normal';
754 }
755 }
756
757 if ( $type == 'history' ) {
758 $msg = 'history_copyright';
759 } else {
760 $msg = 'copyright';
761 }
762
763 if ( $wgRightsPage ) {
764 $title = Title::newFromText( $wgRightsPage );
765 $link = Linker::linkKnown( $title, $wgRightsText );
766 } elseif ( $wgRightsUrl ) {
767 $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
768 } elseif ( $wgRightsText ) {
769 $link = $wgRightsText;
770 } else {
771 # Give up now
772 return '';
773 }
774
775 // Allow for site and per-namespace customization of copyright notice.
776 // @todo Remove deprecated $forContent param from hook handlers and then remove here.
777 $forContent = true;
778
779 Hooks::run(
780 'SkinCopyrightFooter',
781 [ $this->getTitle(), $type, &$msg, &$link, &$forContent ]
782 );
783
784 return $this->msg( $msg )->rawParams( $link )->text();
785 }
786
787 /**
788 * @return null|string
789 */
790 function getCopyrightIcon() {
791 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgFooterIcons;
792
793 $out = '';
794
795 if ( $wgFooterIcons['copyright']['copyright'] ) {
796 $out = $wgFooterIcons['copyright']['copyright'];
797 } elseif ( $wgRightsIcon ) {
798 $icon = htmlspecialchars( $wgRightsIcon );
799
800 if ( $wgRightsUrl ) {
801 $url = htmlspecialchars( $wgRightsUrl );
802 $out .= '<a href="' . $url . '">';
803 }
804
805 $text = htmlspecialchars( $wgRightsText );
806 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
807
808 if ( $wgRightsUrl ) {
809 $out .= '</a>';
810 }
811 }
812
813 return $out;
814 }
815
816 /**
817 * Gets the powered by MediaWiki icon.
818 * @return string
819 */
820 function getPoweredBy() {
821 global $wgResourceBasePath;
822
823 $url1 = htmlspecialchars(
824 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
825 );
826 $url1_5 = htmlspecialchars(
827 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png"
828 );
829 $url2 = htmlspecialchars(
830 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png"
831 );
832 $text = '<a href="//www.mediawiki.org/"><img src="' . $url1
833 . '" srcset="' . $url1_5 . ' 1.5x, ' . $url2 . ' 2x" '
834 . 'height="31" width="88" alt="Powered by MediaWiki" /></a>';
835 Hooks::run( 'SkinGetPoweredBy', [ &$text, $this ] );
836 return $text;
837 }
838
839 /**
840 * Get the timestamp of the latest revision, formatted in user language
841 *
842 * @return string
843 */
844 protected function lastModified() {
845 $timestamp = $this->getOutput()->getRevisionTimestamp();
846
847 # No cached timestamp, load it from the database
848 if ( $timestamp === null ) {
849 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
850 }
851
852 if ( $timestamp ) {
853 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
854 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
855 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->parse();
856 } else {
857 $s = '';
858 }
859
860 if ( wfGetLB()->getLaggedReplicaMode() ) {
861 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
862 }
863
864 return $s;
865 }
866
867 /**
868 * @param string $align
869 * @return string
870 */
871 function logoText( $align = '' ) {
872 if ( $align != '' ) {
873 $a = " style='float: {$align};'";
874 } else {
875 $a = '';
876 }
877
878 $mp = $this->msg( 'mainpage' )->escaped();
879 $mptitle = Title::newMainPage();
880 $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
881
882 $logourl = $this->getLogo();
883 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
884
885 return $s;
886 }
887
888 /**
889 * Renders a $wgFooterIcons icon according to the method's arguments
890 * @param array $icon The icon to build the html for, see $wgFooterIcons
891 * for the format of this array.
892 * @param bool|string $withImage Whether to use the icon's image or output
893 * a text-only footericon.
894 * @return string HTML
895 */
896 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
897 if ( is_string( $icon ) ) {
898 $html = $icon;
899 } else { // Assuming array
900 $url = isset( $icon["url"] ) ? $icon["url"] : null;
901 unset( $icon["url"] );
902 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
903 // do this the lazy way, just pass icon data as an attribute array
904 $html = Html::element( 'img', $icon );
905 } else {
906 $html = htmlspecialchars( $icon["alt"] );
907 }
908 if ( $url ) {
909 global $wgExternalLinkTarget;
910 $html = Html::rawElement( 'a',
911 [ "href" => $url, "target" => $wgExternalLinkTarget ],
912 $html );
913 }
914 }
915 return $html;
916 }
917
918 /**
919 * Gets the link to the wiki's main page.
920 * @return string
921 */
922 function mainPageLink() {
923 $s = Linker::linkKnown(
924 Title::newMainPage(),
925 $this->msg( 'mainpage' )->escaped()
926 );
927
928 return $s;
929 }
930
931 /**
932 * Returns an HTML link for use in the footer
933 * @param string $desc The i18n message key for the link text
934 * @param string $page The i18n message key for the page to link to
935 * @return string HTML anchor
936 */
937 public function footerLink( $desc, $page ) {
938 $title = $this->footerLinkTitle( $desc, $page );
939 if ( !$title ) {
940 return '';
941 }
942
943 return Linker::linkKnown(
944 $title,
945 $this->msg( $desc )->escaped()
946 );
947 }
948
949 /**
950 * @param string $desc
951 * @param string $page
952 * @return Title|null
953 */
954 private function footerLinkTitle( $desc, $page ) {
955 // If the link description has been set to "-" in the default language,
956 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
957 // then it is disabled, for all languages.
958 return null;
959 }
960 // Otherwise, we display the link for the user, described in their
961 // language (which may or may not be the same as the default language),
962 // but we make the link target be the one site-wide page.
963 $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
964
965 return $title ?: null;
966 }
967
968 /**
969 * Gets the link to the wiki's privacy policy page.
970 * @return string HTML
971 */
972 function privacyLink() {
973 return $this->footerLink( 'privacy', 'privacypage' );
974 }
975
976 /**
977 * Gets the link to the wiki's about page.
978 * @return string HTML
979 */
980 function aboutLink() {
981 return $this->footerLink( 'aboutsite', 'aboutpage' );
982 }
983
984 /**
985 * Gets the link to the wiki's general disclaimers page.
986 * @return string HTML
987 */
988 function disclaimerLink() {
989 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
990 }
991
992 /**
993 * Return URL options for the 'edit page' link.
994 * This may include an 'oldid' specifier, if the current page view is such.
995 *
996 * @return array
997 * @private
998 */
999 function editUrlOptions() {
1000 $options = [ 'action' => 'edit' ];
1001
1002 if ( !$this->isRevisionCurrent() ) {
1003 $options['oldid'] = intval( $this->getRevisionId() );
1004 }
1005
1006 return $options;
1007 }
1008
1009 /**
1010 * @param User|int $id
1011 * @return bool
1012 */
1013 function showEmailUser( $id ) {
1014 if ( $id instanceof User ) {
1015 $targetUser = $id;
1016 } else {
1017 $targetUser = User::newFromId( $id );
1018 }
1019
1020 # The sending user must have a confirmed email address and the target
1021 # user must have a confirmed email address and allow emails from users.
1022 return $this->getUser()->canSendEmail() &&
1023 $targetUser->canReceiveEmail();
1024 }
1025
1026 /**
1027 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1028 * This method returns a url resolved using the configured skin style path
1029 * and includes the style version inside of the url.
1030 *
1031 * Requires $stylename to be set, otherwise throws MWException.
1032 *
1033 * @param string $name The name or path of a skin resource file
1034 * @return string The fully resolved style path url including styleversion
1035 * @throws MWException
1036 */
1037 function getSkinStylePath( $name ) {
1038 global $wgStylePath, $wgStyleVersion;
1039
1040 if ( $this->stylename === null ) {
1041 $class = static::class;
1042 throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
1043 }
1044
1045 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1046 }
1047
1048 /* these are used extensively in SkinTemplate, but also some other places */
1049
1050 /**
1051 * @param string $urlaction
1052 * @return string
1053 */
1054 static function makeMainPageUrl( $urlaction = '' ) {
1055 $title = Title::newMainPage();
1056 self::checkTitle( $title, '' );
1057
1058 return $title->getLocalURL( $urlaction );
1059 }
1060
1061 /**
1062 * Make a URL for a Special Page using the given query and protocol.
1063 *
1064 * If $proto is set to null, make a local URL. Otherwise, make a full
1065 * URL with the protocol specified.
1066 *
1067 * @param string $name Name of the Special page
1068 * @param string $urlaction Query to append
1069 * @param string|null $proto Protocol to use or null for a local URL
1070 * @return string
1071 */
1072 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1073 $title = SpecialPage::getSafeTitleFor( $name );
1074 if ( is_null( $proto ) ) {
1075 return $title->getLocalURL( $urlaction );
1076 } else {
1077 return $title->getFullURL( $urlaction, false, $proto );
1078 }
1079 }
1080
1081 /**
1082 * @param string $name
1083 * @param string $subpage
1084 * @param string $urlaction
1085 * @return string
1086 */
1087 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1088 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1089 return $title->getLocalURL( $urlaction );
1090 }
1091
1092 /**
1093 * @param string $name
1094 * @param string $urlaction
1095 * @return string
1096 */
1097 static function makeI18nUrl( $name, $urlaction = '' ) {
1098 $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1099 self::checkTitle( $title, $name );
1100 return $title->getLocalURL( $urlaction );
1101 }
1102
1103 /**
1104 * @param string $name
1105 * @param string $urlaction
1106 * @return string
1107 */
1108 static function makeUrl( $name, $urlaction = '' ) {
1109 $title = Title::newFromText( $name );
1110 self::checkTitle( $title, $name );
1111
1112 return $title->getLocalURL( $urlaction );
1113 }
1114
1115 /**
1116 * If url string starts with http, consider as external URL, else
1117 * internal
1118 * @param string $name
1119 * @return string URL
1120 */
1121 static function makeInternalOrExternalUrl( $name ) {
1122 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1123 return $name;
1124 } else {
1125 return self::makeUrl( $name );
1126 }
1127 }
1128
1129 /**
1130 * this can be passed the NS number as defined in Language.php
1131 * @param string $name
1132 * @param string $urlaction
1133 * @param int $namespace
1134 * @return string
1135 */
1136 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1137 $title = Title::makeTitleSafe( $namespace, $name );
1138 self::checkTitle( $title, $name );
1139
1140 return $title->getLocalURL( $urlaction );
1141 }
1142
1143 /**
1144 * these return an array with the 'href' and boolean 'exists'
1145 * @param string $name
1146 * @param string $urlaction
1147 * @return array
1148 */
1149 static function makeUrlDetails( $name, $urlaction = '' ) {
1150 $title = Title::newFromText( $name );
1151 self::checkTitle( $title, $name );
1152
1153 return [
1154 'href' => $title->getLocalURL( $urlaction ),
1155 'exists' => $title->isKnown(),
1156 ];
1157 }
1158
1159 /**
1160 * Make URL details where the article exists (or at least it's convenient to think so)
1161 * @param string $name Article name
1162 * @param string $urlaction
1163 * @return array
1164 */
1165 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1166 $title = Title::newFromText( $name );
1167 self::checkTitle( $title, $name );
1168
1169 return [
1170 'href' => $title->getLocalURL( $urlaction ),
1171 'exists' => true
1172 ];
1173 }
1174
1175 /**
1176 * make sure we have some title to operate on
1177 *
1178 * @param Title $title
1179 * @param string $name
1180 */
1181 static function checkTitle( &$title, $name ) {
1182 if ( !is_object( $title ) ) {
1183 $title = Title::newFromText( $name );
1184 if ( !is_object( $title ) ) {
1185 $title = Title::newFromText( '--error: link target missing--' );
1186 }
1187 }
1188 }
1189
1190 /**
1191 * Build an array that represents the sidebar(s), the navigation bar among them.
1192 *
1193 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1194 *
1195 * The format of the returned array is [ heading => content, ... ], where:
1196 * - heading is the heading of a navigation portlet. It is either:
1197 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1198 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1199 * - plain text, which should be HTML-escaped by the skin
1200 * - content is the contents of the portlet. It is either:
1201 * - HTML text (<ul><li>...</li>...</ul>)
1202 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1203 * - (for a magic string as a key, any value)
1204 *
1205 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1206 * and can technically insert anything in here; skin creators are expected to handle
1207 * values described above.
1208 *
1209 * @return array
1210 */
1211 function buildSidebar() {
1212 global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1213
1214 $that = $this;
1215 $callback = function () use ( $that ) {
1216 $bar = [];
1217 $that->addToSidebar( $bar, 'sidebar' );
1218 Hooks::run( 'SkinBuildSidebar', [ $that, &$bar ] );
1219
1220 return $bar;
1221 };
1222
1223 if ( $wgEnableSidebarCache ) {
1224 $cache = ObjectCache::getMainWANInstance();
1225 $sidebar = $cache->getWithSetCallback(
1226 $cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
1227 MessageCache::singleton()->isDisabled()
1228 ? $cache::TTL_UNCACHEABLE // bug T133069
1229 : $wgSidebarCacheExpiry,
1230 $callback,
1231 [ 'lockTSE' => 30 ]
1232 );
1233 } else {
1234 $sidebar = $callback();
1235 }
1236
1237 // Apply post-processing to the cached value
1238 Hooks::run( 'SidebarBeforeOutput', [ $this, &$sidebar ] );
1239
1240 return $sidebar;
1241 }
1242
1243 /**
1244 * Add content from a sidebar system message
1245 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1246 *
1247 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1248 *
1249 * @param array $bar
1250 * @param string $message
1251 */
1252 public function addToSidebar( &$bar, $message ) {
1253 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1254 }
1255
1256 /**
1257 * Add content from plain text
1258 * @since 1.17
1259 * @param array $bar
1260 * @param string $text
1261 * @return array
1262 */
1263 function addToSidebarPlain( &$bar, $text ) {
1264 $lines = explode( "\n", $text );
1265
1266 $heading = '';
1267 $messageTitle = $this->getConfig()->get( 'EnableSidebarCache' )
1268 ? Title::newMainPage() : $this->getTitle();
1269
1270 foreach ( $lines as $line ) {
1271 if ( strpos( $line, '*' ) !== 0 ) {
1272 continue;
1273 }
1274 $line = rtrim( $line, "\r" ); // for Windows compat
1275
1276 if ( strpos( $line, '**' ) !== 0 ) {
1277 $heading = trim( $line, '* ' );
1278 if ( !array_key_exists( $heading, $bar ) ) {
1279 $bar[$heading] = [];
1280 }
1281 } else {
1282 $line = trim( $line, '* ' );
1283
1284 if ( strpos( $line, '|' ) !== false ) { // sanity check
1285 $line = MessageCache::singleton()->transform( $line, false, null, $messageTitle );
1286 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1287 if ( count( $line ) !== 2 ) {
1288 // Second sanity check, could be hit by people doing
1289 // funky stuff with parserfuncs... (T35321)
1290 continue;
1291 }
1292
1293 $extraAttribs = [];
1294
1295 $msgLink = $this->msg( $line[0] )->title( $messageTitle )->inContentLanguage();
1296 if ( $msgLink->exists() ) {
1297 $link = $msgLink->text();
1298 if ( $link == '-' ) {
1299 continue;
1300 }
1301 } else {
1302 $link = $line[0];
1303 }
1304 $msgText = $this->msg( $line[1] )->title( $messageTitle );
1305 if ( $msgText->exists() ) {
1306 $text = $msgText->text();
1307 } else {
1308 $text = $line[1];
1309 }
1310
1311 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1312 $href = $link;
1313
1314 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1315 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1316 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1317 $extraAttribs['rel'] = 'nofollow';
1318 }
1319
1320 global $wgExternalLinkTarget;
1321 if ( $wgExternalLinkTarget ) {
1322 $extraAttribs['target'] = $wgExternalLinkTarget;
1323 }
1324 } else {
1325 $title = Title::newFromText( $link );
1326
1327 if ( $title ) {
1328 $title = $title->fixSpecialName();
1329 $href = $title->getLinkURL();
1330 } else {
1331 $href = 'INVALID-TITLE';
1332 }
1333 }
1334
1335 $bar[$heading][] = array_merge( [
1336 'text' => $text,
1337 'href' => $href,
1338 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1339 'active' => false
1340 ], $extraAttribs );
1341 } else {
1342 continue;
1343 }
1344 }
1345 }
1346
1347 return $bar;
1348 }
1349
1350 /**
1351 * Gets new talk page messages for the current user and returns an
1352 * appropriate alert message (or an empty string if there are no messages)
1353 * @return string
1354 */
1355 function getNewtalks() {
1356
1357 $newMessagesAlert = '';
1358 $user = $this->getUser();
1359 $newtalks = $user->getNewMessageLinks();
1360 $out = $this->getOutput();
1361
1362 // Allow extensions to disable or modify the new messages alert
1363 if ( !Hooks::run( 'GetNewMessagesAlert', [ &$newMessagesAlert, $newtalks, $user, $out ] ) ) {
1364 return '';
1365 }
1366 if ( $newMessagesAlert ) {
1367 return $newMessagesAlert;
1368 }
1369
1370 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1371 $uTalkTitle = $user->getTalkPage();
1372 $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
1373 $nofAuthors = 0;
1374 if ( $lastSeenRev !== null ) {
1375 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1376 $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
1377 if ( $latestRev !== null ) {
1378 // Singular if only 1 unseen revision, plural if several unseen revisions.
1379 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1380 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1381 $lastSeenRev, $latestRev, 10, 'include_new' );
1382 }
1383 } else {
1384 // Singular if no revision -> diff link will show latest change only in any case
1385 $plural = false;
1386 }
1387 $plural = $plural ? 999 : 1;
1388 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1389 // the number of revisions or authors is not necessarily the same as the number of
1390 // "messages".
1391 $newMessagesLink = Linker::linkKnown(
1392 $uTalkTitle,
1393 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1394 [],
1395 [ 'redirect' => 'no' ]
1396 );
1397
1398 $newMessagesDiffLink = Linker::linkKnown(
1399 $uTalkTitle,
1400 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1401 [],
1402 $lastSeenRev !== null
1403 ? [ 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' ]
1404 : [ 'diff' => 'cur' ]
1405 );
1406
1407 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1408 $newMessagesAlert = $this->msg(
1409 'youhavenewmessagesfromusers',
1410 $newMessagesLink,
1411 $newMessagesDiffLink
1412 )->numParams( $nofAuthors, $plural );
1413 } else {
1414 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1415 $newMessagesAlert = $this->msg(
1416 $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1417 $newMessagesLink,
1418 $newMessagesDiffLink
1419 )->numParams( $plural );
1420 }
1421 $newMessagesAlert = $newMessagesAlert->text();
1422 # Disable CDN cache
1423 $out->setCdnMaxage( 0 );
1424 } elseif ( count( $newtalks ) ) {
1425 $sep = $this->msg( 'newtalkseparator' )->escaped();
1426 $msgs = [];
1427
1428 foreach ( $newtalks as $newtalk ) {
1429 $msgs[] = Xml::element(
1430 'a',
1431 [ 'href' => $newtalk['link'] ], $newtalk['wiki']
1432 );
1433 }
1434 $parts = implode( $sep, $msgs );
1435 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1436 $out->setCdnMaxage( 0 );
1437 }
1438
1439 return $newMessagesAlert;
1440 }
1441
1442 /**
1443 * Get a cached notice
1444 *
1445 * @param string $name Message name, or 'default' for $wgSiteNotice
1446 * @return string|bool HTML fragment, or false to indicate that the caller
1447 * should fall back to the next notice in its sequence
1448 */
1449 private function getCachedNotice( $name ) {
1450 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1451
1452 $needParse = false;
1453
1454 if ( $name === 'default' ) {
1455 // special case
1456 global $wgSiteNotice;
1457 $notice = $wgSiteNotice;
1458 if ( empty( $notice ) ) {
1459 return false;
1460 }
1461 } else {
1462 $msg = $this->msg( $name )->inContentLanguage();
1463 if ( $msg->isBlank() ) {
1464 return '';
1465 } elseif ( $msg->isDisabled() ) {
1466 return false;
1467 }
1468 $notice = $msg->plain();
1469 }
1470
1471 // Use the extra hash appender to let eg SSL variants separately cache.
1472 $key = wfMemcKey( $name . $wgRenderHashAppend );
1473 $cachedNotice = $parserMemc->get( $key );
1474 if ( is_array( $cachedNotice ) ) {
1475 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1476 $notice = $cachedNotice['html'];
1477 } else {
1478 $needParse = true;
1479 }
1480 } else {
1481 $needParse = true;
1482 }
1483
1484 if ( $needParse ) {
1485 $parsed = $this->getOutput()->parse( $notice );
1486 $parserMemc->set( $key, [ 'html' => $parsed, 'hash' => md5( $notice ) ], 600 );
1487 $notice = $parsed;
1488 }
1489
1490 $notice = Html::rawElement( 'div', [ 'id' => 'localNotice',
1491 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ], $notice );
1492 return $notice;
1493 }
1494
1495 /**
1496 * Get the site notice
1497 *
1498 * @return string HTML fragment
1499 */
1500 function getSiteNotice() {
1501 $siteNotice = '';
1502
1503 if ( Hooks::run( 'SiteNoticeBefore', [ &$siteNotice, $this ] ) ) {
1504 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1505 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1506 } else {
1507 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1508 if ( $anonNotice === false ) {
1509 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1510 } else {
1511 $siteNotice = $anonNotice;
1512 }
1513 }
1514 if ( $siteNotice === false ) {
1515 $siteNotice = $this->getCachedNotice( 'default' );
1516 }
1517 }
1518
1519 Hooks::run( 'SiteNoticeAfter', [ &$siteNotice, $this ] );
1520 return $siteNotice;
1521 }
1522
1523 /**
1524 * Create a section edit link. This supersedes editSectionLink() and
1525 * editSectionLinkForOther().
1526 *
1527 * @param Title $nt The title being linked to (may not be the same as
1528 * the current page, if the section is included from a template)
1529 * @param string $section The designation of the section being pointed to,
1530 * to be included in the link, like "&section=$section"
1531 * @param string $tooltip The tooltip to use for the link: will be escaped
1532 * and wrapped in the 'editsectionhint' message
1533 * @param string $lang Language code
1534 * @return string HTML to use for edit link
1535 */
1536 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1537 // HTML generated here should probably have userlangattributes
1538 // added to it for LTR text on RTL pages
1539
1540 $lang = wfGetLangObj( $lang );
1541
1542 $attribs = [];
1543 if ( !is_null( $tooltip ) ) {
1544 # T27462: undo double-escaping.
1545 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1546 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1547 ->inLanguage( $lang )->text();
1548 }
1549
1550 $links = [
1551 'editsection' => [
1552 'text' => wfMessage( 'editsection' )->inLanguage( $lang )->escaped(),
1553 'targetTitle' => $nt,
1554 'attribs' => $attribs,
1555 'query' => [ 'action' => 'edit', 'section' => $section ],
1556 'options' => [ 'noclasses', 'known' ]
1557 ]
1558 ];
1559
1560 Hooks::run( 'SkinEditSectionLinks', [ $this, $nt, $section, $tooltip, &$links, $lang ] );
1561
1562 $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
1563
1564 $linksHtml = [];
1565 foreach ( $links as $k => $linkDetails ) {
1566 $linksHtml[] = Linker::link(
1567 $linkDetails['targetTitle'],
1568 $linkDetails['text'],
1569 $linkDetails['attribs'],
1570 $linkDetails['query'],
1571 $linkDetails['options']
1572 );
1573 }
1574
1575 $result .= implode(
1576 '<span class="mw-editsection-divider">'
1577 . wfMessage( 'pipe-separator' )->inLanguage( $lang )->text()
1578 . '</span>',
1579 $linksHtml
1580 );
1581
1582 $result .= '<span class="mw-editsection-bracket">]</span></span>';
1583 // Deprecated, use SkinEditSectionLinks hook instead
1584 Hooks::run(
1585 'DoEditSectionLink',
1586 [ $this, $nt, $section, $tooltip, &$result, $lang ],
1587 '1.25'
1588 );
1589 return $result;
1590 }
1591
1592 }