Fix fatal in r82258
[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 * Make a <script> tag containing global variables
475 * @param $skinName string Name of the skin
476 * The odd calling convention is for backwards compatibility
477 * @todo FIXME: Make this not depend on $wgTitle!
478 *
479 * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
480 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
481 */
482 static function makeGlobalVariablesScript( $skinName ) {
483 global $wgTitle, $wgUser, $wgRequest, $wgOut, $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
484
485 $ns = $wgTitle->getNamespace();
486 $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
487 $vars = array(
488 'wgCanonicalNamespace' => $nsname,
489 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
490 SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
491 'wgNamespaceNumber' => $wgTitle->getNamespace(),
492 'wgPageName' => $wgTitle->getPrefixedDBKey(),
493 'wgTitle' => $wgTitle->getText(),
494 'wgAction' => $wgRequest->getText( 'action', 'view' ),
495 'wgArticleId' => $wgTitle->getArticleId(),
496 'wgIsArticle' => $wgOut->isArticle(),
497 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
498 'wgUserGroups' => $wgUser->getEffectiveGroups(),
499 'wgCurRevisionId' => $wgTitle->getLatestRevID(),
500 'wgCategories' => $wgOut->getCategories(),
501 'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY',
502 );
503 if ( $wgContLang->hasVariants() ) {
504 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
505 }
506 foreach ( $wgTitle->getRestrictionTypes() as $type ) {
507 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
508 }
509 if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
510 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
511 }
512
513 // Allow extensions to add their custom variables to the global JS variables
514 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
515
516 return self::makeVariablesScript( $vars );
517 }
518
519 /**
520 * To make it harder for someone to slip a user a fake
521 * user-JavaScript or user-CSS preview, a random token
522 * is associated with the login session. If it's not
523 * passed back with the preview request, we won't render
524 * the code.
525 *
526 * @param $action String: 'edit', 'submit' etc.
527 * @return bool
528 */
529 public function userCanPreview( $action ) {
530 global $wgRequest, $wgUser;
531
532 if ( $action != 'submit' ) {
533 return false;
534 }
535 if ( !$wgRequest->wasPosted() ) {
536 return false;
537 }
538 if ( !$this->mTitle->userCanEditCssSubpage() ) {
539 return false;
540 }
541 if ( !$this->mTitle->userCanEditJsSubpage() ) {
542 return false;
543 }
544
545 return $wgUser->matchEditToken(
546 $wgRequest->getVal( 'wpEditToken' ) );
547 }
548
549 /**
550 * Generated JavaScript action=raw&gen=js
551 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
552 * nated together. For some bizarre reason, it does *not* return any
553 * custom user JS from subpages. Huh?
554 *
555 * There's absolutely no reason to have separate Monobook/Common JSes.
556 * Any JS that cares can just check the skin variable generated at the
557 * top. For now Monobook.js will be maintained, but it should be consi-
558 * dered deprecated.
559 *
560 * @param $skinName String: If set, overrides the skin name
561 * @return string
562 */
563 public function generateUserJs( $skinName = null ) {
564
565 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
566
567 return '';
568 }
569
570 /**
571 * Generate user stylesheet for action=raw&gen=css
572 */
573 public function generateUserStylesheet() {
574
575 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
576
577 return '';
578 }
579
580 /**
581 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
582 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
583 */
584 protected function reallyGenerateUserStylesheet() {
585
586 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
587
588 return '';
589 }
590
591 /**
592 * @private
593 */
594 function setupUserCss( OutputPage $out ) {
595 global $wgRequest;
596 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
597
598 wfProfileIn( __METHOD__ );
599
600 $this->setupSkinUserCss( $out );
601 // Add any extension CSS
602 foreach ( $out->getExtStyle() as $url ) {
603 $out->addStyle( $url );
604 }
605
606 // Per-site custom styles
607 if ( $wgUseSiteCss ) {
608 $out->addModuleStyles( 'site' );
609 }
610
611 // Per-user custom styles
612 if ( $wgAllowUserCss ) {
613 if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
614 // @FIXME: properly escape the cdata!
615 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
616 } else {
617 $out->addModuleStyles( 'user' );
618 }
619 }
620
621 // Per-user preference styles
622 if ( $wgAllowUserCssPrefs ) {
623 $out->addModuleStyles( 'user.options' );
624 }
625
626 wfProfileOut( __METHOD__ );
627 }
628
629 /**
630 * Get the query to generate a dynamic stylesheet
631 *
632 * @return array
633 */
634 public static function getDynamicStylesheetQuery() {
635 global $wgSquidMaxage;
636
637 return array(
638 'action' => 'raw',
639 'maxage' => $wgSquidMaxage,
640 'usemsgcache' => 'yes',
641 'ctype' => 'text/css',
642 'smaxage' => $wgSquidMaxage,
643 );
644 }
645
646 /**
647 * Add skin specific stylesheets
648 * @param $out OutputPage
649 * @delete
650 */
651 abstract function setupSkinUserCss( OutputPage $out );
652
653 function getPageClasses( $title ) {
654 $numeric = 'ns-' . $title->getNamespace();
655
656 if ( $title->getNamespace() == NS_SPECIAL ) {
657 $type = 'ns-special';
658 // bug 23315: provide a class based on the canonical special page name without subpages
659 list( $canonicalName ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
660 if ( $canonicalName ) {
661 $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
662 } else {
663 $type .= ' mw-invalidspecialpage';
664 }
665 } elseif ( $title->isTalkPage() ) {
666 $type = 'ns-talk';
667 } else {
668 $type = 'ns-subject';
669 }
670
671 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
672
673 return "$numeric $type $name";
674 }
675
676 /**
677 * This will be called by OutputPage::headElement when it is creating the
678 * <body> tag, skins can override it if they have a need to add in any
679 * body attributes or classes of their own.
680 */
681 function addToBodyAttributes( $out, &$bodyAttrs ) {
682 // does nothing by default
683 }
684
685 /**
686 * URL to the logo
687 */
688 function getLogo() {
689 global $wgLogo;
690 return $wgLogo;
691 }
692
693 function getCategoryLinks() {
694 global $wgOut, $wgUseCategoryBrowser;
695 global $wgContLang, $wgUser;
696
697 if ( count( $wgOut->mCategoryLinks ) == 0 ) {
698 return '';
699 }
700
701 # Separator
702 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
703
704 // Use Unicode bidi embedding override characters,
705 // to make sure links don't smash each other up in ugly ways.
706 $dir = $wgContLang->getDir();
707 $embed = "<span dir='$dir'>";
708 $pop = '</span>';
709
710 $allCats = $wgOut->getCategoryLinks();
711 $s = '';
712 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
713
714 if ( !empty( $allCats['normal'] ) ) {
715 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
716
717 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
718 $s .= '<div id="mw-normal-catlinks">' .
719 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
720 . $colon . $t . '</div>';
721 }
722
723 # Hidden categories
724 if ( isset( $allCats['hidden'] ) ) {
725 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
726 $class = 'mw-hidden-cats-user-shown';
727 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
728 $class = 'mw-hidden-cats-ns-shown';
729 } else {
730 $class = 'mw-hidden-cats-hidden';
731 }
732
733 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
734 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
735 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
736 '</div>';
737 }
738
739 # optional 'dmoz-like' category browser. Will be shown under the list
740 # of categories an article belong to
741 if ( $wgUseCategoryBrowser ) {
742 $s .= '<br /><hr />';
743
744 # get a big array of the parents tree
745 $parenttree = $this->mTitle->getParentCategoryTree();
746 # Skin object passed by reference cause it can not be
747 # accessed under the method subfunction drawCategoryBrowser
748 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
749 # Clean out bogus first entry and sort them
750 unset( $tempout[0] );
751 asort( $tempout );
752 # Output one per line
753 $s .= implode( "<br />\n", $tempout );
754 }
755
756 return $s;
757 }
758
759 /**
760 * Render the array as a serie of links.
761 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
762 * @param &skin Object: skin passed by reference
763 * @return String separated by &gt;, terminate with "\n"
764 */
765 function drawCategoryBrowser( $tree, &$skin ) {
766 $return = '';
767
768 foreach ( $tree as $element => $parent ) {
769 if ( empty( $parent ) ) {
770 # element start a new list
771 $return .= "\n";
772 } else {
773 # grab the others elements
774 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
775 }
776
777 # add our current element to the list
778 $eltitle = Title::newFromText( $element );
779 $return .= $skin->link( $eltitle, $eltitle->getText() );
780 }
781
782 return $return;
783 }
784
785 function getCategories() {
786 $catlinks = $this->getCategoryLinks();
787
788 $classes = 'catlinks';
789
790 global $wgOut, $wgUser;
791
792 // Check what we're showing
793 $allCats = $wgOut->getCategoryLinks();
794 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
795 $this->mTitle->getNamespace() == NS_CATEGORY;
796
797 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
798 $classes .= ' catlinks-allhidden';
799 }
800
801 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
802 }
803
804 /**
805 * This runs a hook to allow extensions placing their stuff after content
806 * and article metadata (e.g. categories).
807 * Note: This function has nothing to do with afterContent().
808 *
809 * This hook is placed here in order to allow using the same hook for all
810 * skins, both the SkinTemplate based ones and the older ones, which directly
811 * use this class to get their data.
812 *
813 * The output of this function gets processed in SkinTemplate::outputPage() for
814 * the SkinTemplate based skins, all other skins should directly echo it.
815 *
816 * Returns an empty string by default, if not changed by any hook function.
817 */
818 protected function afterContentHook() {
819 $data = '';
820
821 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
822 // adding just some spaces shouldn't toggle the output
823 // of the whole <div/>, so we use trim() here
824 if ( trim( $data ) != '' ) {
825 // Doing this here instead of in the skins to
826 // ensure that the div has the same ID in all
827 // skins
828 $data = "<div id='mw-data-after-content'>\n" .
829 "\t$data\n" .
830 "</div>\n";
831 }
832 } else {
833 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
834 }
835
836 return $data;
837 }
838
839 /**
840 * Generate debug data HTML for displaying at the bottom of the main content
841 * area.
842 * @return String HTML containing debug data, if enabled (otherwise empty).
843 */
844 protected function generateDebugHTML() {
845 global $wgShowDebug, $wgOut;
846
847 if ( $wgShowDebug ) {
848 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
849 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
850 $listInternals . "</ul>\n";
851 }
852
853 return '';
854 }
855
856 private function formatDebugHTML( $debugText ) {
857 $lines = explode( "\n", $debugText );
858 $curIdent = 0;
859 $ret = '<li>';
860
861 foreach ( $lines as $line ) {
862 $display = ltrim( $line );
863 $ident = strlen( $line ) - strlen( $display );
864 $diff = $ident - $curIdent;
865
866 if ( $display == '' ) {
867 $display = "\xc2\xa0";
868 }
869
870 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
871 $ident = $curIdent;
872 $diff = 0;
873 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
874 } else {
875 $display = htmlspecialchars( $display );
876 }
877
878 if ( $diff < 0 ) {
879 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
880 } elseif ( $diff == 0 ) {
881 $ret .= "</li><li>\n";
882 } else {
883 $ret .= str_repeat( "<ul><li>\n", $diff );
884 }
885 $ret .= $display . "\n";
886
887 $curIdent = $ident;
888 }
889
890 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
891
892 return $ret;
893 }
894
895 /**
896 * This gets called shortly before the </body> tag.
897 * @param $out OutputPage object
898 * @return String HTML-wrapped JS code to be put before </body>
899 */
900 function bottomScripts( $out ) {
901 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
902 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
903
904 return $bottomScriptText;
905 }
906
907 /** @return string Retrievied from HTML text */
908 function printSource() {
909 $url = htmlspecialchars( $this->mTitle->getFullURL() );
910 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
911 }
912
913 function getUndeleteLink() {
914 global $wgUser, $wgLang, $wgRequest;
915
916 $action = $wgRequest->getVal( 'action', 'view' );
917
918 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
919 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
920 $n = $this->mTitle->isDeleted();
921
922 if ( $n ) {
923 if ( $wgUser->isAllowed( 'undelete' ) ) {
924 $msg = 'thisisdeleted';
925 } else {
926 $msg = 'viewdeleted';
927 }
928
929 return wfMsg(
930 $msg,
931 $this->link(
932 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
933 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
934 array(),
935 array(),
936 array( 'known', 'noclasses' )
937 )
938 );
939 }
940 }
941
942 return '';
943 }
944
945 function subPageSubtitle() {
946 $subpages = '';
947
948 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
949 return $subpages;
950 }
951
952 global $wgOut;
953
954 if ( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
955 $ptext = $this->mTitle->getPrefixedText();
956 if ( preg_match( '/\//', $ptext ) ) {
957 $links = explode( '/', $ptext );
958 array_pop( $links );
959 $c = 0;
960 $growinglink = '';
961 $display = '';
962
963 foreach ( $links as $link ) {
964 $growinglink .= $link;
965 $display .= $link;
966 $linkObj = Title::newFromText( $growinglink );
967
968 if ( is_object( $linkObj ) && $linkObj->exists() ) {
969 $getlink = $this->link(
970 $linkObj,
971 htmlspecialchars( $display ),
972 array(),
973 array(),
974 array( 'known', 'noclasses' )
975 );
976
977 $c++;
978
979 if ( $c > 1 ) {
980 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
981 } else {
982 $subpages .= '&lt; ';
983 }
984
985 $subpages .= $getlink;
986 $display = '';
987 } else {
988 $display .= '/';
989 }
990 $growinglink .= '/';
991 }
992 }
993 }
994
995 return $subpages;
996 }
997
998 /**
999 * Returns true if the IP should be shown in the header
1000 */
1001 function showIPinHeader() {
1002 global $wgShowIPinHeader;
1003 return $wgShowIPinHeader && session_id() != '';
1004 }
1005
1006 function getSearchLink() {
1007 $searchPage = SpecialPage::getTitleFor( 'Search' );
1008 return $searchPage->getLocalURL();
1009 }
1010
1011 function escapeSearchLink() {
1012 return htmlspecialchars( $this->getSearchLink() );
1013 }
1014
1015 function getCopyright( $type = 'detect' ) {
1016 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1017
1018 if ( $type == 'detect' ) {
1019 $diff = $wgRequest->getVal( 'diff' );
1020
1021 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1022 $type = 'history';
1023 } else {
1024 $type = 'normal';
1025 }
1026 }
1027
1028 if ( $type == 'history' ) {
1029 $msg = 'history_copyright';
1030 } else {
1031 $msg = 'copyright';
1032 }
1033
1034 $out = '';
1035
1036 if ( $wgRightsPage ) {
1037 $title = Title::newFromText( $wgRightsPage );
1038 $link = $this->linkKnown( $title, $wgRightsText );
1039 } elseif ( $wgRightsUrl ) {
1040 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1041 } elseif ( $wgRightsText ) {
1042 $link = $wgRightsText;
1043 } else {
1044 # Give up now
1045 return $out;
1046 }
1047
1048 // Allow for site and per-namespace customization of copyright notice.
1049 $forContent = true;
1050
1051 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle, $type, &$msg, &$link, &$forContent ) );
1052
1053 if ( $forContent ) {
1054 $out .= wfMsgForContent( $msg, $link );
1055 } else {
1056 $out .= wfMsg( $msg, $link );
1057 }
1058
1059 return $out;
1060 }
1061
1062 function getCopyrightIcon() {
1063 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1064
1065 $out = '';
1066
1067 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1068 $out = $wgCopyrightIcon;
1069 } elseif ( $wgRightsIcon ) {
1070 $icon = htmlspecialchars( $wgRightsIcon );
1071
1072 if ( $wgRightsUrl ) {
1073 $url = htmlspecialchars( $wgRightsUrl );
1074 $out .= '<a href="' . $url . '">';
1075 }
1076
1077 $text = htmlspecialchars( $wgRightsText );
1078 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1079
1080 if ( $wgRightsUrl ) {
1081 $out .= '</a>';
1082 }
1083 }
1084
1085 return $out;
1086 }
1087
1088 /**
1089 * Gets the powered by MediaWiki icon.
1090 * @return string
1091 */
1092 function getPoweredBy() {
1093 global $wgStylePath;
1094
1095 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1096 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1097 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1098 return $text;
1099 }
1100
1101 /**
1102 * Get the timestamp of the latest revision, formatted in user language
1103 *
1104 * @param $article Article object. Used if we're working with the current revision
1105 * @return String
1106 */
1107 protected function lastModified( $article ) {
1108 global $wgLang;
1109
1110 if ( !$this->isRevisionCurrent() ) {
1111 $timestamp = Revision::getTimestampFromId( $this->mTitle, $this->mRevisionId );
1112 } else {
1113 $timestamp = $article->getTimestamp();
1114 }
1115
1116 if ( $timestamp ) {
1117 $d = $wgLang->date( $timestamp, true );
1118 $t = $wgLang->time( $timestamp, true );
1119 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1120 } else {
1121 $s = '';
1122 }
1123
1124 if ( wfGetLB()->getLaggedSlaveMode() ) {
1125 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1126 }
1127
1128 return $s;
1129 }
1130
1131 function logoText( $align = '' ) {
1132 if ( $align != '' ) {
1133 $a = " align='{$align}'";
1134 } else {
1135 $a = '';
1136 }
1137
1138 $mp = wfMsg( 'mainpage' );
1139 $mptitle = Title::newMainPage();
1140 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1141
1142 $logourl = $this->getLogo();
1143 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1144
1145 return $s;
1146 }
1147
1148 /**
1149 * Renders a $wgFooterIcons icon acording to the method's arguments
1150 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1151 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1152 */
1153 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1154 if ( is_string( $icon ) ) {
1155 $html = $icon;
1156 } else { // Assuming array
1157 $url = isset($icon["url"]) ? $icon["url"] : null;
1158 unset( $icon["url"] );
1159 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1160 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1161 } else {
1162 $html = htmlspecialchars( $icon["alt"] );
1163 }
1164 if ( $url ) {
1165 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
1166 }
1167 }
1168 return $html;
1169 }
1170
1171 /**
1172 * Gets the link to the wiki's main page.
1173 * @return string
1174 */
1175 function mainPageLink() {
1176 $s = $this->link(
1177 Title::newMainPage(),
1178 wfMsg( 'mainpage' ),
1179 array(),
1180 array(),
1181 array( 'known', 'noclasses' )
1182 );
1183
1184 return $s;
1185 }
1186
1187 public function footerLink( $desc, $page ) {
1188 // if the link description has been set to "-" in the default language,
1189 if ( wfMsgForContent( $desc ) == '-' ) {
1190 // then it is disabled, for all languages.
1191 return '';
1192 } else {
1193 // Otherwise, we display the link for the user, described in their
1194 // language (which may or may not be the same as the default language),
1195 // but we make the link target be the one site-wide page.
1196 $title = Title::newFromText( wfMsgForContent( $page ) );
1197
1198 return $this->linkKnown(
1199 $title,
1200 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1201 );
1202 }
1203 }
1204
1205 /**
1206 * Gets the link to the wiki's privacy policy page.
1207 */
1208 function privacyLink() {
1209 return $this->footerLink( 'privacy', 'privacypage' );
1210 }
1211
1212 /**
1213 * Gets the link to the wiki's about page.
1214 */
1215 function aboutLink() {
1216 return $this->footerLink( 'aboutsite', 'aboutpage' );
1217 }
1218
1219 /**
1220 * Gets the link to the wiki's general disclaimers page.
1221 */
1222 function disclaimerLink() {
1223 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1224 }
1225
1226 /**
1227 * Return URL options for the 'edit page' link.
1228 * This may include an 'oldid' specifier, if the current page view is such.
1229 *
1230 * @return array
1231 * @private
1232 */
1233 function editUrlOptions() {
1234 $options = array( 'action' => 'edit' );
1235
1236 if ( !$this->isRevisionCurrent() ) {
1237 $options['oldid'] = intval( $this->mRevisionId );
1238 }
1239
1240 return $options;
1241 }
1242
1243 function showEmailUser( $id ) {
1244 global $wgUser;
1245 $targetUser = User::newFromId( $id );
1246 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1247 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1248 }
1249
1250 /**
1251 * Return a fully resolved style path url to images or styles stored in the common folder.
1252 * This method returns a url resolved using the configured skin style path
1253 * and includes the style version inside of the url.
1254 * @param $name String: The name or path of a skin resource file
1255 * @return String The fully resolved style path url including styleversion
1256 */
1257 function getCommonStylePath( $name ) {
1258 global $wgStylePath, $wgStyleVersion;
1259 return "$wgStylePath/common/$name?$wgStyleVersion";
1260 }
1261
1262 /**
1263 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1264 * This method returns a url resolved using the configured skin style path
1265 * and includes the style version inside of the url.
1266 * @param $name String: The name or path of a skin resource file
1267 * @return String The fully resolved style path url including styleversion
1268 */
1269 function getSkinStylePath( $name ) {
1270 global $wgStylePath, $wgStyleVersion;
1271 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1272 }
1273
1274 /* these are used extensively in SkinTemplate, but also some other places */
1275 static function makeMainPageUrl( $urlaction = '' ) {
1276 $title = Title::newMainPage();
1277 self::checkTitle( $title, '' );
1278
1279 return $title->getLocalURL( $urlaction );
1280 }
1281
1282 static function makeSpecialUrl( $name, $urlaction = '' ) {
1283 $title = SpecialPage::getTitleFor( $name );
1284 return $title->getLocalURL( $urlaction );
1285 }
1286
1287 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1288 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1289 return $title->getLocalURL( $urlaction );
1290 }
1291
1292 static function makeI18nUrl( $name, $urlaction = '' ) {
1293 $title = Title::newFromText( wfMsgForContent( $name ) );
1294 self::checkTitle( $title, $name );
1295 return $title->getLocalURL( $urlaction );
1296 }
1297
1298 static function makeUrl( $name, $urlaction = '' ) {
1299 $title = Title::newFromText( $name );
1300 self::checkTitle( $title, $name );
1301
1302 return $title->getLocalURL( $urlaction );
1303 }
1304
1305 /**
1306 * If url string starts with http, consider as external URL, else
1307 * internal
1308 */
1309 static function makeInternalOrExternalUrl( $name ) {
1310 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1311 return $name;
1312 } else {
1313 return self::makeUrl( $name );
1314 }
1315 }
1316
1317 # this can be passed the NS number as defined in Language.php
1318 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1319 $title = Title::makeTitleSafe( $namespace, $name );
1320 self::checkTitle( $title, $name );
1321
1322 return $title->getLocalURL( $urlaction );
1323 }
1324
1325 /* these return an array with the 'href' and boolean 'exists' */
1326 static function makeUrlDetails( $name, $urlaction = '' ) {
1327 $title = Title::newFromText( $name );
1328 self::checkTitle( $title, $name );
1329
1330 return array(
1331 'href' => $title->getLocalURL( $urlaction ),
1332 'exists' => $title->getArticleID() != 0,
1333 );
1334 }
1335
1336 /**
1337 * Make URL details where the article exists (or at least it's convenient to think so)
1338 */
1339 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1340 $title = Title::newFromText( $name );
1341 self::checkTitle( $title, $name );
1342
1343 return array(
1344 'href' => $title->getLocalURL( $urlaction ),
1345 'exists' => true
1346 );
1347 }
1348
1349 # make sure we have some title to operate on
1350 static function checkTitle( &$title, $name ) {
1351 if ( !is_object( $title ) ) {
1352 $title = Title::newFromText( $name );
1353 if ( !is_object( $title ) ) {
1354 $title = Title::newFromText( '--error: link target missing--' );
1355 }
1356 }
1357 }
1358
1359 /**
1360 * Build an array that represents the sidebar(s), the navigation bar among them
1361 *
1362 * @return array
1363 */
1364 function buildSidebar() {
1365 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1366 global $wgLang;
1367 wfProfileIn( __METHOD__ );
1368
1369 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1370
1371 if ( $wgEnableSidebarCache ) {
1372 $cachedsidebar = $parserMemc->get( $key );
1373 if ( $cachedsidebar ) {
1374 wfProfileOut( __METHOD__ );
1375 return $cachedsidebar;
1376 }
1377 }
1378
1379 $bar = array();
1380 $this->addToSidebar( $bar, 'sidebar' );
1381
1382 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1383 if ( $wgEnableSidebarCache ) {
1384 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1385 }
1386
1387 wfProfileOut( __METHOD__ );
1388 return $bar;
1389 }
1390 /**
1391 * Add content from a sidebar system message
1392 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1393 *
1394 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1395 *
1396 * @param &$bar array
1397 * @param $message String
1398 */
1399 function addToSidebar( &$bar, $message ) {
1400 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
1401 }
1402
1403 /**
1404 * Add content from plain text
1405 * @since 1.17
1406 * @param &$bar array
1407 * @param $text string
1408 */
1409 function addToSidebarPlain( &$bar, $text ) {
1410 $lines = explode( "\n", $text );
1411 $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.
1412
1413 $heading = '';
1414
1415 foreach ( $lines as $line ) {
1416 if ( strpos( $line, '*' ) !== 0 ) {
1417 continue;
1418 }
1419
1420 if ( strpos( $line, '**' ) !== 0 ) {
1421 $heading = trim( $line, '* ' );
1422 if ( !array_key_exists( $heading, $bar ) ) {
1423 $bar[$heading] = array();
1424 }
1425 } else {
1426 $line = trim( $line, '* ' );
1427
1428 if ( strpos( $line, '|' ) !== false ) { // sanity check
1429 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1430 $link = wfMsgForContent( $line[0] );
1431
1432 if ( $link == '-' ) {
1433 continue;
1434 }
1435
1436 $text = wfMsgExt( $line[1], 'parsemag' );
1437
1438 if ( wfEmptyMsg( $line[1], $text ) ) {
1439 $text = $line[1];
1440 }
1441
1442 if ( wfEmptyMsg( $line[0], $link ) ) {
1443 $link = $line[0];
1444 }
1445
1446 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1447 $href = $link;
1448 } else {
1449 $title = Title::newFromText( $link );
1450
1451 if ( $title ) {
1452 $title = $title->fixSpecialName();
1453 $href = $title->getLocalURL();
1454 } else {
1455 $href = 'INVALID-TITLE';
1456 }
1457 }
1458
1459 $bar[$heading][] = array(
1460 'text' => $text,
1461 'href' => $href,
1462 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1463 'active' => false
1464 );
1465 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1466 global $wgParser, $wgTitle;
1467
1468 $line = substr( $line, 2, strlen( $line ) - 4 );
1469
1470 $options = new ParserOptions();
1471 $options->setEditSection( false );
1472 $options->setInterfaceMessage( true );
1473 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $options )->getText();
1474 } else {
1475 continue;
1476 }
1477 }
1478 }
1479
1480 if ( count( $wikiBar ) > 0 ) {
1481 $bar = array_merge( $bar, $wikiBar );
1482 }
1483
1484 return $bar;
1485 }
1486
1487 /**
1488 * Should we include common/wikiprintable.css? Skins that have their own
1489 * print stylesheet should override this and return false. (This is an
1490 * ugly hack to get Monobook to play nicely with
1491 * OutputPage::headElement().)
1492 *
1493 * @return bool
1494 */
1495 public function commonPrintStylesheet() {
1496 return true;
1497 }
1498
1499 /**
1500 * Gets new talk page messages for the current user.
1501 * @return MediaWiki message or if no new talk page messages, nothing
1502 */
1503 function getNewtalks() {
1504 global $wgUser, $wgOut;
1505
1506 $newtalks = $wgUser->getNewMessageLinks();
1507 $ntl = '';
1508
1509 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1510 $userTitle = $this->mUser->getUserPage();
1511 $userTalkTitle = $userTitle->getTalkPage();
1512
1513 if ( !$userTalkTitle->equals( $this->mTitle ) ) {
1514 $newMessagesLink = $this->link(
1515 $userTalkTitle,
1516 wfMsgHtml( 'newmessageslink' ),
1517 array(),
1518 array( 'redirect' => 'no' ),
1519 array( 'known', 'noclasses' )
1520 );
1521
1522 $newMessagesDiffLink = $this->link(
1523 $userTalkTitle,
1524 wfMsgHtml( 'newmessagesdifflink' ),
1525 array(),
1526 array( 'diff' => 'cur' ),
1527 array( 'known', 'noclasses' )
1528 );
1529
1530 $ntl = wfMsg(
1531 'youhavenewmessages',
1532 $newMessagesLink,
1533 $newMessagesDiffLink
1534 );
1535 # Disable Squid cache
1536 $wgOut->setSquidMaxage( 0 );
1537 }
1538 } elseif ( count( $newtalks ) ) {
1539 // _>" " for BC <= 1.16
1540 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1541 $msgs = array();
1542
1543 foreach ( $newtalks as $newtalk ) {
1544 $msgs[] = Xml::element(
1545 'a',
1546 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1547 );
1548 }
1549 $parts = implode( $sep, $msgs );
1550 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1551 $wgOut->setSquidMaxage( 0 );
1552 }
1553
1554 return $ntl;
1555 }
1556
1557 /**
1558 * Get a cached notice
1559 *
1560 * @param $name String: message name, or 'default' for $wgSiteNotice
1561 * @return String: HTML fragment
1562 */
1563 private function getCachedNotice( $name ) {
1564 global $wgOut, $wgRenderHashAppend, $parserMemc;
1565
1566 wfProfileIn( __METHOD__ );
1567
1568 $needParse = false;
1569
1570 if( $name === 'default' ) {
1571 // special case
1572 global $wgSiteNotice;
1573 $notice = $wgSiteNotice;
1574 if( empty( $notice ) ) {
1575 wfProfileOut( __METHOD__ );
1576 return false;
1577 }
1578 } else {
1579 $msg = wfMessage( $name )->inContentLanguage();
1580 if( $msg->isDisabled() ) {
1581 wfProfileOut( __METHOD__ );
1582 return false;
1583 }
1584 $notice = $msg->plain();
1585 }
1586
1587 // Use the extra hash appender to let eg SSL variants separately cache.
1588 $key = wfMemcKey( $name . $wgRenderHashAppend );
1589 $cachedNotice = $parserMemc->get( $key );
1590 if( is_array( $cachedNotice ) ) {
1591 if( md5( $notice ) == $cachedNotice['hash'] ) {
1592 $notice = $cachedNotice['html'];
1593 } else {
1594 $needParse = true;
1595 }
1596 } else {
1597 $needParse = true;
1598 }
1599
1600 if ( $needParse ) {
1601 if( is_object( $wgOut ) ) {
1602 $parsed = $wgOut->parse( $notice );
1603 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1604 $notice = $parsed;
1605 } else {
1606 wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
1607 $notice = '';
1608 }
1609 }
1610
1611 $notice = '<div id="localNotice">' .$notice . '</div>';
1612 wfProfileOut( __METHOD__ );
1613 return $notice;
1614 }
1615
1616 /**
1617 * Get a notice based on page's namespace
1618 *
1619 * @return String: HTML fragment
1620 */
1621 function getNamespaceNotice() {
1622 wfProfileIn( __METHOD__ );
1623
1624 $key = 'namespacenotice-' . $this->mTitle->getNsText();
1625 $namespaceNotice = wfGetCachedNotice( $key );
1626 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1627 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1628 } else {
1629 $namespaceNotice = '';
1630 }
1631
1632 wfProfileOut( $fname );
1633 return $namespaceNotice;
1634 }
1635
1636 /**
1637 * Get the site notice
1638 *
1639 * @return String: HTML fragment
1640 */
1641 function getSiteNotice() {
1642 global $wgUser;
1643
1644 wfProfileIn( __METHOD__ );
1645 $siteNotice = '';
1646
1647 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1648 if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
1649 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1650 } else {
1651 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1652 if ( !$anonNotice ) {
1653 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1654 } else {
1655 $siteNotice = $anonNotice;
1656 }
1657 }
1658 if ( !$siteNotice ) {
1659 $siteNotice = $this->getCachedNotice( 'default' );
1660 }
1661 }
1662
1663 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1664 wfProfileOut( __METHOD__ );
1665 return $siteNotice;
1666 }
1667 }