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