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