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 ) {
334 global $wgJsMimeType;
336 $r = array( "<script type=\"$wgJsMimeType\">/*<![CDATA[*/" );
337 foreach ( $data as $name => $value ) {
338 $encValue = Xml
::encodeJsVar( $value );
339 $r[] = "var $name = $encValue;";
341 $r[] = "/*]]>*/</script>\n";
343 return implode( "\n\t\t", $r );
347 * Make a <script> tag containing global variables
348 * @param array $data Associative array containing one element:
349 * skinname => the skin name
350 * The odd calling convention is for backwards compatibility
351 * @TODO @FIXME Make this not depend on $wgTitle!
353 static function makeGlobalVariablesScript( $data ) {
354 global $wgScript, $wgTitle, $wgStylePath, $wgUser;
355 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang, $wgVariant;
356 global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
357 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
358 global $wgUseAjax, $wgAjaxWatch;
359 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
360 global $wgRestrictionTypes, $wgLivePreview;
361 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
363 $ns = $wgTitle->getNamespace();
364 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ?
$wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
365 $separatorTransTable = $wgContLang->separatorTransformTable();
366 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
367 $compactSeparatorTransTable = array(
368 implode( "\t", array_keys( $separatorTransTable ) ),
369 implode( "\t", $separatorTransTable ),
371 $digitTransTable = $wgContLang->digitTransformTable();
372 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
373 $compactDigitTransTable = array(
374 implode( "\t", array_keys( $digitTransTable ) ),
375 implode( "\t", $digitTransTable ),
379 'skin' => $data['skinname'],
380 'stylepath' => $wgStylePath,
381 'wgArticlePath' => $wgArticlePath,
382 'wgScriptPath' => $wgScriptPath,
383 'wgScript' => $wgScript,
384 'wgVariantArticlePath' => $wgVariantArticlePath,
385 'wgActionPaths' => (object)$wgActionPaths,
386 'wgServer' => $wgServer,
387 'wgCanonicalNamespace' => $nsname,
388 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBkey() ),
389 'wgNamespaceNumber' => $wgTitle->getNamespace(),
390 'wgPageName' => $wgTitle->getPrefixedDBKey(),
391 'wgTitle' => $wgTitle->getText(),
392 'wgAction' => $wgRequest->getText( 'action', 'view' ),
393 'wgArticleId' => $wgTitle->getArticleId(),
394 'wgIsArticle' => $wgOut->isArticle(),
395 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
396 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
397 'wgUserVariant' => $wgVariant->getCode(),
398 'wgUserLanguage' => $wgLang->getCode(),
399 'wgContentLanguage' => $wgContLang->getCode(),
400 'wgBreakFrames' => $wgBreakFrames,
401 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
402 'wgVersion' => $wgVersion,
403 'wgEnableAPI' => $wgEnableAPI,
404 'wgEnableWriteAPI' => $wgEnableWriteAPI,
405 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
406 'wgDigitTransformTable' => $compactDigitTransTable,
408 if ( !( $wgContLang->hasVariants() ) ) {
409 unset( $vars['wgUserVariant'] );
412 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
413 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
414 $vars['wgDBname'] = $wgDBname;
415 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
416 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
419 foreach( $wgRestrictionTypes as $type )
420 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
422 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
423 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
424 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
425 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
426 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
429 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
430 $msgs = (object)array();
431 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
432 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
434 $vars['wgAjaxWatch'] = $msgs;
437 // Allow extensions to add their custom variables to the global JS variables
438 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
440 return self
::makeVariablesScript( $vars );
443 function getHeadScripts( $allowUserJs ) {
444 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
446 $vars = self
::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
448 $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
451 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
452 $r[] = "<script type=\"$wgJsMimeType\" src=\"".
453 htmlspecialchars( self
::makeUrl( '-',
454 "action=raw$jsCache&gen=js&useskin=" .
455 urlencode( $this->getSkinName() ) ) ) .
456 "\"><!-- site js --></script>";
458 if( $allowUserJs && $wgUser->isLoggedIn() ) {
459 $userpage = $wgUser->getUserPage();
460 $userjs = htmlspecialchars( self
::makeUrl(
461 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
462 'action=raw&ctype='.$wgJsMimeType ) );
463 $r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
465 return $vars . "\t\t" . implode ( "\n\t\t", $r );
469 * To make it harder for someone to slip a user a fake
470 * user-JavaScript or user-CSS preview, a random token
471 * is associated with the login session. If it's not
472 * passed back with the preview request, we won't render
475 * @param string $action
479 function userCanPreview( $action ) {
480 global $wgRequest, $wgUser;
482 if( $action != 'submit' )
484 if( !$wgRequest->wasPosted() )
486 if( !$this->mTitle
->userCanEditCssJsSubpage() )
488 return $wgUser->matchEditToken(
489 $wgRequest->getVal( 'wpEditToken' ) );
493 * generated JavaScript action=raw&gen=js
494 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
495 * nated together. For some bizarre reason, it does *not* return any
496 * custom user JS from subpages. Huh?
498 * There's absolutely no reason to have separate Monobook/Common JSes.
499 * Any JS that cares can just check the skin variable generated at the
500 * top. For now Monobook.js will be maintained, but it should be consi-
505 public function generateUserJs() {
508 wfProfileIn( __METHOD__
);
510 $s = "/* generated javascript */\n";
511 $s .= "var skin = '" . Xml
::escapeJsString( $this->getSkinName() ) . "';\n";
512 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
513 $s .= "\n\n/* MediaWiki:Common.js */\n";
514 $commonJs = wfMsgForContent( 'common.js' );
515 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
519 $s .= "\n\n/* MediaWiki:".ucfirst( $this->getSkinName() ).".js */\n";
520 // avoid inclusion of non defined user JavaScript (with custom skins only)
521 // by checking for default message content
522 $msgKey = ucfirst( $this->getSkinName() ).'.js';
523 $userJS = wfMsgForContent( $msgKey );
524 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
528 wfProfileOut( __METHOD__
);
533 * Generate user stylesheet for action=raw&gen=css
535 public function generateUserStylesheet() {
536 wfProfileIn( __METHOD__
);
537 $s = "/* generated user stylesheet */\n" .
538 $this->reallyGenerateUserStylesheet();
539 wfProfileOut( __METHOD__
);
544 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
546 protected function reallyGenerateUserStylesheet(){
549 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
550 $underline = $undopt ?
'underline' : 'none';
551 $s .= "a { text-decoration: $underline; }\n";
553 if( $wgUser->getOption( 'highlightbroken' ) ) {
554 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
557 a.new, #quickbar a.new,
558 a.stub, #quickbar a.stub {
561 a.new:after, #quickbar a.new:after {
565 a.stub:after, #quickbar a.stub:after {
571 if( $wgUser->getOption( 'justify' ) ) {
572 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
574 if( !$wgUser->getOption( 'showtoc' ) ) {
575 $s .= "#toc { display: none; }\n";
577 if( !$wgUser->getOption( 'editsection' ) ) {
578 $s .= ".editsection { display: none; }\n";
586 function setupUserCss( OutputPage
$out ) {
587 global $wgRequest, $wgContLang, $wgUser;
588 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
590 wfProfileIn( __METHOD__
);
592 $this->setupSkinUserCss( $out );
596 'maxage' => $wgSquidMaxage,
599 // Add any extension CSS
600 foreach( $out->getExtStyle() as $tag ) {
601 $out->addStyle( $tag['href'] );
604 // If we use the site's dynamic CSS, throw that in, too
605 // Per-site custom styles
606 if( $wgUseSiteCss ) {
607 global $wgHandheldStyle;
608 $query = wfArrayToCGI( array(
609 'usemsgcache' => 'yes',
610 'ctype' => 'text/css',
611 'smaxage' => $wgSquidMaxage
613 # Site settings must override extension css! (bug 15025)
614 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
615 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
616 if( $wgHandheldStyle ) {
617 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
619 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
622 if( $wgUser->isLoggedIn() ) {
623 // Ensure that logged-in users' generated CSS isn't clobbered
624 // by anons' publicly cacheable generated CSS.
625 $siteargs['smaxage'] = '0';
626 $siteargs['ts'] = $wgUser->mTouched
;
628 // Per-user styles based on preferences
629 $siteargs['gen'] = 'css';
630 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
631 $siteargs['useskin'] = $us;
633 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
635 // Per-user custom style pages
636 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
637 $action = $wgRequest->getVal( 'action' );
638 # If we're previewing the CSS page, use it
639 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
640 $previewCss = $wgRequest->getText( 'wpTextbox1' );
641 // @FIXME: properly escape the cdata!
642 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
644 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
645 'action=raw&ctype=text/css' ) );
649 wfProfileOut( __METHOD__
);
653 * Add skin specific stylesheets
654 * @param $out OutputPage
656 function setupSkinUserCss( OutputPage
$out ) {
657 $out->addStyle( 'common/shared.css' );
658 $out->addStyle( 'common/oldshared.css' );
659 $out->addStyle( $this->getStylesheet() );
660 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
663 function getBodyOptions() {
664 global $wgUser, $wgOut, $wgRequest, $wgContLang;
666 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
668 if ( 0 != $this->mTitle
->getNamespace() ) {
669 $a = array( 'bgcolor' => '#ffffec' );
671 else $a = array( 'bgcolor' => '#FFFFFF' );
672 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
673 $this->mTitle
->quickUserCan( 'edit' ) ) {
674 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
675 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
676 $a +
= array( 'ondblclick' => $s );
678 $a['onload'] = $wgOut->getOnloadHandler();
681 ' '.( $wgContLang->isRTL() ?
'rtl' : 'ltr' ).
682 ' '.$this->getPageClasses( $this->mTitle
) .
683 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
687 function getPageClasses( $title ) {
688 $numeric = 'ns-'.$title->getNamespace();
689 if( $title->getNamespace() == NS_SPECIAL
) {
690 $type = 'ns-special';
691 } elseif( $title->isTalkPage() ) {
694 $type = 'ns-subject';
696 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
697 return "$numeric $type $name";
709 * This will be called immediately after the <body> tag. Split into
710 * two functions to make it easier to subclass.
712 function beforeContent() {
713 return $this->doBeforeContent();
716 function doBeforeContent() {
718 wfProfileIn( __METHOD__
);
721 $qb = $this->qbSetting();
723 if( $langlinks = $this->otherLanguages() ) {
729 $borderhack = 'class="top"';
732 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
733 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
735 $shove = ( $qb != 0 );
736 $left = ( $qb == 1 ||
$qb == 3 );
737 if( $wgContLang->isRTL() ) $left = !$left;
740 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
741 $this->logoText() . '</td>';
743 $s .= $this->getQuickbarCompensator( $rows );
745 $l = $wgContLang->isRTL() ?
'right' : 'left';
746 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
748 $s .= $this->topLinks();
749 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
751 $r = $wgContLang->isRTL() ?
'left' : 'right';
752 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
753 $s .= $this->nameAndLogin();
754 $s .= "\n<br />" . $this->searchForm() . "</td>";
757 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
760 if ( $shove && !$left ) { # Right
761 $s .= $this->getQuickbarCompensator( $rows );
763 $s .= "</tr>\n</table>\n</div>\n";
764 $s .= "\n<div id='article'>\n";
766 $notice = wfGetSiteNotice();
768 $s .= "\n<div id='siteNotice'>$notice</div>\n";
770 $s .= $this->pageTitle();
771 $s .= $this->pageSubtitle();
772 $s .= $this->getCategories();
773 wfProfileOut( __METHOD__
);
778 function getCategoryLinks() {
779 global $wgOut, $wgUseCategoryBrowser;
780 global $wgContLang, $wgUser;
782 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
785 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
787 // Use Unicode bidi embedding override characters,
788 // to make sure links don't smash each other up in ugly ways.
789 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
790 $embed = "<span dir='$dir'>";
793 $allCats = $wgOut->getCategoryLinks();
795 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
796 if ( !empty( $allCats['normal'] ) ) {
797 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
799 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
800 $s .= '<div id="mw-normal-catlinks">' .
801 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
802 . $colon . $t . '</div>';
806 if ( isset( $allCats['hidden'] ) ) {
807 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
808 $class ='mw-hidden-cats-user-shown';
809 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
810 $class = 'mw-hidden-cats-ns-shown';
812 $class = 'mw-hidden-cats-hidden';
814 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
815 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
816 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
820 # optional 'dmoz-like' category browser. Will be shown under the list
821 # of categories an article belong to
822 if( $wgUseCategoryBrowser ){
823 $s .= '<br /><hr />';
825 # get a big array of the parents tree
826 $parenttree = $this->mTitle
->getParentCategoryTree();
827 # Skin object passed by reference cause it can not be
828 # accessed under the method subfunction drawCategoryBrowser
829 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
830 # Clean out bogus first entry and sort them
831 unset( $tempout[0] );
833 # Output one per line
834 $s .= implode( "<br />\n", $tempout );
841 * Render the array as a serie of links.
842 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
843 * @param &skin Object: skin passed by reference
844 * @return String separated by >, terminate with "\n"
846 function drawCategoryBrowser( $tree, &$skin ){
848 foreach( $tree as $element => $parent ) {
849 if( empty( $parent ) ) {
850 # element start a new list
853 # grab the others elements
854 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
856 # add our current element to the list
857 $eltitle = Title
::newFromText( $element );
858 $return .= $skin->link( $eltitle, $eltitle->getText() );
863 function getCategories() {
864 $catlinks=$this->getCategoryLinks();
866 $classes = 'catlinks';
868 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
869 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
870 $classes .= ' catlinks-allhidden';
873 if( !empty( $catlinks ) ){
874 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
878 function getQuickbarCompensator( $rows = 1 ) {
879 return "<td width='152' rowspan='{$rows}'> </td>";
883 * This runs a hook to allow extensions placing their stuff after content
884 * and article metadata (e.g. categories).
885 * Note: This function has nothing to do with afterContent().
887 * This hook is placed here in order to allow using the same hook for all
888 * skins, both the SkinTemplate based ones and the older ones, which directly
889 * use this class to get their data.
891 * The output of this function gets processed in SkinTemplate::outputPage() for
892 * the SkinTemplate based skins, all other skins should directly echo it.
894 * Returns an empty string by default, if not changed by any hook function.
896 protected function afterContentHook() {
899 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
900 // adding just some spaces shouldn't toggle the output
901 // of the whole <div/>, so we use trim() here
902 if( trim( $data ) != '' ){
903 // Doing this here instead of in the skins to
904 // ensure that the div has the same ID in all
906 $data = "<div id='mw-data-after-content'>\n" .
911 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
918 * Generate debug data HTML for displaying at the bottom of the main content
920 * @return String HTML containing debug data, if enabled (otherwise empty).
922 protected function generateDebugHTML() {
923 global $wgShowDebug, $wgOut;
924 if ( $wgShowDebug ) {
925 $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext
) );
926 return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
927 $listInternals . "</li></ul>\n";
933 * This gets called shortly before the </body> tag.
934 * @return String HTML to be put before </body>
936 function afterContent() {
937 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
938 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
942 * This gets called shortly before the </body> tag.
943 * @return String HTML-wrapped JS code to be put before </body>
945 function bottomScripts() {
946 global $wgJsMimeType;
947 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
948 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
949 return $bottomScriptText;
952 /** @return string Retrievied from HTML text */
953 function printSource() {
954 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
955 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
958 function printFooter() {
959 return "<p>" . $this->printSource() .
960 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
963 /** overloaded by derived classes */
964 function doAfterContent() { return '</div></div>'; }
966 function pageTitleLinks() {
967 global $wgOut, $wgUser, $wgRequest, $wgLang;
969 $oldid = $wgRequest->getVal( 'oldid' );
970 $diff = $wgRequest->getVal( 'diff' );
971 $action = $wgRequest->getText( 'action' );
973 $s[] = $this->printableLink();
974 $disclaimer = $this->disclaimerLink(); # may be empty
978 $privacy = $this->privacyLink(); # may be empty too
983 if ( $wgOut->isArticleRelated() ) {
984 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
985 $name = $this->mTitle
->getDBkey();
986 $image = wfFindFile( $this->mTitle
);
988 $link = htmlspecialchars( $image->getURL() );
989 $style = $this->getInternalLinkAttributes( $link, $name );
990 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
994 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
997 wfMsg( 'currentrev' ),
1000 array( 'known', 'noclasses' )
1004 if ( $wgUser->getNewtalk() ) {
1005 # do not show "You have new messages" text when we are viewing our
1007 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1009 $wgUser->getTalkPage(),
1010 wfMsgHtml( 'newmessageslink' ),
1012 array( 'redirect' => 'no' ),
1013 array( 'known', 'noclasses' )
1017 $wgUser->getTalkPage(),
1018 wfMsgHtml( 'newmessagesdifflink' ),
1020 array( 'diff' => 'cur' ),
1021 array( 'known', 'noclasses' )
1023 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1025 $wgOut->setSquidMaxage( 0 );
1026 $wgOut->enableClientCache( false );
1030 $undelete = $this->getUndeleteLink();
1031 if( !empty( $undelete ) ) {
1034 return $wgLang->pipeList( $s );
1037 function getUndeleteLink() {
1038 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1040 $action = $wgRequest->getVal( 'action', 'view' );
1042 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1043 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1044 $n = $this->mTitle
->isDeleted();
1046 if ( $wgUser->isAllowed( 'undelete' ) ) {
1047 $msg = 'thisisdeleted';
1049 $msg = 'viewdeleted';
1054 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1055 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1058 array( 'known', 'noclasses' )
1066 function printableLink() {
1067 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1069 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1071 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1072 if( $wgOut->isSyndicated() ) {
1073 foreach( $wgFeedClasses as $format => $class ) {
1074 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1075 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1076 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1079 return $wgLang->pipeList( $s );
1082 function pageTitle() {
1084 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1088 function pageSubtitle() {
1091 $sub = $wgOut->getSubtitle();
1093 global $wgExtraSubtitle;
1094 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1096 $subpages = $this->subPageSubtitle();
1097 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1098 $s = "<p class='subtitle'>{$sub}</p>\n";
1102 function subPageSubtitle() {
1104 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1108 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1109 $ptext = $this->mTitle
->getPrefixedText();
1110 if( preg_match( '/\//', $ptext ) ) {
1111 $links = explode( '/', $ptext );
1112 array_pop( $links );
1116 foreach( $links as $link ) {
1117 $growinglink .= $link;
1119 $linkObj = Title
::newFromText( $growinglink );
1120 if( is_object( $linkObj ) && $linkObj->exists() ){
1121 $getlink = $this->link(
1123 htmlspecialchars( $display ),
1126 array( 'known', 'noclasses' )
1130 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1132 $subpages .= '< ';
1134 $subpages .= $getlink;
1139 $growinglink .= '/';
1147 * Returns true if the IP should be shown in the header
1149 function showIPinHeader() {
1150 global $wgShowIPinHeader;
1151 return $wgShowIPinHeader && session_id() != '';
1154 function nameAndLogin() {
1155 global $wgUser, $wgLang, $wgContLang;
1157 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1160 if ( $wgUser->isAnon() ) {
1161 if( $this->showIPinHeader() ) {
1164 $talkLink = $this->link( $wgUser->getTalkPage(),
1165 $wgLang->getNsText( NS_TALK
) );
1167 $ret .= "$name ($talkLink)";
1169 $ret .= wfMsg( 'notloggedin' );
1172 $returnTo = $this->mTitle
->getPrefixedDBkey();
1174 if ( $logoutPage != $returnTo ) {
1175 $query['returnto'] = $returnTo;
1178 $loginlink = $wgUser->isAllowed( 'createaccount' )
1179 ?
'nav-login-createaccount'
1181 $ret .= "\n<br />" . $this->link(
1182 SpecialPage
::getTitleFor( 'Userlogin' ),
1183 wfMsg( $loginlink ), array(), $query
1186 $returnTo = $this->mTitle
->getPrefixedDBkey();
1187 $talkLink = $this->link( $wgUser->getTalkPage(),
1188 $wgLang->getNsText( NS_TALK
) );
1190 $ret .= $this->link( $wgUser->getUserPage(),
1191 htmlspecialchars( $wgUser->getName() ) );
1192 $ret .= " ($talkLink)<br />";
1193 $ret .= $wgLang->pipeList( array(
1195 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1196 array(), array( 'returnto' => $returnTo )
1198 $this->specialLink( 'preferences' ),
1201 $ret = $wgLang->pipeList( array(
1204 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1212 function getSearchLink() {
1213 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1214 return $searchPage->getLocalURL();
1217 function escapeSearchLink() {
1218 return htmlspecialchars( $this->getSearchLink() );
1221 function searchForm() {
1222 global $wgRequest, $wgUseTwoButtonsSearchForm;
1223 $search = $wgRequest->getText( 'search' );
1225 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1226 . $this->escapeSearchLink() . "\">\n"
1227 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1228 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1229 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1231 if( $wgUseTwoButtonsSearchForm )
1232 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1234 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1238 // Ensure unique id's for search boxes made after the first
1239 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1244 function topLinks() {
1248 $this->mainPageLink(),
1249 $this->specialLink( 'recentchanges' )
1252 if ( $wgOut->isArticleRelated() ) {
1253 $s[] = $this->editThisPage();
1254 $s[] = $this->historyLink();
1256 # Many people don't like this dropdown box
1257 #$s[] = $this->specialPagesList();
1259 if( $this->variantLinks() ) {
1260 $s[] = $this->variantLinks();
1263 if( $this->extensionTabLinks() ) {
1264 $s[] = $this->extensionTabLinks();
1267 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1268 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1272 * Compatibility for extensions adding functionality through tabs.
1273 * Eventually these old skins should be replaced with SkinTemplate-based
1277 function extensionTabLinks() {
1281 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1282 foreach( $tabs as $tab ) {
1283 $s[] = Xml
::element( 'a',
1284 array( 'href' => $tab['href'] ),
1291 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1292 $out .= $wgLang->pipeList( $s );
1299 * Language/charset variant links for classic-style skins
1302 function variantLinks() {
1304 /* show links to different language variants */
1305 global $wgDisableLangConversion, $wgLang, $wgContLang;
1306 $variants = $wgContLang->getVariants();
1307 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1308 foreach( $variants as $code ) {
1309 $varname = $wgContLang->getVariantname( $code );
1310 if( $varname == 'disable' )
1312 $s = $wgLang->pipeList( array(
1314 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1321 function bottomLinks() {
1322 global $wgOut, $wgUser, $wgUseTrackbacks;
1323 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1326 if ( $wgOut->isArticleRelated() ) {
1327 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1328 if ( $wgUser->isLoggedIn() ) {
1329 $element[] = $this->watchThisPage();
1331 $element[] = $this->talkLink();
1332 $element[] = $this->historyLink();
1333 $element[] = $this->whatLinksHere();
1334 $element[] = $this->watchPageLinksLink();
1336 if( $wgUseTrackbacks )
1337 $element[] = $this->trackbackLink();
1339 if ( $this->mTitle
->getNamespace() == NS_USER
1340 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1341 $id = User
::idFromName( $this->mTitle
->getText() );
1342 $ip = User
::isIP( $this->mTitle
->getText() );
1344 if( $id ||
$ip ) { # both anons and non-anons have contri list
1345 $element[] = $this->userContribsLink();
1347 if( $this->showEmailUser( $id ) ) {
1348 $element[] = $this->emailUserLink();
1352 $s = implode( $element, $sep );
1354 if ( $this->mTitle
->getArticleId() ) {
1356 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1357 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1358 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1360 $s .= "<br />\n" . $this->otherLanguages();
1366 function pageStats() {
1367 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1368 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1370 $oldid = $wgRequest->getVal( 'oldid' );
1371 $diff = $wgRequest->getVal( 'diff' );
1372 if ( ! $wgOut->isArticle() ) { return ''; }
1373 if( !$wgArticle instanceOf Article
) { return ''; }
1374 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1375 if ( 0 == $wgArticle->getID() ) { return ''; }
1378 if ( !$wgDisableCounters ) {
1379 $count = $wgLang->formatNum( $wgArticle->getCount() );
1381 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1385 if( $wgMaxCredits != 0 ){
1386 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1388 $s .= $this->lastModified();
1391 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1392 $dbr = wfGetDB( DB_SLAVE
);
1393 $res = $dbr->select( 'watchlist',
1394 array( 'COUNT(*) AS n' ),
1395 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1398 $x = $dbr->fetchObject( $res );
1400 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1401 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1405 return $s . ' ' . $this->getCopyright();
1408 function getCopyright( $type = 'detect' ) {
1409 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1411 if ( $type == 'detect' ) {
1412 $diff = $wgRequest->getVal( 'diff' );
1413 $isCur = $wgArticle && $wgArticle->isCurrent();
1414 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1421 if ( $type == 'history' ) {
1422 $msg = 'history_copyright';
1428 if( $wgRightsPage ) {
1429 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1430 } elseif( $wgRightsUrl ) {
1431 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1432 } elseif( $wgRightsText ) {
1433 $link = $wgRightsText;
1438 $out .= wfMsgForContent( $msg, $link );
1442 function getCopyrightIcon() {
1443 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1445 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1446 $out = $wgCopyrightIcon;
1447 } else if ( $wgRightsIcon ) {
1448 $icon = htmlspecialchars( $wgRightsIcon );
1449 if ( $wgRightsUrl ) {
1450 $url = htmlspecialchars( $wgRightsUrl );
1451 $out .= '<a href="'.$url.'">';
1453 $text = htmlspecialchars( $wgRightsText );
1454 $out .= "<img src=\"$icon\" alt='$text' />";
1455 if ( $wgRightsUrl ) {
1462 function getPoweredBy() {
1463 global $wgStylePath;
1464 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1465 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1469 function lastModified() {
1470 global $wgLang, $wgArticle;
1471 if( $this->mRevisionId
) {
1472 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1474 $timestamp = $wgArticle->getTimestamp();
1477 $d = $wgLang->date( $timestamp, true );
1478 $t = $wgLang->time( $timestamp, true );
1479 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1483 if ( wfGetLB()->getLaggedSlaveMode() ) {
1484 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1489 function logoText( $align = '' ) {
1490 if ( '' != $align ) {
1491 $a = " align='{$align}'";
1496 $mp = wfMsg( 'mainpage' );
1497 $mptitle = Title
::newMainPage();
1498 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1500 $logourl = $this->getLogo();
1501 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1506 * show a drop-down box of special pages
1508 function specialPagesList() {
1509 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1510 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1511 foreach ( $pages as $name => $page ) {
1512 $pages[$name] = $page->getDescription();
1515 $go = wfMsg( 'go' );
1516 $sp = wfMsg( 'specialpages' );
1517 $spp = $wgContLang->specialPage( 'Specialpages' );
1519 $s = '<form id="specialpages" method="get" ' .
1520 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1521 $s .= "<select name=\"wpDropdown\">\n";
1522 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1525 foreach ( $pages as $name => $desc ) {
1526 $p = $wgContLang->specialPage( $name );
1527 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1529 $s .= "</select>\n";
1530 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1535 function mainPageLink() {
1537 Title
::newMainPage(),
1538 wfMsg( 'mainpage' ),
1541 array( 'known', 'noclasses' )
1546 function copyrightLink() {
1547 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1548 wfMsg( 'copyrightpagename' ) );
1552 private function footerLink ( $desc, $page ) {
1553 // if the link description has been set to "-" in the default language,
1554 if ( wfMsgForContent( $desc ) == '-') {
1555 // then it is disabled, for all languages.
1558 // Otherwise, we display the link for the user, described in their
1559 // language (which may or may not be the same as the default language),
1560 // but we make the link target be the one site-wide page.
1561 return $this->makeKnownLink( wfMsgForContent( $page ),
1562 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1566 function privacyLink() {
1567 return $this->footerLink( 'privacy', 'privacypage' );
1570 function aboutLink() {
1571 return $this->footerLink( 'aboutsite', 'aboutpage' );
1574 function disclaimerLink() {
1575 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1578 function editThisPage() {
1581 if ( !$wgOut->isArticleRelated() ) {
1582 $s = wfMsg( 'protectedpage' );
1584 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1585 $t = wfMsg( 'editthispage' );
1586 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1587 $t = wfMsg( 'create-this-page' );
1589 $t = wfMsg( 'viewsource' );
1596 $this->editUrlOptions(),
1597 array( 'known', 'noclasses' )
1604 * Return URL options for the 'edit page' link.
1605 * This may include an 'oldid' specifier, if the current page view is such.
1610 function editUrlOptions() {
1613 $options = array( 'action' => 'edit' );
1615 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1616 $options['oldid'] = intval( $this->mRevisionId
);
1622 function deleteThisPage() {
1623 global $wgUser, $wgRequest;
1625 $diff = $wgRequest->getVal( 'diff' );
1626 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1627 $t = wfMsg( 'deletethispage' );
1633 array( 'action' => 'delete' ),
1634 array( 'known', 'noclasses' )
1642 function protectThisPage() {
1643 global $wgUser, $wgRequest;
1645 $diff = $wgRequest->getVal( 'diff' );
1646 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1647 if ( $this->mTitle
->isProtected() ) {
1648 $text = wfMsg( 'unprotectthispage' );
1649 $query = array( 'action' => 'unprotect' );
1651 $text = wfMsg( 'protectthispage' );
1652 $query = array( 'action' => 'protect' );
1660 array( 'known', 'noclasses' )
1668 function watchThisPage() {
1670 ++
$this->mWatchLinkNum
;
1672 if ( $wgOut->isArticleRelated() ) {
1673 if ( $this->mTitle
->userIsWatching() ) {
1674 $text = wfMsg( 'unwatchthispage' );
1675 $query = array( 'action' => 'unwatch' );
1676 $id = array( 'mw-unwatch-link' => $this->mWatchLinkNum
);
1678 $text = wfMsg( 'watchthispage' );
1679 $query = array( 'action' => 'watch' );
1680 $id = array( 'mw-watch-link' => $this->mWatchLinkNum
);
1686 array( 'id' => $id ),
1688 array( 'known', 'noclasses' )
1691 $s = wfMsg( 'notanarticle' );
1696 function moveThisPage() {
1697 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1699 SpecialPage
::getTitleFor( 'Movepage' ),
1700 wfMsg( 'movethispage' ),
1702 array( 'target' => $this->mTitle
->getPrefixedURL() ),
1703 array( 'known', 'noclasses' )
1706 // no message if page is protected - would be redundant
1711 function historyLink() {
1714 wfMsgHtml( 'history' ),
1715 array( 'rel' => 'archives' ),
1716 array( 'action' => 'history' )
1720 function whatLinksHere() {
1722 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1723 wfMsgHtml( 'whatlinkshere' ),
1726 array( 'known', 'noclasses' )
1730 function userContribsLink() {
1732 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1733 wfMsgHtml( 'contributions' ),
1736 array( 'known', 'noclasses' )
1740 function showEmailUser( $id ) {
1742 $targetUser = User
::newFromId( $id );
1743 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1744 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1747 function emailUserLink() {
1749 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1750 wfMsg( 'emailuser' ),
1753 array( 'known', 'noclasses' )
1757 function watchPageLinksLink() {
1759 if ( ! $wgOut->isArticleRelated() ) {
1760 return '(' . wfMsg( 'notanarticle' ) . ')';
1763 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1764 wfMsg( 'recentchangeslinked-toolbox' ),
1767 array( 'known', 'noclasses' )
1772 function trackbackLink() {
1773 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1774 . wfMsg( 'trackbacklink' ) . '</a>';
1777 function otherLanguages() {
1778 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1780 if ( $wgHideInterlanguageLinks ) {
1784 $a = $wgOut->getLanguageLinks();
1785 if ( 0 == count( $a ) ) {
1789 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1791 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1792 foreach( $a as $l ) {
1794 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1798 $nt = Title
::newFromText( $l );
1799 $url = $nt->escapeFullURL();
1800 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1802 if ( '' == $text ) { $text = $l; }
1803 $style = $this->getExternalLinkAttributes( $l, $text );
1804 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1806 if( $wgContLang->isRTL() ) $s .= '</span>';
1810 function talkLink() {
1811 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1812 # No discussion links for special pages
1816 $linkOptions = array();
1818 if( $this->mTitle
->isTalkPage() ) {
1819 $link = $this->mTitle
->getSubjectPage();
1820 switch( $link->getNamespace() ) {
1822 $text = wfMsg( 'articlepage' );
1825 $text = wfMsg( 'userpage' );
1828 $text = wfMsg( 'projectpage' );
1831 $text = wfMsg( 'imagepage' );
1832 # Make link known if image exists, even if the desc. page doesn't.
1833 if( wfFindFile( $link ) )
1834 $linkOptions[] = 'known';
1837 $text = wfMsg( 'mediawikipage' );
1840 $text = wfMsg( 'templatepage' );
1843 $text = wfMsg( 'viewhelppage' );
1846 $text = wfMsg( 'categorypage' );
1849 $text = wfMsg( 'articlepage' );
1852 $link = $this->mTitle
->getTalkPage();
1853 $text = wfMsg( 'talkpage' );
1856 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1861 function commentLink() {
1864 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1868 # __NEWSECTIONLINK___ changes behaviour here
1869 # If it is present, the link points to this page, otherwise
1870 # it points to the talk page
1871 if( $this->mTitle
->isTalkPage() ) {
1872 $title = $this->mTitle
;
1873 } elseif( $wgOut->showNewSectionLink() ) {
1874 $title = $this->mTitle
;
1876 $title = $this->mTitle
->getTalkPage();
1881 wfMsg( 'postcomment' ),
1887 array( 'known', 'noclasses' )
1891 /* these are used extensively in SkinTemplate, but also some other places */
1892 static function makeMainPageUrl( $urlaction = '' ) {
1893 $title = Title
::newMainPage();
1894 self
::checkTitle( $title, '' );
1895 return $title->getLocalURL( $urlaction );
1898 static function makeSpecialUrl( $name, $urlaction = '' ) {
1899 $title = SpecialPage
::getTitleFor( $name );
1900 return $title->getLocalURL( $urlaction );
1903 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1904 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1905 return $title->getLocalURL( $urlaction );
1908 static function makeI18nUrl( $name, $urlaction = '' ) {
1909 $title = Title
::newFromText( wfMsgForContent( $name ) );
1910 self
::checkTitle( $title, $name );
1911 return $title->getLocalURL( $urlaction );
1914 static function makeUrl( $name, $urlaction = '' ) {
1915 $title = Title
::newFromText( $name );
1916 self
::checkTitle( $title, $name );
1917 return $title->getLocalURL( $urlaction );
1920 # If url string starts with http, consider as external URL, else
1922 static function makeInternalOrExternalUrl( $name ) {
1923 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1926 return self
::makeUrl( $name );
1930 # this can be passed the NS number as defined in Language.php
1931 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1932 $title = Title
::makeTitleSafe( $namespace, $name );
1933 self
::checkTitle( $title, $name );
1934 return $title->getLocalURL( $urlaction );
1937 /* these return an array with the 'href' and boolean 'exists' */
1938 static function makeUrlDetails( $name, $urlaction = '' ) {
1939 $title = Title
::newFromText( $name );
1940 self
::checkTitle( $title, $name );
1942 'href' => $title->getLocalURL( $urlaction ),
1943 'exists' => $title->getArticleID() != 0 ?
true : false
1948 * Make URL details where the article exists (or at least it's convenient to think so)
1950 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1951 $title = Title
::newFromText( $name );
1952 self
::checkTitle( $title, $name );
1954 'href' => $title->getLocalURL( $urlaction ),
1959 # make sure we have some title to operate on
1960 static function checkTitle( &$title, $name ) {
1961 if( !is_object( $title ) ) {
1962 $title = Title
::newFromText( $name );
1963 if( !is_object( $title ) ) {
1964 $title = Title
::newFromText( '--error: link target missing--' );
1970 * Build an array that represents the sidebar(s), the navigation bar among them
1974 function buildSidebar() {
1975 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1977 wfProfileIn( __METHOD__
);
1979 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1981 if ( $wgEnableSidebarCache ) {
1982 $cachedsidebar = $parserMemc->get( $key );
1983 if ( $cachedsidebar ) {
1984 wfProfileOut( __METHOD__
);
1985 return $cachedsidebar;
1990 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1992 foreach( $lines as $line ) {
1993 if( strpos( $line, '*' ) !== 0 )
1995 if( strpos( $line, '**') !== 0 ) {
1996 $heading = trim( $line, '* ' );
1997 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
1999 if( strpos( $line, '|' ) !== false ) { // sanity check
2000 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2001 $link = wfMsgForContent( $line[0] );
2005 $text = wfMsgExt( $line[1], 'parsemag' );
2006 if( wfEmptyMsg( $line[1], $text ) )
2008 if( wfEmptyMsg( $line[0], $link ) )
2011 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2014 $title = Title
::newFromText( $link );
2016 $title = $title->fixSpecialName();
2017 $href = $title->getLocalURL();
2019 $href = 'INVALID-TITLE';
2023 $bar[$heading][] = array(
2026 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2029 } else { continue; }
2032 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2033 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2034 wfProfileOut( __METHOD__
);