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 ) {
338 foreach ( $data as $name => $value ) {
339 $encValue = Xml
::encodeJsVar( $value );
340 $r[] = "$name=$encValue";
342 $js = 'var ' . implode( ",\n", $r ) . ';';
343 return Html
::inlineScript( "\n$js\n" );
350 * Make a <script> tag containing global variables
351 * @param $skinName string Name of the skin
352 * The odd calling convention is for backwards compatibility
353 * @TODO @FIXME Make this not depend on $wgTitle!
355 static function makeGlobalVariablesScript( $skinName ) {
356 if ( is_array( $skinName ) ) {
357 # Weird back-compat stuff.
358 $skinName = $skinName['skinname'];
360 global $wgScript, $wgTitle, $wgStylePath, $wgUser;
361 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang, $wgVariant;
362 global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
363 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
364 global $wgUseAjax, $wgAjaxWatch;
365 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
366 global $wgRestrictionTypes, $wgLivePreview;
367 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
369 $ns = $wgTitle->getNamespace();
370 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ?
$wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
371 $separatorTransTable = $wgContLang->separatorTransformTable();
372 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
373 $compactSeparatorTransTable = array(
374 implode( "\t", array_keys( $separatorTransTable ) ),
375 implode( "\t", $separatorTransTable ),
377 $digitTransTable = $wgContLang->digitTransformTable();
378 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
379 $compactDigitTransTable = array(
380 implode( "\t", array_keys( $digitTransTable ) ),
381 implode( "\t", $digitTransTable ),
384 $mainPage = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
387 'stylepath' => $wgStylePath,
388 'wgArticlePath' => $wgArticlePath,
389 'wgScriptPath' => $wgScriptPath,
390 'wgScript' => $wgScript,
391 'wgVariantArticlePath' => $wgVariantArticlePath,
392 'wgActionPaths' => (object)$wgActionPaths,
393 'wgServer' => $wgServer,
394 'wgCanonicalNamespace' => $nsname,
395 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBkey() ),
396 'wgNamespaceNumber' => $wgTitle->getNamespace(),
397 'wgPageName' => $wgTitle->getPrefixedDBKey(),
398 'wgTitle' => $wgTitle->getText(),
399 'wgAction' => $wgRequest->getText( 'action', 'view' ),
400 'wgArticleId' => $wgTitle->getArticleId(),
401 'wgIsArticle' => $wgOut->isArticle(),
402 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
403 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
404 'wgUserVariant' => $wgVariant->getCode(),
405 'wgUserLanguage' => $wgLang->getCode(),
406 'wgContentLanguage' => $wgContLang->getCode(),
407 'wgBreakFrames' => $wgBreakFrames,
408 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
409 'wgVersion' => $wgVersion,
410 'wgEnableAPI' => $wgEnableAPI,
411 'wgEnableWriteAPI' => $wgEnableWriteAPI,
412 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
413 'wgDigitTransformTable' => $compactDigitTransTable,
414 'wgMainPageTitle' => $mainPage ?
$mainPage->getPrefixedText() : null,
416 if ( !( $wgContLang->hasVariants() ) ) {
417 unset( $vars['wgUserVariant'] );
420 //if on upload page output the extension list & js_upload
421 if( SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) == "Upload" ){
422 global $wgFileExtensions, $wgAjaxUploadInterface;
423 $vars['wgFileExtensions'] = $wgFileExtensions;
424 $vars['wgAjaxUploadInterface'] = $wgAjaxUploadInterface;
427 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
428 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
429 $vars['wgDBname'] = $wgDBname;
430 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
431 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
434 foreach( $wgRestrictionTypes as $type )
435 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
437 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
438 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
439 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
440 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
441 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
444 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
445 $msgs = (object)array();
446 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
447 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
449 $vars['wgAjaxWatch'] = $msgs;
452 // Allow extensions to add their custom variables to the global JS variables
453 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
455 return self
::makeVariablesScript( $vars );
458 * Return a random selection of the scripts we want in the header,
459 * according to no particular rhyme or reason. Various other scripts are
460 * returned from a haphazard assortment of other functions scattered over
461 * various files. This entire hackish system needs to be burned to the
462 * ground and rebuilt.
464 * @param $out OutputPage object, should be $wgOut
466 * @return string Raw HTML to output to <head>
468 function getHeadScripts( OutputPage
$out ) {
469 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion, $wgOut;
472 $vars = self
::makeGlobalVariablesScript( $this->getSkinName() );
474 //moved wikibits to be called earlier on
475 //$out->addScriptFile( "{$wgStylePath}/common/wikibits.js" );
477 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
478 $wgOut->addScriptFile( self
::makeUrl( '-',
479 "action=raw$jsCache&gen=js&useskin=" .
480 urlencode( $this->getSkinName() )
484 if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
485 $userpage = $wgUser->getUserPage();
486 $userjs = self
::makeUrl(
487 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
488 'action=raw&ctype='.$wgJsMimeType );
489 $wgOut->addScriptFile( $userjs );
491 return "\t" . $vars . "\t" . $out->mScripts
;
495 * To make it harder for someone to slip a user a fake
496 * user-JavaScript or user-CSS preview, a random token
497 * is associated with the login session. If it's not
498 * passed back with the preview request, we won't render
501 * @param string $action
505 function userCanPreview( $action ) {
506 global $wgRequest, $wgUser;
508 if( $action != 'submit' )
510 if( !$wgRequest->wasPosted() )
512 if( !$this->mTitle
->userCanEditCssSubpage() )
514 if( !$this->mTitle
->userCanEditJsSubpage() )
516 return $wgUser->matchEditToken(
517 $wgRequest->getVal( 'wpEditToken' ) );
521 * generated JavaScript action=raw&gen=js
522 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
523 * nated together. For some bizarre reason, it does *not* return any
524 * custom user JS from subpages. Huh?
526 * There's absolutely no reason to have separate Monobook/Common JSes.
527 * Any JS that cares can just check the skin variable generated at the
528 * top. For now Monobook.js will be maintained, but it should be consi-
531 * @param force_skin lets you override the skin name
535 public function generateUserJs( $skinName = null) {
538 wfProfileIn( __METHOD__
);
540 $skinName = $this->getSkinName();
543 $s = "/* generated javascript */\n";
544 $s .= "var skin = '" . Xml
::escapeJsString($skinName ) . "';\n";
545 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
546 $s .= "\n\n/* MediaWiki:Common.js */\n";
547 $commonJs = wfMsgForContent( 'common.js' );
548 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
552 $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n";
553 // avoid inclusion of non defined user JavaScript (with custom skins only)
554 // by checking for default message content
555 $msgKey = ucfirst( $skinName ).'.js';
556 $userJS = wfMsgForContent( $msgKey );
557 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
561 wfProfileOut( __METHOD__
);
566 * Generate user stylesheet for action=raw&gen=css
568 public function generateUserStylesheet() {
569 wfProfileIn( __METHOD__
);
570 $s = "/* generated user stylesheet */\n" .
571 $this->reallyGenerateUserStylesheet();
572 wfProfileOut( __METHOD__
);
577 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
579 protected function reallyGenerateUserStylesheet(){
582 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
583 $underline = $undopt ?
'underline' : 'none';
584 $s .= "a { text-decoration: $underline; }\n";
586 if( $wgUser->getOption( 'highlightbroken' ) ) {
587 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
590 a.new, #quickbar a.new,
591 a.stub, #quickbar a.stub {
594 a.new:after, #quickbar a.new:after {
598 a.stub:after, #quickbar a.stub:after {
604 if( $wgUser->getOption( 'justify' ) ) {
605 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
607 if( !$wgUser->getOption( 'showtoc' ) ) {
608 $s .= "#toc { display: none; }\n";
610 if( !$wgUser->getOption( 'editsection' ) ) {
611 $s .= ".editsection { display: none; }\n";
613 $fontstyle = $wgUser->getOption( 'editfont' );
614 if ( $fontstyle !== 'default' ) {
615 $s .= "textarea { font-family: $fontstyle; }\n";
623 function setupUserCss( OutputPage
$out ) {
624 global $wgRequest, $wgContLang, $wgUser;
625 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
627 wfProfileIn( __METHOD__
);
629 $this->setupSkinUserCss( $out );
633 'maxage' => $wgSquidMaxage,
636 // Add any extension CSS
637 foreach ( $out->getExtStyle() as $url ) {
638 $out->addStyle( $url );
641 // If we use the site's dynamic CSS, throw that in, too
642 // Per-site custom styles
643 if( $wgUseSiteCss ) {
644 global $wgHandheldStyle;
645 $query = wfArrayToCGI( array(
646 'usemsgcache' => 'yes',
647 'ctype' => 'text/css',
648 'smaxage' => $wgSquidMaxage
650 # Site settings must override extension css! (bug 15025)
651 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
652 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
653 if( $wgHandheldStyle ) {
654 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
656 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
659 if( $wgUser->isLoggedIn() ) {
660 // Ensure that logged-in users' generated CSS isn't clobbered
661 // by anons' publicly cacheable generated CSS.
662 $siteargs['smaxage'] = '0';
663 $siteargs['ts'] = $wgUser->mTouched
;
665 // Per-user styles based on preferences
666 $siteargs['gen'] = 'css';
667 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
668 $siteargs['useskin'] = $us;
670 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
672 // Per-user custom style pages
673 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
674 $action = $wgRequest->getVal( 'action' );
675 # If we're previewing the CSS page, use it
676 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
677 $previewCss = $wgRequest->getText( 'wpTextbox1' );
678 // @FIXME: properly escape the cdata!
679 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
681 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
682 'action=raw&ctype=text/css' ) );
686 wfProfileOut( __METHOD__
);
690 * Add skin specific stylesheets
691 * @param $out OutputPage
693 function setupSkinUserCss( OutputPage
$out ) {
694 $out->addStyle( 'common/shared.css' );
695 $out->addStyle( 'common/oldshared.css' );
696 $out->addStyle( $this->getStylesheet() );
697 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
700 function getBodyOptions() {
701 global $wgUser, $wgOut, $wgRequest, $wgContLang;
703 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
705 if ( 0 != $this->mTitle
->getNamespace() ) {
706 $a = array( 'bgcolor' => '#ffffec' );
708 else $a = array( 'bgcolor' => '#FFFFFF' );
709 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
710 $this->mTitle
->quickUserCan( 'edit' ) ) {
711 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
712 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
713 $a +
= array( 'ondblclick' => $s );
715 $a['onload'] = $wgOut->getOnloadHandler();
718 ' '.( $wgContLang->getDir() ).
719 ' '.$this->getPageClasses( $this->mTitle
) .
720 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
724 function getPageClasses( $title ) {
725 $numeric = 'ns-'.$title->getNamespace();
726 if( $title->getNamespace() == NS_SPECIAL
) {
727 $type = 'ns-special';
728 } elseif( $title->isTalkPage() ) {
731 $type = 'ns-subject';
733 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
734 return "$numeric $type $name";
746 * This will be called immediately after the <body> tag. Split into
747 * two functions to make it easier to subclass.
749 function beforeContent() {
750 return $this->doBeforeContent();
753 function doBeforeContent() {
755 wfProfileIn( __METHOD__
);
758 $qb = $this->qbSetting();
760 if( $langlinks = $this->otherLanguages() ) {
766 $borderhack = 'class="top"';
769 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
770 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
772 $shove = ( $qb != 0 );
773 $left = ( $qb == 1 ||
$qb == 3 );
774 if( $wgContLang->isRTL() ) $left = !$left;
777 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
778 $this->logoText() . '</td>';
780 $s .= $this->getQuickbarCompensator( $rows );
782 $l = $wgContLang->alignStart();
783 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
785 $s .= $this->topLinks();
786 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
788 $r = $wgContLang->alignEnd();
789 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
790 $s .= $this->nameAndLogin();
791 $s .= "\n<br />" . $this->searchForm() . "</td>";
794 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
797 if ( $shove && !$left ) { # Right
798 $s .= $this->getQuickbarCompensator( $rows );
800 $s .= "</tr>\n</table>\n</div>\n";
801 $s .= "\n<div id='article'>\n";
803 $notice = wfGetSiteNotice();
805 $s .= "\n<div id='siteNotice'>$notice</div>\n";
807 $s .= $this->pageTitle();
808 $s .= $this->pageSubtitle();
809 $s .= $this->getCategories();
810 wfProfileOut( __METHOD__
);
815 function getCategoryLinks() {
816 global $wgOut, $wgUseCategoryBrowser;
817 global $wgContLang, $wgUser;
819 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
822 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
824 // Use Unicode bidi embedding override characters,
825 // to make sure links don't smash each other up in ugly ways.
826 $dir = $wgContLang->getDir();
827 $embed = "<span dir='$dir'>";
830 $allCats = $wgOut->getCategoryLinks();
832 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
833 if ( !empty( $allCats['normal'] ) ) {
834 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
836 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
837 $s .= '<div id="mw-normal-catlinks">' .
838 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
839 . $colon . $t . '</div>';
843 if ( isset( $allCats['hidden'] ) ) {
844 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
845 $class ='mw-hidden-cats-user-shown';
846 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
847 $class = 'mw-hidden-cats-ns-shown';
849 $class = 'mw-hidden-cats-hidden';
851 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
852 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
853 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
857 # optional 'dmoz-like' category browser. Will be shown under the list
858 # of categories an article belong to
859 if( $wgUseCategoryBrowser ){
860 $s .= '<br /><hr />';
862 # get a big array of the parents tree
863 $parenttree = $this->mTitle
->getParentCategoryTree();
864 # Skin object passed by reference cause it can not be
865 # accessed under the method subfunction drawCategoryBrowser
866 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
867 # Clean out bogus first entry and sort them
868 unset( $tempout[0] );
870 # Output one per line
871 $s .= implode( "<br />\n", $tempout );
878 * Render the array as a serie of links.
879 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
880 * @param &skin Object: skin passed by reference
881 * @return String separated by >, terminate with "\n"
883 function drawCategoryBrowser( $tree, &$skin ){
885 foreach( $tree as $element => $parent ) {
886 if( empty( $parent ) ) {
887 # element start a new list
890 # grab the others elements
891 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
893 # add our current element to the list
894 $eltitle = Title
::newFromText( $element );
895 $return .= $skin->link( $eltitle, $eltitle->getText() );
900 function getCategories() {
901 $catlinks=$this->getCategoryLinks();
903 $classes = 'catlinks';
905 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
906 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
907 $classes .= ' catlinks-allhidden';
910 if( !empty( $catlinks ) ){
911 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
915 function getQuickbarCompensator( $rows = 1 ) {
916 return "<td width='152' rowspan='{$rows}'> </td>";
920 * This runs a hook to allow extensions placing their stuff after content
921 * and article metadata (e.g. categories).
922 * Note: This function has nothing to do with afterContent().
924 * This hook is placed here in order to allow using the same hook for all
925 * skins, both the SkinTemplate based ones and the older ones, which directly
926 * use this class to get their data.
928 * The output of this function gets processed in SkinTemplate::outputPage() for
929 * the SkinTemplate based skins, all other skins should directly echo it.
931 * Returns an empty string by default, if not changed by any hook function.
933 protected function afterContentHook() {
936 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
937 // adding just some spaces shouldn't toggle the output
938 // of the whole <div/>, so we use trim() here
939 if( trim( $data ) != '' ){
940 // Doing this here instead of in the skins to
941 // ensure that the div has the same ID in all
943 $data = "<div id='mw-data-after-content'>\n" .
948 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
955 * Generate debug data HTML for displaying at the bottom of the main content
957 * @return String HTML containing debug data, if enabled (otherwise empty).
959 protected function generateDebugHTML() {
960 global $wgShowDebug, $wgOut;
961 if ( $wgShowDebug ) {
962 $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext
) );
963 return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
964 $listInternals . "</li></ul>\n";
970 * This gets called shortly before the </body> tag.
971 * @return String HTML to be put before </body>
973 function afterContent() {
974 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
975 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
979 * This gets called shortly before the </body> tag.
980 * @return String HTML-wrapped JS code to be put before </body>
982 function bottomScripts() {
983 $bottomScriptText = "\n\t\t" . Html
::inlineScript( 'if (window.runOnloadHook) runOnloadHook();' ) . "\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() ) ) {
1045 $wgUser->getTalkPage(),
1046 wfMsgHtml( 'newmessageslink' ),
1048 array( 'redirect' => 'no' ),
1049 array( 'known', 'noclasses' )
1053 $wgUser->getTalkPage(),
1054 wfMsgHtml( 'newmessagesdifflink' ),
1056 array( 'diff' => 'cur' ),
1057 array( 'known', 'noclasses' )
1059 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1061 $wgOut->setSquidMaxage( 0 );
1062 $wgOut->enableClientCache( false );
1066 $undelete = $this->getUndeleteLink();
1067 if( !empty( $undelete ) ) {
1070 return $wgLang->pipeList( $s );
1073 function getUndeleteLink() {
1074 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1076 $action = $wgRequest->getVal( 'action', 'view' );
1078 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1079 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1080 $n = $this->mTitle
->isDeleted();
1082 if ( $wgUser->isAllowed( 'undelete' ) ) {
1083 $msg = 'thisisdeleted';
1085 $msg = 'viewdeleted';
1090 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1091 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1094 array( 'known', 'noclasses' )
1102 function printableLink() {
1103 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1107 if ( !$wgRequest->getBool( 'printable' ) ) {
1108 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1109 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1112 if( $wgOut->isSyndicated() ) {
1113 foreach( $wgFeedClasses as $format => $class ) {
1114 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1115 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1116 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1119 return $wgLang->pipeList( $s );
1122 function pageTitle() {
1124 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1128 function pageSubtitle() {
1131 $sub = $wgOut->getSubtitle();
1133 global $wgExtraSubtitle;
1134 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1136 $subpages = $this->subPageSubtitle();
1137 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1138 $s = "<p class='subtitle'>{$sub}</p>\n";
1142 function subPageSubtitle() {
1144 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1148 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1149 $ptext = $this->mTitle
->getPrefixedText();
1150 if( preg_match( '/\//', $ptext ) ) {
1151 $links = explode( '/', $ptext );
1152 array_pop( $links );
1156 foreach( $links as $link ) {
1157 $growinglink .= $link;
1159 $linkObj = Title
::newFromText( $growinglink );
1160 if( is_object( $linkObj ) && $linkObj->exists() ){
1161 $getlink = $this->link(
1163 htmlspecialchars( $display ),
1166 array( 'known', 'noclasses' )
1170 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1172 $subpages .= '< ';
1174 $subpages .= $getlink;
1179 $growinglink .= '/';
1187 * Returns true if the IP should be shown in the header
1189 function showIPinHeader() {
1190 global $wgShowIPinHeader;
1191 return $wgShowIPinHeader && session_id() != '';
1194 function nameAndLogin() {
1195 global $wgUser, $wgLang, $wgContLang;
1197 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1200 if ( $wgUser->isAnon() ) {
1201 if( $this->showIPinHeader() ) {
1204 $talkLink = $this->link( $wgUser->getTalkPage(),
1205 $wgLang->getNsText( NS_TALK
) );
1207 $ret .= "$name ($talkLink)";
1209 $ret .= wfMsg( 'notloggedin' );
1212 $returnTo = $this->mTitle
->getPrefixedDBkey();
1214 if ( $logoutPage != $returnTo ) {
1215 $query['returnto'] = $returnTo;
1218 $loginlink = $wgUser->isAllowed( 'createaccount' )
1219 ?
'nav-login-createaccount'
1221 $ret .= "\n<br />" . $this->link(
1222 SpecialPage
::getTitleFor( 'Userlogin' ),
1223 wfMsg( $loginlink ), array(), $query
1226 $returnTo = $this->mTitle
->getPrefixedDBkey();
1227 $talkLink = $this->link( $wgUser->getTalkPage(),
1228 $wgLang->getNsText( NS_TALK
) );
1230 $ret .= $this->link( $wgUser->getUserPage(),
1231 htmlspecialchars( $wgUser->getName() ) );
1232 $ret .= " ($talkLink)<br />";
1233 $ret .= $wgLang->pipeList( array(
1235 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1236 array(), array( 'returnto' => $returnTo )
1238 $this->specialLink( 'preferences' ),
1241 $ret = $wgLang->pipeList( array(
1244 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1252 function getSearchLink() {
1253 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1254 return $searchPage->getLocalURL();
1257 function escapeSearchLink() {
1258 return htmlspecialchars( $this->getSearchLink() );
1261 function searchForm() {
1262 global $wgRequest, $wgUseTwoButtonsSearchForm;
1263 $search = $wgRequest->getText( 'search' );
1265 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1266 . $this->escapeSearchLink() . "\">\n"
1267 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1268 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1269 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1271 if( $wgUseTwoButtonsSearchForm )
1272 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1274 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1278 // Ensure unique id's for search boxes made after the first
1279 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1284 function topLinks() {
1288 $this->mainPageLink(),
1289 $this->specialLink( 'recentchanges' )
1292 if ( $wgOut->isArticleRelated() ) {
1293 $s[] = $this->editThisPage();
1294 $s[] = $this->historyLink();
1296 # Many people don't like this dropdown box
1297 #$s[] = $this->specialPagesList();
1299 if( $this->variantLinks() ) {
1300 $s[] = $this->variantLinks();
1303 if( $this->extensionTabLinks() ) {
1304 $s[] = $this->extensionTabLinks();
1307 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1308 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1312 * Compatibility for extensions adding functionality through tabs.
1313 * Eventually these old skins should be replaced with SkinTemplate-based
1317 function extensionTabLinks() {
1321 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1322 foreach( $tabs as $tab ) {
1323 $s[] = Xml
::element( 'a',
1324 array( 'href' => $tab['href'] ),
1331 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1332 $out .= $wgLang->pipeList( $s );
1339 * Language/charset variant links for classic-style skins
1342 function variantLinks() {
1344 /* show links to different language variants */
1345 global $wgDisableLangConversion, $wgLang, $wgContLang;
1346 $variants = $wgContLang->getVariants();
1347 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1348 foreach( $variants as $code ) {
1349 $varname = $wgContLang->getVariantname( $code );
1350 if( $varname == 'disable' )
1352 $s = $wgLang->pipeList( array(
1354 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1361 function bottomLinks() {
1362 global $wgOut, $wgUser, $wgUseTrackbacks;
1363 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1366 if ( $wgOut->isArticleRelated() ) {
1367 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1368 if ( $wgUser->isLoggedIn() ) {
1369 $element[] = $this->watchThisPage();
1371 $element[] = $this->talkLink();
1372 $element[] = $this->historyLink();
1373 $element[] = $this->whatLinksHere();
1374 $element[] = $this->watchPageLinksLink();
1376 if( $wgUseTrackbacks )
1377 $element[] = $this->trackbackLink();
1379 if ( $this->mTitle
->getNamespace() == NS_USER
1380 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1381 $id = User
::idFromName( $this->mTitle
->getText() );
1382 $ip = User
::isIP( $this->mTitle
->getText() );
1384 if( $id ||
$ip ) { # both anons and non-anons have contri list
1385 $element[] = $this->userContribsLink();
1387 if( $this->showEmailUser( $id ) ) {
1388 $element[] = $this->emailUserLink();
1392 $s = implode( $element, $sep );
1394 if ( $this->mTitle
->getArticleId() ) {
1396 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1397 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1398 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1400 $s .= "<br />\n" . $this->otherLanguages();
1406 function pageStats() {
1407 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1408 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1410 $oldid = $wgRequest->getVal( 'oldid' );
1411 $diff = $wgRequest->getVal( 'diff' );
1412 if ( ! $wgOut->isArticle() ) { return ''; }
1413 if( !$wgArticle instanceOf Article
) { return ''; }
1414 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1415 if ( 0 == $wgArticle->getID() ) { return ''; }
1418 if ( !$wgDisableCounters ) {
1419 $count = $wgLang->formatNum( $wgArticle->getCount() );
1421 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1425 if( $wgMaxCredits != 0 ){
1426 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1428 $s .= $this->lastModified();
1431 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1432 $dbr = wfGetDB( DB_SLAVE
);
1433 $res = $dbr->select( 'watchlist',
1434 array( 'COUNT(*) AS n' ),
1435 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1438 $x = $dbr->fetchObject( $res );
1440 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1441 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1445 return $s . ' ' . $this->getCopyright();
1448 function getCopyright( $type = 'detect' ) {
1449 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1451 if ( $type == 'detect' ) {
1452 $diff = $wgRequest->getVal( 'diff' );
1453 $isCur = $wgArticle && $wgArticle->isCurrent();
1454 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1461 if ( $type == 'history' ) {
1462 $msg = 'history_copyright';
1468 if( $wgRightsPage ) {
1469 $title = Title
::newFromText( $wgRightsPage );
1470 $link = $this->linkKnown( $title, $wgRightsText );
1471 } elseif( $wgRightsUrl ) {
1472 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1473 } elseif( $wgRightsText ) {
1474 $link = $wgRightsText;
1479 // Allow for site and per-namespace customization of copyright notice.
1480 if( isset($wgArticle) )
1481 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1483 $out .= wfMsgForContent( $msg, $link );
1487 function getCopyrightIcon() {
1488 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1490 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1491 $out = $wgCopyrightIcon;
1492 } else if ( $wgRightsIcon ) {
1493 $icon = htmlspecialchars( $wgRightsIcon );
1494 if ( $wgRightsUrl ) {
1495 $url = htmlspecialchars( $wgRightsUrl );
1496 $out .= '<a href="'.$url.'">';
1498 $text = htmlspecialchars( $wgRightsText );
1499 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1500 if ( $wgRightsUrl ) {
1507 function getPoweredBy() {
1508 global $wgStylePath;
1509 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1510 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1514 function lastModified() {
1515 global $wgLang, $wgArticle;
1516 if( $this->mRevisionId
) {
1517 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1519 $timestamp = $wgArticle->getTimestamp();
1522 $d = $wgLang->date( $timestamp, true );
1523 $t = $wgLang->time( $timestamp, true );
1524 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1528 if ( wfGetLB()->getLaggedSlaveMode() ) {
1529 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1534 function logoText( $align = '' ) {
1535 if ( '' != $align ) {
1536 $a = " align='{$align}'";
1541 $mp = wfMsg( 'mainpage' );
1542 $mptitle = Title
::newMainPage();
1543 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1545 $logourl = $this->getLogo();
1546 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1551 * show a drop-down box of special pages
1553 function specialPagesList() {
1554 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1555 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1556 foreach ( $pages as $name => $page ) {
1557 $pages[$name] = $page->getDescription();
1560 $go = wfMsg( 'go' );
1561 $sp = wfMsg( 'specialpages' );
1562 $spp = $wgContLang->specialPage( 'Specialpages' );
1564 $s = '<form id="specialpages" method="get" ' .
1565 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1566 $s .= "<select name=\"wpDropdown\">\n";
1567 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1570 foreach ( $pages as $name => $desc ) {
1571 $p = $wgContLang->specialPage( $name );
1572 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1574 $s .= "</select>\n";
1575 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1580 function mainPageLink() {
1582 Title
::newMainPage(),
1583 wfMsg( 'mainpage' ),
1586 array( 'known', 'noclasses' )
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() {