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