]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/Skin.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / includes / Skin.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3         die( 1 );
4
5 # See skin.txt
6
7 /**
8  * The main skin class that provide methods and properties for all other skins.
9  * This base class is also the "Standard" skin.
10  *
11  * See docs/skin.txt for more information.
12  *
13  * @addtogroup Skins
14  */
15 class Skin extends Linker {
16         /**#@+
17          * @private
18          */
19         var $lastdate, $lastline;
20         var $rc_cache ; # Cache for Enhanced Recent Changes
21         var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
22         var $rcMoveIndex;
23         var $mWatchLinkNum = 0; // Appended to end of watch link id's
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          * Normalize a skin preference value to a form that can be loaded.
66          * If a skin can't be found, it will fall back to the configured
67          * default (or the old 'Classic' skin if that's broken).
68          * @param string $key
69          * @return string
70          * @static
71          */
72         static function normalizeKey( $key ) {
73                 global $wgDefaultSkin;
74                 $skinNames = Skin::getSkinNames();
75
76                 if( $key == '' ) {
77                         // Don't return the default immediately;
78                         // in a misconfiguration we need to fall back.
79                         $key = $wgDefaultSkin;
80                 }
81
82                 if( isset( $skinNames[$key] ) ) {
83                         return $key;
84                 }
85
86                 // Older versions of the software used a numeric setting
87                 // in the user preferences.
88                 $fallback = array(
89                         0 => $wgDefaultSkin,
90                         1 => 'nostalgia',
91                         2 => 'cologneblue' );
92
93                 if( isset( $fallback[$key] ) ){
94                         $key = $fallback[$key];
95                 }
96
97                 if( isset( $skinNames[$key] ) ) {
98                         return $key;
99                 } else {
100                         // The old built-in skin
101                         return 'standard';
102                 }
103         }
104
105         /**
106          * Factory method for loading a skin of a given type
107          * @param string $key 'monobook', 'standard', etc
108          * @return Skin
109          * @static
110          */
111         static function &newFromKey( $key ) {
112                 global $wgStyleDirectory;
113                 
114                 $key = Skin::normalizeKey( $key );
115
116                 $skinNames = Skin::getSkinNames();
117                 $skinName = $skinNames[$key];
118
119                 # Grab the skin class and initialise it.
120                 // Preload base classes to work around APC/PHP5 bug
121                 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
122                 if( file_exists( $deps ) ) include_once( $deps );
123                 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
124
125                 # Check if we got if not failback to default skin
126                 $className = 'Skin'.$skinName;
127                 if( !class_exists( $className ) ) {
128                         # DO NOT die if the class isn't found. This breaks maintenance
129                         # scripts and can cause a user account to be unrecoverable
130                         # except by SQL manipulation if a previously valid skin name
131                         # is no longer valid.
132                         wfDebug( "Skin class does not exist: $className\n" );
133                         $className = 'SkinStandard';
134                         require_once( "{$wgStyleDirectory}/Standard.php" );
135                 }
136                 $skin = new $className;
137                 return $skin;
138         }
139
140         /** @return string path to the skin stylesheet */
141         function getStylesheet() {
142                 return 'common/wikistandard.css';
143         }
144
145         /** @return string skin name */
146         public function getSkinName() {
147                 return $this->skinname;
148         }
149
150         function qbSetting() {
151                 global $wgOut, $wgUser;
152
153                 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
154                 $q = $wgUser->getOption( 'quickbar', 0 );
155                 return $q;
156         }
157
158         function initPage( &$out ) {
159                 global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
160
161                 $fname = 'Skin::initPage';
162                 wfProfileIn( $fname );
163
164                 if( false !== $wgFavicon ) {
165                         $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
166                 }
167
168                 # OpenSearch description link
169                 $out->addLink( array( 
170                         'rel' => 'search', 
171                         'type' => 'application/opensearchdescription+xml',
172                         'href' => "$wgScriptPath/opensearch_desc.php",
173                         'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
174                 ));
175
176                 $this->addMetadataLinks($out);
177
178                 $this->mRevisionId = $out->mRevisionId;
179                 
180                 $this->preloadExistence();
181
182                 wfProfileOut( $fname );
183         }
184
185         /**
186          * Preload the existence of three commonly-requested pages in a single query
187          */
188         function preloadExistence() {
189                 global $wgUser, $wgTitle;
190
191                 // User/talk link
192                 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
193
194                 // Other tab link
195                 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
196                         // nothing
197                 } elseif ( $wgTitle->isTalkPage() ) {
198                         $titles[] = $wgTitle->getSubjectPage();
199                 } else {
200                         $titles[] = $wgTitle->getTalkPage();
201                 }
202
203                 $lb = new LinkBatch( $titles );
204                 $lb->execute();
205         }
206         
207         function addMetadataLinks( &$out ) {
208                 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
209                 global $wgRightsPage, $wgRightsUrl;
210
211                 if( $out->isArticleRelated() ) {
212                         # note: buggy CC software only reads first "meta" link
213                         if( $wgEnableCreativeCommonsRdf ) {
214                                 $out->addMetadataLink( array(
215                                         'title' => 'Creative Commons',
216                                         'type' => 'application/rdf+xml',
217                                         'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
218                         }
219                         if( $wgEnableDublinCoreRdf ) {
220                                 $out->addMetadataLink( array(
221                                         'title' => 'Dublin Core',
222                                         'type' => 'application/rdf+xml',
223                                         'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
224                         }
225                 }
226                 $copyright = '';
227                 if( $wgRightsPage ) {
228                         $copy = Title::newFromText( $wgRightsPage );
229                         if( $copy ) {
230                                 $copyright = $copy->getLocalURL();
231                         }
232                 }
233                 if( !$copyright && $wgRightsUrl ) {
234                         $copyright = $wgRightsUrl;
235                 }
236                 if( $copyright ) {
237                         $out->addLink( array(
238                                 'rel' => 'copyright',
239                                 'href' => $copyright ) );
240                 }
241         }
242
243         function outputPage( &$out ) {
244                 global $wgDebugComments;
245
246                 wfProfileIn( __METHOD__ );
247                 $this->initPage( $out );
248
249                 $out->out( $out->headElement() );
250
251                 $out->out( "\n<body" );
252                 $ops = $this->getBodyOptions();
253                 foreach ( $ops as $name => $val ) {
254                         $out->out( " $name='$val'" );
255                 }
256                 $out->out( ">\n" );
257                 if ( $wgDebugComments ) {
258                         $out->out( "<!-- Wiki debugging output:\n" .
259                           $out->mDebugtext . "-->\n" );
260                 }
261
262                 $out->out( $this->beforeContent() );
263
264                 $out->out( $out->mBodytext . "\n" );
265
266                 $out->out( $this->afterContent() );
267
268                 $out->out( $this->bottomScripts() );
269
270                 $out->out( $out->reportTime() );
271
272                 $out->out( "\n</body></html>" );
273                 wfProfileOut( __METHOD__ );
274         }
275
276         static function makeVariablesScript( $data ) {
277                 global $wgJsMimeType;
278
279                 $r = "<script type= \"$wgJsMimeType\">/*<![CDATA[*/\n";
280                 foreach ( $data as $name => $value ) {
281                         $encValue = Xml::encodeJsVar( $value );
282                         $r .= "var $name = $encValue;\n";
283                 }
284                 $r .= "/*]]>*/</script>\n";
285
286                 return $r;
287         }
288
289         /**
290          * Make a <script> tag containing global variables
291          * @param array $data Associative array containing one element:
292          *     skinname => the skin name
293          * The odd calling convention is for backwards compatibility
294          */
295         static function makeGlobalVariablesScript( $data ) {
296                 global $wgScript, $wgStylePath, $wgUser;
297                 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
298                 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
299                 global $wgBreakFrames, $wgRequest;
300                 global $wgUseAjax, $wgAjaxWatch;
301
302                 $ns = $wgTitle->getNamespace();
303                 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
304
305                 $vars = array( 
306                         'skin' => $data['skinname'],
307                         'stylepath' => $wgStylePath,
308                         'wgArticlePath' => $wgArticlePath,
309                         'wgScriptPath' => $wgScriptPath,
310                         'wgScript' => $wgScript,
311                         'wgServer' => $wgServer,
312                         'wgCanonicalNamespace' => $nsname,
313                         'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBKey() ),
314                         'wgNamespaceNumber' => $wgTitle->getNamespace(),
315                         'wgPageName' => $wgTitle->getPrefixedDBKey(),
316                         'wgTitle' => $wgTitle->getText(),
317                         'wgAction' => $wgRequest->getText( 'action', 'view' ),
318                         'wgRestrictionEdit' => $wgTitle->getRestrictions( 'edit' ),
319                         'wgRestrictionMove' => $wgTitle->getRestrictions( 'move' ),
320                         'wgArticleId' => $wgTitle->getArticleId(),
321                         'wgIsArticle' => $wgOut->isArticle(),
322                         'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
323                         'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
324                         'wgUserLanguage' => $wgLang->getCode(),
325                         'wgContentLanguage' => $wgContLang->getCode(),
326                         'wgBreakFrames' => $wgBreakFrames,
327                         'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
328                 );
329
330                 global $wgLivePreview;
331                 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
332                         $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
333                         $vars['wgLivepreviewMessageReady']   = wfMsg( 'livepreview-ready' );
334                         $vars['wgLivepreviewMessageFailed']  = wfMsg( 'livepreview-failed' );
335                         $vars['wgLivepreviewMessageError']   = wfMsg( 'livepreview-error' );
336                 }
337
338                 if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
339                         $msgs = (object)array();
340                         foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
341                                 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
342                         }
343                         $vars['wgAjaxWatch'] = $msgs;
344                 }
345
346                 return self::makeVariablesScript( $vars );
347         }
348
349         function getHeadScripts( $allowUserJs ) {
350                 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
351
352                 $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
353
354                 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
355                 global $wgUseSiteJs;
356                 if ($wgUseSiteJs) {
357                         $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
358                         $r .= "<script type=\"$wgJsMimeType\" src=\"".
359                                 htmlspecialchars(self::makeUrl('-',
360                                         "action=raw$jsCache&gen=js&useskin=" .
361                                         urlencode( $this->getSkinName() ) ) ) .
362                                 "\"><!-- site js --></script>\n";
363                 }
364                 if( $allowUserJs && $wgUser->isLoggedIn() ) {
365                         $userpage = $wgUser->getUserPage();
366                         $userjs = htmlspecialchars( self::makeUrl(
367                                 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
368                                 'action=raw&ctype='.$wgJsMimeType));
369                         $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
370                 }
371                 return $r;
372         }
373
374         /**
375          * To make it harder for someone to slip a user a fake
376          * user-JavaScript or user-CSS preview, a random token
377          * is associated with the login session. If it's not
378          * passed back with the preview request, we won't render
379          * the code.
380          *
381          * @param string $action
382          * @return bool
383          * @private
384          */
385         function userCanPreview( $action ) {
386                 global $wgTitle, $wgRequest, $wgUser;
387
388                 if( $action != 'submit' )
389                         return false;
390                 if( !$wgRequest->wasPosted() )
391                         return false;
392                 if( !$wgTitle->userCanEditCssJsSubpage() )
393                         return false;
394                 return $wgUser->matchEditToken(
395                         $wgRequest->getVal( 'wpEditToken' ) );
396         }
397
398         # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
399         function getUserStylesheet() {
400                 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
401                 $sheet = $this->getStylesheet();
402                 $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
403                 $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
404                 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
405                 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
406
407                 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
408                 $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
409                         '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
410
411                 $s .= $this->doGetUserStyles();
412                 return $s."\n";
413         }
414
415         /**
416          * This returns MediaWiki:Common.js, and derived classes may add other JS.
417          * Despite its name, it does *not* return any custom user JS from user
418          * subpages.  The returned script is sitewide and publicly cacheable and
419          * therefore must not include anything that varies according to user,
420          * interface language, etc. (although it may vary by skin).  See
421          * makeGlobalVariablesScript for things that can vary per page view and are
422          * not cacheable.
423          *
424          * @return string Raw JavaScript to be returned
425          */
426         public function getUserJs() {
427                 wfProfileIn( __METHOD__ );
428
429                 global $wgStylePath;
430                 $s = "/* generated javascript */\n";
431                 $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n";
432                 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
433                 $s .= "\n\n/* MediaWiki:Common.js */\n";
434                 $commonJs = wfMsgForContent('common.js');
435                 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
436                         $s .= $commonJs;
437                 }
438                 wfProfileOut( __METHOD__ );
439                 return $s;
440         }
441
442         /**
443          * Return html code that include User stylesheets
444          */
445         function getUserStyles() {
446                 $s = "<style type='text/css'>\n";
447                 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
448                 $s .= $this->getUserStylesheet();
449                 $s .= "/*]]>*/ /* */\n";
450                 $s .= "</style>\n";
451                 return $s;
452         }
453
454         /**
455          * Some styles that are set by user through the user settings interface.
456          */
457         function doGetUserStyles() {
458                 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
459
460                 $s = '';
461
462                 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
463                         if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
464                                 $s .= $wgRequest->getText('wpTextbox1');
465                         } else {
466                                 $userpage = $wgUser->getUserPage();
467                                 $s.= '@import "'.self::makeUrl(
468                                         $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
469                                         'action=raw&ctype=text/css').'";'."\n";
470                         }
471                 }
472
473                 return $s . $this->reallyDoGetUserStyles();
474         }
475
476         function reallyDoGetUserStyles() {
477                 global $wgUser;
478                 $s = '';
479                 if (($undopt = $wgUser->getOption("underline")) != 2) {
480                         $underline = $undopt ? 'underline' : 'none';
481                         $s .= "a { text-decoration: $underline; }\n";
482                 }
483                 if( $wgUser->getOption( 'highlightbroken' ) ) {
484                         $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
485                 } else {
486                         $s .= <<<END
487 a.new, #quickbar a.new,
488 a.stub, #quickbar a.stub {
489         color: inherit;
490         text-decoration: inherit;
491 }
492 a.new:after, #quickbar a.new:after {
493         content: "?";
494         color: #CC2200;
495         text-decoration: $underline;
496 }
497 a.stub:after, #quickbar a.stub:after {
498         content: "!";
499         color: #772233;
500         text-decoration: $underline;
501 }
502 END;
503                 }
504                 if( $wgUser->getOption( 'justify' ) ) {
505                         $s .= "#article, #bodyContent { text-align: justify; }\n";
506                 }
507                 if( !$wgUser->getOption( 'showtoc' ) ) {
508                         $s .= "#toc { display: none; }\n";
509                 }
510                 if( !$wgUser->getOption( 'editsection' ) ) {
511                         $s .= ".editsection { display: none; }\n";
512                 }
513                 return $s;
514         }
515
516         function getBodyOptions() {
517                 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
518
519                 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
520
521                 if ( 0 != $wgTitle->getNamespace() ) {
522                         $a = array( 'bgcolor' => '#ffffec' );
523                 }
524                 else $a = array( 'bgcolor' => '#FFFFFF' );
525                 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
526                   $wgTitle->userCan( 'edit' ) ) {
527                         $s = $wgTitle->getFullURL( $this->editUrlOptions() );
528                         $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
529                         $a += array ('ondblclick' => $s);
530
531                 }
532                 $a['onload'] = $wgOut->getOnloadHandler();
533                 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
534                         if( $a['onload'] != '' ) {
535                                 $a['onload'] .= ';';
536                         }
537                         $a['onload'] .= 'setupRightClickEdit()';
538                 }
539                 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
540                 ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
541                 return $a;
542         }
543
544         /**
545          * URL to the logo
546          */
547         function getLogo() {
548                 global $wgLogo;
549                 return $wgLogo;
550         }
551
552         /**
553          * This will be called immediately after the <body> tag.  Split into
554          * two functions to make it easier to subclass.
555          */
556         function beforeContent() {
557                 return $this->doBeforeContent();
558         }
559
560         function doBeforeContent() {
561                 global $wgContLang;
562                 $fname = 'Skin::doBeforeContent';
563                 wfProfileIn( $fname );
564
565                 $s = '';
566                 $qb = $this->qbSetting();
567
568                 if( $langlinks = $this->otherLanguages() ) {
569                         $rows = 2;
570                         $borderhack = '';
571                 } else {
572                         $rows = 1;
573                         $langlinks = false;
574                         $borderhack = 'class="top"';
575                 }
576
577                 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
578                   "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
579
580                 $shove = ($qb != 0);
581                 $left = ($qb == 1 || $qb == 3);
582                 if($wgContLang->isRTL()) $left = !$left;
583
584                 if ( !$shove ) {
585                         $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
586                           $this->logoText() . '</td>';
587                 } elseif( $left ) {
588                         $s .= $this->getQuickbarCompensator( $rows );
589                 }
590                 $l = $wgContLang->isRTL() ? 'right' : 'left';
591                 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
592
593                 $s .= $this->topLinks() ;
594                 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
595
596                 $r = $wgContLang->isRTL() ? "left" : "right";
597                 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
598                 $s .= $this->nameAndLogin();
599                 $s .= "\n<br />" . $this->searchForm() . "</td>";
600
601                 if ( $langlinks ) {
602                         $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
603                 }
604
605                 if ( $shove && !$left ) { # Right
606                         $s .= $this->getQuickbarCompensator( $rows );
607                 }
608                 $s .= "</tr>\n</table>\n</div>\n";
609                 $s .= "\n<div id='article'>\n";
610
611                 $notice = wfGetSiteNotice();
612                 if( $notice ) {
613                         $s .= "\n<div id='siteNotice'>$notice</div>\n";
614                 }
615                 $s .= $this->pageTitle();
616                 $s .= $this->pageSubtitle() ;
617                 $s .= $this->getCategories();
618                 wfProfileOut( $fname );
619                 return $s;
620         }
621
622
623         function getCategoryLinks () {
624                 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
625                 global $wgContLang;
626
627                 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
628
629                 # Separator
630                 $sep = wfMsgHtml( 'catseparator' );
631
632                 // Use Unicode bidi embedding override characters,
633                 // to make sure links don't smash each other up in ugly ways.
634                 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
635                 $embed = "<span dir='$dir'>";
636                 $pop = '</span>';
637                 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
638
639                 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
640                 $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
641                         . ': ' . $t;
642
643                 # optional 'dmoz-like' category browser. Will be shown under the list
644                 # of categories an article belong to
645                 if($wgUseCategoryBrowser) {
646                         $s .= '<br /><hr />';
647
648                         # get a big array of the parents tree
649                         $parenttree = $wgTitle->getParentCategoryTree();
650                         # Skin object passed by reference cause it can not be
651                         # accessed under the method subfunction drawCategoryBrowser
652                         $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
653                         # Clean out bogus first entry and sort them
654                         unset($tempout[0]);
655                         asort($tempout);
656                         # Output one per line
657                         $s .= implode("<br />\n", $tempout);
658                 }
659
660                 return $s;
661         }
662
663         /** Render the array as a serie of links.
664          * @param $tree Array: categories tree returned by Title::getParentCategoryTree
665          * @param &skin Object: skin passed by reference
666          * @return String separated by &gt;, terminate with "\n"
667          */
668         function drawCategoryBrowser($tree, &$skin) {
669                 $return = '';
670                 foreach ($tree as $element => $parent) {
671                         if (empty($parent)) {
672                                 # element start a new list
673                                 $return .= "\n";
674                         } else {
675                                 # grab the others elements
676                                 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
677                         }
678                         # add our current element to the list
679                         $eltitle = Title::NewFromText($element);
680                         $return .=  $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
681                 }
682                 return $return;
683         }
684
685         function getCategories() {
686                 $catlinks=$this->getCategoryLinks();
687                 if(!empty($catlinks)) {
688                         return "<p class='catlinks'>{$catlinks}</p>";
689                 }
690         }
691
692         function getQuickbarCompensator( $rows = 1 ) {
693                 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
694         }
695
696         /**
697          * This gets called shortly before the \</body\> tag.
698          * @return String HTML to be put before \</body\> 
699          */
700         function afterContent() {
701                 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
702                 return $printfooter . $this->doAfterContent();
703         }
704
705         /**
706          * This gets called shortly before the \</body\> tag.
707          * @return String HTML-wrapped JS code to be put before \</body\> 
708          */
709         function bottomScripts() {
710                 global $wgJsMimeType;
711                 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
712                 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
713                 return $bottomScriptText;
714         }
715
716         /** @return string Retrievied from HTML text */
717         function printSource() {
718                 global $wgTitle;
719                 $url = htmlspecialchars( $wgTitle->getFullURL() );
720                 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
721         }
722
723         function printFooter() {
724                 return "<p>" .  $this->printSource() .
725                         "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
726         }
727
728         /** overloaded by derived classes */
729         function doAfterContent() { }
730
731         function pageTitleLinks() {
732                 global $wgOut, $wgTitle, $wgUser, $wgRequest;
733
734                 $oldid = $wgRequest->getVal( 'oldid' );
735                 $diff = $wgRequest->getVal( 'diff' );
736                 $action = $wgRequest->getText( 'action' );
737
738                 $s = $this->printableLink();
739                 $disclaimer = $this->disclaimerLink(); # may be empty
740                 if( $disclaimer ) {
741                         $s .= ' | ' . $disclaimer;
742                 }
743                 $privacy = $this->privacyLink(); # may be empty too
744                 if( $privacy ) {
745                         $s .= ' | ' . $privacy;
746                 }
747
748                 if ( $wgOut->isArticleRelated() ) {
749                         if ( $wgTitle->getNamespace() == NS_IMAGE ) {
750                                 $name = $wgTitle->getDBkey();
751                                 $image = wfFindFile( $wgTitle );
752                                 if( $image ) {
753                                         $link = htmlspecialchars( $image->getURL() );
754                                         $style = $this->getInternalLinkAttributes( $link, $name );
755                                         $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
756                                 }
757                         }
758                 }
759                 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
760                         $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
761                                         wfMsg( 'currentrev' ) );
762                 }
763
764                 if ( $wgUser->getNewtalk() ) {
765                         # do not show "You have new messages" text when we are viewing our
766                         # own talk page
767                         if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
768                                 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
769                                 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
770                                 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
771                                 # disable caching
772                                 $wgOut->setSquidMaxage(0);
773                                 $wgOut->enableClientCache(false);
774                         }
775                 }
776
777                 $undelete = $this->getUndeleteLink();
778                 if( !empty( $undelete ) ) {
779                         $s .= ' | '.$undelete;
780                 }
781                 return $s;
782         }
783
784         function getUndeleteLink() {
785                 global $wgUser, $wgTitle, $wgContLang, $action;
786                 if(     $wgUser->isAllowed( 'deletedhistory' ) &&
787                         (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
788                         ($n = $wgTitle->isDeleted() ) )
789                 {
790                         if ( $wgUser->isAllowed( 'delete' ) ) {
791                                 $msg = 'thisisdeleted';
792                         } else {
793                                 $msg = 'viewdeleted';
794                         }
795                         return wfMsg( $msg,
796                                 $this->makeKnownLinkObj(
797                                         SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
798                                         wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
799                 }
800                 return '';
801         }
802
803         function printableLink() {
804                 global $wgOut, $wgFeedClasses, $wgRequest;
805
806                 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
807
808                 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
809                 if( $wgOut->isSyndicated() ) {
810                         foreach( $wgFeedClasses as $format => $class ) {
811                                 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
812                                 $s .= " | <a href=\"$feedurl\">{$format}</a>";
813                         }
814                 }
815                 return $s;
816         }
817
818         function pageTitle() {
819                 global $wgOut;
820                 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
821                 return $s;
822         }
823
824         function pageSubtitle() {
825                 global $wgOut;
826
827                 $sub = $wgOut->getSubtitle();
828                 if ( '' == $sub ) {
829                         global $wgExtraSubtitle;
830                         $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
831                 }
832                 $subpages = $this->subPageSubtitle();
833                 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
834                 $s = "<p class='subtitle'>{$sub}</p>\n";
835                 return $s;
836         }
837
838         function subPageSubtitle() {
839                 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
840                 $subpages = '';
841                 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
842                         $ptext=$wgTitle->getPrefixedText();
843                         if(preg_match('/\//',$ptext)) {
844                                 $links = explode('/',$ptext);
845                                 $c = 0;
846                                 $growinglink = '';
847                                 foreach($links as $link) {
848                                         $c++;
849                                         if ($c<count($links)) {
850                                                 $growinglink .= $link;
851                                                 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
852                                                 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
853                                                 if ($c>1) {
854                                                         $subpages .= ' | ';
855                                                 } else  {
856                                                         $subpages .= '&lt; ';
857                                                 }
858                                                 $subpages .= $getlink;
859                                                 $growinglink .= '/';
860                                         }
861                                 }
862                         }
863                 }
864                 return $subpages;
865         }
866
867         /**
868          * Returns true if the IP should be shown in the header
869          */
870         function showIPinHeader() {
871                 global $wgShowIPinHeader;
872                 return $wgShowIPinHeader && session_id() != '';
873         }
874
875         function nameAndLogin() {
876                 global $wgUser, $wgTitle, $wgLang, $wgContLang;
877
878                 $lo = $wgContLang->specialPage( 'Userlogout' );
879
880                 $s = '';
881                 if ( $wgUser->isAnon() ) {
882                         if( $this->showIPinHeader() ) {
883                                 $n = wfGetIP();
884
885                                 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
886                                   $wgLang->getNsText( NS_TALK ) );
887
888                                 $s .= $n . ' ('.$tl.')';
889                         } else {
890                                 $s .= wfMsg('notloggedin');
891                         }
892
893                         $rt = $wgTitle->getPrefixedURL();
894                         if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
895                                 $q = '';
896                         } else { $q = "returnto={$rt}"; }
897
898                         $s .= "\n<br />" . $this->makeKnownLinkObj(
899                                 SpecialPage::getTitleFor( 'Userlogin' ),
900                                 wfMsg( 'login' ), $q );
901                 } else {
902                         $n = $wgUser->getName();
903                         $rt = $wgTitle->getPrefixedURL();
904                         $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
905                           $wgLang->getNsText( NS_TALK ) );
906
907                         $tl = " ({$tl})";
908
909                         $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
910                           $n ) . "{$tl}<br />" .
911                           $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
912                           "returnto={$rt}" ) . ' | ' .
913                           $this->specialLink( 'preferences' );
914                 }
915                 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
916                   wfMsg( 'help' ) );
917
918                 return $s;
919         }
920
921         function getSearchLink() {
922                 $searchPage = SpecialPage::getTitleFor( 'Search' );
923                 return $searchPage->getLocalURL();
924         }
925
926         function escapeSearchLink() {
927                 return htmlspecialchars( $this->getSearchLink() );
928         }
929
930         function searchForm() {
931                 global $wgRequest;
932                 $search = $wgRequest->getText( 'search' );
933
934                 $s = '<form name="search" class="inline" method="post" action="'
935                   . $this->escapeSearchLink() . "\">\n"
936                   . '<input type="text" name="search" size="19" value="'
937                   . htmlspecialchars(substr($search,0,256)) . "\" />\n"
938                   . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
939                   . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
940
941                 return $s;
942         }
943
944         function topLinks() {
945                 global $wgOut;
946                 $sep = " |\n";
947
948                 $s = $this->mainPageLink() . $sep
949                   . $this->specialLink( 'recentchanges' );
950
951                 if ( $wgOut->isArticleRelated() ) {
952                         $s .=  $sep . $this->editThisPage()
953                           . $sep . $this->historyLink();
954                 }
955                 # Many people don't like this dropdown box
956                 #$s .= $sep . $this->specialPagesList();
957                 
958                 $s .= $this->variantLinks();
959                 
960                 $s .= $this->extensionTabLinks();
961
962                 return $s;
963         }
964         
965         /**
966          * Compatibility for extensions adding functionality through tabs.
967          * Eventually these old skins should be replaced with SkinTemplate-based
968          * versions, sigh...
969          * @return string
970          */
971         function extensionTabLinks() {
972                 $tabs = array();
973                 $s = '';
974                 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
975                 foreach( $tabs as $tab ) {
976                         $s .= ' | ' . Xml::element( 'a',
977                                 array( 'href' => $tab['href'] ),
978                                 $tab['text'] );
979                 }
980                 return $s;
981         }
982         
983         /**
984          * Language/charset variant links for classic-style skins
985          * @return string
986          */
987         function variantLinks() {
988                 $s = '';
989                 /* show links to different language variants */
990                 global $wgDisableLangConversion, $wgContLang, $wgTitle;
991                 $variants = $wgContLang->getVariants();
992                 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
993                         foreach( $variants as $code ) {
994                                 $varname = $wgContLang->getVariantname( $code );
995                                 if( $varname == 'disable' )
996                                         continue;
997                                 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
998                         }
999                 }
1000                 return $s;
1001         }
1002
1003         function bottomLinks() {
1004                 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1005                 $sep = " |\n";
1006
1007                 $s = '';
1008                 if ( $wgOut->isArticleRelated() ) {
1009                         $s .= '<strong>' . $this->editThisPage() . '</strong>';
1010                         if ( $wgUser->isLoggedIn() ) {
1011                                 $s .= $sep . $this->watchThisPage();
1012                         }
1013                         $s .= $sep . $this->talkLink()
1014                           . $sep . $this->historyLink()
1015                           . $sep . $this->whatLinksHere()
1016                           . $sep . $this->watchPageLinksLink();
1017
1018                         if ($wgUseTrackbacks)
1019                                 $s .= $sep . $this->trackbackLink();
1020
1021                         if ( $wgTitle->getNamespace() == NS_USER
1022                             || $wgTitle->getNamespace() == NS_USER_TALK )
1023
1024                         {
1025                                 $id=User::idFromName($wgTitle->getText());
1026                                 $ip=User::isIP($wgTitle->getText());
1027
1028                                 if($id || $ip) { # both anons and non-anons have contri list
1029                                         $s .= $sep . $this->userContribsLink();
1030                                 }
1031                                 if( $this->showEmailUser( $id ) ) {
1032                                         $s .= $sep . $this->emailUserLink();
1033                                 }
1034                         }
1035                         if ( $wgTitle->getArticleId() ) {
1036                                 $s .= "\n<br />";
1037                                 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1038                                 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1039                                 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1040                         }
1041                         $s .= "<br />\n" . $this->otherLanguages();
1042                 }
1043                 return $s;
1044         }
1045
1046         function pageStats() {
1047                 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1048                 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1049
1050                 $oldid = $wgRequest->getVal( 'oldid' );
1051                 $diff = $wgRequest->getVal( 'diff' );
1052                 if ( ! $wgOut->isArticle() ) { return ''; }
1053                 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1054                 if ( 0 == $wgArticle->getID() ) { return ''; }
1055
1056                 $s = '';
1057                 if ( !$wgDisableCounters ) {
1058                         $count = $wgLang->formatNum( $wgArticle->getCount() );
1059                         if ( $count ) {
1060                                 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1061                         }
1062                 }
1063
1064                 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1065                     require_once('Credits.php');
1066                     $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1067                 } else {
1068                     $s .= $this->lastModified();
1069                 }
1070
1071                 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1072                         $dbr = wfGetDB( DB_SLAVE );
1073                         $watchlist = $dbr->tableName( 'watchlist' );
1074                         $sql = "SELECT COUNT(*) AS n FROM $watchlist
1075                                 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
1076                                 "' AND  wl_namespace=" . $wgTitle->getNamespace() ;
1077                         $res = $dbr->query( $sql, 'Skin::pageStats');
1078                         $x = $dbr->fetchObject( $res );
1079                         $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
1080                 }
1081
1082                 return $s . ' ' .  $this->getCopyright();
1083         }
1084
1085         function getCopyright( $type = 'detect' ) {
1086                 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1087
1088                 if ( $type == 'detect' ) {
1089                         $oldid = $wgRequest->getVal( 'oldid' );
1090                         $diff = $wgRequest->getVal( 'diff' );
1091
1092                         if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1093                                 $type = 'history';
1094                         } else {
1095                                 $type = 'normal';
1096                         }
1097                 }
1098
1099                 if ( $type == 'history' ) {
1100                         $msg = 'history_copyright';
1101                 } else {
1102                         $msg = 'copyright';
1103                 }
1104
1105                 $out = '';
1106                 if( $wgRightsPage ) {
1107                         $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1108                 } elseif( $wgRightsUrl ) {
1109                         $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1110                 } else {
1111                         # Give up now
1112                         return $out;
1113                 }
1114                 $out .= wfMsgForContent( $msg, $link );
1115                 return $out;
1116         }
1117
1118         function getCopyrightIcon() {
1119                 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1120                 $out = '';
1121                 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1122                         $out = $wgCopyrightIcon;
1123                 } else if ( $wgRightsIcon ) {
1124                         $icon = htmlspecialchars( $wgRightsIcon );
1125                         if ( $wgRightsUrl ) {
1126                                 $url = htmlspecialchars( $wgRightsUrl );
1127                                 $out .= '<a href="'.$url.'">';
1128                         }
1129                         $text = htmlspecialchars( $wgRightsText );
1130                         $out .= "<img src=\"$icon\" alt='$text' />";
1131                         if ( $wgRightsUrl ) {
1132                                 $out .= '</a>';
1133                         }
1134                 }
1135                 return $out;
1136         }
1137
1138         function getPoweredBy() {
1139                 global $wgStylePath;
1140                 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1141                 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1142                 return $img;
1143         }
1144
1145         function lastModified() {
1146                 global $wgLang, $wgArticle, $wgLoadBalancer;
1147
1148                 $timestamp = $wgArticle->getTimestamp();
1149                 if ( $timestamp ) {
1150                         $d = $wgLang->date( $timestamp, true );
1151                         $t = $wgLang->time( $timestamp, true );
1152                         $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1153                 } else {
1154                         $s = '';
1155                 }
1156                 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1157                         $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1158                 }
1159                 return $s;
1160         }
1161
1162         function logoText( $align = '' ) {
1163                 if ( '' != $align ) { $a = " align='{$align}'"; }
1164                 else { $a = ''; }
1165
1166                 $mp = wfMsg( 'mainpage' );
1167                 $mptitle = Title::newMainPage();
1168                 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1169
1170                 $logourl = $this->getLogo();
1171                 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1172                 return $s;
1173         }
1174
1175         /**
1176          * show a drop-down box of special pages
1177          */
1178         function specialPagesList() {
1179                 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1180                 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1181                 foreach ( $pages as $name => $page ) {
1182                         $pages[$name] = $page->getDescription();
1183                 }
1184
1185                 $go = wfMsg( 'go' );
1186                 $sp = wfMsg( 'specialpages' );
1187                 $spp = $wgContLang->specialPage( 'Specialpages' );
1188
1189                 $s = '<form id="specialpages" method="get" class="inline" ' .
1190                   'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1191                 $s .= "<select name=\"wpDropdown\">\n";
1192                 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1193
1194
1195                 foreach ( $pages as $name => $desc ) {
1196                         $p = $wgContLang->specialPage( $name );
1197                         $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1198                 }
1199                 $s .= "</select>\n";
1200                 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1201                 $s .= "</form>\n";
1202                 return $s;
1203         }
1204
1205         function mainPageLink() {
1206                 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1207                 return $s;
1208         }
1209
1210         function copyrightLink() {
1211                 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1212                   wfMsg( 'copyrightpagename' ) );
1213                 return $s;
1214         }
1215
1216         private function footerLink ( $desc, $page ) {
1217                 // if the link description has been set to "-" in the default language,
1218                 if ( wfMsgForContent( $desc )  == '-') {
1219                         // then it is disabled, for all languages.
1220                         return '';
1221                 } else {
1222                         // Otherwise, we display the link for the user, described in their
1223                         // language (which may or may not be the same as the default language),
1224                         // but we make the link target be the one site-wide page.
1225                         return $this->makeKnownLink( wfMsgForContent( $page ), wfMsg( $desc ) );
1226                 }
1227         }
1228
1229         function privacyLink() {
1230                 return $this->footerLink( 'privacy', 'privacypage' );
1231         }
1232
1233         function aboutLink() {
1234                 return $this->footerLink( 'aboutsite', 'aboutpage' );
1235         }
1236
1237         function disclaimerLink() {
1238                 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1239         }
1240
1241         function editThisPage() {
1242                 global $wgOut, $wgTitle;
1243
1244                 if ( ! $wgOut->isArticleRelated() ) {
1245                         $s = wfMsg( 'protectedpage' );
1246                 } else {
1247                         if ( $wgTitle->userCan( 'edit' ) ) {
1248                                 $t = wfMsg( 'editthispage' );
1249                         } else {
1250                                 $t = wfMsg( 'viewsource' );
1251                         }
1252
1253                         $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1254                 }
1255                 return $s;
1256         }
1257
1258         /**
1259          * Return URL options for the 'edit page' link.
1260          * This may include an 'oldid' specifier, if the current page view is such.
1261          *
1262          * @return string
1263          * @private
1264          */
1265         function editUrlOptions() {
1266                 global $wgArticle;
1267
1268                 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1269                         return "action=edit&oldid=" . intval( $this->mRevisionId );
1270                 } else {
1271                         return "action=edit";
1272                 }
1273         }
1274
1275         function deleteThisPage() {
1276                 global $wgUser, $wgTitle, $wgRequest;
1277
1278                 $diff = $wgRequest->getVal( 'diff' );
1279                 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1280                         $t = wfMsg( 'deletethispage' );
1281
1282                         $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1283                 } else {
1284                         $s = '';
1285                 }
1286                 return $s;
1287         }
1288
1289         function protectThisPage() {
1290                 global $wgUser, $wgTitle, $wgRequest;
1291
1292                 $diff = $wgRequest->getVal( 'diff' );
1293                 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1294                         if ( $wgTitle->isProtected() ) {
1295                                 $t = wfMsg( 'unprotectthispage' );
1296                                 $q = 'action=unprotect';
1297                         } else {
1298                                 $t = wfMsg( 'protectthispage' );
1299                                 $q = 'action=protect';
1300                         }
1301                         $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1302                 } else {
1303                         $s = '';
1304                 }
1305                 return $s;
1306         }
1307
1308         function watchThisPage() {
1309                 global $wgOut, $wgTitle;
1310                 ++$this->mWatchLinkNum;
1311
1312                 if ( $wgOut->isArticleRelated() ) {
1313                         if ( $wgTitle->userIsWatching() ) {
1314                                 $t = wfMsg( 'unwatchthispage' );
1315                                 $q = 'action=unwatch';
1316                                 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1317                         } else {
1318                                 $t = wfMsg( 'watchthispage' );
1319                                 $q = 'action=watch';
1320                                 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1321                         }
1322                         $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1323                 } else {
1324                         $s = wfMsg( 'notanarticle' );
1325                 }
1326                 return $s;
1327         }
1328
1329         function moveThisPage() {
1330                 global $wgTitle;
1331
1332                 if ( $wgTitle->userCan( 'move' ) ) {
1333                         return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1334                           wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1335                 } else {
1336                         // no message if page is protected - would be redundant
1337                         return '';
1338                 }
1339         }
1340
1341         function historyLink() {
1342                 global $wgTitle;
1343
1344                 return $this->makeKnownLinkObj( $wgTitle,
1345                   wfMsg( 'history' ), 'action=history' );
1346         }
1347
1348         function whatLinksHere() {
1349                 global $wgTitle;
1350
1351                 return $this->makeKnownLinkObj( 
1352                         SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ), 
1353                         wfMsg( 'whatlinkshere' ) );
1354         }
1355
1356         function userContribsLink() {
1357                 global $wgTitle;
1358
1359                 return $this->makeKnownLinkObj( 
1360                         SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1361                         wfMsg( 'contributions' ) );
1362         }
1363
1364         function showEmailUser( $id ) {
1365                 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1366                 return $wgEnableEmail &&
1367                        $wgEnableUserEmail &&
1368                        $wgUser->isLoggedIn() && # show only to signed in users
1369                        0 != $id; # we can only email to non-anons ..
1370 #                      '' != $id->getEmail() && # who must have an email address stored ..
1371 #                      0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1372 #                      1 != $wgUser->getOption('disablemail'); # and not disabled
1373         }
1374
1375         function emailUserLink() {
1376                 global $wgTitle;
1377
1378                 return $this->makeKnownLinkObj( 
1379                         SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1380                         wfMsg( 'emailuser' ) );
1381         }
1382
1383         function watchPageLinksLink() {
1384                 global $wgOut, $wgTitle;
1385
1386                 if ( ! $wgOut->isArticleRelated() ) {
1387                         return '(' . wfMsg( 'notanarticle' ) . ')';
1388                 } else {
1389                         return $this->makeKnownLinkObj( 
1390                                 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ), 
1391                                 wfMsg( 'recentchangeslinked' ) );
1392                 }
1393         }
1394
1395         function trackbackLink() {
1396                 global $wgTitle;
1397
1398                 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1399                         . wfMsg('trackbacklink') . "</a>";
1400         }
1401
1402         function otherLanguages() {
1403                 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1404
1405                 if ( $wgHideInterlanguageLinks ) {
1406                         return '';
1407                 }
1408
1409                 $a = $wgOut->getLanguageLinks();
1410                 if ( 0 == count( $a ) ) {
1411                         return '';
1412                 }
1413
1414                 $s = wfMsg( 'otherlanguages' ) . ': ';
1415                 $first = true;
1416                 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1417                 foreach( $a as $l ) {
1418                         if ( ! $first ) { $s .= ' | '; }
1419                         $first = false;
1420
1421                         $nt = Title::newFromText( $l );
1422                         $url = $nt->escapeFullURL();
1423                         $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1424
1425                         if ( '' == $text ) { $text = $l; }
1426                         $style = $this->getExternalLinkAttributes( $l, $text );
1427                         $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1428                 }
1429                 if($wgContLang->isRTL()) $s .= '</span>';
1430                 return $s;
1431         }
1432
1433         function bugReportsLink() {
1434                 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1435                   wfMsg( 'bugreports' ) );
1436                 return $s;
1437         }
1438
1439         function talkLink() {
1440                 global $wgTitle;
1441
1442                 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1443                         # No discussion links for special pages
1444                         return '';
1445                 }
1446
1447                 if( $wgTitle->isTalkPage() ) {
1448                         $link = $wgTitle->getSubjectPage();
1449                         switch( $link->getNamespace() ) {
1450                                 case NS_MAIN:
1451                                         $text = wfMsg( 'articlepage' );
1452                                         break;
1453                                 case NS_USER:
1454                                         $text = wfMsg( 'userpage' );
1455                                         break;
1456                                 case NS_PROJECT:
1457                                         $text = wfMsg( 'projectpage' );
1458                                         break;
1459                                 case NS_IMAGE:
1460                                         $text = wfMsg( 'imagepage' );
1461                                         break;
1462                                 case NS_MEDIAWIKI:
1463                                         $text = wfMsg( 'mediawikipage' );
1464                                         break;
1465                                 case NS_TEMPLATE:
1466                                         $text = wfMsg( 'templatepage' );
1467                                         break;
1468                                 case NS_HELP:
1469                                         $text = wfMsg( 'viewhelppage' );
1470                                         break;
1471                                 case NS_CATEGORY:
1472                                         $text = wfMsg( 'categorypage' );
1473                                         break;
1474                                 default:
1475                                         $text = wfMsg( 'articlepage' );
1476                         }
1477                 } else {
1478                         $link = $wgTitle->getTalkPage();
1479                         $text = wfMsg( 'talkpage' );
1480                 }
1481
1482                 $s = $this->makeLinkObj( $link, $text );
1483
1484                 return $s;
1485         }
1486
1487         function commentLink() {
1488                 global $wgTitle, $wgOut;
1489
1490                 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1491                         return '';
1492                 }
1493                 
1494                 # __NEWSECTIONLINK___ changes behaviour here
1495                 # If it's present, the link points to this page, otherwise
1496                 # it points to the talk page
1497                 if( $wgTitle->isTalkPage() ) {
1498                         $title =& $wgTitle;
1499                 } elseif( $wgOut->showNewSectionLink() ) {
1500                         $title =& $wgTitle;
1501                 } else {
1502                         $title =& $wgTitle->getTalkPage();
1503                 }
1504                 
1505                 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1506         }
1507
1508         /* these are used extensively in SkinTemplate, but also some other places */
1509         static function makeMainPageUrl( $urlaction = '' ) {
1510                 $title = Title::newMainPage();
1511                 self::checkTitle( $title, '' );
1512                 return $title->getLocalURL( $urlaction );
1513         }
1514
1515         static function makeSpecialUrl( $name, $urlaction = '' ) {
1516                 $title = SpecialPage::getTitleFor( $name );
1517                 return $title->getLocalURL( $urlaction );
1518         }
1519
1520         static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1521                 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1522                 return $title->getLocalURL( $urlaction );
1523         }
1524
1525         static function makeI18nUrl( $name, $urlaction = '' ) {
1526                 $title = Title::newFromText( wfMsgForContent( $name ) );
1527                 self::checkTitle( $title, $name );
1528                 return $title->getLocalURL( $urlaction );
1529         }
1530
1531         static function makeUrl( $name, $urlaction = '' ) {
1532                 $title = Title::newFromText( $name );
1533                 self::checkTitle( $title, $name );
1534                 return $title->getLocalURL( $urlaction );
1535         }
1536
1537         # If url string starts with http, consider as external URL, else
1538         # internal
1539         static function makeInternalOrExternalUrl( $name ) {
1540                 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1541                         return $name;
1542                 } else {
1543                         return self::makeUrl( $name );
1544                 }
1545         }
1546
1547         # this can be passed the NS number as defined in Language.php
1548         static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1549                 $title = Title::makeTitleSafe( $namespace, $name );
1550                 self::checkTitle( $title, $name );
1551                 return $title->getLocalURL( $urlaction );
1552         }
1553
1554         /* these return an array with the 'href' and boolean 'exists' */
1555         static function makeUrlDetails( $name, $urlaction = '' ) {
1556                 $title = Title::newFromText( $name );
1557                 self::checkTitle( $title, $name );
1558                 return array(
1559                         'href' => $title->getLocalURL( $urlaction ),
1560                         'exists' => $title->getArticleID() != 0 ? true : false
1561                 );
1562         }
1563
1564         /**
1565          * Make URL details where the article exists (or at least it's convenient to think so)
1566          */
1567         static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1568                 $title = Title::newFromText( $name );
1569                 self::checkTitle( $title, $name );
1570                 return array(
1571                         'href' => $title->getLocalURL( $urlaction ),
1572                         'exists' => true
1573                 );
1574         }
1575
1576         # make sure we have some title to operate on
1577         static function checkTitle( &$title, $name ) {
1578                 if( !is_object( $title ) ) {
1579                         $title = Title::newFromText( $name );
1580                         if( !is_object( $title ) ) {
1581                                 $title = Title::newFromText( '--error: link target missing--' );
1582                         }
1583                 }
1584         }
1585
1586         /**
1587          * Build an array that represents the sidebar(s), the navigation bar among them
1588          *
1589          * @return array
1590          * @private
1591          */
1592         function buildSidebar() {
1593                 global $parserMemc, $wgEnableSidebarCache;
1594                 global $wgLang, $wgContLang;
1595
1596                 $fname = 'SkinTemplate::buildSidebar';
1597
1598                 wfProfileIn( $fname );
1599
1600                 $key = wfMemcKey( 'sidebar' );
1601                 $cacheSidebar = $wgEnableSidebarCache &&
1602                         ($wgLang->getCode() == $wgContLang->getCode());
1603                 
1604                 if ($cacheSidebar) {
1605                         $cachedsidebar = $parserMemc->get( $key );
1606                         if ($cachedsidebar!="") {
1607                                 wfProfileOut($fname);
1608                                 return $cachedsidebar;
1609                         }
1610                 }
1611
1612                 $bar = array();
1613                 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1614                 foreach ($lines as $line) {
1615                         if (strpos($line, '*') !== 0)
1616                                 continue;
1617                         if (strpos($line, '**') !== 0) {
1618                                 $line = trim($line, '* ');
1619                                 $heading = $line;
1620                         } else {
1621                                 if (strpos($line, '|') !== false) { // sanity check
1622                                         $line = explode( '|' , trim($line, '* '), 2 );
1623                                         $link = wfMsgForContent( $line[0] );
1624                                         if ($link == '-')
1625                                                 continue;
1626                                         if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1627                                                 $text = $line[1];
1628                                         if (wfEmptyMsg($line[0], $link))
1629                                                 $link = $line[0];
1630
1631                                         if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1632                                                 $href = $link;
1633                                         } else {
1634                                                 $title = Title::newFromText( $link );
1635                                                 if ( $title ) {
1636                                                         $title = $title->fixSpecialName();
1637                                                         $href = $title->getLocalURL();
1638                                                 } else {
1639                                                         $href = 'INVALID-TITLE';
1640                                                 }
1641                                         }
1642
1643                                         $bar[$heading][] = array(
1644                                                 'text' => $text,
1645                                                 'href' => $href,
1646                                                 'id' => 'n-' . strtr($line[1], ' ', '-'),
1647                                                 'active' => false
1648                                         );
1649                                 } else { continue; }
1650                         }
1651                 }
1652                 if ($cacheSidebar)
1653                         $parserMemc->set( $key, $bar, 86400 );
1654                 wfProfileOut( $fname );
1655                 return $bar;
1656         }
1657         
1658 }