3 * @defgroup Skins Skins
6 if ( ! defined( 'MEDIAWIKI' ) )
10 * The main skin class that provide methods and properties for all other skins.
11 * This base class is also the "Standard" skin.
13 * See docs/skin.txt for more information.
17 class Skin
extends Linker
{
21 var $mWatchLinkNum = 0; // Appended to end of watch link id's
22 // How many search boxes have we made? Avoid duplicate id's.
23 protected $searchboxes = '';
25 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
26 protected $skinname = 'standard';
27 // @fixme Should be protected :-\
30 /** Constructor, call parent constructor */
31 function Skin() { parent
::__construct(); }
34 * Fetch the set of available skins.
35 * @return array of strings
38 static function getSkinNames() {
39 global $wgValidSkinNames;
40 static $skinsInitialised = false;
41 if ( !$skinsInitialised ) {
42 # Get a list of available skins
43 # Build using the regular expression '^(.*).php$'
44 # Array keys are all lower case, array value keep the case used by filename
46 wfProfileIn( __METHOD__
. '-init' );
47 global $wgStyleDirectory;
48 $skinDir = dir( $wgStyleDirectory );
50 # while code from www.php.net
51 while( false !== ( $file = $skinDir->read() ) ) {
52 // Skip non-PHP files, hidden files, and '.dep' includes
54 if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
56 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
60 $skinsInitialised = true;
61 wfProfileOut( __METHOD__
. '-init' );
63 return $wgValidSkinNames;
67 * Fetch the list of usable skins in regards to $wgSkipSkins.
68 * Useful for Special:Preferences and other places where you
69 * only want to show skins users _can_ use.
70 * @return array of strings
72 public static function getUsableSkins() {
74 $usableSkins = self
::getSkinNames();
75 foreach ( $wgSkipSkins as $skip ) {
76 unset( $usableSkins[$skip] );
82 * Normalize a skin preference value to a form that can be loaded.
83 * If a skin can't be found, it will fall back to the configured
84 * default (or the old 'Classic' skin if that's broken).
89 static function normalizeKey( $key ) {
90 global $wgDefaultSkin;
91 $skinNames = Skin
::getSkinNames();
94 // Don't return the default immediately;
95 // in a misconfiguration we need to fall back.
96 $key = $wgDefaultSkin;
99 if( isset( $skinNames[$key] ) ) {
103 // Older versions of the software used a numeric setting
104 // in the user preferences.
108 2 => 'cologneblue' );
110 if( isset( $fallback[$key] ) ){
111 $key = $fallback[$key];
114 if( isset( $skinNames[$key] ) ) {
122 * Factory method for loading a skin of a given type
123 * @param string $key 'monobook', 'standard', etc
127 static function &newFromKey( $key ) {
128 global $wgStyleDirectory;
130 $key = Skin
::normalizeKey( $key );
132 $skinNames = Skin
::getSkinNames();
133 $skinName = $skinNames[$key];
134 $className = 'Skin'.ucfirst($key);
136 # Grab the skin class and initialise it.
137 if ( !class_exists( $className ) ) {
138 // Preload base classes to work around APC/PHP5 bug
139 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
140 if( file_exists( $deps ) ) include_once( $deps );
141 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
143 # Check if we got if not failback to default skin
144 if( !class_exists( $className ) ) {
145 # DO NOT die if the class isn't found. This breaks maintenance
146 # scripts and can cause a user account to be unrecoverable
147 # except by SQL manipulation if a previously valid skin name
148 # is no longer valid.
149 wfDebug( "Skin class does not exist: $className\n" );
150 $className = 'SkinMonobook';
151 require_once( "{$wgStyleDirectory}/MonoBook.php" );
154 $skin = new $className;
158 /** @return string path to the skin stylesheet */
159 function getStylesheet() {
160 return 'common/wikistandard.css';
163 /** @return string skin name */
164 public function getSkinName() {
165 return $this->skinname
;
168 function qbSetting() {
169 global $wgOut, $wgUser;
171 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
172 $q = $wgUser->getOption( 'quickbar', 0 );
176 function initPage( OutputPage
$out ) {
177 global $wgFavicon, $wgAppleTouchIcon;
179 wfProfileIn( __METHOD__
);
181 # Generally the order of the favicon and apple-touch-icon links
182 # should not matter, but Konqueror (3.5.9 at least) incorrectly
183 # uses whichever one appears later in the HTML source. Make sure
184 # apple-touch-icon is specified first to avoid this.
185 if( false !== $wgAppleTouchIcon ) {
186 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
189 if( false !== $wgFavicon ) {
190 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
193 # OpenSearch description link
194 $out->addLink( array(
196 'type' => 'application/opensearchdescription+xml',
197 'href' => wfScript( 'opensearch_desc' ),
198 'title' => wfMsgForContent( 'opensearch-desc' ),
201 $this->addMetadataLinks( $out );
203 $this->mRevisionId
= $out->mRevisionId
;
205 $this->preloadExistence();
207 wfProfileOut( __METHOD__
);
211 * Preload the existence of three commonly-requested pages in a single query
213 function preloadExistence() {
217 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
220 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
222 } elseif ( $this->mTitle
->isTalkPage() ) {
223 $titles[] = $this->mTitle
->getSubjectPage();
225 $titles[] = $this->mTitle
->getTalkPage();
228 $lb = new LinkBatch( $titles );
232 function addMetadataLinks( OutputPage
$out ) {
233 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
234 global $wgRightsPage, $wgRightsUrl;
236 if( $out->isArticleRelated() ) {
237 # note: buggy CC software only reads first "meta" link
238 if( $wgEnableCreativeCommonsRdf ) {
239 $out->addMetadataLink( array(
240 'title' => 'Creative Commons',
241 'type' => 'application/rdf+xml',
242 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
245 if( $wgEnableDublinCoreRdf ) {
246 $out->addMetadataLink( array(
247 'title' => 'Dublin Core',
248 'type' => 'application/rdf+xml',
249 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
254 if( $wgRightsPage ) {
255 $copy = Title
::newFromText( $wgRightsPage );
257 $copyright = $copy->getLocalURL();
260 if( !$copyright && $wgRightsUrl ) {
261 $copyright = $wgRightsUrl;
264 $out->addLink( array(
265 'rel' => 'copyright',
266 'href' => $copyright )
272 * Set some local variables
274 protected function setMembers(){
276 $this->mUser
= $wgUser;
277 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
278 $this->usercss
= false;
283 * @param Title $t The title to use
285 public function setTitle( $t ) {
290 public function getTitle() {
291 return $this->mTitle
;
294 function outputPage( OutputPage
$out ) {
295 global $wgDebugComments;
296 wfProfileIn( __METHOD__
);
299 $this->initPage( $out );
301 // See self::afterContentHook() for documentation
302 $afterContent = $this->afterContentHook();
304 $out->out( $out->headElement( $this ) );
306 $out->out( "\n<body" );
307 $ops = $this->getBodyOptions();
308 foreach ( $ops as $name => $val ) {
309 $out->out( " $name='$val'" );
312 if ( $wgDebugComments ) {
313 $out->out( "<!-- Wiki debugging output:\n" .
314 $out->mDebugtext
. "-->\n" );
317 $out->out( $this->beforeContent() );
319 $out->out( $out->mBodytext
. "\n" );
321 $out->out( $this->afterContent() );
323 $out->out( $afterContent );
325 $out->out( $this->bottomScripts() );
327 $out->out( wfReportTime() );
329 $out->out( "\n</body></html>" );
330 wfProfileOut( __METHOD__
);
333 static function makeVariablesScript( $data ) {
336 foreach ( $data as $name => $value ) {
337 $encValue = Xml
::encodeJsVar( $value );
338 $r[] = "$name=$encValue";
340 $js = 'var ' . implode( ",\n", $r ) . ';';
341 return Html
::inlineScript( "\n$js\n" );
348 * Make a <script> tag containing global variables
349 * @param $skinName string Name of the skin
350 * The odd calling convention is for backwards compatibility
351 * @TODO @FIXME Make this not depend on $wgTitle!
353 static function makeGlobalVariablesScript( $skinName ) {
354 if ( is_array( $skinName ) ) {
355 # Weird back-compat stuff.
356 $skinName = $skinName['skinname'];
358 global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
359 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
360 global $wgOut, $wgArticle;
361 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
362 global $wgUseAjax, $wgAjaxWatch;
363 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
364 global $wgRestrictionTypes;
365 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
368 $ns = $wgTitle->getNamespace();
369 $nsname = MWNamespace
::exists( $ns ) ? MWNamespace
::getCanonicalName( $ns ) : $wgTitle->getNsText();
370 $separatorTransTable = $wgContLang->separatorTransformTable();
371 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
372 $compactSeparatorTransTable = array(
373 implode( "\t", array_keys( $separatorTransTable ) ),
374 implode( "\t", $separatorTransTable ),
376 $digitTransTable = $wgContLang->digitTransformTable();
377 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
378 $compactDigitTransTable = array(
379 implode( "\t", array_keys( $digitTransTable ) ),
380 implode( "\t", $digitTransTable ),
383 $mainPage = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
386 'stylepath' => $wgStylePath,
387 'urlprotocols' => wfUrlProtocols(),
388 'wgArticlePath' => $wgArticlePath,
389 'wgScriptPath' => $wgScriptPath,
390 'wgScriptExtension' => $wgScriptExtension,
391 'wgScript' => $wgScript,
392 'wgVariantArticlePath' => $wgVariantArticlePath,
393 'wgActionPaths' => (object)$wgActionPaths,
394 'wgServer' => $wgServer,
395 'wgCanonicalNamespace' => $nsname,
396 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
397 SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
398 'wgNamespaceNumber' => $wgTitle->getNamespace(),
399 'wgPageName' => $wgTitle->getPrefixedDBKey(),
400 'wgTitle' => $wgTitle->getText(),
401 'wgAction' => $wgRequest->getText( 'action', 'view' ),
402 'wgArticleId' => $wgTitle->getArticleId(),
403 'wgIsArticle' => $wgOut->isArticle(),
404 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
405 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
406 'wgUserLanguage' => $wgLang->getCode(),
407 'wgContentLanguage' => $wgContLang->getCode(),
408 'wgBreakFrames' => $wgBreakFrames,
409 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
410 'wgVersion' => $wgVersion,
411 'wgEnableAPI' => $wgEnableAPI,
412 'wgEnableWriteAPI' => $wgEnableWriteAPI,
413 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
414 'wgDigitTransformTable' => $compactDigitTransTable,
415 'wgMainPageTitle' => $mainPage ?
$mainPage->getPrefixedText() : null,
416 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
417 'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
418 'wgSiteName' => $wgSitename,
419 'wgCategories' => $wgOut->getCategories(),
421 if ( $wgContLang->hasVariants() ) {
422 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
425 //if on upload page output the extension list & js_upload
426 if( SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) == "Upload" ) {
427 global $wgFileExtensions, $wgAjaxUploadInterface;
428 $vars['wgFileExtensions'] = $wgFileExtensions;
431 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
432 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
433 $vars['wgDBname'] = $wgDBname;
434 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
435 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
438 foreach( $wgRestrictionTypes as $type )
439 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
441 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
442 $msgs = (object)array();
443 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
444 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
446 $vars['wgAjaxWatch'] = $msgs;
449 // Allow extensions to add their custom variables to the global JS variables
450 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
452 return self
::makeVariablesScript( $vars );
456 * To make it harder for someone to slip a user a fake
457 * user-JavaScript or user-CSS preview, a random token
458 * is associated with the login session. If it's not
459 * passed back with the preview request, we won't render
462 * @param string $action
465 public function userCanPreview( $action ) {
466 global $wgRequest, $wgUser;
468 if( $action != 'submit' )
470 if( !$wgRequest->wasPosted() )
472 if( !$this->mTitle
->userCanEditCssSubpage() )
474 if( !$this->mTitle
->userCanEditJsSubpage() )
476 return $wgUser->matchEditToken(
477 $wgRequest->getVal( 'wpEditToken' ) );
481 * generated JavaScript action=raw&gen=js
482 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
483 * nated together. For some bizarre reason, it does *not* return any
484 * custom user JS from subpages. Huh?
486 * There's absolutely no reason to have separate Monobook/Common JSes.
487 * Any JS that cares can just check the skin variable generated at the
488 * top. For now Monobook.js will be maintained, but it should be consi-
491 * @param $force_skin string If set, overrides the skin name
495 public function generateUserJs( $skinName = null ) {
498 wfProfileIn( __METHOD__
);
500 $skinName = $this->getSkinName();
503 $s = "/* generated javascript */\n";
504 $s .= "var skin = '" . Xml
::escapeJsString($skinName ) . "';\n";
505 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
506 $s .= "\n\n/* MediaWiki:Common.js */\n";
507 $commonJs = wfMsgForContent( 'common.js' );
508 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
512 $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n";
513 // avoid inclusion of non defined user JavaScript (with custom skins only)
514 // by checking for default message content
515 $msgKey = ucfirst( $skinName ) . '.js';
516 $userJS = wfMsgForContent( $msgKey );
517 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
521 wfProfileOut( __METHOD__
);
526 * Generate user stylesheet for action=raw&gen=css
528 public function generateUserStylesheet() {
529 wfProfileIn( __METHOD__
);
530 $s = "/* generated user stylesheet */\n" .
531 $this->reallyGenerateUserStylesheet();
532 wfProfileOut( __METHOD__
);
537 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
539 protected function reallyGenerateUserStylesheet(){
542 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
543 $underline = $undopt ?
'underline' : 'none';
544 $s .= "a { text-decoration: $underline; }\n";
546 if( $wgUser->getOption( 'highlightbroken' ) ) {
547 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
550 a.new, #quickbar a.new,
551 a.stub, #quickbar a.stub {
554 a.new:after, #quickbar a.new:after {
558 a.stub:after, #quickbar a.stub:after {
564 if( $wgUser->getOption( 'justify' ) ) {
565 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
567 if( !$wgUser->getOption( 'showtoc' ) ) {
568 $s .= "#toc { display: none; }\n";
570 if( !$wgUser->getOption( 'editsection' ) ) {
571 $s .= ".editsection { display: none; }\n";
573 $fontstyle = $wgUser->getOption( 'editfont' );
574 if ( $fontstyle !== 'default' ) {
575 $s .= "textarea { font-family: $fontstyle; }\n";
583 function setupUserCss( OutputPage
$out ) {
584 global $wgRequest, $wgContLang, $wgUser;
585 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
587 wfProfileIn( __METHOD__
);
589 $this->setupSkinUserCss( $out );
593 'maxage' => $wgSquidMaxage,
596 // Add any extension CSS
597 foreach ( $out->getExtStyle() as $url ) {
598 $out->addStyle( $url );
601 // If we use the site's dynamic CSS, throw that in, too
602 // Per-site custom styles
603 if( $wgUseSiteCss ) {
604 global $wgHandheldStyle;
605 $query = wfArrayToCGI( array(
606 'usemsgcache' => 'yes',
607 'ctype' => 'text/css',
608 'smaxage' => $wgSquidMaxage
610 # Site settings must override extension css! (bug 15025)
611 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
612 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
613 if( $wgHandheldStyle ) {
614 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
616 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
619 if( $wgUser->isLoggedIn() ) {
620 // Ensure that logged-in users' generated CSS isn't clobbered
621 // by anons' publicly cacheable generated CSS.
622 $siteargs['smaxage'] = '0';
623 $siteargs['ts'] = $wgUser->mTouched
;
625 // Per-user styles based on preferences
626 $siteargs['gen'] = 'css';
627 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
628 $siteargs['useskin'] = $us;
630 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
632 // Per-user custom style pages
633 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
634 $action = $wgRequest->getVal( 'action' );
635 # If we're previewing the CSS page, use it
636 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
637 // @FIXME: properly escape the cdata!
638 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
640 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
641 'action=raw&ctype=text/css' ) );
645 wfProfileOut( __METHOD__
);
649 * Add skin specific stylesheets
650 * @param $out OutputPage
652 function setupSkinUserCss( OutputPage
$out ) {
653 $out->addStyle( 'common/shared.css' );
654 $out->addStyle( 'common/oldshared.css' );
655 $out->addStyle( $this->getStylesheet() );
656 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
659 function getBodyOptions() {
660 global $wgUser, $wgOut, $wgRequest, $wgContLang;
662 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
664 if ( 0 != $this->mTitle
->getNamespace() ) {
665 $a = array( 'bgcolor' => '#ffffec' );
667 else $a = array( 'bgcolor' => '#FFFFFF' );
668 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
669 $this->mTitle
->quickUserCan( 'edit' ) ) {
670 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
671 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
672 $a +
= array( 'ondblclick' => $s );
674 $a['onload'] = $wgOut->getOnloadHandler();
677 ' '.( $wgContLang->getDir() ).
678 ' '.$this->getPageClasses( $this->mTitle
) .
679 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
683 function getPageClasses( $title ) {
684 $numeric = 'ns-'.$title->getNamespace();
685 if( $title->getNamespace() == NS_SPECIAL
) {
686 $type = 'ns-special';
687 } elseif( $title->isTalkPage() ) {
690 $type = 'ns-subject';
692 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
693 return "$numeric $type $name";
705 * This will be called immediately after the <body> tag. Split into
706 * two functions to make it easier to subclass.
708 function beforeContent() {
709 return $this->doBeforeContent();
712 function doBeforeContent() {
714 wfProfileIn( __METHOD__
);
717 $qb = $this->qbSetting();
719 if( $langlinks = $this->otherLanguages() ) {
725 $borderhack = 'class="top"';
728 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
729 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
731 $shove = ( $qb != 0 );
732 $left = ( $qb == 1 ||
$qb == 3 );
733 if( $wgContLang->isRTL() ) $left = !$left;
736 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
737 $this->logoText() . '</td>';
739 $s .= $this->getQuickbarCompensator( $rows );
741 $l = $wgContLang->alignStart();
742 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
744 $s .= $this->topLinks();
745 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
747 $r = $wgContLang->alignEnd();
748 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
749 $s .= $this->nameAndLogin();
750 $s .= "\n<br />" . $this->searchForm() . "</td>";
753 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
756 if ( $shove && !$left ) { # Right
757 $s .= $this->getQuickbarCompensator( $rows );
759 $s .= "</tr>\n</table>\n</div>\n";
760 $s .= "\n<div id='article'>\n";
762 $notice = wfGetSiteNotice();
764 $s .= "\n<div id='siteNotice'>$notice</div>\n";
766 $s .= $this->pageTitle();
767 $s .= $this->pageSubtitle();
768 $s .= $this->getCategories();
769 wfProfileOut( __METHOD__
);
774 function getCategoryLinks() {
775 global $wgOut, $wgUseCategoryBrowser;
776 global $wgContLang, $wgUser;
778 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
781 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
783 // Use Unicode bidi embedding override characters,
784 // to make sure links don't smash each other up in ugly ways.
785 $dir = $wgContLang->getDir();
786 $embed = "<span dir='$dir'>";
789 $allCats = $wgOut->getCategoryLinks();
791 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
792 if ( !empty( $allCats['normal'] ) ) {
793 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
795 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
796 $s .= '<div id="mw-normal-catlinks">' .
797 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
798 . $colon . $t . '</div>';
802 if ( isset( $allCats['hidden'] ) ) {
803 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
804 $class ='mw-hidden-cats-user-shown';
805 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
806 $class = 'mw-hidden-cats-ns-shown';
808 $class = 'mw-hidden-cats-hidden';
810 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
811 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
812 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
816 # optional 'dmoz-like' category browser. Will be shown under the list
817 # of categories an article belong to
818 if( $wgUseCategoryBrowser ){
819 $s .= '<br /><hr />';
821 # get a big array of the parents tree
822 $parenttree = $this->mTitle
->getParentCategoryTree();
823 # Skin object passed by reference cause it can not be
824 # accessed under the method subfunction drawCategoryBrowser
825 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
826 # Clean out bogus first entry and sort them
827 unset( $tempout[0] );
829 # Output one per line
830 $s .= implode( "<br />\n", $tempout );
837 * Render the array as a serie of links.
838 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
839 * @param &skin Object: skin passed by reference
840 * @return String separated by >, terminate with "\n"
842 function drawCategoryBrowser( $tree, &$skin ){
844 foreach( $tree as $element => $parent ) {
845 if( empty( $parent ) ) {
846 # element start a new list
849 # grab the others elements
850 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
852 # add our current element to the list
853 $eltitle = Title
::newFromText( $element );
854 $return .= $skin->link( $eltitle, $eltitle->getText() );
859 function getCategories() {
860 $catlinks = $this->getCategoryLinks();
862 $classes = 'catlinks';
864 // Check what we're showing
865 global $wgOut, $wgUser;
866 $allCats = $wgOut->getCategoryLinks();
867 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
868 $this->mTitle
->getNamespace() == NS_CATEGORY
;
870 if( empty($allCats['normal']) && !( !empty($allCats['hidden']) && $showHidden ) ) {
871 $classes .= ' catlinks-allhidden';
874 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
877 function getQuickbarCompensator( $rows = 1 ) {
878 return "<td width='152' rowspan='{$rows}'> </td>";
882 * This runs a hook to allow extensions placing their stuff after content
883 * and article metadata (e.g. categories).
884 * Note: This function has nothing to do with afterContent().
886 * This hook is placed here in order to allow using the same hook for all
887 * skins, both the SkinTemplate based ones and the older ones, which directly
888 * use this class to get their data.
890 * The output of this function gets processed in SkinTemplate::outputPage() for
891 * the SkinTemplate based skins, all other skins should directly echo it.
893 * Returns an empty string by default, if not changed by any hook function.
895 protected function afterContentHook() {
898 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
899 // adding just some spaces shouldn't toggle the output
900 // of the whole <div/>, so we use trim() here
901 if( trim( $data ) != '' ){
902 // Doing this here instead of in the skins to
903 // ensure that the div has the same ID in all
905 $data = "<div id='mw-data-after-content'>\n" .
910 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
917 * Generate debug data HTML for displaying at the bottom of the main content
919 * @return String HTML containing debug data, if enabled (otherwise empty).
921 protected function generateDebugHTML() {
922 global $wgShowDebug, $wgOut;
923 if ( $wgShowDebug ) {
924 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
925 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
926 $listInternals . "</ul>\n";
931 private function formatDebugHTML( $debugText ) {
932 $lines = explode( "\n", $debugText );
935 foreach( $lines as $line ) {
937 $display = ltrim( $line );
938 $ident = strlen( $line ) - strlen( $display );
939 $diff = $ident - $curIdent;
941 if ( $display == '' )
942 $display = "\xc2\xa0";
944 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
947 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
949 $display = htmlspecialchars( $display );
953 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
954 elseif ( $diff == 0 )
955 $ret .= "</li><li>\n";
957 $ret .= str_repeat( "<ul><li>\n", $diff );
958 $ret .= $display . "\n";
962 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
967 * This gets called shortly before the </body> tag.
968 * @return String HTML to be put before </body>
970 function afterContent() {
971 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
972 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
976 * This gets called shortly before the </body> tag.
977 * @return String HTML-wrapped JS code to be put before </body>
979 function bottomScripts() {
980 $bottomScriptText = "\n" . Html
::inlineScript( 'if (window.runOnloadHook) runOnloadHook();' ) . "\n";
981 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
982 return $bottomScriptText;
985 /** @return string Retrievied from HTML text */
986 function printSource() {
987 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
988 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
991 function printFooter() {
992 return "<p>" . $this->printSource() .
993 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
996 /** overloaded by derived classes */
997 function doAfterContent() { return '</div></div>'; }
999 function pageTitleLinks() {
1000 global $wgOut, $wgUser, $wgRequest, $wgLang;
1002 $oldid = $wgRequest->getVal( 'oldid' );
1003 $diff = $wgRequest->getVal( 'diff' );
1004 $action = $wgRequest->getText( 'action' );
1006 $s[] = $this->printableLink();
1007 $disclaimer = $this->disclaimerLink(); # may be empty
1011 $privacy = $this->privacyLink(); # may be empty too
1016 if ( $wgOut->isArticleRelated() ) {
1017 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1018 $name = $this->mTitle
->getDBkey();
1019 $image = wfFindFile( $this->mTitle
);
1021 $link = htmlspecialchars( $image->getURL() );
1022 $style = $this->getInternalLinkAttributes( $link, $name );
1023 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1027 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1028 $s[] .= $this->link(
1030 wfMsg( 'currentrev' ),
1033 array( 'known', 'noclasses' )
1037 if ( $wgUser->getNewtalk() ) {
1038 # do not show "You have new messages" text when we are viewing our
1040 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1042 $wgUser->getTalkPage(),
1043 wfMsgHtml( 'newmessageslink' ),
1045 array( 'redirect' => 'no' ),
1046 array( 'known', 'noclasses' )
1050 $wgUser->getTalkPage(),
1051 wfMsgHtml( 'newmessagesdifflink' ),
1053 array( 'diff' => 'cur' ),
1054 array( 'known', 'noclasses' )
1056 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1058 $wgOut->setSquidMaxage( 0 );
1059 $wgOut->enableClientCache( false );
1063 $undelete = $this->getUndeleteLink();
1064 if( !empty( $undelete ) ) {
1067 return $wgLang->pipeList( $s );
1070 function getUndeleteLink() {
1071 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1073 $action = $wgRequest->getVal( 'action', 'view' );
1075 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1076 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1077 $n = $this->mTitle
->isDeleted();
1079 if ( $wgUser->isAllowed( 'undelete' ) ) {
1080 $msg = 'thisisdeleted';
1082 $msg = 'viewdeleted';
1087 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1088 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1091 array( 'known', 'noclasses' )
1099 function printableLink() {
1100 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1104 if ( !$wgOut->isPrintable() ) {
1105 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1106 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1109 if( $wgOut->isSyndicated() ) {
1110 foreach( $wgFeedClasses as $format => $class ) {
1111 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1112 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1113 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1116 return $wgLang->pipeList( $s );
1119 function pageTitle() {
1121 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1125 function pageSubtitle() {
1128 $sub = $wgOut->getSubtitle();
1130 global $wgExtraSubtitle;
1131 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1133 $subpages = $this->subPageSubtitle();
1134 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1135 $s = "<p class='subtitle'>{$sub}</p>\n";
1139 function subPageSubtitle() {
1141 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1145 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1146 $ptext = $this->mTitle
->getPrefixedText();
1147 if( preg_match( '/\//', $ptext ) ) {
1148 $links = explode( '/', $ptext );
1149 array_pop( $links );
1153 foreach( $links as $link ) {
1154 $growinglink .= $link;
1156 $linkObj = Title
::newFromText( $growinglink );
1157 if( is_object( $linkObj ) && $linkObj->exists() ){
1158 $getlink = $this->link(
1160 htmlspecialchars( $display ),
1163 array( 'known', 'noclasses' )
1167 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1169 $subpages .= '< ';
1171 $subpages .= $getlink;
1176 $growinglink .= '/';
1184 * Returns true if the IP should be shown in the header
1186 function showIPinHeader() {
1187 global $wgShowIPinHeader;
1188 return $wgShowIPinHeader && session_id() != '';
1191 function nameAndLogin() {
1192 global $wgUser, $wgLang, $wgContLang;
1194 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1197 if ( $wgUser->isAnon() ) {
1198 if( $this->showIPinHeader() ) {
1201 $talkLink = $this->link( $wgUser->getTalkPage(),
1202 $wgLang->getNsText( NS_TALK
) );
1204 $ret .= "$name ($talkLink)";
1206 $ret .= wfMsg( 'notloggedin' );
1209 $returnTo = $this->mTitle
->getPrefixedDBkey();
1211 if ( $logoutPage != $returnTo ) {
1212 $query['returnto'] = $returnTo;
1215 $loginlink = $wgUser->isAllowed( 'createaccount' )
1216 ?
'nav-login-createaccount'
1218 $ret .= "\n<br />" . $this->link(
1219 SpecialPage
::getTitleFor( 'Userlogin' ),
1220 wfMsg( $loginlink ), array(), $query
1223 $returnTo = $this->mTitle
->getPrefixedDBkey();
1224 $talkLink = $this->link( $wgUser->getTalkPage(),
1225 $wgLang->getNsText( NS_TALK
) );
1227 $ret .= $this->link( $wgUser->getUserPage(),
1228 htmlspecialchars( $wgUser->getName() ) );
1229 $ret .= " ($talkLink)<br />";
1230 $ret .= $wgLang->pipeList( array(
1232 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1233 array(), array( 'returnto' => $returnTo )
1235 $this->specialLink( 'preferences' ),
1238 $ret = $wgLang->pipeList( array(
1241 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1249 function getSearchLink() {
1250 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1251 return $searchPage->getLocalURL();
1254 function escapeSearchLink() {
1255 return htmlspecialchars( $this->getSearchLink() );
1258 function searchForm() {
1259 global $wgRequest, $wgUseTwoButtonsSearchForm;
1260 $search = $wgRequest->getText( 'search' );
1262 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1263 . $this->escapeSearchLink() . "\">\n"
1264 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1265 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1266 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1268 if( $wgUseTwoButtonsSearchForm )
1269 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1271 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1275 // Ensure unique id's for search boxes made after the first
1276 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1281 function topLinks() {
1285 $this->mainPageLink(),
1286 $this->specialLink( 'recentchanges' )
1289 if ( $wgOut->isArticleRelated() ) {
1290 $s[] = $this->editThisPage();
1291 $s[] = $this->historyLink();
1293 # Many people don't like this dropdown box
1294 #$s[] = $this->specialPagesList();
1296 if( $this->variantLinks() ) {
1297 $s[] = $this->variantLinks();
1300 if( $this->extensionTabLinks() ) {
1301 $s[] = $this->extensionTabLinks();
1304 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1305 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1309 * Compatibility for extensions adding functionality through tabs.
1310 * Eventually these old skins should be replaced with SkinTemplate-based
1314 function extensionTabLinks() {
1318 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1319 foreach( $tabs as $tab ) {
1320 $s[] = Xml
::element( 'a',
1321 array( 'href' => $tab['href'] ),
1328 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1329 $out .= $wgLang->pipeList( $s );
1336 * Language/charset variant links for classic-style skins
1339 function variantLinks() {
1341 /* show links to different language variants */
1342 global $wgDisableLangConversion, $wgLang, $wgContLang;
1343 $variants = $wgContLang->getVariants();
1344 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1345 foreach( $variants as $code ) {
1346 $varname = $wgContLang->getVariantname( $code );
1347 if( $varname == 'disable' )
1349 $s = $wgLang->pipeList( array(
1351 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1358 function bottomLinks() {
1359 global $wgOut, $wgUser, $wgUseTrackbacks;
1360 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1363 if ( $wgOut->isArticleRelated() ) {
1364 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1365 if ( $wgUser->isLoggedIn() ) {
1366 $element[] = $this->watchThisPage();
1368 $element[] = $this->talkLink();
1369 $element[] = $this->historyLink();
1370 $element[] = $this->whatLinksHere();
1371 $element[] = $this->watchPageLinksLink();
1373 if( $wgUseTrackbacks )
1374 $element[] = $this->trackbackLink();
1376 if ( $this->mTitle
->getNamespace() == NS_USER
1377 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1378 $id = User
::idFromName( $this->mTitle
->getText() );
1379 $ip = User
::isIP( $this->mTitle
->getText() );
1381 if( $id ||
$ip ) { # both anons and non-anons have contri list
1382 $element[] = $this->userContribsLink();
1384 if( $this->showEmailUser( $id ) ) {
1385 $element[] = $this->emailUserLink();
1389 $s = implode( $element, $sep );
1391 if ( $this->mTitle
->getArticleId() ) {
1393 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1394 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1395 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1397 $s .= "<br />\n" . $this->otherLanguages();
1403 function pageStats() {
1404 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1405 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1407 $oldid = $wgRequest->getVal( 'oldid' );
1408 $diff = $wgRequest->getVal( 'diff' );
1409 if ( ! $wgOut->isArticle() ) { return ''; }
1410 if( !$wgArticle instanceOf Article
) { return ''; }
1411 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1412 if ( 0 == $wgArticle->getID() ) { return ''; }
1415 if ( !$wgDisableCounters ) {
1416 $count = $wgLang->formatNum( $wgArticle->getCount() );
1418 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1422 if( $wgMaxCredits != 0 ){
1423 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1425 $s .= $this->lastModified();
1428 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1429 $dbr = wfGetDB( DB_SLAVE
);
1430 $res = $dbr->select( 'watchlist',
1431 array( 'COUNT(*) AS n' ),
1432 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1435 $x = $dbr->fetchObject( $res );
1437 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1438 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1442 return $s . ' ' . $this->getCopyright();
1445 function getCopyright( $type = 'detect' ) {
1446 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1448 if ( $type == 'detect' ) {
1449 $diff = $wgRequest->getVal( 'diff' );
1450 $isCur = $wgArticle && $wgArticle->isCurrent();
1451 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1458 if ( $type == 'history' ) {
1459 $msg = 'history_copyright';
1465 if( $wgRightsPage ) {
1466 $title = Title
::newFromText( $wgRightsPage );
1467 $link = $this->linkKnown( $title, $wgRightsText );
1468 } elseif( $wgRightsUrl ) {
1469 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1470 } elseif( $wgRightsText ) {
1471 $link = $wgRightsText;
1476 // Allow for site and per-namespace customization of copyright notice.
1477 if( isset($wgArticle) )
1478 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1480 $out .= wfMsgForContent( $msg, $link );
1484 function getCopyrightIcon() {
1485 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1487 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1488 $out = $wgCopyrightIcon;
1489 } else if ( $wgRightsIcon ) {
1490 $icon = htmlspecialchars( $wgRightsIcon );
1491 if ( $wgRightsUrl ) {
1492 $url = htmlspecialchars( $wgRightsUrl );
1493 $out .= '<a href="'.$url.'">';
1495 $text = htmlspecialchars( $wgRightsText );
1496 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1497 if ( $wgRightsUrl ) {
1504 function getPoweredBy() {
1505 global $wgStylePath;
1506 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1507 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1511 function lastModified() {
1512 global $wgLang, $wgArticle;
1513 if( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest()) {
1514 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1516 $timestamp = $wgArticle->getTimestamp();
1519 $d = $wgLang->date( $timestamp, true );
1520 $t = $wgLang->time( $timestamp, true );
1521 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1525 if ( wfGetLB()->getLaggedSlaveMode() ) {
1526 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1531 function logoText( $align = '' ) {
1532 if ( '' != $align ) {
1533 $a = " align='{$align}'";
1538 $mp = wfMsg( 'mainpage' );
1539 $mptitle = Title
::newMainPage();
1540 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1542 $logourl = $this->getLogo();
1543 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1548 * show a drop-down box of special pages
1550 function specialPagesList() {
1551 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1552 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1553 foreach ( $pages as $name => $page ) {
1554 $pages[$name] = $page->getDescription();
1557 $go = wfMsg( 'go' );
1558 $sp = wfMsg( 'specialpages' );
1559 $spp = $wgContLang->specialPage( 'Specialpages' );
1561 $s = '<form id="specialpages" method="get" ' .
1562 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1563 $s .= "<select name=\"wpDropdown\">\n";
1564 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1567 foreach ( $pages as $name => $desc ) {
1568 $p = $wgContLang->specialPage( $name );
1569 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1571 $s .= "</select>\n";
1572 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1577 function mainPageLink() {
1579 Title
::newMainPage(),
1580 wfMsg( 'mainpage' ),
1583 array( 'known', 'noclasses' )
1588 private function footerLink ( $desc, $page ) {
1589 // if the link description has been set to "-" in the default language,
1590 if ( wfMsgForContent( $desc ) == '-') {
1591 // then it is disabled, for all languages.
1594 // Otherwise, we display the link for the user, described in their
1595 // language (which may or may not be the same as the default language),
1596 // but we make the link target be the one site-wide page.
1597 $title = Title
::newFromText( wfMsgForContent( $page ) );
1598 return $this->linkKnown(
1600 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1605 function privacyLink() {
1606 return $this->footerLink( 'privacy', 'privacypage' );
1609 function aboutLink() {
1610 return $this->footerLink( 'aboutsite', 'aboutpage' );
1613 function disclaimerLink() {
1614 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1617 function editThisPage() {
1620 if ( !$wgOut->isArticleRelated() ) {
1621 $s = wfMsg( 'protectedpage' );
1623 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1624 $t = wfMsg( 'editthispage' );
1625 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1626 $t = wfMsg( 'create-this-page' );
1628 $t = wfMsg( 'viewsource' );
1635 $this->editUrlOptions(),
1636 array( 'known', 'noclasses' )
1643 * Return URL options for the 'edit page' link.
1644 * This may include an 'oldid' specifier, if the current page view is such.
1649 function editUrlOptions() {
1652 $options = array( 'action' => 'edit' );
1654 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1655 $options['oldid'] = intval( $this->mRevisionId
);
1661 function deleteThisPage() {
1662 global $wgUser, $wgRequest;
1664 $diff = $wgRequest->getVal( 'diff' );
1665 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1666 $t = wfMsg( 'deletethispage' );
1672 array( 'action' => 'delete' ),
1673 array( 'known', 'noclasses' )
1681 function protectThisPage() {
1682 global $wgUser, $wgRequest;
1684 $diff = $wgRequest->getVal( 'diff' );
1685 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1686 if ( $this->mTitle
->isProtected() ) {
1687 $text = wfMsg( 'unprotectthispage' );
1688 $query = array( 'action' => 'unprotect' );
1690 $text = wfMsg( 'protectthispage' );
1691 $query = array( 'action' => 'protect' );
1699 array( 'known', 'noclasses' )
1707 function watchThisPage() {
1709 ++
$this->mWatchLinkNum
;
1711 if ( $wgOut->isArticleRelated() ) {
1712 if ( $this->mTitle
->userIsWatching() ) {
1713 $text = wfMsg( 'unwatchthispage' );
1714 $query = array( 'action' => 'unwatch' );
1715 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1717 $text = wfMsg( 'watchthispage' );
1718 $query = array( 'action' => 'watch' );
1719 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1725 array( 'id' => $id ),
1727 array( 'known', 'noclasses' )
1730 $s = wfMsg( 'notanarticle' );
1735 function moveThisPage() {
1736 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1738 SpecialPage
::getTitleFor( 'Movepage' ),
1739 wfMsg( 'movethispage' ),
1741 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1742 array( 'known', 'noclasses' )
1745 // no message if page is protected - would be redundant
1750 function historyLink() {
1753 wfMsgHtml( 'history' ),
1754 array( 'rel' => 'archives' ),
1755 array( 'action' => 'history' )
1759 function whatLinksHere() {
1761 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1762 wfMsgHtml( 'whatlinkshere' ),
1765 array( 'known', 'noclasses' )
1769 function userContribsLink() {
1771 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1772 wfMsgHtml( 'contributions' ),
1775 array( 'known', 'noclasses' )
1779 function showEmailUser( $id ) {
1781 $targetUser = User
::newFromId( $id );
1782 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1783 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1786 function emailUserLink() {
1788 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1789 wfMsg( 'emailuser' ),
1792 array( 'known', 'noclasses' )
1796 function watchPageLinksLink() {
1798 if ( ! $wgOut->isArticleRelated() ) {
1799 return '(' . wfMsg( 'notanarticle' ) . ')';
1802 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1803 wfMsg( 'recentchangeslinked-toolbox' ),
1806 array( 'known', 'noclasses' )
1811 function trackbackLink() {
1812 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1813 . wfMsg( 'trackbacklink' ) . '</a>';
1816 function otherLanguages() {
1817 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1819 if ( $wgHideInterlanguageLinks ) {
1823 $a = $wgOut->getLanguageLinks();
1824 if ( 0 == count( $a ) ) {
1828 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1830 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1831 foreach( $a as $l ) {
1833 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1837 $nt = Title
::newFromText( $l );
1838 $url = $nt->escapeFullURL();
1839 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1841 if ( '' == $text ) { $text = $l; }
1842 $style = $this->getExternalLinkAttributes();
1843 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1845 if( $wgContLang->isRTL() ) $s .= '</span>';
1849 function talkLink() {
1850 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1851 # No discussion links for special pages
1855 $linkOptions = array();
1857 if( $this->mTitle
->isTalkPage() ) {
1858 $link = $this->mTitle
->getSubjectPage();
1859 switch( $link->getNamespace() ) {
1861 $text = wfMsg( 'articlepage' );
1864 $text = wfMsg( 'userpage' );
1867 $text = wfMsg( 'projectpage' );
1870 $text = wfMsg( 'imagepage' );
1871 # Make link known if image exists, even if the desc. page doesn't.
1872 if( wfFindFile( $link ) )
1873 $linkOptions[] = 'known';
1876 $text = wfMsg( 'mediawikipage' );
1879 $text = wfMsg( 'templatepage' );
1882 $text = wfMsg( 'viewhelppage' );
1885 $text = wfMsg( 'categorypage' );
1888 $text = wfMsg( 'articlepage' );
1891 $link = $this->mTitle
->getTalkPage();
1892 $text = wfMsg( 'talkpage' );
1895 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1900 function commentLink() {
1903 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1907 # __NEWSECTIONLINK___ changes behaviour here
1908 # If it is present, the link points to this page, otherwise
1909 # it points to the talk page
1910 if( $this->mTitle
->isTalkPage() ) {
1911 $title = $this->mTitle
;
1912 } elseif( $wgOut->showNewSectionLink() ) {
1913 $title = $this->mTitle
;
1915 $title = $this->mTitle
->getTalkPage();
1920 wfMsg( 'postcomment' ),
1926 array( 'known', 'noclasses' )
1930 /* these are used extensively in SkinTemplate, but also some other places */
1931 static function makeMainPageUrl( $urlaction = '' ) {
1932 $title = Title
::newMainPage();
1933 self
::checkTitle( $title, '' );
1934 return $title->getLocalURL( $urlaction );
1937 static function makeSpecialUrl( $name, $urlaction = '' ) {
1938 $title = SpecialPage
::getTitleFor( $name );
1939 return $title->getLocalURL( $urlaction );
1942 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1943 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1944 return $title->getLocalURL( $urlaction );
1947 static function makeI18nUrl( $name, $urlaction = '' ) {
1948 $title = Title
::newFromText( wfMsgForContent( $name ) );
1949 self
::checkTitle( $title, $name );
1950 return $title->getLocalURL( $urlaction );
1953 static function makeUrl( $name, $urlaction = '' ) {
1954 $title = Title
::newFromText( $name );
1955 self
::checkTitle( $title, $name );
1956 return $title->getLocalURL( $urlaction );
1959 # If url string starts with http, consider as external URL, else
1961 static function makeInternalOrExternalUrl( $name ) {
1962 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1965 return self
::makeUrl( $name );
1969 # this can be passed the NS number as defined in Language.php
1970 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1971 $title = Title
::makeTitleSafe( $namespace, $name );
1972 self
::checkTitle( $title, $name );
1973 return $title->getLocalURL( $urlaction );
1976 /* these return an array with the 'href' and boolean 'exists' */
1977 static function makeUrlDetails( $name, $urlaction = '' ) {
1978 $title = Title
::newFromText( $name );
1979 self
::checkTitle( $title, $name );
1981 'href' => $title->getLocalURL( $urlaction ),
1982 'exists' => $title->getArticleID() != 0 ?
true : false
1987 * Make URL details where the article exists (or at least it's convenient to think so)
1989 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1990 $title = Title
::newFromText( $name );
1991 self
::checkTitle( $title, $name );
1993 'href' => $title->getLocalURL( $urlaction ),
1998 # make sure we have some title to operate on
1999 static function checkTitle( &$title, $name ) {
2000 if( !is_object( $title ) ) {
2001 $title = Title
::newFromText( $name );
2002 if( !is_object( $title ) ) {
2003 $title = Title
::newFromText( '--error: link target missing--' );
2009 * Build an array that represents the sidebar(s), the navigation bar among them
2013 function buildSidebar() {
2014 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2016 wfProfileIn( __METHOD__
);
2018 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2020 if ( $wgEnableSidebarCache ) {
2021 $cachedsidebar = $parserMemc->get( $key );
2022 if ( $cachedsidebar ) {
2023 wfProfileOut( __METHOD__
);
2024 return $cachedsidebar;
2029 $this->addToSidebar( $bar, 'sidebar' );
2031 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2032 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2033 wfProfileOut( __METHOD__
);
2037 * Add content from a sidebar system message
2038 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2040 * @param &$bar array
2041 * @param $message String
2043 function addToSidebar( &$bar, $message ) {
2044 $lines = explode( "\n", wfMsgForContent( $message ) );
2046 foreach( $lines as $line ) {
2047 if( strpos( $line, '*' ) !== 0 )
2049 if( strpos( $line, '**') !== 0 ) {
2050 $heading = trim( $line, '* ' );
2051 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
2053 if( strpos( $line, '|' ) !== false ) { // sanity check
2054 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2055 $link = wfMsgForContent( $line[0] );
2059 $text = wfMsgExt( $line[1], 'parsemag' );
2060 if( wfEmptyMsg( $line[1], $text ) )
2062 if( wfEmptyMsg( $line[0], $link ) )
2065 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2068 $title = Title
::newFromText( $link );
2070 $title = $title->fixSpecialName();
2071 $href = $title->getLocalURL();
2073 $href = 'INVALID-TITLE';
2077 $bar[$heading][] = array(
2080 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2083 } else { continue; }
2089 * Should we include common/wikiprintable.css? Skins that have their own
2090 * print stylesheet should override this and return false. (This is an
2091 * ugly hack to get Monobook to play nicely with
2092 * OutputPage::headElement().)
2096 public function commonPrintStylesheet() {