Major refactoring of site and user CSS, creating ResourceLoaderUserModule and Resourc...
[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 class Skin extends Linker {
19 /**#@+
20 * @private
21 */
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
23 // How many search boxes have we made? Avoid duplicate id's.
24 protected $searchboxes = '';
25 /**#@-*/
26 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
27 protected $skinname = 'standard';
28 // @todo Fixme: should be protected :-\
29 var $mTitle = 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 ) {
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' . ucfirst( $key );
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 qbSetting() {
183 global $wgOut, $wgUser;
184
185 if ( $wgOut->isQuickbarSuppressed() ) {
186 return 0;
187 }
188
189 $q = $wgUser->getOption( 'quickbar', 0 );
190
191 return $q;
192 }
193
194 function initPage( OutputPage $out ) {
195 global $wgFavicon, $wgAppleTouchIcon;
196
197 wfProfileIn( __METHOD__ );
198
199 # Generally the order of the favicon and apple-touch-icon links
200 # should not matter, but Konqueror (3.5.9 at least) incorrectly
201 # uses whichever one appears later in the HTML source. Make sure
202 # apple-touch-icon is specified first to avoid this.
203 if ( false !== $wgAppleTouchIcon ) {
204 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
205 }
206
207 if ( false !== $wgFavicon ) {
208 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
209 }
210
211 # OpenSearch description link
212 $out->addLink( array(
213 'rel' => 'search',
214 'type' => 'application/opensearchdescription+xml',
215 'href' => wfScript( 'opensearch_desc' ),
216 'title' => wfMsgForContent( 'opensearch-desc' ),
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->execute();
248 }
249
250 /**
251 * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML
252 * output.
253 * @param $out Object: instance of OutputPage
254 */
255 function addMetadataLinks( OutputPage $out ) {
256 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
257 global $wgRightsPage, $wgRightsUrl;
258
259 if ( $out->isArticleRelated() ) {
260 # note: buggy CC software only reads first "meta" link
261 if ( $wgEnableCreativeCommonsRdf ) {
262 $out->addMetadataLink( array(
263 'title' => 'Creative Commons',
264 'type' => 'application/rdf+xml',
265 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) )
266 );
267 }
268
269 if ( $wgEnableDublinCoreRdf ) {
270 $out->addMetadataLink( array(
271 'title' => 'Dublin Core',
272 'type' => 'application/rdf+xml',
273 'href' => $this->mTitle->getLocalURL( 'action=dublincore' ) )
274 );
275 }
276 }
277 $copyright = '';
278 if ( $wgRightsPage ) {
279 $copy = Title::newFromText( $wgRightsPage );
280
281 if ( $copy ) {
282 $copyright = $copy->getLocalURL();
283 }
284 }
285
286 if ( !$copyright && $wgRightsUrl ) {
287 $copyright = $wgRightsUrl;
288 }
289
290 if ( $copyright ) {
291 $out->addLink( array(
292 'rel' => 'copyright',
293 'href' => $copyright )
294 );
295 }
296 }
297
298 /**
299 * Set some local variables
300 */
301 protected function setMembers() {
302 global $wgUser;
303 $this->mUser = $wgUser;
304 $this->userpage = $wgUser->getUserPage()->getPrefixedText();
305 $this->usercss = false;
306 }
307
308 /**
309 * Set the title
310 * @param $t Title object to use
311 */
312 public function setTitle( $t ) {
313 $this->mTitle = $t;
314 }
315
316 /** Get the title */
317 public function getTitle() {
318 return $this->mTitle;
319 }
320
321 /**
322 * Outputs the HTML generated by other functions.
323 * @param $out Object: instance of OutputPage
324 */
325 function outputPage( OutputPage $out ) {
326 global $wgDebugComments;
327 wfProfileIn( __METHOD__ );
328
329 $this->setMembers();
330 $this->initPage( $out );
331
332 // See self::afterContentHook() for documentation
333 $afterContent = $this->afterContentHook();
334
335 $out->out( $out->headElement( $this ) );
336
337 if ( $wgDebugComments ) {
338 $out->out( "<!-- Wiki debugging output:\n" .
339 $out->mDebugtext . "-->\n" );
340 }
341
342 $out->out( $this->beforeContent() );
343
344 $out->out( $out->mBodytext . "\n" );
345
346 $out->out( $this->afterContent() );
347
348 $out->out( $afterContent );
349
350 $out->out( $this->bottomScripts( $out ) );
351
352 $out->out( wfReportTime() );
353
354 $out->out( "\n</body></html>" );
355 wfProfileOut( __METHOD__ );
356 }
357
358 static function makeVariablesScript( $data ) {
359 if ( $data ) {
360 return Html::inlineScript( 'mediaWiki.config.set(' . FormatJson::encode( $data ) . ');' );
361 } else {
362 return '';
363 }
364 }
365
366 /**
367 * Make a <script> tag containing global variables
368 * @param $skinName string Name of the skin
369 * The odd calling convention is for backwards compatibility
370 * @todo FIXME: Make this not depend on $wgTitle!
371 *
372 * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
373 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
374 */
375 static function makeGlobalVariablesScript( $skinName ) {
376 global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgRestrictionTypes;
377
378 $ns = $wgTitle->getNamespace();
379 $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
380 $vars = array(
381 'wgCanonicalNamespace' => $nsname,
382 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
383 SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
384 'wgNamespaceNumber' => $wgTitle->getNamespace(),
385 'wgPageName' => $wgTitle->getPrefixedDBKey(),
386 'wgTitle' => $wgTitle->getText(),
387 'wgAction' => $wgRequest->getText( 'action', 'view' ),
388 'wgArticleId' => $wgTitle->getArticleId(),
389 'wgIsArticle' => $wgOut->isArticle(),
390 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
391 'wgUserGroups' => $wgUser->getEffectiveGroups(),
392 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
393 'wgCategories' => $wgOut->getCategories(),
394 );
395 foreach ( $wgRestrictionTypes as $type ) {
396 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
397 }
398
399 // Allow extensions to add their custom variables to the global JS variables
400 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
401
402 return self::makeVariablesScript( $vars );
403 }
404
405 /**
406 * To make it harder for someone to slip a user a fake
407 * user-JavaScript or user-CSS preview, a random token
408 * is associated with the login session. If it's not
409 * passed back with the preview request, we won't render
410 * the code.
411 *
412 * @param $action String: 'edit', 'submit' etc.
413 * @return bool
414 */
415 public function userCanPreview( $action ) {
416 global $wgRequest, $wgUser;
417
418 if ( $action != 'submit' ) {
419 return false;
420 }
421 if ( !$wgRequest->wasPosted() ) {
422 return false;
423 }
424 if ( !$this->mTitle->userCanEditCssSubpage() ) {
425 return false;
426 }
427 if ( !$this->mTitle->userCanEditJsSubpage() ) {
428 return false;
429 }
430
431 return $wgUser->matchEditToken(
432 $wgRequest->getVal( 'wpEditToken' ) );
433 }
434
435 /**
436 * Generated JavaScript action=raw&gen=js
437 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
438 * nated together. For some bizarre reason, it does *not* return any
439 * custom user JS from subpages. Huh?
440 *
441 * There's absolutely no reason to have separate Monobook/Common JSes.
442 * Any JS that cares can just check the skin variable generated at the
443 * top. For now Monobook.js will be maintained, but it should be consi-
444 * dered deprecated.
445 *
446 * @param $skinName String: If set, overrides the skin name
447 * @return string
448 */
449 public function generateUserJs( $skinName = null ) {
450
451 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
452
453 return '';
454 }
455
456 /**
457 * Generate user stylesheet for action=raw&gen=css
458 */
459 public function generateUserStylesheet() {
460
461 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
462
463 return '';
464 }
465
466 /**
467 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
468 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
469 */
470 protected function reallyGenerateUserStylesheet() {
471
472 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
473
474 return '';
475 }
476
477 /**
478 * @private
479 */
480 function setupUserCss( OutputPage $out ) {
481 global $wgRequest, $wgUser;
482 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs, $wgSquidMaxage;
483
484 wfProfileIn( __METHOD__ );
485
486 $this->setupSkinUserCss( $out );
487
488 $siteargs = array(
489 'action' => 'raw',
490 'maxage' => $wgSquidMaxage,
491 );
492
493 // Add any extension CSS
494 foreach ( $out->getExtStyle() as $url ) {
495 $out->addStyle( $url );
496 }
497
498 // Per-site custom styles
499 if ( $wgUseSiteCss ) {
500 $out->addModuleStyles( 'site' );
501 }
502
503 // Per-user custom styles
504 if ( $wgAllowUserCss ) {
505 if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
506 // @FIXME: properly escape the cdata!
507 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
508 } else {
509 $out->addModuleStyles( 'user' );
510 }
511 }
512
513 // Per-user preference styles
514 if ( $wgAllowUserCssPrefs ) {
515 $out->addModuleStyles( 'user.preferences' );
516 }
517
518 wfProfileOut( __METHOD__ );
519 }
520
521 /**
522 * Get the query to generate a dynamic stylesheet
523 *
524 * @return array
525 */
526 public static function getDynamicStylesheetQuery() {
527 global $wgSquidMaxage;
528
529 return array(
530 'action' => 'raw',
531 'maxage' => $wgSquidMaxage,
532 'usemsgcache' => 'yes',
533 'ctype' => 'text/css',
534 'smaxage' => $wgSquidMaxage,
535 );
536 }
537
538 /**
539 * Add skin specific stylesheets
540 * @param $out OutputPage
541 */
542 function setupSkinUserCss( OutputPage $out ) {
543 $out->addModuleStyles( 'mediawiki.legacy.shared' );
544 $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
545 // TODO: When converting old skins to use ResourceLoader (or removing them) the following should be reconsidered
546 $out->addStyle( $this->getStylesheet() );
547 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
548 }
549
550 function getPageClasses( $title ) {
551 $numeric = 'ns-' . $title->getNamespace();
552
553 if ( $title->getNamespace() == NS_SPECIAL ) {
554 $type = 'ns-special';
555 } elseif ( $title->isTalkPage() ) {
556 $type = 'ns-talk';
557 } else {
558 $type = 'ns-subject';
559 }
560
561 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
562
563 return "$numeric $type $name";
564 }
565
566 /**
567 * URL to the logo
568 */
569 function getLogo() {
570 global $wgLogo;
571 return $wgLogo;
572 }
573
574 /**
575 * This will be called immediately after the <body> tag. Split into
576 * two functions to make it easier to subclass.
577 */
578 function beforeContent() {
579 return $this->doBeforeContent();
580 }
581
582 function doBeforeContent() {
583 global $wgContLang;
584 wfProfileIn( __METHOD__ );
585
586 $s = '';
587 $qb = $this->qbSetting();
588
589 $langlinks = $this->otherLanguages();
590 if ( $langlinks ) {
591 $rows = 2;
592 $borderhack = '';
593 } else {
594 $rows = 1;
595 $langlinks = false;
596 $borderhack = 'class="top"';
597 }
598
599 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
600 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
601
602 $shove = ( $qb != 0 );
603 $left = ( $qb == 1 || $qb == 3 );
604
605 if ( $wgContLang->isRTL() ) {
606 $left = !$left;
607 }
608
609 if ( !$shove ) {
610 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
611 $this->logoText() . '</td>';
612 } elseif ( $left ) {
613 $s .= $this->getQuickbarCompensator( $rows );
614 }
615
616 $l = $wgContLang->alignStart();
617 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
618
619 $s .= $this->topLinks();
620 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
621
622 $r = $wgContLang->alignEnd();
623 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
624 $s .= $this->nameAndLogin();
625 $s .= "\n<br />" . $this->searchForm() . '</td>';
626
627 if ( $langlinks ) {
628 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
629 }
630
631 if ( $shove && !$left ) { # Right
632 $s .= $this->getQuickbarCompensator( $rows );
633 }
634
635 $s .= "</tr>\n</table>\n</div>\n";
636 $s .= "\n<div id='article'>\n";
637
638 $notice = wfGetSiteNotice();
639
640 if ( $notice ) {
641 $s .= "\n<div id='siteNotice'>$notice</div>\n";
642 }
643 $s .= $this->pageTitle();
644 $s .= $this->pageSubtitle();
645 $s .= $this->getCategories();
646
647 wfProfileOut( __METHOD__ );
648 return $s;
649 }
650
651 function getCategoryLinks() {
652 global $wgOut, $wgUseCategoryBrowser;
653 global $wgContLang, $wgUser;
654
655 if ( count( $wgOut->mCategoryLinks ) == 0 ) {
656 return '';
657 }
658
659 # Separator
660 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
661
662 // Use Unicode bidi embedding override characters,
663 // to make sure links don't smash each other up in ugly ways.
664 $dir = $wgContLang->getDir();
665 $embed = "<span dir='$dir'>";
666 $pop = '</span>';
667
668 $allCats = $wgOut->getCategoryLinks();
669 $s = '';
670 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
671
672 if ( !empty( $allCats['normal'] ) ) {
673 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
674
675 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
676 $s .= '<div id="mw-normal-catlinks">' .
677 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
678 . $colon . $t . '</div>';
679 }
680
681 # Hidden categories
682 if ( isset( $allCats['hidden'] ) ) {
683 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
684 $class = 'mw-hidden-cats-user-shown';
685 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
686 $class = 'mw-hidden-cats-ns-shown';
687 } else {
688 $class = 'mw-hidden-cats-hidden';
689 }
690
691 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
692 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
693 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
694 '</div>';
695 }
696
697 # optional 'dmoz-like' category browser. Will be shown under the list
698 # of categories an article belong to
699 if ( $wgUseCategoryBrowser ) {
700 $s .= '<br /><hr />';
701
702 # get a big array of the parents tree
703 $parenttree = $this->mTitle->getParentCategoryTree();
704 # Skin object passed by reference cause it can not be
705 # accessed under the method subfunction drawCategoryBrowser
706 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
707 # Clean out bogus first entry and sort them
708 unset( $tempout[0] );
709 asort( $tempout );
710 # Output one per line
711 $s .= implode( "<br />\n", $tempout );
712 }
713
714 return $s;
715 }
716
717 /**
718 * Render the array as a serie of links.
719 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
720 * @param &skin Object: skin passed by reference
721 * @return String separated by &gt;, terminate with "\n"
722 */
723 function drawCategoryBrowser( $tree, &$skin ) {
724 $return = '';
725
726 foreach ( $tree as $element => $parent ) {
727 if ( empty( $parent ) ) {
728 # element start a new list
729 $return .= "\n";
730 } else {
731 # grab the others elements
732 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
733 }
734
735 # add our current element to the list
736 $eltitle = Title::newFromText( $element );
737 $return .= $skin->link( $eltitle, $eltitle->getText() );
738 }
739
740 return $return;
741 }
742
743 function getCategories() {
744 $catlinks = $this->getCategoryLinks();
745
746 $classes = 'catlinks';
747
748 global $wgOut, $wgUser;
749
750 // Check what we're showing
751 $allCats = $wgOut->getCategoryLinks();
752 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
753 $this->mTitle->getNamespace() == NS_CATEGORY;
754
755 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
756 $classes .= ' catlinks-allhidden';
757 }
758
759 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
760 }
761
762 function getQuickbarCompensator( $rows = 1 ) {
763 return "<td width='152' rowspan='{$rows}'>&#160;</td>";
764 }
765
766 /**
767 * This runs a hook to allow extensions placing their stuff after content
768 * and article metadata (e.g. categories).
769 * Note: This function has nothing to do with afterContent().
770 *
771 * This hook is placed here in order to allow using the same hook for all
772 * skins, both the SkinTemplate based ones and the older ones, which directly
773 * use this class to get their data.
774 *
775 * The output of this function gets processed in SkinTemplate::outputPage() for
776 * the SkinTemplate based skins, all other skins should directly echo it.
777 *
778 * Returns an empty string by default, if not changed by any hook function.
779 */
780 protected function afterContentHook() {
781 $data = '';
782
783 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
784 // adding just some spaces shouldn't toggle the output
785 // of the whole <div/>, so we use trim() here
786 if ( trim( $data ) != '' ) {
787 // Doing this here instead of in the skins to
788 // ensure that the div has the same ID in all
789 // skins
790 $data = "<div id='mw-data-after-content'>\n" .
791 "\t$data\n" .
792 "</div>\n";
793 }
794 } else {
795 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
796 }
797
798 return $data;
799 }
800
801 /**
802 * Generate debug data HTML for displaying at the bottom of the main content
803 * area.
804 * @return String HTML containing debug data, if enabled (otherwise empty).
805 */
806 protected function generateDebugHTML() {
807 global $wgShowDebug, $wgOut;
808
809 if ( $wgShowDebug ) {
810 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
811 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
812 $listInternals . "</ul>\n";
813 }
814
815 return '';
816 }
817
818 private function formatDebugHTML( $debugText ) {
819 $lines = explode( "\n", $debugText );
820 $curIdent = 0;
821 $ret = '<li>';
822
823 foreach ( $lines as $line ) {
824 $m = array();
825 $display = ltrim( $line );
826 $ident = strlen( $line ) - strlen( $display );
827 $diff = $ident - $curIdent;
828
829 if ( $display == '' ) {
830 $display = "\xc2\xa0";
831 }
832
833 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
834 $ident = $curIdent;
835 $diff = 0;
836 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
837 } else {
838 $display = htmlspecialchars( $display );
839 }
840
841 if ( $diff < 0 ) {
842 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
843 } elseif ( $diff == 0 ) {
844 $ret .= "</li><li>\n";
845 } else {
846 $ret .= str_repeat( "<ul><li>\n", $diff );
847 }
848 $ret .= $display . "\n";
849
850 $curIdent = $ident;
851 }
852
853 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
854
855 return $ret;
856 }
857
858 /**
859 * This gets called shortly before the </body> tag.
860 * @return String HTML to be put before </body>
861 */
862 function afterContent() {
863 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
864 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
865 }
866
867 /**
868 * This gets called shortly before the </body> tag.
869 * @param $out OutputPage object
870 * @return String HTML-wrapped JS code to be put before </body>
871 */
872 function bottomScripts( $out ) {
873 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
874 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
875
876 return $bottomScriptText;
877 }
878
879 /** @return string Retrievied from HTML text */
880 function printSource() {
881 $url = htmlspecialchars( $this->mTitle->getFullURL() );
882 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
883 }
884
885 function printFooter() {
886 return "<p>" . $this->printSource() .
887 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
888 }
889
890 /** overloaded by derived classes */
891 function doAfterContent() {
892 return '</div></div>';
893 }
894
895 function pageTitleLinks() {
896 global $wgOut, $wgUser, $wgRequest, $wgLang;
897
898 $oldid = $wgRequest->getVal( 'oldid' );
899 $diff = $wgRequest->getVal( 'diff' );
900 $action = $wgRequest->getText( 'action' );
901
902 $s[] = $this->printableLink();
903 $disclaimer = $this->disclaimerLink(); # may be empty
904
905 if ( $disclaimer ) {
906 $s[] = $disclaimer;
907 }
908
909 $privacy = $this->privacyLink(); # may be empty too
910
911 if ( $privacy ) {
912 $s[] = $privacy;
913 }
914
915 if ( $wgOut->isArticleRelated() ) {
916 if ( $this->mTitle->getNamespace() == NS_FILE ) {
917 $name = $this->mTitle->getDBkey();
918 $image = wfFindFile( $this->mTitle );
919
920 if ( $image ) {
921 $link = htmlspecialchars( $image->getURL() );
922 $style = $this->getInternalLinkAttributes( $link, $name );
923 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
924 }
925 }
926 }
927
928 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
929 $s[] .= $this->link(
930 $this->mTitle,
931 wfMsg( 'currentrev' ),
932 array(),
933 array(),
934 array( 'known', 'noclasses' )
935 );
936 }
937
938 if ( $wgUser->getNewtalk() ) {
939 # do not show "You have new messages" text when we are viewing our
940 # own talk page
941 if ( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
942 $tl = $this->link(
943 $wgUser->getTalkPage(),
944 wfMsgHtml( 'newmessageslink' ),
945 array(),
946 array( 'redirect' => 'no' ),
947 array( 'known', 'noclasses' )
948 );
949
950 $dl = $this->link(
951 $wgUser->getTalkPage(),
952 wfMsgHtml( 'newmessagesdifflink' ),
953 array(),
954 array( 'diff' => 'cur' ),
955 array( 'known', 'noclasses' )
956 );
957 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
958 # disable caching
959 $wgOut->setSquidMaxage( 0 );
960 $wgOut->enableClientCache( false );
961 }
962 }
963
964 $undelete = $this->getUndeleteLink();
965
966 if ( !empty( $undelete ) ) {
967 $s[] = $undelete;
968 }
969
970 return $wgLang->pipeList( $s );
971 }
972
973 function getUndeleteLink() {
974 global $wgUser, $wgLang, $wgRequest;
975
976 $action = $wgRequest->getVal( 'action', 'view' );
977
978 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
979 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
980 $n = $this->mTitle->isDeleted();
981
982 if ( $n ) {
983 if ( $wgUser->isAllowed( 'undelete' ) ) {
984 $msg = 'thisisdeleted';
985 } else {
986 $msg = 'viewdeleted';
987 }
988
989 return wfMsg(
990 $msg,
991 $this->link(
992 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
993 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
994 array(),
995 array(),
996 array( 'known', 'noclasses' )
997 )
998 );
999 }
1000 }
1001
1002 return '';
1003 }
1004
1005 function printableLink() {
1006 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1007
1008 $s = array();
1009
1010 if ( !$wgOut->isPrintable() ) {
1011 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1012 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1013 }
1014
1015 if ( $wgOut->isSyndicated() ) {
1016 foreach ( $wgFeedClasses as $format => $class ) {
1017 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1018 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1019 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1020 }
1021 }
1022 return $wgLang->pipeList( $s );
1023 }
1024
1025 /**
1026 * Gets the h1 element with the page title.
1027 * @return string
1028 */
1029 function pageTitle() {
1030 global $wgOut;
1031 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1032 return $s;
1033 }
1034
1035 function pageSubtitle() {
1036 global $wgOut;
1037
1038 $sub = $wgOut->getSubtitle();
1039
1040 if ( $sub == '' ) {
1041 global $wgExtraSubtitle;
1042 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1043 }
1044
1045 $subpages = $this->subPageSubtitle();
1046 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1047 $s = "<p class='subtitle'>{$sub}</p>\n";
1048
1049 return $s;
1050 }
1051
1052 function subPageSubtitle() {
1053 $subpages = '';
1054
1055 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1056 return $subpages;
1057 }
1058
1059 global $wgOut;
1060
1061 if ( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1062 $ptext = $this->mTitle->getPrefixedText();
1063 if ( preg_match( '/\//', $ptext ) ) {
1064 $links = explode( '/', $ptext );
1065 array_pop( $links );
1066 $c = 0;
1067 $growinglink = '';
1068 $display = '';
1069
1070 foreach ( $links as $link ) {
1071 $growinglink .= $link;
1072 $display .= $link;
1073 $linkObj = Title::newFromText( $growinglink );
1074
1075 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1076 $getlink = $this->link(
1077 $linkObj,
1078 htmlspecialchars( $display ),
1079 array(),
1080 array(),
1081 array( 'known', 'noclasses' )
1082 );
1083
1084 $c++;
1085
1086 if ( $c > 1 ) {
1087 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1088 } else {
1089 $subpages .= '&lt; ';
1090 }
1091
1092 $subpages .= $getlink;
1093 $display = '';
1094 } else {
1095 $display .= '/';
1096 }
1097 $growinglink .= '/';
1098 }
1099 }
1100 }
1101
1102 return $subpages;
1103 }
1104
1105 /**
1106 * Returns true if the IP should be shown in the header
1107 */
1108 function showIPinHeader() {
1109 global $wgShowIPinHeader;
1110 return $wgShowIPinHeader && session_id() != '';
1111 }
1112
1113 function nameAndLogin() {
1114 global $wgUser, $wgLang, $wgContLang;
1115
1116 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1117
1118 $ret = '';
1119
1120 if ( $wgUser->isAnon() ) {
1121 if ( $this->showIPinHeader() ) {
1122 $name = wfGetIP();
1123
1124 $talkLink = $this->link( $wgUser->getTalkPage(),
1125 $wgLang->getNsText( NS_TALK ) );
1126
1127 $ret .= "$name ($talkLink)";
1128 } else {
1129 $ret .= wfMsg( 'notloggedin' );
1130 }
1131
1132 $returnTo = $this->mTitle->getPrefixedDBkey();
1133 $query = array();
1134
1135 if ( $logoutPage != $returnTo ) {
1136 $query['returnto'] = $returnTo;
1137 }
1138
1139 $loginlink = $wgUser->isAllowed( 'createaccount' )
1140 ? 'nav-login-createaccount'
1141 : 'login';
1142 $ret .= "\n<br />" . $this->link(
1143 SpecialPage::getTitleFor( 'Userlogin' ),
1144 wfMsg( $loginlink ), array(), $query
1145 );
1146 } else {
1147 $returnTo = $this->mTitle->getPrefixedDBkey();
1148 $talkLink = $this->link( $wgUser->getTalkPage(),
1149 $wgLang->getNsText( NS_TALK ) );
1150
1151 $ret .= $this->link( $wgUser->getUserPage(),
1152 htmlspecialchars( $wgUser->getName() ) );
1153 $ret .= " ($talkLink)<br />";
1154 $ret .= $wgLang->pipeList( array(
1155 $this->link(
1156 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1157 array(), array( 'returnto' => $returnTo )
1158 ),
1159 $this->specialLink( 'preferences' ),
1160 ) );
1161 }
1162
1163 $ret = $wgLang->pipeList( array(
1164 $ret,
1165 $this->link(
1166 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1167 wfMsg( 'help' )
1168 ),
1169 ) );
1170
1171 return $ret;
1172 }
1173
1174 function getSearchLink() {
1175 $searchPage = SpecialPage::getTitleFor( 'Search' );
1176 return $searchPage->getLocalURL();
1177 }
1178
1179 function escapeSearchLink() {
1180 return htmlspecialchars( $this->getSearchLink() );
1181 }
1182
1183 function searchForm() {
1184 global $wgRequest, $wgUseTwoButtonsSearchForm;
1185
1186 $search = $wgRequest->getText( 'search' );
1187
1188 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
1189 . $this->escapeSearchLink() . "\">\n"
1190 . '<input type="text" id="searchInput' . $this->searchboxes . '" name="search" size="19" value="'
1191 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1192 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1193
1194 if ( $wgUseTwoButtonsSearchForm ) {
1195 $s .= '&#160;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1196 } else {
1197 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1198 }
1199
1200 $s .= '</form>';
1201
1202 // Ensure unique id's for search boxes made after the first
1203 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1204
1205 return $s;
1206 }
1207
1208 function topLinks() {
1209 global $wgOut;
1210
1211 $s = array(
1212 $this->mainPageLink(),
1213 $this->specialLink( 'recentchanges' )
1214 );
1215
1216 if ( $wgOut->isArticleRelated() ) {
1217 $s[] = $this->editThisPage();
1218 $s[] = $this->historyLink();
1219 }
1220
1221 # Many people don't like this dropdown box
1222 # $s[] = $this->specialPagesList();
1223
1224 if ( $this->variantLinks() ) {
1225 $s[] = $this->variantLinks();
1226 }
1227
1228 if ( $this->extensionTabLinks() ) {
1229 $s[] = $this->extensionTabLinks();
1230 }
1231
1232 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1233 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1234 }
1235
1236 /**
1237 * Compatibility for extensions adding functionality through tabs.
1238 * Eventually these old skins should be replaced with SkinTemplate-based
1239 * versions, sigh...
1240 * @return string
1241 */
1242 function extensionTabLinks() {
1243 $tabs = array();
1244 $out = '';
1245 $s = array();
1246 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1247 foreach ( $tabs as $tab ) {
1248 $s[] = Xml::element( 'a',
1249 array( 'href' => $tab['href'] ),
1250 $tab['text'] );
1251 }
1252
1253 if ( count( $s ) ) {
1254 global $wgLang;
1255
1256 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1257 $out .= $wgLang->pipeList( $s );
1258 }
1259
1260 return $out;
1261 }
1262
1263 /**
1264 * Language/charset variant links for classic-style skins
1265 * @return string
1266 */
1267 function variantLinks() {
1268 $s = '';
1269
1270 /* show links to different language variants */
1271 global $wgDisableLangConversion, $wgLang, $wgContLang;
1272
1273 $variants = $wgContLang->getVariants();
1274
1275 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1276 foreach ( $variants as $code ) {
1277 $varname = $wgContLang->getVariantname( $code );
1278
1279 if ( $varname == 'disable' ) {
1280 continue;
1281 }
1282 $s = $wgLang->pipeList( array(
1283 $s,
1284 '<a href="' . $this->mTitle->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1285 ) );
1286 }
1287 }
1288
1289 return $s;
1290 }
1291
1292 function bottomLinks() {
1293 global $wgOut, $wgUser, $wgUseTrackbacks;
1294 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1295
1296 $s = '';
1297 if ( $wgOut->isArticleRelated() ) {
1298 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1299
1300 if ( $wgUser->isLoggedIn() ) {
1301 $element[] = $this->watchThisPage();
1302 }
1303
1304 $element[] = $this->talkLink();
1305 $element[] = $this->historyLink();
1306 $element[] = $this->whatLinksHere();
1307 $element[] = $this->watchPageLinksLink();
1308
1309 if ( $wgUseTrackbacks ) {
1310 $element[] = $this->trackbackLink();
1311 }
1312
1313 if (
1314 $this->mTitle->getNamespace() == NS_USER ||
1315 $this->mTitle->getNamespace() == NS_USER_TALK
1316 ) {
1317 $id = User::idFromName( $this->mTitle->getText() );
1318 $ip = User::isIP( $this->mTitle->getText() );
1319
1320 # Both anons and non-anons have contributions list
1321 if ( $id || $ip ) {
1322 $element[] = $this->userContribsLink();
1323 }
1324
1325 if ( $this->showEmailUser( $id ) ) {
1326 $element[] = $this->emailUserLink();
1327 }
1328 }
1329
1330 $s = implode( $element, $sep );
1331
1332 if ( $this->mTitle->getArticleId() ) {
1333 $s .= "\n<br />";
1334
1335 // Delete/protect/move links for privileged users
1336 if ( $wgUser->isAllowed( 'delete' ) ) {
1337 $s .= $this->deleteThisPage();
1338 }
1339
1340 if ( $wgUser->isAllowed( 'protect' ) ) {
1341 $s .= $sep . $this->protectThisPage();
1342 }
1343
1344 if ( $wgUser->isAllowed( 'move' ) ) {
1345 $s .= $sep . $this->moveThisPage();
1346 }
1347 }
1348
1349 $s .= "<br />\n" . $this->otherLanguages();
1350 }
1351
1352 return $s;
1353 }
1354
1355 function pageStats() {
1356 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1357 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1358
1359 $oldid = $wgRequest->getVal( 'oldid' );
1360 $diff = $wgRequest->getVal( 'diff' );
1361
1362 if ( !$wgOut->isArticle() ) {
1363 return '';
1364 }
1365
1366 if ( !$wgArticle instanceof Article ) {
1367 return '';
1368 }
1369
1370 if ( isset( $oldid ) || isset( $diff ) ) {
1371 return '';
1372 }
1373
1374 if ( 0 == $wgArticle->getID() ) {
1375 return '';
1376 }
1377
1378 $s = '';
1379
1380 if ( !$wgDisableCounters ) {
1381 $count = $wgLang->formatNum( $wgArticle->getCount() );
1382
1383 if ( $count ) {
1384 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1385 }
1386 }
1387
1388 if ( $wgMaxCredits != 0 ) {
1389 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1390 } else {
1391 $s .= $this->lastModified();
1392 }
1393
1394 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1395 $dbr = wfGetDB( DB_SLAVE );
1396 $res = $dbr->select(
1397 'watchlist',
1398 array( 'COUNT(*) AS n' ),
1399 array(
1400 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1401 'wl_namespace' => $this->mTitle->getNamespace()
1402 ),
1403 __METHOD__
1404 );
1405 $x = $dbr->fetchObject( $res );
1406
1407 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1408 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1409 );
1410 }
1411
1412 return $s . ' ' . $this->getCopyright();
1413 }
1414
1415 function getCopyright( $type = 'detect' ) {
1416 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1417
1418 if ( $type == 'detect' ) {
1419 $diff = $wgRequest->getVal( 'diff' );
1420 $isCur = $wgArticle && $wgArticle->isCurrent();
1421
1422 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1423 $type = 'history';
1424 } else {
1425 $type = 'normal';
1426 }
1427 }
1428
1429 if ( $type == 'history' ) {
1430 $msg = 'history_copyright';
1431 } else {
1432 $msg = 'copyright';
1433 }
1434
1435 $out = '';
1436
1437 if ( $wgRightsPage ) {
1438 $title = Title::newFromText( $wgRightsPage );
1439 $link = $this->linkKnown( $title, $wgRightsText );
1440 } elseif ( $wgRightsUrl ) {
1441 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1442 } elseif ( $wgRightsText ) {
1443 $link = $wgRightsText;
1444 } else {
1445 # Give up now
1446 return $out;
1447 }
1448
1449 // Allow for site and per-namespace customization of copyright notice.
1450 $forContent = true;
1451
1452 if ( isset( $wgArticle ) ) {
1453 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1454 }
1455
1456 if ( $forContent ) {
1457 $out .= wfMsgForContent( $msg, $link );
1458 } else {
1459 $out .= wfMsg( $msg, $link );
1460 }
1461
1462 return $out;
1463 }
1464
1465 function getCopyrightIcon() {
1466 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1467
1468 $out = '';
1469
1470 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1471 $out = $wgCopyrightIcon;
1472 } elseif ( $wgRightsIcon ) {
1473 $icon = htmlspecialchars( $wgRightsIcon );
1474
1475 if ( $wgRightsUrl ) {
1476 $url = htmlspecialchars( $wgRightsUrl );
1477 $out .= '<a href="' . $url . '">';
1478 }
1479
1480 $text = htmlspecialchars( $wgRightsText );
1481 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1482
1483 if ( $wgRightsUrl ) {
1484 $out .= '</a>';
1485 }
1486 }
1487
1488 return $out;
1489 }
1490
1491 /**
1492 * Gets the powered by MediaWiki icon.
1493 * @return string
1494 */
1495 function getPoweredBy() {
1496 global $wgStylePath;
1497
1498 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1499 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1500
1501 return $img;
1502 }
1503
1504 function lastModified() {
1505 global $wgLang, $wgArticle;
1506
1507 if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
1508 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1509 } else {
1510 $timestamp = $wgArticle->getTimestamp();
1511 }
1512
1513 if ( $timestamp ) {
1514 $d = $wgLang->date( $timestamp, true );
1515 $t = $wgLang->time( $timestamp, true );
1516 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1517 } else {
1518 $s = '';
1519 }
1520
1521 if ( wfGetLB()->getLaggedSlaveMode() ) {
1522 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1523 }
1524
1525 return $s;
1526 }
1527
1528 function logoText( $align = '' ) {
1529 if ( $align != '' ) {
1530 $a = " align='{$align}'";
1531 } else {
1532 $a = '';
1533 }
1534
1535 $mp = wfMsg( 'mainpage' );
1536 $mptitle = Title::newMainPage();
1537 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1538
1539 $logourl = $this->getLogo();
1540 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1541
1542 return $s;
1543 }
1544
1545 /**
1546 * Show a drop-down box of special pages
1547 */
1548 function specialPagesList() {
1549 global $wgContLang, $wgServer, $wgRedirectScript;
1550
1551 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1552
1553 foreach ( $pages as $name => $page ) {
1554 $pages[$name] = $page->getDescription();
1555 }
1556
1557 $go = wfMsg( 'go' );
1558 $sp = wfMsg( 'specialpages' );
1559 $spp = $wgContLang->specialPage( 'Specialpages' );
1560
1561 $s = '<form id="specialpages" method="get" ' .
1562 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1563 $s .= "<select name=\"wpDropdown\">\n";
1564 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1565
1566
1567 foreach ( $pages as $name => $desc ) {
1568 $p = $wgContLang->specialPage( $name );
1569 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1570 }
1571
1572 $s .= "</select>\n";
1573 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1574 $s .= "</form>\n";
1575
1576 return $s;
1577 }
1578
1579 /**
1580 * Gets the link to the wiki's main page.
1581 * @return string
1582 */
1583 function mainPageLink() {
1584 $s = $this->link(
1585 Title::newMainPage(),
1586 wfMsg( 'mainpage' ),
1587 array(),
1588 array(),
1589 array( 'known', 'noclasses' )
1590 );
1591
1592 return $s;
1593 }
1594
1595 private function footerLink( $desc, $page ) {
1596 // if the link description has been set to "-" in the default language,
1597 if ( wfMsgForContent( $desc ) == '-' ) {
1598 // then it is disabled, for all languages.
1599 return '';
1600 } else {
1601 // Otherwise, we display the link for the user, described in their
1602 // language (which may or may not be the same as the default language),
1603 // but we make the link target be the one site-wide page.
1604 $title = Title::newFromText( wfMsgForContent( $page ) );
1605
1606 return $this->linkKnown(
1607 $title,
1608 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1609 );
1610 }
1611 }
1612
1613 /**
1614 * Gets the link to the wiki's privacy policy page.
1615 */
1616 function privacyLink() {
1617 return $this->footerLink( 'privacy', 'privacypage' );
1618 }
1619
1620 /**
1621 * Gets the link to the wiki's about page.
1622 */
1623 function aboutLink() {
1624 return $this->footerLink( 'aboutsite', 'aboutpage' );
1625 }
1626
1627 /**
1628 * Gets the link to the wiki's general disclaimers page.
1629 */
1630 function disclaimerLink() {
1631 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1632 }
1633
1634 function editThisPage() {
1635 global $wgOut;
1636
1637 if ( !$wgOut->isArticleRelated() ) {
1638 $s = wfMsg( 'protectedpage' );
1639 } else {
1640 if ( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1641 $t = wfMsg( 'editthispage' );
1642 } elseif ( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1643 $t = wfMsg( 'create-this-page' );
1644 } else {
1645 $t = wfMsg( 'viewsource' );
1646 }
1647
1648 $s = $this->link(
1649 $this->mTitle,
1650 $t,
1651 array(),
1652 $this->editUrlOptions(),
1653 array( 'known', 'noclasses' )
1654 );
1655 }
1656
1657 return $s;
1658 }
1659
1660 /**
1661 * Return URL options for the 'edit page' link.
1662 * This may include an 'oldid' specifier, if the current page view is such.
1663 *
1664 * @return array
1665 * @private
1666 */
1667 function editUrlOptions() {
1668 global $wgArticle;
1669
1670 $options = array( 'action' => 'edit' );
1671
1672 if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1673 $options['oldid'] = intval( $this->mRevisionId );
1674 }
1675
1676 return $options;
1677 }
1678
1679 function deleteThisPage() {
1680 global $wgUser, $wgRequest;
1681
1682 $diff = $wgRequest->getVal( 'diff' );
1683
1684 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1685 $t = wfMsg( 'deletethispage' );
1686
1687 $s = $this->link(
1688 $this->mTitle,
1689 $t,
1690 array(),
1691 array( 'action' => 'delete' ),
1692 array( 'known', 'noclasses' )
1693 );
1694 } else {
1695 $s = '';
1696 }
1697
1698 return $s;
1699 }
1700
1701 function protectThisPage() {
1702 global $wgUser, $wgRequest;
1703
1704 $diff = $wgRequest->getVal( 'diff' );
1705
1706 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1707 if ( $this->mTitle->isProtected() ) {
1708 $text = wfMsg( 'unprotectthispage' );
1709 $query = array( 'action' => 'unprotect' );
1710 } else {
1711 $text = wfMsg( 'protectthispage' );
1712 $query = array( 'action' => 'protect' );
1713 }
1714
1715 $s = $this->link(
1716 $this->mTitle,
1717 $text,
1718 array(),
1719 $query,
1720 array( 'known', 'noclasses' )
1721 );
1722 } else {
1723 $s = '';
1724 }
1725
1726 return $s;
1727 }
1728
1729 function watchThisPage() {
1730 global $wgOut;
1731 ++$this->mWatchLinkNum;
1732
1733 if ( $wgOut->isArticleRelated() ) {
1734 if ( $this->mTitle->userIsWatching() ) {
1735 $text = wfMsg( 'unwatchthispage' );
1736 $query = array( 'action' => 'unwatch' );
1737 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1738 } else {
1739 $text = wfMsg( 'watchthispage' );
1740 $query = array( 'action' => 'watch' );
1741 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1742 }
1743
1744 $s = $this->link(
1745 $this->mTitle,
1746 $text,
1747 array( 'id' => $id ),
1748 $query,
1749 array( 'known', 'noclasses' )
1750 );
1751 } else {
1752 $s = wfMsg( 'notanarticle' );
1753 }
1754
1755 return $s;
1756 }
1757
1758 function moveThisPage() {
1759 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1760 return $this->link(
1761 SpecialPage::getTitleFor( 'Movepage' ),
1762 wfMsg( 'movethispage' ),
1763 array(),
1764 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1765 array( 'known', 'noclasses' )
1766 );
1767 } else {
1768 // no message if page is protected - would be redundant
1769 return '';
1770 }
1771 }
1772
1773 function historyLink() {
1774 return $this->link(
1775 $this->mTitle,
1776 wfMsgHtml( 'history' ),
1777 array( 'rel' => 'archives' ),
1778 array( 'action' => 'history' )
1779 );
1780 }
1781
1782 function whatLinksHere() {
1783 return $this->link(
1784 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1785 wfMsgHtml( 'whatlinkshere' ),
1786 array(),
1787 array(),
1788 array( 'known', 'noclasses' )
1789 );
1790 }
1791
1792 function userContribsLink() {
1793 return $this->link(
1794 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1795 wfMsgHtml( 'contributions' ),
1796 array(),
1797 array(),
1798 array( 'known', 'noclasses' )
1799 );
1800 }
1801
1802 function showEmailUser( $id ) {
1803 global $wgUser;
1804 $targetUser = User::newFromId( $id );
1805 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1806 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1807 }
1808
1809 function emailUserLink() {
1810 return $this->link(
1811 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1812 wfMsg( 'emailuser' ),
1813 array(),
1814 array(),
1815 array( 'known', 'noclasses' )
1816 );
1817 }
1818
1819 function watchPageLinksLink() {
1820 global $wgOut;
1821
1822 if ( !$wgOut->isArticleRelated() ) {
1823 return '(' . wfMsg( 'notanarticle' ) . ')';
1824 } else {
1825 return $this->link(
1826 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1827 wfMsg( 'recentchangeslinked-toolbox' ),
1828 array(),
1829 array(),
1830 array( 'known', 'noclasses' )
1831 );
1832 }
1833 }
1834
1835 function trackbackLink() {
1836 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1837 . wfMsg( 'trackbacklink' ) . '</a>';
1838 }
1839
1840 function otherLanguages() {
1841 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1842
1843 if ( $wgHideInterlanguageLinks ) {
1844 return '';
1845 }
1846
1847 $a = $wgOut->getLanguageLinks();
1848
1849 if ( 0 == count( $a ) ) {
1850 return '';
1851 }
1852
1853 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1854 $first = true;
1855
1856 if ( $wgContLang->isRTL() ) {
1857 $s .= '<span dir="LTR">';
1858 }
1859
1860 foreach ( $a as $l ) {
1861 if ( !$first ) {
1862 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1863 }
1864
1865 $first = false;
1866
1867 $nt = Title::newFromText( $l );
1868 $url = $nt->escapeFullURL();
1869 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1870 $title = htmlspecialchars( $nt->getText() );
1871
1872 if ( $text == '' ) {
1873 $text = $l;
1874 }
1875
1876 $style = $this->getExternalLinkAttributes();
1877 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
1878 }
1879
1880 if ( $wgContLang->isRTL() ) {
1881 $s .= '</span>';
1882 }
1883
1884 return $s;
1885 }
1886
1887 function talkLink() {
1888 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1889 # No discussion links for special pages
1890 return '';
1891 }
1892
1893 $linkOptions = array();
1894
1895 if ( $this->mTitle->isTalkPage() ) {
1896 $link = $this->mTitle->getSubjectPage();
1897 switch( $link->getNamespace() ) {
1898 case NS_MAIN:
1899 $text = wfMsg( 'articlepage' );
1900 break;
1901 case NS_USER:
1902 $text = wfMsg( 'userpage' );
1903 break;
1904 case NS_PROJECT:
1905 $text = wfMsg( 'projectpage' );
1906 break;
1907 case NS_FILE:
1908 $text = wfMsg( 'imagepage' );
1909 # Make link known if image exists, even if the desc. page doesn't.
1910 if ( wfFindFile( $link ) )
1911 $linkOptions[] = 'known';
1912 break;
1913 case NS_MEDIAWIKI:
1914 $text = wfMsg( 'mediawikipage' );
1915 break;
1916 case NS_TEMPLATE:
1917 $text = wfMsg( 'templatepage' );
1918 break;
1919 case NS_HELP:
1920 $text = wfMsg( 'viewhelppage' );
1921 break;
1922 case NS_CATEGORY:
1923 $text = wfMsg( 'categorypage' );
1924 break;
1925 default:
1926 $text = wfMsg( 'articlepage' );
1927 }
1928 } else {
1929 $link = $this->mTitle->getTalkPage();
1930 $text = wfMsg( 'talkpage' );
1931 }
1932
1933 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1934
1935 return $s;
1936 }
1937
1938 function commentLink() {
1939 global $wgOut;
1940
1941 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
1942 return '';
1943 }
1944
1945 # __NEWSECTIONLINK___ changes behaviour here
1946 # If it is present, the link points to this page, otherwise
1947 # it points to the talk page
1948 if ( $this->mTitle->isTalkPage() ) {
1949 $title = $this->mTitle;
1950 } elseif ( $wgOut->showNewSectionLink() ) {
1951 $title = $this->mTitle;
1952 } else {
1953 $title = $this->mTitle->getTalkPage();
1954 }
1955
1956 return $this->link(
1957 $title,
1958 wfMsg( 'postcomment' ),
1959 array(),
1960 array(
1961 'action' => 'edit',
1962 'section' => 'new'
1963 ),
1964 array( 'known', 'noclasses' )
1965 );
1966 }
1967
1968 function getUploadLink() {
1969 global $wgUploadNavigationUrl;
1970
1971 if ( $wgUploadNavigationUrl ) {
1972 # Using an empty class attribute to avoid automatic setting of "external" class
1973 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
1974 } else {
1975 return $this->link(
1976 SpecialPage::getTitleFor( 'Upload' ),
1977 wfMsgHtml( 'upload' ),
1978 array(),
1979 array(),
1980 array( 'known', 'noclasses' )
1981 );
1982 }
1983 }
1984
1985 /* these are used extensively in SkinTemplate, but also some other places */
1986 static function makeMainPageUrl( $urlaction = '' ) {
1987 $title = Title::newMainPage();
1988 self::checkTitle( $title, '' );
1989
1990 return $title->getLocalURL( $urlaction );
1991 }
1992
1993 static function makeSpecialUrl( $name, $urlaction = '' ) {
1994 $title = SpecialPage::getTitleFor( $name );
1995 return $title->getLocalURL( $urlaction );
1996 }
1997
1998 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1999 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2000 return $title->getLocalURL( $urlaction );
2001 }
2002
2003 static function makeI18nUrl( $name, $urlaction = '' ) {
2004 $title = Title::newFromText( wfMsgForContent( $name ) );
2005 self::checkTitle( $title, $name );
2006 return $title->getLocalURL( $urlaction );
2007 }
2008
2009 static function makeUrl( $name, $urlaction = '' ) {
2010 $title = Title::newFromText( $name );
2011 self::checkTitle( $title, $name );
2012
2013 return $title->getLocalURL( $urlaction );
2014 }
2015
2016 /**
2017 * If url string starts with http, consider as external URL, else
2018 * internal
2019 */
2020 static function makeInternalOrExternalUrl( $name ) {
2021 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2022 return $name;
2023 } else {
2024 return self::makeUrl( $name );
2025 }
2026 }
2027
2028 # this can be passed the NS number as defined in Language.php
2029 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2030 $title = Title::makeTitleSafe( $namespace, $name );
2031 self::checkTitle( $title, $name );
2032
2033 return $title->getLocalURL( $urlaction );
2034 }
2035
2036 /* these return an array with the 'href' and boolean 'exists' */
2037 static function makeUrlDetails( $name, $urlaction = '' ) {
2038 $title = Title::newFromText( $name );
2039 self::checkTitle( $title, $name );
2040
2041 return array(
2042 'href' => $title->getLocalURL( $urlaction ),
2043 'exists' => $title->getArticleID() != 0 ? true : false
2044 );
2045 }
2046
2047 /**
2048 * Make URL details where the article exists (or at least it's convenient to think so)
2049 */
2050 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2051 $title = Title::newFromText( $name );
2052 self::checkTitle( $title, $name );
2053
2054 return array(
2055 'href' => $title->getLocalURL( $urlaction ),
2056 'exists' => true
2057 );
2058 }
2059
2060 # make sure we have some title to operate on
2061 static function checkTitle( &$title, $name ) {
2062 if ( !is_object( $title ) ) {
2063 $title = Title::newFromText( $name );
2064 if ( !is_object( $title ) ) {
2065 $title = Title::newFromText( '--error: link target missing--' );
2066 }
2067 }
2068 }
2069
2070 /**
2071 * Build an array that represents the sidebar(s), the navigation bar among them
2072 *
2073 * @return array
2074 */
2075 function buildSidebar() {
2076 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2077 global $wgLang;
2078 wfProfileIn( __METHOD__ );
2079
2080 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2081
2082 if ( $wgEnableSidebarCache ) {
2083 $cachedsidebar = $parserMemc->get( $key );
2084 if ( $cachedsidebar ) {
2085 wfProfileOut( __METHOD__ );
2086 return $cachedsidebar;
2087 }
2088 }
2089
2090 $bar = array();
2091 $this->addToSidebar( $bar, 'sidebar' );
2092
2093 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2094 if ( $wgEnableSidebarCache ) {
2095 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2096 }
2097
2098 wfProfileOut( __METHOD__ );
2099 return $bar;
2100 }
2101 /**
2102 * Add content from a sidebar system message
2103 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2104 *
2105 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2106 *
2107 * @param &$bar array
2108 * @param $message String
2109 */
2110 function addToSidebar( &$bar, $message ) {
2111 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2112 }
2113
2114 /**
2115 * Add content from plain text
2116 * @since 1.17
2117 * @param &$bar array
2118 * @param $text string
2119 */
2120 function addToSidebarPlain( &$bar, $text ) {
2121 $lines = explode( "\n", $text );
2122 $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.
2123
2124 $heading = '';
2125
2126 foreach ( $lines as $line ) {
2127 if ( strpos( $line, '*' ) !== 0 ) {
2128 continue;
2129 }
2130
2131 if ( strpos( $line, '**' ) !== 0 ) {
2132 $heading = trim( $line, '* ' );
2133 if ( !array_key_exists( $heading, $bar ) ) {
2134 $bar[$heading] = array();
2135 }
2136 } else {
2137 $line = trim( $line, '* ' );
2138
2139 if ( strpos( $line, '|' ) !== false ) { // sanity check
2140 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2141 $link = wfMsgForContent( $line[0] );
2142
2143 if ( $link == '-' ) {
2144 continue;
2145 }
2146
2147 $text = wfMsgExt( $line[1], 'parsemag' );
2148
2149 if ( wfEmptyMsg( $line[1], $text ) ) {
2150 $text = $line[1];
2151 }
2152
2153 if ( wfEmptyMsg( $line[0], $link ) ) {
2154 $link = $line[0];
2155 }
2156
2157 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2158 $href = $link;
2159 } else {
2160 $title = Title::newFromText( $link );
2161
2162 if ( $title ) {
2163 $title = $title->fixSpecialName();
2164 $href = $title->getLocalURL();
2165 } else {
2166 $href = 'INVALID-TITLE';
2167 }
2168 }
2169
2170 $bar[$heading][] = array(
2171 'text' => $text,
2172 'href' => $href,
2173 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2174 'active' => false
2175 );
2176 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2177 global $wgParser, $wgTitle;
2178
2179 $line = substr( $line, 2, strlen( $line ) - 4 );
2180
2181 if ( is_null( $wgParser->mOptions ) ) {
2182 $wgParser->mOptions = new ParserOptions();
2183 }
2184
2185 $wgParser->mOptions->setEditSection( false );
2186 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $wgParser->mOptions )->getText();
2187 } else {
2188 continue;
2189 }
2190 }
2191 }
2192
2193 if ( count( $wikiBar ) > 0 ) {
2194 $bar = array_merge( $bar, $wikiBar );
2195 }
2196
2197 return $bar;
2198 }
2199
2200 /**
2201 * Should we include common/wikiprintable.css? Skins that have their own
2202 * print stylesheet should override this and return false. (This is an
2203 * ugly hack to get Monobook to play nicely with
2204 * OutputPage::headElement().)
2205 *
2206 * @return bool
2207 */
2208 public function commonPrintStylesheet() {
2209 return true;
2210 }
2211
2212 /**
2213 * Gets new talk page messages for the current user.
2214 * @return MediaWiki message or if no new talk page messages, nothing
2215 */
2216 function getNewtalks() {
2217 global $wgUser, $wgOut;
2218
2219 $newtalks = $wgUser->getNewMessageLinks();
2220 $ntl = '';
2221
2222 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2223 $userTitle = $this->mUser->getUserPage();
2224 $userTalkTitle = $userTitle->getTalkPage();
2225
2226 if ( !$userTalkTitle->equals( $this->mTitle ) ) {
2227 $newMessagesLink = $this->link(
2228 $userTalkTitle,
2229 wfMsgHtml( 'newmessageslink' ),
2230 array(),
2231 array( 'redirect' => 'no' ),
2232 array( 'known', 'noclasses' )
2233 );
2234
2235 $newMessagesDiffLink = $this->link(
2236 $userTalkTitle,
2237 wfMsgHtml( 'newmessagesdifflink' ),
2238 array(),
2239 array( 'diff' => 'cur' ),
2240 array( 'known', 'noclasses' )
2241 );
2242
2243 $ntl = wfMsg(
2244 'youhavenewmessages',
2245 $newMessagesLink,
2246 $newMessagesDiffLink
2247 );
2248 # Disable Squid cache
2249 $wgOut->setSquidMaxage( 0 );
2250 }
2251 } elseif ( count( $newtalks ) ) {
2252 // _>" " for BC <= 1.16
2253 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2254 $msgs = array();
2255
2256 foreach ( $newtalks as $newtalk ) {
2257 $msgs[] = Xml::element(
2258 'a',
2259 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2260 );
2261 }
2262 $parts = implode( $sep, $msgs );
2263 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2264 $wgOut->setSquidMaxage( 0 );
2265 }
2266
2267 return $ntl;
2268 }
2269 }