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