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