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