60fe1cae04879f911ea412a067943474d00a6294
3 * @defgroup Skins Skins
6 if ( ! defined( 'MEDIAWIKI' ) )
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.
17 class Skin
extends Linker
{
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 = '';
25 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
26 protected $skinname = 'standard';
27 // @fixme Should be protected :-\
30 /** Constructor, call parent constructor */
31 function Skin() { parent
::__construct(); }
34 * Fetch the set of available skins.
35 * @return array of strings
38 static function getSkinNames() {
39 global $wgValidSkinNames;
40 static $skinsInitialised = false;
41 if ( !$skinsInitialised ) {
42 # Get a list of available skins
43 # Build using the regular expression '^(.*).php$'
44 # Array keys are all lower case, array value keep the case used by filename
46 wfProfileIn( __METHOD__
. '-init' );
47 global $wgStyleDirectory;
48 $skinDir = dir( $wgStyleDirectory );
50 # while code from www.php.net
51 while( false !== ( $file = $skinDir->read() ) ) {
52 // Skip non-PHP files, hidden files, and '.dep' includes
54 if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
56 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
60 $skinsInitialised = true;
61 wfProfileOut( __METHOD__
. '-init' );
63 return $wgValidSkinNames;
67 * Fetch the list of usable skins in regards to $wgSkipSkins.
68 * Useful for Special:Preferences and other places where you
69 * only want to show skins users _can_ use.
70 * @return array of strings
72 public static function getUsableSkins() {
74 $usableSkins = self
::getSkinNames();
75 foreach ( $wgSkipSkins as $skip ) {
76 unset( $usableSkins[$skip] );
82 * Normalize a skin preference value to a form that can be loaded.
83 * If a skin can't be found, it will fall back to the configured
84 * default (or the old 'Classic' skin if that's broken).
89 static function normalizeKey( $key ) {
90 global $wgDefaultSkin;
91 $skinNames = Skin
::getSkinNames();
94 // Don't return the default immediately;
95 // in a misconfiguration we need to fall back.
96 $key = $wgDefaultSkin;
99 if( isset( $skinNames[$key] ) ) {
103 // Older versions of the software used a numeric setting
104 // in the user preferences.
108 2 => 'cologneblue' );
110 if( isset( $fallback[$key] ) ){
111 $key = $fallback[$key];
114 if( isset( $skinNames[$key] ) ) {
122 * Factory method for loading a skin of a given type
123 * @param string $key 'monobook', 'standard', etc
127 static function &newFromKey( $key ) {
128 global $wgStyleDirectory;
130 $key = Skin
::normalizeKey( $key );
132 $skinNames = Skin
::getSkinNames();
133 $skinName = $skinNames[$key];
134 $className = 'Skin'.ucfirst($key);
136 # Grab the skin class and initialise it.
137 if ( !class_exists( $className ) ) {
138 // Preload base classes to work around APC/PHP5 bug
139 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
140 if( file_exists( $deps ) ) include_once( $deps );
141 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
143 # Check if we got if not failback to default skin
144 if( !class_exists( $className ) ) {
145 # DO NOT die if the class isn't found. This breaks maintenance
146 # scripts and can cause a user account to be unrecoverable
147 # except by SQL manipulation if a previously valid skin name
148 # is no longer valid.
149 wfDebug( "Skin class does not exist: $className\n" );
150 $className = 'SkinMonobook';
151 require_once( "{$wgStyleDirectory}/MonoBook.php" );
154 $skin = new $className;
158 /** @return string path to the skin stylesheet */
159 function getStylesheet() {
160 return 'common/wikistandard.css';
163 /** @return string skin name */
164 public function getSkinName() {
165 return $this->skinname
;
168 function qbSetting() {
169 global $wgOut, $wgUser;
171 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
172 $q = $wgUser->getOption( 'quickbar', 0 );
176 function initPage( OutputPage
$out ) {
177 global $wgFavicon, $wgAppleTouchIcon;
179 wfProfileIn( __METHOD__
);
181 # Generally the order of the favicon and apple-touch-icon links
182 # should not matter, but Konqueror (3.5.9 at least) incorrectly
183 # uses whichever one appears later in the HTML source. Make sure
184 # apple-touch-icon is specified first to avoid this.
185 if( false !== $wgAppleTouchIcon ) {
186 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
189 if( false !== $wgFavicon ) {
190 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
193 # OpenSearch description link
194 $out->addLink( array(
196 'type' => 'application/opensearchdescription+xml',
197 'href' => wfScript( 'opensearch_desc' ),
198 'title' => wfMsgForContent( 'opensearch-desc' ),
201 $this->addMetadataLinks( $out );
203 $this->mRevisionId
= $out->mRevisionId
;
205 $this->preloadExistence();
207 wfProfileOut( __METHOD__
);
211 * Preload the existence of three commonly-requested pages in a single query
213 function preloadExistence() {
217 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
220 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
222 } elseif ( $this->mTitle
->isTalkPage() ) {
223 $titles[] = $this->mTitle
->getSubjectPage();
225 $titles[] = $this->mTitle
->getTalkPage();
228 $lb = new LinkBatch( $titles );
232 function addMetadataLinks( OutputPage
$out ) {
233 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
234 global $wgRightsPage, $wgRightsUrl;
236 if( $out->isArticleRelated() ) {
237 # note: buggy CC software only reads first "meta" link
238 if( $wgEnableCreativeCommonsRdf ) {
239 $out->addMetadataLink( array(
240 'title' => 'Creative Commons',
241 'type' => 'application/rdf+xml',
242 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
245 if( $wgEnableDublinCoreRdf ) {
246 $out->addMetadataLink( array(
247 'title' => 'Dublin Core',
248 'type' => 'application/rdf+xml',
249 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
254 if( $wgRightsPage ) {
255 $copy = Title
::newFromText( $wgRightsPage );
257 $copyright = $copy->getLocalURL();
260 if( !$copyright && $wgRightsUrl ) {
261 $copyright = $wgRightsUrl;
264 $out->addLink( array(
265 'rel' => 'copyright',
266 'href' => $copyright )
272 * Set some local variables
274 protected function setMembers(){
276 $this->mUser
= $wgUser;
277 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
278 $this->usercss
= false;
283 * @param Title $t The title to use
285 public function setTitle( $t ) {
290 public function getTitle() {
291 return $this->mTitle
;
294 function outputPage( OutputPage
$out ) {
295 global $wgDebugComments;
296 wfProfileIn( __METHOD__
);
299 $this->initPage( $out );
301 // See self::afterContentHook() for documentation
302 $afterContent = $this->afterContentHook();
304 $out->out( $out->headElement( $this ) );
306 $out->out( "\n<body" );
307 $ops = $this->getBodyOptions();
308 foreach ( $ops as $name => $val ) {
309 $out->out( " $name='$val'" );
312 if ( $wgDebugComments ) {
313 $out->out( "<!-- Wiki debugging output:\n" .
314 $out->mDebugtext
. "-->\n" );
317 $out->out( $this->beforeContent() );
319 $out->out( $out->mBodytext
. "\n" );
321 $out->out( $this->afterContent() );
323 $out->out( $afterContent );
325 $out->out( $this->bottomScripts() );
327 $out->out( wfReportTime() );
329 $out->out( "\n</body></html>" );
330 wfProfileOut( __METHOD__
);
333 static function makeVariablesScript( $data ) {
336 foreach ( $data as $name => $value ) {
337 $encValue = Xml
::encodeJsVar( $value );
338 $r[] = "$name=$encValue";
340 $js = 'var ' . implode( ",\n", $r ) . ';';
341 return Html
::inlineScript( "\n$js\n" );
348 * Make a <script> tag containing global variables
349 * @param $skinName string Name of the skin
350 * The odd calling convention is for backwards compatibility
351 * @TODO @FIXME Make this not depend on $wgTitle!
353 static function makeGlobalVariablesScript( $skinName ) {
354 if ( is_array( $skinName ) ) {
355 # Weird back-compat stuff.
356 $skinName = $skinName['skinname'];
358 global $wgScript, $wgTitle, $wgStylePath, $wgUser;
359 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
360 global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
361 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
362 global $wgUseAjax, $wgAjaxWatch;
363 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
364 global $wgRestrictionTypes, $wgLivePreview;
365 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
367 $ns = $wgTitle->getNamespace();
368 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ?
$wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
369 $separatorTransTable = $wgContLang->separatorTransformTable();
370 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
371 $compactSeparatorTransTable = array(
372 implode( "\t", array_keys( $separatorTransTable ) ),
373 implode( "\t", $separatorTransTable ),
375 $digitTransTable = $wgContLang->digitTransformTable();
376 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
377 $compactDigitTransTable = array(
378 implode( "\t", array_keys( $digitTransTable ) ),
379 implode( "\t", $digitTransTable ),
382 $mainPage = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
385 'stylepath' => $wgStylePath,
386 'wgArticlePath' => $wgArticlePath,
387 'wgScriptPath' => $wgScriptPath,
388 'wgScript' => $wgScript,
389 'wgVariantArticlePath' => $wgVariantArticlePath,
390 'wgActionPaths' => (object)$wgActionPaths,
391 'wgServer' => $wgServer,
392 'wgCanonicalNamespace' => $nsname,
393 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBkey() ),
394 'wgNamespaceNumber' => $wgTitle->getNamespace(),
395 'wgPageName' => $wgTitle->getPrefixedDBKey(),
396 'wgTitle' => $wgTitle->getText(),
397 'wgAction' => $wgRequest->getText( 'action', 'view' ),
398 'wgArticleId' => $wgTitle->getArticleId(),
399 'wgIsArticle' => $wgOut->isArticle(),
400 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
401 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
402 'wgUserLanguage' => $wgLang->getCode(),
403 'wgContentLanguage' => $wgContLang->getCode(),
404 'wgBreakFrames' => $wgBreakFrames,
405 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
406 'wgVersion' => $wgVersion,
407 'wgEnableAPI' => $wgEnableAPI,
408 'wgEnableWriteAPI' => $wgEnableWriteAPI,
409 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
410 'wgDigitTransformTable' => $compactDigitTransTable,
411 'wgMainPageTitle' => $mainPage ?
$mainPage->getPrefixedText() : null,
412 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
413 'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
415 if ( $wgContLang->hasVariants() ) {
416 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
419 //if on upload page output the extension list & js_upload
420 if( SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) == "Upload" ) {
421 global $wgFileExtensions, $wgAjaxUploadInterface;
422 $vars['wgFileExtensions'] = $wgFileExtensions;
423 $vars['wgAjaxUploadInterface'] = $wgAjaxUploadInterface;
426 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
427 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
428 $vars['wgDBname'] = $wgDBname;
429 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
430 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
433 foreach( $wgRestrictionTypes as $type )
434 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
436 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
437 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
438 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
439 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
440 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
443 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
444 $msgs = (object)array();
445 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
446 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
448 $vars['wgAjaxWatch'] = $msgs;
451 // Allow extensions to add their custom variables to the global JS variables
452 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
454 return self
::makeVariablesScript( $vars );
457 * Return a random selection of the scripts we want in the header,
458 * according to no particular rhyme or reason. Various other scripts are
459 * returned from a haphazard assortment of other functions scattered over
460 * various files. This entire hackish system needs to be burned to the
461 * ground and rebuilt.
463 * @param $out OutputPage object, should be $wgOut
465 * @return string Raw HTML to output to <head>
467 function getHeadScripts( OutputPage
$out ) {
468 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion, $wgOut;
471 $vars = self
::makeGlobalVariablesScript( $this->getSkinName() );
474 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
475 $wgOut->addScriptFile( self
::makeUrl( '-',
476 "action=raw$jsCache&gen=js&useskin=" .
477 urlencode( $this->getSkinName() )
481 if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
482 $userpage = $wgUser->getUserPage();
483 $userjs = self
::makeUrl(
484 $userpage->getPrefixedText() . '/' . $this->getSkinName() . '.js',
485 'action=raw&ctype=' . $wgJsMimeType );
486 $wgOut->addScriptFile( $userjs );
488 return $vars . "\n" . $out->mScripts
;
492 * To make it harder for someone to slip a user a fake
493 * user-JavaScript or user-CSS preview, a random token
494 * is associated with the login session. If it's not
495 * passed back with the preview request, we won't render
498 * @param string $action
502 function userCanPreview( $action ) {
503 global $wgRequest, $wgUser;
505 if( $action != 'submit' )
507 if( !$wgRequest->wasPosted() )
509 if( !$this->mTitle
->userCanEditCssSubpage() )
511 if( !$this->mTitle
->userCanEditJsSubpage() )
513 return $wgUser->matchEditToken(
514 $wgRequest->getVal( 'wpEditToken' ) );
518 * generated JavaScript action=raw&gen=js
519 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
520 * nated together. For some bizarre reason, it does *not* return any
521 * custom user JS from subpages. Huh?
523 * There's absolutely no reason to have separate Monobook/Common JSes.
524 * Any JS that cares can just check the skin variable generated at the
525 * top. For now Monobook.js will be maintained, but it should be consi-
528 * @param $force_skin string If set, overrides the skin name
532 public function generateUserJs( $skinName = null ) {
535 wfProfileIn( __METHOD__
);
537 $skinName = $this->getSkinName();
540 $s = "/* generated javascript */\n";
541 $s .= "var skin = '" . Xml
::escapeJsString($skinName ) . "';\n";
542 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
543 $s .= "\n\n/* MediaWiki:Common.js */\n";
544 $commonJs = wfMsgForContent( 'common.js' );
545 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
549 $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n";
550 // avoid inclusion of non defined user JavaScript (with custom skins only)
551 // by checking for default message content
552 $msgKey = ucfirst( $skinName ) . '.js';
553 $userJS = wfMsgForContent( $msgKey );
554 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
558 wfProfileOut( __METHOD__
);
563 * Generate user stylesheet for action=raw&gen=css
565 public function generateUserStylesheet() {
566 wfProfileIn( __METHOD__
);
567 $s = "/* generated user stylesheet */\n" .
568 $this->reallyGenerateUserStylesheet();
569 wfProfileOut( __METHOD__
);
574 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
576 protected function reallyGenerateUserStylesheet(){
579 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
580 $underline = $undopt ?
'underline' : 'none';
581 $s .= "a { text-decoration: $underline; }\n";
583 if( $wgUser->getOption( 'highlightbroken' ) ) {
584 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
587 a.new, #quickbar a.new,
588 a.stub, #quickbar a.stub {
591 a.new:after, #quickbar a.new:after {
595 a.stub:after, #quickbar a.stub:after {
601 if( $wgUser->getOption( 'justify' ) ) {
602 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
604 if( !$wgUser->getOption( 'showtoc' ) ) {
605 $s .= "#toc { display: none; }\n";
607 if( !$wgUser->getOption( 'editsection' ) ) {
608 $s .= ".editsection { display: none; }\n";
610 $fontstyle = $wgUser->getOption( 'editfont' );
611 if ( $fontstyle !== 'default' ) {
612 $s .= "textarea { font-family: $fontstyle; }\n";
620 function setupUserCss( OutputPage
$out ) {
621 global $wgRequest, $wgContLang, $wgUser;
622 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
624 wfProfileIn( __METHOD__
);
626 $this->setupSkinUserCss( $out );
630 'maxage' => $wgSquidMaxage,
633 // Add any extension CSS
634 foreach ( $out->getExtStyle() as $url ) {
635 $out->addStyle( $url );
638 // If we use the site's dynamic CSS, throw that in, too
639 // Per-site custom styles
640 if( $wgUseSiteCss ) {
641 global $wgHandheldStyle;
642 $query = wfArrayToCGI( array(
643 'usemsgcache' => 'yes',
644 'ctype' => 'text/css',
645 'smaxage' => $wgSquidMaxage
647 # Site settings must override extension css! (bug 15025)
648 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
649 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
650 if( $wgHandheldStyle ) {
651 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
653 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
656 if( $wgUser->isLoggedIn() ) {
657 // Ensure that logged-in users' generated CSS isn't clobbered
658 // by anons' publicly cacheable generated CSS.
659 $siteargs['smaxage'] = '0';
660 $siteargs['ts'] = $wgUser->mTouched
;
662 // Per-user styles based on preferences
663 $siteargs['gen'] = 'css';
664 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
665 $siteargs['useskin'] = $us;
667 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
669 // Per-user custom style pages
670 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
671 $action = $wgRequest->getVal( 'action' );
672 # If we're previewing the CSS page, use it
673 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
674 $previewCss = $wgRequest->getText( 'wpTextbox1' );
675 // @FIXME: properly escape the cdata!
676 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
678 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
679 'action=raw&ctype=text/css' ) );
683 wfProfileOut( __METHOD__
);
687 * Add skin specific stylesheets
688 * @param $out OutputPage
690 function setupSkinUserCss( OutputPage
$out ) {
691 $out->addStyle( 'common/shared.css' );
692 $out->addStyle( 'common/oldshared.css' );
693 $out->addStyle( $this->getStylesheet() );
694 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
697 function getBodyOptions() {
698 global $wgUser, $wgOut, $wgRequest, $wgContLang;
700 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
702 if ( 0 != $this->mTitle
->getNamespace() ) {
703 $a = array( 'bgcolor' => '#ffffec' );
705 else $a = array( 'bgcolor' => '#FFFFFF' );
706 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
707 $this->mTitle
->quickUserCan( 'edit' ) ) {
708 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
709 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
710 $a +
= array( 'ondblclick' => $s );
712 $a['onload'] = $wgOut->getOnloadHandler();
715 ' '.( $wgContLang->getDir() ).
716 ' '.$this->getPageClasses( $this->mTitle
) .
717 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
721 function getPageClasses( $title ) {
722 $numeric = 'ns-'.$title->getNamespace();
723 if( $title->getNamespace() == NS_SPECIAL
) {
724 $type = 'ns-special';
725 } elseif( $title->isTalkPage() ) {
728 $type = 'ns-subject';
730 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
731 return "$numeric $type $name";
743 * This will be called immediately after the <body> tag. Split into
744 * two functions to make it easier to subclass.
746 function beforeContent() {
747 return $this->doBeforeContent();
750 function doBeforeContent() {
752 wfProfileIn( __METHOD__
);
755 $qb = $this->qbSetting();
757 if( $langlinks = $this->otherLanguages() ) {
763 $borderhack = 'class="top"';
766 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
767 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
769 $shove = ( $qb != 0 );
770 $left = ( $qb == 1 ||
$qb == 3 );
771 if( $wgContLang->isRTL() ) $left = !$left;
774 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
775 $this->logoText() . '</td>';
777 $s .= $this->getQuickbarCompensator( $rows );
779 $l = $wgContLang->alignStart();
780 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
782 $s .= $this->topLinks();
783 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
785 $r = $wgContLang->alignEnd();
786 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
787 $s .= $this->nameAndLogin();
788 $s .= "\n<br />" . $this->searchForm() . "</td>";
791 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
794 if ( $shove && !$left ) { # Right
795 $s .= $this->getQuickbarCompensator( $rows );
797 $s .= "</tr>\n</table>\n</div>\n";
798 $s .= "\n<div id='article'>\n";
800 $notice = wfGetSiteNotice();
802 $s .= "\n<div id='siteNotice'>$notice</div>\n";
804 $s .= $this->pageTitle();
805 $s .= $this->pageSubtitle();
806 $s .= $this->getCategories();
807 wfProfileOut( __METHOD__
);
812 function getCategoryLinks() {
813 global $wgOut, $wgUseCategoryBrowser;
814 global $wgContLang, $wgUser;
816 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
819 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
821 // Use Unicode bidi embedding override characters,
822 // to make sure links don't smash each other up in ugly ways.
823 $dir = $wgContLang->getDir();
824 $embed = "<span dir='$dir'>";
827 $allCats = $wgOut->getCategoryLinks();
829 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
830 if ( !empty( $allCats['normal'] ) ) {
831 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
833 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
834 $s .= '<div id="mw-normal-catlinks">' .
835 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
836 . $colon . $t . '</div>';
840 if ( isset( $allCats['hidden'] ) ) {
841 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
842 $class ='mw-hidden-cats-user-shown';
843 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
844 $class = 'mw-hidden-cats-ns-shown';
846 $class = 'mw-hidden-cats-hidden';
848 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
849 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
850 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
854 # optional 'dmoz-like' category browser. Will be shown under the list
855 # of categories an article belong to
856 if( $wgUseCategoryBrowser ){
857 $s .= '<br /><hr />';
859 # get a big array of the parents tree
860 $parenttree = $this->mTitle
->getParentCategoryTree();
861 # Skin object passed by reference cause it can not be
862 # accessed under the method subfunction drawCategoryBrowser
863 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
864 # Clean out bogus first entry and sort them
865 unset( $tempout[0] );
867 # Output one per line
868 $s .= implode( "<br />\n", $tempout );
875 * Render the array as a serie of links.
876 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
877 * @param &skin Object: skin passed by reference
878 * @return String separated by >, terminate with "\n"
880 function drawCategoryBrowser( $tree, &$skin ){
882 foreach( $tree as $element => $parent ) {
883 if( empty( $parent ) ) {
884 # element start a new list
887 # grab the others elements
888 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
890 # add our current element to the list
891 $eltitle = Title
::newFromText( $element );
892 $return .= $skin->link( $eltitle, $eltitle->getText() );
897 function getCategories() {
898 $catlinks = $this->getCategoryLinks();
900 $classes = 'catlinks';
902 // Check what we're showing
903 global $wgOut, $wgUser;
904 $allCats = $wgOut->getCategoryLinks();
905 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
906 $this->mTitle
->getNamespace() == NS_CATEGORY
;
908 if( empty($allCats['normal']) && !( !empty($allCats['hidden']) && $showHidden ) ) {
909 $classes .= ' catlinks-allhidden';
912 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
915 function getQuickbarCompensator( $rows = 1 ) {
916 return "<td width='152' rowspan='{$rows}'> </td>";
920 * This runs a hook to allow extensions placing their stuff after content
921 * and article metadata (e.g. categories).
922 * Note: This function has nothing to do with afterContent().
924 * This hook is placed here in order to allow using the same hook for all
925 * skins, both the SkinTemplate based ones and the older ones, which directly
926 * use this class to get their data.
928 * The output of this function gets processed in SkinTemplate::outputPage() for
929 * the SkinTemplate based skins, all other skins should directly echo it.
931 * Returns an empty string by default, if not changed by any hook function.
933 protected function afterContentHook() {
936 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
937 // adding just some spaces shouldn't toggle the output
938 // of the whole <div/>, so we use trim() here
939 if( trim( $data ) != '' ){
940 // Doing this here instead of in the skins to
941 // ensure that the div has the same ID in all
943 $data = "<div id='mw-data-after-content'>\n" .
948 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
955 * Generate debug data HTML for displaying at the bottom of the main content
957 * @return String HTML containing debug data, if enabled (otherwise empty).
959 protected function generateDebugHTML() {
960 global $wgShowDebug, $wgOut;
961 if ( $wgShowDebug ) {
962 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
963 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
964 $listInternals . "</ul>\n";
969 private function formatDebugHTML( $debugText ) {
970 $lines = explode( "\n", $debugText );
973 foreach( $lines as $line ) {
975 $display = ltrim( $line );
976 $ident = strlen( $line ) - strlen( $display );
977 $diff = $ident - $curIdent;
979 if ( $display == '' )
980 $display = "\xc2\xa0";
982 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
985 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
987 $display = htmlspecialchars( $display );
991 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
992 elseif ( $diff == 0 )
993 $ret .= "</li><li>\n";
995 $ret .= str_repeat( "<ul><li>\n", $diff );
996 $ret .= $display . "\n";
1000 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
1005 * This gets called shortly before the </body> tag.
1006 * @return String HTML to be put before </body>
1008 function afterContent() {
1009 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
1010 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
1014 * This gets called shortly before the </body> tag.
1015 * @return String HTML-wrapped JS code to be put before </body>
1017 function bottomScripts() {
1018 $bottomScriptText = "\n" . Html
::inlineScript( 'if (window.runOnloadHook) runOnloadHook();' ) . "\n";
1019 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
1020 return $bottomScriptText;
1023 /** @return string Retrievied from HTML text */
1024 function printSource() {
1025 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
1026 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
1029 function printFooter() {
1030 return "<p>" . $this->printSource() .
1031 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1034 /** overloaded by derived classes */
1035 function doAfterContent() { return '</div></div>'; }
1037 function pageTitleLinks() {
1038 global $wgOut, $wgUser, $wgRequest, $wgLang;
1040 $oldid = $wgRequest->getVal( 'oldid' );
1041 $diff = $wgRequest->getVal( 'diff' );
1042 $action = $wgRequest->getText( 'action' );
1044 $s[] = $this->printableLink();
1045 $disclaimer = $this->disclaimerLink(); # may be empty
1049 $privacy = $this->privacyLink(); # may be empty too
1054 if ( $wgOut->isArticleRelated() ) {
1055 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1056 $name = $this->mTitle
->getDBkey();
1057 $image = wfFindFile( $this->mTitle
);
1059 $link = htmlspecialchars( $image->getURL() );
1060 $style = $this->getInternalLinkAttributes( $link, $name );
1061 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1065 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1066 $s[] .= $this->link(
1068 wfMsg( 'currentrev' ),
1071 array( 'known', 'noclasses' )
1075 if ( $wgUser->getNewtalk() ) {
1076 # do not show "You have new messages" text when we are viewing our
1078 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1080 $wgUser->getTalkPage(),
1081 wfMsgHtml( 'newmessageslink' ),
1083 array( 'redirect' => 'no' ),
1084 array( 'known', 'noclasses' )
1088 $wgUser->getTalkPage(),
1089 wfMsgHtml( 'newmessagesdifflink' ),
1091 array( 'diff' => 'cur' ),
1092 array( 'known', 'noclasses' )
1094 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1096 $wgOut->setSquidMaxage( 0 );
1097 $wgOut->enableClientCache( false );
1101 $undelete = $this->getUndeleteLink();
1102 if( !empty( $undelete ) ) {
1105 return $wgLang->pipeList( $s );
1108 function getUndeleteLink() {
1109 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1111 $action = $wgRequest->getVal( 'action', 'view' );
1113 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1114 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1115 $n = $this->mTitle
->isDeleted();
1117 if ( $wgUser->isAllowed( 'undelete' ) ) {
1118 $msg = 'thisisdeleted';
1120 $msg = 'viewdeleted';
1125 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1126 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1129 array( 'known', 'noclasses' )
1137 function printableLink() {
1138 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1142 if ( !$wgOut->isPrintable() ) {
1143 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1144 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1147 if( $wgOut->isSyndicated() ) {
1148 foreach( $wgFeedClasses as $format => $class ) {
1149 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1150 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1151 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1154 return $wgLang->pipeList( $s );
1157 function pageTitle() {
1159 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1163 function pageSubtitle() {
1166 $sub = $wgOut->getSubtitle();
1168 global $wgExtraSubtitle;
1169 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1171 $subpages = $this->subPageSubtitle();
1172 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1173 $s = "<p class='subtitle'>{$sub}</p>\n";
1177 function subPageSubtitle() {
1179 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1183 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1184 $ptext = $this->mTitle
->getPrefixedText();
1185 if( preg_match( '/\//', $ptext ) ) {
1186 $links = explode( '/', $ptext );
1187 array_pop( $links );
1191 foreach( $links as $link ) {
1192 $growinglink .= $link;
1194 $linkObj = Title
::newFromText( $growinglink );
1195 if( is_object( $linkObj ) && $linkObj->exists() ){
1196 $getlink = $this->link(
1198 htmlspecialchars( $display ),
1201 array( 'known', 'noclasses' )
1205 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1207 $subpages .= '< ';
1209 $subpages .= $getlink;
1214 $growinglink .= '/';
1222 * Returns true if the IP should be shown in the header
1224 function showIPinHeader() {
1225 global $wgShowIPinHeader;
1226 return $wgShowIPinHeader && session_id() != '';
1229 function nameAndLogin() {
1230 global $wgUser, $wgLang, $wgContLang;
1232 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1235 if ( $wgUser->isAnon() ) {
1236 if( $this->showIPinHeader() ) {
1239 $talkLink = $this->link( $wgUser->getTalkPage(),
1240 $wgLang->getNsText( NS_TALK
) );
1242 $ret .= "$name ($talkLink)";
1244 $ret .= wfMsg( 'notloggedin' );
1247 $returnTo = $this->mTitle
->getPrefixedDBkey();
1249 if ( $logoutPage != $returnTo ) {
1250 $query['returnto'] = $returnTo;
1253 $loginlink = $wgUser->isAllowed( 'createaccount' )
1254 ?
'nav-login-createaccount'
1256 $ret .= "\n<br />" . $this->link(
1257 SpecialPage
::getTitleFor( 'Userlogin' ),
1258 wfMsg( $loginlink ), array(), $query
1261 $returnTo = $this->mTitle
->getPrefixedDBkey();
1262 $talkLink = $this->link( $wgUser->getTalkPage(),
1263 $wgLang->getNsText( NS_TALK
) );
1265 $ret .= $this->link( $wgUser->getUserPage(),
1266 htmlspecialchars( $wgUser->getName() ) );
1267 $ret .= " ($talkLink)<br />";
1268 $ret .= $wgLang->pipeList( array(
1270 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1271 array(), array( 'returnto' => $returnTo )
1273 $this->specialLink( 'preferences' ),
1276 $ret = $wgLang->pipeList( array(
1279 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1287 function getSearchLink() {
1288 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1289 return $searchPage->getLocalURL();
1292 function escapeSearchLink() {
1293 return htmlspecialchars( $this->getSearchLink() );
1296 function searchForm() {
1297 global $wgRequest, $wgUseTwoButtonsSearchForm;
1298 $search = $wgRequest->getText( 'search' );
1300 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1301 . $this->escapeSearchLink() . "\">\n"
1302 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1303 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1304 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1306 if( $wgUseTwoButtonsSearchForm )
1307 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1309 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1313 // Ensure unique id's for search boxes made after the first
1314 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1319 function topLinks() {
1323 $this->mainPageLink(),
1324 $this->specialLink( 'recentchanges' )
1327 if ( $wgOut->isArticleRelated() ) {
1328 $s[] = $this->editThisPage();
1329 $s[] = $this->historyLink();
1331 # Many people don't like this dropdown box
1332 #$s[] = $this->specialPagesList();
1334 if( $this->variantLinks() ) {
1335 $s[] = $this->variantLinks();
1338 if( $this->extensionTabLinks() ) {
1339 $s[] = $this->extensionTabLinks();
1342 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1343 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1347 * Compatibility for extensions adding functionality through tabs.
1348 * Eventually these old skins should be replaced with SkinTemplate-based
1352 function extensionTabLinks() {
1356 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1357 foreach( $tabs as $tab ) {
1358 $s[] = Xml
::element( 'a',
1359 array( 'href' => $tab['href'] ),
1366 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1367 $out .= $wgLang->pipeList( $s );
1374 * Language/charset variant links for classic-style skins
1377 function variantLinks() {
1379 /* show links to different language variants */
1380 global $wgDisableLangConversion, $wgLang, $wgContLang;
1381 $variants = $wgContLang->getVariants();
1382 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1383 foreach( $variants as $code ) {
1384 $varname = $wgContLang->getVariantname( $code );
1385 if( $varname == 'disable' )
1387 $s = $wgLang->pipeList( array(
1389 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1396 function bottomLinks() {
1397 global $wgOut, $wgUser, $wgUseTrackbacks;
1398 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1401 if ( $wgOut->isArticleRelated() ) {
1402 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1403 if ( $wgUser->isLoggedIn() ) {
1404 $element[] = $this->watchThisPage();
1406 $element[] = $this->talkLink();
1407 $element[] = $this->historyLink();
1408 $element[] = $this->whatLinksHere();
1409 $element[] = $this->watchPageLinksLink();
1411 if( $wgUseTrackbacks )
1412 $element[] = $this->trackbackLink();
1414 if ( $this->mTitle
->getNamespace() == NS_USER
1415 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1416 $id = User
::idFromName( $this->mTitle
->getText() );
1417 $ip = User
::isIP( $this->mTitle
->getText() );
1419 if( $id ||
$ip ) { # both anons and non-anons have contri list
1420 $element[] = $this->userContribsLink();
1422 if( $this->showEmailUser( $id ) ) {
1423 $element[] = $this->emailUserLink();
1427 $s = implode( $element, $sep );
1429 if ( $this->mTitle
->getArticleId() ) {
1431 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1432 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1433 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1435 $s .= "<br />\n" . $this->otherLanguages();
1441 function pageStats() {
1442 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1443 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1445 $oldid = $wgRequest->getVal( 'oldid' );
1446 $diff = $wgRequest->getVal( 'diff' );
1447 if ( ! $wgOut->isArticle() ) { return ''; }
1448 if( !$wgArticle instanceOf Article
) { return ''; }
1449 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1450 if ( 0 == $wgArticle->getID() ) { return ''; }
1453 if ( !$wgDisableCounters ) {
1454 $count = $wgLang->formatNum( $wgArticle->getCount() );
1456 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1460 if( $wgMaxCredits != 0 ){
1461 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1463 $s .= $this->lastModified();
1466 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1467 $dbr = wfGetDB( DB_SLAVE
);
1468 $res = $dbr->select( 'watchlist',
1469 array( 'COUNT(*) AS n' ),
1470 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1473 $x = $dbr->fetchObject( $res );
1475 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1476 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1480 return $s . ' ' . $this->getCopyright();
1483 function getCopyright( $type = 'detect' ) {
1484 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1486 if ( $type == 'detect' ) {
1487 $diff = $wgRequest->getVal( 'diff' );
1488 $isCur = $wgArticle && $wgArticle->isCurrent();
1489 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1496 if ( $type == 'history' ) {
1497 $msg = 'history_copyright';
1503 if( $wgRightsPage ) {
1504 $title = Title
::newFromText( $wgRightsPage );
1505 $link = $this->linkKnown( $title, $wgRightsText );
1506 } elseif( $wgRightsUrl ) {
1507 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1508 } elseif( $wgRightsText ) {
1509 $link = $wgRightsText;
1514 // Allow for site and per-namespace customization of copyright notice.
1515 if( isset($wgArticle) )
1516 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1518 $out .= wfMsgForContent( $msg, $link );
1522 function getCopyrightIcon() {
1523 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1525 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1526 $out = $wgCopyrightIcon;
1527 } else if ( $wgRightsIcon ) {
1528 $icon = htmlspecialchars( $wgRightsIcon );
1529 if ( $wgRightsUrl ) {
1530 $url = htmlspecialchars( $wgRightsUrl );
1531 $out .= '<a href="'.$url.'">';
1533 $text = htmlspecialchars( $wgRightsText );
1534 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1535 if ( $wgRightsUrl ) {
1542 function getPoweredBy() {
1543 global $wgStylePath;
1544 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1545 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1549 function lastModified() {
1550 global $wgLang, $wgArticle;
1551 if( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest()) {
1552 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1554 $timestamp = $wgArticle->getTimestamp();
1557 $d = $wgLang->date( $timestamp, true );
1558 $t = $wgLang->time( $timestamp, true );
1559 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1563 if ( wfGetLB()->getLaggedSlaveMode() ) {
1564 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1569 function logoText( $align = '' ) {
1570 if ( '' != $align ) {
1571 $a = " align='{$align}'";
1576 $mp = wfMsg( 'mainpage' );
1577 $mptitle = Title
::newMainPage();
1578 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1580 $logourl = $this->getLogo();
1581 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1586 * show a drop-down box of special pages
1588 function specialPagesList() {
1589 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1590 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1591 foreach ( $pages as $name => $page ) {
1592 $pages[$name] = $page->getDescription();
1595 $go = wfMsg( 'go' );
1596 $sp = wfMsg( 'specialpages' );
1597 $spp = $wgContLang->specialPage( 'Specialpages' );
1599 $s = '<form id="specialpages" method="get" ' .
1600 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1601 $s .= "<select name=\"wpDropdown\">\n";
1602 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1605 foreach ( $pages as $name => $desc ) {
1606 $p = $wgContLang->specialPage( $name );
1607 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1609 $s .= "</select>\n";
1610 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1615 function mainPageLink() {
1617 Title
::newMainPage(),
1618 wfMsg( 'mainpage' ),
1621 array( 'known', 'noclasses' )
1626 private function footerLink ( $desc, $page ) {
1627 // if the link description has been set to "-" in the default language,
1628 if ( wfMsgForContent( $desc ) == '-') {
1629 // then it is disabled, for all languages.
1632 // Otherwise, we display the link for the user, described in their
1633 // language (which may or may not be the same as the default language),
1634 // but we make the link target be the one site-wide page.
1635 $title = Title
::newFromText( wfMsgForContent( $page ) );
1636 return $this->linkKnown(
1638 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1643 function privacyLink() {
1644 return $this->footerLink( 'privacy', 'privacypage' );
1647 function aboutLink() {
1648 return $this->footerLink( 'aboutsite', 'aboutpage' );
1651 function disclaimerLink() {
1652 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1655 function editThisPage() {
1658 if ( !$wgOut->isArticleRelated() ) {
1659 $s = wfMsg( 'protectedpage' );
1661 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1662 $t = wfMsg( 'editthispage' );
1663 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1664 $t = wfMsg( 'create-this-page' );
1666 $t = wfMsg( 'viewsource' );
1673 $this->editUrlOptions(),
1674 array( 'known', 'noclasses' )
1681 * Return URL options for the 'edit page' link.
1682 * This may include an 'oldid' specifier, if the current page view is such.
1687 function editUrlOptions() {
1690 $options = array( 'action' => 'edit' );
1692 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1693 $options['oldid'] = intval( $this->mRevisionId
);
1699 function deleteThisPage() {
1700 global $wgUser, $wgRequest;
1702 $diff = $wgRequest->getVal( 'diff' );
1703 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1704 $t = wfMsg( 'deletethispage' );
1710 array( 'action' => 'delete' ),
1711 array( 'known', 'noclasses' )
1719 function protectThisPage() {
1720 global $wgUser, $wgRequest;
1722 $diff = $wgRequest->getVal( 'diff' );
1723 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1724 if ( $this->mTitle
->isProtected() ) {
1725 $text = wfMsg( 'unprotectthispage' );
1726 $query = array( 'action' => 'unprotect' );
1728 $text = wfMsg( 'protectthispage' );
1729 $query = array( 'action' => 'protect' );
1737 array( 'known', 'noclasses' )
1745 function watchThisPage() {
1747 ++
$this->mWatchLinkNum
;
1749 if ( $wgOut->isArticleRelated() ) {
1750 if ( $this->mTitle
->userIsWatching() ) {
1751 $text = wfMsg( 'unwatchthispage' );
1752 $query = array( 'action' => 'unwatch' );
1753 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1755 $text = wfMsg( 'watchthispage' );
1756 $query = array( 'action' => 'watch' );
1757 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1763 array( 'id' => $id ),
1765 array( 'known', 'noclasses' )
1768 $s = wfMsg( 'notanarticle' );
1773 function moveThisPage() {
1774 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1776 SpecialPage
::getTitleFor( 'Movepage' ),
1777 wfMsg( 'movethispage' ),
1779 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1780 array( 'known', 'noclasses' )
1783 // no message if page is protected - would be redundant
1788 function historyLink() {
1791 wfMsgHtml( 'history' ),
1792 array( 'rel' => 'archives' ),
1793 array( 'action' => 'history' )
1797 function whatLinksHere() {
1799 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1800 wfMsgHtml( 'whatlinkshere' ),
1803 array( 'known', 'noclasses' )
1807 function userContribsLink() {
1809 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1810 wfMsgHtml( 'contributions' ),
1813 array( 'known', 'noclasses' )
1817 function showEmailUser( $id ) {
1819 $targetUser = User
::newFromId( $id );
1820 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1821 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1824 function emailUserLink() {
1826 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1827 wfMsg( 'emailuser' ),
1830 array( 'known', 'noclasses' )
1834 function watchPageLinksLink() {
1836 if ( ! $wgOut->isArticleRelated() ) {
1837 return '(' . wfMsg( 'notanarticle' ) . ')';
1840 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1841 wfMsg( 'recentchangeslinked-toolbox' ),
1844 array( 'known', 'noclasses' )
1849 function trackbackLink() {
1850 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1851 . wfMsg( 'trackbacklink' ) . '</a>';
1854 function otherLanguages() {
1855 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1857 if ( $wgHideInterlanguageLinks ) {
1861 $a = $wgOut->getLanguageLinks();
1862 if ( 0 == count( $a ) ) {
1866 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1868 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1869 foreach( $a as $l ) {
1871 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1875 $nt = Title
::newFromText( $l );
1876 $url = $nt->escapeFullURL();
1877 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1879 if ( '' == $text ) { $text = $l; }
1880 $style = $this->getExternalLinkAttributes();
1881 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1883 if( $wgContLang->isRTL() ) $s .= '</span>';
1887 function talkLink() {
1888 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1889 # No discussion links for special pages
1893 $linkOptions = array();
1895 if( $this->mTitle
->isTalkPage() ) {
1896 $link = $this->mTitle
->getSubjectPage();
1897 switch( $link->getNamespace() ) {
1899 $text = wfMsg( 'articlepage' );
1902 $text = wfMsg( 'userpage' );
1905 $text = wfMsg( 'projectpage' );
1908 $text = wfMsg( 'imagepage' );
1909 # Make link known if image exists, even if the desc. page doesn't.
1910 if( wfFindFile( $link ) )
1911 $linkOptions[] = 'known';
1914 $text = wfMsg( 'mediawikipage' );
1917 $text = wfMsg( 'templatepage' );
1920 $text = wfMsg( 'viewhelppage' );
1923 $text = wfMsg( 'categorypage' );
1926 $text = wfMsg( 'articlepage' );
1929 $link = $this->mTitle
->getTalkPage();
1930 $text = wfMsg( 'talkpage' );
1933 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1938 function commentLink() {
1941 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1945 # __NEWSECTIONLINK___ changes behaviour here
1946 # If it is present, the link points to this page, otherwise
1947 # it points to the talk page
1948 if( $this->mTitle
->isTalkPage() ) {
1949 $title = $this->mTitle
;
1950 } elseif( $wgOut->showNewSectionLink() ) {
1951 $title = $this->mTitle
;
1953 $title = $this->mTitle
->getTalkPage();
1958 wfMsg( 'postcomment' ),
1964 array( 'known', 'noclasses' )
1968 /* these are used extensively in SkinTemplate, but also some other places */
1969 static function makeMainPageUrl( $urlaction = '' ) {
1970 $title = Title
::newMainPage();
1971 self
::checkTitle( $title, '' );
1972 return $title->getLocalURL( $urlaction );
1975 static function makeSpecialUrl( $name, $urlaction = '' ) {
1976 $title = SpecialPage
::getTitleFor( $name );
1977 return $title->getLocalURL( $urlaction );
1980 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1981 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1982 return $title->getLocalURL( $urlaction );
1985 static function makeI18nUrl( $name, $urlaction = '' ) {
1986 $title = Title
::newFromText( wfMsgForContent( $name ) );
1987 self
::checkTitle( $title, $name );
1988 return $title->getLocalURL( $urlaction );
1991 static function makeUrl( $name, $urlaction = '' ) {
1992 $title = Title
::newFromText( $name );
1993 self
::checkTitle( $title, $name );
1994 return $title->getLocalURL( $urlaction );
1997 # If url string starts with http, consider as external URL, else
1999 static function makeInternalOrExternalUrl( $name ) {
2000 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2003 return self
::makeUrl( $name );
2007 # this can be passed the NS number as defined in Language.php
2008 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2009 $title = Title
::makeTitleSafe( $namespace, $name );
2010 self
::checkTitle( $title, $name );
2011 return $title->getLocalURL( $urlaction );
2014 /* these return an array with the 'href' and boolean 'exists' */
2015 static function makeUrlDetails( $name, $urlaction = '' ) {
2016 $title = Title
::newFromText( $name );
2017 self
::checkTitle( $title, $name );
2019 'href' => $title->getLocalURL( $urlaction ),
2020 'exists' => $title->getArticleID() != 0 ?
true : false
2025 * Make URL details where the article exists (or at least it's convenient to think so)
2027 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2028 $title = Title
::newFromText( $name );
2029 self
::checkTitle( $title, $name );
2031 'href' => $title->getLocalURL( $urlaction ),
2036 # make sure we have some title to operate on
2037 static function checkTitle( &$title, $name ) {
2038 if( !is_object( $title ) ) {
2039 $title = Title
::newFromText( $name );
2040 if( !is_object( $title ) ) {
2041 $title = Title
::newFromText( '--error: link target missing--' );
2047 * Build an array that represents the sidebar(s), the navigation bar among them
2051 function buildSidebar() {
2052 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2054 wfProfileIn( __METHOD__
);
2056 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2058 if ( $wgEnableSidebarCache ) {
2059 $cachedsidebar = $parserMemc->get( $key );
2060 if ( $cachedsidebar ) {
2061 wfProfileOut( __METHOD__
);
2062 return $cachedsidebar;
2067 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
2069 foreach( $lines as $line ) {
2070 if( strpos( $line, '*' ) !== 0 )
2072 if( strpos( $line, '**') !== 0 ) {
2073 $heading = trim( $line, '* ' );
2074 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
2076 if( strpos( $line, '|' ) !== false ) { // sanity check
2077 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2078 $link = wfMsgForContent( $line[0] );
2082 $text = wfMsgExt( $line[1], 'parsemag' );
2083 if( wfEmptyMsg( $line[1], $text ) )
2085 if( wfEmptyMsg( $line[0], $link ) )
2088 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2091 $title = Title
::newFromText( $link );
2093 $title = $title->fixSpecialName();
2094 $href = $title->getLocalURL();
2096 $href = 'INVALID-TITLE';
2100 $bar[$heading][] = array(
2103 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2106 } else { continue; }
2109 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2110 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2111 wfProfileOut( __METHOD__
);
2116 * Should we include common/wikiprintable.css? Skins that have their own
2117 * print stylesheet should override this and return false. (This is an
2118 * ugly hack to get Monobook to play nicely with
2119 * OutputPage::headElement().)
2123 public function commonPrintStylesheet() {