Fixing release notes item.
[mediawiki.git] / includes / Skin.php
blob9296d2431862b411a369efea2dc86b7ed6f385ad
1 <?php
2 /**
3 * @defgroup Skins Skins
4 */
6 if ( ! defined( 'MEDIAWIKI' ) )
7 die( 1 );
9 /**
10 * The main skin class that provide methods and properties for all other skins.
11 * This base class is also the "Standard" skin.
13 * See docs/skin.txt for more information.
15 * @ingroup Skins
17 class Skin extends Linker {
18 /**#@+
19 * @private
21 var $mWatchLinkNum = 0; // Appended to end of watch link id's
22 // How many search boxes have we made? Avoid duplicate id's.
23 protected $searchboxes = '';
24 /**#@-*/
25 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
26 protected $skinname = 'standard' ;
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 * Fetch the list of usable skins in regards to $wgSkipSkins.
66 * Useful for Special:Preferences and other places where you
67 * only want to show skins users _can_ use.
68 * @return array of strings
70 public static function getUsableSkins() {
71 global $wgSkipSkins;
72 $usableSkins = self::getSkinNames();
73 foreach ( $wgSkipSkins as $skip ) {
74 unset( $usableSkins[$skip] );
76 return $usableSkins;
79 /**
80 * Normalize a skin preference value to a form that can be loaded.
81 * If a skin can't be found, it will fall back to the configured
82 * default (or the old 'Classic' skin if that's broken).
83 * @param string $key
84 * @return string
85 * @static
87 static function normalizeKey( $key ) {
88 global $wgDefaultSkin;
89 $skinNames = Skin::getSkinNames();
91 if( $key == '' ) {
92 // Don't return the default immediately;
93 // in a misconfiguration we need to fall back.
94 $key = $wgDefaultSkin;
97 if( isset( $skinNames[$key] ) ) {
98 return $key;
101 // Older versions of the software used a numeric setting
102 // in the user preferences.
103 $fallback = array(
104 0 => $wgDefaultSkin,
105 1 => 'nostalgia',
106 2 => 'cologneblue' );
108 if( isset( $fallback[$key] ) ){
109 $key = $fallback[$key];
112 if( isset( $skinNames[$key] ) ) {
113 return $key;
114 } else {
115 return 'monobook';
120 * Factory method for loading a skin of a given type
121 * @param string $key 'monobook', 'standard', etc
122 * @return Skin
123 * @static
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory;
128 $key = Skin::normalizeKey( $key );
130 $skinNames = Skin::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = 'Skin'.ucfirst($key);
134 # Grab the skin class and initialise it.
135 if ( !class_exists( $className ) ) {
136 // Preload base classes to work around APC/PHP5 bug
137 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
138 if( file_exists( $deps ) ) include_once( $deps );
139 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
141 # Check if we got if not failback to default skin
142 if( !class_exists( $className ) ) {
143 # DO NOT die if the class isn't found. This breaks maintenance
144 # scripts and can cause a user account to be unrecoverable
145 # except by SQL manipulation if a previously valid skin name
146 # is no longer valid.
147 wfDebug( "Skin class does not exist: $className\n" );
148 $className = 'SkinMonobook';
149 require_once( "{$wgStyleDirectory}/MonoBook.php" );
152 $skin = new $className;
153 return $skin;
156 /** @return string path to the skin stylesheet */
157 function getStylesheet() {
158 return 'common/wikistandard.css';
161 /** @return string skin name */
162 public function getSkinName() {
163 return $this->skinname;
166 function qbSetting() {
167 global $wgOut, $wgUser;
169 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
170 $q = $wgUser->getOption( 'quickbar', 0 );
171 return $q;
174 function initPage( OutputPage $out ) {
175 global $wgFavicon, $wgAppleTouchIcon;
177 wfProfileIn( __METHOD__ );
179 if( false !== $wgFavicon ) {
180 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
183 if( false !== $wgAppleTouchIcon ) {
184 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
187 # OpenSearch description link
188 $out->addLink( array(
189 'rel' => 'search',
190 'type' => 'application/opensearchdescription+xml',
191 'href' => wfScript( 'opensearch_desc' ),
192 'title' => wfMsgForContent( 'opensearch-desc' ),
195 $this->addMetadataLinks($out);
197 $this->mRevisionId = $out->mRevisionId;
199 $this->preloadExistence();
201 wfProfileOut( __METHOD__ );
205 * Preload the existence of three commonly-requested pages in a single query
207 function preloadExistence() {
208 global $wgUser, $wgTitle;
210 // User/talk link
211 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
213 // Other tab link
214 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
215 // nothing
216 } elseif ( $wgTitle->isTalkPage() ) {
217 $titles[] = $wgTitle->getSubjectPage();
218 } else {
219 $titles[] = $wgTitle->getTalkPage();
222 $lb = new LinkBatch( $titles );
223 $lb->execute();
226 function addMetadataLinks( OutputPage $out ) {
227 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
228 global $wgRightsPage, $wgRightsUrl;
230 if( $out->isArticleRelated() ) {
231 # note: buggy CC software only reads first "meta" link
232 if( $wgEnableCreativeCommonsRdf ) {
233 $out->addMetadataLink( array(
234 'title' => 'Creative Commons',
235 'type' => 'application/rdf+xml',
236 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
238 if( $wgEnableDublinCoreRdf ) {
239 $out->addMetadataLink( array(
240 'title' => 'Dublin Core',
241 'type' => 'application/rdf+xml',
242 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
245 $copyright = '';
246 if( $wgRightsPage ) {
247 $copy = Title::newFromText( $wgRightsPage );
248 if( $copy ) {
249 $copyright = $copy->getLocalURL();
252 if( !$copyright && $wgRightsUrl ) {
253 $copyright = $wgRightsUrl;
255 if( $copyright ) {
256 $out->addLink( array(
257 'rel' => 'copyright',
258 'href' => $copyright ) );
262 function setMembers(){
263 global $wgTitle, $wgUser;
264 $this->mTitle = $wgTitle;
265 $this->mUser = $wgUser;
266 $this->userpage = $wgUser->getUserPage()->getPrefixedText();
267 $this->usercss = false;
270 function outputPage( OutputPage $out ) {
271 global $wgDebugComments;
272 wfProfileIn( __METHOD__ );
274 $this->setMembers();
275 $this->initPage( $out );
277 // See self::afterContentHook() for documentation
278 $afterContent = $this->afterContentHook();
280 $out->out( $out->headElement( $this ) );
282 $out->out( "\n<body" );
283 $ops = $this->getBodyOptions();
284 foreach ( $ops as $name => $val ) {
285 $out->out( " $name='$val'" );
287 $out->out( ">\n" );
288 if ( $wgDebugComments ) {
289 $out->out( "<!-- Wiki debugging output:\n" .
290 $out->mDebugtext . "-->\n" );
293 $out->out( $this->beforeContent() );
295 $out->out( $out->mBodytext . "\n" );
297 $out->out( $this->afterContent() );
299 $out->out( $afterContent );
301 $out->out( $this->bottomScripts() );
303 $out->out( wfReportTime() );
305 $out->out( "\n</body></html>" );
306 wfProfileOut( __METHOD__ );
309 static function makeVariablesScript( $data ) {
310 global $wgJsMimeType;
312 $r = array( "<script type= \"$wgJsMimeType\">/*<![CDATA[*/" );
313 foreach ( $data as $name => $value ) {
314 $encValue = Xml::encodeJsVar( $value );
315 $r[] = "var $name = $encValue;";
317 $r[] = "/*]]>*/</script>\n";
319 return implode( "\n\t\t", $r );
323 * Make a <script> tag containing global variables
324 * @param array $data Associative array containing one element:
325 * skinname => the skin name
326 * The odd calling convention is for backwards compatibility
328 static function makeGlobalVariablesScript( $data ) {
329 global $wgScript, $wgStylePath, $wgUser;
330 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
331 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
332 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
333 global $wgUseAjax, $wgAjaxWatch;
334 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
335 global $wgRestrictionTypes, $wgLivePreview;
336 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
338 $ns = $wgTitle->getNamespace();
339 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
341 $vars = array(
342 'skin' => $data['skinname'],
343 'stylepath' => $wgStylePath,
344 'wgArticlePath' => $wgArticlePath,
345 'wgScriptPath' => $wgScriptPath,
346 'wgScript' => $wgScript,
347 'wgVariantArticlePath' => $wgVariantArticlePath,
348 'wgActionPaths' => (object)$wgActionPaths,
349 'wgServer' => $wgServer,
350 'wgCanonicalNamespace' => $nsname,
351 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
352 'wgNamespaceNumber' => $wgTitle->getNamespace(),
353 'wgPageName' => $wgTitle->getPrefixedDBKey(),
354 'wgTitle' => $wgTitle->getText(),
355 'wgAction' => $wgRequest->getText( 'action', 'view' ),
356 'wgArticleId' => $wgTitle->getArticleId(),
357 'wgIsArticle' => $wgOut->isArticle(),
358 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
359 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
360 'wgUserLanguage' => $wgLang->getCode(),
361 'wgContentLanguage' => $wgContLang->getCode(),
362 'wgBreakFrames' => $wgBreakFrames,
363 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
364 'wgVersion' => $wgVersion,
365 'wgEnableAPI' => $wgEnableAPI,
366 'wgEnableWriteAPI' => $wgEnableWriteAPI,
369 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false )){
370 $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
371 $vars['wgDBname'] = $wgDBname;
372 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
373 $vars['wgMWSuggestMessages'] = array( wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled'));
376 foreach( $wgRestrictionTypes as $type )
377 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
379 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
380 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
381 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
382 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
383 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
386 if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
387 $msgs = (object)array();
388 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
389 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
391 $vars['wgAjaxWatch'] = $msgs;
394 wfRunHooks('MakeGlobalVariablesScript', array(&$vars));
396 return self::makeVariablesScript( $vars );
399 function getHeadScripts( $allowUserJs ) {
400 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
402 $vars = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
404 $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
405 global $wgUseSiteJs;
406 if ($wgUseSiteJs) {
407 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
408 $r[] = "<script type=\"$wgJsMimeType\" src=\"".
409 htmlspecialchars(self::makeUrl('-',
410 "action=raw$jsCache&gen=js&useskin=" .
411 urlencode( $this->getSkinName() ) ) ) .
412 "\"><!-- site js --></script>";
414 if( $allowUserJs && $wgUser->isLoggedIn() ) {
415 $userpage = $wgUser->getUserPage();
416 $userjs = htmlspecialchars( self::makeUrl(
417 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
418 'action=raw&ctype='.$wgJsMimeType));
419 $r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
421 return $vars . "\t\t" . implode ( "\n\t\t", $r );
425 * To make it harder for someone to slip a user a fake
426 * user-JavaScript or user-CSS preview, a random token
427 * is associated with the login session. If it's not
428 * passed back with the preview request, we won't render
429 * the code.
431 * @param string $action
432 * @return bool
433 * @private
435 function userCanPreview( $action ) {
436 global $wgTitle, $wgRequest, $wgUser;
438 if( $action != 'submit' )
439 return false;
440 if( !$wgRequest->wasPosted() )
441 return false;
442 if( !$wgTitle->userCanEditCssJsSubpage() )
443 return false;
444 return $wgUser->matchEditToken(
445 $wgRequest->getVal( 'wpEditToken' ) );
449 * generated JavaScript action=raw&gen=js
450 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
451 * nated together. For some bizarre reason, it does *not* return any
452 * custom user JS from subpages. Huh?
454 * There's absolutely no reason to have separate Monobook/Common JSes.
455 * Any JS that cares can just check the skin variable generated at the
456 * top. For now Monobook.js will be maintained, but it should be consi-
457 * dered deprecated.
459 * @return string
461 public function generateUserJs() {
462 global $wgStylePath;
464 wfProfileIn( __METHOD__ );
466 $s = "/* generated javascript */\n";
467 $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n";
468 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
469 $s .= "\n\n/* MediaWiki:Common.js */\n";
470 $commonJs = wfMsgForContent('common.js');
471 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
472 $s .= $commonJs;
475 $s .= "\n\n/* MediaWiki:".ucfirst( $this->getSkinName() ).".js */\n";
476 // avoid inclusion of non defined user JavaScript (with custom skins only)
477 // by checking for default message content
478 $msgKey = ucfirst( $this->getSkinName() ).'.js';
479 $userJS = wfMsgForContent($msgKey);
480 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
481 $s .= $userJS;
484 wfProfileOut( __METHOD__ );
485 return $s;
489 * generate user stylesheet for action=raw&gen=css
491 public function generateUserStylesheet() {
492 wfProfileIn( __METHOD__ );
493 $s = "/* generated user stylesheet */\n" .
494 $this->reallyGenerateUserStylesheet();
495 wfProfileOut( __METHOD__ );
496 return $s;
500 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
502 protected function reallyGenerateUserStylesheet(){
503 global $wgUser;
504 $s = '';
505 if (($undopt = $wgUser->getOption("underline")) < 2) {
506 $underline = $undopt ? 'underline' : 'none';
507 $s .= "a { text-decoration: $underline; }\n";
509 if( $wgUser->getOption( 'highlightbroken' ) ) {
510 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
511 } else {
512 $s .= <<<END
513 a.new, #quickbar a.new,
514 a.stub, #quickbar a.stub {
515 color: inherit;
517 a.new:after, #quickbar a.new:after {
518 content: "?";
519 color: #CC2200;
521 a.stub:after, #quickbar a.stub:after {
522 content: "!";
523 color: #772233;
525 END;
527 if( $wgUser->getOption( 'justify' ) ) {
528 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
530 if( !$wgUser->getOption( 'showtoc' ) ) {
531 $s .= "#toc { display: none; }\n";
533 if( !$wgUser->getOption( 'editsection' ) ) {
534 $s .= ".editsection { display: none; }\n";
536 return $s;
540 * @private
542 function setupUserCss( OutputPage $out ) {
543 global $wgRequest, $wgContLang, $wgUser;
544 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
546 wfProfileIn( __METHOD__ );
548 $this->setupSkinUserCss( $out );
550 $siteargs = array(
551 'action' => 'raw',
552 'maxage' => $wgSquidMaxage,
554 if( $wgUser->isLoggedIn() ) {
555 // Ensure that logged-in users' generated CSS isn't clobbered
556 // by anons' publicly cacheable generated CSS.
557 $siteargs['smaxage'] = '0';
558 $siteargs['ts'] = $wgUser->mTouched;
561 // Add any extension CSS
562 foreach( $out->getExtStyle() as $tag ) {
563 $out->addStyle( $tag['href'] );
566 // If we use the site's dynamic CSS, throw that in, too
567 // Per-site custom styles
568 if( $wgUseSiteCss ) {
569 $query = wfArrayToCGI( array(
570 'usemsgcache' => 'yes',
571 'ctype' => 'text/css',
572 'smaxage' => $wgSquidMaxage
573 ) + $siteargs );
574 # Site settings must override extension css! (bug 15025)
575 $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) );
576 $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
579 // Per-user styles based on preferences
580 $siteargs['gen'] = 'css';
581 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
582 $siteargs['useskin'] = $us;
584 $out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
586 // Per-user custom style pages
587 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
588 $action = $wgRequest->getVal('action');
589 # If we're previewing the CSS page, use it
590 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
591 $previewCss = $wgRequest->getText('wpTextbox1');
592 // @FIXME: properly escape the cdata!
593 $this->usercss = "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
594 } else {
595 $out->addStyle( self::makeUrl($this->userpage .'/'.$this->getSkinName() .'.css',
596 'action=raw&ctype=text/css') );
600 wfProfileOut( __METHOD__ );
604 * Add skin specific stylesheets
605 * @param $out OutputPage
607 function setupSkinUserCss( OutputPage $out ) {
608 $out->addStyle( 'common/shared.css' );
609 $out->addStyle( 'common/oldshared.css' );
610 $out->addStyle( $this->getStylesheet() );
611 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
614 function getBodyOptions() {
615 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
617 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
619 if ( 0 != $wgTitle->getNamespace() ) {
620 $a = array( 'bgcolor' => '#ffffec' );
622 else $a = array( 'bgcolor' => '#FFFFFF' );
623 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
624 $wgTitle->quickUserCan( 'edit' ) ) {
625 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
626 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
627 $a += array ('ondblclick' => $s);
630 $a['onload'] = $wgOut->getOnloadHandler();
631 $a['class'] =
632 'mediawiki' .
633 ' '.( $wgContLang->isRTL() ? "rtl" : "ltr" ).
634 ' '.$this->getPageClasses( $wgTitle ) .
635 ' skin-'. Sanitizer::escapeClass( $this->getSkinName( ) );
636 return $a;
639 function getPageClasses( $title ) {
640 $numeric = 'ns-'.$title->getNamespace();
641 if( $title->getNamespace() == NS_SPECIAL ) {
642 $type = "ns-special";
643 } elseif( $title->isTalkPage() ) {
644 $type = "ns-talk";
645 } else {
646 $type = "ns-subject";
648 $name = Sanitizer::escapeClass( 'page-'.$title->getPrefixedText() );
649 return "$numeric $type $name";
653 * URL to the logo
655 function getLogo() {
656 global $wgLogo;
657 return $wgLogo;
661 * This will be called immediately after the <body> tag. Split into
662 * two functions to make it easier to subclass.
664 function beforeContent() {
665 return $this->doBeforeContent();
668 function doBeforeContent() {
669 global $wgContLang;
670 $fname = 'Skin::doBeforeContent';
671 wfProfileIn( $fname );
673 $s = '';
674 $qb = $this->qbSetting();
676 if( $langlinks = $this->otherLanguages() ) {
677 $rows = 2;
678 $borderhack = '';
679 } else {
680 $rows = 1;
681 $langlinks = false;
682 $borderhack = 'class="top"';
685 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
686 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
688 $shove = ( $qb != 0 );
689 $left = ( $qb == 1 || $qb == 3 );
690 if( $wgContLang->isRTL() ) $left = !$left;
692 if( !$shove ) {
693 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
694 $this->logoText() . '</td>';
695 } elseif( $left ) {
696 $s .= $this->getQuickbarCompensator( $rows );
698 $l = $wgContLang->isRTL() ? 'right' : 'left';
699 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
701 $s .= $this->topLinks() ;
702 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
704 $r = $wgContLang->isRTL() ? "left" : "right";
705 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
706 $s .= $this->nameAndLogin();
707 $s .= "\n<br />" . $this->searchForm() . "</td>";
709 if ( $langlinks ) {
710 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
713 if ( $shove && !$left ) { # Right
714 $s .= $this->getQuickbarCompensator( $rows );
716 $s .= "</tr>\n</table>\n</div>\n";
717 $s .= "\n<div id='article'>\n";
719 $notice = wfGetSiteNotice();
720 if( $notice ) {
721 $s .= "\n<div id='siteNotice'>$notice</div>\n";
723 $s .= $this->pageTitle();
724 $s .= $this->pageSubtitle() ;
725 $s .= $this->getCategories();
726 wfProfileOut( $fname );
727 return $s;
731 function getCategoryLinks() {
732 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
733 global $wgContLang, $wgUser;
735 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
737 # Separator
738 $sep = wfMsgHtml( 'catseparator' );
740 // Use Unicode bidi embedding override characters,
741 // to make sure links don't smash each other up in ugly ways.
742 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
743 $embed = "<span dir='$dir'>";
744 $pop = '</span>';
746 $allCats = $wgOut->getCategoryLinks();
747 $s = '';
748 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
749 if ( !empty( $allCats['normal'] ) ) {
750 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
752 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
753 $s .= '<div id="mw-normal-catlinks">' .
754 $this->link( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
755 . $colon . $t . '</div>';
758 # Hidden categories
759 if ( isset( $allCats['hidden'] ) ) {
760 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
761 $class ='mw-hidden-cats-user-shown';
762 } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) {
763 $class = 'mw-hidden-cats-ns-shown';
764 } else {
765 $class = 'mw-hidden-cats-hidden';
767 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
768 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
769 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
770 "</div>";
773 # optional 'dmoz-like' category browser. Will be shown under the list
774 # of categories an article belong to
775 if( $wgUseCategoryBrowser ){
776 $s .= '<br /><hr />';
778 # get a big array of the parents tree
779 $parenttree = $wgTitle->getParentCategoryTree();
780 # Skin object passed by reference cause it can not be
781 # accessed under the method subfunction drawCategoryBrowser
782 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
783 # Clean out bogus first entry and sort them
784 unset($tempout[0]);
785 asort($tempout);
786 # Output one per line
787 $s .= implode("<br />\n", $tempout);
790 return $s;
793 /** Render the array as a serie of links.
794 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
795 * @param &skin Object: skin passed by reference
796 * @return String separated by &gt;, terminate with "\n"
798 function drawCategoryBrowser( $tree, &$skin ){
799 $return = '';
800 foreach ($tree as $element => $parent) {
801 if (empty($parent)) {
802 # element start a new list
803 $return .= "\n";
804 } else {
805 # grab the others elements
806 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
808 # add our current element to the list
809 $eltitle = Title::newFromText($element);
810 $return .= $skin->link( $eltitle, $eltitle->getText() ) ;
812 return $return;
815 function getCategories() {
816 $catlinks=$this->getCategoryLinks();
818 $classes = 'catlinks';
820 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
821 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
822 $classes .= ' catlinks-allhidden';
825 if( !empty( $catlinks ) ){
826 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
830 function getQuickbarCompensator( $rows = 1 ) {
831 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
835 * This runs a hook to allow extensions placing their stuff after content
836 * and article metadata (e.g. categories).
837 * Note: This function has nothing to do with afterContent().
839 * This hook is placed here in order to allow using the same hook for all
840 * skins, both the SkinTemplate based ones and the older ones, which directly
841 * use this class to get their data.
843 * The output of this function gets processed in SkinTemplate::outputPage() for
844 * the SkinTemplate based skins, all other skins should directly echo it.
846 * Returns an empty string by default, if not changed by any hook function.
848 protected function afterContentHook() {
849 $data = "";
851 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
852 // adding just some spaces shouldn't toggle the output
853 // of the whole <div/>, so we use trim() here
854 if( trim( $data ) != '' ){
855 // Doing this here instead of in the skins to
856 // ensure that the div has the same ID in all
857 // skins
858 $data = "<div id='mw-data-after-content'>\n" .
859 "\t$data\n" .
860 "</div>\n";
862 } else {
863 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
866 return $data;
870 * This gets called shortly before the </body> tag.
871 * @return String HTML to be put before </body>
873 function afterContent() {
874 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
875 return $printfooter . $this->doAfterContent();
879 * This gets called shortly before the </body> tag.
880 * @return String HTML-wrapped JS code to be put before </body>
882 function bottomScripts() {
883 global $wgJsMimeType;
884 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
885 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
886 return $bottomScriptText;
889 /** @return string Retrievied from HTML text */
890 function printSource() {
891 global $wgTitle;
892 $url = htmlspecialchars( $wgTitle->getFullURL() );
893 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
896 function printFooter() {
897 return "<p>" . $this->printSource() .
898 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
901 /** overloaded by derived classes */
902 function doAfterContent() { return "</div></div>"; }
904 function pageTitleLinks() {
905 global $wgOut, $wgTitle, $wgUser, $wgRequest;
907 $oldid = $wgRequest->getVal( 'oldid' );
908 $diff = $wgRequest->getVal( 'diff' );
909 $action = $wgRequest->getText( 'action' );
911 $s = $this->printableLink();
912 $disclaimer = $this->disclaimerLink(); # may be empty
913 if( $disclaimer ) {
914 $s .= ' | ' . $disclaimer;
916 $privacy = $this->privacyLink(); # may be empty too
917 if( $privacy ) {
918 $s .= ' | ' . $privacy;
921 if ( $wgOut->isArticleRelated() ) {
922 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
923 $name = $wgTitle->getDBkey();
924 $image = wfFindFile( $wgTitle );
925 if( $image ) {
926 $link = htmlspecialchars( $image->getURL() );
927 $style = $this->getInternalLinkAttributes( $link, $name );
928 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
932 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
933 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
934 wfMsg( 'currentrev' ) );
937 if ( $wgUser->getNewtalk() ) {
938 # do not show "You have new messages" text when we are viewing our
939 # own talk page
940 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
941 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
942 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
943 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
944 # disable caching
945 $wgOut->setSquidMaxage(0);
946 $wgOut->enableClientCache(false);
950 $undelete = $this->getUndeleteLink();
951 if( !empty( $undelete ) ) {
952 $s .= ' | '.$undelete;
954 return $s;
957 function getUndeleteLink() {
958 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
959 if( $wgUser->isAllowed( 'deletedhistory' ) &&
960 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
961 ($n = $wgTitle->isDeleted() ) )
963 if ( $wgUser->isAllowed( 'undelete' ) ) {
964 $msg = 'thisisdeleted';
965 } else {
966 $msg = 'viewdeleted';
968 return wfMsg( $msg,
969 $this->makeKnownLinkObj(
970 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
971 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
973 return '';
976 function printableLink() {
977 global $wgOut, $wgFeedClasses, $wgRequest;
979 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
981 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
982 if( $wgOut->isSyndicated() ) {
983 foreach( $wgFeedClasses as $format => $class ) {
984 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
985 $s .= " | <a href=\"$feedurl\">{$format}</a>";
988 return $s;
991 function pageTitle() {
992 global $wgOut;
993 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
994 return $s;
997 function pageSubtitle() {
998 global $wgOut;
1000 $sub = $wgOut->getSubtitle();
1001 if ( '' == $sub ) {
1002 global $wgExtraSubtitle;
1003 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
1005 $subpages = $this->subPageSubtitle();
1006 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
1007 $s = "<p class='subtitle'>{$sub}</p>\n";
1008 return $s;
1011 function subPageSubtitle() {
1012 $subpages = '';
1013 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
1014 return $subpages;
1016 global $wgOut, $wgTitle;
1017 if($wgOut->isArticle() && MWNamespace::hasSubpages( $wgTitle->getNamespace() )) {
1018 $ptext=$wgTitle->getPrefixedText();
1019 if(preg_match('/\//',$ptext)) {
1020 $links = explode('/',$ptext);
1021 array_pop( $links );
1022 $c = 0;
1023 $growinglink = '';
1024 $display = '';
1025 foreach($links as $link) {
1026 $growinglink .= $link;
1027 $display .= $link;
1028 $linkObj = Title::newFromText( $growinglink );
1029 if( is_object( $linkObj ) && $linkObj->exists() ){
1030 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
1031 $c++;
1032 if ($c>1) {
1033 $subpages .= ' | ';
1034 } else {
1035 $subpages .= '&lt; ';
1037 $subpages .= $getlink;
1038 $display = '';
1039 } else {
1040 $display .= '/';
1042 $growinglink .= '/';
1046 return $subpages;
1050 * Returns true if the IP should be shown in the header
1052 function showIPinHeader() {
1053 global $wgShowIPinHeader;
1054 return $wgShowIPinHeader && session_id() != '';
1057 function nameAndLogin() {
1058 global $wgUser, $wgTitle, $wgLang, $wgContLang;
1060 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1062 $ret = '';
1063 if ( $wgUser->isAnon() ) {
1064 if( $this->showIPinHeader() ) {
1065 $name = wfGetIP();
1067 $talkLink = $this->link( $wgUser->getTalkPage(),
1068 $wgLang->getNsText( NS_TALK ) );
1070 $ret .= "$name ($talkLink)";
1071 } else {
1072 $ret .= wfMsg( 'notloggedin' );
1075 $returnTo = $wgTitle->getPrefixedDBkey();
1076 $query = array();
1077 if ( $logoutPage != $returnTo ) {
1078 $query['returnto'] = $returnTo;
1081 $loginlink = $wgUser->isAllowed( 'createaccount' )
1082 ? 'nav-login-createaccount'
1083 : 'login';
1084 $ret .= "\n<br />" . $this->link(
1085 SpecialPage::getTitleFor( 'Userlogin' ),
1086 wfMsg( $loginlink ), array(), $query
1088 } else {
1089 $returnTo = $wgTitle->getPrefixedDBkey();
1090 $talkLink = $this->link( $wgUser->getTalkPage(),
1091 $wgLang->getNsText( NS_TALK ) );
1093 $ret .= $this->link( $wgUser->getUserPage(),
1094 htmlspecialchars( $wgUser->getName() ) );
1095 $ret .= " ($talkLink)<br />";
1096 $ret .= $this->link(
1097 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1098 array(), array( 'returnto' => $returnTo )
1100 $ret .= ' | ' . $this->specialLink( 'preferences' );
1102 $ret .= ' | ' . $this->link(
1103 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1104 wfMsg( 'help' )
1107 return $ret;
1110 function getSearchLink() {
1111 $searchPage = SpecialPage::getTitleFor( 'Search' );
1112 return $searchPage->getLocalURL();
1115 function escapeSearchLink() {
1116 return htmlspecialchars( $this->getSearchLink() );
1119 function searchForm() {
1120 global $wgRequest;
1121 $search = $wgRequest->getText( 'search' );
1123 $s = '<form id="searchform'.$this->searchboxes.'" name="search" class="inline" method="post" action="'
1124 . $this->escapeSearchLink() . "\">\n"
1125 . '<input type="text" id="searchInput'.$this->searchboxes.'" name="search" size="19" value="'
1126 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
1127 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
1128 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
1130 // Ensure unique id's for search boxes made after the first
1131 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1133 return $s;
1136 function topLinks() {
1137 global $wgOut;
1138 $sep = " |\n";
1140 $s = $this->mainPageLink() . $sep
1141 . $this->specialLink( 'recentchanges' );
1143 if ( $wgOut->isArticleRelated() ) {
1144 $s .= $sep . $this->editThisPage()
1145 . $sep . $this->historyLink();
1147 # Many people don't like this dropdown box
1148 #$s .= $sep . $this->specialPagesList();
1150 $s .= $this->variantLinks();
1152 $s .= $this->extensionTabLinks();
1154 return $s;
1158 * Compatibility for extensions adding functionality through tabs.
1159 * Eventually these old skins should be replaced with SkinTemplate-based
1160 * versions, sigh...
1161 * @return string
1163 function extensionTabLinks() {
1164 $tabs = array();
1165 $s = '';
1166 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1167 foreach( $tabs as $tab ) {
1168 $s .= ' | ' . Xml::element( 'a',
1169 array( 'href' => $tab['href'] ),
1170 $tab['text'] );
1172 return $s;
1176 * Language/charset variant links for classic-style skins
1177 * @return string
1179 function variantLinks() {
1180 $s = '';
1181 /* show links to different language variants */
1182 global $wgDisableLangConversion, $wgContLang, $wgTitle;
1183 $variants = $wgContLang->getVariants();
1184 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1185 foreach( $variants as $code ) {
1186 $varname = $wgContLang->getVariantname( $code );
1187 if( $varname == 'disable' )
1188 continue;
1189 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1192 return $s;
1195 function bottomLinks() {
1196 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1197 $sep = " |\n";
1199 $s = '';
1200 if ( $wgOut->isArticleRelated() ) {
1201 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1202 if ( $wgUser->isLoggedIn() ) {
1203 $s .= $sep . $this->watchThisPage();
1205 $s .= $sep . $this->talkLink()
1206 . $sep . $this->historyLink()
1207 . $sep . $this->whatLinksHere()
1208 . $sep . $this->watchPageLinksLink();
1210 if ($wgUseTrackbacks)
1211 $s .= $sep . $this->trackbackLink();
1213 if ( $wgTitle->getNamespace() == NS_USER
1214 || $wgTitle->getNamespace() == NS_USER_TALK )
1217 $id=User::idFromName($wgTitle->getText());
1218 $ip=User::isIP($wgTitle->getText());
1220 if($id || $ip) { # both anons and non-anons have contri list
1221 $s .= $sep . $this->userContribsLink();
1223 if( $this->showEmailUser( $id ) ) {
1224 $s .= $sep . $this->emailUserLink();
1227 if ( $wgTitle->getArticleId() ) {
1228 $s .= "\n<br />";
1229 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1230 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1231 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1233 $s .= "<br />\n" . $this->otherLanguages();
1235 return $s;
1238 function pageStats() {
1239 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1240 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1242 $oldid = $wgRequest->getVal( 'oldid' );
1243 $diff = $wgRequest->getVal( 'diff' );
1244 if ( ! $wgOut->isArticle() ) { return ''; }
1245 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1246 if ( 0 == $wgArticle->getID() ) { return ''; }
1248 $s = '';
1249 if ( !$wgDisableCounters ) {
1250 $count = $wgLang->formatNum( $wgArticle->getCount() );
1251 if ( $count ) {
1252 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1256 if( $wgMaxCredits != 0 ){
1257 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1258 } else {
1259 $s .= $this->lastModified();
1262 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1263 $dbr = wfGetDB( DB_SLAVE );
1264 $watchlist = $dbr->tableName( 'watchlist' );
1265 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1266 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1267 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1268 $res = $dbr->query( $sql, 'Skin::pageStats');
1269 $x = $dbr->fetchObject( $res );
1271 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1272 array( 'parseinline' ), $wgLang->formatNum($x->n)
1276 return $s . ' ' . $this->getCopyright();
1279 function getCopyright( $type = 'detect' ) {
1280 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1282 if ( $type == 'detect' ) {
1283 $oldid = $wgRequest->getVal( 'oldid' );
1284 $diff = $wgRequest->getVal( 'diff' );
1286 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1287 $type = 'history';
1288 } else {
1289 $type = 'normal';
1293 if ( $type == 'history' ) {
1294 $msg = 'history_copyright';
1295 } else {
1296 $msg = 'copyright';
1299 $out = '';
1300 if( $wgRightsPage ) {
1301 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1302 } elseif( $wgRightsUrl ) {
1303 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1304 } else {
1305 # Give up now
1306 return $out;
1308 $out .= wfMsgForContent( $msg, $link );
1309 return $out;
1312 function getCopyrightIcon() {
1313 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1314 $out = '';
1315 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1316 $out = $wgCopyrightIcon;
1317 } else if ( $wgRightsIcon ) {
1318 $icon = htmlspecialchars( $wgRightsIcon );
1319 if ( $wgRightsUrl ) {
1320 $url = htmlspecialchars( $wgRightsUrl );
1321 $out .= '<a href="'.$url.'">';
1323 $text = htmlspecialchars( $wgRightsText );
1324 $out .= "<img src=\"$icon\" alt='$text' />";
1325 if ( $wgRightsUrl ) {
1326 $out .= '</a>';
1329 return $out;
1332 function getPoweredBy() {
1333 global $wgStylePath;
1334 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1335 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1336 return $img;
1339 function lastModified() {
1340 global $wgLang, $wgArticle;
1341 if( $this->mRevisionId ) {
1342 $timestamp = Revision::getTimestampFromId( $this->mRevisionId, $wgArticle->getId() );
1343 } else {
1344 $timestamp = $wgArticle->getTimestamp();
1346 if ( $timestamp ) {
1347 $d = $wgLang->date( $timestamp, true );
1348 $t = $wgLang->time( $timestamp, true );
1349 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1350 } else {
1351 $s = '';
1353 if ( wfGetLB()->getLaggedSlaveMode() ) {
1354 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1356 return $s;
1359 function logoText( $align = '' ) {
1360 if ( '' != $align ) { $a = " align='{$align}'"; }
1361 else { $a = ''; }
1363 $mp = wfMsg( 'mainpage' );
1364 $mptitle = Title::newMainPage();
1365 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1367 $logourl = $this->getLogo();
1368 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1369 return $s;
1373 * show a drop-down box of special pages
1375 function specialPagesList() {
1376 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1377 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1378 foreach ( $pages as $name => $page ) {
1379 $pages[$name] = $page->getDescription();
1382 $go = wfMsg( 'go' );
1383 $sp = wfMsg( 'specialpages' );
1384 $spp = $wgContLang->specialPage( 'Specialpages' );
1386 $s = '<form id="specialpages" method="get" class="inline" ' .
1387 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1388 $s .= "<select name=\"wpDropdown\">\n";
1389 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1392 foreach ( $pages as $name => $desc ) {
1393 $p = $wgContLang->specialPage( $name );
1394 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1396 $s .= "</select>\n";
1397 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1398 $s .= "</form>\n";
1399 return $s;
1402 function mainPageLink() {
1403 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1404 return $s;
1407 function copyrightLink() {
1408 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1409 wfMsg( 'copyrightpagename' ) );
1410 return $s;
1413 private function footerLink ( $desc, $page ) {
1414 // if the link description has been set to "-" in the default language,
1415 if ( wfMsgForContent( $desc ) == '-') {
1416 // then it is disabled, for all languages.
1417 return '';
1418 } else {
1419 // Otherwise, we display the link for the user, described in their
1420 // language (which may or may not be the same as the default language),
1421 // but we make the link target be the one site-wide page.
1422 return $this->makeKnownLink( wfMsgForContent( $page ),
1423 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1427 function privacyLink() {
1428 return $this->footerLink( 'privacy', 'privacypage' );
1431 function aboutLink() {
1432 return $this->footerLink( 'aboutsite', 'aboutpage' );
1435 function disclaimerLink() {
1436 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1439 function editThisPage() {
1440 global $wgOut, $wgTitle;
1442 if ( !$wgOut->isArticleRelated() ) {
1443 $s = wfMsg( 'protectedpage' );
1444 } else {
1445 if( $wgTitle->quickUserCan( 'edit' ) && $wgTitle->exists() ) {
1446 $t = wfMsg( 'editthispage' );
1447 } elseif( $wgTitle->quickUserCan( 'create' ) && !$wgTitle->exists() ) {
1448 $t = wfMsg( 'create-this-page' );
1449 } else {
1450 $t = wfMsg( 'viewsource' );
1453 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1455 return $s;
1459 * Return URL options for the 'edit page' link.
1460 * This may include an 'oldid' specifier, if the current page view is such.
1462 * @return string
1463 * @private
1465 function editUrlOptions() {
1466 global $wgArticle;
1468 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1469 return "action=edit&oldid=" . intval( $this->mRevisionId );
1470 } else {
1471 return "action=edit";
1475 function deleteThisPage() {
1476 global $wgUser, $wgTitle, $wgRequest;
1478 $diff = $wgRequest->getVal( 'diff' );
1479 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1480 $t = wfMsg( 'deletethispage' );
1482 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1483 } else {
1484 $s = '';
1486 return $s;
1489 function protectThisPage() {
1490 global $wgUser, $wgTitle, $wgRequest;
1492 $diff = $wgRequest->getVal( 'diff' );
1493 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1494 if ( $wgTitle->isProtected() ) {
1495 $t = wfMsg( 'unprotectthispage' );
1496 $q = 'action=unprotect';
1497 } else {
1498 $t = wfMsg( 'protectthispage' );
1499 $q = 'action=protect';
1501 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1502 } else {
1503 $s = '';
1505 return $s;
1508 function watchThisPage() {
1509 global $wgOut, $wgTitle;
1510 ++$this->mWatchLinkNum;
1512 if ( $wgOut->isArticleRelated() ) {
1513 if ( $wgTitle->userIsWatching() ) {
1514 $t = wfMsg( 'unwatchthispage' );
1515 $q = 'action=unwatch';
1516 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1517 } else {
1518 $t = wfMsg( 'watchthispage' );
1519 $q = 'action=watch';
1520 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1522 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1523 } else {
1524 $s = wfMsg( 'notanarticle' );
1526 return $s;
1529 function moveThisPage() {
1530 global $wgTitle;
1532 if ( $wgTitle->quickUserCan( 'move' ) ) {
1533 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1534 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1535 } else {
1536 // no message if page is protected - would be redundant
1537 return '';
1541 function historyLink() {
1542 global $wgTitle;
1544 return $this->makeKnownLinkObj( $wgTitle,
1545 wfMsg( 'history' ), 'action=history' );
1548 function whatLinksHere() {
1549 global $wgTitle;
1551 return $this->makeKnownLinkObj(
1552 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1553 wfMsg( 'whatlinkshere' ) );
1556 function userContribsLink() {
1557 global $wgTitle;
1559 return $this->makeKnownLinkObj(
1560 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1561 wfMsg( 'contributions' ) );
1564 function showEmailUser( $id ) {
1565 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1566 return $wgEnableEmail &&
1567 $wgEnableUserEmail &&
1568 $wgUser->isLoggedIn() && # show only to signed in users
1569 0 != $id; # we can only email to non-anons ..
1570 # '' != $id->getEmail() && # who must have an email address stored ..
1571 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1572 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1575 function emailUserLink() {
1576 global $wgTitle;
1578 return $this->makeKnownLinkObj(
1579 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1580 wfMsg( 'emailuser' ) );
1583 function watchPageLinksLink() {
1584 global $wgOut, $wgTitle;
1586 if ( ! $wgOut->isArticleRelated() ) {
1587 return '(' . wfMsg( 'notanarticle' ) . ')';
1588 } else {
1589 return $this->makeKnownLinkObj(
1590 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1591 wfMsg( 'recentchangeslinked' ) );
1595 function trackbackLink() {
1596 global $wgTitle;
1598 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1599 . wfMsg('trackbacklink') . "</a>";
1602 function otherLanguages() {
1603 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1605 if ( $wgHideInterlanguageLinks ) {
1606 return '';
1609 $a = $wgOut->getLanguageLinks();
1610 if ( 0 == count( $a ) ) {
1611 return '';
1614 $s = wfMsg( 'otherlanguages' ) . ': ';
1615 $first = true;
1616 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1617 foreach( $a as $l ) {
1618 if ( ! $first ) { $s .= ' | '; }
1619 $first = false;
1621 $nt = Title::newFromText( $l );
1622 $url = $nt->escapeFullURL();
1623 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1625 if ( '' == $text ) { $text = $l; }
1626 $style = $this->getExternalLinkAttributes( $l, $text );
1627 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1629 if($wgContLang->isRTL()) $s .= '</span>';
1630 return $s;
1633 function bugReportsLink() {
1634 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1635 wfMsg( 'bugreports' ) );
1636 return $s;
1639 function talkLink() {
1640 global $wgTitle;
1642 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1643 # No discussion links for special pages
1644 return '';
1647 $linkOptions = array();
1649 if( $wgTitle->isTalkPage() ) {
1650 $link = $wgTitle->getSubjectPage();
1651 switch( $link->getNamespace() ) {
1652 case NS_MAIN:
1653 $text = wfMsg( 'articlepage' );
1654 break;
1655 case NS_USER:
1656 $text = wfMsg( 'userpage' );
1657 break;
1658 case NS_PROJECT:
1659 $text = wfMsg( 'projectpage' );
1660 break;
1661 case NS_IMAGE:
1662 $text = wfMsg( 'imagepage' );
1663 # Make link known if image exists, even if the desc. page doesn't.
1664 if( wfFindFile( $link ) )
1665 $linkOptions[] = 'known';
1666 break;
1667 case NS_MEDIAWIKI:
1668 $text = wfMsg( 'mediawikipage' );
1669 break;
1670 case NS_TEMPLATE:
1671 $text = wfMsg( 'templatepage' );
1672 break;
1673 case NS_HELP:
1674 $text = wfMsg( 'viewhelppage' );
1675 break;
1676 case NS_CATEGORY:
1677 $text = wfMsg( 'categorypage' );
1678 break;
1679 default:
1680 $text = wfMsg( 'articlepage' );
1682 } else {
1683 $link = $wgTitle->getTalkPage();
1684 $text = wfMsg( 'talkpage' );
1687 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1689 return $s;
1692 function commentLink() {
1693 global $wgTitle, $wgOut;
1695 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1696 return '';
1699 # __NEWSECTIONLINK___ changes behaviour here
1700 # If it's present, the link points to this page, otherwise
1701 # it points to the talk page
1702 if( $wgTitle->isTalkPage() ) {
1703 $title = $wgTitle;
1704 } elseif( $wgOut->showNewSectionLink() ) {
1705 $title = $wgTitle;
1706 } else {
1707 $title = $wgTitle->getTalkPage();
1710 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1713 /* these are used extensively in SkinTemplate, but also some other places */
1714 static function makeMainPageUrl( $urlaction = '' ) {
1715 $title = Title::newMainPage();
1716 self::checkTitle( $title, '' );
1717 return $title->getLocalURL( $urlaction );
1720 static function makeSpecialUrl( $name, $urlaction = '' ) {
1721 $title = SpecialPage::getTitleFor( $name );
1722 return $title->getLocalURL( $urlaction );
1725 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1726 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1727 return $title->getLocalURL( $urlaction );
1730 static function makeI18nUrl( $name, $urlaction = '' ) {
1731 $title = Title::newFromText( wfMsgForContent( $name ) );
1732 self::checkTitle( $title, $name );
1733 return $title->getLocalURL( $urlaction );
1736 static function makeUrl( $name, $urlaction = '' ) {
1737 $title = Title::newFromText( $name );
1738 self::checkTitle( $title, $name );
1739 return $title->getLocalURL( $urlaction );
1742 # If url string starts with http, consider as external URL, else
1743 # internal
1744 static function makeInternalOrExternalUrl( $name ) {
1745 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1746 return $name;
1747 } else {
1748 return self::makeUrl( $name );
1752 # this can be passed the NS number as defined in Language.php
1753 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1754 $title = Title::makeTitleSafe( $namespace, $name );
1755 self::checkTitle( $title, $name );
1756 return $title->getLocalURL( $urlaction );
1759 /* these return an array with the 'href' and boolean 'exists' */
1760 static function makeUrlDetails( $name, $urlaction = '' ) {
1761 $title = Title::newFromText( $name );
1762 self::checkTitle( $title, $name );
1763 return array(
1764 'href' => $title->getLocalURL( $urlaction ),
1765 'exists' => $title->getArticleID() != 0 ? true : false
1770 * Make URL details where the article exists (or at least it's convenient to think so)
1772 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1773 $title = Title::newFromText( $name );
1774 self::checkTitle( $title, $name );
1775 return array(
1776 'href' => $title->getLocalURL( $urlaction ),
1777 'exists' => true
1781 # make sure we have some title to operate on
1782 static function checkTitle( &$title, $name ) {
1783 if( !is_object( $title ) ) {
1784 $title = Title::newFromText( $name );
1785 if( !is_object( $title ) ) {
1786 $title = Title::newFromText( '--error: link target missing--' );
1792 * Build an array that represents the sidebar(s), the navigation bar among them
1794 * @return array
1796 function buildSidebar() {
1797 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1798 global $wgLang;
1799 wfProfileIn( __METHOD__ );
1801 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1803 if ( $wgEnableSidebarCache ) {
1804 $cachedsidebar = $parserMemc->get( $key );
1805 if ( $cachedsidebar ) {
1806 wfProfileOut( __METHOD__ );
1807 return $cachedsidebar;
1811 $bar = array();
1812 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1813 $heading = '';
1814 foreach ($lines as $line) {
1815 if (strpos($line, '*') !== 0)
1816 continue;
1817 if (strpos($line, '**') !== 0) {
1818 $line = trim($line, '* ');
1819 $heading = $line;
1820 if( !array_key_exists($heading, $bar) ) $bar[$heading] = array();
1821 } else {
1822 if (strpos($line, '|') !== false) { // sanity check
1823 $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
1824 $link = wfMsgForContent( $line[0] );
1825 if ($link == '-')
1826 continue;
1827 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1828 $text = $line[1];
1829 if (wfEmptyMsg($line[0], $link))
1830 $link = $line[0];
1832 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1833 $href = $link;
1834 } else {
1835 $title = Title::newFromText( $link );
1836 if ( $title ) {
1837 $title = $title->fixSpecialName();
1838 $href = $title->getLocalURL();
1839 } else {
1840 $href = 'INVALID-TITLE';
1844 $bar[$heading][] = array(
1845 'text' => $text,
1846 'href' => $href,
1847 'id' => 'n-' . strtr($line[1], ' ', '-'),
1848 'active' => false
1850 } else { continue; }
1853 wfRunHooks('SkinBuildSidebar', array($this, &$bar));
1854 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1855 wfProfileOut( __METHOD__ );
1856 return $bar;