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] ) ) {
124 * Factory method for loading a skin of a given type
125 * @param $key String: 'monobook', 'standard', etc.
128 static function &newFromKey( $key ) {
129 global $wgStyleDirectory;
131 $key = Skin
::normalizeKey( $key );
133 $skinNames = Skin
::getSkinNames();
134 $skinName = $skinNames[$key];
135 $className = 'Skin' . ucfirst( $key );
137 # Grab the skin class and initialise it.
138 if ( !class_exists( $className ) ) {
139 // Preload base classes to work around APC/PHP5 bug
140 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
141 if( file_exists( $deps ) ) {
142 include_once( $deps );
144 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
146 # Check if we got if not failback to default skin
147 if( !class_exists( $className ) ) {
148 # DO NOT die if the class isn't found. This breaks maintenance
149 # scripts and can cause a user account to be unrecoverable
150 # except by SQL manipulation if a previously valid skin name
151 # is no longer valid.
152 wfDebug( "Skin class does not exist: $className\n" );
153 $className = 'SkinMonobook';
154 require_once( "{$wgStyleDirectory}/MonoBook.php" );
157 $skin = new $className;
161 /** @return string path to the skin stylesheet */
162 function getStylesheet() {
163 return 'common/wikistandard.css';
166 /** @return string skin name */
167 public function getSkinName() {
168 return $this->skinname
;
171 function qbSetting() {
172 global $wgOut, $wgUser;
174 if ( $wgOut->isQuickbarSuppressed() ) {
177 $q = $wgUser->getOption( 'quickbar', 0 );
181 function initPage( OutputPage
$out ) {
182 global $wgFavicon, $wgAppleTouchIcon;
184 wfProfileIn( __METHOD__
);
186 # Generally the order of the favicon and apple-touch-icon links
187 # should not matter, but Konqueror (3.5.9 at least) incorrectly
188 # uses whichever one appears later in the HTML source. Make sure
189 # apple-touch-icon is specified first to avoid this.
190 if( false !== $wgAppleTouchIcon ) {
191 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
194 if( false !== $wgFavicon ) {
195 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
198 # OpenSearch description link
199 $out->addLink( array(
201 'type' => 'application/opensearchdescription+xml',
202 'href' => wfScript( 'opensearch_desc' ),
203 'title' => wfMsgForContent( 'opensearch-desc' ),
206 $this->addMetadataLinks( $out );
208 $this->mRevisionId
= $out->mRevisionId
;
210 $this->preloadExistence();
212 wfProfileOut( __METHOD__
);
216 * Preload the existence of three commonly-requested pages in a single query
218 function preloadExistence() {
222 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
225 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
227 } elseif ( $this->mTitle
->isTalkPage() ) {
228 $titles[] = $this->mTitle
->getSubjectPage();
230 $titles[] = $this->mTitle
->getTalkPage();
233 $lb = new LinkBatch( $titles );
238 * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML
240 * @param $out Object: instance of OutputPage
242 function addMetadataLinks( OutputPage
$out ) {
243 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
244 global $wgRightsPage, $wgRightsUrl;
246 if( $out->isArticleRelated() ) {
247 # note: buggy CC software only reads first "meta" link
248 if( $wgEnableCreativeCommonsRdf ) {
249 $out->addMetadataLink( array(
250 'title' => 'Creative Commons',
251 'type' => 'application/rdf+xml',
252 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
255 if( $wgEnableDublinCoreRdf ) {
256 $out->addMetadataLink( array(
257 'title' => 'Dublin Core',
258 'type' => 'application/rdf+xml',
259 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
264 if( $wgRightsPage ) {
265 $copy = Title
::newFromText( $wgRightsPage );
267 $copyright = $copy->getLocalURL();
270 if( !$copyright && $wgRightsUrl ) {
271 $copyright = $wgRightsUrl;
274 $out->addLink( array(
275 'rel' => 'copyright',
276 'href' => $copyright )
282 * Set some local variables
284 protected function setMembers() {
286 $this->mUser
= $wgUser;
287 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
288 $this->usercss
= false;
293 * @param Title $t The title to use
295 public function setTitle( $t ) {
300 public function getTitle() {
301 return $this->mTitle
;
305 * Outputs the HTML generated by other functions.
306 * @param $out Object: instance of OutputPage
308 function outputPage( OutputPage
$out ) {
309 global $wgDebugComments;
310 wfProfileIn( __METHOD__
);
313 $this->initPage( $out );
315 // See self::afterContentHook() for documentation
316 $afterContent = $this->afterContentHook();
318 $out->out( $out->headElement( $this ) );
320 if ( $wgDebugComments ) {
321 $out->out( "<!-- Wiki debugging output:\n" .
322 $out->mDebugtext
. "-->\n" );
325 $out->out( $this->beforeContent() );
327 $out->out( $out->mBodytext
. "\n" );
329 $out->out( $this->afterContent() );
331 $out->out( $afterContent );
333 $out->out( $this->bottomScripts() );
335 $out->out( wfReportTime() );
337 $out->out( "\n</body></html>" );
338 wfProfileOut( __METHOD__
);
341 static function makeVariablesScript( $data ) {
344 foreach ( $data as $name => $value ) {
345 $encValue = Xml
::encodeJsVar( $value );
346 $r[] = "$name=$encValue";
348 $js = 'var ' . implode( ",\n", $r ) . ';';
349 return Html
::inlineScript( "\n$js\n" );
356 * Make a <script> tag containing global variables
357 * @param $skinName string Name of the skin
358 * The odd calling convention is for backwards compatibility
359 * @TODO @FIXME Make this not depend on $wgTitle!
361 static function makeGlobalVariablesScript( $skinName ) {
362 if ( is_array( $skinName ) ) {
363 # Weird back-compat stuff.
364 $skinName = $skinName['skinname'];
366 global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
367 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
368 global $wgOut, $wgArticle;
369 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
370 global $wgUseAjax, $wgAjaxWatch;
371 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
372 global $wgRestrictionTypes;
373 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
376 $ns = $wgTitle->getNamespace();
377 $nsname = MWNamespace
::exists( $ns ) ? MWNamespace
::getCanonicalName( $ns ) : $wgTitle->getNsText();
378 $separatorTransTable = $wgContLang->separatorTransformTable();
379 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
380 $compactSeparatorTransTable = array(
381 implode( "\t", array_keys( $separatorTransTable ) ),
382 implode( "\t", $separatorTransTable ),
384 $digitTransTable = $wgContLang->digitTransformTable();
385 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
386 $compactDigitTransTable = array(
387 implode( "\t", array_keys( $digitTransTable ) ),
388 implode( "\t", $digitTransTable ),
391 $mainPage = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
394 'stylepath' => $wgStylePath,
395 'wgUrlProtocols' => wfUrlProtocols(),
396 'wgArticlePath' => $wgArticlePath,
397 'wgScriptPath' => $wgScriptPath,
398 'wgScriptExtension' => $wgScriptExtension,
399 'wgScript' => $wgScript,
400 'wgVariantArticlePath' => $wgVariantArticlePath,
401 'wgActionPaths' => (object)$wgActionPaths,
402 'wgServer' => $wgServer,
403 'wgCanonicalNamespace' => $nsname,
404 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
405 SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
406 'wgNamespaceNumber' => $wgTitle->getNamespace(),
407 'wgPageName' => $wgTitle->getPrefixedDBKey(),
408 'wgTitle' => $wgTitle->getText(),
409 'wgAction' => $wgRequest->getText( 'action', 'view' ),
410 'wgArticleId' => $wgTitle->getArticleId(),
411 'wgIsArticle' => $wgOut->isArticle(),
412 'wgUserName' => $wgUser->isAnon() ?
null : $wgUser->getName(),
413 'wgUserGroups' => $wgUser->isAnon() ?
null : $wgUser->getEffectiveGroups(),
414 'wgUserLanguage' => $wgLang->getCode(),
415 'wgContentLanguage' => $wgContLang->getCode(),
416 'wgBreakFrames' => $wgBreakFrames,
417 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
418 'wgVersion' => $wgVersion,
419 'wgEnableAPI' => $wgEnableAPI,
420 'wgEnableWriteAPI' => $wgEnableWriteAPI,
421 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
422 'wgDigitTransformTable' => $compactDigitTransTable,
423 'wgMainPageTitle' => $mainPage ?
$mainPage->getPrefixedText() : null,
424 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
425 'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
426 'wgSiteName' => $wgSitename,
427 'wgCategories' => $wgOut->getCategories(),
429 if ( $wgContLang->hasVariants() ) {
430 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
433 // if on upload page output the extension list & js_upload
434 if( SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) == 'Upload' ) {
435 global $wgFileExtensions, $wgAjaxUploadInterface;
436 $vars['wgFileExtensions'] = $wgFileExtensions;
439 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
440 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
441 $vars['wgDBname'] = $wgDBname;
442 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
443 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
446 foreach( $wgRestrictionTypes as $type ) {
447 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
450 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
451 $msgs = (object)array();
452 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching',
453 'tooltip-ca-watch', 'tooltip-ca-unwatch' ) as $msgName ) {
454 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
456 $vars['wgAjaxWatch'] = $msgs;
459 // Allow extensions to add their custom variables to the global JS variables
460 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
462 return self
::makeVariablesScript( $vars );
466 * To make it harder for someone to slip a user a fake
467 * user-JavaScript or user-CSS preview, a random token
468 * is associated with the login session. If it's not
469 * passed back with the preview request, we won't render
472 * @param $action String: 'edit', 'submit' etc.
475 public function userCanPreview( $action ) {
476 global $wgRequest, $wgUser;
478 if( $action != 'submit' ) {
481 if( !$wgRequest->wasPosted() ) {
484 if( !$this->mTitle
->userCanEditCssSubpage() ) {
487 if( !$this->mTitle
->userCanEditJsSubpage() ) {
490 return $wgUser->matchEditToken(
491 $wgRequest->getVal( 'wpEditToken' ) );
495 * Generated JavaScript action=raw&gen=js
496 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
497 * nated together. For some bizarre reason, it does *not* return any
498 * custom user JS from subpages. Huh?
500 * There's absolutely no reason to have separate Monobook/Common JSes.
501 * Any JS that cares can just check the skin variable generated at the
502 * top. For now Monobook.js will be maintained, but it should be consi-
505 * @param $skinName String: If set, overrides the skin name
508 public function generateUserJs( $skinName = null ) {
511 wfProfileIn( __METHOD__
);
513 $skinName = $this->getSkinName();
516 $s = "/* generated javascript */\n";
517 $s .= "var skin = '" . Xml
::escapeJsString( $skinName ) . "';\n";
518 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
519 $s .= "\n\n/* MediaWiki:Common.js */\n";
520 $commonJs = wfMsgExt( 'common.js', 'content' );
521 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
525 $s .= "\n\n/* MediaWiki:" . ucfirst( $skinName ) . ".js */\n";
526 // avoid inclusion of non defined user JavaScript (with custom skins only)
527 // by checking for default message content
528 $msgKey = ucfirst( $skinName ) . '.js';
529 $userJS = wfMsgExt( $msgKey, 'content' );
530 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
534 wfProfileOut( __METHOD__
);
539 * Generate user stylesheet for action=raw&gen=css
541 public function generateUserStylesheet() {
542 wfProfileIn( __METHOD__
);
543 $s = "/* generated user stylesheet */\n" .
544 $this->reallyGenerateUserStylesheet();
545 wfProfileOut( __METHOD__
);
550 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
551 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
553 protected function reallyGenerateUserStylesheet() {
556 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
557 $underline = $undopt ?
'underline' : 'none';
558 $s .= "a { text-decoration: $underline; }\n";
560 if( $wgUser->getOption( 'highlightbroken' ) ) {
561 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
564 a.new, #quickbar a.new,
565 a.stub, #quickbar a.stub {
568 a.new:after, #quickbar a.new:after {
572 a.stub:after, #quickbar a.stub:after {
578 if( $wgUser->getOption( 'justify' ) ) {
579 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
581 if( !$wgUser->getOption( 'showtoc' ) ) {
582 $s .= "#toc { display: none; }\n";
584 if( !$wgUser->getOption( 'editsection' ) ) {
585 $s .= ".editsection { display: none; }\n";
587 $fontstyle = $wgUser->getOption( 'editfont' );
588 if ( $fontstyle !== 'default' ) {
589 $s .= "textarea { font-family: $fontstyle; }\n";
597 function setupUserCss( OutputPage
$out ) {
598 global $wgRequest, $wgContLang, $wgUser;
599 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
601 wfProfileIn( __METHOD__
);
603 $this->setupSkinUserCss( $out );
607 'maxage' => $wgSquidMaxage,
610 // Add any extension CSS
611 foreach ( $out->getExtStyle() as $url ) {
612 $out->addStyle( $url );
615 // If we use the site's dynamic CSS, throw that in, too
616 // Per-site custom styles
617 if( $wgUseSiteCss ) {
618 global $wgHandheldStyle;
619 $query = wfArrayToCGI( array(
620 'usemsgcache' => 'yes',
621 'ctype' => 'text/css',
622 'smaxage' => $wgSquidMaxage
624 # Site settings must override extension css! (bug 15025)
625 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
626 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
627 if( $wgHandheldStyle ) {
628 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
630 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
633 global $wgAllowUserCssPrefs;
634 if( $wgAllowUserCssPrefs ){
635 if( $wgUser->isLoggedIn() ) {
636 // Ensure that logged-in users' generated CSS isn't clobbered
637 // by anons' publicly cacheable generated CSS.
638 $siteargs['smaxage'] = '0';
639 $siteargs['ts'] = $wgUser->mTouched
;
641 // Per-user styles based on preferences
642 $siteargs['gen'] = 'css';
643 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
644 $siteargs['useskin'] = $us;
646 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
649 // Per-user custom style pages
650 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
651 $action = $wgRequest->getVal( 'action' );
652 # If we're previewing the CSS page, use it
653 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
654 // @FIXME: properly escape the cdata!
655 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
657 $names = array( 'common', $this->getSkinName() );
658 foreach( $names as $name ) {
659 $out->addStyle( self
::makeUrl(
660 $this->userpage
. '/' . $name . '.css',
661 'action=raw&ctype=text/css' )
667 wfProfileOut( __METHOD__
);
671 * Add skin specific stylesheets
672 * @param $out OutputPage
674 function setupSkinUserCss( OutputPage
$out ) {
675 $out->addStyle( 'common/shared.css' );
676 $out->addStyle( 'common/oldshared.css' );
677 $out->addStyle( $this->getStylesheet() );
678 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
681 function getPageClasses( $title ) {
682 $numeric = 'ns-' . $title->getNamespace();
683 if( $title->getNamespace() == NS_SPECIAL
) {
684 $type = 'ns-special';
685 } elseif( $title->isTalkPage() ) {
688 $type = 'ns-subject';
690 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
691 return "$numeric $type $name";
703 * This will be called immediately after the <body> tag. Split into
704 * two functions to make it easier to subclass.
706 function beforeContent() {
707 return $this->doBeforeContent();
710 function doBeforeContent() {
712 wfProfileIn( __METHOD__
);
715 $qb = $this->qbSetting();
717 $langlinks = $this->otherLanguages();
724 $borderhack = 'class="top"';
727 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
728 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
730 $shove = ( $qb != 0 );
731 $left = ( $qb == 1 ||
$qb == 3 );
732 if( $wgContLang->isRTL() ) {
737 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
738 $this->logoText() . '</td>';
740 $s .= $this->getQuickbarCompensator( $rows );
742 $l = $wgContLang->alignStart();
743 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
745 $s .= $this->topLinks();
746 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
748 $r = $wgContLang->alignEnd();
749 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
750 $s .= $this->nameAndLogin();
751 $s .= "\n<br />" . $this->searchForm() . '</td>';
754 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
757 if ( $shove && !$left ) { # Right
758 $s .= $this->getQuickbarCompensator( $rows );
760 $s .= "</tr>\n</table>\n</div>\n";
761 $s .= "\n<div id='article'>\n";
763 $notice = wfGetSiteNotice();
765 $s .= "\n<div id='siteNotice'>$notice</div>\n";
767 $s .= $this->pageTitle();
768 $s .= $this->pageSubtitle();
769 $s .= $this->getCategories();
770 wfProfileOut( __METHOD__
);
774 function getCategoryLinks() {
775 global $wgOut, $wgUseCategoryBrowser;
776 global $wgContLang, $wgUser;
778 if( count( $wgOut->mCategoryLinks
) == 0 ) {
783 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
785 // Use Unicode bidi embedding override characters,
786 // to make sure links don't smash each other up in ugly ways.
787 $dir = $wgContLang->getDir();
788 $embed = "<span dir='$dir'>";
791 $allCats = $wgOut->getCategoryLinks();
793 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
794 if ( !empty( $allCats['normal'] ) ) {
795 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
797 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
798 $s .= '<div id="mw-normal-catlinks">' .
799 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
800 . $colon . $t . '</div>';
804 if ( isset( $allCats['hidden'] ) ) {
805 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
806 $class ='mw-hidden-cats-user-shown';
807 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
808 $class = 'mw-hidden-cats-ns-shown';
810 $class = 'mw-hidden-cats-hidden';
812 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
813 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
814 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
818 # optional 'dmoz-like' category browser. Will be shown under the list
819 # of categories an article belong to
820 if( $wgUseCategoryBrowser ) {
821 $s .= '<br /><hr />';
823 # get a big array of the parents tree
824 $parenttree = $this->mTitle
->getParentCategoryTree();
825 # Skin object passed by reference cause it can not be
826 # accessed under the method subfunction drawCategoryBrowser
827 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
828 # Clean out bogus first entry and sort them
829 unset( $tempout[0] );
831 # Output one per line
832 $s .= implode( "<br />\n", $tempout );
839 * Render the array as a serie of links.
840 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
841 * @param &skin Object: skin passed by reference
842 * @return String separated by >, terminate with "\n"
844 function drawCategoryBrowser( $tree, &$skin ) {
846 foreach( $tree as $element => $parent ) {
847 if( empty( $parent ) ) {
848 # element start a new list
851 # grab the others elements
852 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
854 # add our current element to the list
855 $eltitle = Title
::newFromText( $element );
856 $return .= $skin->link( $eltitle, $eltitle->getText() );
861 function getCategories() {
862 $catlinks = $this->getCategoryLinks();
864 $classes = 'catlinks';
866 // Check what we're showing
867 global $wgOut, $wgUser;
868 $allCats = $wgOut->getCategoryLinks();
869 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
870 $this->mTitle
->getNamespace() == NS_CATEGORY
;
872 if( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
873 $classes .= ' catlinks-allhidden';
876 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
879 function getQuickbarCompensator( $rows = 1 ) {
880 return "<td width='152' rowspan='{$rows}'> </td>";
884 * This runs a hook to allow extensions placing their stuff after content
885 * and article metadata (e.g. categories).
886 * Note: This function has nothing to do with afterContent().
888 * This hook is placed here in order to allow using the same hook for all
889 * skins, both the SkinTemplate based ones and the older ones, which directly
890 * use this class to get their data.
892 * The output of this function gets processed in SkinTemplate::outputPage() for
893 * the SkinTemplate based skins, all other skins should directly echo it.
895 * Returns an empty string by default, if not changed by any hook function.
897 protected function afterContentHook() {
900 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ) {
901 // adding just some spaces shouldn't toggle the output
902 // of the whole <div/>, so we use trim() here
903 if( trim( $data ) != '' ) {
904 // Doing this here instead of in the skins to
905 // ensure that the div has the same ID in all
907 $data = "<div id='mw-data-after-content'>\n" .
912 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
919 * Generate debug data HTML for displaying at the bottom of the main content
921 * @return String HTML containing debug data, if enabled (otherwise empty).
923 protected function generateDebugHTML() {
924 global $wgShowDebug, $wgOut;
925 if ( $wgShowDebug ) {
926 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
927 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
928 $listInternals . "</ul>\n";
933 private function formatDebugHTML( $debugText ) {
934 $lines = explode( "\n", $debugText );
937 foreach( $lines as $line ) {
939 $display = ltrim( $line );
940 $ident = strlen( $line ) - strlen( $display );
941 $diff = $ident - $curIdent;
943 if ( $display == '' ) {
944 $display = "\xc2\xa0";
947 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
950 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
952 $display = htmlspecialchars( $display );
956 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
957 } elseif ( $diff == 0 ) {
958 $ret .= "</li><li>\n";
960 $ret .= str_repeat( "<ul><li>\n", $diff );
962 $ret .= $display . "\n";
966 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
971 * This gets called shortly before the </body> tag.
972 * @return String HTML to be put before </body>
974 function afterContent() {
975 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
976 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
980 * This gets called shortly before the </body> tag.
981 * @return String HTML-wrapped JS code to be put before </body>
983 function bottomScripts() {
984 $bottomScriptText = "\n" . Html
::inlineScript( 'if (window.runOnloadHook) runOnloadHook();' ) . "\n";
985 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
986 return $bottomScriptText;
989 /** @return string Retrievied from HTML text */
990 function printSource() {
991 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
992 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
995 function printFooter() {
996 return "<p>" . $this->printSource() .
997 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1000 /** overloaded by derived classes */
1001 function doAfterContent() {
1002 return '</div></div>';
1005 function pageTitleLinks() {
1006 global $wgOut, $wgUser, $wgRequest, $wgLang;
1008 $oldid = $wgRequest->getVal( 'oldid' );
1009 $diff = $wgRequest->getVal( 'diff' );
1010 $action = $wgRequest->getText( 'action' );
1012 $s[] = $this->printableLink();
1013 $disclaimer = $this->disclaimerLink(); # may be empty
1017 $privacy = $this->privacyLink(); # may be empty too
1022 if ( $wgOut->isArticleRelated() ) {
1023 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1024 $name = $this->mTitle
->getDBkey();
1025 $image = wfFindFile( $this->mTitle
);
1027 $link = htmlspecialchars( $image->getURL() );
1028 $style = $this->getInternalLinkAttributes( $link, $name );
1029 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1033 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1034 $s[] .= $this->link(
1036 wfMsg( 'currentrev' ),
1039 array( 'known', 'noclasses' )
1043 if ( $wgUser->getNewtalk() ) {
1044 # do not show "You have new messages" text when we are viewing our
1046 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1048 $wgUser->getTalkPage(),
1049 wfMsgHtml( 'newmessageslink' ),
1051 array( 'redirect' => 'no' ),
1052 array( 'known', 'noclasses' )
1056 $wgUser->getTalkPage(),
1057 wfMsgHtml( 'newmessagesdifflink' ),
1059 array( 'diff' => 'cur' ),
1060 array( 'known', 'noclasses' )
1062 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1064 $wgOut->setSquidMaxage( 0 );
1065 $wgOut->enableClientCache( false );
1069 $undelete = $this->getUndeleteLink();
1070 if( !empty( $undelete ) ) {
1073 return $wgLang->pipeList( $s );
1076 function getUndeleteLink() {
1077 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1079 $action = $wgRequest->getVal( 'action', 'view' );
1081 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1082 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1083 $n = $this->mTitle
->isDeleted();
1085 if ( $wgUser->isAllowed( 'undelete' ) ) {
1086 $msg = 'thisisdeleted';
1088 $msg = 'viewdeleted';
1093 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1094 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1097 array( 'known', 'noclasses' )
1105 function printableLink() {
1106 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1110 if ( !$wgOut->isPrintable() ) {
1111 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1112 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1115 if( $wgOut->isSyndicated() ) {
1116 foreach( $wgFeedClasses as $format => $class ) {
1117 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1118 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1119 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1122 return $wgLang->pipeList( $s );
1126 * Gets the h1 element with the page title.
1129 function pageTitle() {
1131 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1135 function pageSubtitle() {
1138 $sub = $wgOut->getSubtitle();
1140 global $wgExtraSubtitle;
1141 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1143 $subpages = $this->subPageSubtitle();
1144 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1145 $s = "<p class='subtitle'>{$sub}</p>\n";
1149 function subPageSubtitle() {
1151 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1156 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1157 $ptext = $this->mTitle
->getPrefixedText();
1158 if( preg_match( '/\//', $ptext ) ) {
1159 $links = explode( '/', $ptext );
1160 array_pop( $links );
1164 foreach( $links as $link ) {
1165 $growinglink .= $link;
1167 $linkObj = Title
::newFromText( $growinglink );
1168 if( is_object( $linkObj ) && $linkObj->exists() ) {
1169 $getlink = $this->link(
1171 htmlspecialchars( $display ),
1174 array( 'known', 'noclasses' )
1178 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1180 $subpages .= '< ';
1182 $subpages .= $getlink;
1187 $growinglink .= '/';
1195 * Returns true if the IP should be shown in the header
1197 function showIPinHeader() {
1198 global $wgShowIPinHeader;
1199 return $wgShowIPinHeader && session_id() != '';
1202 function nameAndLogin() {
1203 global $wgUser, $wgLang, $wgContLang;
1205 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1208 if ( $wgUser->isAnon() ) {
1209 if( $this->showIPinHeader() ) {
1212 $talkLink = $this->link( $wgUser->getTalkPage(),
1213 $wgLang->getNsText( NS_TALK
) );
1215 $ret .= "$name ($talkLink)";
1217 $ret .= wfMsg( 'notloggedin' );
1220 $returnTo = $this->mTitle
->getPrefixedDBkey();
1222 if ( $logoutPage != $returnTo ) {
1223 $query['returnto'] = $returnTo;
1226 $loginlink = $wgUser->isAllowed( 'createaccount' )
1227 ?
'nav-login-createaccount'
1229 $ret .= "\n<br />" . $this->link(
1230 SpecialPage
::getTitleFor( 'Userlogin' ),
1231 wfMsg( $loginlink ), array(), $query
1234 $returnTo = $this->mTitle
->getPrefixedDBkey();
1235 $talkLink = $this->link( $wgUser->getTalkPage(),
1236 $wgLang->getNsText( NS_TALK
) );
1238 $ret .= $this->link( $wgUser->getUserPage(),
1239 htmlspecialchars( $wgUser->getName() ) );
1240 $ret .= " ($talkLink)<br />";
1241 $ret .= $wgLang->pipeList( array(
1243 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1244 array(), array( 'returnto' => $returnTo )
1246 $this->specialLink( 'preferences' ),
1249 $ret = $wgLang->pipeList( array(
1252 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1260 function getSearchLink() {
1261 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1262 return $searchPage->getLocalURL();
1265 function escapeSearchLink() {
1266 return htmlspecialchars( $this->getSearchLink() );
1269 function searchForm() {
1270 global $wgRequest, $wgUseTwoButtonsSearchForm;
1271 $search = $wgRequest->getText( 'search' );
1273 $s = '<form id="searchform' . $this->searchboxes
. '" name="search" class="inline" method="post" action="'
1274 . $this->escapeSearchLink() . "\">\n"
1275 . '<input type="text" id="searchInput' . $this->searchboxes
. '" name="search" size="19" value="'
1276 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1277 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1279 if( $wgUseTwoButtonsSearchForm ) {
1280 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1282 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1287 // Ensure unique id's for search boxes made after the first
1288 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1293 function topLinks() {
1297 $this->mainPageLink(),
1298 $this->specialLink( 'recentchanges' )
1301 if ( $wgOut->isArticleRelated() ) {
1302 $s[] = $this->editThisPage();
1303 $s[] = $this->historyLink();
1305 # Many people don't like this dropdown box
1306 #$s[] = $this->specialPagesList();
1308 if( $this->variantLinks() ) {
1309 $s[] = $this->variantLinks();
1312 if( $this->extensionTabLinks() ) {
1313 $s[] = $this->extensionTabLinks();
1316 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1317 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1321 * Compatibility for extensions adding functionality through tabs.
1322 * Eventually these old skins should be replaced with SkinTemplate-based
1326 function extensionTabLinks() {
1330 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1331 foreach( $tabs as $tab ) {
1332 $s[] = Xml
::element( 'a',
1333 array( 'href' => $tab['href'] ),
1340 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1341 $out .= $wgLang->pipeList( $s );
1348 * Language/charset variant links for classic-style skins
1351 function variantLinks() {
1353 /* show links to different language variants */
1354 global $wgDisableLangConversion, $wgLang, $wgContLang;
1355 $variants = $wgContLang->getVariants();
1356 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1357 foreach( $variants as $code ) {
1358 $varname = $wgContLang->getVariantname( $code );
1359 if( $varname == 'disable' ) {
1362 $s = $wgLang->pipeList( array(
1364 '<a href="' . $this->mTitle
->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1371 function bottomLinks() {
1372 global $wgOut, $wgUser, $wgUseTrackbacks;
1373 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1376 if ( $wgOut->isArticleRelated() ) {
1377 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1378 if ( $wgUser->isLoggedIn() ) {
1379 $element[] = $this->watchThisPage();
1381 $element[] = $this->talkLink();
1382 $element[] = $this->historyLink();
1383 $element[] = $this->whatLinksHere();
1384 $element[] = $this->watchPageLinksLink();
1386 if( $wgUseTrackbacks ) {
1387 $element[] = $this->trackbackLink();
1391 $this->mTitle
->getNamespace() == NS_USER ||
1392 $this->mTitle
->getNamespace() == NS_USER_TALK
1395 $id = User
::idFromName( $this->mTitle
->getText() );
1396 $ip = User
::isIP( $this->mTitle
->getText() );
1398 # Both anons and non-anons have contributions list
1400 $element[] = $this->userContribsLink();
1402 if( $this->showEmailUser( $id ) ) {
1403 $element[] = $this->emailUserLink();
1407 $s = implode( $element, $sep );
1409 if ( $this->mTitle
->getArticleId() ) {
1411 // Delete/protect/move links for privileged users
1412 if( $wgUser->isAllowed( 'delete' ) ) {
1413 $s .= $this->deleteThisPage();
1415 if( $wgUser->isAllowed( 'protect' ) ) {
1416 $s .= $sep . $this->protectThisPage();
1418 if( $wgUser->isAllowed( 'move' ) ) {
1419 $s .= $sep . $this->moveThisPage();
1422 $s .= "<br />\n" . $this->otherLanguages();
1428 function pageStats() {
1429 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1430 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1432 $oldid = $wgRequest->getVal( 'oldid' );
1433 $diff = $wgRequest->getVal( 'diff' );
1434 if ( !$wgOut->isArticle() ) {
1437 if( !$wgArticle instanceof Article
) {
1440 if ( isset( $oldid ) ||
isset( $diff ) ) {
1443 if ( 0 == $wgArticle->getID() ) {
1448 if ( !$wgDisableCounters ) {
1449 $count = $wgLang->formatNum( $wgArticle->getCount() );
1451 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1455 if( $wgMaxCredits != 0 ) {
1456 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1458 $s .= $this->lastModified();
1461 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1462 $dbr = wfGetDB( DB_SLAVE
);
1463 $res = $dbr->select(
1465 array( 'COUNT(*) AS n' ),
1467 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ),
1468 'wl_namespace' => $this->mTitle
->getNamespace()
1472 $x = $dbr->fetchObject( $res );
1474 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1475 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1479 return $s . ' ' . $this->getCopyright();
1482 function getCopyright( $type = 'detect' ) {
1483 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1485 if ( $type == 'detect' ) {
1486 $diff = $wgRequest->getVal( 'diff' );
1487 $isCur = $wgArticle && $wgArticle->isCurrent();
1488 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1495 if ( $type == 'history' ) {
1496 $msg = 'history_copyright';
1502 if( $wgRightsPage ) {
1503 $title = Title
::newFromText( $wgRightsPage );
1504 $link = $this->linkKnown( $title, $wgRightsText );
1505 } elseif( $wgRightsUrl ) {
1506 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1507 } elseif( $wgRightsText ) {
1508 $link = $wgRightsText;
1513 // Allow for site and per-namespace customization of copyright notice.
1514 if( isset( $wgArticle ) ) {
1515 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1518 $out .= wfMsgForContent( $msg, $link );
1522 function getCopyrightIcon() {
1523 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1525 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1526 $out = $wgCopyrightIcon;
1527 } elseif ( $wgRightsIcon ) {
1528 $icon = htmlspecialchars( $wgRightsIcon );
1529 if ( $wgRightsUrl ) {
1530 $url = htmlspecialchars( $wgRightsUrl );
1531 $out .= '<a href="'.$url.'">';
1533 $text = htmlspecialchars( $wgRightsText );
1534 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1535 if ( $wgRightsUrl ) {
1543 * Gets the powered by MediaWiki icon.
1546 function getPoweredBy() {
1547 global $wgStylePath;
1548 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1549 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1553 function lastModified() {
1554 global $wgLang, $wgArticle;
1555 if( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest() ) {
1556 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1558 $timestamp = $wgArticle->getTimestamp();
1561 $d = $wgLang->date( $timestamp, true );
1562 $t = $wgLang->time( $timestamp, true );
1563 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1567 if ( wfGetLB()->getLaggedSlaveMode() ) {
1568 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1573 function logoText( $align = '' ) {
1574 if ( $align != '' ) {
1575 $a = " align='{$align}'";
1580 $mp = wfMsg( 'mainpage' );
1581 $mptitle = Title
::newMainPage();
1582 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1584 $logourl = $this->getLogo();
1585 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1590 * Show a drop-down box of special pages
1592 function specialPagesList() {
1593 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1594 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1595 foreach ( $pages as $name => $page ) {
1596 $pages[$name] = $page->getDescription();
1599 $go = wfMsg( 'go' );
1600 $sp = wfMsg( 'specialpages' );
1601 $spp = $wgContLang->specialPage( 'Specialpages' );
1603 $s = '<form id="specialpages" method="get" ' .
1604 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1605 $s .= "<select name=\"wpDropdown\">\n";
1606 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1609 foreach ( $pages as $name => $desc ) {
1610 $p = $wgContLang->specialPage( $name );
1611 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1613 $s .= "</select>\n";
1614 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1620 * Gets the link to the wiki's main page.
1623 function mainPageLink() {
1625 Title
::newMainPage(),
1626 wfMsg( 'mainpage' ),
1629 array( 'known', 'noclasses' )
1634 private function footerLink( $desc, $page ) {
1635 // if the link description has been set to "-" in the default language,
1636 if ( wfMsgForContent( $desc ) == '-') {
1637 // then it is disabled, for all languages.
1640 // Otherwise, we display the link for the user, described in their
1641 // language (which may or may not be the same as the default language),
1642 // but we make the link target be the one site-wide page.
1643 $title = Title
::newFromText( wfMsgForContent( $page ) );
1644 return $this->linkKnown(
1646 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1652 * Gets the link to the wiki's privacy policy page.
1654 function privacyLink() {
1655 return $this->footerLink( 'privacy', 'privacypage' );
1659 * Gets the link to the wiki's about page.
1661 function aboutLink() {
1662 return $this->footerLink( 'aboutsite', 'aboutpage' );
1666 * Gets the link to the wiki's general disclaimers page.
1668 function disclaimerLink() {
1669 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1672 function editThisPage() {
1675 if ( !$wgOut->isArticleRelated() ) {
1676 $s = wfMsg( 'protectedpage' );
1678 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1679 $t = wfMsg( 'editthispage' );
1680 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1681 $t = wfMsg( 'create-this-page' );
1683 $t = wfMsg( 'viewsource' );
1690 $this->editUrlOptions(),
1691 array( 'known', 'noclasses' )
1698 * Return URL options for the 'edit page' link.
1699 * This may include an 'oldid' specifier, if the current page view is such.
1704 function editUrlOptions() {
1707 $options = array( 'action' => 'edit' );
1709 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1710 $options['oldid'] = intval( $this->mRevisionId
);
1716 function deleteThisPage() {
1717 global $wgUser, $wgRequest;
1719 $diff = $wgRequest->getVal( 'diff' );
1720 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1721 $t = wfMsg( 'deletethispage' );
1727 array( 'action' => 'delete' ),
1728 array( 'known', 'noclasses' )
1736 function protectThisPage() {
1737 global $wgUser, $wgRequest;
1739 $diff = $wgRequest->getVal( 'diff' );
1740 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1741 if ( $this->mTitle
->isProtected() ) {
1742 $text = wfMsg( 'unprotectthispage' );
1743 $query = array( 'action' => 'unprotect' );
1745 $text = wfMsg( 'protectthispage' );
1746 $query = array( 'action' => 'protect' );
1754 array( 'known', 'noclasses' )
1762 function watchThisPage() {
1764 ++
$this->mWatchLinkNum
;
1766 if ( $wgOut->isArticleRelated() ) {
1767 if ( $this->mTitle
->userIsWatching() ) {
1768 $text = wfMsg( 'unwatchthispage' );
1769 $query = array( 'action' => 'unwatch' );
1770 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1772 $text = wfMsg( 'watchthispage' );
1773 $query = array( 'action' => 'watch' );
1774 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1780 array( 'id' => $id ),
1782 array( 'known', 'noclasses' )
1785 $s = wfMsg( 'notanarticle' );
1790 function moveThisPage() {
1791 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1793 SpecialPage
::getTitleFor( 'Movepage' ),
1794 wfMsg( 'movethispage' ),
1796 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1797 array( 'known', 'noclasses' )
1800 // no message if page is protected - would be redundant
1805 function historyLink() {
1808 wfMsgHtml( 'history' ),
1809 array( 'rel' => 'archives' ),
1810 array( 'action' => 'history' )
1814 function whatLinksHere() {
1816 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1817 wfMsgHtml( 'whatlinkshere' ),
1820 array( 'known', 'noclasses' )
1824 function userContribsLink() {
1826 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1827 wfMsgHtml( 'contributions' ),
1830 array( 'known', 'noclasses' )
1834 function showEmailUser( $id ) {
1836 $targetUser = User
::newFromId( $id );
1837 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1838 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1841 function emailUserLink() {
1843 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1844 wfMsg( 'emailuser' ),
1847 array( 'known', 'noclasses' )
1851 function watchPageLinksLink() {
1853 if ( !$wgOut->isArticleRelated() ) {
1854 return '(' . wfMsg( 'notanarticle' ) . ')';
1857 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1858 wfMsg( 'recentchangeslinked-toolbox' ),
1861 array( 'known', 'noclasses' )
1866 function trackbackLink() {
1867 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1868 . wfMsg( 'trackbacklink' ) . '</a>';
1871 function otherLanguages() {
1872 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1874 if ( $wgHideInterlanguageLinks ) {
1878 $a = $wgOut->getLanguageLinks();
1879 if ( 0 == count( $a ) ) {
1883 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1885 if( $wgContLang->isRTL() ) {
1886 $s .= '<span dir="LTR">';
1888 foreach( $a as $l ) {
1890 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1894 $nt = Title
::newFromText( $l );
1895 $url = $nt->escapeFullURL();
1896 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1898 if ( $text == '' ) {
1901 $style = $this->getExternalLinkAttributes();
1902 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1904 if( $wgContLang->isRTL() ) {
1910 function talkLink() {
1911 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1912 # No discussion links for special pages
1916 $linkOptions = array();
1918 if( $this->mTitle
->isTalkPage() ) {
1919 $link = $this->mTitle
->getSubjectPage();
1920 switch( $link->getNamespace() ) {
1922 $text = wfMsg( 'articlepage' );
1925 $text = wfMsg( 'userpage' );
1928 $text = wfMsg( 'projectpage' );
1931 $text = wfMsg( 'imagepage' );
1932 # Make link known if image exists, even if the desc. page doesn't.
1933 if( wfFindFile( $link ) )
1934 $linkOptions[] = 'known';
1937 $text = wfMsg( 'mediawikipage' );
1940 $text = wfMsg( 'templatepage' );
1943 $text = wfMsg( 'viewhelppage' );
1946 $text = wfMsg( 'categorypage' );
1949 $text = wfMsg( 'articlepage' );
1952 $link = $this->mTitle
->getTalkPage();
1953 $text = wfMsg( 'talkpage' );
1956 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1961 function commentLink() {
1964 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1968 # __NEWSECTIONLINK___ changes behaviour here
1969 # If it is present, the link points to this page, otherwise
1970 # it points to the talk page
1971 if( $this->mTitle
->isTalkPage() ) {
1972 $title = $this->mTitle
;
1973 } elseif( $wgOut->showNewSectionLink() ) {
1974 $title = $this->mTitle
;
1976 $title = $this->mTitle
->getTalkPage();
1981 wfMsg( 'postcomment' ),
1987 array( 'known', 'noclasses' )
1991 /* these are used extensively in SkinTemplate, but also some other places */
1992 static function makeMainPageUrl( $urlaction = '' ) {
1993 $title = Title
::newMainPage();
1994 self
::checkTitle( $title, '' );
1995 return $title->getLocalURL( $urlaction );
1998 static function makeSpecialUrl( $name, $urlaction = '' ) {
1999 $title = SpecialPage
::getTitleFor( $name );
2000 return $title->getLocalURL( $urlaction );
2003 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2004 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
2005 return $title->getLocalURL( $urlaction );
2008 static function makeI18nUrl( $name, $urlaction = '' ) {
2009 $title = Title
::newFromText( wfMsgForContent( $name ) );
2010 self
::checkTitle( $title, $name );
2011 return $title->getLocalURL( $urlaction );
2014 static function makeUrl( $name, $urlaction = '' ) {
2015 $title = Title
::newFromText( $name );
2016 self
::checkTitle( $title, $name );
2017 return $title->getLocalURL( $urlaction );
2021 * If url string starts with http, consider as external URL, else
2024 static function makeInternalOrExternalUrl( $name ) {
2025 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2028 return self
::makeUrl( $name );
2032 # this can be passed the NS number as defined in Language.php
2033 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2034 $title = Title
::makeTitleSafe( $namespace, $name );
2035 self
::checkTitle( $title, $name );
2036 return $title->getLocalURL( $urlaction );
2039 /* these return an array with the 'href' and boolean 'exists' */
2040 static function makeUrlDetails( $name, $urlaction = '' ) {
2041 $title = Title
::newFromText( $name );
2042 self
::checkTitle( $title, $name );
2044 'href' => $title->getLocalURL( $urlaction ),
2045 'exists' => $title->getArticleID() != 0 ?
true : false
2050 * Make URL details where the article exists (or at least it's convenient to think so)
2052 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2053 $title = Title
::newFromText( $name );
2054 self
::checkTitle( $title, $name );
2056 'href' => $title->getLocalURL( $urlaction ),
2061 # make sure we have some title to operate on
2062 static function checkTitle( &$title, $name ) {
2063 if( !is_object( $title ) ) {
2064 $title = Title
::newFromText( $name );
2065 if( !is_object( $title ) ) {
2066 $title = Title
::newFromText( '--error: link target missing--' );
2072 * Build an array that represents the sidebar(s), the navigation bar among them
2076 function buildSidebar() {
2077 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2079 wfProfileIn( __METHOD__
);
2081 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2083 if ( $wgEnableSidebarCache ) {
2084 $cachedsidebar = $parserMemc->get( $key );
2085 if ( $cachedsidebar ) {
2086 wfProfileOut( __METHOD__
);
2087 return $cachedsidebar;
2092 $this->addToSidebar( $bar, 'sidebar' );
2094 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2095 if ( $wgEnableSidebarCache ) {
2096 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2098 wfProfileOut( __METHOD__
);
2102 * Add content from a sidebar system message
2103 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2105 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2107 * @param &$bar array
2108 * @param $message String
2110 function addToSidebar( &$bar, $message ) {
2111 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2115 * Add content from plain text
2117 * @param &$bar array
2118 * @param $text string
2120 function addToSidebarPlain( &$bar, $text ) {
2121 $lines = explode( "\n", $text );
2123 foreach( $lines as $line ) {
2124 if( strpos( $line, '*' ) !== 0 ) {
2127 if( strpos( $line, '**') !== 0 ) {
2128 $heading = trim( $line, '* ' );
2129 if( !array_key_exists( $heading, $bar ) ) {
2130 $bar[$heading] = array();
2133 if( strpos( $line, '|' ) !== false ) { // sanity check
2134 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2135 $link = wfMsgForContent( $line[0] );
2136 if( $link == '-' ) {
2140 $text = wfMsgExt( $line[1], 'parsemag' );
2141 if( wfEmptyMsg( $line[1], $text ) ) {
2144 if( wfEmptyMsg( $line[0], $link ) ) {
2148 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2151 $title = Title
::newFromText( $link );
2153 $title = $title->fixSpecialName();
2154 $href = $title->getLocalURL();
2156 $href = 'INVALID-TITLE';
2160 $bar[$heading][] = array(
2163 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2174 * Should we include common/wikiprintable.css? Skins that have their own
2175 * print stylesheet should override this and return false. (This is an
2176 * ugly hack to get Monobook to play nicely with
2177 * OutputPage::headElement().)
2181 public function commonPrintStylesheet() {