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