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