3 * @defgroup Skins Skins
6 if ( !defined( 'MEDIAWIKI' ) ) {
11 * The main skin class that provide methods and properties for all other skins.
12 * This base class is also the "Standard" skin.
14 * See docs/skin.txt for more information.
18 class Skin
extends Linker
{
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
23 // How many search boxes have we made? Avoid duplicate id's.
24 protected $searchboxes = '';
26 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
27 protected $skinname = 'standard';
28 // @todo Fixme: should be protected :-\
31 /** Constructor, call parent constructor */
32 function __construct() {
33 parent
::__construct();
37 * Fetch the set of available skins.
38 * @return array of strings
40 static function getSkinNames() {
41 global $wgValidSkinNames;
42 static $skinsInitialised = false;
43 if ( !$skinsInitialised ) {
44 # Get a list of available skins
45 # Build using the regular expression '^(.*).php$'
46 # Array keys are all lower case, array value keep the case used by filename
48 wfProfileIn( __METHOD__
. '-init' );
49 global $wgStyleDirectory;
50 $skinDir = dir( $wgStyleDirectory );
52 # while code from www.php.net
53 while( false !== ( $file = $skinDir->read() ) ) {
54 // Skip non-PHP files, hidden files, and '.dep' includes
56 if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
58 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
62 $skinsInitialised = true;
63 wfProfileOut( __METHOD__
. '-init' );
65 return $wgValidSkinNames;
69 * Fetch the list of usable skins in regards to $wgSkipSkins.
70 * Useful for Special:Preferences and other places where you
71 * only want to show skins users _can_ use.
72 * @return array of strings
74 public static function getUsableSkins() {
76 $usableSkins = self
::getSkinNames();
77 foreach ( $wgSkipSkins as $skip ) {
78 unset( $usableSkins[$skip] );
84 * Normalize a skin preference value to a form that can be loaded.
85 * If a skin can't be found, it will fall back to the configured
86 * default (or the old 'Classic' skin if that's broken).
87 * @param $key String: 'monobook', 'standard', etc.
90 static function normalizeKey( $key ) {
91 global $wgDefaultSkin;
92 $skinNames = Skin
::getSkinNames();
95 // Don't return the default immediately;
96 // in a misconfiguration we need to fall back.
97 $key = $wgDefaultSkin;
100 if( isset( $skinNames[$key] ) ) {
104 // Older versions of the software used a numeric setting
105 // in the user preferences.
112 if( isset( $fallback[$key] ) ) {
113 $key = $fallback[$key];
116 if( isset( $skinNames[$key] ) ) {
118 } else if( isset( $skinNames[$wgDefaultSkin] ) ) {
119 return $wgDefaultSkin;
126 * Factory method for loading a skin of a given type
127 * @param $key String: 'monobook', 'standard', etc.
130 static function &newFromKey( $key ) {
131 global $wgStyleDirectory;
133 $key = Skin
::normalizeKey( $key );
135 $skinNames = Skin
::getSkinNames();
136 $skinName = $skinNames[$key];
137 $className = 'Skin' . ucfirst( $key );
139 # Grab the skin class and initialise it.
140 if ( !class_exists( $className ) ) {
141 // Preload base classes to work around APC/PHP5 bug
142 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
143 if( file_exists( $deps ) ) {
144 include_once( $deps );
146 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
148 # Check if we got if not failback to default skin
149 if( !class_exists( $className ) ) {
150 # DO NOT die if the class isn't found. This breaks maintenance
151 # scripts and can cause a user account to be unrecoverable
152 # except by SQL manipulation if a previously valid skin name
153 # is no longer valid.
154 wfDebug( "Skin class does not exist: $className\n" );
155 $className = 'SkinVector';
156 require_once( "{$wgStyleDirectory}/Vector.php" );
159 $skin = new $className;
163 /** @return string path to the skin stylesheet */
164 function getStylesheet() {
165 return 'common/wikistandard.css';
168 /** @return string skin name */
169 public function getSkinName() {
170 return $this->skinname
;
173 function qbSetting() {
174 global $wgOut, $wgUser;
176 if ( $wgOut->isQuickbarSuppressed() ) {
179 $q = $wgUser->getOption( 'quickbar', 0 );
183 function initPage( OutputPage
$out ) {
184 global $wgFavicon, $wgAppleTouchIcon;
186 wfProfileIn( __METHOD__
);
188 # Generally the order of the favicon and apple-touch-icon links
189 # should not matter, but Konqueror (3.5.9 at least) incorrectly
190 # uses whichever one appears later in the HTML source. Make sure
191 # apple-touch-icon is specified first to avoid this.
192 if( false !== $wgAppleTouchIcon ) {
193 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
196 if( false !== $wgFavicon ) {
197 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
200 # OpenSearch description link
201 $out->addLink( array(
203 'type' => 'application/opensearchdescription+xml',
204 'href' => wfScript( 'opensearch_desc' ),
205 'title' => wfMsgForContent( 'opensearch-desc' ),
208 $this->addMetadataLinks( $out );
210 $this->mRevisionId
= $out->mRevisionId
;
212 $this->preloadExistence();
214 wfProfileOut( __METHOD__
);
218 * Preload the existence of three commonly-requested pages in a single query
220 function preloadExistence() {
224 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
227 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
229 } elseif ( $this->mTitle
->isTalkPage() ) {
230 $titles[] = $this->mTitle
->getSubjectPage();
232 $titles[] = $this->mTitle
->getTalkPage();
235 $lb = new LinkBatch( $titles );
240 * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML
242 * @param $out Object: instance of OutputPage
244 function addMetadataLinks( OutputPage
$out ) {
245 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
246 global $wgRightsPage, $wgRightsUrl;
248 if( $out->isArticleRelated() ) {
249 # note: buggy CC software only reads first "meta" link
250 if( $wgEnableCreativeCommonsRdf ) {
251 $out->addMetadataLink( array(
252 'title' => 'Creative Commons',
253 'type' => 'application/rdf+xml',
254 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
257 if( $wgEnableDublinCoreRdf ) {
258 $out->addMetadataLink( array(
259 'title' => 'Dublin Core',
260 'type' => 'application/rdf+xml',
261 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
266 if( $wgRightsPage ) {
267 $copy = Title
::newFromText( $wgRightsPage );
269 $copyright = $copy->getLocalURL();
272 if( !$copyright && $wgRightsUrl ) {
273 $copyright = $wgRightsUrl;
276 $out->addLink( array(
277 'rel' => 'copyright',
278 'href' => $copyright )
284 * Set some local variables
286 protected function setMembers() {
288 $this->mUser
= $wgUser;
289 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
290 $this->usercss
= false;
295 * @param $t Title object to use
297 public function setTitle( $t ) {
302 public function getTitle() {
303 return $this->mTitle
;
307 * Outputs the HTML generated by other functions.
308 * @param $out Object: instance of OutputPage
310 function outputPage( OutputPage
$out ) {
311 global $wgDebugComments;
312 wfProfileIn( __METHOD__
);
315 $this->initPage( $out );
317 // See self::afterContentHook() for documentation
318 $afterContent = $this->afterContentHook();
320 $out->out( $out->headElement( $this ) );
322 if ( $wgDebugComments ) {
323 $out->out( "<!-- Wiki debugging output:\n" .
324 $out->mDebugtext
. "-->\n" );
327 $out->out( $this->beforeContent() );
329 $out->out( $out->mBodytext
. "\n" );
331 $out->out( $this->afterContent() );
333 $out->out( $afterContent );
335 $out->out( $this->bottomScripts( $out ) );
337 $out->out( wfReportTime() );
339 $out->out( "\n</body></html>" );
340 wfProfileOut( __METHOD__
);
343 static function makeVariablesScript( $data ) {
345 return Html
::inlineScript( 'mediaWiki.config.set(' . json_encode( $data ) . ');' );
352 * Make a <script> tag containing global variables
353 * @param $skinName string Name of the skin
354 * The odd calling convention is for backwards compatibility
355 * @todo FIXME: Make this not depend on $wgTitle!
357 static function makeGlobalVariablesScript( $skinName ) {
358 if ( is_array( $skinName ) ) {
359 # Weird back-compat stuff.
360 $skinName = $skinName['skinname'];
362 global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
363 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
364 global $wgOut, $wgArticle;
365 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
366 global $wgUseAjax, $wgAjaxWatch;
367 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
368 global $wgRestrictionTypes;
369 global $wgDBname, $wgEnableMWSuggest;
372 $ns = $wgTitle->getNamespace();
373 $nsname = MWNamespace
::exists( $ns ) ? MWNamespace
::getCanonicalName( $ns ) : $wgTitle->getNsText();
374 $separatorTransTable = $wgContLang->separatorTransformTable();
375 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
376 $compactSeparatorTransTable = array(
377 implode( "\t", array_keys( $separatorTransTable ) ),
378 implode( "\t", $separatorTransTable ),
380 $digitTransTable = $wgContLang->digitTransformTable();
381 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
382 $compactDigitTransTable = array(
383 implode( "\t", array_keys( $digitTransTable ) ),
384 implode( "\t", $digitTransTable ),
387 $mainPage = Title
::newMainPage();
390 'stylepath' => $wgStylePath,
391 'wgUrlProtocols' => wfUrlProtocols(),
392 'wgArticlePath' => $wgArticlePath,
393 'wgScriptPath' => $wgScriptPath,
394 'wgScriptExtension' => $wgScriptExtension,
395 'wgScript' => $wgScript,
396 'wgVariantArticlePath' => $wgVariantArticlePath,
397 'wgActionPaths' => (object)$wgActionPaths,
398 'wgServer' => $wgServer,
399 'wgCanonicalNamespace' => $nsname,
400 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
401 SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
402 'wgNamespaceNumber' => $wgTitle->getNamespace(),
403 'wgPageName' => $wgTitle->getPrefixedDBKey(),
404 'wgTitle' => $wgTitle->getText(),
405 'wgAction' => $wgRequest->getText( 'action', 'view' ),
406 'wgArticleId' => $wgTitle->getArticleId(),
407 'wgIsArticle' => $wgOut->isArticle(),
408 'wgUserName' => $wgUser->isAnon() ?
null : $wgUser->getName(),
409 'wgUserGroups' => $wgUser->getEffectiveGroups(),
410 'wgUserLanguage' => $wgLang->getCode(),
411 'wgContentLanguage' => $wgContLang->getCode(),
412 'wgBreakFrames' => $wgBreakFrames,
413 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
414 'wgVersion' => $wgVersion,
415 'wgEnableAPI' => $wgEnableAPI,
416 'wgEnableWriteAPI' => $wgEnableWriteAPI,
417 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
418 'wgDigitTransformTable' => $compactDigitTransTable,
419 'wgMainPageTitle' => $mainPage ?
$mainPage->getPrefixedText() : null,
420 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
421 'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
422 'wgSiteName' => $wgSitename,
423 'wgCategories' => $wgOut->getCategories(),
425 if ( $wgContLang->hasVariants() ) {
426 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
429 // if on upload page output the extension list & js_upload
430 if( SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) == 'Upload' ) {
431 global $wgFileExtensions;
432 $vars['wgFileExtensions'] = $wgFileExtensions;
435 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
436 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
437 $vars['wgDBname'] = $wgDBname;
438 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
439 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
442 foreach( $wgRestrictionTypes as $type ) {
443 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
446 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
447 $msgs = (object)array();
448 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching',
449 'tooltip-ca-watch', 'tooltip-ca-unwatch' ) as $msgName ) {
450 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
452 $vars['wgAjaxWatch'] = $msgs;
455 // Allow extensions to add their custom variables to the global JS variables
456 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
458 return self
::makeVariablesScript( $vars );
462 * To make it harder for someone to slip a user a fake
463 * user-JavaScript or user-CSS preview, a random token
464 * is associated with the login session. If it's not
465 * passed back with the preview request, we won't render
468 * @param $action String: 'edit', 'submit' etc.
471 public function userCanPreview( $action ) {
472 global $wgRequest, $wgUser;
474 if( $action != 'submit' ) {
477 if( !$wgRequest->wasPosted() ) {
480 if( !$this->mTitle
->userCanEditCssSubpage() ) {
483 if( !$this->mTitle
->userCanEditJsSubpage() ) {
486 return $wgUser->matchEditToken(
487 $wgRequest->getVal( 'wpEditToken' ) );
491 * Generated JavaScript action=raw&gen=js
492 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
493 * nated together. For some bizarre reason, it does *not* return any
494 * custom user JS from subpages. Huh?
496 * There's absolutely no reason to have separate Monobook/Common JSes.
497 * Any JS that cares can just check the skin variable generated at the
498 * top. For now Monobook.js will be maintained, but it should be consi-
501 * @param $skinName String: If set, overrides the skin name
504 public function generateUserJs( $skinName = null ) {
507 wfProfileIn( __METHOD__
);
509 $skinName = $this->getSkinName();
512 $s = "/* generated javascript */\n";
513 $s .= "var skin = '" . Xml
::escapeJsString( $skinName ) . "';\n";
514 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
515 $s .= "\n\n/* MediaWiki:Common.js */\n";
516 $commonJs = wfMsgExt( 'common.js', 'content' );
517 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
521 $s .= "\n\n/* MediaWiki:" . ucfirst( $skinName ) . ".js */\n";
522 // avoid inclusion of non defined user JavaScript (with custom skins only)
523 // by checking for default message content
524 $msgKey = ucfirst( $skinName ) . '.js';
525 $userJS = wfMsgExt( $msgKey, 'content' );
526 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
530 wfProfileOut( __METHOD__
);
535 * Generate user stylesheet for action=raw&gen=css
537 public function generateUserStylesheet() {
538 wfProfileIn( __METHOD__
);
539 $s = "/* generated user stylesheet */\n" .
540 $this->reallyGenerateUserStylesheet();
541 wfProfileOut( __METHOD__
);
546 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
547 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
549 protected function reallyGenerateUserStylesheet() {
552 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
553 $underline = $undopt ?
'underline' : 'none';
554 $s .= "a { text-decoration: $underline; }\n";
556 if( $wgUser->getOption( 'highlightbroken' ) ) {
557 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
560 a.new, #quickbar a.new,
561 a.stub, #quickbar a.stub {
564 a.new:after, #quickbar a.new:after {
568 a.stub:after, #quickbar a.stub:after {
574 if( $wgUser->getOption( 'justify' ) ) {
575 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
577 if( !$wgUser->getOption( 'showtoc' ) ) {
578 $s .= "#toc { display: none; }\n";
580 if( !$wgUser->getOption( 'editsection' ) ) {
581 $s .= ".editsection { display: none; }\n";
583 $fontstyle = $wgUser->getOption( 'editfont' );
584 if ( $fontstyle !== 'default' ) {
585 $s .= "textarea { font-family: $fontstyle; }\n";
593 function setupUserCss( OutputPage
$out ) {
594 global $wgRequest, $wgUser;
595 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage;
597 wfProfileIn( __METHOD__
);
599 $this->setupSkinUserCss( $out );
603 'maxage' => $wgSquidMaxage,
606 // Add any extension CSS
607 foreach ( $out->getExtStyle() as $url ) {
608 $out->addStyle( $url );
611 // If we use the site's dynamic CSS, throw that in, too
612 // Per-site custom styles
613 if( $wgUseSiteCss ) {
614 global $wgHandheldStyle;
615 $query = wfArrayToCGI( self
::getDynamicStylesheetQuery() );
616 # Site settings must override extension css! (bug 15025)
617 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
618 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
619 if( $wgHandheldStyle ) {
620 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
622 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
625 global $wgAllowUserCssPrefs;
626 if( $wgAllowUserCssPrefs ){
627 if( $wgUser->isLoggedIn() ) {
628 // Ensure that logged-in users' generated CSS isn't clobbered
629 // by anons' publicly cacheable generated CSS.
630 $siteargs['smaxage'] = '0';
631 $siteargs['ts'] = $wgUser->mTouched
;
633 // Per-user styles based on preferences
634 $siteargs['gen'] = 'css';
635 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
636 $siteargs['useskin'] = $us;
638 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
641 // Per-user custom style pages
642 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
643 $action = $wgRequest->getVal( 'action' );
644 # If we're previewing the CSS page, use it
645 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
646 // @FIXME: properly escape the cdata!
647 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
649 $names = array( 'common', $this->getSkinName() );
650 foreach( $names as $name ) {
651 $out->addStyle( self
::makeUrl(
652 $this->userpage
. '/' . $name . '.css',
653 'action=raw&ctype=text/css' )
659 wfProfileOut( __METHOD__
);
663 * Get the query to generate a dynamic stylesheet
667 public static function getDynamicStylesheetQuery() {
668 global $wgSquidMaxage;
671 'maxage' => $wgSquidMaxage,
672 'usemsgcache' => 'yes',
673 'ctype' => 'text/css',
674 'smaxage' => $wgSquidMaxage,
679 * Add skin specific stylesheets
680 * @param $out OutputPage
682 function setupSkinUserCss( OutputPage
$out ) {
683 // This includes the shared.js and oldshared.js files from skins/common/
684 $out->addModuleStyles( 'mediawiki.legacy.shared' );
685 // TODO: Figure out how to best integrate this stuff into ResourceLoader
686 $out->addStyle( $this->getStylesheet() );
687 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
690 function getPageClasses( $title ) {
691 $numeric = 'ns-' . $title->getNamespace();
692 if( $title->getNamespace() == NS_SPECIAL
) {
693 $type = 'ns-special';
694 } elseif( $title->isTalkPage() ) {
697 $type = 'ns-subject';
699 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
700 return "$numeric $type $name";
712 * This will be called immediately after the <body> tag. Split into
713 * two functions to make it easier to subclass.
715 function beforeContent() {
716 return $this->doBeforeContent();
719 function doBeforeContent() {
721 wfProfileIn( __METHOD__
);
724 $qb = $this->qbSetting();
726 $langlinks = $this->otherLanguages();
733 $borderhack = 'class="top"';
736 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
737 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
739 $shove = ( $qb != 0 );
740 $left = ( $qb == 1 ||
$qb == 3 );
741 if( $wgContLang->isRTL() ) {
746 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
747 $this->logoText() . '</td>';
749 $s .= $this->getQuickbarCompensator( $rows );
751 $l = $wgContLang->alignStart();
752 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
754 $s .= $this->topLinks();
755 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
757 $r = $wgContLang->alignEnd();
758 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
759 $s .= $this->nameAndLogin();
760 $s .= "\n<br />" . $this->searchForm() . '</td>';
763 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
766 if ( $shove && !$left ) { # Right
767 $s .= $this->getQuickbarCompensator( $rows );
769 $s .= "</tr>\n</table>\n</div>\n";
770 $s .= "\n<div id='article'>\n";
772 $notice = wfGetSiteNotice();
774 $s .= "\n<div id='siteNotice'>$notice</div>\n";
776 $s .= $this->pageTitle();
777 $s .= $this->pageSubtitle();
778 $s .= $this->getCategories();
779 wfProfileOut( __METHOD__
);
783 function getCategoryLinks() {
784 global $wgOut, $wgUseCategoryBrowser;
785 global $wgContLang, $wgUser;
787 if( count( $wgOut->mCategoryLinks
) == 0 ) {
792 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
794 // Use Unicode bidi embedding override characters,
795 // to make sure links don't smash each other up in ugly ways.
796 $dir = $wgContLang->getDir();
797 $embed = "<span dir='$dir'>";
800 $allCats = $wgOut->getCategoryLinks();
802 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
803 if ( !empty( $allCats['normal'] ) ) {
804 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
806 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
807 $s .= '<div id="mw-normal-catlinks">' .
808 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
809 . $colon . $t . '</div>';
813 if ( isset( $allCats['hidden'] ) ) {
814 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
815 $class ='mw-hidden-cats-user-shown';
816 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
817 $class = 'mw-hidden-cats-ns-shown';
819 $class = 'mw-hidden-cats-hidden';
821 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
822 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
823 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
827 # optional 'dmoz-like' category browser. Will be shown under the list
828 # of categories an article belong to
829 if( $wgUseCategoryBrowser ) {
830 $s .= '<br /><hr />';
832 # get a big array of the parents tree
833 $parenttree = $this->mTitle
->getParentCategoryTree();
834 # Skin object passed by reference cause it can not be
835 # accessed under the method subfunction drawCategoryBrowser
836 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
837 # Clean out bogus first entry and sort them
838 unset( $tempout[0] );
840 # Output one per line
841 $s .= implode( "<br />\n", $tempout );
848 * Render the array as a serie of links.
849 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
850 * @param &skin Object: skin passed by reference
851 * @return String separated by >, terminate with "\n"
853 function drawCategoryBrowser( $tree, &$skin ) {
855 foreach( $tree as $element => $parent ) {
856 if( empty( $parent ) ) {
857 # element start a new list
860 # grab the others elements
861 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
863 # add our current element to the list
864 $eltitle = Title
::newFromText( $element );
865 $return .= $skin->link( $eltitle, $eltitle->getText() );
870 function getCategories() {
871 $catlinks = $this->getCategoryLinks();
873 $classes = 'catlinks';
875 // Check what we're showing
876 global $wgOut, $wgUser;
877 $allCats = $wgOut->getCategoryLinks();
878 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
879 $this->mTitle
->getNamespace() == NS_CATEGORY
;
881 if( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
882 $classes .= ' catlinks-allhidden';
885 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
888 function getQuickbarCompensator( $rows = 1 ) {
889 return "<td width='152' rowspan='{$rows}'> </td>";
893 * This runs a hook to allow extensions placing their stuff after content
894 * and article metadata (e.g. categories).
895 * Note: This function has nothing to do with afterContent().
897 * This hook is placed here in order to allow using the same hook for all
898 * skins, both the SkinTemplate based ones and the older ones, which directly
899 * use this class to get their data.
901 * The output of this function gets processed in SkinTemplate::outputPage() for
902 * the SkinTemplate based skins, all other skins should directly echo it.
904 * Returns an empty string by default, if not changed by any hook function.
906 protected function afterContentHook() {
909 if( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
910 // adding just some spaces shouldn't toggle the output
911 // of the whole <div/>, so we use trim() here
912 if( trim( $data ) != '' ) {
913 // Doing this here instead of in the skins to
914 // ensure that the div has the same ID in all
916 $data = "<div id='mw-data-after-content'>\n" .
921 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
928 * Generate debug data HTML for displaying at the bottom of the main content
930 * @return String HTML containing debug data, if enabled (otherwise empty).
932 protected function generateDebugHTML() {
933 global $wgShowDebug, $wgOut;
934 if ( $wgShowDebug ) {
935 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
936 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
937 $listInternals . "</ul>\n";
942 private function formatDebugHTML( $debugText ) {
943 $lines = explode( "\n", $debugText );
946 foreach( $lines as $line ) {
948 $display = ltrim( $line );
949 $ident = strlen( $line ) - strlen( $display );
950 $diff = $ident - $curIdent;
952 if ( $display == '' ) {
953 $display = "\xc2\xa0";
956 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
959 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
961 $display = htmlspecialchars( $display );
965 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
966 } elseif ( $diff == 0 ) {
967 $ret .= "</li><li>\n";
969 $ret .= str_repeat( "<ul><li>\n", $diff );
971 $ret .= $display . "\n";
975 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
980 * This gets called shortly before the </body> tag.
981 * @return String HTML to be put before </body>
983 function afterContent() {
984 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
985 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
989 * This gets called shortly before the </body> tag.
990 * @param $out OutputPage object
991 * @return String HTML-wrapped JS code to be put before </body>
993 function bottomScripts( $out ) {
994 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
995 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
996 return $bottomScriptText;
999 /** @return string Retrievied from HTML text */
1000 function printSource() {
1001 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
1002 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
1005 function printFooter() {
1006 return "<p>" . $this->printSource() .
1007 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1010 /** overloaded by derived classes */
1011 function doAfterContent() {
1012 return '</div></div>';
1015 function pageTitleLinks() {
1016 global $wgOut, $wgUser, $wgRequest, $wgLang;
1018 $oldid = $wgRequest->getVal( 'oldid' );
1019 $diff = $wgRequest->getVal( 'diff' );
1020 $action = $wgRequest->getText( 'action' );
1022 $s[] = $this->printableLink();
1023 $disclaimer = $this->disclaimerLink(); # may be empty
1027 $privacy = $this->privacyLink(); # may be empty too
1032 if ( $wgOut->isArticleRelated() ) {
1033 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1034 $name = $this->mTitle
->getDBkey();
1035 $image = wfFindFile( $this->mTitle
);
1037 $link = htmlspecialchars( $image->getURL() );
1038 $style = $this->getInternalLinkAttributes( $link, $name );
1039 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1043 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1044 $s[] .= $this->link(
1046 wfMsg( 'currentrev' ),
1049 array( 'known', 'noclasses' )
1053 if ( $wgUser->getNewtalk() ) {
1054 # do not show "You have new messages" text when we are viewing our
1056 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1058 $wgUser->getTalkPage(),
1059 wfMsgHtml( 'newmessageslink' ),
1061 array( 'redirect' => 'no' ),
1062 array( 'known', 'noclasses' )
1066 $wgUser->getTalkPage(),
1067 wfMsgHtml( 'newmessagesdifflink' ),
1069 array( 'diff' => 'cur' ),
1070 array( 'known', 'noclasses' )
1072 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1074 $wgOut->setSquidMaxage( 0 );
1075 $wgOut->enableClientCache( false );
1079 $undelete = $this->getUndeleteLink();
1080 if( !empty( $undelete ) ) {
1083 return $wgLang->pipeList( $s );
1086 function getUndeleteLink() {
1087 global $wgUser, $wgLang, $wgRequest;
1089 $action = $wgRequest->getVal( 'action', 'view' );
1091 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1092 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1093 $n = $this->mTitle
->isDeleted();
1095 if ( $wgUser->isAllowed( 'undelete' ) ) {
1096 $msg = 'thisisdeleted';
1098 $msg = 'viewdeleted';
1103 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1104 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1107 array( 'known', 'noclasses' )
1115 function printableLink() {
1116 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1120 if ( !$wgOut->isPrintable() ) {
1121 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1122 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1125 if( $wgOut->isSyndicated() ) {
1126 foreach( $wgFeedClasses as $format => $class ) {
1127 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1128 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1129 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1132 return $wgLang->pipeList( $s );
1136 * Gets the h1 element with the page title.
1139 function pageTitle() {
1141 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1145 function pageSubtitle() {
1148 $sub = $wgOut->getSubtitle();
1150 global $wgExtraSubtitle;
1151 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1153 $subpages = $this->subPageSubtitle();
1154 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1155 $s = "<p class='subtitle'>{$sub}</p>\n";
1159 function subPageSubtitle() {
1161 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1166 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1167 $ptext = $this->mTitle
->getPrefixedText();
1168 if( preg_match( '/\//', $ptext ) ) {
1169 $links = explode( '/', $ptext );
1170 array_pop( $links );
1174 foreach( $links as $link ) {
1175 $growinglink .= $link;
1177 $linkObj = Title
::newFromText( $growinglink );
1178 if( is_object( $linkObj ) && $linkObj->exists() ) {
1179 $getlink = $this->link(
1181 htmlspecialchars( $display ),
1184 array( 'known', 'noclasses' )
1188 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1190 $subpages .= '< ';
1192 $subpages .= $getlink;
1197 $growinglink .= '/';
1205 * Returns true if the IP should be shown in the header
1207 function showIPinHeader() {
1208 global $wgShowIPinHeader;
1209 return $wgShowIPinHeader && session_id() != '';
1212 function nameAndLogin() {
1213 global $wgUser, $wgLang, $wgContLang;
1215 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1218 if ( $wgUser->isAnon() ) {
1219 if( $this->showIPinHeader() ) {
1222 $talkLink = $this->link( $wgUser->getTalkPage(),
1223 $wgLang->getNsText( NS_TALK
) );
1225 $ret .= "$name ($talkLink)";
1227 $ret .= wfMsg( 'notloggedin' );
1230 $returnTo = $this->mTitle
->getPrefixedDBkey();
1232 if ( $logoutPage != $returnTo ) {
1233 $query['returnto'] = $returnTo;
1236 $loginlink = $wgUser->isAllowed( 'createaccount' )
1237 ?
'nav-login-createaccount'
1239 $ret .= "\n<br />" . $this->link(
1240 SpecialPage
::getTitleFor( 'Userlogin' ),
1241 wfMsg( $loginlink ), array(), $query
1244 $returnTo = $this->mTitle
->getPrefixedDBkey();
1245 $talkLink = $this->link( $wgUser->getTalkPage(),
1246 $wgLang->getNsText( NS_TALK
) );
1248 $ret .= $this->link( $wgUser->getUserPage(),
1249 htmlspecialchars( $wgUser->getName() ) );
1250 $ret .= " ($talkLink)<br />";
1251 $ret .= $wgLang->pipeList( array(
1253 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1254 array(), array( 'returnto' => $returnTo )
1256 $this->specialLink( 'preferences' ),
1259 $ret = $wgLang->pipeList( array(
1262 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1270 function getSearchLink() {
1271 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1272 return $searchPage->getLocalURL();
1275 function escapeSearchLink() {
1276 return htmlspecialchars( $this->getSearchLink() );
1279 function searchForm() {
1280 global $wgRequest, $wgUseTwoButtonsSearchForm;
1281 $search = $wgRequest->getText( 'search' );
1283 $s = '<form id="searchform' . $this->searchboxes
. '" name="search" class="inline" method="post" action="'
1284 . $this->escapeSearchLink() . "\">\n"
1285 . '<input type="text" id="searchInput' . $this->searchboxes
. '" name="search" size="19" value="'
1286 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1287 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1289 if( $wgUseTwoButtonsSearchForm ) {
1290 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1292 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1297 // Ensure unique id's for search boxes made after the first
1298 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1303 function topLinks() {
1307 $this->mainPageLink(),
1308 $this->specialLink( 'recentchanges' )
1311 if ( $wgOut->isArticleRelated() ) {
1312 $s[] = $this->editThisPage();
1313 $s[] = $this->historyLink();
1315 # Many people don't like this dropdown box
1316 #$s[] = $this->specialPagesList();
1318 if( $this->variantLinks() ) {
1319 $s[] = $this->variantLinks();
1322 if( $this->extensionTabLinks() ) {
1323 $s[] = $this->extensionTabLinks();
1326 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1327 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1331 * Compatibility for extensions adding functionality through tabs.
1332 * Eventually these old skins should be replaced with SkinTemplate-based
1336 function extensionTabLinks() {
1340 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1341 foreach( $tabs as $tab ) {
1342 $s[] = Xml
::element( 'a',
1343 array( 'href' => $tab['href'] ),
1350 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1351 $out .= $wgLang->pipeList( $s );
1358 * Language/charset variant links for classic-style skins
1361 function variantLinks() {
1363 /* show links to different language variants */
1364 global $wgDisableLangConversion, $wgLang, $wgContLang;
1365 $variants = $wgContLang->getVariants();
1366 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1367 foreach( $variants as $code ) {
1368 $varname = $wgContLang->getVariantname( $code );
1369 if( $varname == 'disable' ) {
1372 $s = $wgLang->pipeList( array(
1374 '<a href="' . $this->mTitle
->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1381 function bottomLinks() {
1382 global $wgOut, $wgUser, $wgUseTrackbacks;
1383 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1386 if ( $wgOut->isArticleRelated() ) {
1387 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1388 if ( $wgUser->isLoggedIn() ) {
1389 $element[] = $this->watchThisPage();
1391 $element[] = $this->talkLink();
1392 $element[] = $this->historyLink();
1393 $element[] = $this->whatLinksHere();
1394 $element[] = $this->watchPageLinksLink();
1396 if( $wgUseTrackbacks ) {
1397 $element[] = $this->trackbackLink();
1401 $this->mTitle
->getNamespace() == NS_USER ||
1402 $this->mTitle
->getNamespace() == NS_USER_TALK
1405 $id = User
::idFromName( $this->mTitle
->getText() );
1406 $ip = User
::isIP( $this->mTitle
->getText() );
1408 # Both anons and non-anons have contributions list
1410 $element[] = $this->userContribsLink();
1412 if( $this->showEmailUser( $id ) ) {
1413 $element[] = $this->emailUserLink();
1417 $s = implode( $element, $sep );
1419 if ( $this->mTitle
->getArticleId() ) {
1421 // Delete/protect/move links for privileged users
1422 if( $wgUser->isAllowed( 'delete' ) ) {
1423 $s .= $this->deleteThisPage();
1425 if( $wgUser->isAllowed( 'protect' ) ) {
1426 $s .= $sep . $this->protectThisPage();
1428 if( $wgUser->isAllowed( 'move' ) ) {
1429 $s .= $sep . $this->moveThisPage();
1432 $s .= "<br />\n" . $this->otherLanguages();
1438 function pageStats() {
1439 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1440 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1442 $oldid = $wgRequest->getVal( 'oldid' );
1443 $diff = $wgRequest->getVal( 'diff' );
1444 if ( !$wgOut->isArticle() ) {
1447 if( !$wgArticle instanceof Article
) {
1450 if ( isset( $oldid ) ||
isset( $diff ) ) {
1453 if ( 0 == $wgArticle->getID() ) {
1458 if ( !$wgDisableCounters ) {
1459 $count = $wgLang->formatNum( $wgArticle->getCount() );
1461 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1465 if( $wgMaxCredits != 0 ) {
1466 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1468 $s .= $this->lastModified();
1471 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1472 $dbr = wfGetDB( DB_SLAVE
);
1473 $res = $dbr->select(
1475 array( 'COUNT(*) AS n' ),
1477 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ),
1478 'wl_namespace' => $this->mTitle
->getNamespace()
1482 $x = $dbr->fetchObject( $res );
1484 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1485 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1489 return $s . ' ' . $this->getCopyright();
1492 function getCopyright( $type = 'detect' ) {
1493 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1495 if ( $type == 'detect' ) {
1496 $diff = $wgRequest->getVal( 'diff' );
1497 $isCur = $wgArticle && $wgArticle->isCurrent();
1498 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1505 if ( $type == 'history' ) {
1506 $msg = 'history_copyright';
1512 if( $wgRightsPage ) {
1513 $title = Title
::newFromText( $wgRightsPage );
1514 $link = $this->linkKnown( $title, $wgRightsText );
1515 } elseif( $wgRightsUrl ) {
1516 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1517 } elseif( $wgRightsText ) {
1518 $link = $wgRightsText;
1523 // Allow for site and per-namespace customization of copyright notice.
1525 if( isset( $wgArticle ) ) {
1526 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1529 if ( $forContent ) {
1530 $out .= wfMsgForContent( $msg, $link );
1532 $out .= wfMsg( $msg, $link );
1537 function getCopyrightIcon() {
1538 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1540 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1541 $out = $wgCopyrightIcon;
1542 } elseif ( $wgRightsIcon ) {
1543 $icon = htmlspecialchars( $wgRightsIcon );
1544 if ( $wgRightsUrl ) {
1545 $url = htmlspecialchars( $wgRightsUrl );
1546 $out .= '<a href="'.$url.'">';
1548 $text = htmlspecialchars( $wgRightsText );
1549 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1550 if ( $wgRightsUrl ) {
1558 * Gets the powered by MediaWiki icon.
1561 function getPoweredBy() {
1562 global $wgStylePath;
1563 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1564 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1568 function lastModified() {
1569 global $wgLang, $wgArticle;
1570 if( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest() ) {
1571 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1573 $timestamp = $wgArticle->getTimestamp();
1576 $d = $wgLang->date( $timestamp, true );
1577 $t = $wgLang->time( $timestamp, true );
1578 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1582 if ( wfGetLB()->getLaggedSlaveMode() ) {
1583 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1588 function logoText( $align = '' ) {
1589 if ( $align != '' ) {
1590 $a = " align='{$align}'";
1595 $mp = wfMsg( 'mainpage' );
1596 $mptitle = Title
::newMainPage();
1597 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1599 $logourl = $this->getLogo();
1600 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1605 * Show a drop-down box of special pages
1607 function specialPagesList() {
1608 global $wgContLang, $wgServer, $wgRedirectScript;
1609 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1610 foreach ( $pages as $name => $page ) {
1611 $pages[$name] = $page->getDescription();
1614 $go = wfMsg( 'go' );
1615 $sp = wfMsg( 'specialpages' );
1616 $spp = $wgContLang->specialPage( 'Specialpages' );
1618 $s = '<form id="specialpages" method="get" ' .
1619 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1620 $s .= "<select name=\"wpDropdown\">\n";
1621 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1624 foreach ( $pages as $name => $desc ) {
1625 $p = $wgContLang->specialPage( $name );
1626 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1628 $s .= "</select>\n";
1629 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1635 * Gets the link to the wiki's main page.
1638 function mainPageLink() {
1640 Title
::newMainPage(),
1641 wfMsg( 'mainpage' ),
1644 array( 'known', 'noclasses' )
1649 private function footerLink( $desc, $page ) {
1650 // if the link description has been set to "-" in the default language,
1651 if ( wfMsgForContent( $desc ) == '-') {
1652 // then it is disabled, for all languages.
1655 // Otherwise, we display the link for the user, described in their
1656 // language (which may or may not be the same as the default language),
1657 // but we make the link target be the one site-wide page.
1658 $title = Title
::newFromText( wfMsgForContent( $page ) );
1659 return $this->linkKnown(
1661 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1667 * Gets the link to the wiki's privacy policy page.
1669 function privacyLink() {
1670 return $this->footerLink( 'privacy', 'privacypage' );
1674 * Gets the link to the wiki's about page.
1676 function aboutLink() {
1677 return $this->footerLink( 'aboutsite', 'aboutpage' );
1681 * Gets the link to the wiki's general disclaimers page.
1683 function disclaimerLink() {
1684 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1687 function editThisPage() {
1690 if ( !$wgOut->isArticleRelated() ) {
1691 $s = wfMsg( 'protectedpage' );
1693 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1694 $t = wfMsg( 'editthispage' );
1695 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1696 $t = wfMsg( 'create-this-page' );
1698 $t = wfMsg( 'viewsource' );
1705 $this->editUrlOptions(),
1706 array( 'known', 'noclasses' )
1713 * Return URL options for the 'edit page' link.
1714 * This may include an 'oldid' specifier, if the current page view is such.
1719 function editUrlOptions() {
1722 $options = array( 'action' => 'edit' );
1724 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1725 $options['oldid'] = intval( $this->mRevisionId
);
1731 function deleteThisPage() {
1732 global $wgUser, $wgRequest;
1734 $diff = $wgRequest->getVal( 'diff' );
1735 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1736 $t = wfMsg( 'deletethispage' );
1742 array( 'action' => 'delete' ),
1743 array( 'known', 'noclasses' )
1751 function protectThisPage() {
1752 global $wgUser, $wgRequest;
1754 $diff = $wgRequest->getVal( 'diff' );
1755 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1756 if ( $this->mTitle
->isProtected() ) {
1757 $text = wfMsg( 'unprotectthispage' );
1758 $query = array( 'action' => 'unprotect' );
1760 $text = wfMsg( 'protectthispage' );
1761 $query = array( 'action' => 'protect' );
1769 array( 'known', 'noclasses' )
1777 function watchThisPage() {
1779 ++
$this->mWatchLinkNum
;
1781 if ( $wgOut->isArticleRelated() ) {
1782 if ( $this->mTitle
->userIsWatching() ) {
1783 $text = wfMsg( 'unwatchthispage' );
1784 $query = array( 'action' => 'unwatch' );
1785 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1787 $text = wfMsg( 'watchthispage' );
1788 $query = array( 'action' => 'watch' );
1789 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1795 array( 'id' => $id ),
1797 array( 'known', 'noclasses' )
1800 $s = wfMsg( 'notanarticle' );
1805 function moveThisPage() {
1806 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1808 SpecialPage
::getTitleFor( 'Movepage' ),
1809 wfMsg( 'movethispage' ),
1811 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1812 array( 'known', 'noclasses' )
1815 // no message if page is protected - would be redundant
1820 function historyLink() {
1823 wfMsgHtml( 'history' ),
1824 array( 'rel' => 'archives' ),
1825 array( 'action' => 'history' )
1829 function whatLinksHere() {
1831 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1832 wfMsgHtml( 'whatlinkshere' ),
1835 array( 'known', 'noclasses' )
1839 function userContribsLink() {
1841 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1842 wfMsgHtml( 'contributions' ),
1845 array( 'known', 'noclasses' )
1849 function showEmailUser( $id ) {
1851 $targetUser = User
::newFromId( $id );
1852 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1853 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1856 function emailUserLink() {
1858 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1859 wfMsg( 'emailuser' ),
1862 array( 'known', 'noclasses' )
1866 function watchPageLinksLink() {
1868 if ( !$wgOut->isArticleRelated() ) {
1869 return '(' . wfMsg( 'notanarticle' ) . ')';
1872 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1873 wfMsg( 'recentchangeslinked-toolbox' ),
1876 array( 'known', 'noclasses' )
1881 function trackbackLink() {
1882 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1883 . wfMsg( 'trackbacklink' ) . '</a>';
1886 function otherLanguages() {
1887 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1889 if ( $wgHideInterlanguageLinks ) {
1893 $a = $wgOut->getLanguageLinks();
1894 if ( 0 == count( $a ) ) {
1898 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1900 if( $wgContLang->isRTL() ) {
1901 $s .= '<span dir="LTR">';
1903 foreach( $a as $l ) {
1905 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1909 $nt = Title
::newFromText( $l );
1910 $url = $nt->escapeFullURL();
1911 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1912 $title = htmlspecialchars( $nt->getText() );
1914 if ( $text == '' ) {
1917 $style = $this->getExternalLinkAttributes();
1918 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
1920 if( $wgContLang->isRTL() ) {
1926 function talkLink() {
1927 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1928 # No discussion links for special pages
1932 $linkOptions = array();
1934 if( $this->mTitle
->isTalkPage() ) {
1935 $link = $this->mTitle
->getSubjectPage();
1936 switch( $link->getNamespace() ) {
1938 $text = wfMsg( 'articlepage' );
1941 $text = wfMsg( 'userpage' );
1944 $text = wfMsg( 'projectpage' );
1947 $text = wfMsg( 'imagepage' );
1948 # Make link known if image exists, even if the desc. page doesn't.
1949 if( wfFindFile( $link ) )
1950 $linkOptions[] = 'known';
1953 $text = wfMsg( 'mediawikipage' );
1956 $text = wfMsg( 'templatepage' );
1959 $text = wfMsg( 'viewhelppage' );
1962 $text = wfMsg( 'categorypage' );
1965 $text = wfMsg( 'articlepage' );
1968 $link = $this->mTitle
->getTalkPage();
1969 $text = wfMsg( 'talkpage' );
1972 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1977 function commentLink() {
1980 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1984 # __NEWSECTIONLINK___ changes behaviour here
1985 # If it is present, the link points to this page, otherwise
1986 # it points to the talk page
1987 if( $this->mTitle
->isTalkPage() ) {
1988 $title = $this->mTitle
;
1989 } elseif( $wgOut->showNewSectionLink() ) {
1990 $title = $this->mTitle
;
1992 $title = $this->mTitle
->getTalkPage();
1997 wfMsg( 'postcomment' ),
2003 array( 'known', 'noclasses' )
2007 function getUploadLink() {
2008 global $wgUploadNavigationUrl;
2010 if( $wgUploadNavigationUrl ) {
2011 # Using an empty class attribute to avoid automatic setting of "external" class
2012 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '') );
2015 SpecialPage
::getTitleFor('Upload'),
2016 wfMsgHtml( 'upload' ),
2019 array( 'known', 'noclasses' )
2024 /* these are used extensively in SkinTemplate, but also some other places */
2025 static function makeMainPageUrl( $urlaction = '' ) {
2026 $title = Title
::newMainPage();
2027 self
::checkTitle( $title, '' );
2028 return $title->getLocalURL( $urlaction );
2031 static function makeSpecialUrl( $name, $urlaction = '' ) {
2032 $title = SpecialPage
::getTitleFor( $name );
2033 return $title->getLocalURL( $urlaction );
2036 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2037 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
2038 return $title->getLocalURL( $urlaction );
2041 static function makeI18nUrl( $name, $urlaction = '' ) {
2042 $title = Title
::newFromText( wfMsgForContent( $name ) );
2043 self
::checkTitle( $title, $name );
2044 return $title->getLocalURL( $urlaction );
2047 static function makeUrl( $name, $urlaction = '' ) {
2048 $title = Title
::newFromText( $name );
2049 self
::checkTitle( $title, $name );
2050 return $title->getLocalURL( $urlaction );
2054 * If url string starts with http, consider as external URL, else
2057 static function makeInternalOrExternalUrl( $name ) {
2058 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2061 return self
::makeUrl( $name );
2065 # this can be passed the NS number as defined in Language.php
2066 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2067 $title = Title
::makeTitleSafe( $namespace, $name );
2068 self
::checkTitle( $title, $name );
2069 return $title->getLocalURL( $urlaction );
2072 /* these return an array with the 'href' and boolean 'exists' */
2073 static function makeUrlDetails( $name, $urlaction = '' ) {
2074 $title = Title
::newFromText( $name );
2075 self
::checkTitle( $title, $name );
2077 'href' => $title->getLocalURL( $urlaction ),
2078 'exists' => $title->getArticleID() != 0 ?
true : false
2083 * Make URL details where the article exists (or at least it's convenient to think so)
2085 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2086 $title = Title
::newFromText( $name );
2087 self
::checkTitle( $title, $name );
2089 'href' => $title->getLocalURL( $urlaction ),
2094 # make sure we have some title to operate on
2095 static function checkTitle( &$title, $name ) {
2096 if( !is_object( $title ) ) {
2097 $title = Title
::newFromText( $name );
2098 if( !is_object( $title ) ) {
2099 $title = Title
::newFromText( '--error: link target missing--' );
2105 * Build an array that represents the sidebar(s), the navigation bar among them
2109 function buildSidebar() {
2110 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2112 wfProfileIn( __METHOD__
);
2114 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2116 if ( $wgEnableSidebarCache ) {
2117 $cachedsidebar = $parserMemc->get( $key );
2118 if ( $cachedsidebar ) {
2119 wfProfileOut( __METHOD__
);
2120 return $cachedsidebar;
2125 $this->addToSidebar( $bar, 'sidebar' );
2127 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2128 if ( $wgEnableSidebarCache ) {
2129 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2131 wfProfileOut( __METHOD__
);
2135 * Add content from a sidebar system message
2136 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2138 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2140 * @param &$bar array
2141 * @param $message String
2143 function addToSidebar( &$bar, $message ) {
2144 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2148 * Add content from plain text
2150 * @param &$bar array
2151 * @param $text string
2153 function addToSidebarPlain( &$bar, $text ) {
2154 $lines = explode( "\n", $text );
2155 $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
2158 foreach( $lines as $line ) {
2159 if( strpos( $line, '*' ) !== 0 ) {
2162 if( strpos( $line, '**') !== 0 ) {
2163 $heading = trim( $line, '* ' );
2164 if( !array_key_exists( $heading, $bar ) ) {
2165 $bar[$heading] = array();
2168 $line = trim( $line, '* ' );
2169 if( strpos( $line, '|' ) !== false ) { // sanity check
2170 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2171 $link = wfMsgForContent( $line[0] );
2172 if( $link == '-' ) {
2176 $text = wfMsgExt( $line[1], 'parsemag' );
2177 if( wfEmptyMsg( $line[1], $text ) ) {
2180 if( wfEmptyMsg( $line[0], $link ) ) {
2184 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2187 $title = Title
::newFromText( $link );
2189 $title = $title->fixSpecialName();
2190 $href = $title->getLocalURL();
2192 $href = 'INVALID-TITLE';
2196 $bar[$heading][] = array(
2199 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2202 } else if ( (substr($line, 0, 2) == '{{') && (substr($line, -2) == '}}') ) {
2203 global $wgParser, $wgTitle;
2205 $line = substr($line, 2, strlen($line) - 4 );
2207 if (is_null($wgParser->mOptions
))
2208 $wgParser->mOptions
= new ParserOptions();
2210 $wgParser->mOptions
->setEditSection(false);
2211 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $wgParser->mOptions
)->getText();
2218 if ( count($wikiBar) > 0 )
2219 $bar = array_merge($bar, $wikiBar);
2225 * Should we include common/wikiprintable.css? Skins that have their own
2226 * print stylesheet should override this and return false. (This is an
2227 * ugly hack to get Monobook to play nicely with
2228 * OutputPage::headElement().)
2232 public function commonPrintStylesheet() {
2237 * Gets new talk page messages for the current user.
2238 * @return MediaWiki message or if no new talk page messages, nothing
2240 function getNewtalks() {
2241 global $wgUser, $wgOut;
2242 $newtalks = $wgUser->getNewMessageLinks();
2245 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2246 $userTitle = $this->mUser
->getUserPage();
2247 $userTalkTitle = $userTitle->getTalkPage();
2249 if( !$userTalkTitle->equals( $this->mTitle
) ) {
2250 $newMessagesLink = $this->link(
2252 wfMsgHtml( 'newmessageslink' ),
2254 array( 'redirect' => 'no' ),
2255 array( 'known', 'noclasses' )
2258 $newMessagesDiffLink = $this->link(
2260 wfMsgHtml( 'newmessagesdifflink' ),
2262 array( 'diff' => 'cur' ),
2263 array( 'known', 'noclasses' )
2267 'youhavenewmessages',
2269 $newMessagesDiffLink
2271 # Disable Squid cache
2272 $wgOut->setSquidMaxage( 0 );
2274 } elseif( count( $newtalks ) ) {
2275 // _>" " for BC <= 1.16
2276 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2278 foreach( $newtalks as $newtalk ) {
2279 $msgs[] = Xml
::element(
2281 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2284 $parts = implode( $sep, $msgs );
2285 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2286 $wgOut->setSquidMaxage( 0 );