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 ) ) {
995 $s[] .= $this->makeKnownLinkObj( $this->mTitle
,
996 wfMsg( 'currentrev' ) );
999 if ( $wgUser->getNewtalk() ) {
1000 # do not show "You have new messages" text when we are viewing our
1002 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1003 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
1004 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
1005 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1007 $wgOut->setSquidMaxage( 0 );
1008 $wgOut->enableClientCache( false );
1012 $undelete = $this->getUndeleteLink();
1013 if( !empty( $undelete ) ) {
1016 return $wgLang->pipeList( $s );
1019 function getUndeleteLink() {
1020 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1022 $action = $wgRequest->getVal( 'action', 'view' );
1024 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1025 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1026 $n = $this->mTitle
->isDeleted();
1028 if ( $wgUser->isAllowed( 'undelete' ) ) {
1029 $msg = 'thisisdeleted';
1031 $msg = 'viewdeleted';
1034 $this->makeKnownLinkObj(
1035 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1036 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
1042 function printableLink() {
1043 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1045 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1047 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1048 if( $wgOut->isSyndicated() ) {
1049 foreach( $wgFeedClasses as $format => $class ) {
1050 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1051 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1052 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1055 return $wgLang->pipeList( $s );
1058 function pageTitle() {
1060 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1064 function pageSubtitle() {
1067 $sub = $wgOut->getSubtitle();
1069 global $wgExtraSubtitle;
1070 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1072 $subpages = $this->subPageSubtitle();
1073 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1074 $s = "<p class='subtitle'>{$sub}</p>\n";
1078 function subPageSubtitle() {
1080 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1084 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1085 $ptext = $this->mTitle
->getPrefixedText();
1086 if( preg_match( '/\//', $ptext ) ) {
1087 $links = explode( '/', $ptext );
1088 array_pop( $links );
1092 foreach( $links as $link ) {
1093 $growinglink .= $link;
1095 $linkObj = Title
::newFromText( $growinglink );
1096 if( is_object( $linkObj ) && $linkObj->exists() ){
1097 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
1100 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1102 $subpages .= '< ';
1104 $subpages .= $getlink;
1109 $growinglink .= '/';
1117 * Returns true if the IP should be shown in the header
1119 function showIPinHeader() {
1120 global $wgShowIPinHeader;
1121 return $wgShowIPinHeader && session_id() != '';
1124 function nameAndLogin() {
1125 global $wgUser, $wgLang, $wgContLang;
1127 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1130 if ( $wgUser->isAnon() ) {
1131 if( $this->showIPinHeader() ) {
1134 $talkLink = $this->link( $wgUser->getTalkPage(),
1135 $wgLang->getNsText( NS_TALK
) );
1137 $ret .= "$name ($talkLink)";
1139 $ret .= wfMsg( 'notloggedin' );
1142 $returnTo = $this->mTitle
->getPrefixedDBkey();
1144 if ( $logoutPage != $returnTo ) {
1145 $query['returnto'] = $returnTo;
1148 $loginlink = $wgUser->isAllowed( 'createaccount' )
1149 ?
'nav-login-createaccount'
1151 $ret .= "\n<br />" . $this->link(
1152 SpecialPage
::getTitleFor( 'Userlogin' ),
1153 wfMsg( $loginlink ), array(), $query
1156 $returnTo = $this->mTitle
->getPrefixedDBkey();
1157 $talkLink = $this->link( $wgUser->getTalkPage(),
1158 $wgLang->getNsText( NS_TALK
) );
1160 $ret .= $this->link( $wgUser->getUserPage(),
1161 htmlspecialchars( $wgUser->getName() ) );
1162 $ret .= " ($talkLink)<br />";
1163 $ret .= $wgLang->pipeList( array(
1165 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1166 array(), array( 'returnto' => $returnTo )
1168 $this->specialLink( 'preferences' ),
1171 $ret = $wgLang->pipeList( array(
1174 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1182 function getSearchLink() {
1183 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1184 return $searchPage->getLocalURL();
1187 function escapeSearchLink() {
1188 return htmlspecialchars( $this->getSearchLink() );
1191 function searchForm() {
1192 global $wgRequest, $wgUseTwoButtonsSearchForm;
1193 $search = $wgRequest->getText( 'search' );
1195 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1196 . $this->escapeSearchLink() . "\">\n"
1197 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1198 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1199 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1201 if( $wgUseTwoButtonsSearchForm )
1202 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1204 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1208 // Ensure unique id's for search boxes made after the first
1209 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1214 function topLinks() {
1218 $this->mainPageLink(),
1219 $this->specialLink( 'recentchanges' )
1222 if ( $wgOut->isArticleRelated() ) {
1223 $s[] = $this->editThisPage();
1224 $s[] = $this->historyLink();
1226 # Many people don't like this dropdown box
1227 #$s[] = $this->specialPagesList();
1229 if( $this->variantLinks() ) {
1230 $s[] = $this->variantLinks();
1233 if( $this->extensionTabLinks() ) {
1234 $s[] = $this->extensionTabLinks();
1237 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1238 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1242 * Compatibility for extensions adding functionality through tabs.
1243 * Eventually these old skins should be replaced with SkinTemplate-based
1247 function extensionTabLinks() {
1251 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1252 foreach( $tabs as $tab ) {
1253 $s[] = Xml
::element( 'a',
1254 array( 'href' => $tab['href'] ),
1261 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1262 $out .= $wgLang->pipeList( $s );
1269 * Language/charset variant links for classic-style skins
1272 function variantLinks() {
1274 /* show links to different language variants */
1275 global $wgDisableLangConversion, $wgLang, $wgContLang;
1276 $variants = $wgContLang->getVariants();
1277 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1278 foreach( $variants as $code ) {
1279 $varname = $wgContLang->getVariantname( $code );
1280 if( $varname == 'disable' )
1282 $s = $wgLang->pipeList( array(
1284 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1291 function bottomLinks() {
1292 global $wgOut, $wgUser, $wgUseTrackbacks;
1293 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1296 if ( $wgOut->isArticleRelated() ) {
1297 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1298 if ( $wgUser->isLoggedIn() ) {
1299 $element[] = $this->watchThisPage();
1301 $element[] = $this->talkLink();
1302 $element[] = $this->historyLink();
1303 $element[] = $this->whatLinksHere();
1304 $element[] = $this->watchPageLinksLink();
1306 if( $wgUseTrackbacks )
1307 $element[] = $this->trackbackLink();
1309 if ( $this->mTitle
->getNamespace() == NS_USER
1310 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1311 $id = User
::idFromName( $this->mTitle
->getText() );
1312 $ip = User
::isIP( $this->mTitle
->getText() );
1314 if( $id ||
$ip ) { # both anons and non-anons have contri list
1315 $element[] = $this->userContribsLink();
1317 if( $this->showEmailUser( $id ) ) {
1318 $element[] = $this->emailUserLink();
1322 $s = implode( $element, $sep );
1324 if ( $this->mTitle
->getArticleId() ) {
1326 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1327 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1328 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1330 $s .= "<br />\n" . $this->otherLanguages();
1336 function pageStats() {
1337 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1338 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1340 $oldid = $wgRequest->getVal( 'oldid' );
1341 $diff = $wgRequest->getVal( 'diff' );
1342 if ( ! $wgOut->isArticle() ) { return ''; }
1343 if( !$wgArticle instanceOf Article
) { return ''; }
1344 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1345 if ( 0 == $wgArticle->getID() ) { return ''; }
1348 if ( !$wgDisableCounters ) {
1349 $count = $wgLang->formatNum( $wgArticle->getCount() );
1351 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1355 if( $wgMaxCredits != 0 ){
1356 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1358 $s .= $this->lastModified();
1361 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1362 $dbr = wfGetDB( DB_SLAVE
);
1363 $res = $dbr->select( 'watchlist',
1364 array( 'COUNT(*) AS n' ),
1365 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1368 $x = $dbr->fetchObject( $res );
1370 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1371 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1375 return $s . ' ' . $this->getCopyright();
1378 function getCopyright( $type = 'detect' ) {
1379 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1381 if ( $type == 'detect' ) {
1382 $diff = $wgRequest->getVal( 'diff' );
1383 $isCur = $wgArticle && $wgArticle->isCurrent();
1384 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1391 if ( $type == 'history' ) {
1392 $msg = 'history_copyright';
1398 if( $wgRightsPage ) {
1399 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1400 } elseif( $wgRightsUrl ) {
1401 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1402 } elseif( $wgRightsText ) {
1403 $link = $wgRightsText;
1408 $out .= wfMsgForContent( $msg, $link );
1412 function getCopyrightIcon() {
1413 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1415 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1416 $out = $wgCopyrightIcon;
1417 } else if ( $wgRightsIcon ) {
1418 $icon = htmlspecialchars( $wgRightsIcon );
1419 if ( $wgRightsUrl ) {
1420 $url = htmlspecialchars( $wgRightsUrl );
1421 $out .= '<a href="'.$url.'">';
1423 $text = htmlspecialchars( $wgRightsText );
1424 $out .= "<img src=\"$icon\" alt='$text' />";
1425 if ( $wgRightsUrl ) {
1432 function getPoweredBy() {
1433 global $wgStylePath;
1434 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1435 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1439 function lastModified() {
1440 global $wgLang, $wgArticle;
1441 if( $this->mRevisionId
) {
1442 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1444 $timestamp = $wgArticle->getTimestamp();
1447 $d = $wgLang->date( $timestamp, true );
1448 $t = $wgLang->time( $timestamp, true );
1449 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1453 if ( wfGetLB()->getLaggedSlaveMode() ) {
1454 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1459 function logoText( $align = '' ) {
1460 if ( '' != $align ) {
1461 $a = " align='{$align}'";
1466 $mp = wfMsg( 'mainpage' );
1467 $mptitle = Title
::newMainPage();
1468 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1470 $logourl = $this->getLogo();
1471 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1476 * show a drop-down box of special pages
1478 function specialPagesList() {
1479 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1480 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1481 foreach ( $pages as $name => $page ) {
1482 $pages[$name] = $page->getDescription();
1485 $go = wfMsg( 'go' );
1486 $sp = wfMsg( 'specialpages' );
1487 $spp = $wgContLang->specialPage( 'Specialpages' );
1489 $s = '<form id="specialpages" method="get" ' .
1490 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1491 $s .= "<select name=\"wpDropdown\">\n";
1492 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1495 foreach ( $pages as $name => $desc ) {
1496 $p = $wgContLang->specialPage( $name );
1497 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1499 $s .= "</select>\n";
1500 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1505 function mainPageLink() {
1506 $s = $this->makeKnownLinkObj( Title
::newMainPage(), wfMsg( 'mainpage' ) );
1510 function copyrightLink() {
1511 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1512 wfMsg( 'copyrightpagename' ) );
1516 private function footerLink ( $desc, $page ) {
1517 // if the link description has been set to "-" in the default language,
1518 if ( wfMsgForContent( $desc ) == '-') {
1519 // then it is disabled, for all languages.
1522 // Otherwise, we display the link for the user, described in their
1523 // language (which may or may not be the same as the default language),
1524 // but we make the link target be the one site-wide page.
1525 return $this->makeKnownLink( wfMsgForContent( $page ),
1526 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1530 function privacyLink() {
1531 return $this->footerLink( 'privacy', 'privacypage' );
1534 function aboutLink() {
1535 return $this->footerLink( 'aboutsite', 'aboutpage' );
1538 function disclaimerLink() {
1539 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1542 function editThisPage() {
1545 if ( !$wgOut->isArticleRelated() ) {
1546 $s = wfMsg( 'protectedpage' );
1548 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1549 $t = wfMsg( 'editthispage' );
1550 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1551 $t = wfMsg( 'create-this-page' );
1553 $t = wfMsg( 'viewsource' );
1556 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, $this->editUrlOptions() );
1562 * Return URL options for the 'edit page' link.
1563 * This may include an 'oldid' specifier, if the current page view is such.
1568 function editUrlOptions() {
1571 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1572 return 'action=edit&oldid=' . intval( $this->mRevisionId
);
1574 return 'action=edit';
1578 function deleteThisPage() {
1579 global $wgUser, $wgRequest;
1581 $diff = $wgRequest->getVal( 'diff' );
1582 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1583 $t = wfMsg( 'deletethispage' );
1585 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, 'action=delete' );
1592 function protectThisPage() {
1593 global $wgUser, $wgRequest;
1595 $diff = $wgRequest->getVal( 'diff' );
1596 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1597 if ( $this->mTitle
->isProtected() ) {
1598 $t = wfMsg( 'unprotectthispage' );
1599 $q = 'action=unprotect';
1601 $t = wfMsg( 'protectthispage' );
1602 $q = 'action=protect';
1604 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, $q );
1611 function watchThisPage() {
1613 ++
$this->mWatchLinkNum
;
1615 if ( $wgOut->isArticleRelated() ) {
1616 if ( $this->mTitle
->userIsWatching() ) {
1617 $t = wfMsg( 'unwatchthispage' );
1618 $q = 'action=unwatch';
1619 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1621 $t = wfMsg( 'watchthispage' );
1622 $q = 'action=watch';
1623 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1625 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, $q, '', '', " id=\"$id\"" );
1627 $s = wfMsg( 'notanarticle' );
1632 function moveThisPage() {
1633 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1634 return $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Movepage' ),
1635 wfMsg( 'movethispage' ), 'target=' . $this->mTitle
->getPrefixedURL() );
1637 // no message if page is protected - would be redundant
1642 function historyLink() {
1643 return $this->link( $this->mTitle
, wfMsgHtml( 'history' ),
1644 array( 'rel' => 'archives' ), array( 'action' => 'history' ) );
1647 function whatLinksHere() {
1648 return $this->makeKnownLinkObj(
1649 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1650 wfMsgHtml( 'whatlinkshere' ) );
1653 function userContribsLink() {
1654 return $this->makeKnownLinkObj(
1655 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1656 wfMsgHtml( 'contributions' ) );
1659 function showEmailUser( $id ) {
1661 $targetUser = User
::newFromId( $id );
1662 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1663 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1666 function emailUserLink() {
1667 return $this->makeKnownLinkObj(
1668 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1669 wfMsg( 'emailuser' ) );
1672 function watchPageLinksLink() {
1674 if ( ! $wgOut->isArticleRelated() ) {
1675 return '(' . wfMsg( 'notanarticle' ) . ')';
1677 return $this->makeKnownLinkObj(
1678 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1679 wfMsg( 'recentchangeslinked-toolbox' ) );
1683 function trackbackLink() {
1684 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1685 . wfMsg( 'trackbacklink' ) . '</a>';
1688 function otherLanguages() {
1689 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1691 if ( $wgHideInterlanguageLinks ) {
1695 $a = $wgOut->getLanguageLinks();
1696 if ( 0 == count( $a ) ) {
1700 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1702 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1703 foreach( $a as $l ) {
1705 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1709 $nt = Title
::newFromText( $l );
1710 $url = $nt->escapeFullURL();
1711 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1713 if ( '' == $text ) { $text = $l; }
1714 $style = $this->getExternalLinkAttributes( $l, $text );
1715 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1717 if( $wgContLang->isRTL() ) $s .= '</span>';
1721 function talkLink() {
1722 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1723 # No discussion links for special pages
1727 $linkOptions = array();
1729 if( $this->mTitle
->isTalkPage() ) {
1730 $link = $this->mTitle
->getSubjectPage();
1731 switch( $link->getNamespace() ) {
1733 $text = wfMsg( 'articlepage' );
1736 $text = wfMsg( 'userpage' );
1739 $text = wfMsg( 'projectpage' );
1742 $text = wfMsg( 'imagepage' );
1743 # Make link known if image exists, even if the desc. page doesn't.
1744 if( wfFindFile( $link ) )
1745 $linkOptions[] = 'known';
1748 $text = wfMsg( 'mediawikipage' );
1751 $text = wfMsg( 'templatepage' );
1754 $text = wfMsg( 'viewhelppage' );
1757 $text = wfMsg( 'categorypage' );
1760 $text = wfMsg( 'articlepage' );
1763 $link = $this->mTitle
->getTalkPage();
1764 $text = wfMsg( 'talkpage' );
1767 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1772 function commentLink() {
1775 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1779 # __NEWSECTIONLINK___ changes behaviour here
1780 # If it's present, the link points to this page, otherwise
1781 # it points to the talk page
1782 if( $this->mTitle
->isTalkPage() ) {
1783 $title = $this->mTitle
;
1784 } elseif( $wgOut->showNewSectionLink() ) {
1785 $title = $this->mTitle
;
1787 $title = $this->mTitle
->getTalkPage();
1790 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1793 /* these are used extensively in SkinTemplate, but also some other places */
1794 static function makeMainPageUrl( $urlaction = '' ) {
1795 $title = Title
::newMainPage();
1796 self
::checkTitle( $title, '' );
1797 return $title->getLocalURL( $urlaction );
1800 static function makeSpecialUrl( $name, $urlaction = '' ) {
1801 $title = SpecialPage
::getTitleFor( $name );
1802 return $title->getLocalURL( $urlaction );
1805 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1806 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1807 return $title->getLocalURL( $urlaction );
1810 static function makeI18nUrl( $name, $urlaction = '' ) {
1811 $title = Title
::newFromText( wfMsgForContent( $name ) );
1812 self
::checkTitle( $title, $name );
1813 return $title->getLocalURL( $urlaction );
1816 static function makeUrl( $name, $urlaction = '' ) {
1817 $title = Title
::newFromText( $name );
1818 self
::checkTitle( $title, $name );
1819 return $title->getLocalURL( $urlaction );
1822 # If url string starts with http, consider as external URL, else
1824 static function makeInternalOrExternalUrl( $name ) {
1825 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1828 return self
::makeUrl( $name );
1832 # this can be passed the NS number as defined in Language.php
1833 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1834 $title = Title
::makeTitleSafe( $namespace, $name );
1835 self
::checkTitle( $title, $name );
1836 return $title->getLocalURL( $urlaction );
1839 /* these return an array with the 'href' and boolean 'exists' */
1840 static function makeUrlDetails( $name, $urlaction = '' ) {
1841 $title = Title
::newFromText( $name );
1842 self
::checkTitle( $title, $name );
1844 'href' => $title->getLocalURL( $urlaction ),
1845 'exists' => $title->getArticleID() != 0 ?
true : false
1850 * Make URL details where the article exists (or at least it's convenient to think so)
1852 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1853 $title = Title
::newFromText( $name );
1854 self
::checkTitle( $title, $name );
1856 'href' => $title->getLocalURL( $urlaction ),
1861 # make sure we have some title to operate on
1862 static function checkTitle( &$title, $name ) {
1863 if( !is_object( $title ) ) {
1864 $title = Title
::newFromText( $name );
1865 if( !is_object( $title ) ) {
1866 $title = Title
::newFromText( '--error: link target missing--' );
1872 * Build an array that represents the sidebar(s), the navigation bar among them
1876 function buildSidebar() {
1877 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1879 wfProfileIn( __METHOD__
);
1881 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1883 if ( $wgEnableSidebarCache ) {
1884 $cachedsidebar = $parserMemc->get( $key );
1885 if ( $cachedsidebar ) {
1886 wfProfileOut( __METHOD__
);
1887 return $cachedsidebar;
1892 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1894 foreach( $lines as $line ) {
1895 if( strpos( $line, '*' ) !== 0 )
1897 if( strpos( $line, '**') !== 0 ) {
1898 $heading = trim( $line, '* ' );
1899 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
1901 if( strpos( $line, '|' ) !== false ) { // sanity check
1902 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
1903 $link = wfMsgForContent( $line[0] );
1907 $text = wfMsgExt( $line[1], 'parsemag' );
1908 if( wfEmptyMsg( $line[1], $text ) )
1910 if( wfEmptyMsg( $line[0], $link ) )
1913 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1916 $title = Title
::newFromText( $link );
1918 $title = $title->fixSpecialName();
1919 $href = $title->getLocalURL();
1921 $href = 'INVALID-TITLE';
1925 $bar[$heading][] = array(
1928 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1931 } else { continue; }
1934 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1935 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1936 wfProfileOut( __METHOD__
);