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;
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 'wgUserLanguage' => $wgLang->getCode(),
398 'wgContentLanguage' => $wgContLang->getCode(),
399 'wgBreakFrames' => $wgBreakFrames,
400 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
401 'wgVersion' => $wgVersion,
402 'wgEnableAPI' => $wgEnableAPI,
403 'wgEnableWriteAPI' => $wgEnableWriteAPI,
404 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
405 'wgDigitTransformTable' => $compactDigitTransTable,
408 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
409 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
410 $vars['wgDBname'] = $wgDBname;
411 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
412 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
415 foreach( $wgRestrictionTypes as $type )
416 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
418 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
419 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
420 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
421 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
422 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
425 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
426 $msgs = (object)array();
427 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
428 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
430 $vars['wgAjaxWatch'] = $msgs;
433 // Allow extensions to add their custom variables to the global JS variables
434 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
436 return self
::makeVariablesScript( $vars );
439 function getHeadScripts( $allowUserJs ) {
440 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
442 $vars = self
::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
444 $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
447 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
448 $r[] = "<script type=\"$wgJsMimeType\" src=\"".
449 htmlspecialchars( self
::makeUrl( '-',
450 "action=raw$jsCache&gen=js&useskin=" .
451 urlencode( $this->getSkinName() ) ) ) .
452 "\"><!-- site js --></script>";
454 if( $allowUserJs && $wgUser->isLoggedIn() ) {
455 $userpage = $wgUser->getUserPage();
456 $userjs = htmlspecialchars( self
::makeUrl(
457 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
458 'action=raw&ctype='.$wgJsMimeType ) );
459 $r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
461 return $vars . "\t\t" . implode ( "\n\t\t", $r );
465 * To make it harder for someone to slip a user a fake
466 * user-JavaScript or user-CSS preview, a random token
467 * is associated with the login session. If it's not
468 * passed back with the preview request, we won't render
471 * @param string $action
475 function userCanPreview( $action ) {
476 global $wgRequest, $wgUser;
478 if( $action != 'submit' )
480 if( !$wgRequest->wasPosted() )
482 if( !$this->mTitle
->userCanEditCssJsSubpage() )
484 return $wgUser->matchEditToken(
485 $wgRequest->getVal( 'wpEditToken' ) );
489 * generated JavaScript action=raw&gen=js
490 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
491 * nated together. For some bizarre reason, it does *not* return any
492 * custom user JS from subpages. Huh?
494 * There's absolutely no reason to have separate Monobook/Common JSes.
495 * Any JS that cares can just check the skin variable generated at the
496 * top. For now Monobook.js will be maintained, but it should be consi-
501 public function generateUserJs() {
504 wfProfileIn( __METHOD__
);
506 $s = "/* generated javascript */\n";
507 $s .= "var skin = '" . Xml
::escapeJsString( $this->getSkinName() ) . "';\n";
508 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
509 $s .= "\n\n/* MediaWiki:Common.js */\n";
510 $commonJs = wfMsgForContent( 'common.js' );
511 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
515 $s .= "\n\n/* MediaWiki:".ucfirst( $this->getSkinName() ).".js */\n";
516 // avoid inclusion of non defined user JavaScript (with custom skins only)
517 // by checking for default message content
518 $msgKey = ucfirst( $this->getSkinName() ).'.js';
519 $userJS = wfMsgForContent( $msgKey );
520 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
524 wfProfileOut( __METHOD__
);
529 * Generate user stylesheet for action=raw&gen=css
531 public function generateUserStylesheet() {
532 wfProfileIn( __METHOD__
);
533 $s = "/* generated user stylesheet */\n" .
534 $this->reallyGenerateUserStylesheet();
535 wfProfileOut( __METHOD__
);
540 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
542 protected function reallyGenerateUserStylesheet(){
545 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
546 $underline = $undopt ?
'underline' : 'none';
547 $s .= "a { text-decoration: $underline; }\n";
549 if( $wgUser->getOption( 'highlightbroken' ) ) {
550 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
553 a.new, #quickbar a.new,
554 a.stub, #quickbar a.stub {
557 a.new:after, #quickbar a.new:after {
561 a.stub:after, #quickbar a.stub:after {
567 if( $wgUser->getOption( 'justify' ) ) {
568 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
570 if( !$wgUser->getOption( 'showtoc' ) ) {
571 $s .= "#toc { display: none; }\n";
573 if( !$wgUser->getOption( 'editsection' ) ) {
574 $s .= ".editsection { display: none; }\n";
582 function setupUserCss( OutputPage
$out ) {
583 global $wgRequest, $wgContLang, $wgUser;
584 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
586 wfProfileIn( __METHOD__
);
588 $this->setupSkinUserCss( $out );
592 'maxage' => $wgSquidMaxage,
595 // Add any extension CSS
596 foreach( $out->getExtStyle() as $tag ) {
597 $out->addStyle( $tag['href'] );
600 // If we use the site's dynamic CSS, throw that in, too
601 // Per-site custom styles
602 if( $wgUseSiteCss ) {
603 global $wgHandheldStyle;
604 $query = wfArrayToCGI( array(
605 'usemsgcache' => 'yes',
606 'ctype' => 'text/css',
607 'smaxage' => $wgSquidMaxage
609 # Site settings must override extension css! (bug 15025)
610 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
611 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
612 if( $wgHandheldStyle ) {
613 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
615 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
618 if( $wgUser->isLoggedIn() ) {
619 // Ensure that logged-in users' generated CSS isn't clobbered
620 // by anons' publicly cacheable generated CSS.
621 $siteargs['smaxage'] = '0';
622 $siteargs['ts'] = $wgUser->mTouched
;
624 // Per-user styles based on preferences
625 $siteargs['gen'] = 'css';
626 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
627 $siteargs['useskin'] = $us;
629 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
631 // Per-user custom style pages
632 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
633 $action = $wgRequest->getVal( 'action' );
634 # If we're previewing the CSS page, use it
635 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
636 $previewCss = $wgRequest->getText( 'wpTextbox1' );
637 // @FIXME: properly escape the cdata!
638 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
640 $out->addStyle( self
::makeUrl( $this->userpage
. '/' . $this->getSkinName() .'.css',
641 'action=raw&ctype=text/css' ) );
645 wfProfileOut( __METHOD__
);
649 * Add skin specific stylesheets
650 * @param $out OutputPage
652 function setupSkinUserCss( OutputPage
$out ) {
653 $out->addStyle( 'common/shared.css' );
654 $out->addStyle( 'common/oldshared.css' );
655 $out->addStyle( $this->getStylesheet() );
656 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
659 function getBodyOptions() {
660 global $wgUser, $wgOut, $wgRequest, $wgContLang;
662 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
664 if ( 0 != $this->mTitle
->getNamespace() ) {
665 $a = array( 'bgcolor' => '#ffffec' );
667 else $a = array( 'bgcolor' => '#FFFFFF' );
668 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
669 $this->mTitle
->quickUserCan( 'edit' ) ) {
670 $s = $this->mTitle
->getFullURL( $this->editUrlOptions() );
671 $s = 'document.location = "' .Xml
::escapeJsString( $s ) .'";';
672 $a +
= array( 'ondblclick' => $s );
674 $a['onload'] = $wgOut->getOnloadHandler();
677 ' '.( $wgContLang->isRTL() ?
'rtl' : 'ltr' ).
678 ' '.$this->getPageClasses( $this->mTitle
) .
679 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName() );
683 function getPageClasses( $title ) {
684 $numeric = 'ns-'.$title->getNamespace();
685 if( $title->getNamespace() == NS_SPECIAL
) {
686 $type = 'ns-special';
687 } elseif( $title->isTalkPage() ) {
690 $type = 'ns-subject';
692 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
693 return "$numeric $type $name";
705 * This will be called immediately after the <body> tag. Split into
706 * two functions to make it easier to subclass.
708 function beforeContent() {
709 return $this->doBeforeContent();
712 function doBeforeContent() {
714 wfProfileIn( __METHOD__
);
717 $qb = $this->qbSetting();
719 if( $langlinks = $this->otherLanguages() ) {
725 $borderhack = 'class="top"';
728 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
729 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
731 $shove = ( $qb != 0 );
732 $left = ( $qb == 1 ||
$qb == 3 );
733 if( $wgContLang->isRTL() ) $left = !$left;
736 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
737 $this->logoText() . '</td>';
739 $s .= $this->getQuickbarCompensator( $rows );
741 $l = $wgContLang->isRTL() ?
'right' : 'left';
742 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
744 $s .= $this->topLinks();
745 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
747 $r = $wgContLang->isRTL() ?
'left' : 'right';
748 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
749 $s .= $this->nameAndLogin();
750 $s .= "\n<br />" . $this->searchForm() . "</td>";
753 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
756 if ( $shove && !$left ) { # Right
757 $s .= $this->getQuickbarCompensator( $rows );
759 $s .= "</tr>\n</table>\n</div>\n";
760 $s .= "\n<div id='article'>\n";
762 $notice = wfGetSiteNotice();
764 $s .= "\n<div id='siteNotice'>$notice</div>\n";
766 $s .= $this->pageTitle();
767 $s .= $this->pageSubtitle();
768 $s .= $this->getCategories();
769 wfProfileOut( __METHOD__
);
774 function getCategoryLinks() {
775 global $wgOut, $wgUseCategoryBrowser;
776 global $wgContLang, $wgUser;
778 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
781 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
783 // Use Unicode bidi embedding override characters,
784 // to make sure links don't smash each other up in ugly ways.
785 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
786 $embed = "<span dir='$dir'>";
789 $allCats = $wgOut->getCategoryLinks();
791 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
792 if ( !empty( $allCats['normal'] ) ) {
793 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
795 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
796 $s .= '<div id="mw-normal-catlinks">' .
797 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
798 . $colon . $t . '</div>';
802 if ( isset( $allCats['hidden'] ) ) {
803 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
804 $class ='mw-hidden-cats-user-shown';
805 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
806 $class = 'mw-hidden-cats-ns-shown';
808 $class = 'mw-hidden-cats-hidden';
810 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
811 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
812 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
816 # optional 'dmoz-like' category browser. Will be shown under the list
817 # of categories an article belong to
818 if( $wgUseCategoryBrowser ){
819 $s .= '<br /><hr />';
821 # get a big array of the parents tree
822 $parenttree = $this->mTitle
->getParentCategoryTree();
823 # Skin object passed by reference cause it can not be
824 # accessed under the method subfunction drawCategoryBrowser
825 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
826 # Clean out bogus first entry and sort them
827 unset( $tempout[0] );
829 # Output one per line
830 $s .= implode( "<br />\n", $tempout );
837 * Render the array as a serie of links.
838 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
839 * @param &skin Object: skin passed by reference
840 * @return String separated by >, terminate with "\n"
842 function drawCategoryBrowser( $tree, &$skin ){
844 foreach( $tree as $element => $parent ) {
845 if( empty( $parent ) ) {
846 # element start a new list
849 # grab the others elements
850 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
852 # add our current element to the list
853 $eltitle = Title
::newFromText( $element );
854 $return .= $skin->link( $eltitle, $eltitle->getText() );
859 function getCategories() {
860 $catlinks=$this->getCategoryLinks();
862 $classes = 'catlinks';
864 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
865 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
866 $classes .= ' catlinks-allhidden';
869 if( !empty( $catlinks ) ){
870 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
874 function getQuickbarCompensator( $rows = 1 ) {
875 return "<td width='152' rowspan='{$rows}'> </td>";
879 * This runs a hook to allow extensions placing their stuff after content
880 * and article metadata (e.g. categories).
881 * Note: This function has nothing to do with afterContent().
883 * This hook is placed here in order to allow using the same hook for all
884 * skins, both the SkinTemplate based ones and the older ones, which directly
885 * use this class to get their data.
887 * The output of this function gets processed in SkinTemplate::outputPage() for
888 * the SkinTemplate based skins, all other skins should directly echo it.
890 * Returns an empty string by default, if not changed by any hook function.
892 protected function afterContentHook() {
895 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
896 // adding just some spaces shouldn't toggle the output
897 // of the whole <div/>, so we use trim() here
898 if( trim( $data ) != '' ){
899 // Doing this here instead of in the skins to
900 // ensure that the div has the same ID in all
902 $data = "<div id='mw-data-after-content'>\n" .
907 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
914 * Generate debug data HTML for displaying at the bottom of the main content
916 * @return String HTML containing debug data, if enabled (otherwise empty).
918 protected function generateDebugHTML() {
919 global $wgShowDebug, $wgOut;
920 if ( $wgShowDebug ) {
921 $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext
) );
922 return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
923 $listInternals . "</li></ul>\n";
929 * This gets called shortly before the </body> tag.
930 * @return String HTML to be put before </body>
932 function afterContent() {
933 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
934 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
938 * This gets called shortly before the </body> tag.
939 * @return String HTML-wrapped JS code to be put before </body>
941 function bottomScripts() {
942 global $wgJsMimeType;
943 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
944 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
945 return $bottomScriptText;
948 /** @return string Retrievied from HTML text */
949 function printSource() {
950 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
951 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
954 function printFooter() {
955 return "<p>" . $this->printSource() .
956 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
959 /** overloaded by derived classes */
960 function doAfterContent() { return '</div></div>'; }
962 function pageTitleLinks() {
963 global $wgOut, $wgUser, $wgRequest, $wgLang;
965 $oldid = $wgRequest->getVal( 'oldid' );
966 $diff = $wgRequest->getVal( 'diff' );
967 $action = $wgRequest->getText( 'action' );
969 $s[] = $this->printableLink();
970 $disclaimer = $this->disclaimerLink(); # may be empty
974 $privacy = $this->privacyLink(); # may be empty too
979 if ( $wgOut->isArticleRelated() ) {
980 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
981 $name = $this->mTitle
->getDBkey();
982 $image = wfFindFile( $this->mTitle
);
984 $link = htmlspecialchars( $image->getURL() );
985 $style = $this->getInternalLinkAttributes( $link, $name );
986 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
990 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
991 $s[] .= $this->makeKnownLinkObj( $this->mTitle
,
992 wfMsg( 'currentrev' ) );
995 if ( $wgUser->getNewtalk() ) {
996 # do not show "You have new messages" text when we are viewing our
998 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
999 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
1000 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
1001 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1003 $wgOut->setSquidMaxage( 0 );
1004 $wgOut->enableClientCache( false );
1008 $undelete = $this->getUndeleteLink();
1009 if( !empty( $undelete ) ) {
1012 return $wgLang->pipeList( $s );
1015 function getUndeleteLink() {
1016 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1018 $action = $wgRequest->getVal( 'action', 'view' );
1020 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1021 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1022 $n = $this->mTitle
->isDeleted();
1024 if ( $wgUser->isAllowed( 'undelete' ) ) {
1025 $msg = 'thisisdeleted';
1027 $msg = 'viewdeleted';
1030 $this->makeKnownLinkObj(
1031 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1032 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
1038 function printableLink() {
1039 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1041 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1043 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1044 if( $wgOut->isSyndicated() ) {
1045 foreach( $wgFeedClasses as $format => $class ) {
1046 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1047 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1048 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1051 return $wgLang->pipeList( $s );
1054 function pageTitle() {
1056 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1060 function pageSubtitle() {
1063 $sub = $wgOut->getSubtitle();
1065 global $wgExtraSubtitle;
1066 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1068 $subpages = $this->subPageSubtitle();
1069 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1070 $s = "<p class='subtitle'>{$sub}</p>\n";
1074 function subPageSubtitle() {
1076 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1080 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1081 $ptext = $this->mTitle
->getPrefixedText();
1082 if( preg_match( '/\//', $ptext ) ) {
1083 $links = explode( '/', $ptext );
1084 array_pop( $links );
1088 foreach( $links as $link ) {
1089 $growinglink .= $link;
1091 $linkObj = Title
::newFromText( $growinglink );
1092 if( is_object( $linkObj ) && $linkObj->exists() ){
1093 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
1096 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1098 $subpages .= '< ';
1100 $subpages .= $getlink;
1105 $growinglink .= '/';
1113 * Returns true if the IP should be shown in the header
1115 function showIPinHeader() {
1116 global $wgShowIPinHeader;
1117 return $wgShowIPinHeader && session_id() != '';
1120 function nameAndLogin() {
1121 global $wgUser, $wgLang, $wgContLang;
1123 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1126 if ( $wgUser->isAnon() ) {
1127 if( $this->showIPinHeader() ) {
1130 $talkLink = $this->link( $wgUser->getTalkPage(),
1131 $wgLang->getNsText( NS_TALK
) );
1133 $ret .= "$name ($talkLink)";
1135 $ret .= wfMsg( 'notloggedin' );
1138 $returnTo = $this->mTitle
->getPrefixedDBkey();
1140 if ( $logoutPage != $returnTo ) {
1141 $query['returnto'] = $returnTo;
1144 $loginlink = $wgUser->isAllowed( 'createaccount' )
1145 ?
'nav-login-createaccount'
1147 $ret .= "\n<br />" . $this->link(
1148 SpecialPage
::getTitleFor( 'Userlogin' ),
1149 wfMsg( $loginlink ), array(), $query
1152 $returnTo = $this->mTitle
->getPrefixedDBkey();
1153 $talkLink = $this->link( $wgUser->getTalkPage(),
1154 $wgLang->getNsText( NS_TALK
) );
1156 $ret .= $this->link( $wgUser->getUserPage(),
1157 htmlspecialchars( $wgUser->getName() ) );
1158 $ret .= " ($talkLink)<br />";
1159 $ret .= $wgLang->pipeList( array(
1161 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1162 array(), array( 'returnto' => $returnTo )
1164 $this->specialLink( 'preferences' ),
1167 $ret = $wgLang->pipeList( array(
1170 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1178 function getSearchLink() {
1179 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1180 return $searchPage->getLocalURL();
1183 function escapeSearchLink() {
1184 return htmlspecialchars( $this->getSearchLink() );
1187 function searchForm() {
1188 global $wgRequest, $wgUseTwoButtonsSearchForm;
1189 $search = $wgRequest->getText( 'search' );
1191 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1192 . $this->escapeSearchLink() . "\">\n"
1193 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1194 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1195 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1197 if( $wgUseTwoButtonsSearchForm )
1198 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1200 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1204 // Ensure unique id's for search boxes made after the first
1205 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1210 function topLinks() {
1214 $this->mainPageLink(),
1215 $this->specialLink( 'recentchanges' )
1218 if ( $wgOut->isArticleRelated() ) {
1219 $s[] = $this->editThisPage();
1220 $s[] = $this->historyLink();
1222 # Many people don't like this dropdown box
1223 #$s[] = $this->specialPagesList();
1225 if( $this->variantLinks() ) {
1226 $s[] = $this->variantLinks();
1229 if( $this->extensionTabLinks() ) {
1230 $s[] = $this->extensionTabLinks();
1233 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1234 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1238 * Compatibility for extensions adding functionality through tabs.
1239 * Eventually these old skins should be replaced with SkinTemplate-based
1243 function extensionTabLinks() {
1247 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1248 foreach( $tabs as $tab ) {
1249 $s[] = Xml
::element( 'a',
1250 array( 'href' => $tab['href'] ),
1257 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1258 $out .= $wgLang->pipeList( $s );
1265 * Language/charset variant links for classic-style skins
1268 function variantLinks() {
1270 /* show links to different language variants */
1271 global $wgEnableVariants, $wgLang, $wgContLang;
1272 $variants = $wgContLang->getVariants();
1273 if( $wgEnableVariants && sizeof( $variants ) > 1 ) {
1274 foreach( $variants as $code ) {
1275 $varname = $wgContLang->getVariantname( $code );
1276 if( $varname == 'disable' )
1278 $s = $wgLang->pipeList( array(
1280 '<a href="' . $this->mTitle
->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1287 function bottomLinks() {
1288 global $wgOut, $wgUser, $wgUseTrackbacks;
1289 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1292 if ( $wgOut->isArticleRelated() ) {
1293 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1294 if ( $wgUser->isLoggedIn() ) {
1295 $element[] = $this->watchThisPage();
1297 $element[] = $this->talkLink();
1298 $element[] = $this->historyLink();
1299 $element[] = $this->whatLinksHere();
1300 $element[] = $this->watchPageLinksLink();
1302 if( $wgUseTrackbacks )
1303 $element[] = $this->trackbackLink();
1305 if ( $this->mTitle
->getNamespace() == NS_USER
1306 ||
$this->mTitle
->getNamespace() == NS_USER_TALK
){
1307 $id = User
::idFromName( $this->mTitle
->getText() );
1308 $ip = User
::isIP( $this->mTitle
->getText() );
1310 if( $id ||
$ip ) { # both anons and non-anons have contri list
1311 $element[] = $this->userContribsLink();
1313 if( $this->showEmailUser( $id ) ) {
1314 $element[] = $this->emailUserLink();
1318 $s = implode( $element, $sep );
1320 if ( $this->mTitle
->getArticleId() ) {
1322 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1323 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1324 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1326 $s .= "<br />\n" . $this->otherLanguages();
1332 function pageStats() {
1333 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1334 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1336 $oldid = $wgRequest->getVal( 'oldid' );
1337 $diff = $wgRequest->getVal( 'diff' );
1338 if ( ! $wgOut->isArticle() ) { return ''; }
1339 if( !$wgArticle instanceOf Article
) { return ''; }
1340 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1341 if ( 0 == $wgArticle->getID() ) { return ''; }
1344 if ( !$wgDisableCounters ) {
1345 $count = $wgLang->formatNum( $wgArticle->getCount() );
1347 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1351 if( $wgMaxCredits != 0 ){
1352 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1354 $s .= $this->lastModified();
1357 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1358 $dbr = wfGetDB( DB_SLAVE
);
1359 $res = $dbr->select( 'watchlist',
1360 array( 'COUNT(*) AS n' ),
1361 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
1364 $x = $dbr->fetchObject( $res );
1366 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1367 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1371 return $s . ' ' . $this->getCopyright();
1374 function getCopyright( $type = 'detect' ) {
1375 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1377 if ( $type == 'detect' ) {
1378 $diff = $wgRequest->getVal( 'diff' );
1379 $isCur = $wgArticle && $wgArticle->isCurrent();
1380 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1387 if ( $type == 'history' ) {
1388 $msg = 'history_copyright';
1394 if( $wgRightsPage ) {
1395 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1396 } elseif( $wgRightsUrl ) {
1397 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1398 } elseif( $wgRightsText ) {
1399 $link = $wgRightsText;
1404 $out .= wfMsgForContent( $msg, $link );
1408 function getCopyrightIcon() {
1409 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1411 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1412 $out = $wgCopyrightIcon;
1413 } else if ( $wgRightsIcon ) {
1414 $icon = htmlspecialchars( $wgRightsIcon );
1415 if ( $wgRightsUrl ) {
1416 $url = htmlspecialchars( $wgRightsUrl );
1417 $out .= '<a href="'.$url.'">';
1419 $text = htmlspecialchars( $wgRightsText );
1420 $out .= "<img src=\"$icon\" alt='$text' />";
1421 if ( $wgRightsUrl ) {
1428 function getPoweredBy() {
1429 global $wgStylePath;
1430 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1431 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1435 function lastModified() {
1436 global $wgLang, $wgArticle;
1437 if( $this->mRevisionId
) {
1438 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1440 $timestamp = $wgArticle->getTimestamp();
1443 $d = $wgLang->date( $timestamp, true );
1444 $t = $wgLang->time( $timestamp, true );
1445 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1449 if ( wfGetLB()->getLaggedSlaveMode() ) {
1450 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1455 function logoText( $align = '' ) {
1456 if ( '' != $align ) {
1457 $a = " align='{$align}'";
1462 $mp = wfMsg( 'mainpage' );
1463 $mptitle = Title
::newMainPage();
1464 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1466 $logourl = $this->getLogo();
1467 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1472 * show a drop-down box of special pages
1474 function specialPagesList() {
1475 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1476 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1477 foreach ( $pages as $name => $page ) {
1478 $pages[$name] = $page->getDescription();
1481 $go = wfMsg( 'go' );
1482 $sp = wfMsg( 'specialpages' );
1483 $spp = $wgContLang->specialPage( 'Specialpages' );
1485 $s = '<form id="specialpages" method="get" ' .
1486 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1487 $s .= "<select name=\"wpDropdown\">\n";
1488 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1491 foreach ( $pages as $name => $desc ) {
1492 $p = $wgContLang->specialPage( $name );
1493 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1495 $s .= "</select>\n";
1496 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1501 function mainPageLink() {
1502 $s = $this->makeKnownLinkObj( Title
::newMainPage(), wfMsg( 'mainpage' ) );
1506 function copyrightLink() {
1507 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1508 wfMsg( 'copyrightpagename' ) );
1512 private function footerLink ( $desc, $page ) {
1513 // if the link description has been set to "-" in the default language,
1514 if ( wfMsgForContent( $desc ) == '-') {
1515 // then it is disabled, for all languages.
1518 // Otherwise, we display the link for the user, described in their
1519 // language (which may or may not be the same as the default language),
1520 // but we make the link target be the one site-wide page.
1521 return $this->makeKnownLink( wfMsgForContent( $page ),
1522 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1526 function privacyLink() {
1527 return $this->footerLink( 'privacy', 'privacypage' );
1530 function aboutLink() {
1531 return $this->footerLink( 'aboutsite', 'aboutpage' );
1534 function disclaimerLink() {
1535 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1538 function editThisPage() {
1541 if ( !$wgOut->isArticleRelated() ) {
1542 $s = wfMsg( 'protectedpage' );
1544 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1545 $t = wfMsg( 'editthispage' );
1546 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1547 $t = wfMsg( 'create-this-page' );
1549 $t = wfMsg( 'viewsource' );
1552 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, $this->editUrlOptions() );
1558 * Return URL options for the 'edit page' link.
1559 * This may include an 'oldid' specifier, if the current page view is such.
1564 function editUrlOptions() {
1567 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1568 return 'action=edit&oldid=' . intval( $this->mRevisionId
);
1570 return 'action=edit';
1574 function deleteThisPage() {
1575 global $wgUser, $wgRequest;
1577 $diff = $wgRequest->getVal( 'diff' );
1578 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1579 $t = wfMsg( 'deletethispage' );
1581 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, 'action=delete' );
1588 function protectThisPage() {
1589 global $wgUser, $wgRequest;
1591 $diff = $wgRequest->getVal( 'diff' );
1592 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1593 if ( $this->mTitle
->isProtected() ) {
1594 $t = wfMsg( 'unprotectthispage' );
1595 $q = 'action=unprotect';
1597 $t = wfMsg( 'protectthispage' );
1598 $q = 'action=protect';
1600 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, $q );
1607 function watchThisPage() {
1609 ++
$this->mWatchLinkNum
;
1611 if ( $wgOut->isArticleRelated() ) {
1612 if ( $this->mTitle
->userIsWatching() ) {
1613 $t = wfMsg( 'unwatchthispage' );
1614 $q = 'action=unwatch';
1615 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1617 $t = wfMsg( 'watchthispage' );
1618 $q = 'action=watch';
1619 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1621 $s = $this->makeKnownLinkObj( $this->mTitle
, $t, $q, '', '', " id=\"$id\"" );
1623 $s = wfMsg( 'notanarticle' );
1628 function moveThisPage() {
1629 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1630 return $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Movepage' ),
1631 wfMsg( 'movethispage' ), 'target=' . $this->mTitle
->getPrefixedURL() );
1633 // no message if page is protected - would be redundant
1638 function historyLink() {
1639 return $this->link( $this->mTitle
, wfMsgHtml( 'history' ),
1640 array( 'rel' => 'archives' ), array( 'action' => 'history' ) );
1643 function whatLinksHere() {
1644 return $this->makeKnownLinkObj(
1645 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1646 wfMsgHtml( 'whatlinkshere' ) );
1649 function userContribsLink() {
1650 return $this->makeKnownLinkObj(
1651 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1652 wfMsgHtml( 'contributions' ) );
1655 function showEmailUser( $id ) {
1657 $targetUser = User
::newFromId( $id );
1658 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1659 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1662 function emailUserLink() {
1663 return $this->makeKnownLinkObj(
1664 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1665 wfMsg( 'emailuser' ) );
1668 function watchPageLinksLink() {
1670 if ( ! $wgOut->isArticleRelated() ) {
1671 return '(' . wfMsg( 'notanarticle' ) . ')';
1673 return $this->makeKnownLinkObj(
1674 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1675 wfMsg( 'recentchangeslinked' ) );
1679 function trackbackLink() {
1680 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1681 . wfMsg( 'trackbacklink' ) . '</a>';
1684 function otherLanguages() {
1685 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1687 if ( $wgHideInterlanguageLinks ) {
1691 $a = $wgOut->getLanguageLinks();
1692 if ( 0 == count( $a ) ) {
1696 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1698 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1699 foreach( $a as $l ) {
1701 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1705 $nt = Title
::newFromText( $l );
1706 $url = $nt->escapeFullURL();
1707 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1709 if ( '' == $text ) { $text = $l; }
1710 $style = $this->getExternalLinkAttributes( $l, $text );
1711 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1713 if( $wgContLang->isRTL() ) $s .= '</span>';
1717 function talkLink() {
1718 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1719 # No discussion links for special pages
1723 $linkOptions = array();
1725 if( $this->mTitle
->isTalkPage() ) {
1726 $link = $this->mTitle
->getSubjectPage();
1727 switch( $link->getNamespace() ) {
1729 $text = wfMsg( 'articlepage' );
1732 $text = wfMsg( 'userpage' );
1735 $text = wfMsg( 'projectpage' );
1738 $text = wfMsg( 'imagepage' );
1739 # Make link known if image exists, even if the desc. page doesn't.
1740 if( wfFindFile( $link ) )
1741 $linkOptions[] = 'known';
1744 $text = wfMsg( 'mediawikipage' );
1747 $text = wfMsg( 'templatepage' );
1750 $text = wfMsg( 'viewhelppage' );
1753 $text = wfMsg( 'categorypage' );
1756 $text = wfMsg( 'articlepage' );
1759 $link = $this->mTitle
->getTalkPage();
1760 $text = wfMsg( 'talkpage' );
1763 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1768 function commentLink() {
1771 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1775 # __NEWSECTIONLINK___ changes behaviour here
1776 # If it's present, the link points to this page, otherwise
1777 # it points to the talk page
1778 if( $this->mTitle
->isTalkPage() ) {
1779 $title = $this->mTitle
;
1780 } elseif( $wgOut->showNewSectionLink() ) {
1781 $title = $this->mTitle
;
1783 $title = $this->mTitle
->getTalkPage();
1786 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1789 /* these are used extensively in SkinTemplate, but also some other places */
1790 static function makeMainPageUrl( $urlaction = '' ) {
1791 $title = Title
::newMainPage();
1792 self
::checkTitle( $title, '' );
1793 return $title->getLocalURL( $urlaction );
1796 static function makeSpecialUrl( $name, $urlaction = '' ) {
1797 $title = SpecialPage
::getTitleFor( $name );
1798 return $title->getLocalURL( $urlaction );
1801 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1802 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1803 return $title->getLocalURL( $urlaction );
1806 static function makeI18nUrl( $name, $urlaction = '' ) {
1807 $title = Title
::newFromText( wfMsgForContent( $name ) );
1808 self
::checkTitle( $title, $name );
1809 return $title->getLocalURL( $urlaction );
1812 static function makeUrl( $name, $urlaction = '' ) {
1813 $title = Title
::newFromText( $name );
1814 self
::checkTitle( $title, $name );
1815 return $title->getLocalURL( $urlaction );
1818 # If url string starts with http, consider as external URL, else
1820 static function makeInternalOrExternalUrl( $name ) {
1821 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1824 return self
::makeUrl( $name );
1828 # this can be passed the NS number as defined in Language.php
1829 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1830 $title = Title
::makeTitleSafe( $namespace, $name );
1831 self
::checkTitle( $title, $name );
1832 return $title->getLocalURL( $urlaction );
1835 /* these return an array with the 'href' and boolean 'exists' */
1836 static function makeUrlDetails( $name, $urlaction = '' ) {
1837 $title = Title
::newFromText( $name );
1838 self
::checkTitle( $title, $name );
1840 'href' => $title->getLocalURL( $urlaction ),
1841 'exists' => $title->getArticleID() != 0 ?
true : false
1846 * Make URL details where the article exists (or at least it's convenient to think so)
1848 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1849 $title = Title
::newFromText( $name );
1850 self
::checkTitle( $title, $name );
1852 'href' => $title->getLocalURL( $urlaction ),
1857 # make sure we have some title to operate on
1858 static function checkTitle( &$title, $name ) {
1859 if( !is_object( $title ) ) {
1860 $title = Title
::newFromText( $name );
1861 if( !is_object( $title ) ) {
1862 $title = Title
::newFromText( '--error: link target missing--' );
1868 * Build an array that represents the sidebar(s), the navigation bar among them
1872 function buildSidebar() {
1873 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1875 wfProfileIn( __METHOD__
);
1877 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1879 if ( $wgEnableSidebarCache ) {
1880 $cachedsidebar = $parserMemc->get( $key );
1881 if ( $cachedsidebar ) {
1882 wfProfileOut( __METHOD__
);
1883 return $cachedsidebar;
1888 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1890 foreach( $lines as $line ) {
1891 if( strpos( $line, '*' ) !== 0 )
1893 if( strpos( $line, '**') !== 0 ) {
1894 $heading = trim( $line, '* ' );
1895 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
1897 if( strpos( $line, '|' ) !== false ) { // sanity check
1898 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
1899 $link = wfMsgForContent( $line[0] );
1903 $text = wfMsgExt( $line[1], 'parsemag' );
1904 if( wfEmptyMsg( $line[1], $text ) )
1906 if( wfEmptyMsg( $line[0], $link ) )
1909 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1912 $title = Title
::newFromText( $link );
1914 $title = $title->fixSpecialName();
1915 $href = $title->getLocalURL();
1917 $href = 'INVALID-TITLE';
1921 $bar[$heading][] = array(
1924 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1927 } else { continue; }
1930 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1931 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1932 wfProfileOut( __METHOD__
);