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