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