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