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