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