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