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";
607 $fontstyle = $wgUser->getOption( 'editfont' );
608 if ( $fontstyle !== 'default' ) {
609 $s .= "textarea { font-family: $fontstyle; }\n";
617 function setupUserCss( OutputPage
$out ) {
618 global $wgRequest, $wgContLang, $wgUser;
619 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
621 wfProfileIn( __METHOD__
);
623 $this->setupSkinUserCss( $out );
627 'maxage' => $wgSquidMaxage,
630 // Add any extension CSS
631 foreach( $out->getExtStyle() as $tag ) {
632 $out->addStyle( $tag['href'] );
635 // If we use the site's dynamic CSS, throw that in, too
636 // Per-site custom styles
637 if( $wgUseSiteCss ) {
638 global $wgHandheldStyle;
639 $query = wfArrayToCGI( array(
640 'usemsgcache' => 'yes',
641 'ctype' => 'text/css',
642 'smaxage' => $wgSquidMaxage
644 # Site settings must override extension css! (bug 15025)
645 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
646 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
647 if( $wgHandheldStyle ) {
648 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
650 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
653 if( $wgUser->isLoggedIn() ) {
654 // Ensure that logged-in users' generated CSS isn't clobbered
655 // by anons' publicly cacheable generated CSS.
656 $siteargs['smaxage'] = '0';
657 $siteargs['ts'] = $wgUser->mTouched
;
659 // Per-user styles based on preferences
660 $siteargs['gen'] = 'css';
661 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
662 $siteargs['useskin'] = $us;
664 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
666 // Per-user custom style pages
667 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
668 $action = $wgRequest->getVal( 'action' );
669 # If we're previewing the CSS page, use it
670 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
671 $previewCss = $wgRequest->getText( 'wpTextbox1' );
672 // @FIXME: properly escape the cdata!
673 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
675 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
676 'action=raw&ctype=text/css' ) );
680 wfProfileOut( __METHOD__
);
684 * Add skin specific stylesheets
685 * @param $out OutputPage
687 function setupSkinUserCss( OutputPage
$out ) {
688 $out->addStyle( 'common/shared.css' );
689 $out->addStyle( 'common/oldshared.css' );
690 $out->addStyle( $this->getStylesheet() );
691 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
694 function getBodyOptions() {
695 global $wgUser, $wgOut, $wgRequest, $wgContLang;
697 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
699 if ( 0 != $this->mTitle
->getNamespace() ) {
700 $a = array( 'bgcolor' => '#ffffec' );
702 else $a = array( 'bgcolor' => '#FFFFFF' );
703 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
704 $this->mTitle
->quickUserCan( 'edit' ) ) {
705 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
706 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
707 $a +
= array( 'ondblclick' => $s );
709 $a['onload'] = $wgOut->getOnloadHandler();
712 ' '.( $wgContLang->isRTL() ?
'rtl' : 'ltr' ).
713 ' '.$this->getPageClasses( $this->mTitle
) .
714 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
718 function getPageClasses( $title ) {
719 $numeric = 'ns-'.$title->getNamespace();
720 if( $title->getNamespace() == NS_SPECIAL
) {
721 $type = 'ns-special';
722 } elseif( $title->isTalkPage() ) {
725 $type = 'ns-subject';
727 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
728 return "$numeric $type $name";
740 * This will be called immediately after the <body> tag. Split into
741 * two functions to make it easier to subclass.
743 function beforeContent() {
744 return $this->doBeforeContent();
747 function doBeforeContent() {
749 wfProfileIn( __METHOD__
);
752 $qb = $this->qbSetting();
754 if( $langlinks = $this->otherLanguages() ) {
760 $borderhack = 'class="top"';
763 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
764 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
766 $shove = ( $qb != 0 );
767 $left = ( $qb == 1 ||
$qb == 3 );
768 if( $wgContLang->isRTL() ) $left = !$left;
771 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
772 $this->logoText() . '</td>';
774 $s .= $this->getQuickbarCompensator( $rows );
776 $l = $wgContLang->isRTL() ?
'right' : 'left';
777 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
779 $s .= $this->topLinks();
780 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
782 $r = $wgContLang->isRTL() ?
'left' : 'right';
783 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
784 $s .= $this->nameAndLogin();
785 $s .= "\n<br />" . $this->searchForm() . "</td>";
788 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
791 if ( $shove && !$left ) { # Right
792 $s .= $this->getQuickbarCompensator( $rows );
794 $s .= "</tr>\n</table>\n</div>\n";
795 $s .= "\n<div id='article'>\n";
797 $notice = wfGetSiteNotice();
799 $s .= "\n<div id='siteNotice'>$notice</div>\n";
801 $s .= $this->pageTitle();
802 $s .= $this->pageSubtitle();
803 $s .= $this->getCategories();
804 wfProfileOut( __METHOD__
);
809 function getCategoryLinks() {
810 global $wgOut, $wgUseCategoryBrowser;
811 global $wgContLang, $wgUser;
813 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
816 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
818 // Use Unicode bidi embedding override characters,
819 // to make sure links don't smash each other up in ugly ways.
820 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
821 $embed = "<span dir='$dir'>";
824 $allCats = $wgOut->getCategoryLinks();
826 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
827 if ( !empty( $allCats['normal'] ) ) {
828 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
830 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
831 $s .= '<div id="mw-normal-catlinks">' .
832 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
833 . $colon . $t . '</div>';
837 if ( isset( $allCats['hidden'] ) ) {
838 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
839 $class ='mw-hidden-cats-user-shown';
840 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
841 $class = 'mw-hidden-cats-ns-shown';
843 $class = 'mw-hidden-cats-hidden';
845 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
846 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
847 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
851 # optional 'dmoz-like' category browser. Will be shown under the list
852 # of categories an article belong to
853 if( $wgUseCategoryBrowser ){
854 $s .= '<br /><hr />';
856 # get a big array of the parents tree
857 $parenttree = $this->mTitle
->getParentCategoryTree();
858 # Skin object passed by reference cause it can not be
859 # accessed under the method subfunction drawCategoryBrowser
860 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
861 # Clean out bogus first entry and sort them
862 unset( $tempout[0] );
864 # Output one per line
865 $s .= implode( "<br />\n", $tempout );
872 * Render the array as a serie of links.
873 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
874 * @param &skin Object: skin passed by reference
875 * @return String separated by >, terminate with "\n"
877 function drawCategoryBrowser( $tree, &$skin ){
879 foreach( $tree as $element => $parent ) {
880 if( empty( $parent ) ) {
881 # element start a new list
884 # grab the others elements
885 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
887 # add our current element to the list
888 $eltitle = Title
::newFromText( $element );
889 $return .= $skin->link( $eltitle, $eltitle->getText() );
894 function getCategories() {
895 $catlinks=$this->getCategoryLinks();
897 $classes = 'catlinks';
899 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
900 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
901 $classes .= ' catlinks-allhidden';
904 if( !empty( $catlinks ) ){
905 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
909 function getQuickbarCompensator( $rows = 1 ) {
910 return "<td width='152' rowspan='{$rows}'> </td>";
914 * This runs a hook to allow extensions placing their stuff after content
915 * and article metadata (e.g. categories).
916 * Note: This function has nothing to do with afterContent().
918 * This hook is placed here in order to allow using the same hook for all
919 * skins, both the SkinTemplate based ones and the older ones, which directly
920 * use this class to get their data.
922 * The output of this function gets processed in SkinTemplate::outputPage() for
923 * the SkinTemplate based skins, all other skins should directly echo it.
925 * Returns an empty string by default, if not changed by any hook function.
927 protected function afterContentHook() {
930 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
931 // adding just some spaces shouldn't toggle the output
932 // of the whole <div/>, so we use trim() here
933 if( trim( $data ) != '' ){
934 // Doing this here instead of in the skins to
935 // ensure that the div has the same ID in all
937 $data = "<div id='mw-data-after-content'>\n" .
942 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
949 * Generate debug data HTML for displaying at the bottom of the main content
951 * @return String HTML containing debug data, if enabled (otherwise empty).
953 protected function generateDebugHTML() {
954 global $wgShowDebug, $wgOut;
955 if ( $wgShowDebug ) {
956 $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext
) );
957 return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
958 $listInternals . "</li></ul>\n";
964 * This gets called shortly before the </body> tag.
965 * @return String HTML to be put before </body>
967 function afterContent() {
968 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
969 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
973 * This gets called shortly before the </body> tag.
974 * @return String HTML-wrapped JS code to be put before </body>
976 function bottomScripts() {
977 global $wgJsMimeType;
978 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
979 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
980 return $bottomScriptText;
983 /** @return string Retrievied from HTML text */
984 function printSource() {
985 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
986 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
989 function printFooter() {
990 return "<p>" . $this->printSource() .
991 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
994 /** overloaded by derived classes */
995 function doAfterContent() { return '</div></div>'; }
997 function pageTitleLinks() {
998 global $wgOut, $wgUser, $wgRequest, $wgLang;
1000 $oldid = $wgRequest->getVal( 'oldid' );
1001 $diff = $wgRequest->getVal( 'diff' );
1002 $action = $wgRequest->getText( 'action' );
1004 $s[] = $this->printableLink();
1005 $disclaimer = $this->disclaimerLink(); # may be empty
1009 $privacy = $this->privacyLink(); # may be empty too
1014 if ( $wgOut->isArticleRelated() ) {
1015 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1016 $name = $this->mTitle
->getDBkey();
1017 $image = wfFindFile( $this->mTitle
);
1019 $link = htmlspecialchars( $image->getURL() );
1020 $style = $this->getInternalLinkAttributes( $link, $name );
1021 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1025 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1026 $s[] .= $this->link(
1028 wfMsg( 'currentrev' ),
1031 array( 'known', 'noclasses' )
1035 if ( $wgUser->getNewtalk() ) {
1036 # do not show "You have new messages" text when we are viewing our
1038 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1040 $wgUser->getTalkPage(),
1041 wfMsgHtml( 'newmessageslink' ),
1043 array( 'redirect' => 'no' ),
1044 array( 'known', 'noclasses' )
1048 $wgUser->getTalkPage(),
1049 wfMsgHtml( 'newmessagesdifflink' ),
1051 array( 'diff' => 'cur' ),
1052 array( 'known', 'noclasses' )
1054 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1056 $wgOut->setSquidMaxage( 0 );
1057 $wgOut->enableClientCache( false );
1061 $undelete = $this->getUndeleteLink();
1062 if( !empty( $undelete ) ) {
1065 return $wgLang->pipeList( $s );
1068 function getUndeleteLink() {
1069 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1071 $action = $wgRequest->getVal( 'action', 'view' );
1073 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1074 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1075 $n = $this->mTitle
->isDeleted();
1077 if ( $wgUser->isAllowed( 'undelete' ) ) {
1078 $msg = 'thisisdeleted';
1080 $msg = 'viewdeleted';
1085 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1086 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1089 array( 'known', 'noclasses' )
1097 function printableLink() {
1098 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1102 if ( !$wgRequest->getBool( 'printable' ) ) {
1103 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1104 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1107 if( $wgOut->isSyndicated() ) {
1108 foreach( $wgFeedClasses as $format => $class ) {
1109 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1110 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1111 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1114 return $wgLang->pipeList( $s );
1117 function pageTitle() {
1119 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1123 function pageSubtitle() {
1126 $sub = $wgOut->getSubtitle();
1128 global $wgExtraSubtitle;
1129 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1131 $subpages = $this->subPageSubtitle();
1132 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1133 $s = "<p class='subtitle'>{$sub}</p>\n";
1137 function subPageSubtitle() {
1139 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1143 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1144 $ptext = $this->mTitle
->getPrefixedText();
1145 if( preg_match( '/\//', $ptext ) ) {
1146 $links = explode( '/', $ptext );
1147 array_pop( $links );
1151 foreach( $links as $link ) {
1152 $growinglink .= $link;
1154 $linkObj = Title
::newFromText( $growinglink );
1155 if( is_object( $linkObj ) && $linkObj->exists() ){
1156 $getlink = $this->link(
1158 htmlspecialchars( $display ),
1161 array( 'known', 'noclasses' )
1165 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1167 $subpages .= '< ';
1169 $subpages .= $getlink;
1174 $growinglink .= '/';
1182 * Returns true if the IP should be shown in the header
1184 function showIPinHeader() {
1185 global $wgShowIPinHeader;
1186 return $wgShowIPinHeader && session_id() != '';
1189 function nameAndLogin() {
1190 global $wgUser, $wgLang, $wgContLang;
1192 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1195 if ( $wgUser->isAnon() ) {
1196 if( $this->showIPinHeader() ) {
1199 $talkLink = $this->link( $wgUser->getTalkPage(),
1200 $wgLang->getNsText( NS_TALK
) );
1202 $ret .= "$name ($talkLink)";
1204 $ret .= wfMsg( 'notloggedin' );
1207 $returnTo = $this->mTitle
->getPrefixedDBkey();
1209 if ( $logoutPage != $returnTo ) {
1210 $query['returnto'] = $returnTo;
1213 $loginlink = $wgUser->isAllowed( 'createaccount' )
1214 ?
'nav-login-createaccount'
1216 $ret .= "\n<br />" . $this->link(
1217 SpecialPage
::getTitleFor( 'Userlogin' ),
1218 wfMsg( $loginlink ), array(), $query
1221 $returnTo = $this->mTitle
->getPrefixedDBkey();
1222 $talkLink = $this->link( $wgUser->getTalkPage(),
1223 $wgLang->getNsText( NS_TALK
) );
1225 $ret .= $this->link( $wgUser->getUserPage(),
1226 htmlspecialchars( $wgUser->getName() ) );
1227 $ret .= " ($talkLink)<br />";
1228 $ret .= $wgLang->pipeList( array(
1230 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1231 array(), array( 'returnto' => $returnTo )
1233 $this->specialLink( 'preferences' ),
1236 $ret = $wgLang->pipeList( array(
1239 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1247 function getSearchLink() {
1248 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1249 return $searchPage->getLocalURL();
1252 function escapeSearchLink() {
1253 return htmlspecialchars( $this->getSearchLink() );
1256 function searchForm() {
1257 global $wgRequest, $wgUseTwoButtonsSearchForm;
1258 $search = $wgRequest->getText( 'search' );
1260 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1261 . $this->escapeSearchLink() . "\">\n"
1262 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1263 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1264 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1266 if( $wgUseTwoButtonsSearchForm )
1267 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1269 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1273 // Ensure unique id's for search boxes made after the first
1274 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1279 function topLinks() {
1283 $this->mainPageLink(),
1284 $this->specialLink( 'recentchanges' )
1287 if ( $wgOut->isArticleRelated() ) {
1288 $s[] = $this->editThisPage();
1289 $s[] = $this->historyLink();
1291 # Many people don't like this dropdown box
1292 #$s[] = $this->specialPagesList();
1294 if( $this->variantLinks() ) {
1295 $s[] = $this->variantLinks();
1298 if( $this->extensionTabLinks() ) {
1299 $s[] = $this->extensionTabLinks();
1302 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1303 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1307 * Compatibility for extensions adding functionality through tabs.
1308 * Eventually these old skins should be replaced with SkinTemplate-based
1312 function extensionTabLinks() {
1316 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1317 foreach( $tabs as $tab ) {
1318 $s[] = Xml
::element( 'a',
1319 array( 'href' => $tab['href'] ),
1326 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1327 $out .= $wgLang->pipeList( $s );
1334 * Language/charset variant links for classic-style skins
1337 function variantLinks() {
1339 /* show links to different language variants */
1340 global $wgDisableLangConversion, $wgLang, $wgContLang;
1341 $variants = $wgContLang->getVariants();
1342 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1343 foreach( $variants as $code ) {
1344 $varname = $wgContLang->getVariantname( $code );
1345 if( $varname == 'disable' )
1347 $s = $wgLang->pipeList( array(
1349 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1356 function bottomLinks() {
1357 global $wgOut, $wgUser, $wgUseTrackbacks;
1358 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1361 if ( $wgOut->isArticleRelated() ) {
1362 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1363 if ( $wgUser->isLoggedIn() ) {
1364 $element[] = $this->watchThisPage();
1366 $element[] = $this->talkLink();
1367 $element[] = $this->historyLink();
1368 $element[] = $this->whatLinksHere();
1369 $element[] = $this->watchPageLinksLink();
1371 if( $wgUseTrackbacks )
1372 $element[] = $this->trackbackLink();
1374 if ( $this->mTitle
->getNamespace() == NS_USER
1375 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1376 $id = User
::idFromName( $this->mTitle
->getText() );
1377 $ip = User
::isIP( $this->mTitle
->getText() );
1379 if( $id ||
$ip ) { # both anons and non-anons have contri list
1380 $element[] = $this->userContribsLink();
1382 if( $this->showEmailUser( $id ) ) {
1383 $element[] = $this->emailUserLink();
1387 $s = implode( $element, $sep );
1389 if ( $this->mTitle
->getArticleId() ) {
1391 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1392 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1393 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1395 $s .= "<br />\n" . $this->otherLanguages();
1401 function pageStats() {
1402 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1403 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1405 $oldid = $wgRequest->getVal( 'oldid' );
1406 $diff = $wgRequest->getVal( 'diff' );
1407 if ( ! $wgOut->isArticle() ) { return ''; }
1408 if( !$wgArticle instanceOf Article
) { return ''; }
1409 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1410 if ( 0 == $wgArticle->getID() ) { return ''; }
1413 if ( !$wgDisableCounters ) {
1414 $count = $wgLang->formatNum( $wgArticle->getCount() );
1416 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1420 if( $wgMaxCredits != 0 ){
1421 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1423 $s .= $this->lastModified();
1426 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1427 $dbr = wfGetDB( DB_SLAVE
);
1428 $res = $dbr->select( 'watchlist',
1429 array( 'COUNT(*) AS n' ),
1430 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1433 $x = $dbr->fetchObject( $res );
1435 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1436 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1440 return $s . ' ' . $this->getCopyright();
1443 function getCopyright( $type = 'detect' ) {
1444 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1446 if ( $type == 'detect' ) {
1447 $diff = $wgRequest->getVal( 'diff' );
1448 $isCur = $wgArticle && $wgArticle->isCurrent();
1449 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1456 if ( $type == 'history' ) {
1457 $msg = 'history_copyright';
1463 if( $wgRightsPage ) {
1464 $title = Title
::newFromText( $wgRightsPage );
1465 $link = $this->linkKnown( $title, $wgRightsText );
1466 } elseif( $wgRightsUrl ) {
1467 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1468 } elseif( $wgRightsText ) {
1469 $link = $wgRightsText;
1474 // Allow for site and per-namespace customization of copyright notice.
1475 if( isset($wgArticle) )
1476 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1478 $out .= wfMsgForContent( $msg, $link );
1482 function getCopyrightIcon() {
1483 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1485 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1486 $out = $wgCopyrightIcon;
1487 } else if ( $wgRightsIcon ) {
1488 $icon = htmlspecialchars( $wgRightsIcon );
1489 if ( $wgRightsUrl ) {
1490 $url = htmlspecialchars( $wgRightsUrl );
1491 $out .= '<a href="'.$url.'">';
1493 $text = htmlspecialchars( $wgRightsText );
1494 $out .= "<img src=\"$icon\" alt='$text' />";
1495 if ( $wgRightsUrl ) {
1502 function getPoweredBy() {
1503 global $wgStylePath;
1504 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1505 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1509 function lastModified() {
1510 global $wgLang, $wgArticle;
1511 if( $this->mRevisionId
) {
1512 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1514 $timestamp = $wgArticle->getTimestamp();
1517 $d = $wgLang->date( $timestamp, true );
1518 $t = $wgLang->time( $timestamp, true );
1519 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1523 if ( wfGetLB()->getLaggedSlaveMode() ) {
1524 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1529 function logoText( $align = '' ) {
1530 if ( '' != $align ) {
1531 $a = " align='{$align}'";
1536 $mp = wfMsg( 'mainpage' );
1537 $mptitle = Title
::newMainPage();
1538 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1540 $logourl = $this->getLogo();
1541 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1546 * show a drop-down box of special pages
1548 function specialPagesList() {
1549 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1550 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1551 foreach ( $pages as $name => $page ) {
1552 $pages[$name] = $page->getDescription();
1555 $go = wfMsg( 'go' );
1556 $sp = wfMsg( 'specialpages' );
1557 $spp = $wgContLang->specialPage( 'Specialpages' );
1559 $s = '<form id="specialpages" method="get" ' .
1560 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1561 $s .= "<select name=\"wpDropdown\">\n";
1562 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1565 foreach ( $pages as $name => $desc ) {
1566 $p = $wgContLang->specialPage( $name );
1567 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1569 $s .= "</select>\n";
1570 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1575 function mainPageLink() {
1577 Title
::newMainPage(),
1578 wfMsg( 'mainpage' ),
1581 array( 'known', 'noclasses' )
1586 function copyrightLink() {
1587 $title = Title
::newFromText( wfMsgForContent( 'copyrightpage' ) );
1588 $s = $this->linkKnown(
1590 wfMsg( 'copyrightpagename' )
1595 private function footerLink ( $desc, $page ) {
1596 // if the link description has been set to "-" in the default language,
1597 if ( wfMsgForContent( $desc ) == '-') {
1598 // then it is disabled, for all languages.
1601 // Otherwise, we display the link for the user, described in their
1602 // language (which may or may not be the same as the default language),
1603 // but we make the link target be the one site-wide page.
1604 $title = Title
::newFromText( wfMsgForContent( $page ) );
1605 return $this->linkKnown(
1607 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1612 function privacyLink() {
1613 return $this->footerLink( 'privacy', 'privacypage' );
1616 function aboutLink() {
1617 return $this->footerLink( 'aboutsite', 'aboutpage' );
1620 function disclaimerLink() {
1621 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1624 function editThisPage() {
1627 if ( !$wgOut->isArticleRelated() ) {
1628 $s = wfMsg( 'protectedpage' );
1630 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1631 $t = wfMsg( 'editthispage' );
1632 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1633 $t = wfMsg( 'create-this-page' );
1635 $t = wfMsg( 'viewsource' );
1642 $this->editUrlOptions(),
1643 array( 'known', 'noclasses' )
1650 * Return URL options for the 'edit page' link.
1651 * This may include an 'oldid' specifier, if the current page view is such.
1656 function editUrlOptions() {
1659 $options = array( 'action' => 'edit' );
1661 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1662 $options['oldid'] = intval( $this->mRevisionId
);
1668 function deleteThisPage() {
1669 global $wgUser, $wgRequest;
1671 $diff = $wgRequest->getVal( 'diff' );
1672 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1673 $t = wfMsg( 'deletethispage' );
1679 array( 'action' => 'delete' ),
1680 array( 'known', 'noclasses' )
1688 function protectThisPage() {
1689 global $wgUser, $wgRequest;
1691 $diff = $wgRequest->getVal( 'diff' );
1692 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1693 if ( $this->mTitle
->isProtected() ) {
1694 $text = wfMsg( 'unprotectthispage' );
1695 $query = array( 'action' => 'unprotect' );
1697 $text = wfMsg( 'protectthispage' );
1698 $query = array( 'action' => 'protect' );
1706 array( 'known', 'noclasses' )
1714 function watchThisPage() {
1716 ++
$this->mWatchLinkNum
;
1718 if ( $wgOut->isArticleRelated() ) {
1719 if ( $this->mTitle
->userIsWatching() ) {
1720 $text = wfMsg( 'unwatchthispage' );
1721 $query = array( 'action' => 'unwatch' );
1722 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1724 $text = wfMsg( 'watchthispage' );
1725 $query = array( 'action' => 'watch' );
1726 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1732 array( 'id' => $id ),
1734 array( 'known', 'noclasses' )
1737 $s = wfMsg( 'notanarticle' );
1742 function moveThisPage() {
1743 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1745 SpecialPage
::getTitleFor( 'Movepage' ),
1746 wfMsg( 'movethispage' ),
1748 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1749 array( 'known', 'noclasses' )
1752 // no message if page is protected - would be redundant
1757 function historyLink() {
1760 wfMsgHtml( 'history' ),
1761 array( 'rel' => 'archives' ),
1762 array( 'action' => 'history' )
1766 function whatLinksHere() {
1768 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1769 wfMsgHtml( 'whatlinkshere' ),
1772 array( 'known', 'noclasses' )
1776 function userContribsLink() {
1778 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1779 wfMsgHtml( 'contributions' ),
1782 array( 'known', 'noclasses' )
1786 function showEmailUser( $id ) {
1788 $targetUser = User
::newFromId( $id );
1789 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1790 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1793 function emailUserLink() {
1795 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1796 wfMsg( 'emailuser' ),
1799 array( 'known', 'noclasses' )
1803 function watchPageLinksLink() {
1805 if ( ! $wgOut->isArticleRelated() ) {
1806 return '(' . wfMsg( 'notanarticle' ) . ')';
1809 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1810 wfMsg( 'recentchangeslinked-toolbox' ),
1813 array( 'known', 'noclasses' )
1818 function trackbackLink() {
1819 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1820 . wfMsg( 'trackbacklink' ) . '</a>';
1823 function otherLanguages() {
1824 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1826 if ( $wgHideInterlanguageLinks ) {
1830 $a = $wgOut->getLanguageLinks();
1831 if ( 0 == count( $a ) ) {
1835 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1837 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1838 foreach( $a as $l ) {
1840 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1844 $nt = Title
::newFromText( $l );
1845 $url = $nt->escapeFullURL();
1846 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1848 if ( '' == $text ) { $text = $l; }
1849 $style = $this->getExternalLinkAttributes();
1850 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1852 if( $wgContLang->isRTL() ) $s .= '</span>';
1856 function talkLink() {
1857 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1858 # No discussion links for special pages
1862 $linkOptions = array();
1864 if( $this->mTitle
->isTalkPage() ) {
1865 $link = $this->mTitle
->getSubjectPage();
1866 switch( $link->getNamespace() ) {
1868 $text = wfMsg( 'articlepage' );
1871 $text = wfMsg( 'userpage' );
1874 $text = wfMsg( 'projectpage' );
1877 $text = wfMsg( 'imagepage' );
1878 # Make link known if image exists, even if the desc. page doesn't.
1879 if( wfFindFile( $link ) )
1880 $linkOptions[] = 'known';
1883 $text = wfMsg( 'mediawikipage' );
1886 $text = wfMsg( 'templatepage' );
1889 $text = wfMsg( 'viewhelppage' );
1892 $text = wfMsg( 'categorypage' );
1895 $text = wfMsg( 'articlepage' );
1898 $link = $this->mTitle
->getTalkPage();
1899 $text = wfMsg( 'talkpage' );
1902 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1907 function commentLink() {
1910 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1914 # __NEWSECTIONLINK___ changes behaviour here
1915 # If it is present, the link points to this page, otherwise
1916 # it points to the talk page
1917 if( $this->mTitle
->isTalkPage() ) {
1918 $title = $this->mTitle
;
1919 } elseif( $wgOut->showNewSectionLink() ) {
1920 $title = $this->mTitle
;
1922 $title = $this->mTitle
->getTalkPage();
1927 wfMsg( 'postcomment' ),
1933 array( 'known', 'noclasses' )
1937 /* these are used extensively in SkinTemplate, but also some other places */
1938 static function makeMainPageUrl( $urlaction = '' ) {
1939 $title = Title
::newMainPage();
1940 self
::checkTitle( $title, '' );
1941 return $title->getLocalURL( $urlaction );
1944 static function makeSpecialUrl( $name, $urlaction = '' ) {
1945 $title = SpecialPage
::getTitleFor( $name );
1946 return $title->getLocalURL( $urlaction );
1949 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1950 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1951 return $title->getLocalURL( $urlaction );
1954 static function makeI18nUrl( $name, $urlaction = '' ) {
1955 $title = Title
::newFromText( wfMsgForContent( $name ) );
1956 self
::checkTitle( $title, $name );
1957 return $title->getLocalURL( $urlaction );
1960 static function makeUrl( $name, $urlaction = '' ) {
1961 $title = Title
::newFromText( $name );
1962 self
::checkTitle( $title, $name );
1963 return $title->getLocalURL( $urlaction );
1966 # If url string starts with http, consider as external URL, else
1968 static function makeInternalOrExternalUrl( $name ) {
1969 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1972 return self
::makeUrl( $name );
1976 # this can be passed the NS number as defined in Language.php
1977 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1978 $title = Title
::makeTitleSafe( $namespace, $name );
1979 self
::checkTitle( $title, $name );
1980 return $title->getLocalURL( $urlaction );
1983 /* these return an array with the 'href' and boolean 'exists' */
1984 static function makeUrlDetails( $name, $urlaction = '' ) {
1985 $title = Title
::newFromText( $name );
1986 self
::checkTitle( $title, $name );
1988 'href' => $title->getLocalURL( $urlaction ),
1989 'exists' => $title->getArticleID() != 0 ?
true : false
1994 * Make URL details where the article exists (or at least it's convenient to think so)
1996 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1997 $title = Title
::newFromText( $name );
1998 self
::checkTitle( $title, $name );
2000 'href' => $title->getLocalURL( $urlaction ),
2005 # make sure we have some title to operate on
2006 static function checkTitle( &$title, $name ) {
2007 if( !is_object( $title ) ) {
2008 $title = Title
::newFromText( $name );
2009 if( !is_object( $title ) ) {
2010 $title = Title
::newFromText( '--error: link target missing--' );
2016 * Build an array that represents the sidebar(s), the navigation bar among them
2020 function buildSidebar() {
2021 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2023 wfProfileIn( __METHOD__
);
2025 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2027 if ( $wgEnableSidebarCache ) {
2028 $cachedsidebar = $parserMemc->get( $key );
2029 if ( $cachedsidebar ) {
2030 wfProfileOut( __METHOD__
);
2031 return $cachedsidebar;
2036 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
2038 foreach( $lines as $line ) {
2039 if( strpos( $line, '*' ) !== 0 )
2041 if( strpos( $line, '**') !== 0 ) {
2042 $heading = trim( $line, '* ' );
2043 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
2045 if( strpos( $line, '|' ) !== false ) { // sanity check
2046 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2047 $link = wfMsgForContent( $line[0] );
2051 $text = wfMsgExt( $line[1], 'parsemag' );
2052 if( wfEmptyMsg( $line[1], $text ) )
2054 if( wfEmptyMsg( $line[0], $link ) )
2057 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2060 $title = Title
::newFromText( $link );
2062 $title = $title->fixSpecialName();
2063 $href = $title->getLocalURL();
2065 $href = 'INVALID-TITLE';
2069 $bar[$heading][] = array(
2072 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2075 } else { continue; }
2078 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2079 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2080 wfProfileOut( __METHOD__
);
2085 * Should we include common/wikiprintable.css? Skins that have their own
2086 * print stylesheet should override this and return false. (This is an
2087 * ugly hack to get Monobook to play nicely with
2088 * OutputPage::headElement().)
2092 public function commonPrintStylesheet() {