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