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