09460c9aea82d1d9b8535e1903d51a0bbb7d5562
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 # Add favicons and Apple touch icons, if they're not the defaults
183 # Generally the order of the favicon and apple-touch-icon links
184 # should not matter, but Konqueror (3.5.9 at least) incorrectly
185 # uses whichever one appears later in the HTML source. Make sure
186 # apple-touch-icon is specified first to avoid this.
187 if( false !== $wgAppleTouchIcon && wfExpandUrl('/apple-touch-icon.png') != wfExpandUrl($wgAppleTouchIcon) ) {
188 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
191 if( false !== $wgFavicon && wfExpandUrl('/favicon.ico') != wfExpandUrl($wgFavicon) ) {
192 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
195 # OpenSearch description link
196 $out->addLink( array(
198 'type' => 'application/opensearchdescription+xml',
199 'href' => wfScript( 'opensearch_desc' ),
200 'title' => wfMsgForContent( 'opensearch-desc' ),
203 $this->addMetadataLinks( $out );
205 $this->mRevisionId
= $out->mRevisionId
;
207 $this->preloadExistence();
209 wfProfileOut( __METHOD__
);
213 * Preload the existence of three commonly-requested pages in a single query
215 function preloadExistence() {
219 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
222 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
224 } elseif ( $this->mTitle
->isTalkPage() ) {
225 $titles[] = $this->mTitle
->getSubjectPage();
227 $titles[] = $this->mTitle
->getTalkPage();
230 $lb = new LinkBatch( $titles );
234 function addMetadataLinks( OutputPage
$out ) {
235 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
236 global $wgRightsPage, $wgRightsUrl;
238 if( $out->isArticleRelated() ) {
239 # note: buggy CC software only reads first "meta" link
240 if( $wgEnableCreativeCommonsRdf ) {
241 $out->addMetadataLink( array(
242 'title' => 'Creative Commons',
243 'type' => 'application/rdf+xml',
244 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
247 if( $wgEnableDublinCoreRdf ) {
248 $out->addMetadataLink( array(
249 'title' => 'Dublin Core',
250 'type' => 'application/rdf+xml',
251 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
256 if( $wgRightsPage ) {
257 $copy = Title
::newFromText( $wgRightsPage );
259 $copyright = $copy->getLocalURL();
262 if( !$copyright && $wgRightsUrl ) {
263 $copyright = $wgRightsUrl;
266 $out->addLink( array(
267 'rel' => 'copyright',
268 'href' => $copyright )
274 * Set some local variables
276 protected function setMembers(){
278 $this->mUser
= $wgUser;
279 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
280 $this->usercss
= false;
285 * @param Title $t The title to use
287 public function setTitle( $t ) {
292 public function getTitle() {
293 return $this->mTitle
;
296 function outputPage( OutputPage
$out ) {
297 global $wgDebugComments;
298 wfProfileIn( __METHOD__
);
301 $this->initPage( $out );
303 // See self::afterContentHook() for documentation
304 $afterContent = $this->afterContentHook();
306 $out->out( $out->headElement( $this ) );
308 $out->out( "\n<body" );
309 $ops = $this->getBodyOptions();
310 foreach ( $ops as $name => $val ) {
311 $out->out( " $name='$val'" );
314 if ( $wgDebugComments ) {
315 $out->out( "<!-- Wiki debugging output:\n" .
316 $out->mDebugtext
. "-->\n" );
319 $out->out( $this->beforeContent() );
321 $out->out( $out->mBodytext
. "\n" );
323 $out->out( $this->afterContent() );
325 $out->out( $afterContent );
327 $out->out( $this->bottomScripts() );
329 $out->out( wfReportTime() );
331 $out->out( "\n</body></html>" );
332 wfProfileOut( __METHOD__
);
335 static function makeVariablesScript( $data ) {
336 global $wgJsMimeType, $wgHtml5;
338 $r = array( "<script" . ( $wgHtml5 ?
'' : " type=\"$wgJsMimeType\"" )
339 . ">/*<![CDATA[*/" );
340 foreach ( $data as $name => $value ) {
341 $encValue = Xml
::encodeJsVar( $value );
342 $r[] = "var $name = $encValue;";
344 $r[] = "/*]]>*/</script>\n";
345 return implode( "\n\t\t", $r );
349 * Make a <script> tag containing global variables
350 * @param $skinName string Name of the skin
351 * The odd calling convention is for backwards compatibility
352 * @TODO @FIXME Make this not depend on $wgTitle!
354 static function makeGlobalVariablesScript( $skinName ) {
355 if ( is_array( $skinName ) ) {
356 # Weird back-compat stuff.
357 $skinName = $skinName['skinname'];
359 global $wgScript, $wgTitle, $wgStylePath, $wgUser;
360 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang, $wgVariant;
361 global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
362 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
363 global $wgUseAjax, $wgAjaxWatch;
364 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
365 global $wgRestrictionTypes, $wgLivePreview;
366 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
368 $ns = $wgTitle->getNamespace();
369 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ?
$wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
370 $separatorTransTable = $wgContLang->separatorTransformTable();
371 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
372 $compactSeparatorTransTable = array(
373 implode( "\t", array_keys( $separatorTransTable ) ),
374 implode( "\t", $separatorTransTable ),
376 $digitTransTable = $wgContLang->digitTransformTable();
377 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
378 $compactDigitTransTable = array(
379 implode( "\t", array_keys( $digitTransTable ) ),
380 implode( "\t", $digitTransTable ),
383 $mainPage = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
386 'stylepath' => $wgStylePath,
387 'wgArticlePath' => $wgArticlePath,
388 'wgScriptPath' => $wgScriptPath,
389 'wgScript' => $wgScript,
390 'wgVariantArticlePath' => $wgVariantArticlePath,
391 'wgActionPaths' => (object)$wgActionPaths,
392 'wgServer' => $wgServer,
393 'wgCanonicalNamespace' => $nsname,
394 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBkey() ),
395 'wgNamespaceNumber' => $wgTitle->getNamespace(),
396 'wgPageName' => $wgTitle->getPrefixedDBKey(),
397 'wgTitle' => $wgTitle->getText(),
398 'wgAction' => $wgRequest->getText( 'action', 'view' ),
399 'wgArticleId' => $wgTitle->getArticleId(),
400 'wgIsArticle' => $wgOut->isArticle(),
401 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
402 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
403 'wgUserVariant' => $wgVariant->getCode(),
404 'wgUserLanguage' => $wgLang->getCode(),
405 'wgContentLanguage' => $wgContLang->getCode(),
406 'wgBreakFrames' => $wgBreakFrames,
407 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
408 'wgVersion' => $wgVersion,
409 'wgEnableAPI' => $wgEnableAPI,
410 'wgEnableWriteAPI' => $wgEnableWriteAPI,
411 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
412 'wgDigitTransformTable' => $compactDigitTransTable,
413 'wgMainPageTitle' => $mainPage ?
$mainPage->getPrefixedText() : null,
415 if ( !( $wgContLang->hasVariants() ) ) {
416 unset( $vars['wgUserVariant'] );
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() );
473 //moved wikibits to be called earlier on
474 //$out->addScriptFile( "{$wgStylePath}/common/wikibits.js" );
476 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
477 $wgOut->addScriptFile( self
::makeUrl( '-',
478 "action=raw$jsCache&gen=js&useskin=" .
479 urlencode( $this->getSkinName() )
483 if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
484 $userpage = $wgUser->getUserPage();
485 $userjs = self
::makeUrl(
486 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
487 'action=raw&ctype='.$wgJsMimeType );
488 $wgOut->addScriptFile( $userjs );
490 return "\t" . $vars . "\t" . $out->mScripts
;
494 * To make it harder for someone to slip a user a fake
495 * user-JavaScript or user-CSS preview, a random token
496 * is associated with the login session. If it's not
497 * passed back with the preview request, we won't render
500 * @param string $action
504 function userCanPreview( $action ) {
505 global $wgRequest, $wgUser;
507 if( $action != 'submit' )
509 if( !$wgRequest->wasPosted() )
511 if( !$this->mTitle
->userCanEditCssSubpage() )
513 if( !$this->mTitle
->userCanEditJsSubpage() )
515 return $wgUser->matchEditToken(
516 $wgRequest->getVal( 'wpEditToken' ) );
520 * generated JavaScript action=raw&gen=js
521 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
522 * nated together. For some bizarre reason, it does *not* return any
523 * custom user JS from subpages. Huh?
525 * There's absolutely no reason to have separate Monobook/Common JSes.
526 * Any JS that cares can just check the skin variable generated at the
527 * top. For now Monobook.js will be maintained, but it should be consi-
530 * @param force_skin lets you override the skin name
534 public function generateUserJs( $skinName = null) {
537 wfProfileIn( __METHOD__
);
539 $skinName = $this->getSkinName();
542 $s = "/* generated javascript */\n";
543 $s .= "var skin = '" . Xml
::escapeJsString($skinName ) . "';\n";
544 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
545 $s .= "\n\n/* MediaWiki:Common.js */\n";
546 $commonJs = wfMsgForContent( 'common.js' );
547 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
551 $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n";
552 // avoid inclusion of non defined user JavaScript (with custom skins only)
553 // by checking for default message content
554 $msgKey = ucfirst( $skinName ).'.js';
555 $userJS = wfMsgForContent( $msgKey );
556 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
560 wfProfileOut( __METHOD__
);
565 * Generate user stylesheet for action=raw&gen=css
567 public function generateUserStylesheet() {
568 wfProfileIn( __METHOD__
);
569 $s = "/* generated user stylesheet */\n" .
570 $this->reallyGenerateUserStylesheet();
571 wfProfileOut( __METHOD__
);
576 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
578 protected function reallyGenerateUserStylesheet(){
581 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
582 $underline = $undopt ?
'underline' : 'none';
583 $s .= "a { text-decoration: $underline; }\n";
585 if( $wgUser->getOption( 'highlightbroken' ) ) {
586 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
589 a.new, #quickbar a.new,
590 a.stub, #quickbar a.stub {
593 a.new:after, #quickbar a.new:after {
597 a.stub:after, #quickbar a.stub:after {
603 if( $wgUser->getOption( 'justify' ) ) {
604 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
606 if( !$wgUser->getOption( 'showtoc' ) ) {
607 $s .= "#toc { display: none; }\n";
609 if( !$wgUser->getOption( 'editsection' ) ) {
610 $s .= ".editsection { display: none; }\n";
612 $fontstyle = $wgUser->getOption( 'editfont' );
613 if ( $fontstyle !== 'default' ) {
614 $s .= "textarea { font-family: $fontstyle; }\n";
622 function setupUserCss( OutputPage
$out ) {
623 global $wgRequest, $wgContLang, $wgUser;
624 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
626 wfProfileIn( __METHOD__
);
628 $this->setupSkinUserCss( $out );
632 'maxage' => $wgSquidMaxage,
635 // Add any extension CSS
636 foreach( $out->getExtStyle() as $tag ) {
637 $out->addStyle( $tag['href'] );
640 // If we use the site's dynamic CSS, throw that in, too
641 // Per-site custom styles
642 if( $wgUseSiteCss ) {
643 global $wgHandheldStyle;
644 $query = wfArrayToCGI( array(
645 'usemsgcache' => 'yes',
646 'ctype' => 'text/css',
647 'smaxage' => $wgSquidMaxage
649 # Site settings must override extension css! (bug 15025)
650 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
651 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
652 if( $wgHandheldStyle ) {
653 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
655 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
658 if( $wgUser->isLoggedIn() ) {
659 // Ensure that logged-in users' generated CSS isn't clobbered
660 // by anons' publicly cacheable generated CSS.
661 $siteargs['smaxage'] = '0';
662 $siteargs['ts'] = $wgUser->mTouched
;
664 // Per-user styles based on preferences
665 $siteargs['gen'] = 'css';
666 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
667 $siteargs['useskin'] = $us;
669 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
671 // Per-user custom style pages
672 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
673 $action = $wgRequest->getVal( 'action' );
674 # If we're previewing the CSS page, use it
675 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
676 $previewCss = $wgRequest->getText( 'wpTextbox1' );
677 // @FIXME: properly escape the cdata!
678 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
680 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
681 'action=raw&ctype=text/css' ) );
685 wfProfileOut( __METHOD__
);
689 * Add skin specific stylesheets
690 * @param $out OutputPage
692 function setupSkinUserCss( OutputPage
$out ) {
693 $out->addStyle( 'common/shared.css' );
694 $out->addStyle( 'common/oldshared.css' );
695 $out->addStyle( $this->getStylesheet() );
696 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
699 function getBodyOptions() {
700 global $wgUser, $wgOut, $wgRequest, $wgContLang;
702 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
704 if ( 0 != $this->mTitle
->getNamespace() ) {
705 $a = array( 'bgcolor' => '#ffffec' );
707 else $a = array( 'bgcolor' => '#FFFFFF' );
708 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
709 $this->mTitle
->quickUserCan( 'edit' ) ) {
710 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
711 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
712 $a +
= array( 'ondblclick' => $s );
714 $a['onload'] = $wgOut->getOnloadHandler();
717 ' '.( $wgContLang->isRTL() ?
'rtl' : 'ltr' ).
718 ' '.$this->getPageClasses( $this->mTitle
) .
719 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
723 function getPageClasses( $title ) {
724 $numeric = 'ns-'.$title->getNamespace();
725 if( $title->getNamespace() == NS_SPECIAL
) {
726 $type = 'ns-special';
727 } elseif( $title->isTalkPage() ) {
730 $type = 'ns-subject';
732 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
733 return "$numeric $type $name";
745 * This will be called immediately after the <body> tag. Split into
746 * two functions to make it easier to subclass.
748 function beforeContent() {
749 return $this->doBeforeContent();
752 function doBeforeContent() {
754 wfProfileIn( __METHOD__
);
757 $qb = $this->qbSetting();
759 if( $langlinks = $this->otherLanguages() ) {
765 $borderhack = 'class="top"';
768 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
769 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
771 $shove = ( $qb != 0 );
772 $left = ( $qb == 1 ||
$qb == 3 );
773 if( $wgContLang->isRTL() ) $left = !$left;
776 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
777 $this->logoText() . '</td>';
779 $s .= $this->getQuickbarCompensator( $rows );
781 $l = $wgContLang->isRTL() ?
'right' : 'left';
782 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
784 $s .= $this->topLinks();
785 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
787 $r = $wgContLang->isRTL() ?
'left' : 'right';
788 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
789 $s .= $this->nameAndLogin();
790 $s .= "\n<br />" . $this->searchForm() . "</td>";
793 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
796 if ( $shove && !$left ) { # Right
797 $s .= $this->getQuickbarCompensator( $rows );
799 $s .= "</tr>\n</table>\n</div>\n";
800 $s .= "\n<div id='article'>\n";
802 $notice = wfGetSiteNotice();
804 $s .= "\n<div id='siteNotice'>$notice</div>\n";
806 $s .= $this->pageTitle();
807 $s .= $this->pageSubtitle();
808 $s .= $this->getCategories();
809 wfProfileOut( __METHOD__
);
814 function getCategoryLinks() {
815 global $wgOut, $wgUseCategoryBrowser;
816 global $wgContLang, $wgUser;
818 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
821 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
823 // Use Unicode bidi embedding override characters,
824 // to make sure links don't smash each other up in ugly ways.
825 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
826 $embed = "<span dir='$dir'>";
829 $allCats = $wgOut->getCategoryLinks();
831 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
832 if ( !empty( $allCats['normal'] ) ) {
833 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
835 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
836 $s .= '<div id="mw-normal-catlinks">' .
837 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
838 . $colon . $t . '</div>';
842 if ( isset( $allCats['hidden'] ) ) {
843 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
844 $class ='mw-hidden-cats-user-shown';
845 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
846 $class = 'mw-hidden-cats-ns-shown';
848 $class = 'mw-hidden-cats-hidden';
850 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
851 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
852 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
856 # optional 'dmoz-like' category browser. Will be shown under the list
857 # of categories an article belong to
858 if( $wgUseCategoryBrowser ){
859 $s .= '<br /><hr />';
861 # get a big array of the parents tree
862 $parenttree = $this->mTitle
->getParentCategoryTree();
863 # Skin object passed by reference cause it can not be
864 # accessed under the method subfunction drawCategoryBrowser
865 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
866 # Clean out bogus first entry and sort them
867 unset( $tempout[0] );
869 # Output one per line
870 $s .= implode( "<br />\n", $tempout );
877 * Render the array as a serie of links.
878 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
879 * @param &skin Object: skin passed by reference
880 * @return String separated by >, terminate with "\n"
882 function drawCategoryBrowser( $tree, &$skin ){
884 foreach( $tree as $element => $parent ) {
885 if( empty( $parent ) ) {
886 # element start a new list
889 # grab the others elements
890 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
892 # add our current element to the list
893 $eltitle = Title
::newFromText( $element );
894 $return .= $skin->link( $eltitle, $eltitle->getText() );
899 function getCategories() {
900 $catlinks=$this->getCategoryLinks();
902 $classes = 'catlinks';
904 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
905 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
906 $classes .= ' catlinks-allhidden';
909 if( !empty( $catlinks ) ){
910 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
914 function getQuickbarCompensator( $rows = 1 ) {
915 return "<td width='152' rowspan='{$rows}'> </td>";
919 * This runs a hook to allow extensions placing their stuff after content
920 * and article metadata (e.g. categories).
921 * Note: This function has nothing to do with afterContent().
923 * This hook is placed here in order to allow using the same hook for all
924 * skins, both the SkinTemplate based ones and the older ones, which directly
925 * use this class to get their data.
927 * The output of this function gets processed in SkinTemplate::outputPage() for
928 * the SkinTemplate based skins, all other skins should directly echo it.
930 * Returns an empty string by default, if not changed by any hook function.
932 protected function afterContentHook() {
935 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
936 // adding just some spaces shouldn't toggle the output
937 // of the whole <div/>, so we use trim() here
938 if( trim( $data ) != '' ){
939 // Doing this here instead of in the skins to
940 // ensure that the div has the same ID in all
942 $data = "<div id='mw-data-after-content'>\n" .
947 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
954 * Generate debug data HTML for displaying at the bottom of the main content
956 * @return String HTML containing debug data, if enabled (otherwise empty).
958 protected function generateDebugHTML() {
959 global $wgShowDebug, $wgOut;
960 if ( $wgShowDebug ) {
961 $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext
) );
962 return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
963 $listInternals . "</li></ul>\n";
969 * This gets called shortly before the </body> tag.
970 * @return String HTML to be put before </body>
972 function afterContent() {
973 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
974 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
978 * This gets called shortly before the </body> tag.
979 * @return String HTML-wrapped JS code to be put before </body>
981 function bottomScripts() {
982 global $wgJsMimeType;
983 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
984 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
985 return $bottomScriptText;
988 /** @return string Retrievied from HTML text */
989 function printSource() {
990 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
991 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
994 function printFooter() {
995 return "<p>" . $this->printSource() .
996 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
999 /** overloaded by derived classes */
1000 function doAfterContent() { return '</div></div>'; }
1002 function pageTitleLinks() {
1003 global $wgOut, $wgUser, $wgRequest, $wgLang;
1005 $oldid = $wgRequest->getVal( 'oldid' );
1006 $diff = $wgRequest->getVal( 'diff' );
1007 $action = $wgRequest->getText( 'action' );
1009 $s[] = $this->printableLink();
1010 $disclaimer = $this->disclaimerLink(); # may be empty
1014 $privacy = $this->privacyLink(); # may be empty too
1019 if ( $wgOut->isArticleRelated() ) {
1020 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1021 $name = $this->mTitle
->getDBkey();
1022 $image = wfFindFile( $this->mTitle
);
1024 $link = htmlspecialchars( $image->getURL() );
1025 $style = $this->getInternalLinkAttributes( $link, $name );
1026 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1030 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1031 $s[] .= $this->link(
1033 wfMsg( 'currentrev' ),
1036 array( 'known', 'noclasses' )
1040 if ( $wgUser->getNewtalk() ) {
1041 # do not show "You have new messages" text when we are viewing our
1043 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1044 $nu = $wgUser->getnewMessagesCount();
1047 $wgUser->getTalkPage(),
1048 wfMsgExt( 'newmessageslink', array( 'parsemag', 'escape' ) ),
1050 array( 'redirect' => 'no' ),
1051 array( 'known', 'noclasses' )
1055 $wgUser->getTalkPage(),
1056 wfMsgExt( 'newmessagesdifflink', array( 'parsemag', 'escape' ), $nu ),
1058 array( 'diff' => 'cur' ),
1059 array( 'known', 'noclasses' )
1061 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1063 $wgOut->setSquidMaxage( 0 );
1064 $wgOut->enableClientCache( false );
1068 $undelete = $this->getUndeleteLink();
1069 if( !empty( $undelete ) ) {
1072 return $wgLang->pipeList( $s );
1075 function getUndeleteLink() {
1076 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1078 $action = $wgRequest->getVal( 'action', 'view' );
1080 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1081 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1082 $n = $this->mTitle
->isDeleted();
1084 if ( $wgUser->isAllowed( 'undelete' ) ) {
1085 $msg = 'thisisdeleted';
1087 $msg = 'viewdeleted';
1092 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1093 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1096 array( 'known', 'noclasses' )
1104 function printableLink() {
1105 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1109 if ( !$wgRequest->getBool( 'printable' ) ) {
1110 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1111 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1114 if( $wgOut->isSyndicated() ) {
1115 foreach( $wgFeedClasses as $format => $class ) {
1116 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1117 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1118 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1121 return $wgLang->pipeList( $s );
1124 function pageTitle() {
1126 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1130 function pageSubtitle() {
1133 $sub = $wgOut->getSubtitle();
1135 global $wgExtraSubtitle;
1136 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1138 $subpages = $this->subPageSubtitle();
1139 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1140 $s = "<p class='subtitle'>{$sub}</p>\n";
1144 function subPageSubtitle() {
1146 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1150 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1151 $ptext = $this->mTitle
->getPrefixedText();
1152 if( preg_match( '/\//', $ptext ) ) {
1153 $links = explode( '/', $ptext );
1154 array_pop( $links );
1158 foreach( $links as $link ) {
1159 $growinglink .= $link;
1161 $linkObj = Title
::newFromText( $growinglink );
1162 if( is_object( $linkObj ) && $linkObj->exists() ){
1163 $getlink = $this->link(
1165 htmlspecialchars( $display ),
1168 array( 'known', 'noclasses' )
1172 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1174 $subpages .= '< ';
1176 $subpages .= $getlink;
1181 $growinglink .= '/';
1189 * Returns true if the IP should be shown in the header
1191 function showIPinHeader() {
1192 global $wgShowIPinHeader;
1193 return $wgShowIPinHeader && session_id() != '';
1196 function nameAndLogin() {
1197 global $wgUser, $wgLang, $wgContLang;
1199 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1202 if ( $wgUser->isAnon() ) {
1203 if( $this->showIPinHeader() ) {
1206 $talkLink = $this->link( $wgUser->getTalkPage(),
1207 $wgLang->getNsText( NS_TALK
) );
1209 $ret .= "$name ($talkLink)";
1211 $ret .= wfMsg( 'notloggedin' );
1214 $returnTo = $this->mTitle
->getPrefixedDBkey();
1216 if ( $logoutPage != $returnTo ) {
1217 $query['returnto'] = $returnTo;
1220 $loginlink = $wgUser->isAllowed( 'createaccount' )
1221 ?
'nav-login-createaccount'
1223 $ret .= "\n<br />" . $this->link(
1224 SpecialPage
::getTitleFor( 'Userlogin' ),
1225 wfMsg( $loginlink ), array(), $query
1228 $returnTo = $this->mTitle
->getPrefixedDBkey();
1229 $talkLink = $this->link( $wgUser->getTalkPage(),
1230 $wgLang->getNsText( NS_TALK
) );
1232 $ret .= $this->link( $wgUser->getUserPage(),
1233 htmlspecialchars( $wgUser->getName() ) );
1234 $ret .= " ($talkLink)<br />";
1235 $ret .= $wgLang->pipeList( array(
1237 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1238 array(), array( 'returnto' => $returnTo )
1240 $this->specialLink( 'preferences' ),
1243 $ret = $wgLang->pipeList( array(
1246 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1254 function getSearchLink() {
1255 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1256 return $searchPage->getLocalURL();
1259 function escapeSearchLink() {
1260 return htmlspecialchars( $this->getSearchLink() );
1263 function searchForm() {
1264 global $wgRequest, $wgUseTwoButtonsSearchForm;
1265 $search = $wgRequest->getText( 'search' );
1267 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1268 . $this->escapeSearchLink() . "\">\n"
1269 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1270 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1271 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1273 if( $wgUseTwoButtonsSearchForm )
1274 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1276 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1280 // Ensure unique id's for search boxes made after the first
1281 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1286 function topLinks() {
1290 $this->mainPageLink(),
1291 $this->specialLink( 'recentchanges' )
1294 if ( $wgOut->isArticleRelated() ) {
1295 $s[] = $this->editThisPage();
1296 $s[] = $this->historyLink();
1298 # Many people don't like this dropdown box
1299 #$s[] = $this->specialPagesList();
1301 if( $this->variantLinks() ) {
1302 $s[] = $this->variantLinks();
1305 if( $this->extensionTabLinks() ) {
1306 $s[] = $this->extensionTabLinks();
1309 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1310 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1314 * Compatibility for extensions adding functionality through tabs.
1315 * Eventually these old skins should be replaced with SkinTemplate-based
1319 function extensionTabLinks() {
1323 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1324 foreach( $tabs as $tab ) {
1325 $s[] = Xml
::element( 'a',
1326 array( 'href' => $tab['href'] ),
1333 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1334 $out .= $wgLang->pipeList( $s );
1341 * Language/charset variant links for classic-style skins
1344 function variantLinks() {
1346 /* show links to different language variants */
1347 global $wgDisableLangConversion, $wgLang, $wgContLang;
1348 $variants = $wgContLang->getVariants();
1349 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1350 foreach( $variants as $code ) {
1351 $varname = $wgContLang->getVariantname( $code );
1352 if( $varname == 'disable' )
1354 $s = $wgLang->pipeList( array(
1356 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1363 function bottomLinks() {
1364 global $wgOut, $wgUser, $wgUseTrackbacks;
1365 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1368 if ( $wgOut->isArticleRelated() ) {
1369 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1370 if ( $wgUser->isLoggedIn() ) {
1371 $element[] = $this->watchThisPage();
1373 $element[] = $this->talkLink();
1374 $element[] = $this->historyLink();
1375 $element[] = $this->whatLinksHere();
1376 $element[] = $this->watchPageLinksLink();
1378 if( $wgUseTrackbacks )
1379 $element[] = $this->trackbackLink();
1381 if ( $this->mTitle
->getNamespace() == NS_USER
1382 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1383 $id = User
::idFromName( $this->mTitle
->getText() );
1384 $ip = User
::isIP( $this->mTitle
->getText() );
1386 if( $id ||
$ip ) { # both anons and non-anons have contri list
1387 $element[] = $this->userContribsLink();
1389 if( $this->showEmailUser( $id ) ) {
1390 $element[] = $this->emailUserLink();
1394 $s = implode( $element, $sep );
1396 if ( $this->mTitle
->getArticleId() ) {
1398 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1399 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1400 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1402 $s .= "<br />\n" . $this->otherLanguages();
1408 function pageStats() {
1409 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1410 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1412 $oldid = $wgRequest->getVal( 'oldid' );
1413 $diff = $wgRequest->getVal( 'diff' );
1414 if ( ! $wgOut->isArticle() ) { return ''; }
1415 if( !$wgArticle instanceOf Article
) { return ''; }
1416 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1417 if ( 0 == $wgArticle->getID() ) { return ''; }
1420 if ( !$wgDisableCounters ) {
1421 $count = $wgLang->formatNum( $wgArticle->getCount() );
1423 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1427 if( $wgMaxCredits != 0 ){
1428 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1430 $s .= $this->lastModified();
1433 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1434 $dbr = wfGetDB( DB_SLAVE
);
1435 $res = $dbr->select( 'watchlist',
1436 array( 'COUNT(*) AS n' ),
1437 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1440 $x = $dbr->fetchObject( $res );
1442 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1443 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1447 return $s . ' ' . $this->getCopyright();
1450 function getCopyright( $type = 'detect' ) {
1451 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1453 if ( $type == 'detect' ) {
1454 $diff = $wgRequest->getVal( 'diff' );
1455 $isCur = $wgArticle && $wgArticle->isCurrent();
1456 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1463 if ( $type == 'history' ) {
1464 $msg = 'history_copyright';
1470 if( $wgRightsPage ) {
1471 $title = Title
::newFromText( $wgRightsPage );
1472 $link = $this->linkKnown( $title, $wgRightsText );
1473 } elseif( $wgRightsUrl ) {
1474 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1475 } elseif( $wgRightsText ) {
1476 $link = $wgRightsText;
1481 // Allow for site and per-namespace customization of copyright notice.
1482 if( isset($wgArticle) )
1483 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1485 $out .= wfMsgForContent( $msg, $link );
1489 function getCopyrightIcon() {
1490 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1492 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1493 $out = $wgCopyrightIcon;
1494 } else if ( $wgRightsIcon ) {
1495 $icon = htmlspecialchars( $wgRightsIcon );
1496 if ( $wgRightsUrl ) {
1497 $url = htmlspecialchars( $wgRightsUrl );
1498 $out .= '<a href="'.$url.'">';
1500 $text = htmlspecialchars( $wgRightsText );
1501 $out .= "<img src=\"$icon\" alt='$text' />";
1502 if ( $wgRightsUrl ) {
1509 function getPoweredBy() {
1510 global $wgStylePath;
1511 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1512 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1516 function lastModified() {
1517 global $wgLang, $wgArticle;
1518 if( $this->mRevisionId
) {
1519 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1521 $timestamp = $wgArticle->getTimestamp();
1524 $d = $wgLang->date( $timestamp, true );
1525 $t = $wgLang->time( $timestamp, true );
1526 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1530 if ( wfGetLB()->getLaggedSlaveMode() ) {
1531 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1536 function logoText( $align = '' ) {
1537 if ( '' != $align ) {
1538 $a = " align='{$align}'";
1543 $mp = wfMsg( 'mainpage' );
1544 $mptitle = Title
::newMainPage();
1545 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1547 $logourl = $this->getLogo();
1548 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1553 * show a drop-down box of special pages
1555 function specialPagesList() {
1556 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1557 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1558 foreach ( $pages as $name => $page ) {
1559 $pages[$name] = $page->getDescription();
1562 $go = wfMsg( 'go' );
1563 $sp = wfMsg( 'specialpages' );
1564 $spp = $wgContLang->specialPage( 'Specialpages' );
1566 $s = '<form id="specialpages" method="get" ' .
1567 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1568 $s .= "<select name=\"wpDropdown\">\n";
1569 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1572 foreach ( $pages as $name => $desc ) {
1573 $p = $wgContLang->specialPage( $name );
1574 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1576 $s .= "</select>\n";
1577 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1582 function mainPageLink() {
1584 Title
::newMainPage(),
1585 wfMsg( 'mainpage' ),
1588 array( 'known', 'noclasses' )
1593 function copyrightLink() {
1594 $title = Title
::newFromText( wfMsgForContent( 'copyrightpage' ) );
1595 $s = $this->linkKnown(
1597 wfMsg( 'copyrightpagename' )
1602 private function footerLink ( $desc, $page ) {
1603 // if the link description has been set to "-" in the default language,
1604 if ( wfMsgForContent( $desc ) == '-') {
1605 // then it is disabled, for all languages.
1608 // Otherwise, we display the link for the user, described in their
1609 // language (which may or may not be the same as the default language),
1610 // but we make the link target be the one site-wide page.
1611 $title = Title
::newFromText( wfMsgForContent( $page ) );
1612 return $this->linkKnown(
1614 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1619 function privacyLink() {
1620 return $this->footerLink( 'privacy', 'privacypage' );
1623 function aboutLink() {
1624 return $this->footerLink( 'aboutsite', 'aboutpage' );
1627 function disclaimerLink() {
1628 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1631 function editThisPage() {
1634 if ( !$wgOut->isArticleRelated() ) {
1635 $s = wfMsg( 'protectedpage' );
1637 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1638 $t = wfMsg( 'editthispage' );
1639 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1640 $t = wfMsg( 'create-this-page' );
1642 $t = wfMsg( 'viewsource' );
1649 $this->editUrlOptions(),
1650 array( 'known', 'noclasses' )
1657 * Return URL options for the 'edit page' link.
1658 * This may include an 'oldid' specifier, if the current page view is such.
1663 function editUrlOptions() {
1666 $options = array( 'action' => 'edit' );
1668 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1669 $options['oldid'] = intval( $this->mRevisionId
);
1675 function deleteThisPage() {
1676 global $wgUser, $wgRequest;
1678 $diff = $wgRequest->getVal( 'diff' );
1679 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1680 $t = wfMsg( 'deletethispage' );
1686 array( 'action' => 'delete' ),
1687 array( 'known', 'noclasses' )
1695 function protectThisPage() {
1696 global $wgUser, $wgRequest;
1698 $diff = $wgRequest->getVal( 'diff' );
1699 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1700 if ( $this->mTitle
->isProtected() ) {
1701 $text = wfMsg( 'unprotectthispage' );
1702 $query = array( 'action' => 'unprotect' );
1704 $text = wfMsg( 'protectthispage' );
1705 $query = array( 'action' => 'protect' );
1713 array( 'known', 'noclasses' )
1721 function watchThisPage() {
1723 ++
$this->mWatchLinkNum
;
1725 if ( $wgOut->isArticleRelated() ) {
1726 if ( $this->mTitle
->userIsWatching() ) {
1727 $text = wfMsg( 'unwatchthispage' );
1728 $query = array( 'action' => 'unwatch' );
1729 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1731 $text = wfMsg( 'watchthispage' );
1732 $query = array( 'action' => 'watch' );
1733 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1739 array( 'id' => $id ),
1741 array( 'known', 'noclasses' )
1744 $s = wfMsg( 'notanarticle' );
1749 function moveThisPage() {
1750 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1752 SpecialPage
::getTitleFor( 'Movepage' ),
1753 wfMsg( 'movethispage' ),
1755 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1756 array( 'known', 'noclasses' )
1759 // no message if page is protected - would be redundant
1764 function historyLink() {
1767 wfMsgHtml( 'history' ),
1768 array( 'rel' => 'archives' ),
1769 array( 'action' => 'history' )
1773 function whatLinksHere() {
1775 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1776 wfMsgHtml( 'whatlinkshere' ),
1779 array( 'known', 'noclasses' )
1783 function userContribsLink() {
1785 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1786 wfMsgHtml( 'contributions' ),
1789 array( 'known', 'noclasses' )
1793 function showEmailUser( $id ) {
1795 $targetUser = User
::newFromId( $id );
1796 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1797 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1800 function emailUserLink() {
1802 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1803 wfMsg( 'emailuser' ),
1806 array( 'known', 'noclasses' )
1810 function watchPageLinksLink() {
1812 if ( ! $wgOut->isArticleRelated() ) {
1813 return '(' . wfMsg( 'notanarticle' ) . ')';
1816 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1817 wfMsg( 'recentchangeslinked-toolbox' ),
1820 array( 'known', 'noclasses' )
1825 function trackbackLink() {
1826 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1827 . wfMsg( 'trackbacklink' ) . '</a>';
1830 function otherLanguages() {
1831 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1833 if ( $wgHideInterlanguageLinks ) {
1837 $a = $wgOut->getLanguageLinks();
1838 if ( 0 == count( $a ) ) {
1842 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1844 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1845 foreach( $a as $l ) {
1847 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1851 $nt = Title
::newFromText( $l );
1852 $url = $nt->escapeFullURL();
1853 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1855 if ( '' == $text ) { $text = $l; }
1856 $style = $this->getExternalLinkAttributes();
1857 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1859 if( $wgContLang->isRTL() ) $s .= '</span>';
1863 function talkLink() {
1864 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1865 # No discussion links for special pages
1869 $linkOptions = array();
1871 if( $this->mTitle
->isTalkPage() ) {
1872 $link = $this->mTitle
->getSubjectPage();
1873 switch( $link->getNamespace() ) {
1875 $text = wfMsg( 'articlepage' );
1878 $text = wfMsg( 'userpage' );
1881 $text = wfMsg( 'projectpage' );
1884 $text = wfMsg( 'imagepage' );
1885 # Make link known if image exists, even if the desc. page doesn't.
1886 if( wfFindFile( $link ) )
1887 $linkOptions[] = 'known';
1890 $text = wfMsg( 'mediawikipage' );
1893 $text = wfMsg( 'templatepage' );
1896 $text = wfMsg( 'viewhelppage' );
1899 $text = wfMsg( 'categorypage' );
1902 $text = wfMsg( 'articlepage' );
1905 $link = $this->mTitle
->getTalkPage();
1906 $text = wfMsg( 'talkpage' );
1909 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1914 function commentLink() {
1917 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1921 # __NEWSECTIONLINK___ changes behaviour here
1922 # If it is present, the link points to this page, otherwise
1923 # it points to the talk page
1924 if( $this->mTitle
->isTalkPage() ) {
1925 $title = $this->mTitle
;
1926 } elseif( $wgOut->showNewSectionLink() ) {
1927 $title = $this->mTitle
;
1929 $title = $this->mTitle
->getTalkPage();
1934 wfMsg( 'postcomment' ),
1940 array( 'known', 'noclasses' )
1944 /* these are used extensively in SkinTemplate, but also some other places */
1945 static function makeMainPageUrl( $urlaction = '' ) {
1946 $title = Title
::newMainPage();
1947 self
::checkTitle( $title, '' );
1948 return $title->getLocalURL( $urlaction );
1951 static function makeSpecialUrl( $name, $urlaction = '' ) {
1952 $title = SpecialPage
::getTitleFor( $name );
1953 return $title->getLocalURL( $urlaction );
1956 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1957 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1958 return $title->getLocalURL( $urlaction );
1961 static function makeI18nUrl( $name, $urlaction = '' ) {
1962 $title = Title
::newFromText( wfMsgForContent( $name ) );
1963 self
::checkTitle( $title, $name );
1964 return $title->getLocalURL( $urlaction );
1967 static function makeUrl( $name, $urlaction = '' ) {
1968 $title = Title
::newFromText( $name );
1969 self
::checkTitle( $title, $name );
1970 return $title->getLocalURL( $urlaction );
1973 # If url string starts with http, consider as external URL, else
1975 static function makeInternalOrExternalUrl( $name ) {
1976 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1979 return self
::makeUrl( $name );
1983 # this can be passed the NS number as defined in Language.php
1984 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1985 $title = Title
::makeTitleSafe( $namespace, $name );
1986 self
::checkTitle( $title, $name );
1987 return $title->getLocalURL( $urlaction );
1990 /* these return an array with the 'href' and boolean 'exists' */
1991 static function makeUrlDetails( $name, $urlaction = '' ) {
1992 $title = Title
::newFromText( $name );
1993 self
::checkTitle( $title, $name );
1995 'href' => $title->getLocalURL( $urlaction ),
1996 'exists' => $title->getArticleID() != 0 ?
true : false
2001 * Make URL details where the article exists (or at least it's convenient to think so)
2003 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2004 $title = Title
::newFromText( $name );
2005 self
::checkTitle( $title, $name );
2007 'href' => $title->getLocalURL( $urlaction ),
2012 # make sure we have some title to operate on
2013 static function checkTitle( &$title, $name ) {
2014 if( !is_object( $title ) ) {
2015 $title = Title
::newFromText( $name );
2016 if( !is_object( $title ) ) {
2017 $title = Title
::newFromText( '--error: link target missing--' );
2023 * Build an array that represents the sidebar(s), the navigation bar among them
2027 function buildSidebar() {
2028 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2030 wfProfileIn( __METHOD__
);
2032 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2034 if ( $wgEnableSidebarCache ) {
2035 $cachedsidebar = $parserMemc->get( $key );
2036 if ( $cachedsidebar ) {
2037 wfProfileOut( __METHOD__
);
2038 return $cachedsidebar;
2043 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
2045 foreach( $lines as $line ) {
2046 if( strpos( $line, '*' ) !== 0 )
2048 if( strpos( $line, '**') !== 0 ) {
2049 $heading = trim( $line, '* ' );
2050 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
2052 if( strpos( $line, '|' ) !== false ) { // sanity check
2053 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2054 $link = wfMsgForContent( $line[0] );
2058 $text = wfMsgExt( $line[1], 'parsemag' );
2059 if( wfEmptyMsg( $line[1], $text ) )
2061 if( wfEmptyMsg( $line[0], $link ) )
2064 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2067 $title = Title
::newFromText( $link );
2069 $title = $title->fixSpecialName();
2070 $href = $title->getLocalURL();
2072 $href = 'INVALID-TITLE';
2076 $bar[$heading][] = array(
2079 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2082 } else { continue; }
2085 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2086 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2087 wfProfileOut( __METHOD__
);
2092 * Should we include common/wikiprintable.css? Skins that have their own
2093 * print stylesheet should override this and return false. (This is an
2094 * ugly hack to get Monobook to play nicely with
2095 * OutputPage::headElement().)
2099 public function commonPrintStylesheet() {