Rebuild.
[mediawiki.git] / includes / Skin.php
blob21b60ec20011b69ac7295d8ac870b177ad1bfe16
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
5 # See skin.txt
7 /**
8 * The main skin class that provide methods and properties for all other skins.
9 * This base class is also the "Standard" skin.
11 * See docs/skin.txt for more information.
13 * @addtogroup Skins
15 class Skin extends Linker {
16 /**#@+
17 * @private
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' ;
28 /** Constructor, call parent constructor */
29 function Skin() { parent::__construct(); }
31 /**
32 * Fetch the set of available skins.
33 * @return array of strings
34 * @static
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
44 wfProfileIn( __METHOD__ . '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
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;
57 $skinDir->close();
58 $skinsInitialised = true;
59 wfProfileOut( __METHOD__ . '-init' );
61 return $wgValidSkinNames;
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
72 static function normalizeKey( $key ) {
73 global $wgDefaultSkin;
74 $skinNames = Skin::getSkinNames();
76 if( $key == '' ) {
77 // Don't return the default immediately;
78 // in a misconfiguration we need to fall back.
79 $key = $wgDefaultSkin;
82 if( isset( $skinNames[$key] ) ) {
83 return $key;
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' );
93 if( isset( $fallback[$key] ) ){
94 $key = $fallback[$key];
97 if( isset( $skinNames[$key] ) ) {
98 return $key;
99 } else {
100 // The old built-in skin
101 return 'standard';
106 * Factory method for loading a skin of a given type
107 * @param string $key 'monobook', 'standard', etc
108 * @return Skin
109 * @static
111 static function &newFromKey( $key ) {
112 global $wgStyleDirectory;
114 $key = Skin::normalizeKey( $key );
116 $skinNames = Skin::getSkinNames();
117 $skinName = $skinNames[$key];
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" );
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" );
136 $skin = new $className;
137 return $skin;
140 /** @return string path to the skin stylesheet */
141 function getStylesheet() {
142 return 'common/wikistandard.css';
145 /** @return string skin name */
146 public function getSkinName() {
147 return $this->skinname;
150 function qbSetting() {
151 global $wgOut, $wgUser;
153 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
154 $q = $wgUser->getOption( 'quickbar', 0 );
155 return $q;
158 function initPage( &$out ) {
159 global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
161 $fname = 'Skin::initPage';
162 wfProfileIn( $fname );
164 if( false !== $wgFavicon ) {
165 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
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]})",
176 $this->addMetadataLinks($out);
178 $this->mRevisionId = $out->mRevisionId;
180 $this->preloadExistence();
182 wfProfileOut( $fname );
186 * Preload the existence of three commonly-requested pages in a single query
188 function preloadExistence() {
189 global $wgUser, $wgTitle;
191 // User/talk link
192 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
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();
203 $lb = new LinkBatch( $titles );
204 $lb->execute();
207 function addMetadataLinks( &$out ) {
208 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
209 global $wgRightsPage, $wgRightsUrl;
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') ) );
219 if( $wgEnableDublinCoreRdf ) {
220 $out->addMetadataLink( array(
221 'title' => 'Dublin Core',
222 'type' => 'application/rdf+xml',
223 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
226 $copyright = '';
227 if( $wgRightsPage ) {
228 $copy = Title::newFromText( $wgRightsPage );
229 if( $copy ) {
230 $copyright = $copy->getLocalURL();
233 if( !$copyright && $wgRightsUrl ) {
234 $copyright = $wgRightsUrl;
236 if( $copyright ) {
237 $out->addLink( array(
238 'rel' => 'copyright',
239 'href' => $copyright ) );
243 function outputPage( &$out ) {
244 global $wgDebugComments;
246 wfProfileIn( __METHOD__ );
247 $this->initPage( $out );
249 $out->out( $out->headElement() );
251 $out->out( "\n<body" );
252 $ops = $this->getBodyOptions();
253 foreach ( $ops as $name => $val ) {
254 $out->out( " $name='$val'" );
256 $out->out( ">\n" );
257 if ( $wgDebugComments ) {
258 $out->out( "<!-- Wiki debugging output:\n" .
259 $out->mDebugtext . "-->\n" );
262 $out->out( $this->beforeContent() );
264 $out->out( $out->mBodytext . "\n" );
266 $out->out( $this->afterContent() );
268 $out->out( $this->bottomScripts() );
270 $out->out( $out->reportTime() );
272 $out->out( "\n</body></html>" );
273 wfProfileOut( __METHOD__ );
276 static function makeVariablesScript( $data ) {
277 global $wgJsMimeType;
279 $r = "<script type= \"$wgJsMimeType\">/*<![CDATA[*/\n";
280 foreach ( $data as $name => $value ) {
281 $encValue = Xml::encodeJsVar( $value );
282 $r .= "var $name = $encValue;\n";
284 $r .= "/*]]>*/</script>\n";
286 return $r;
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
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;
302 $ns = $wgTitle->getNamespace();
303 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
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,
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' );
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 );
343 $vars['wgAjaxWatch'] = $msgs;
346 return self::makeVariablesScript( $vars );
349 function getHeadScripts( $allowUserJs ) {
350 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
352 $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
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";
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";
371 return $r;
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.
381 * @param string $action
382 * @return bool
383 * @private
385 function userCanPreview( $action ) {
386 global $wgTitle, $wgRequest, $wgUser;
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' ) );
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";
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";
411 $s .= $this->doGetUserStyles();
412 return $s."\n";
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.
424 * @return string Raw JavaScript to be returned
426 public function getUserJs() {
427 wfProfileIn( __METHOD__ );
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;
438 wfProfileOut( __METHOD__ );
439 return $s;
443 * Return html code that include User stylesheets
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;
455 * Some styles that are set by user through the user settings interface.
457 function doGetUserStyles() {
458 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
460 $s = '';
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";
473 return $s . $this->reallyDoGetUserStyles();
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";
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;
492 a.new:after, #quickbar a.new:after {
493 content: "?";
494 color: #CC2200;
495 text-decoration: $underline;
497 a.stub:after, #quickbar a.stub:after {
498 content: "!";
499 color: #772233;
500 text-decoration: $underline;
502 END;
504 if( $wgUser->getOption( 'justify' ) ) {
505 $s .= "#article, #bodyContent { text-align: justify; }\n";
507 if( !$wgUser->getOption( 'showtoc' ) ) {
508 $s .= "#toc { display: none; }\n";
510 if( !$wgUser->getOption( 'editsection' ) ) {
511 $s .= ".editsection { display: none; }\n";
513 return $s;
516 function getBodyOptions() {
517 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
519 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
521 if ( 0 != $wgTitle->getNamespace() ) {
522 $a = array( 'bgcolor' => '#ffffec' );
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);
532 $a['onload'] = $wgOut->getOnloadHandler();
533 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
534 if( $a['onload'] != '' ) {
535 $a['onload'] .= ';';
537 $a['onload'] .= 'setupRightClickEdit()';
539 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
540 ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
541 return $a;
545 * URL to the logo
547 function getLogo() {
548 global $wgLogo;
549 return $wgLogo;
553 * This will be called immediately after the <body> tag. Split into
554 * two functions to make it easier to subclass.
556 function beforeContent() {
557 return $this->doBeforeContent();
560 function doBeforeContent() {
561 global $wgContLang;
562 $fname = 'Skin::doBeforeContent';
563 wfProfileIn( $fname );
565 $s = '';
566 $qb = $this->qbSetting();
568 if( $langlinks = $this->otherLanguages() ) {
569 $rows = 2;
570 $borderhack = '';
571 } else {
572 $rows = 1;
573 $langlinks = false;
574 $borderhack = 'class="top"';
577 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
578 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
580 $shove = ($qb != 0);
581 $left = ($qb == 1 || $qb == 3);
582 if($wgContLang->isRTL()) $left = !$left;
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 );
590 $l = $wgContLang->isRTL() ? 'right' : 'left';
591 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
593 $s .= $this->topLinks() ;
594 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
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>";
601 if ( $langlinks ) {
602 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
605 if ( $shove && !$left ) { # Right
606 $s .= $this->getQuickbarCompensator( $rows );
608 $s .= "</tr>\n</table>\n</div>\n";
609 $s .= "\n<div id='article'>\n";
611 $notice = wfGetSiteNotice();
612 if( $notice ) {
613 $s .= "\n<div id='siteNotice'>$notice</div>\n";
615 $s .= $this->pageTitle();
616 $s .= $this->pageSubtitle() ;
617 $s .= $this->getCategories();
618 wfProfileOut( $fname );
619 return $s;
623 function getCategoryLinks () {
624 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
625 global $wgContLang;
627 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
629 # Separator
630 $sep = wfMsgHtml( 'catseparator' );
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;
639 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
640 $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
641 . ': ' . $t;
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 />';
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);
660 return $s;
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"
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; ';
678 # add our current element to the list
679 $eltitle = Title::NewFromText($element);
680 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
682 return $return;
685 function getCategories() {
686 $catlinks=$this->getCategoryLinks();
687 if(!empty($catlinks)) {
688 return "<p class='catlinks'>{$catlinks}</p>";
692 function getQuickbarCompensator( $rows = 1 ) {
693 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
697 * This gets called shortly before the \</body\> tag.
698 * @return String HTML to be put before \</body\>
700 function afterContent() {
701 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
702 return $printfooter . $this->doAfterContent();
706 * This gets called shortly before the \</body\> tag.
707 * @return String HTML-wrapped JS code to be put before \</body\>
709 function bottomScripts() {
710 global $wgJsMimeType;
711 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
714 /** @return string Retrievied from HTML text */
715 function printSource() {
716 global $wgTitle;
717 $url = htmlspecialchars( $wgTitle->getFullURL() );
718 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
721 function printFooter() {
722 return "<p>" . $this->printSource() .
723 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
726 /** overloaded by derived classes */
727 function doAfterContent() { }
729 function pageTitleLinks() {
730 global $wgOut, $wgTitle, $wgUser, $wgRequest;
732 $oldid = $wgRequest->getVal( 'oldid' );
733 $diff = $wgRequest->getVal( 'diff' );
734 $action = $wgRequest->getText( 'action' );
736 $s = $this->printableLink();
737 $disclaimer = $this->disclaimerLink(); # may be empty
738 if( $disclaimer ) {
739 $s .= ' | ' . $disclaimer;
741 $privacy = $this->privacyLink(); # may be empty too
742 if( $privacy ) {
743 $s .= ' | ' . $privacy;
746 if ( $wgOut->isArticleRelated() ) {
747 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
748 $name = $wgTitle->getDBkey();
749 $image = wfFindFile( $wgTitle );
750 if( $image ) {
751 $link = htmlspecialchars( $image->getURL() );
752 $style = $this->getInternalLinkAttributes( $link, $name );
753 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
757 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
758 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
759 wfMsg( 'currentrev' ) );
762 if ( $wgUser->getNewtalk() ) {
763 # do not show "You have new messages" text when we are viewing our
764 # own talk page
765 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
766 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
767 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
768 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
769 # disable caching
770 $wgOut->setSquidMaxage(0);
771 $wgOut->enableClientCache(false);
775 $undelete = $this->getUndeleteLink();
776 if( !empty( $undelete ) ) {
777 $s .= ' | '.$undelete;
779 return $s;
782 function getUndeleteLink() {
783 global $wgUser, $wgTitle, $wgContLang, $action;
784 if( $wgUser->isAllowed( 'deletedhistory' ) &&
785 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
786 ($n = $wgTitle->isDeleted() ) )
788 if ( $wgUser->isAllowed( 'delete' ) ) {
789 $msg = 'thisisdeleted';
790 } else {
791 $msg = 'viewdeleted';
793 return wfMsg( $msg,
794 $this->makeKnownLinkObj(
795 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
796 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
798 return '';
801 function printableLink() {
802 global $wgOut, $wgFeedClasses, $wgRequest;
804 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
806 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
807 if( $wgOut->isSyndicated() ) {
808 foreach( $wgFeedClasses as $format => $class ) {
809 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
810 $s .= " | <a href=\"$feedurl\">{$format}</a>";
813 return $s;
816 function pageTitle() {
817 global $wgOut;
818 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
819 return $s;
822 function pageSubtitle() {
823 global $wgOut;
825 $sub = $wgOut->getSubtitle();
826 if ( '' == $sub ) {
827 global $wgExtraSubtitle;
828 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
830 $subpages = $this->subPageSubtitle();
831 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
832 $s = "<p class='subtitle'>{$sub}</p>\n";
833 return $s;
836 function subPageSubtitle() {
837 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
838 $subpages = '';
839 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
840 $ptext=$wgTitle->getPrefixedText();
841 if(preg_match('/\//',$ptext)) {
842 $links = explode('/',$ptext);
843 $c = 0;
844 $growinglink = '';
845 foreach($links as $link) {
846 $c++;
847 if ($c<count($links)) {
848 $growinglink .= $link;
849 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
850 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
851 if ($c>1) {
852 $subpages .= ' | ';
853 } else {
854 $subpages .= '&lt; ';
856 $subpages .= $getlink;
857 $growinglink .= '/';
862 return $subpages;
866 * Returns true if the IP should be shown in the header
868 function showIPinHeader() {
869 global $wgShowIPinHeader;
870 return $wgShowIPinHeader && session_id() != '';
873 function nameAndLogin() {
874 global $wgUser, $wgTitle, $wgLang, $wgContLang;
876 $lo = $wgContLang->specialPage( 'Userlogout' );
878 $s = '';
879 if ( $wgUser->isAnon() ) {
880 if( $this->showIPinHeader() ) {
881 $n = wfGetIP();
883 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
884 $wgLang->getNsText( NS_TALK ) );
886 $s .= $n . ' ('.$tl.')';
887 } else {
888 $s .= wfMsg('notloggedin');
891 $rt = $wgTitle->getPrefixedURL();
892 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
893 $q = '';
894 } else { $q = "returnto={$rt}"; }
896 $s .= "\n<br />" . $this->makeKnownLinkObj(
897 SpecialPage::getTitleFor( 'Userlogin' ),
898 wfMsg( 'login' ), $q );
899 } else {
900 $n = $wgUser->getName();
901 $rt = $wgTitle->getPrefixedURL();
902 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
903 $wgLang->getNsText( NS_TALK ) );
905 $tl = " ({$tl})";
907 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
908 $n ) . "{$tl}<br />" .
909 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
910 "returnto={$rt}" ) . ' | ' .
911 $this->specialLink( 'preferences' );
913 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
914 wfMsg( 'help' ) );
916 return $s;
919 function getSearchLink() {
920 $searchPage = SpecialPage::getTitleFor( 'Search' );
921 return $searchPage->getLocalURL();
924 function escapeSearchLink() {
925 return htmlspecialchars( $this->getSearchLink() );
928 function searchForm() {
929 global $wgRequest;
930 $search = $wgRequest->getText( 'search' );
932 $s = '<form name="search" class="inline" method="post" action="'
933 . $this->escapeSearchLink() . "\">\n"
934 . '<input type="text" name="search" size="19" value="'
935 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
936 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
937 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
939 return $s;
942 function topLinks() {
943 global $wgOut;
944 $sep = " |\n";
946 $s = $this->mainPageLink() . $sep
947 . $this->specialLink( 'recentchanges' );
949 if ( $wgOut->isArticleRelated() ) {
950 $s .= $sep . $this->editThisPage()
951 . $sep . $this->historyLink();
953 # Many people don't like this dropdown box
954 #$s .= $sep . $this->specialPagesList();
956 $s .= $this->variantLinks();
958 $s .= $this->extensionTabLinks();
960 return $s;
964 * Compatibility for extensions adding functionality through tabs.
965 * Eventually these old skins should be replaced with SkinTemplate-based
966 * versions, sigh...
967 * @return string
969 function extensionTabLinks() {
970 $tabs = array();
971 $s = '';
972 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
973 foreach( $tabs as $tab ) {
974 $s .= ' | ' . Xml::element( 'a',
975 array( 'href' => $tab['href'] ),
976 $tab['text'] );
978 return $s;
982 * Language/charset variant links for classic-style skins
983 * @return string
985 function variantLinks() {
986 $s = '';
987 /* show links to different language variants */
988 global $wgDisableLangConversion, $wgContLang, $wgTitle;
989 $variants = $wgContLang->getVariants();
990 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
991 foreach( $variants as $code ) {
992 $varname = $wgContLang->getVariantname( $code );
993 if( $varname == 'disable' )
994 continue;
995 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
998 return $s;
1001 function bottomLinks() {
1002 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1003 $sep = " |\n";
1005 $s = '';
1006 if ( $wgOut->isArticleRelated() ) {
1007 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1008 if ( $wgUser->isLoggedIn() ) {
1009 $s .= $sep . $this->watchThisPage();
1011 $s .= $sep . $this->talkLink()
1012 . $sep . $this->historyLink()
1013 . $sep . $this->whatLinksHere()
1014 . $sep . $this->watchPageLinksLink();
1016 if ($wgUseTrackbacks)
1017 $s .= $sep . $this->trackbackLink();
1019 if ( $wgTitle->getNamespace() == NS_USER
1020 || $wgTitle->getNamespace() == NS_USER_TALK )
1023 $id=User::idFromName($wgTitle->getText());
1024 $ip=User::isIP($wgTitle->getText());
1026 if($id || $ip) { # both anons and non-anons have contri list
1027 $s .= $sep . $this->userContribsLink();
1029 if( $this->showEmailUser( $id ) ) {
1030 $s .= $sep . $this->emailUserLink();
1033 if ( $wgTitle->getArticleId() ) {
1034 $s .= "\n<br />";
1035 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1036 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1037 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1039 $s .= "<br />\n" . $this->otherLanguages();
1041 return $s;
1044 function pageStats() {
1045 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1046 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1048 $oldid = $wgRequest->getVal( 'oldid' );
1049 $diff = $wgRequest->getVal( 'diff' );
1050 if ( ! $wgOut->isArticle() ) { return ''; }
1051 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1052 if ( 0 == $wgArticle->getID() ) { return ''; }
1054 $s = '';
1055 if ( !$wgDisableCounters ) {
1056 $count = $wgLang->formatNum( $wgArticle->getCount() );
1057 if ( $count ) {
1058 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1062 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1063 require_once('Credits.php');
1064 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1065 } else {
1066 $s .= $this->lastModified();
1069 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1070 $dbr = wfGetDB( DB_SLAVE );
1071 $watchlist = $dbr->tableName( 'watchlist' );
1072 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1073 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
1074 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1075 $res = $dbr->query( $sql, 'Skin::pageStats');
1076 $x = $dbr->fetchObject( $res );
1077 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
1080 return $s . ' ' . $this->getCopyright();
1083 function getCopyright( $type = 'detect' ) {
1084 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1086 if ( $type == 'detect' ) {
1087 $oldid = $wgRequest->getVal( 'oldid' );
1088 $diff = $wgRequest->getVal( 'diff' );
1090 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1091 $type = 'history';
1092 } else {
1093 $type = 'normal';
1097 if ( $type == 'history' ) {
1098 $msg = 'history_copyright';
1099 } else {
1100 $msg = 'copyright';
1103 $out = '';
1104 if( $wgRightsPage ) {
1105 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1106 } elseif( $wgRightsUrl ) {
1107 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1108 } else {
1109 # Give up now
1110 return $out;
1112 $out .= wfMsgForContent( $msg, $link );
1113 return $out;
1116 function getCopyrightIcon() {
1117 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1118 $out = '';
1119 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1120 $out = $wgCopyrightIcon;
1121 } else if ( $wgRightsIcon ) {
1122 $icon = htmlspecialchars( $wgRightsIcon );
1123 if ( $wgRightsUrl ) {
1124 $url = htmlspecialchars( $wgRightsUrl );
1125 $out .= '<a href="'.$url.'">';
1127 $text = htmlspecialchars( $wgRightsText );
1128 $out .= "<img src=\"$icon\" alt='$text' />";
1129 if ( $wgRightsUrl ) {
1130 $out .= '</a>';
1133 return $out;
1136 function getPoweredBy() {
1137 global $wgStylePath;
1138 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1139 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1140 return $img;
1143 function lastModified() {
1144 global $wgLang, $wgArticle, $wgLoadBalancer;
1146 $timestamp = $wgArticle->getTimestamp();
1147 if ( $timestamp ) {
1148 $d = $wgLang->date( $timestamp, true );
1149 $t = $wgLang->time( $timestamp, true );
1150 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1151 } else {
1152 $s = '';
1154 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1155 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1157 return $s;
1160 function logoText( $align = '' ) {
1161 if ( '' != $align ) { $a = " align='{$align}'"; }
1162 else { $a = ''; }
1164 $mp = wfMsg( 'mainpage' );
1165 $mptitle = Title::newMainPage();
1166 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1168 $logourl = $this->getLogo();
1169 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1170 return $s;
1174 * show a drop-down box of special pages
1176 function specialPagesList() {
1177 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1178 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1179 foreach ( $pages as $name => $page ) {
1180 $pages[$name] = $page->getDescription();
1183 $go = wfMsg( 'go' );
1184 $sp = wfMsg( 'specialpages' );
1185 $spp = $wgContLang->specialPage( 'Specialpages' );
1187 $s = '<form id="specialpages" method="get" class="inline" ' .
1188 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1189 $s .= "<select name=\"wpDropdown\">\n";
1190 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1193 foreach ( $pages as $name => $desc ) {
1194 $p = $wgContLang->specialPage( $name );
1195 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1197 $s .= "</select>\n";
1198 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1199 $s .= "</form>\n";
1200 return $s;
1203 function mainPageLink() {
1204 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1205 return $s;
1208 function copyrightLink() {
1209 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1210 wfMsg( 'copyrightpagename' ) );
1211 return $s;
1214 private function footerLink ( $desc, $page ) {
1215 // if the link description has been set to "-" in the default language,
1216 if ( wfMsgForContent( $desc ) == '-') {
1217 // then it is disabled, for all languages.
1218 return '';
1219 } else {
1220 // Otherwise, we display the link for the user, described in their
1221 // language (which may or may not be the same as the default language),
1222 // but we make the link target be the one site-wide page.
1223 return $this->makeKnownLink( wfMsgForContent( $page ), wfMsg( $desc ) );
1227 function privacyLink() {
1228 return $this->footerLink( 'privacy', 'privacypage' );
1231 function aboutLink() {
1232 return $this->footerLink( 'aboutsite', 'aboutpage' );
1235 function disclaimerLink() {
1236 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1239 function editThisPage() {
1240 global $wgOut, $wgTitle;
1242 if ( ! $wgOut->isArticleRelated() ) {
1243 $s = wfMsg( 'protectedpage' );
1244 } else {
1245 if ( $wgTitle->userCan( 'edit' ) ) {
1246 $t = wfMsg( 'editthispage' );
1247 } else {
1248 $t = wfMsg( 'viewsource' );
1251 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1253 return $s;
1257 * Return URL options for the 'edit page' link.
1258 * This may include an 'oldid' specifier, if the current page view is such.
1260 * @return string
1261 * @private
1263 function editUrlOptions() {
1264 global $wgArticle;
1266 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1267 return "action=edit&oldid=" . intval( $this->mRevisionId );
1268 } else {
1269 return "action=edit";
1273 function deleteThisPage() {
1274 global $wgUser, $wgTitle, $wgRequest;
1276 $diff = $wgRequest->getVal( 'diff' );
1277 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1278 $t = wfMsg( 'deletethispage' );
1280 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1281 } else {
1282 $s = '';
1284 return $s;
1287 function protectThisPage() {
1288 global $wgUser, $wgTitle, $wgRequest;
1290 $diff = $wgRequest->getVal( 'diff' );
1291 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1292 if ( $wgTitle->isProtected() ) {
1293 $t = wfMsg( 'unprotectthispage' );
1294 $q = 'action=unprotect';
1295 } else {
1296 $t = wfMsg( 'protectthispage' );
1297 $q = 'action=protect';
1299 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1300 } else {
1301 $s = '';
1303 return $s;
1306 function watchThisPage() {
1307 global $wgOut, $wgTitle;
1308 ++$this->mWatchLinkNum;
1310 if ( $wgOut->isArticleRelated() ) {
1311 if ( $wgTitle->userIsWatching() ) {
1312 $t = wfMsg( 'unwatchthispage' );
1313 $q = 'action=unwatch';
1314 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1315 } else {
1316 $t = wfMsg( 'watchthispage' );
1317 $q = 'action=watch';
1318 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1320 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1321 } else {
1322 $s = wfMsg( 'notanarticle' );
1324 return $s;
1327 function moveThisPage() {
1328 global $wgTitle;
1330 if ( $wgTitle->userCan( 'move' ) ) {
1331 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1332 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1333 } else {
1334 // no message if page is protected - would be redundant
1335 return '';
1339 function historyLink() {
1340 global $wgTitle;
1342 return $this->makeKnownLinkObj( $wgTitle,
1343 wfMsg( 'history' ), 'action=history' );
1346 function whatLinksHere() {
1347 global $wgTitle;
1349 return $this->makeKnownLinkObj(
1350 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1351 wfMsg( 'whatlinkshere' ) );
1354 function userContribsLink() {
1355 global $wgTitle;
1357 return $this->makeKnownLinkObj(
1358 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1359 wfMsg( 'contributions' ) );
1362 function showEmailUser( $id ) {
1363 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1364 return $wgEnableEmail &&
1365 $wgEnableUserEmail &&
1366 $wgUser->isLoggedIn() && # show only to signed in users
1367 0 != $id; # we can only email to non-anons ..
1368 # '' != $id->getEmail() && # who must have an email address stored ..
1369 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1370 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1373 function emailUserLink() {
1374 global $wgTitle;
1376 return $this->makeKnownLinkObj(
1377 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1378 wfMsg( 'emailuser' ) );
1381 function watchPageLinksLink() {
1382 global $wgOut, $wgTitle;
1384 if ( ! $wgOut->isArticleRelated() ) {
1385 return '(' . wfMsg( 'notanarticle' ) . ')';
1386 } else {
1387 return $this->makeKnownLinkObj(
1388 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1389 wfMsg( 'recentchangeslinked' ) );
1393 function trackbackLink() {
1394 global $wgTitle;
1396 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1397 . wfMsg('trackbacklink') . "</a>";
1400 function otherLanguages() {
1401 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1403 if ( $wgHideInterlanguageLinks ) {
1404 return '';
1407 $a = $wgOut->getLanguageLinks();
1408 if ( 0 == count( $a ) ) {
1409 return '';
1412 $s = wfMsg( 'otherlanguages' ) . ': ';
1413 $first = true;
1414 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1415 foreach( $a as $l ) {
1416 if ( ! $first ) { $s .= ' | '; }
1417 $first = false;
1419 $nt = Title::newFromText( $l );
1420 $url = $nt->escapeFullURL();
1421 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1423 if ( '' == $text ) { $text = $l; }
1424 $style = $this->getExternalLinkAttributes( $l, $text );
1425 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1427 if($wgContLang->isRTL()) $s .= '</span>';
1428 return $s;
1431 function bugReportsLink() {
1432 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1433 wfMsg( 'bugreports' ) );
1434 return $s;
1437 function talkLink() {
1438 global $wgTitle;
1440 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1441 # No discussion links for special pages
1442 return '';
1445 if( $wgTitle->isTalkPage() ) {
1446 $link = $wgTitle->getSubjectPage();
1447 switch( $link->getNamespace() ) {
1448 case NS_MAIN:
1449 $text = wfMsg( 'articlepage' );
1450 break;
1451 case NS_USER:
1452 $text = wfMsg( 'userpage' );
1453 break;
1454 case NS_PROJECT:
1455 $text = wfMsg( 'projectpage' );
1456 break;
1457 case NS_IMAGE:
1458 $text = wfMsg( 'imagepage' );
1459 break;
1460 case NS_MEDIAWIKI:
1461 $text = wfMsg( 'mediawikipage' );
1462 break;
1463 case NS_TEMPLATE:
1464 $text = wfMsg( 'templatepage' );
1465 break;
1466 case NS_HELP:
1467 $text = wfMsg( 'viewhelppage' );
1468 break;
1469 case NS_CATEGORY:
1470 $text = wfMsg( 'categorypage' );
1471 break;
1472 default:
1473 $text = wfMsg( 'articlepage' );
1475 } else {
1476 $link = $wgTitle->getTalkPage();
1477 $text = wfMsg( 'talkpage' );
1480 $s = $this->makeLinkObj( $link, $text );
1482 return $s;
1485 function commentLink() {
1486 global $wgTitle, $wgOut;
1488 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1489 return '';
1492 # __NEWSECTIONLINK___ changes behaviour here
1493 # If it's present, the link points to this page, otherwise
1494 # it points to the talk page
1495 if( $wgTitle->isTalkPage() ) {
1496 $title =& $wgTitle;
1497 } elseif( $wgOut->showNewSectionLink() ) {
1498 $title =& $wgTitle;
1499 } else {
1500 $title =& $wgTitle->getTalkPage();
1503 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1506 /* these are used extensively in SkinTemplate, but also some other places */
1507 static function makeMainPageUrl( $urlaction = '' ) {
1508 $title = Title::newMainPage();
1509 self::checkTitle( $title, '' );
1510 return $title->getLocalURL( $urlaction );
1513 static function makeSpecialUrl( $name, $urlaction = '' ) {
1514 $title = SpecialPage::getTitleFor( $name );
1515 return $title->getLocalURL( $urlaction );
1518 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1519 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1520 return $title->getLocalURL( $urlaction );
1523 static function makeI18nUrl( $name, $urlaction = '' ) {
1524 $title = Title::newFromText( wfMsgForContent( $name ) );
1525 self::checkTitle( $title, $name );
1526 return $title->getLocalURL( $urlaction );
1529 static function makeUrl( $name, $urlaction = '' ) {
1530 $title = Title::newFromText( $name );
1531 self::checkTitle( $title, $name );
1532 return $title->getLocalURL( $urlaction );
1535 # If url string starts with http, consider as external URL, else
1536 # internal
1537 static function makeInternalOrExternalUrl( $name ) {
1538 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1539 return $name;
1540 } else {
1541 return self::makeUrl( $name );
1545 # this can be passed the NS number as defined in Language.php
1546 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1547 $title = Title::makeTitleSafe( $namespace, $name );
1548 self::checkTitle( $title, $name );
1549 return $title->getLocalURL( $urlaction );
1552 /* these return an array with the 'href' and boolean 'exists' */
1553 static function makeUrlDetails( $name, $urlaction = '' ) {
1554 $title = Title::newFromText( $name );
1555 self::checkTitle( $title, $name );
1556 return array(
1557 'href' => $title->getLocalURL( $urlaction ),
1558 'exists' => $title->getArticleID() != 0 ? true : false
1563 * Make URL details where the article exists (or at least it's convenient to think so)
1565 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1566 $title = Title::newFromText( $name );
1567 self::checkTitle( $title, $name );
1568 return array(
1569 'href' => $title->getLocalURL( $urlaction ),
1570 'exists' => true
1574 # make sure we have some title to operate on
1575 static function checkTitle( &$title, $name ) {
1576 if( !is_object( $title ) ) {
1577 $title = Title::newFromText( $name );
1578 if( !is_object( $title ) ) {
1579 $title = Title::newFromText( '--error: link target missing--' );
1585 * Build an array that represents the sidebar(s), the navigation bar among them
1587 * @return array
1588 * @private
1590 function buildSidebar() {
1591 global $parserMemc, $wgEnableSidebarCache;
1592 global $wgLang, $wgContLang;
1594 $fname = 'SkinTemplate::buildSidebar';
1596 wfProfileIn( $fname );
1598 $key = wfMemcKey( 'sidebar' );
1599 $cacheSidebar = $wgEnableSidebarCache &&
1600 ($wgLang->getCode() == $wgContLang->getCode());
1602 if ($cacheSidebar) {
1603 $cachedsidebar = $parserMemc->get( $key );
1604 if ($cachedsidebar!="") {
1605 wfProfileOut($fname);
1606 return $cachedsidebar;
1610 $bar = array();
1611 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1612 foreach ($lines as $line) {
1613 if (strpos($line, '*') !== 0)
1614 continue;
1615 if (strpos($line, '**') !== 0) {
1616 $line = trim($line, '* ');
1617 $heading = $line;
1618 } else {
1619 if (strpos($line, '|') !== false) { // sanity check
1620 $line = explode( '|' , trim($line, '* '), 2 );
1621 $link = wfMsgForContent( $line[0] );
1622 if ($link == '-')
1623 continue;
1624 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1625 $text = $line[1];
1626 if (wfEmptyMsg($line[0], $link))
1627 $link = $line[0];
1629 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1630 $href = $link;
1631 } else {
1632 $title = Title::newFromText( $link );
1633 if ( $title ) {
1634 $title = $title->fixSpecialName();
1635 $href = $title->getLocalURL();
1636 } else {
1637 $href = 'INVALID-TITLE';
1641 $bar[$heading][] = array(
1642 'text' => $text,
1643 'href' => $href,
1644 'id' => 'n-' . strtr($line[1], ' ', '-'),
1645 'active' => false
1647 } else { continue; }
1650 if ($cacheSidebar)
1651 $parserMemc->set( $key, $bar, 86400 );
1652 wfProfileOut( $fname );
1653 return $bar;