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