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' ;
28 /** Constructor, call parent constructor */
29 function Skin() { parent
::__construct(); }
32 * Fetch the set of available skins.
33 * @return array of strings
36 static function getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
44 wfProfileIn( __METHOD__
. '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
52 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
54 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
58 $skinsInitialised = true;
59 wfProfileOut( __METHOD__
. '-init' );
61 return $wgValidSkinNames;
65 * Fetch the list of usable skins in regards to $wgSkipSkins.
66 * Useful for Special:Preferences and other places where you
67 * only want to show skins users _can_ use.
68 * @return array of strings
70 public static function getUsableSkins() {
72 $usableSkins = self
::getSkinNames();
73 foreach ( $wgSkipSkins as $skip ) {
74 unset( $usableSkins[$skip] );
80 * Normalize a skin preference value to a form that can be loaded.
81 * If a skin can't be found, it will fall back to the configured
82 * default (or the old 'Classic' skin if that's broken).
87 static function normalizeKey( $key ) {
88 global $wgDefaultSkin;
89 $skinNames = Skin
::getSkinNames();
92 // Don't return the default immediately;
93 // in a misconfiguration we need to fall back.
94 $key = $wgDefaultSkin;
97 if( isset( $skinNames[$key] ) ) {
101 // Older versions of the software used a numeric setting
102 // in the user preferences.
106 2 => 'cologneblue' );
108 if( isset( $fallback[$key] ) ){
109 $key = $fallback[$key];
112 if( isset( $skinNames[$key] ) ) {
120 * Factory method for loading a skin of a given type
121 * @param string $key 'monobook', 'standard', etc
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory, $wgAutoloadClasses;
128 $key = Skin
::normalizeKey( $key );
130 $skinNames = Skin
::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = 'Skin'.ucfirst($key);
134 # Grab the skin class and initialise it.
135 # Use autoloader if it is set in $wgAutoloadClasses.
136 if( !class_exists( $className, isset($wgAutoloadClasses[$className]) ) ) {
137 // Preload base classes to work around APC/PHP5 bug
138 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
139 if( file_exists( $deps ) ) include_once( $deps );
140 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
142 # Check if we got if not failback to default skin
143 if( !class_exists( $className ) ) {
144 # DO NOT die if the class isn't found. This breaks maintenance
145 # scripts and can cause a user account to be unrecoverable
146 # except by SQL manipulation if a previously valid skin name
147 # is no longer valid.
148 wfDebug( "Skin class does not exist: $className\n" );
149 $className = 'SkinMonobook';
150 require_once( "{$wgStyleDirectory}/MonoBook.php" );
153 $skin = new $className;
157 /** @return string path to the skin stylesheet */
158 function getStylesheet() {
159 return 'common/wikistandard.css';
162 /** @return string skin name */
163 public function getSkinName() {
164 return $this->skinname
;
167 function qbSetting() {
168 global $wgOut, $wgUser;
170 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
171 $q = $wgUser->getOption( 'quickbar', 0 );
175 function initPage( OutputPage
$out ) {
176 global $wgFavicon, $wgAppleTouchIcon;
178 wfProfileIn( __METHOD__
);
180 # Generally the order of the favicon and apple-touch-icon links
181 # should not matter, but Konqueror (3.5.9 at least) incorrectly
182 # uses whichever one appears later in the HTML source. Make sure
183 # apple-touch-icon is specified first to avoid this.
184 if( false !== $wgAppleTouchIcon ) {
185 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
188 if( false !== $wgFavicon ) {
189 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
192 # OpenSearch description link
193 $out->addLink( array(
195 'type' => 'application/opensearchdescription+xml',
196 'href' => wfScript( 'opensearch_desc' ),
197 'title' => wfMsgForContent( 'opensearch-desc' ),
200 $this->addMetadataLinks($out);
202 $this->mRevisionId
= $out->mRevisionId
;
204 $this->preloadExistence();
206 wfProfileOut( __METHOD__
);
210 * Preload the existence of three commonly-requested pages in a single query
212 function preloadExistence() {
213 global $wgUser, $wgTitle;
216 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
219 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
221 } elseif ( $wgTitle->isTalkPage() ) {
222 $titles[] = $wgTitle->getSubjectPage();
224 $titles[] = $wgTitle->getTalkPage();
227 $lb = new LinkBatch( $titles );
231 function addMetadataLinks( OutputPage
$out ) {
232 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
233 global $wgRightsPage, $wgRightsUrl;
235 if( $out->isArticleRelated() ) {
236 # note: buggy CC software only reads first "meta" link
237 if( $wgEnableCreativeCommonsRdf ) {
238 $out->addMetadataLink( array(
239 'title' => 'Creative Commons',
240 'type' => 'application/rdf+xml',
241 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
243 if( $wgEnableDublinCoreRdf ) {
244 $out->addMetadataLink( array(
245 'title' => 'Dublin Core',
246 'type' => 'application/rdf+xml',
247 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
251 if( $wgRightsPage ) {
252 $copy = Title
::newFromText( $wgRightsPage );
254 $copyright = $copy->getLocalURL();
257 if( !$copyright && $wgRightsUrl ) {
258 $copyright = $wgRightsUrl;
261 $out->addLink( array(
262 'rel' => 'copyright',
263 'href' => $copyright ) );
267 function setMembers(){
268 global $wgTitle, $wgUser;
269 $this->mTitle
= $wgTitle;
270 $this->mUser
= $wgUser;
271 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
272 $this->usercss
= false;
275 function outputPage( OutputPage
$out ) {
276 global $wgDebugComments;
277 wfProfileIn( __METHOD__
);
280 $this->initPage( $out );
282 // See self::afterContentHook() for documentation
283 $afterContent = $this->afterContentHook();
285 $out->out( $out->headElement( $this ) );
287 $out->out( "\n<body" );
288 $ops = $this->getBodyOptions();
289 foreach ( $ops as $name => $val ) {
290 $out->out( " $name='$val'" );
293 if ( $wgDebugComments ) {
294 $out->out( "<!-- Wiki debugging output:\n" .
295 $out->mDebugtext
. "-->\n" );
298 $out->out( $this->beforeContent() );
300 $out->out( $out->mBodytext
. "\n" );
302 $out->out( $this->afterContent() );
304 $out->out( $afterContent );
306 $out->out( $this->bottomScripts() );
308 $out->out( wfReportTime() );
310 $out->out( "\n</body></html>" );
311 wfProfileOut( __METHOD__
);
314 static function makeVariablesScript( $data ) {
315 global $wgJsMimeType;
317 $r = array( "<script type= \"$wgJsMimeType\">/*<![CDATA[*/" );
318 foreach ( $data as $name => $value ) {
319 $encValue = Xml
::encodeJsVar( $value );
320 $r[] = "var $name = $encValue;";
322 $r[] = "/*]]>*/</script>\n";
324 return implode( "\n\t\t", $r );
328 * Make a <script> tag containing global variables
329 * @param array $data Associative array containing one element:
330 * skinname => the skin name
331 * The odd calling convention is for backwards compatibility
333 static function makeGlobalVariablesScript( $data ) {
334 global $wgScript, $wgStylePath, $wgUser;
335 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
336 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
337 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
338 global $wgUseAjax, $wgAjaxWatch;
339 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
340 global $wgRestrictionTypes, $wgLivePreview;
341 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
343 $ns = $wgTitle->getNamespace();
344 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ?
$wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
345 $separatorTransTable = $wgContLang->separatorTransformTable();
346 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
347 $compactSeparatorTransTable = array(
348 implode( "\t", array_keys( $separatorTransTable ) ),
349 implode( "\t", $separatorTransTable ),
351 $digitTransTable = $wgContLang->digitTransformTable();
352 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
353 $compactDigitTransTable = array(
354 implode( "\t", array_keys( $digitTransTable ) ),
355 implode( "\t", $digitTransTable ),
359 'skin' => $data['skinname'],
360 'stylepath' => $wgStylePath,
361 'wgArticlePath' => $wgArticlePath,
362 'wgScriptPath' => $wgScriptPath,
363 'wgScript' => $wgScript,
364 'wgVariantArticlePath' => $wgVariantArticlePath,
365 'wgActionPaths' => (object)$wgActionPaths,
366 'wgServer' => $wgServer,
367 'wgCanonicalNamespace' => $nsname,
368 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBkey() ),
369 'wgNamespaceNumber' => $wgTitle->getNamespace(),
370 'wgPageName' => $wgTitle->getPrefixedDBKey(),
371 'wgTitle' => $wgTitle->getText(),
372 'wgAction' => $wgRequest->getText( 'action', 'view' ),
373 'wgArticleId' => $wgTitle->getArticleId(),
374 'wgIsArticle' => $wgOut->isArticle(),
375 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
376 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
377 'wgUserLanguage' => $wgLang->getCode(),
378 'wgContentLanguage' => $wgContLang->getCode(),
379 'wgBreakFrames' => $wgBreakFrames,
380 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
381 'wgVersion' => $wgVersion,
382 'wgEnableAPI' => $wgEnableAPI,
383 'wgEnableWriteAPI' => $wgEnableWriteAPI,
384 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
385 'wgDigitTransformTable' => $compactDigitTransTable,
388 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false )){
389 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
390 $vars['wgDBname'] = $wgDBname;
391 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
392 $vars['wgMWSuggestMessages'] = array( wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled'));
395 foreach( $wgRestrictionTypes as $type )
396 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
398 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
399 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
400 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
401 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
402 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
405 if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
406 $msgs = (object)array();
407 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
408 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
410 $vars['wgAjaxWatch'] = $msgs;
413 wfRunHooks('MakeGlobalVariablesScript', array(&$vars));
415 return self
::makeVariablesScript( $vars );
418 function getHeadScripts( $allowUserJs ) {
419 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
421 $vars = self
::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
423 $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
426 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
427 $r[] = "<script type=\"$wgJsMimeType\" src=\"".
428 htmlspecialchars(self
::makeUrl('-',
429 "action=raw$jsCache&gen=js&useskin=" .
430 urlencode( $this->getSkinName() ) ) ) .
431 "\"><!-- site js --></script>";
433 if( $allowUserJs && $wgUser->isLoggedIn() ) {
434 $userpage = $wgUser->getUserPage();
435 $userjs = htmlspecialchars( self
::makeUrl(
436 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
437 'action=raw&ctype='.$wgJsMimeType));
438 $r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
440 return $vars . "\t\t" . implode ( "\n\t\t", $r );
444 * To make it harder for someone to slip a user a fake
445 * user-JavaScript or user-CSS preview, a random token
446 * is associated with the login session. If it's not
447 * passed back with the preview request, we won't render
450 * @param string $action
454 function userCanPreview( $action ) {
455 global $wgTitle, $wgRequest, $wgUser;
457 if( $action != 'submit' )
459 if( !$wgRequest->wasPosted() )
461 if( !$wgTitle->userCanEditCssJsSubpage() )
463 return $wgUser->matchEditToken(
464 $wgRequest->getVal( 'wpEditToken' ) );
468 * generated JavaScript action=raw&gen=js
469 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
470 * nated together. For some bizarre reason, it does *not* return any
471 * custom user JS from subpages. Huh?
473 * There's absolutely no reason to have separate Monobook/Common JSes.
474 * Any JS that cares can just check the skin variable generated at the
475 * top. For now Monobook.js will be maintained, but it should be consi-
480 public function generateUserJs() {
483 wfProfileIn( __METHOD__
);
485 $s = "/* generated javascript */\n";
486 $s .= "var skin = '" . Xml
::escapeJsString( $this->getSkinName() ) . "';\n";
487 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
488 $s .= "\n\n/* MediaWiki:Common.js */\n";
489 $commonJs = wfMsgForContent('common.js');
490 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
494 $s .= "\n\n/* MediaWiki:".ucfirst( $this->getSkinName() ).".js */\n";
495 // avoid inclusion of non defined user JavaScript (with custom skins only)
496 // by checking for default message content
497 $msgKey = ucfirst( $this->getSkinName() ).'.js';
498 $userJS = wfMsgForContent($msgKey);
499 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
503 wfProfileOut( __METHOD__
);
508 * generate user stylesheet for action=raw&gen=css
510 public function generateUserStylesheet() {
511 wfProfileIn( __METHOD__
);
512 $s = "/* generated user stylesheet */\n" .
513 $this->reallyGenerateUserStylesheet();
514 wfProfileOut( __METHOD__
);
519 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
521 protected function reallyGenerateUserStylesheet(){
524 if (($undopt = $wgUser->getOption("underline")) < 2) {
525 $underline = $undopt ?
'underline' : 'none';
526 $s .= "a { text-decoration: $underline; }\n";
528 if( $wgUser->getOption( 'highlightbroken' ) ) {
529 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
532 a.new, #quickbar a.new,
533 a.stub, #quickbar a.stub {
536 a.new:after, #quickbar a.new:after {
540 a.stub:after, #quickbar a.stub:after {
546 if( $wgUser->getOption( 'justify' ) ) {
547 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
549 if( !$wgUser->getOption( 'showtoc' ) ) {
550 $s .= "#toc { display: none; }\n";
552 if( !$wgUser->getOption( 'editsection' ) ) {
553 $s .= ".editsection { display: none; }\n";
561 function setupUserCss( OutputPage
$out ) {
562 global $wgRequest, $wgContLang, $wgUser;
563 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
565 wfProfileIn( __METHOD__
);
567 $this->setupSkinUserCss( $out );
571 'maxage' => $wgSquidMaxage,
574 // Add any extension CSS
575 foreach( $out->getExtStyle() as $tag ) {
576 $out->addStyle( $tag['href'] );
579 // If we use the site's dynamic CSS, throw that in, too
580 // Per-site custom styles
581 if( $wgUseSiteCss ) {
582 global $wgHandheldStyle;
583 $query = wfArrayToCGI( array(
584 'usemsgcache' => 'yes',
585 'ctype' => 'text/css',
586 'smaxage' => $wgSquidMaxage
588 # Site settings must override extension css! (bug 15025)
589 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
590 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
591 if( $wgHandheldStyle ) {
592 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
594 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
597 if( $wgUser->isLoggedIn() ) {
598 // Ensure that logged-in users' generated CSS isn't clobbered
599 // by anons' publicly cacheable generated CSS.
600 $siteargs['smaxage'] = '0';
601 $siteargs['ts'] = $wgUser->mTouched
;
603 // Per-user styles based on preferences
604 $siteargs['gen'] = 'css';
605 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
606 $siteargs['useskin'] = $us;
608 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
610 // Per-user custom style pages
611 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
612 $action = $wgRequest->getVal('action');
613 # If we're previewing the CSS page, use it
614 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
615 $previewCss = $wgRequest->getText('wpTextbox1');
616 // @FIXME: properly escape the cdata!
617 $this->usercss
= "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
619 $out->addStyle( self
::makeUrl($this->userpage
. '/' . $this->getSkinName() .'.css',
620 'action=raw&ctype=text/css' ) );
624 wfProfileOut( __METHOD__
);
628 * Add skin specific stylesheets
629 * @param $out OutputPage
631 function setupSkinUserCss( OutputPage
$out ) {
632 $out->addStyle( 'common/shared.css' );
633 $out->addStyle( 'common/oldshared.css' );
634 $out->addStyle( $this->getStylesheet() );
635 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
638 function getBodyOptions() {
639 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
641 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
643 if ( 0 != $wgTitle->getNamespace() ) {
644 $a = array( 'bgcolor' => '#ffffec' );
646 else $a = array( 'bgcolor' => '#FFFFFF' );
647 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
648 $wgTitle->quickUserCan( 'edit' ) ) {
649 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
650 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
651 $a +
= array ('ondblclick' => $s);
654 $a['onload'] = $wgOut->getOnloadHandler();
657 ' '.( $wgContLang->isRTL() ?
"rtl" : "ltr" ).
658 ' '.$this->getPageClasses( $wgTitle ) .
659 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName( ) );
663 function getPageClasses( $title ) {
664 $numeric = 'ns-'.$title->getNamespace();
665 if( $title->getNamespace() == NS_SPECIAL
) {
666 $type = "ns-special";
667 } elseif( $title->isTalkPage() ) {
670 $type = "ns-subject";
672 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
673 return "$numeric $type $name";
685 * This will be called immediately after the <body> tag. Split into
686 * two functions to make it easier to subclass.
688 function beforeContent() {
689 return $this->doBeforeContent();
692 function doBeforeContent() {
694 $fname = 'Skin::doBeforeContent';
695 wfProfileIn( $fname );
698 $qb = $this->qbSetting();
700 if( $langlinks = $this->otherLanguages() ) {
706 $borderhack = 'class="top"';
709 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
710 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
712 $shove = ( $qb != 0 );
713 $left = ( $qb == 1 ||
$qb == 3 );
714 if( $wgContLang->isRTL() ) $left = !$left;
717 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
718 $this->logoText() . '</td>';
720 $s .= $this->getQuickbarCompensator( $rows );
722 $l = $wgContLang->isRTL() ?
'right' : 'left';
723 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
725 $s .= $this->topLinks() ;
726 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
728 $r = $wgContLang->isRTL() ?
"left" : "right";
729 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
730 $s .= $this->nameAndLogin();
731 $s .= "\n<br />" . $this->searchForm() . "</td>";
734 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
737 if ( $shove && !$left ) { # Right
738 $s .= $this->getQuickbarCompensator( $rows );
740 $s .= "</tr>\n</table>\n</div>\n";
741 $s .= "\n<div id='article'>\n";
743 $notice = wfGetSiteNotice();
745 $s .= "\n<div id='siteNotice'>$notice</div>\n";
747 $s .= $this->pageTitle();
748 $s .= $this->pageSubtitle() ;
749 $s .= $this->getCategories();
750 wfProfileOut( $fname );
755 function getCategoryLinks() {
756 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
757 global $wgContLang, $wgUser;
759 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
762 $sep = wfMsgHtml( 'catseparator' );
764 // Use Unicode bidi embedding override characters,
765 // to make sure links don't smash each other up in ugly ways.
766 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
767 $embed = "<span dir='$dir'>";
770 $allCats = $wgOut->getCategoryLinks();
772 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
773 if ( !empty( $allCats['normal'] ) ) {
774 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
776 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
777 $s .= '<div id="mw-normal-catlinks">' .
778 $this->link( Title
::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
779 . $colon . $t . '</div>';
783 if ( isset( $allCats['hidden'] ) ) {
784 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
785 $class ='mw-hidden-cats-user-shown';
786 } elseif ( $wgTitle->getNamespace() == NS_CATEGORY
) {
787 $class = 'mw-hidden-cats-ns-shown';
789 $class = 'mw-hidden-cats-hidden';
791 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
792 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
793 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
797 # optional 'dmoz-like' category browser. Will be shown under the list
798 # of categories an article belong to
799 if( $wgUseCategoryBrowser ){
800 $s .= '<br /><hr />';
802 # get a big array of the parents tree
803 $parenttree = $wgTitle->getParentCategoryTree();
804 # Skin object passed by reference cause it can not be
805 # accessed under the method subfunction drawCategoryBrowser
806 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
807 # Clean out bogus first entry and sort them
810 # Output one per line
811 $s .= implode("<br />\n", $tempout);
817 /** Render the array as a serie of links.
818 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
819 * @param &skin Object: skin passed by reference
820 * @return String separated by >, terminate with "\n"
822 function drawCategoryBrowser( $tree, &$skin ){
824 foreach ($tree as $element => $parent) {
825 if (empty($parent)) {
826 # element start a new list
829 # grab the others elements
830 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
832 # add our current element to the list
833 $eltitle = Title
::newFromText($element);
834 $return .= $skin->link( $eltitle, $eltitle->getText() ) ;
839 function getCategories() {
840 $catlinks=$this->getCategoryLinks();
842 $classes = 'catlinks';
844 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
845 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
846 $classes .= ' catlinks-allhidden';
849 if( !empty( $catlinks ) ){
850 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
854 function getQuickbarCompensator( $rows = 1 ) {
855 return "<td width='152' rowspan='{$rows}'> </td>";
859 * This runs a hook to allow extensions placing their stuff after content
860 * and article metadata (e.g. categories).
861 * Note: This function has nothing to do with afterContent().
863 * This hook is placed here in order to allow using the same hook for all
864 * skins, both the SkinTemplate based ones and the older ones, which directly
865 * use this class to get their data.
867 * The output of this function gets processed in SkinTemplate::outputPage() for
868 * the SkinTemplate based skins, all other skins should directly echo it.
870 * Returns an empty string by default, if not changed by any hook function.
872 protected function afterContentHook() {
875 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
876 // adding just some spaces shouldn't toggle the output
877 // of the whole <div/>, so we use trim() here
878 if( trim( $data ) != '' ){
879 // Doing this here instead of in the skins to
880 // ensure that the div has the same ID in all
882 $data = "<div id='mw-data-after-content'>\n" .
887 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
894 * This gets called shortly before the </body> tag.
895 * @return String HTML to be put before </body>
897 function afterContent() {
898 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
899 return $printfooter . $this->doAfterContent();
903 * This gets called shortly before the </body> tag.
904 * @return String HTML-wrapped JS code to be put before </body>
906 function bottomScripts() {
907 global $wgJsMimeType;
908 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
909 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
910 return $bottomScriptText;
913 /** @return string Retrievied from HTML text */
914 function printSource() {
916 $url = htmlspecialchars( $wgTitle->getFullURL() );
917 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
920 function printFooter() {
921 return "<p>" . $this->printSource() .
922 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
925 /** overloaded by derived classes */
926 function doAfterContent() { return "</div></div>"; }
928 function pageTitleLinks() {
929 global $wgOut, $wgTitle, $wgUser, $wgRequest;
931 $oldid = $wgRequest->getVal( 'oldid' );
932 $diff = $wgRequest->getVal( 'diff' );
933 $action = $wgRequest->getText( 'action' );
935 $s = $this->printableLink();
936 $disclaimer = $this->disclaimerLink(); # may be empty
938 $s .= ' | ' . $disclaimer;
940 $privacy = $this->privacyLink(); # may be empty too
942 $s .= ' | ' . $privacy;
945 if ( $wgOut->isArticleRelated() ) {
946 if ( $wgTitle->getNamespace() == NS_FILE
) {
947 $name = $wgTitle->getDBkey();
948 $image = wfFindFile( $wgTitle );
950 $link = htmlspecialchars( $image->getURL() );
951 $style = $this->getInternalLinkAttributes( $link, $name );
952 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
956 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
957 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
958 wfMsg( 'currentrev' ) );
961 if ( $wgUser->getNewtalk() ) {
962 # do not show "You have new messages" text when we are viewing our
964 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
965 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
966 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
967 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
969 $wgOut->setSquidMaxage(0);
970 $wgOut->enableClientCache(false);
974 $undelete = $this->getUndeleteLink();
975 if( !empty( $undelete ) ) {
976 $s .= ' | '.$undelete;
981 function getUndeleteLink() {
982 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
983 if( $wgUser->isAllowed( 'deletedhistory' ) &&
984 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
985 ($n = $wgTitle->isDeleted() ) )
987 if ( $wgUser->isAllowed( 'undelete' ) ) {
988 $msg = 'thisisdeleted';
990 $msg = 'viewdeleted';
993 $this->makeKnownLinkObj(
994 SpecialPage
::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
995 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
1000 function printableLink() {
1001 global $wgOut, $wgFeedClasses, $wgRequest;
1003 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1005 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
1006 if( $wgOut->isSyndicated() ) {
1007 foreach( $wgFeedClasses as $format => $class ) {
1008 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1009 $s .= " | <a href=\"$feedurl\">{$format}</a>";
1015 function pageTitle() {
1017 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
1021 function pageSubtitle() {
1024 $sub = $wgOut->getSubtitle();
1026 global $wgExtraSubtitle;
1027 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
1029 $subpages = $this->subPageSubtitle();
1030 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
1031 $s = "<p class='subtitle'>{$sub}</p>\n";
1035 function subPageSubtitle() {
1037 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
1040 global $wgOut, $wgTitle;
1041 if($wgOut->isArticle() && MWNamespace
::hasSubpages( $wgTitle->getNamespace() )) {
1042 $ptext=$wgTitle->getPrefixedText();
1043 if(preg_match('/\//',$ptext)) {
1044 $links = explode('/',$ptext);
1045 array_pop( $links );
1049 foreach($links as $link) {
1050 $growinglink .= $link;
1052 $linkObj = Title
::newFromText( $growinglink );
1053 if( is_object( $linkObj ) && $linkObj->exists() ){
1054 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
1059 $subpages .= '< ';
1061 $subpages .= $getlink;
1066 $growinglink .= '/';
1074 * Returns true if the IP should be shown in the header
1076 function showIPinHeader() {
1077 global $wgShowIPinHeader;
1078 return $wgShowIPinHeader && session_id() != '';
1081 function nameAndLogin() {
1082 global $wgUser, $wgTitle, $wgLang, $wgContLang;
1084 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1087 if ( $wgUser->isAnon() ) {
1088 if( $this->showIPinHeader() ) {
1091 $talkLink = $this->link( $wgUser->getTalkPage(),
1092 $wgLang->getNsText( NS_TALK
) );
1094 $ret .= "$name ($talkLink)";
1096 $ret .= wfMsg( 'notloggedin' );
1099 $returnTo = $wgTitle->getPrefixedDBkey();
1101 if ( $logoutPage != $returnTo ) {
1102 $query['returnto'] = $returnTo;
1105 $loginlink = $wgUser->isAllowed( 'createaccount' )
1106 ?
'nav-login-createaccount'
1108 $ret .= "\n<br />" . $this->link(
1109 SpecialPage
::getTitleFor( 'Userlogin' ),
1110 wfMsg( $loginlink ), array(), $query
1113 $returnTo = $wgTitle->getPrefixedDBkey();
1114 $talkLink = $this->link( $wgUser->getTalkPage(),
1115 $wgLang->getNsText( NS_TALK
) );
1117 $ret .= $this->link( $wgUser->getUserPage(),
1118 htmlspecialchars( $wgUser->getName() ) );
1119 $ret .= " ($talkLink)<br />";
1120 $ret .= $this->link(
1121 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1122 array(), array( 'returnto' => $returnTo )
1124 $ret .= ' | ' . $this->specialLink( 'preferences' );
1126 $ret .= ' | ' . $this->link(
1127 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1134 function getSearchLink() {
1135 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1136 return $searchPage->getLocalURL();
1139 function escapeSearchLink() {
1140 return htmlspecialchars( $this->getSearchLink() );
1143 function searchForm() {
1145 $search = $wgRequest->getText( 'search' );
1147 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1148 . $this->escapeSearchLink() . "\">\n"
1149 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1150 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
1151 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" /> '
1152 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
1154 // Ensure unique id's for search boxes made after the first
1155 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1160 function topLinks() {
1164 $s = $this->mainPageLink() . $sep
1165 . $this->specialLink( 'recentchanges' );
1167 if ( $wgOut->isArticleRelated() ) {
1168 $s .= $sep . $this->editThisPage()
1169 . $sep . $this->historyLink();
1171 # Many people don't like this dropdown box
1172 #$s .= $sep . $this->specialPagesList();
1174 $s .= $this->variantLinks();
1176 $s .= $this->extensionTabLinks();
1182 * Compatibility for extensions adding functionality through tabs.
1183 * Eventually these old skins should be replaced with SkinTemplate-based
1187 function extensionTabLinks() {
1190 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1191 foreach( $tabs as $tab ) {
1192 $s .= ' | ' . Xml
::element( 'a',
1193 array( 'href' => $tab['href'] ),
1200 * Language/charset variant links for classic-style skins
1203 function variantLinks() {
1205 /* show links to different language variants */
1206 global $wgDisableLangConversion, $wgContLang, $wgTitle;
1207 $variants = $wgContLang->getVariants();
1208 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1209 foreach( $variants as $code ) {
1210 $varname = $wgContLang->getVariantname( $code );
1211 if( $varname == 'disable' )
1213 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1219 function bottomLinks() {
1220 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1224 if ( $wgOut->isArticleRelated() ) {
1225 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1226 if ( $wgUser->isLoggedIn() ) {
1227 $s .= $sep . $this->watchThisPage();
1229 $s .= $sep . $this->talkLink()
1230 . $sep . $this->historyLink()
1231 . $sep . $this->whatLinksHere()
1232 . $sep . $this->watchPageLinksLink();
1234 if ($wgUseTrackbacks)
1235 $s .= $sep . $this->trackbackLink();
1237 if ( $wgTitle->getNamespace() == NS_USER
1238 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
1241 $id=User
::idFromName($wgTitle->getText());
1242 $ip=User
::isIP($wgTitle->getText());
1244 if($id ||
$ip) { # both anons and non-anons have contri list
1245 $s .= $sep . $this->userContribsLink();
1247 if( $this->showEmailUser( $id ) ) {
1248 $s .= $sep . $this->emailUserLink();
1251 if ( $wgTitle->getArticleId() ) {
1253 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1254 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1255 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1257 $s .= "<br />\n" . $this->otherLanguages();
1262 function pageStats() {
1263 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1264 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1266 $oldid = $wgRequest->getVal( 'oldid' );
1267 $diff = $wgRequest->getVal( 'diff' );
1268 if ( ! $wgOut->isArticle() ) { return ''; }
1269 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1270 if ( 0 == $wgArticle->getID() ) { return ''; }
1273 if ( !$wgDisableCounters ) {
1274 $count = $wgLang->formatNum( $wgArticle->getCount() );
1276 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1280 if( $wgMaxCredits != 0 ){
1281 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1283 $s .= $this->lastModified();
1286 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1287 $dbr = wfGetDB( DB_SLAVE
);
1288 $watchlist = $dbr->tableName( 'watchlist' );
1289 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1290 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1291 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1292 $res = $dbr->query( $sql, 'Skin::pageStats');
1293 $x = $dbr->fetchObject( $res );
1295 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1296 array( 'parseinline' ), $wgLang->formatNum($x->n
)
1300 return $s . ' ' . $this->getCopyright();
1303 function getCopyright( $type = 'detect' ) {
1304 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1306 if ( $type == 'detect' ) {
1307 $diff = $wgRequest->getVal( 'diff' );
1308 $isCur = $wgArticle && $wgArticle->isCurrent();
1309 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1316 if ( $type == 'history' ) {
1317 $msg = 'history_copyright';
1323 if( $wgRightsPage ) {
1324 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1325 } elseif( $wgRightsUrl ) {
1326 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1327 } elseif( $wgRightsText ) {
1328 $link = $wgRightsText;
1333 $out .= wfMsgForContent( $msg, $link );
1337 function getCopyrightIcon() {
1338 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1340 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1341 $out = $wgCopyrightIcon;
1342 } else if ( $wgRightsIcon ) {
1343 $icon = htmlspecialchars( $wgRightsIcon );
1344 if ( $wgRightsUrl ) {
1345 $url = htmlspecialchars( $wgRightsUrl );
1346 $out .= '<a href="'.$url.'">';
1348 $text = htmlspecialchars( $wgRightsText );
1349 $out .= "<img src=\"$icon\" alt='$text' />";
1350 if ( $wgRightsUrl ) {
1357 function getPoweredBy() {
1358 global $wgStylePath;
1359 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1360 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1364 function lastModified() {
1365 global $wgLang, $wgArticle;
1366 if( $this->mRevisionId
) {
1367 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1369 $timestamp = $wgArticle->getTimestamp();
1372 $d = $wgLang->date( $timestamp, true );
1373 $t = $wgLang->time( $timestamp, true );
1374 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1378 if ( wfGetLB()->getLaggedSlaveMode() ) {
1379 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1384 function logoText( $align = '' ) {
1385 if ( '' != $align ) { $a = " align='{$align}'"; }
1388 $mp = wfMsg( 'mainpage' );
1389 $mptitle = Title
::newMainPage();
1390 $url = ( is_object($mptitle) ?
$mptitle->escapeLocalURL() : '' );
1392 $logourl = $this->getLogo();
1393 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1398 * show a drop-down box of special pages
1400 function specialPagesList() {
1401 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1402 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1403 foreach ( $pages as $name => $page ) {
1404 $pages[$name] = $page->getDescription();
1407 $go = wfMsg( 'go' );
1408 $sp = wfMsg( 'specialpages' );
1409 $spp = $wgContLang->specialPage( 'Specialpages' );
1411 $s = '<form id="specialpages" method="get" ' .
1412 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1413 $s .= "<select name=\"wpDropdown\">\n";
1414 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1417 foreach ( $pages as $name => $desc ) {
1418 $p = $wgContLang->specialPage( $name );
1419 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1421 $s .= "</select>\n";
1422 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1427 function mainPageLink() {
1428 $s = $this->makeKnownLinkObj( Title
::newMainPage(), wfMsg( 'mainpage' ) );
1432 function copyrightLink() {
1433 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1434 wfMsg( 'copyrightpagename' ) );
1438 private function footerLink ( $desc, $page ) {
1439 // if the link description has been set to "-" in the default language,
1440 if ( wfMsgForContent( $desc ) == '-') {
1441 // then it is disabled, for all languages.
1444 // Otherwise, we display the link for the user, described in their
1445 // language (which may or may not be the same as the default language),
1446 // but we make the link target be the one site-wide page.
1447 return $this->makeKnownLink( wfMsgForContent( $page ),
1448 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1452 function privacyLink() {
1453 return $this->footerLink( 'privacy', 'privacypage' );
1456 function aboutLink() {
1457 return $this->footerLink( 'aboutsite', 'aboutpage' );
1460 function disclaimerLink() {
1461 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1464 function editThisPage() {
1465 global $wgOut, $wgTitle;
1467 if ( !$wgOut->isArticleRelated() ) {
1468 $s = wfMsg( 'protectedpage' );
1470 if( $wgTitle->quickUserCan( 'edit' ) && $wgTitle->exists() ) {
1471 $t = wfMsg( 'editthispage' );
1472 } elseif( $wgTitle->quickUserCan( 'create' ) && !$wgTitle->exists() ) {
1473 $t = wfMsg( 'create-this-page' );
1475 $t = wfMsg( 'viewsource' );
1478 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1484 * Return URL options for the 'edit page' link.
1485 * This may include an 'oldid' specifier, if the current page view is such.
1490 function editUrlOptions() {
1493 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1494 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1496 return "action=edit";
1500 function deleteThisPage() {
1501 global $wgUser, $wgTitle, $wgRequest;
1503 $diff = $wgRequest->getVal( 'diff' );
1504 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1505 $t = wfMsg( 'deletethispage' );
1507 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1514 function protectThisPage() {
1515 global $wgUser, $wgTitle, $wgRequest;
1517 $diff = $wgRequest->getVal( 'diff' );
1518 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1519 if ( $wgTitle->isProtected() ) {
1520 $t = wfMsg( 'unprotectthispage' );
1521 $q = 'action=unprotect';
1523 $t = wfMsg( 'protectthispage' );
1524 $q = 'action=protect';
1526 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1533 function watchThisPage() {
1534 global $wgOut, $wgTitle;
1535 ++
$this->mWatchLinkNum
;
1537 if ( $wgOut->isArticleRelated() ) {
1538 if ( $wgTitle->userIsWatching() ) {
1539 $t = wfMsg( 'unwatchthispage' );
1540 $q = 'action=unwatch';
1541 $id = "mw-unwatch-link".$this->mWatchLinkNum
;
1543 $t = wfMsg( 'watchthispage' );
1544 $q = 'action=watch';
1545 $id = 'mw-watch-link'.$this->mWatchLinkNum
;
1547 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1549 $s = wfMsg( 'notanarticle' );
1554 function moveThisPage() {
1557 if ( $wgTitle->quickUserCan( 'move' ) ) {
1558 return $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Movepage' ),
1559 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1561 // no message if page is protected - would be redundant
1566 function historyLink() {
1569 return $this->makeKnownLinkObj( $wgTitle,
1570 wfMsg( 'history' ), 'action=history' );
1573 function whatLinksHere() {
1576 return $this->makeKnownLinkObj(
1577 SpecialPage
::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1578 wfMsg( 'whatlinkshere' ) );
1581 function userContribsLink() {
1584 return $this->makeKnownLinkObj(
1585 SpecialPage
::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1586 wfMsg( 'contributions' ) );
1589 function showEmailUser( $id ) {
1591 $targetUser = User
::newFromId( $id );
1592 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1593 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1596 function emailUserLink() {
1599 return $this->makeKnownLinkObj(
1600 SpecialPage
::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1601 wfMsg( 'emailuser' ) );
1604 function watchPageLinksLink() {
1605 global $wgOut, $wgTitle;
1607 if ( ! $wgOut->isArticleRelated() ) {
1608 return '(' . wfMsg( 'notanarticle' ) . ')';
1610 return $this->makeKnownLinkObj(
1611 SpecialPage
::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1612 wfMsg( 'recentchangeslinked' ) );
1616 function trackbackLink() {
1619 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1620 . wfMsg('trackbacklink') . "</a>";
1623 function otherLanguages() {
1624 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1626 if ( $wgHideInterlanguageLinks ) {
1630 $a = $wgOut->getLanguageLinks();
1631 if ( 0 == count( $a ) ) {
1635 $s = wfMsg( 'otherlanguages' ) . ': ';
1637 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1638 foreach( $a as $l ) {
1639 if ( ! $first ) { $s .= ' | '; }
1642 $nt = Title
::newFromText( $l );
1643 $url = $nt->escapeFullURL();
1644 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1646 if ( '' == $text ) { $text = $l; }
1647 $style = $this->getExternalLinkAttributes( $l, $text );
1648 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1650 if($wgContLang->isRTL()) $s .= '</span>';
1654 function bugReportsLink() {
1655 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1656 wfMsg( 'bugreports' ) );
1660 function talkLink() {
1663 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1664 # No discussion links for special pages
1668 $linkOptions = array();
1670 if( $wgTitle->isTalkPage() ) {
1671 $link = $wgTitle->getSubjectPage();
1672 switch( $link->getNamespace() ) {
1674 $text = wfMsg( 'articlepage' );
1677 $text = wfMsg( 'userpage' );
1680 $text = wfMsg( 'projectpage' );
1683 $text = wfMsg( 'imagepage' );
1684 # Make link known if image exists, even if the desc. page doesn't.
1685 if( wfFindFile( $link ) )
1686 $linkOptions[] = 'known';
1689 $text = wfMsg( 'mediawikipage' );
1692 $text = wfMsg( 'templatepage' );
1695 $text = wfMsg( 'viewhelppage' );
1698 $text = wfMsg( 'categorypage' );
1701 $text = wfMsg( 'articlepage' );
1704 $link = $wgTitle->getTalkPage();
1705 $text = wfMsg( 'talkpage' );
1708 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1713 function commentLink() {
1714 global $wgTitle, $wgOut;
1716 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1720 # __NEWSECTIONLINK___ changes behaviour here
1721 # If it's present, the link points to this page, otherwise
1722 # it points to the talk page
1723 if( $wgTitle->isTalkPage() ) {
1725 } elseif( $wgOut->showNewSectionLink() ) {
1728 $title = $wgTitle->getTalkPage();
1731 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1734 /* these are used extensively in SkinTemplate, but also some other places */
1735 static function makeMainPageUrl( $urlaction = '' ) {
1736 $title = Title
::newMainPage();
1737 self
::checkTitle( $title, '' );
1738 return $title->getLocalURL( $urlaction );
1741 static function makeSpecialUrl( $name, $urlaction = '' ) {
1742 $title = SpecialPage
::getTitleFor( $name );
1743 return $title->getLocalURL( $urlaction );
1746 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1747 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1748 return $title->getLocalURL( $urlaction );
1751 static function makeI18nUrl( $name, $urlaction = '' ) {
1752 $title = Title
::newFromText( wfMsgForContent( $name ) );
1753 self
::checkTitle( $title, $name );
1754 return $title->getLocalURL( $urlaction );
1757 static function makeUrl( $name, $urlaction = '' ) {
1758 $title = Title
::newFromText( $name );
1759 self
::checkTitle( $title, $name );
1760 return $title->getLocalURL( $urlaction );
1763 # If url string starts with http, consider as external URL, else
1765 static function makeInternalOrExternalUrl( $name ) {
1766 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1769 return self
::makeUrl( $name );
1773 # this can be passed the NS number as defined in Language.php
1774 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1775 $title = Title
::makeTitleSafe( $namespace, $name );
1776 self
::checkTitle( $title, $name );
1777 return $title->getLocalURL( $urlaction );
1780 /* these return an array with the 'href' and boolean 'exists' */
1781 static function makeUrlDetails( $name, $urlaction = '' ) {
1782 $title = Title
::newFromText( $name );
1783 self
::checkTitle( $title, $name );
1785 'href' => $title->getLocalURL( $urlaction ),
1786 'exists' => $title->getArticleID() != 0 ?
true : false
1791 * Make URL details where the article exists (or at least it's convenient to think so)
1793 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1794 $title = Title
::newFromText( $name );
1795 self
::checkTitle( $title, $name );
1797 'href' => $title->getLocalURL( $urlaction ),
1802 # make sure we have some title to operate on
1803 static function checkTitle( &$title, $name ) {
1804 if( !is_object( $title ) ) {
1805 $title = Title
::newFromText( $name );
1806 if( !is_object( $title ) ) {
1807 $title = Title
::newFromText( '--error: link target missing--' );
1813 * Build an array that represents the sidebar(s), the navigation bar among them
1817 function buildSidebar() {
1818 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1820 wfProfileIn( __METHOD__
);
1822 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1824 if ( $wgEnableSidebarCache ) {
1825 $cachedsidebar = $parserMemc->get( $key );
1826 if ( $cachedsidebar ) {
1827 wfProfileOut( __METHOD__
);
1828 return $cachedsidebar;
1833 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1835 foreach ($lines as $line) {
1836 if (strpos($line, '*') !== 0)
1838 if (strpos($line, '**') !== 0) {
1839 $line = trim($line, '* ');
1841 if( !array_key_exists($heading, $bar) ) $bar[$heading] = array();
1843 if (strpos($line, '|') !== false) { // sanity check
1844 $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
1845 $link = wfMsgForContent( $line[0] );
1848 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1850 if (wfEmptyMsg($line[0], $link))
1853 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1856 $title = Title
::newFromText( $link );
1858 $title = $title->fixSpecialName();
1859 $href = $title->getLocalURL();
1861 $href = 'INVALID-TITLE';
1865 $bar[$heading][] = array(
1868 'id' => 'n-' . strtr($line[1], ' ', '-'),
1871 } else { continue; }
1874 wfRunHooks('SkinBuildSidebar', array($this, &$bar));
1875 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1876 wfProfileOut( __METHOD__
);