Merge "Remove Sajax"
[lhc/web/wiklou.git] / includes / skins / Skin.php
1 <?php
2 /**
3 * Base class for all skins.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 /**
24 * @defgroup Skins Skins
25 */
26
27 /**
28 * The main skin class which provides methods and properties for all other skins.
29 *
30 * See docs/skin.txt for more information.
31 *
32 * @ingroup Skins
33 */
34 abstract class Skin extends ContextSource {
35 protected $skinname = null;
36 protected $mRelevantTitle = null;
37 protected $mRelevantUser = null;
38
39 /**
40 * @var string Stylesheets set to use. Subdirectory in skins/ where various stylesheets are
41 * located. Only needs to be set if you intend to use the getSkinStylePath() method.
42 */
43 public $stylename = null;
44
45 /**
46 * Fetch the set of available skins.
47 * @return array Associative array of strings
48 */
49 static function getSkinNames() {
50 return SkinFactory::getDefaultInstance()->getSkinNames();
51 }
52
53 /**
54 * Fetch the skinname messages for available skins.
55 * @return string[]
56 */
57 static function getSkinNameMessages() {
58 $messages = array();
59 foreach ( self::getSkinNames() as $skinKey => $skinName ) {
60 $messages[] = "skinname-$skinKey";
61 }
62 return $messages;
63 }
64
65 /**
66 * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
67 * Useful for Special:Preferences and other places where you
68 * only want to show skins users _can_ use.
69 * @return string[]
70 * @since 1.23
71 */
72 public static function getAllowedSkins() {
73 global $wgSkipSkins;
74
75 $allowedSkins = self::getSkinNames();
76
77 foreach ( $wgSkipSkins as $skip ) {
78 unset( $allowedSkins[$skip] );
79 }
80
81 return $allowedSkins;
82 }
83
84 /**
85 * @deprecated since 1.23, use getAllowedSkins
86 * @return string[]
87 */
88 public static function getUsableSkins() {
89 wfDeprecated( __METHOD__, '1.23' );
90 return self::getAllowedSkins();
91 }
92
93 /**
94 * Normalize a skin preference value to a form that can be loaded.
95 *
96 * If a skin can't be found, it will fall back to the configured default ($wgDefaultSkin), or the
97 * hardcoded default ($wgFallbackSkin) if the default skin is unavailable too.
98 *
99 * @param string $key 'monobook', 'vector', etc.
100 * @return string
101 */
102 static function normalizeKey( $key ) {
103 global $wgDefaultSkin, $wgFallbackSkin;
104
105 $skinNames = Skin::getSkinNames();
106
107 // Make keys lowercase for case-insensitive matching.
108 $skinNames = array_change_key_case( $skinNames, CASE_LOWER );
109 $key = strtolower( $key );
110 $defaultSkin = strtolower( $wgDefaultSkin );
111 $fallbackSkin = strtolower( $wgFallbackSkin );
112
113 if ( $key == '' || $key == 'default' ) {
114 // Don't return the default immediately;
115 // in a misconfiguration we need to fall back.
116 $key = $defaultSkin;
117 }
118
119 if ( isset( $skinNames[$key] ) ) {
120 return $key;
121 }
122
123 // Older versions of the software used a numeric setting
124 // in the user preferences.
125 $fallback = array(
126 0 => $defaultSkin,
127 2 => 'cologneblue'
128 );
129
130 if ( isset( $fallback[$key] ) ) {
131 $key = $fallback[$key];
132 }
133
134 if ( isset( $skinNames[$key] ) ) {
135 return $key;
136 } elseif ( isset( $skinNames[$defaultSkin] ) ) {
137 return $defaultSkin;
138 } else {
139 return $fallbackSkin;
140 }
141 }
142
143 /**
144 * Factory method for loading a skin of a given type
145 * @param string $key 'monobook', 'vector', etc.
146 * @return Skin
147 * @deprecated since 1.24; Use SkinFactory instead
148 */
149 static function &newFromKey( $key ) {
150 wfDeprecated( __METHOD__, '1.24' );
151
152 $key = Skin::normalizeKey( $key );
153 $factory = SkinFactory::getDefaultInstance();
154
155 // normalizeKey() guarantees that a skin with this key will exist.
156 $skin = $factory->makeSkin( $key );
157 return $skin;
158 }
159
160 /**
161 * @return string Skin name
162 */
163 public function getSkinName() {
164 return $this->skinname;
165 }
166
167 /**
168 * @param OutputPage $out
169 */
170 function initPage( OutputPage $out ) {
171
172 $this->preloadExistence();
173
174 }
175
176 /**
177 * Defines the ResourceLoader modules that should be added to the skin
178 * It is recommended that skins wishing to override call parent::getDefaultModules()
179 * and substitute out any modules they wish to change by using a key to look them up
180 * @return array Array of modules with helper keys for easy overriding
181 */
182 public function getDefaultModules() {
183 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
184 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
185
186 $out = $this->getOutput();
187 $user = $out->getUser();
188 $modules = array(
189 // modules that enhance the page content in some way
190 'content' => array(
191 'mediawiki.page.ready',
192 ),
193 // modules that exist for legacy reasons
194 'legacy' => array(),
195 // modules relating to search functionality
196 'search' => array(),
197 // modules relating to functionality relating to watching an article
198 'watch' => array(),
199 // modules which relate to the current users preferences
200 'user' => array(),
201 );
202 if ( $wgIncludeLegacyJavaScript ) {
203 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
204 }
205
206 if ( $wgPreloadJavaScriptMwUtil ) {
207 $modules['legacy'][] = 'mediawiki.util';
208 }
209
210 // Add various resources if required
211 if ( $wgUseAjax ) {
212 if ( $wgEnableAPI ) {
213 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
214 && $user->isAllowed( 'writeapi' )
215 ) {
216 $modules['watch'][] = 'mediawiki.page.watch.ajax';
217 }
218
219 $modules['search'][] = 'mediawiki.searchSuggest';
220 }
221 }
222
223 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
224 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
225 }
226
227 // Crazy edit-on-double-click stuff
228 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
229 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
230 }
231 return $modules;
232 }
233
234 /**
235 * Preload the existence of three commonly-requested pages in a single query
236 */
237 function preloadExistence() {
238 $titles = array();
239
240 $user = $this->getUser();
241 $title = $this->getRelevantTitle();
242
243 // User/talk link
244 if ( $user->isLoggedIn() || $this->showIPinHeader() ) {
245 $titles[] = $user->getUserPage();
246 $titles[] = $user->getTalkPage();
247 }
248
249 // Other tab link
250 if ( $title->isSpecialPage() ) {
251 // nothing
252 } elseif ( $title->isTalkPage() ) {
253 $titles[] = $title->getSubjectPage();
254 } else {
255 $titles[] = $title->getTalkPage();
256 }
257
258 Hooks::run( 'SkinPreloadExistence', array( &$titles, $this ) );
259
260 if ( count( $titles ) ) {
261 $lb = new LinkBatch( $titles );
262 $lb->setCaller( __METHOD__ );
263 $lb->execute();
264 }
265 }
266
267 /**
268 * Get the current revision ID
269 *
270 * @return int
271 */
272 public function getRevisionId() {
273 return $this->getOutput()->getRevisionId();
274 }
275
276 /**
277 * Whether the revision displayed is the latest revision of the page
278 *
279 * @return bool
280 */
281 public function isRevisionCurrent() {
282 $revID = $this->getRevisionId();
283 return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
284 }
285
286 /**
287 * Set the "relevant" title
288 * @see self::getRelevantTitle()
289 * @param Title $t
290 */
291 public function setRelevantTitle( $t ) {
292 $this->mRelevantTitle = $t;
293 }
294
295 /**
296 * Return the "relevant" title.
297 * A "relevant" title is not necessarily the actual title of the page.
298 * Special pages like Special:MovePage use set the page they are acting on
299 * as their "relevant" title, this allows the skin system to display things
300 * such as content tabs which belong to to that page instead of displaying
301 * a basic special page tab which has almost no meaning.
302 *
303 * @return Title
304 */
305 public function getRelevantTitle() {
306 if ( isset( $this->mRelevantTitle ) ) {
307 return $this->mRelevantTitle;
308 }
309 return $this->getTitle();
310 }
311
312 /**
313 * Set the "relevant" user
314 * @see self::getRelevantUser()
315 * @param User $u
316 */
317 public function setRelevantUser( $u ) {
318 $this->mRelevantUser = $u;
319 }
320
321 /**
322 * Return the "relevant" user.
323 * A "relevant" user is similar to a relevant title. Special pages like
324 * Special:Contributions mark the user which they are relevant to so that
325 * things like the toolbox can display the information they usually are only
326 * able to display on a user's userpage and talkpage.
327 * @return User
328 */
329 public function getRelevantUser() {
330 if ( isset( $this->mRelevantUser ) ) {
331 return $this->mRelevantUser;
332 }
333 $title = $this->getRelevantTitle();
334 if ( $title->hasSubjectNamespace( NS_USER ) ) {
335 $rootUser = $title->getRootText();
336 if ( User::isIP( $rootUser ) ) {
337 $this->mRelevantUser = User::newFromName( $rootUser, false );
338 } else {
339 $user = User::newFromName( $rootUser, false );
340
341 if ( $user ) {
342 $user->load( User::READ_NORMAL );
343
344 if ( $user->isLoggedIn() ) {
345 $this->mRelevantUser = $user;
346 }
347 }
348 }
349 return $this->mRelevantUser;
350 }
351 return null;
352 }
353
354 /**
355 * Outputs the HTML generated by other functions.
356 * @param OutputPage $out
357 */
358 abstract function outputPage( OutputPage $out = null );
359
360 /**
361 * @param array $data
362 * @return string
363 */
364 static function makeVariablesScript( $data ) {
365 if ( $data ) {
366 return ResourceLoader::makeInlineScript(
367 ResourceLoader::makeConfigSetScript( $data )
368 );
369 } else {
370 return '';
371 }
372 }
373
374 /**
375 * Get the query to generate a dynamic stylesheet
376 *
377 * @return array
378 */
379 public static function getDynamicStylesheetQuery() {
380 global $wgSquidMaxage;
381
382 return array(
383 'action' => 'raw',
384 'maxage' => $wgSquidMaxage,
385 'usemsgcache' => 'yes',
386 'ctype' => 'text/css',
387 'smaxage' => $wgSquidMaxage,
388 );
389 }
390
391 /**
392 * Add skin specific stylesheets
393 * Calling this method with an $out of anything but the same OutputPage
394 * inside ->getOutput() is deprecated. The $out arg is kept
395 * for compatibility purposes with skins.
396 * @param OutputPage $out
397 * @todo delete
398 */
399 abstract function setupSkinUserCss( OutputPage $out );
400
401 /**
402 * TODO: document
403 * @param Title $title
404 * @return string
405 */
406 function getPageClasses( $title ) {
407 $numeric = 'ns-' . $title->getNamespace();
408
409 if ( $title->isSpecialPage() ) {
410 $type = 'ns-special';
411 // bug 23315: provide a class based on the canonical special page name without subpages
412 list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
413 if ( $canonicalName ) {
414 $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
415 } else {
416 $type .= ' mw-invalidspecialpage';
417 }
418 } elseif ( $title->isTalkPage() ) {
419 $type = 'ns-talk';
420 } else {
421 $type = 'ns-subject';
422 }
423
424 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
425
426 return "$numeric $type $name";
427 }
428
429 /**
430 * Return values for <html> element
431 * @return array Array of associative name-to-value elements for <html> element
432 */
433 public function getHtmlElementAttributes() {
434 $lang = $this->getLanguage();
435 return array(
436 'lang' => $lang->getHtmlCode(),
437 'dir' => $lang->getDir(),
438 'class' => 'client-nojs',
439 );
440 }
441
442 /**
443 * This will be called by OutputPage::headElement when it is creating the
444 * "<body>" tag, skins can override it if they have a need to add in any
445 * body attributes or classes of their own.
446 * @param OutputPage $out
447 * @param array $bodyAttrs
448 */
449 function addToBodyAttributes( $out, &$bodyAttrs ) {
450 // does nothing by default
451 }
452
453 /**
454 * URL to the logo
455 * @return string
456 */
457 function getLogo() {
458 global $wgLogo;
459 return $wgLogo;
460 }
461
462 /**
463 * @return string
464 */
465 function getCategoryLinks() {
466 global $wgUseCategoryBrowser;
467
468 $out = $this->getOutput();
469 $allCats = $out->getCategoryLinks();
470
471 if ( !count( $allCats ) ) {
472 return '';
473 }
474
475 $embed = "<li>";
476 $pop = "</li>";
477
478 $s = '';
479 $colon = $this->msg( 'colon-separator' )->escaped();
480
481 if ( !empty( $allCats['normal'] ) ) {
482 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
483
484 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
485 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
486 $title = Title::newFromText( $linkPage );
487 $link = $title ? Linker::link( $title, $msg ) : $msg;
488 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
489 $link . $colon . '<ul>' . $t . '</ul>' . '</div>';
490 }
491
492 # Hidden categories
493 if ( isset( $allCats['hidden'] ) ) {
494 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
495 $class = ' mw-hidden-cats-user-shown';
496 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
497 $class = ' mw-hidden-cats-ns-shown';
498 } else {
499 $class = ' mw-hidden-cats-hidden';
500 }
501
502 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
503 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
504 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
505 '</div>';
506 }
507
508 # optional 'dmoz-like' category browser. Will be shown under the list
509 # of categories an article belong to
510 if ( $wgUseCategoryBrowser ) {
511 $s .= '<br /><hr />';
512
513 # get a big array of the parents tree
514 $parenttree = $this->getTitle()->getParentCategoryTree();
515 # Skin object passed by reference cause it can not be
516 # accessed under the method subfunction drawCategoryBrowser
517 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
518 # Clean out bogus first entry and sort them
519 unset( $tempout[0] );
520 asort( $tempout );
521 # Output one per line
522 $s .= implode( "<br />\n", $tempout );
523 }
524
525 return $s;
526 }
527
528 /**
529 * Render the array as a series of links.
530 * @param array $tree Categories tree returned by Title::getParentCategoryTree
531 * @return string Separated by &gt;, terminate with "\n"
532 */
533 function drawCategoryBrowser( $tree ) {
534 $return = '';
535
536 foreach ( $tree as $element => $parent ) {
537 if ( empty( $parent ) ) {
538 # element start a new list
539 $return .= "\n";
540 } else {
541 # grab the others elements
542 $return .= $this->drawCategoryBrowser( $parent ) . ' &gt; ';
543 }
544
545 # add our current element to the list
546 $eltitle = Title::newFromText( $element );
547 $return .= Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
548 }
549
550 return $return;
551 }
552
553 /**
554 * @return string
555 */
556 function getCategories() {
557 $out = $this->getOutput();
558
559 $catlinks = $this->getCategoryLinks();
560
561 $classes = 'catlinks';
562
563 // Check what we're showing
564 $allCats = $out->getCategoryLinks();
565 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
566 $this->getTitle()->getNamespace() == NS_CATEGORY;
567
568 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
569 $classes .= ' catlinks-allhidden';
570 }
571
572 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
573 }
574
575 /**
576 * This runs a hook to allow extensions placing their stuff after content
577 * and article metadata (e.g. categories).
578 * Note: This function has nothing to do with afterContent().
579 *
580 * This hook is placed here in order to allow using the same hook for all
581 * skins, both the SkinTemplate based ones and the older ones, which directly
582 * use this class to get their data.
583 *
584 * The output of this function gets processed in SkinTemplate::outputPage() for
585 * the SkinTemplate based skins, all other skins should directly echo it.
586 *
587 * @return string Empty by default, if not changed by any hook function.
588 */
589 protected function afterContentHook() {
590 $data = '';
591
592 if ( Hooks::run( 'SkinAfterContent', array( &$data, $this ) ) ) {
593 // adding just some spaces shouldn't toggle the output
594 // of the whole <div/>, so we use trim() here
595 if ( trim( $data ) != '' ) {
596 // Doing this here instead of in the skins to
597 // ensure that the div has the same ID in all
598 // skins
599 $data = "<div id='mw-data-after-content'>\n" .
600 "\t$data\n" .
601 "</div>\n";
602 }
603 } else {
604 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
605 }
606
607 return $data;
608 }
609
610 /**
611 * Generate debug data HTML for displaying at the bottom of the main content
612 * area.
613 * @return string HTML containing debug data, if enabled (otherwise empty).
614 */
615 protected function generateDebugHTML() {
616 return MWDebug::getHTMLDebugLog();
617 }
618
619 /**
620 * This gets called shortly before the "</body>" tag.
621 *
622 * @return string HTML-wrapped JS code to be put before "</body>"
623 */
624 function bottomScripts() {
625 // TODO and the suckage continues. This function is really just a wrapper around
626 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
627 // up at some point
628 $bottomScriptText = $this->getOutput()->getBottomScripts();
629 Hooks::run( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
630
631 return $bottomScriptText;
632 }
633
634 /**
635 * Text with the permalink to the source page,
636 * usually shown on the footer of a printed page
637 *
638 * @return string HTML text with an URL
639 */
640 function printSource() {
641 $oldid = $this->getRevisionId();
642 if ( $oldid ) {
643 $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
644 $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
645 } else {
646 // oldid not available for non existing pages
647 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
648 }
649
650 return $this->msg( 'retrievedfrom' )
651 ->rawParams( '<a dir="ltr" href="' . $url . '">' . $url . '</a>' )
652 ->parse();
653 }
654
655 /**
656 * @return string HTML
657 */
658 function getUndeleteLink() {
659 $action = $this->getRequest()->getVal( 'action', 'view' );
660
661 if ( $this->getTitle()->userCan( 'deletedhistory', $this->getUser() ) &&
662 ( !$this->getTitle()->exists() || $action == 'history' ) ) {
663 $n = $this->getTitle()->isDeleted();
664
665 if ( $n ) {
666 if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {
667 $msg = 'thisisdeleted';
668 } else {
669 $msg = 'viewdeleted';
670 }
671
672 return $this->msg( $msg )->rawParams(
673 Linker::linkKnown(
674 SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
675 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
676 )->escaped();
677 }
678 }
679
680 return '';
681 }
682
683 /**
684 * @return string
685 */
686 function subPageSubtitle() {
687 $out = $this->getOutput();
688 $subpages = '';
689
690 if ( !Hooks::run( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
691 return $subpages;
692 }
693
694 if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
695 $ptext = $this->getTitle()->getPrefixedText();
696 if ( preg_match( '/\//', $ptext ) ) {
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 * Returns true if the IP should be shown in the header
738 * @return bool
739 */
740 function showIPinHeader() {
741 global $wgShowIPinHeader;
742 return $wgShowIPinHeader && session_id() != '';
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 array( $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, $wgCopyrightIcon;
812
813 $out = '';
814
815 if ( $wgCopyrightIcon ) {
816 $out = $wgCopyrightIcon;
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', array( &$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()->getLaggedSlaveMode() ) {
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 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
930 }
931 }
932 return $html;
933 }
934
935 /**
936 * Gets the link to the wiki's main page.
937 * @return string
938 */
939 function mainPageLink() {
940 $s = Linker::linkKnown(
941 Title::newMainPage(),
942 $this->msg( 'mainpage' )->escaped()
943 );
944
945 return $s;
946 }
947
948 /**
949 * Returns an HTML link for use in the footer
950 * @param string $desc The i18n message key for the link text
951 * @param string $page The i18n message key for the page to link to
952 * @return string HTML anchor
953 */
954 public function footerLink( $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 '';
959 } else {
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 if ( !$title ) {
966 return '';
967 }
968
969 return Linker::linkKnown(
970 $title,
971 $this->msg( $desc )->escaped()
972 );
973 }
974 }
975
976 /**
977 * Gets the link to the wiki's privacy policy page.
978 * @return string HTML
979 */
980 function privacyLink() {
981 return $this->footerLink( 'privacy', 'privacypage' );
982 }
983
984 /**
985 * Gets the link to the wiki's about page.
986 * @return string HTML
987 */
988 function aboutLink() {
989 return $this->footerLink( 'aboutsite', 'aboutpage' );
990 }
991
992 /**
993 * Gets the link to the wiki's general disclaimers page.
994 * @return string HTML
995 */
996 function disclaimerLink() {
997 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
998 }
999
1000 /**
1001 * Return URL options for the 'edit page' link.
1002 * This may include an 'oldid' specifier, if the current page view is such.
1003 *
1004 * @return array
1005 * @private
1006 */
1007 function editUrlOptions() {
1008 $options = array( 'action' => 'edit' );
1009
1010 if ( !$this->isRevisionCurrent() ) {
1011 $options['oldid'] = intval( $this->getRevisionId() );
1012 }
1013
1014 return $options;
1015 }
1016
1017 /**
1018 * @param User|int $id
1019 * @return bool
1020 */
1021 function showEmailUser( $id ) {
1022 if ( $id instanceof User ) {
1023 $targetUser = $id;
1024 } else {
1025 $targetUser = User::newFromId( $id );
1026 }
1027
1028 # The sending user must have a confirmed email address and the target
1029 # user must have a confirmed email address and allow emails from users.
1030 return $this->getUser()->canSendEmail() &&
1031 $targetUser->canReceiveEmail();
1032 }
1033
1034 /**
1035 * This function previously returned a fully resolved style path URL to images or styles stored in
1036 * the legacy skins/common/ directory.
1037 *
1038 * That directory has been removed in 1.24 and the function always returns an empty string.
1039 *
1040 * @deprecated since 1.24
1041 * @param string $name The name or path of a skin resource file
1042 * @return string Empty string
1043 */
1044 function getCommonStylePath( $name ) {
1045 wfDeprecated( __METHOD__, '1.24' );
1046 return '';
1047 }
1048
1049 /**
1050 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1051 * This method returns a url resolved using the configured skin style path
1052 * and includes the style version inside of the url.
1053 *
1054 * Requires $stylename to be set, otherwise throws MWException.
1055 *
1056 * @param string $name The name or path of a skin resource file
1057 * @return string The fully resolved style path url including styleversion
1058 * @throws MWException
1059 */
1060 function getSkinStylePath( $name ) {
1061 global $wgStylePath, $wgStyleVersion;
1062
1063 if ( $this->stylename === null ) {
1064 $class = get_class( $this );
1065 throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
1066 }
1067
1068 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1069 }
1070
1071 /* these are used extensively in SkinTemplate, but also some other places */
1072
1073 /**
1074 * @param string $urlaction
1075 * @return string
1076 */
1077 static function makeMainPageUrl( $urlaction = '' ) {
1078 $title = Title::newMainPage();
1079 self::checkTitle( $title, '' );
1080
1081 return $title->getLocalURL( $urlaction );
1082 }
1083
1084 /**
1085 * Make a URL for a Special Page using the given query and protocol.
1086 *
1087 * If $proto is set to null, make a local URL. Otherwise, make a full
1088 * URL with the protocol specified.
1089 *
1090 * @param string $name Name of the Special page
1091 * @param string $urlaction Query to append
1092 * @param string|null $proto Protocol to use or null for a local URL
1093 * @return string
1094 */
1095 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1096 $title = SpecialPage::getSafeTitleFor( $name );
1097 if ( is_null( $proto ) ) {
1098 return $title->getLocalURL( $urlaction );
1099 } else {
1100 return $title->getFullURL( $urlaction, false, $proto );
1101 }
1102 }
1103
1104 /**
1105 * @param string $name
1106 * @param string $subpage
1107 * @param string $urlaction
1108 * @return string
1109 */
1110 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1111 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1112 return $title->getLocalURL( $urlaction );
1113 }
1114
1115 /**
1116 * @param string $name
1117 * @param string $urlaction
1118 * @return string
1119 */
1120 static function makeI18nUrl( $name, $urlaction = '' ) {
1121 $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1122 self::checkTitle( $title, $name );
1123 return $title->getLocalURL( $urlaction );
1124 }
1125
1126 /**
1127 * @param string $name
1128 * @param string $urlaction
1129 * @return string
1130 */
1131 static function makeUrl( $name, $urlaction = '' ) {
1132 $title = Title::newFromText( $name );
1133 self::checkTitle( $title, $name );
1134
1135 return $title->getLocalURL( $urlaction );
1136 }
1137
1138 /**
1139 * If url string starts with http, consider as external URL, else
1140 * internal
1141 * @param string $name
1142 * @return string URL
1143 */
1144 static function makeInternalOrExternalUrl( $name ) {
1145 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1146 return $name;
1147 } else {
1148 return self::makeUrl( $name );
1149 }
1150 }
1151
1152 /**
1153 * this can be passed the NS number as defined in Language.php
1154 * @param string $name
1155 * @param string $urlaction
1156 * @param int $namespace
1157 * @return string
1158 */
1159 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1160 $title = Title::makeTitleSafe( $namespace, $name );
1161 self::checkTitle( $title, $name );
1162
1163 return $title->getLocalURL( $urlaction );
1164 }
1165
1166 /**
1167 * these return an array with the 'href' and boolean 'exists'
1168 * @param string $name
1169 * @param string $urlaction
1170 * @return array
1171 */
1172 static function makeUrlDetails( $name, $urlaction = '' ) {
1173 $title = Title::newFromText( $name );
1174 self::checkTitle( $title, $name );
1175
1176 return array(
1177 'href' => $title->getLocalURL( $urlaction ),
1178 'exists' => $title->isKnown(),
1179 );
1180 }
1181
1182 /**
1183 * Make URL details where the article exists (or at least it's convenient to think so)
1184 * @param string $name Article name
1185 * @param string $urlaction
1186 * @return array
1187 */
1188 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1189 $title = Title::newFromText( $name );
1190 self::checkTitle( $title, $name );
1191
1192 return array(
1193 'href' => $title->getLocalURL( $urlaction ),
1194 'exists' => true
1195 );
1196 }
1197
1198 /**
1199 * make sure we have some title to operate on
1200 *
1201 * @param Title $title
1202 * @param string $name
1203 */
1204 static function checkTitle( &$title, $name ) {
1205 if ( !is_object( $title ) ) {
1206 $title = Title::newFromText( $name );
1207 if ( !is_object( $title ) ) {
1208 $title = Title::newFromText( '--error: link target missing--' );
1209 }
1210 }
1211 }
1212
1213 /**
1214 * Build an array that represents the sidebar(s), the navigation bar among them.
1215 *
1216 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1217 *
1218 * The format of the returned array is array( heading => content, ... ), where:
1219 * - heading is the heading of a navigation portlet. It is either:
1220 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1221 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1222 * - plain text, which should be HTML-escaped by the skin
1223 * - content is the contents of the portlet. It is either:
1224 * - HTML text (<ul><li>...</li>...</ul>)
1225 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1226 * - (for a magic string as a key, any value)
1227 *
1228 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1229 * and can technically insert anything in here; skin creators are expected to handle
1230 * values described above.
1231 *
1232 * @return array
1233 */
1234 function buildSidebar() {
1235 global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1236
1237 $cache = ObjectCache::getMainWANInstance();
1238 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1239
1240 if ( $wgEnableSidebarCache ) {
1241 $cachedsidebar = $cache->get( $key );
1242 if ( $cachedsidebar ) {
1243 Hooks::run( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
1244
1245 return $cachedsidebar;
1246 }
1247 }
1248
1249 $bar = array();
1250 $this->addToSidebar( $bar, 'sidebar' );
1251
1252 Hooks::run( 'SkinBuildSidebar', array( $this, &$bar ) );
1253 if ( $wgEnableSidebarCache ) {
1254 $cache->set( $key, $bar, $wgSidebarCacheExpiry );
1255 }
1256
1257 Hooks::run( 'SidebarBeforeOutput', array( $this, &$bar ) );
1258
1259 return $bar;
1260 }
1261
1262 /**
1263 * Add content from a sidebar system message
1264 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1265 *
1266 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1267 *
1268 * @param array $bar
1269 * @param string $message
1270 */
1271 function addToSidebar( &$bar, $message ) {
1272 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1273 }
1274
1275 /**
1276 * Add content from plain text
1277 * @since 1.17
1278 * @param array $bar
1279 * @param string $text
1280 * @return array
1281 */
1282 function addToSidebarPlain( &$bar, $text ) {
1283 $lines = explode( "\n", $text );
1284
1285 $heading = '';
1286
1287 foreach ( $lines as $line ) {
1288 if ( strpos( $line, '*' ) !== 0 ) {
1289 continue;
1290 }
1291 $line = rtrim( $line, "\r" ); // for Windows compat
1292
1293 if ( strpos( $line, '**' ) !== 0 ) {
1294 $heading = trim( $line, '* ' );
1295 if ( !array_key_exists( $heading, $bar ) ) {
1296 $bar[$heading] = array();
1297 }
1298 } else {
1299 $line = trim( $line, '* ' );
1300
1301 if ( strpos( $line, '|' ) !== false ) { // sanity check
1302 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1303 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1304 if ( count( $line ) !== 2 ) {
1305 // Second sanity check, could be hit by people doing
1306 // funky stuff with parserfuncs... (bug 33321)
1307 continue;
1308 }
1309
1310 $extraAttribs = array();
1311
1312 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1313 if ( $msgLink->exists() ) {
1314 $link = $msgLink->text();
1315 if ( $link == '-' ) {
1316 continue;
1317 }
1318 } else {
1319 $link = $line[0];
1320 }
1321 $msgText = $this->msg( $line[1] );
1322 if ( $msgText->exists() ) {
1323 $text = $msgText->text();
1324 } else {
1325 $text = $line[1];
1326 }
1327
1328 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1329 $href = $link;
1330
1331 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1332 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1333 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1334 $extraAttribs['rel'] = 'nofollow';
1335 }
1336
1337 global $wgExternalLinkTarget;
1338 if ( $wgExternalLinkTarget ) {
1339 $extraAttribs['target'] = $wgExternalLinkTarget;
1340 }
1341 } else {
1342 $title = Title::newFromText( $link );
1343
1344 if ( $title ) {
1345 $title = $title->fixSpecialName();
1346 $href = $title->getLinkURL();
1347 } else {
1348 $href = 'INVALID-TITLE';
1349 }
1350 }
1351
1352 $bar[$heading][] = array_merge( array(
1353 'text' => $text,
1354 'href' => $href,
1355 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1356 'active' => false
1357 ), $extraAttribs );
1358 } else {
1359 continue;
1360 }
1361 }
1362 }
1363
1364 return $bar;
1365 }
1366
1367 /**
1368 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1369 * should be loaded by OutputPage. That module no longer exists and the return value of this
1370 * method is ignored.
1371 *
1372 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1373 * can be used instead (SkinTemplate-based skins do it automatically).
1374 *
1375 * @deprecated since 1.22
1376 * @return bool
1377 */
1378 public function commonPrintStylesheet() {
1379 wfDeprecated( __METHOD__, '1.22' );
1380 return false;
1381 }
1382
1383 /**
1384 * Gets new talk page messages for the current user and returns an
1385 * appropriate alert message (or an empty string if there are no messages)
1386 * @return string
1387 */
1388 function getNewtalks() {
1389
1390 $newMessagesAlert = '';
1391 $user = $this->getUser();
1392 $newtalks = $user->getNewMessageLinks();
1393 $out = $this->getOutput();
1394
1395 // Allow extensions to disable or modify the new messages alert
1396 if ( !Hooks::run( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1397 return '';
1398 }
1399 if ( $newMessagesAlert ) {
1400 return $newMessagesAlert;
1401 }
1402
1403 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1404 $uTalkTitle = $user->getTalkPage();
1405 $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
1406 $nofAuthors = 0;
1407 if ( $lastSeenRev !== null ) {
1408 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1409 $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
1410 if ( $latestRev !== null ) {
1411 // Singular if only 1 unseen revision, plural if several unseen revisions.
1412 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1413 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1414 $lastSeenRev, $latestRev, 10, 'include_new' );
1415 }
1416 } else {
1417 // Singular if no revision -> diff link will show latest change only in any case
1418 $plural = false;
1419 }
1420 $plural = $plural ? 999 : 1;
1421 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1422 // the number of revisions or authors is not necessarily the same as the number of
1423 // "messages".
1424 $newMessagesLink = Linker::linkKnown(
1425 $uTalkTitle,
1426 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1427 array(),
1428 array( 'redirect' => 'no' )
1429 );
1430
1431 $newMessagesDiffLink = Linker::linkKnown(
1432 $uTalkTitle,
1433 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1434 array(),
1435 $lastSeenRev !== null
1436 ? array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1437 : array( 'diff' => 'cur' )
1438 );
1439
1440 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1441 $newMessagesAlert = $this->msg(
1442 'youhavenewmessagesfromusers',
1443 $newMessagesLink,
1444 $newMessagesDiffLink
1445 )->numParams( $nofAuthors, $plural );
1446 } else {
1447 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1448 $newMessagesAlert = $this->msg(
1449 $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1450 $newMessagesLink,
1451 $newMessagesDiffLink
1452 )->numParams( $plural );
1453 }
1454 $newMessagesAlert = $newMessagesAlert->text();
1455 # Disable Squid cache
1456 $out->setSquidMaxage( 0 );
1457 } elseif ( count( $newtalks ) ) {
1458 $sep = $this->msg( 'newtalkseparator' )->escaped();
1459 $msgs = array();
1460
1461 foreach ( $newtalks as $newtalk ) {
1462 $msgs[] = Xml::element(
1463 'a',
1464 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1465 );
1466 }
1467 $parts = implode( $sep, $msgs );
1468 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1469 $out->setSquidMaxage( 0 );
1470 }
1471
1472 return $newMessagesAlert;
1473 }
1474
1475 /**
1476 * Get a cached notice
1477 *
1478 * @param string $name Message name, or 'default' for $wgSiteNotice
1479 * @return string|bool HTML fragment, or false to indicate that the caller
1480 * should fall back to the next notice in its sequence
1481 */
1482 private function getCachedNotice( $name ) {
1483 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1484
1485 $needParse = false;
1486
1487 if ( $name === 'default' ) {
1488 // special case
1489 global $wgSiteNotice;
1490 $notice = $wgSiteNotice;
1491 if ( empty( $notice ) ) {
1492 return false;
1493 }
1494 } else {
1495 $msg = $this->msg( $name )->inContentLanguage();
1496 if ( $msg->isBlank() ) {
1497 return '';
1498 } elseif ( $msg->isDisabled() ) {
1499 return false;
1500 }
1501 $notice = $msg->plain();
1502 }
1503
1504 // Use the extra hash appender to let eg SSL variants separately cache.
1505 $key = wfMemcKey( $name . $wgRenderHashAppend );
1506 $cachedNotice = $parserMemc->get( $key );
1507 if ( is_array( $cachedNotice ) ) {
1508 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1509 $notice = $cachedNotice['html'];
1510 } else {
1511 $needParse = true;
1512 }
1513 } else {
1514 $needParse = true;
1515 }
1516
1517 if ( $needParse ) {
1518 $parsed = $this->getOutput()->parse( $notice );
1519 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1520 $notice = $parsed;
1521 }
1522
1523 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1524 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1525 return $notice;
1526 }
1527
1528 /**
1529 * Get a notice based on page's namespace
1530 *
1531 * @return string HTML fragment
1532 */
1533 function getNamespaceNotice() {
1534
1535 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1536 $namespaceNotice = $this->getCachedNotice( $key );
1537 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1538 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1539 } else {
1540 $namespaceNotice = '';
1541 }
1542
1543 return $namespaceNotice;
1544 }
1545
1546 /**
1547 * Get the site notice
1548 *
1549 * @return string HTML fragment
1550 */
1551 function getSiteNotice() {
1552 $siteNotice = '';
1553
1554 if ( Hooks::run( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1555 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1556 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1557 } else {
1558 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1559 if ( $anonNotice === false ) {
1560 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1561 } else {
1562 $siteNotice = $anonNotice;
1563 }
1564 }
1565 if ( $siteNotice === false ) {
1566 $siteNotice = $this->getCachedNotice( 'default' );
1567 }
1568 }
1569
1570 Hooks::run( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1571 return $siteNotice;
1572 }
1573
1574 /**
1575 * Create a section edit link. This supersedes editSectionLink() and
1576 * editSectionLinkForOther().
1577 *
1578 * @param Title $nt The title being linked to (may not be the same as
1579 * the current page, if the section is included from a template)
1580 * @param string $section The designation of the section being pointed to,
1581 * to be included in the link, like "&section=$section"
1582 * @param string $tooltip The tooltip to use for the link: will be escaped
1583 * and wrapped in the 'editsectionhint' message
1584 * @param string $lang Language code
1585 * @return string HTML to use for edit link
1586 */
1587 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1588 // HTML generated here should probably have userlangattributes
1589 // added to it for LTR text on RTL pages
1590
1591 $lang = wfGetLangObj( $lang );
1592
1593 $attribs = array();
1594 if ( !is_null( $tooltip ) ) {
1595 # Bug 25462: undo double-escaping.
1596 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1597 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1598 ->inLanguage( $lang )->text();
1599 }
1600
1601 $links = array(
1602 'editsection' => array(
1603 'text' => wfMessage( 'editsection' )->inLanguage( $lang )->escaped(),
1604 'targetTitle' => $nt,
1605 'attribs' => $attribs,
1606 'query' => array( 'action' => 'edit', 'section' => $section ),
1607 'options' => array( 'noclasses', 'known' )
1608 )
1609 );
1610
1611 Hooks::run( 'SkinEditSectionLinks', array( $this, $nt, $section, $tooltip, &$links, $lang ) );
1612
1613 $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
1614
1615 $linksHtml = array();
1616 foreach ( $links as $k => $linkDetails ) {
1617 $linksHtml[] = Linker::link(
1618 $linkDetails['targetTitle'],
1619 $linkDetails['text'],
1620 $linkDetails['attribs'],
1621 $linkDetails['query'],
1622 $linkDetails['options']
1623 );
1624 }
1625
1626 $result .= implode(
1627 '<span class="mw-editsection-divider">'
1628 . wfMessage( 'pipe-separator' )->inLanguage( $lang )->text()
1629 . '</span>',
1630 $linksHtml
1631 );
1632
1633 $result .= '<span class="mw-editsection-bracket">]</span></span>';
1634 // Deprecated, use SkinEditSectionLinks hook instead
1635 Hooks::run(
1636 'DoEditSectionLink',
1637 array( $this, $nt, $section, $tooltip, &$result, $lang ),
1638 '1.25'
1639 );
1640 return $result;
1641 }
1642
1643 /**
1644 * Use PHP's magic __call handler to intercept legacy calls to the linker
1645 * for backwards compatibility.
1646 *
1647 * @param string $fname Name of called method
1648 * @param array $args Arguments to the method
1649 * @throws MWException
1650 * @return mixed
1651 */
1652 function __call( $fname, $args ) {
1653 $realFunction = array( 'Linker', $fname );
1654 if ( is_callable( $realFunction ) ) {
1655 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1656 return call_user_func_array( $realFunction, $args );
1657 } else {
1658 $className = get_class( $this );
1659 throw new MWException( "Call to undefined method $className::$fname" );
1660 }
1661 }
1662
1663 }