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