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