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