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