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