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