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;
338 $r = array( "<script type=\"$wgJsMimeType\">/*<![CDATA[*/" );
339 foreach ( $data as $name => $value ) {
340 $encValue = Xml
::encodeJsVar( $value );
341 $r[] = "var $name = $encValue;";
343 $r[] = "/*]]>*/</script>\n";
344 return implode( "\n\t\t", $r );
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, $wgVariant;
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 ),
384 'stylepath' => $wgStylePath,
385 'wgArticlePath' => $wgArticlePath,
386 'wgScriptPath' => $wgScriptPath,
387 'wgScript' => $wgScript,
388 'wgVariantArticlePath' => $wgVariantArticlePath,
389 'wgActionPaths' => (object)$wgActionPaths,
390 'wgServer' => $wgServer,
391 'wgCanonicalNamespace' => $nsname,
392 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBkey() ),
393 'wgNamespaceNumber' => $wgTitle->getNamespace(),
394 'wgPageName' => $wgTitle->getPrefixedDBKey(),
395 'wgTitle' => $wgTitle->getText(),
396 'wgAction' => $wgRequest->getText( 'action', 'view' ),
397 'wgArticleId' => $wgTitle->getArticleId(),
398 'wgIsArticle' => $wgOut->isArticle(),
399 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
400 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
401 'wgUserVariant' => $wgVariant->getCode(),
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,
412 if ( !( $wgContLang->hasVariants() ) ) {
413 unset( $vars['wgUserVariant'] );
416 //if on upload page output the extension list & js_upload
417 if( SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) == "Upload" ){
418 global $wgFileExtensions, $wgAjaxUploadInterface;
419 $vars['wgFileExtensions'] = $wgFileExtensions;
420 $vars['wgAjaxUploadInterface'] = $wgAjaxUploadInterface;
423 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
424 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
425 $vars['wgDBname'] = $wgDBname;
426 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
427 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
430 foreach( $wgRestrictionTypes as $type )
431 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
433 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
434 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
435 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
436 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
437 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
440 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
441 $msgs = (object)array();
442 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
443 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
445 $vars['wgAjaxWatch'] = $msgs;
448 // Allow extensions to add their custom variables to the global JS variables
449 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
451 return self
::makeVariablesScript( $vars );
454 * Return a random selection of the scripts we want in the header,
455 * according to no particular rhyme or reason. Various other scripts are
456 * returned from a haphazard assortment of other functions scattered over
457 * various files. This entire hackish system needs to be burned to the
458 * ground and rebuilt.
460 * @param $out OutputPage object, should be $wgOut
462 * @return string Raw HTML to output to <head>
464 function getHeadScripts( OutputPage
$out ) {
465 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion, $wgOut;
468 $vars = self
::makeGlobalVariablesScript( $this->getSkinName() );
470 //moved wikibits to be called earlier on
471 //$out->addScriptFile( "{$wgStylePath}/common/wikibits.js" );
473 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
474 $wgOut->addScriptFile( self
::makeUrl( '-',
475 "action=raw$jsCache&gen=js&useskin=" .
476 urlencode( $this->getSkinName() )
480 if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
481 $userpage = $wgUser->getUserPage();
482 $userjs = self
::makeUrl(
483 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
484 'action=raw&ctype='.$wgJsMimeType );
485 $wgOut->addScriptFile( $userjs );
487 return "\t" . $vars . "\t" . $out->mScripts
;
491 * To make it harder for someone to slip a user a fake
492 * user-JavaScript or user-CSS preview, a random token
493 * is associated with the login session. If it's not
494 * passed back with the preview request, we won't render
497 * @param string $action
501 function userCanPreview( $action ) {
502 global $wgRequest, $wgUser;
504 if( $action != 'submit' )
506 if( !$wgRequest->wasPosted() )
508 if( !$this->mTitle
->userCanEditCssJsSubpage() )
510 return $wgUser->matchEditToken(
511 $wgRequest->getVal( 'wpEditToken' ) );
515 * generated JavaScript action=raw&gen=js
516 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
517 * nated together. For some bizarre reason, it does *not* return any
518 * custom user JS from subpages. Huh?
520 * There's absolutely no reason to have separate Monobook/Common JSes.
521 * Any JS that cares can just check the skin variable generated at the
522 * top. For now Monobook.js will be maintained, but it should be consi-
525 * @param force_skin lets you override the skin name
529 public function generateUserJs( $skinName = null) {
532 wfProfileIn( __METHOD__
);
534 $skinName = $this->getSkinName();
537 $s = "/* generated javascript */\n";
538 $s .= "var skin = '" . Xml
::escapeJsString($skinName ) . "';\n";
539 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
540 $s .= "\n\n/* MediaWiki:Common.js */\n";
541 $commonJs = wfMsgForContent( 'common.js' );
542 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
546 $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n";
547 // avoid inclusion of non defined user JavaScript (with custom skins only)
548 // by checking for default message content
549 $msgKey = ucfirst( $skinName ).'.js';
550 $userJS = wfMsgForContent( $msgKey );
551 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
555 wfProfileOut( __METHOD__
);
560 * Generate user stylesheet for action=raw&gen=css
562 public function generateUserStylesheet() {
563 wfProfileIn( __METHOD__
);
564 $s = "/* generated user stylesheet */\n" .
565 $this->reallyGenerateUserStylesheet();
566 wfProfileOut( __METHOD__
);
571 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
573 protected function reallyGenerateUserStylesheet(){
576 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
577 $underline = $undopt ?
'underline' : 'none';
578 $s .= "a { text-decoration: $underline; }\n";
580 if( $wgUser->getOption( 'highlightbroken' ) ) {
581 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
584 a.new, #quickbar a.new,
585 a.stub, #quickbar a.stub {
588 a.new:after, #quickbar a.new:after {
592 a.stub:after, #quickbar a.stub:after {
598 if( $wgUser->getOption( 'justify' ) ) {
599 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
601 if( !$wgUser->getOption( 'showtoc' ) ) {
602 $s .= "#toc { display: none; }\n";
604 if( !$wgUser->getOption( 'editsection' ) ) {
605 $s .= ".editsection { display: none; }\n";
613 function setupUserCss( OutputPage
$out ) {
614 global $wgRequest, $wgContLang, $wgUser;
615 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
617 wfProfileIn( __METHOD__
);
619 $this->setupSkinUserCss( $out );
623 'maxage' => $wgSquidMaxage,
626 // Add any extension CSS
627 foreach( $out->getExtStyle() as $tag ) {
628 $out->addStyle( $tag['href'] );
631 // If we use the site's dynamic CSS, throw that in, too
632 // Per-site custom styles
633 if( $wgUseSiteCss ) {
634 global $wgHandheldStyle;
635 $query = wfArrayToCGI( array(
636 'usemsgcache' => 'yes',
637 'ctype' => 'text/css',
638 'smaxage' => $wgSquidMaxage
640 # Site settings must override extension css! (bug 15025)
641 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
642 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
643 if( $wgHandheldStyle ) {
644 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
646 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
649 if( $wgUser->isLoggedIn() ) {
650 // Ensure that logged-in users' generated CSS isn't clobbered
651 // by anons' publicly cacheable generated CSS.
652 $siteargs['smaxage'] = '0';
653 $siteargs['ts'] = $wgUser->mTouched
;
655 // Per-user styles based on preferences
656 $siteargs['gen'] = 'css';
657 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
658 $siteargs['useskin'] = $us;
660 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
662 // Per-user custom style pages
663 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
664 $action = $wgRequest->getVal( 'action' );
665 # If we're previewing the CSS page, use it
666 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
667 $previewCss = $wgRequest->getText( 'wpTextbox1' );
668 // @FIXME: properly escape the cdata!
669 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
671 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
672 'action=raw&ctype=text/css' ) );
676 wfProfileOut( __METHOD__
);
680 * Add skin specific stylesheets
681 * @param $out OutputPage
683 function setupSkinUserCss( OutputPage
$out ) {
684 $out->addStyle( 'common/shared.css' );
685 $out->addStyle( 'common/oldshared.css' );
686 $out->addStyle( $this->getStylesheet() );
687 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
690 function getBodyOptions() {
691 global $wgUser, $wgOut, $wgRequest, $wgContLang;
693 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
695 if ( 0 != $this->mTitle
->getNamespace() ) {
696 $a = array( 'bgcolor' => '#ffffec' );
698 else $a = array( 'bgcolor' => '#FFFFFF' );
699 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
700 $this->mTitle
->quickUserCan( 'edit' ) ) {
701 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
702 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
703 $a +
= array( 'ondblclick' => $s );
705 $a['onload'] = $wgOut->getOnloadHandler();
708 ' '.( $wgContLang->isRTL() ?
'rtl' : 'ltr' ).
709 ' '.$this->getPageClasses( $this->mTitle
) .
710 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
714 function getPageClasses( $title ) {
715 $numeric = 'ns-'.$title->getNamespace();
716 if( $title->getNamespace() == NS_SPECIAL
) {
717 $type = 'ns-special';
718 } elseif( $title->isTalkPage() ) {
721 $type = 'ns-subject';
723 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
724 return "$numeric $type $name";
736 * This will be called immediately after the <body> tag. Split into
737 * two functions to make it easier to subclass.
739 function beforeContent() {
740 return $this->doBeforeContent();
743 function doBeforeContent() {
745 wfProfileIn( __METHOD__
);
748 $qb = $this->qbSetting();
750 if( $langlinks = $this->otherLanguages() ) {
756 $borderhack = 'class="top"';
759 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
760 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
762 $shove = ( $qb != 0 );
763 $left = ( $qb == 1 ||
$qb == 3 );
764 if( $wgContLang->isRTL() ) $left = !$left;
767 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
768 $this->logoText() . '</td>';
770 $s .= $this->getQuickbarCompensator( $rows );
772 $l = $wgContLang->isRTL() ?
'right' : 'left';
773 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
775 $s .= $this->topLinks();
776 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
778 $r = $wgContLang->isRTL() ?
'left' : 'right';
779 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
780 $s .= $this->nameAndLogin();
781 $s .= "\n<br />" . $this->searchForm() . "</td>";
784 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
787 if ( $shove && !$left ) { # Right
788 $s .= $this->getQuickbarCompensator( $rows );
790 $s .= "</tr>\n</table>\n</div>\n";
791 $s .= "\n<div id='article'>\n";
793 $notice = wfGetSiteNotice();
795 $s .= "\n<div id='siteNotice'>$notice</div>\n";
797 $s .= $this->pageTitle();
798 $s .= $this->pageSubtitle();
799 $s .= $this->getCategories();
800 wfProfileOut( __METHOD__
);
805 function getCategoryLinks() {
806 global $wgOut, $wgUseCategoryBrowser;
807 global $wgContLang, $wgUser;
809 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
812 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
814 // Use Unicode bidi embedding override characters,
815 // to make sure links don't smash each other up in ugly ways.
816 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
817 $embed = "<span dir='$dir'>";
820 $allCats = $wgOut->getCategoryLinks();
822 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
823 if ( !empty( $allCats['normal'] ) ) {
824 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
826 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
827 $s .= '<div id="mw-normal-catlinks">' .
828 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
829 . $colon . $t . '</div>';
833 if ( isset( $allCats['hidden'] ) ) {
834 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
835 $class ='mw-hidden-cats-user-shown';
836 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
837 $class = 'mw-hidden-cats-ns-shown';
839 $class = 'mw-hidden-cats-hidden';
841 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
842 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
843 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
847 # optional 'dmoz-like' category browser. Will be shown under the list
848 # of categories an article belong to
849 if( $wgUseCategoryBrowser ){
850 $s .= '<br /><hr />';
852 # get a big array of the parents tree
853 $parenttree = $this->mTitle
->getParentCategoryTree();
854 # Skin object passed by reference cause it can not be
855 # accessed under the method subfunction drawCategoryBrowser
856 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
857 # Clean out bogus first entry and sort them
858 unset( $tempout[0] );
860 # Output one per line
861 $s .= implode( "<br />\n", $tempout );
868 * Render the array as a serie of links.
869 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
870 * @param &skin Object: skin passed by reference
871 * @return String separated by >, terminate with "\n"
873 function drawCategoryBrowser( $tree, &$skin ){
875 foreach( $tree as $element => $parent ) {
876 if( empty( $parent ) ) {
877 # element start a new list
880 # grab the others elements
881 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
883 # add our current element to the list
884 $eltitle = Title
::newFromText( $element );
885 $return .= $skin->link( $eltitle, $eltitle->getText() );
890 function getCategories() {
891 $catlinks=$this->getCategoryLinks();
893 $classes = 'catlinks';
895 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
896 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
897 $classes .= ' catlinks-allhidden';
900 if( !empty( $catlinks ) ){
901 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
905 function getQuickbarCompensator( $rows = 1 ) {
906 return "<td width='152' rowspan='{$rows}'> </td>";
910 * This runs a hook to allow extensions placing their stuff after content
911 * and article metadata (e.g. categories).
912 * Note: This function has nothing to do with afterContent().
914 * This hook is placed here in order to allow using the same hook for all
915 * skins, both the SkinTemplate based ones and the older ones, which directly
916 * use this class to get their data.
918 * The output of this function gets processed in SkinTemplate::outputPage() for
919 * the SkinTemplate based skins, all other skins should directly echo it.
921 * Returns an empty string by default, if not changed by any hook function.
923 protected function afterContentHook() {
926 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
927 // adding just some spaces shouldn't toggle the output
928 // of the whole <div/>, so we use trim() here
929 if( trim( $data ) != '' ){
930 // Doing this here instead of in the skins to
931 // ensure that the div has the same ID in all
933 $data = "<div id='mw-data-after-content'>\n" .
938 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
945 * Generate debug data HTML for displaying at the bottom of the main content
947 * @return String HTML containing debug data, if enabled (otherwise empty).
949 protected function generateDebugHTML() {
950 global $wgShowDebug, $wgOut;
951 if ( $wgShowDebug ) {
952 $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext
) );
953 return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
954 $listInternals . "</li></ul>\n";
960 * This gets called shortly before the </body> tag.
961 * @return String HTML to be put before </body>
963 function afterContent() {
964 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
965 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
969 * This gets called shortly before the </body> tag.
970 * @return String HTML-wrapped JS code to be put before </body>
972 function bottomScripts() {
973 global $wgJsMimeType;
974 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
975 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
976 return $bottomScriptText;
979 /** @return string Retrievied from HTML text */
980 function printSource() {
981 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
982 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
985 function printFooter() {
986 return "<p>" . $this->printSource() .
987 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
990 /** overloaded by derived classes */
991 function doAfterContent() { return '</div></div>'; }
993 function pageTitleLinks() {
994 global $wgOut, $wgUser, $wgRequest, $wgLang;
996 $oldid = $wgRequest->getVal( 'oldid' );
997 $diff = $wgRequest->getVal( 'diff' );
998 $action = $wgRequest->getText( 'action' );
1000 $s[] = $this->printableLink();
1001 $disclaimer = $this->disclaimerLink(); # may be empty
1005 $privacy = $this->privacyLink(); # may be empty too
1010 if ( $wgOut->isArticleRelated() ) {
1011 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1012 $name = $this->mTitle
->getDBkey();
1013 $image = wfFindFile( $this->mTitle
);
1015 $link = htmlspecialchars( $image->getURL() );
1016 $style = $this->getInternalLinkAttributes( $link, $name );
1017 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1021 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1022 $s[] .= $this->link(
1024 wfMsg( 'currentrev' ),
1027 array( 'known', 'noclasses' )
1031 if ( $wgUser->getNewtalk() ) {
1032 # do not show "You have new messages" text when we are viewing our
1034 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1036 $wgUser->getTalkPage(),
1037 wfMsgHtml( 'newmessageslink' ),
1039 array( 'redirect' => 'no' ),
1040 array( 'known', 'noclasses' )
1044 $wgUser->getTalkPage(),
1045 wfMsgHtml( 'newmessagesdifflink' ),
1047 array( 'diff' => 'cur' ),
1048 array( 'known', 'noclasses' )
1050 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1052 $wgOut->setSquidMaxage( 0 );
1053 $wgOut->enableClientCache( false );
1057 $undelete = $this->getUndeleteLink();
1058 if( !empty( $undelete ) ) {
1061 return $wgLang->pipeList( $s );
1064 function getUndeleteLink() {
1065 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1067 $action = $wgRequest->getVal( 'action', 'view' );
1069 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1070 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1071 $n = $this->mTitle
->isDeleted();
1073 if ( $wgUser->isAllowed( 'undelete' ) ) {
1074 $msg = 'thisisdeleted';
1076 $msg = 'viewdeleted';
1081 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1082 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1085 array( 'known', 'noclasses' )
1093 function printableLink() {
1094 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1098 if ( !$wgRequest->getBool( 'printable' ) ) {
1099 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1100 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1103 if( $wgOut->isSyndicated() ) {
1104 foreach( $wgFeedClasses as $format => $class ) {
1105 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1106 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1107 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1110 return $wgLang->pipeList( $s );
1113 function pageTitle() {
1115 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1119 function pageSubtitle() {
1122 $sub = $wgOut->getSubtitle();
1124 global $wgExtraSubtitle;
1125 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1127 $subpages = $this->subPageSubtitle();
1128 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1129 $s = "<p class='subtitle'>{$sub}</p>\n";
1133 function subPageSubtitle() {
1135 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1139 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1140 $ptext = $this->mTitle
->getPrefixedText();
1141 if( preg_match( '/\//', $ptext ) ) {
1142 $links = explode( '/', $ptext );
1143 array_pop( $links );
1147 foreach( $links as $link ) {
1148 $growinglink .= $link;
1150 $linkObj = Title
::newFromText( $growinglink );
1151 if( is_object( $linkObj ) && $linkObj->exists() ){
1152 $getlink = $this->link(
1154 htmlspecialchars( $display ),
1157 array( 'known', 'noclasses' )
1161 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1163 $subpages .= '< ';
1165 $subpages .= $getlink;
1170 $growinglink .= '/';
1178 * Returns true if the IP should be shown in the header
1180 function showIPinHeader() {
1181 global $wgShowIPinHeader;
1182 return $wgShowIPinHeader && session_id() != '';
1185 function nameAndLogin() {
1186 global $wgUser, $wgLang, $wgContLang;
1188 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1191 if ( $wgUser->isAnon() ) {
1192 if( $this->showIPinHeader() ) {
1195 $talkLink = $this->link( $wgUser->getTalkPage(),
1196 $wgLang->getNsText( NS_TALK
) );
1198 $ret .= "$name ($talkLink)";
1200 $ret .= wfMsg( 'notloggedin' );
1203 $returnTo = $this->mTitle
->getPrefixedDBkey();
1205 if ( $logoutPage != $returnTo ) {
1206 $query['returnto'] = $returnTo;
1209 $loginlink = $wgUser->isAllowed( 'createaccount' )
1210 ?
'nav-login-createaccount'
1212 $ret .= "\n<br />" . $this->link(
1213 SpecialPage
::getTitleFor( 'Userlogin' ),
1214 wfMsg( $loginlink ), array(), $query
1217 $returnTo = $this->mTitle
->getPrefixedDBkey();
1218 $talkLink = $this->link( $wgUser->getTalkPage(),
1219 $wgLang->getNsText( NS_TALK
) );
1221 $ret .= $this->link( $wgUser->getUserPage(),
1222 htmlspecialchars( $wgUser->getName() ) );
1223 $ret .= " ($talkLink)<br />";
1224 $ret .= $wgLang->pipeList( array(
1226 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1227 array(), array( 'returnto' => $returnTo )
1229 $this->specialLink( 'preferences' ),
1232 $ret = $wgLang->pipeList( array(
1235 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1243 function getSearchLink() {
1244 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1245 return $searchPage->getLocalURL();
1248 function escapeSearchLink() {
1249 return htmlspecialchars( $this->getSearchLink() );
1252 function searchForm() {
1253 global $wgRequest, $wgUseTwoButtonsSearchForm;
1254 $search = $wgRequest->getText( 'search' );
1256 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1257 . $this->escapeSearchLink() . "\">\n"
1258 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1259 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1260 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1262 if( $wgUseTwoButtonsSearchForm )
1263 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1265 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1269 // Ensure unique id's for search boxes made after the first
1270 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1275 function topLinks() {
1279 $this->mainPageLink(),
1280 $this->specialLink( 'recentchanges' )
1283 if ( $wgOut->isArticleRelated() ) {
1284 $s[] = $this->editThisPage();
1285 $s[] = $this->historyLink();
1287 # Many people don't like this dropdown box
1288 #$s[] = $this->specialPagesList();
1290 if( $this->variantLinks() ) {
1291 $s[] = $this->variantLinks();
1294 if( $this->extensionTabLinks() ) {
1295 $s[] = $this->extensionTabLinks();
1298 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1299 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1303 * Compatibility for extensions adding functionality through tabs.
1304 * Eventually these old skins should be replaced with SkinTemplate-based
1308 function extensionTabLinks() {
1312 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1313 foreach( $tabs as $tab ) {
1314 $s[] = Xml
::element( 'a',
1315 array( 'href' => $tab['href'] ),
1322 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1323 $out .= $wgLang->pipeList( $s );
1330 * Language/charset variant links for classic-style skins
1333 function variantLinks() {
1335 /* show links to different language variants */
1336 global $wgDisableLangConversion, $wgLang, $wgContLang;
1337 $variants = $wgContLang->getVariants();
1338 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1339 foreach( $variants as $code ) {
1340 $varname = $wgContLang->getVariantname( $code );
1341 if( $varname == 'disable' )
1343 $s = $wgLang->pipeList( array(
1345 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1352 function bottomLinks() {
1353 global $wgOut, $wgUser, $wgUseTrackbacks;
1354 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1357 if ( $wgOut->isArticleRelated() ) {
1358 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1359 if ( $wgUser->isLoggedIn() ) {
1360 $element[] = $this->watchThisPage();
1362 $element[] = $this->talkLink();
1363 $element[] = $this->historyLink();
1364 $element[] = $this->whatLinksHere();
1365 $element[] = $this->watchPageLinksLink();
1367 if( $wgUseTrackbacks )
1368 $element[] = $this->trackbackLink();
1370 if ( $this->mTitle
->getNamespace() == NS_USER
1371 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1372 $id = User
::idFromName( $this->mTitle
->getText() );
1373 $ip = User
::isIP( $this->mTitle
->getText() );
1375 if( $id ||
$ip ) { # both anons and non-anons have contri list
1376 $element[] = $this->userContribsLink();
1378 if( $this->showEmailUser( $id ) ) {
1379 $element[] = $this->emailUserLink();
1383 $s = implode( $element, $sep );
1385 if ( $this->mTitle
->getArticleId() ) {
1387 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1388 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1389 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1391 $s .= "<br />\n" . $this->otherLanguages();
1397 function pageStats() {
1398 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1399 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1401 $oldid = $wgRequest->getVal( 'oldid' );
1402 $diff = $wgRequest->getVal( 'diff' );
1403 if ( ! $wgOut->isArticle() ) { return ''; }
1404 if( !$wgArticle instanceOf Article
) { return ''; }
1405 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1406 if ( 0 == $wgArticle->getID() ) { return ''; }
1409 if ( !$wgDisableCounters ) {
1410 $count = $wgLang->formatNum( $wgArticle->getCount() );
1412 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1416 if( $wgMaxCredits != 0 ){
1417 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1419 $s .= $this->lastModified();
1422 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1423 $dbr = wfGetDB( DB_SLAVE
);
1424 $res = $dbr->select( 'watchlist',
1425 array( 'COUNT(*) AS n' ),
1426 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1429 $x = $dbr->fetchObject( $res );
1431 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1432 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1436 return $s . ' ' . $this->getCopyright();
1439 function getCopyright( $type = 'detect' ) {
1440 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1442 if ( $type == 'detect' ) {
1443 $diff = $wgRequest->getVal( 'diff' );
1444 $isCur = $wgArticle && $wgArticle->isCurrent();
1445 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1452 if ( $type == 'history' ) {
1453 $msg = 'history_copyright';
1459 if( $wgRightsPage ) {
1460 $title = Title
::newFromText( $wgRightsPage );
1461 $link = $this->linkKnown( $title, $wgRightsText );
1462 } elseif( $wgRightsUrl ) {
1463 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1464 } elseif( $wgRightsText ) {
1465 $link = $wgRightsText;
1470 // Allow for site and per-namespace customization of copyright notice.
1471 if( isset($wgArticle) )
1472 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1474 $out .= wfMsgForContent( $msg, $link );
1478 function getCopyrightIcon() {
1479 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1481 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1482 $out = $wgCopyrightIcon;
1483 } else if ( $wgRightsIcon ) {
1484 $icon = htmlspecialchars( $wgRightsIcon );
1485 if ( $wgRightsUrl ) {
1486 $url = htmlspecialchars( $wgRightsUrl );
1487 $out .= '<a href="'.$url.'">';
1489 $text = htmlspecialchars( $wgRightsText );
1490 $out .= "<img src=\"$icon\" alt='$text' />";
1491 if ( $wgRightsUrl ) {
1498 function getPoweredBy() {
1499 global $wgStylePath;
1500 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1501 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1505 function lastModified() {
1506 global $wgLang, $wgArticle;
1507 if( $this->mRevisionId
) {
1508 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1510 $timestamp = $wgArticle->getTimestamp();
1513 $d = $wgLang->date( $timestamp, true );
1514 $t = $wgLang->time( $timestamp, true );
1515 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1519 if ( wfGetLB()->getLaggedSlaveMode() ) {
1520 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1525 function logoText( $align = '' ) {
1526 if ( '' != $align ) {
1527 $a = " align='{$align}'";
1532 $mp = wfMsg( 'mainpage' );
1533 $mptitle = Title
::newMainPage();
1534 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1536 $logourl = $this->getLogo();
1537 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1542 * show a drop-down box of special pages
1544 function specialPagesList() {
1545 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1546 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1547 foreach ( $pages as $name => $page ) {
1548 $pages[$name] = $page->getDescription();
1551 $go = wfMsg( 'go' );
1552 $sp = wfMsg( 'specialpages' );
1553 $spp = $wgContLang->specialPage( 'Specialpages' );
1555 $s = '<form id="specialpages" method="get" ' .
1556 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1557 $s .= "<select name=\"wpDropdown\">\n";
1558 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1561 foreach ( $pages as $name => $desc ) {
1562 $p = $wgContLang->specialPage( $name );
1563 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1565 $s .= "</select>\n";
1566 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1571 function mainPageLink() {
1573 Title
::newMainPage(),
1574 wfMsg( 'mainpage' ),
1577 array( 'known', 'noclasses' )
1582 function copyrightLink() {
1583 $title = Title
::newFromText( wfMsgForContent( 'copyrightpage' ) );
1584 $s = $this->linkKnown(
1586 wfMsg( 'copyrightpagename' )
1591 private function footerLink ( $desc, $page ) {
1592 // if the link description has been set to "-" in the default language,
1593 if ( wfMsgForContent( $desc ) == '-') {
1594 // then it is disabled, for all languages.
1597 // Otherwise, we display the link for the user, described in their
1598 // language (which may or may not be the same as the default language),
1599 // but we make the link target be the one site-wide page.
1600 $title = Title
::newFromText( wfMsgForContent( $page ) );
1601 return $this->linkKnown(
1603 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1608 function privacyLink() {
1609 return $this->footerLink( 'privacy', 'privacypage' );
1612 function aboutLink() {
1613 return $this->footerLink( 'aboutsite', 'aboutpage' );
1616 function disclaimerLink() {
1617 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1620 function editThisPage() {
1623 if ( !$wgOut->isArticleRelated() ) {
1624 $s = wfMsg( 'protectedpage' );
1626 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1627 $t = wfMsg( 'editthispage' );
1628 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1629 $t = wfMsg( 'create-this-page' );
1631 $t = wfMsg( 'viewsource' );
1638 $this->editUrlOptions(),
1639 array( 'known', 'noclasses' )
1646 * Return URL options for the 'edit page' link.
1647 * This may include an 'oldid' specifier, if the current page view is such.
1652 function editUrlOptions() {
1655 $options = array( 'action' => 'edit' );
1657 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1658 $options['oldid'] = intval( $this->mRevisionId
);
1664 function deleteThisPage() {
1665 global $wgUser, $wgRequest;
1667 $diff = $wgRequest->getVal( 'diff' );
1668 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1669 $t = wfMsg( 'deletethispage' );
1675 array( 'action' => 'delete' ),
1676 array( 'known', 'noclasses' )
1684 function protectThisPage() {
1685 global $wgUser, $wgRequest;
1687 $diff = $wgRequest->getVal( 'diff' );
1688 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1689 if ( $this->mTitle
->isProtected() ) {
1690 $text = wfMsg( 'unprotectthispage' );
1691 $query = array( 'action' => 'unprotect' );
1693 $text = wfMsg( 'protectthispage' );
1694 $query = array( 'action' => 'protect' );
1702 array( 'known', 'noclasses' )
1710 function watchThisPage() {
1712 ++
$this->mWatchLinkNum
;
1714 if ( $wgOut->isArticleRelated() ) {
1715 if ( $this->mTitle
->userIsWatching() ) {
1716 $text = wfMsg( 'unwatchthispage' );
1717 $query = array( 'action' => 'unwatch' );
1718 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1720 $text = wfMsg( 'watchthispage' );
1721 $query = array( 'action' => 'watch' );
1722 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1728 array( 'id' => $id ),
1730 array( 'known', 'noclasses' )
1733 $s = wfMsg( 'notanarticle' );
1738 function moveThisPage() {
1739 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1741 SpecialPage
::getTitleFor( 'Movepage' ),
1742 wfMsg( 'movethispage' ),
1744 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1745 array( 'known', 'noclasses' )
1748 // no message if page is protected - would be redundant
1753 function historyLink() {
1756 wfMsgHtml( 'history' ),
1757 array( 'rel' => 'archives' ),
1758 array( 'action' => 'history' )
1762 function whatLinksHere() {
1764 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1765 wfMsgHtml( 'whatlinkshere' ),
1768 array( 'known', 'noclasses' )
1772 function userContribsLink() {
1774 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1775 wfMsgHtml( 'contributions' ),
1778 array( 'known', 'noclasses' )
1782 function showEmailUser( $id ) {
1784 $targetUser = User
::newFromId( $id );
1785 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1786 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1789 function emailUserLink() {
1791 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1792 wfMsg( 'emailuser' ),
1795 array( 'known', 'noclasses' )
1799 function watchPageLinksLink() {
1801 if ( ! $wgOut->isArticleRelated() ) {
1802 return '(' . wfMsg( 'notanarticle' ) . ')';
1805 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1806 wfMsg( 'recentchangeslinked-toolbox' ),
1809 array( 'known', 'noclasses' )
1814 function trackbackLink() {
1815 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1816 . wfMsg( 'trackbacklink' ) . '</a>';
1819 function otherLanguages() {
1820 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1822 if ( $wgHideInterlanguageLinks ) {
1826 $a = $wgOut->getLanguageLinks();
1827 if ( 0 == count( $a ) ) {
1831 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1833 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1834 foreach( $a as $l ) {
1836 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1840 $nt = Title
::newFromText( $l );
1841 $url = $nt->escapeFullURL();
1842 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1844 if ( '' == $text ) { $text = $l; }
1845 $style = $this->getExternalLinkAttributes();
1846 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1848 if( $wgContLang->isRTL() ) $s .= '</span>';
1852 function talkLink() {
1853 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1854 # No discussion links for special pages
1858 $linkOptions = array();
1860 if( $this->mTitle
->isTalkPage() ) {
1861 $link = $this->mTitle
->getSubjectPage();
1862 switch( $link->getNamespace() ) {
1864 $text = wfMsg( 'articlepage' );
1867 $text = wfMsg( 'userpage' );
1870 $text = wfMsg( 'projectpage' );
1873 $text = wfMsg( 'imagepage' );
1874 # Make link known if image exists, even if the desc. page doesn't.
1875 if( wfFindFile( $link ) )
1876 $linkOptions[] = 'known';
1879 $text = wfMsg( 'mediawikipage' );
1882 $text = wfMsg( 'templatepage' );
1885 $text = wfMsg( 'viewhelppage' );
1888 $text = wfMsg( 'categorypage' );
1891 $text = wfMsg( 'articlepage' );
1894 $link = $this->mTitle
->getTalkPage();
1895 $text = wfMsg( 'talkpage' );
1898 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1903 function commentLink() {
1906 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1910 # __NEWSECTIONLINK___ changes behaviour here
1911 # If it is present, the link points to this page, otherwise
1912 # it points to the talk page
1913 if( $this->mTitle
->isTalkPage() ) {
1914 $title = $this->mTitle
;
1915 } elseif( $wgOut->showNewSectionLink() ) {
1916 $title = $this->mTitle
;
1918 $title = $this->mTitle
->getTalkPage();
1923 wfMsg( 'postcomment' ),
1929 array( 'known', 'noclasses' )
1933 /* these are used extensively in SkinTemplate, but also some other places */
1934 static function makeMainPageUrl( $urlaction = '' ) {
1935 $title = Title
::newMainPage();
1936 self
::checkTitle( $title, '' );
1937 return $title->getLocalURL( $urlaction );
1940 static function makeSpecialUrl( $name, $urlaction = '' ) {
1941 $title = SpecialPage
::getTitleFor( $name );
1942 return $title->getLocalURL( $urlaction );
1945 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1946 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1947 return $title->getLocalURL( $urlaction );
1950 static function makeI18nUrl( $name, $urlaction = '' ) {
1951 $title = Title
::newFromText( wfMsgForContent( $name ) );
1952 self
::checkTitle( $title, $name );
1953 return $title->getLocalURL( $urlaction );
1956 static function makeUrl( $name, $urlaction = '' ) {
1957 $title = Title
::newFromText( $name );
1958 self
::checkTitle( $title, $name );
1959 return $title->getLocalURL( $urlaction );
1962 # If url string starts with http, consider as external URL, else
1964 static function makeInternalOrExternalUrl( $name ) {
1965 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1968 return self
::makeUrl( $name );
1972 # this can be passed the NS number as defined in Language.php
1973 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1974 $title = Title
::makeTitleSafe( $namespace, $name );
1975 self
::checkTitle( $title, $name );
1976 return $title->getLocalURL( $urlaction );
1979 /* these return an array with the 'href' and boolean 'exists' */
1980 static function makeUrlDetails( $name, $urlaction = '' ) {
1981 $title = Title
::newFromText( $name );
1982 self
::checkTitle( $title, $name );
1984 'href' => $title->getLocalURL( $urlaction ),
1985 'exists' => $title->getArticleID() != 0 ?
true : false
1990 * Make URL details where the article exists (or at least it's convenient to think so)
1992 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1993 $title = Title
::newFromText( $name );
1994 self
::checkTitle( $title, $name );
1996 'href' => $title->getLocalURL( $urlaction ),
2001 # make sure we have some title to operate on
2002 static function checkTitle( &$title, $name ) {
2003 if( !is_object( $title ) ) {
2004 $title = Title
::newFromText( $name );
2005 if( !is_object( $title ) ) {
2006 $title = Title
::newFromText( '--error: link target missing--' );
2012 * Build an array that represents the sidebar(s), the navigation bar among them
2016 function buildSidebar() {
2017 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2019 wfProfileIn( __METHOD__
);
2021 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2023 if ( $wgEnableSidebarCache ) {
2024 $cachedsidebar = $parserMemc->get( $key );
2025 if ( $cachedsidebar ) {
2026 wfProfileOut( __METHOD__
);
2027 return $cachedsidebar;
2032 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
2034 foreach( $lines as $line ) {
2035 if( strpos( $line, '*' ) !== 0 )
2037 if( strpos( $line, '**') !== 0 ) {
2038 $heading = trim( $line, '* ' );
2039 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
2041 if( strpos( $line, '|' ) !== false ) { // sanity check
2042 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2043 $link = wfMsgForContent( $line[0] );
2047 $text = wfMsgExt( $line[1], 'parsemag' );
2048 if( wfEmptyMsg( $line[1], $text ) )
2050 if( wfEmptyMsg( $line[0], $link ) )
2053 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2056 $title = Title
::newFromText( $link );
2058 $title = $title->fixSpecialName();
2059 $href = $title->getLocalURL();
2061 $href = 'INVALID-TITLE';
2065 $bar[$heading][] = array(
2068 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2071 } else { continue; }
2074 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2075 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2076 wfProfileOut( __METHOD__
);
2081 * Should we include common/wikiprintable.css? Skins that have their own
2082 * print stylesheet should override this and return false. (This is an
2083 * ugly hack to get Monobook to play nicely with
2084 * OutputPage::headElement().)
2088 public function commonPrintStylesheet() {