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