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