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 $t Title object 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->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' ) ) {
562 a.new, #quickbar a.new,
563 a.stub, #quickbar a.stub {
566 a.new:after, #quickbar a.new:after {
570 a.stub:after, #quickbar a.stub:after {
576 if( $wgUser->getOption( 'justify' ) ) {
577 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
579 if( !$wgUser->getOption( 'showtoc' ) ) {
580 $s .= "#toc { display: none; }\n";
582 if( !$wgUser->getOption( 'editsection' ) ) {
583 $s .= ".editsection { display: none; }\n";
585 $fontstyle = $wgUser->getOption( 'editfont' );
586 if ( $fontstyle !== 'default' ) {
587 $s .= "textarea { font-family: $fontstyle; }\n";
595 function setupUserCss( OutputPage
$out ) {
596 global $wgRequest, $wgContLang, $wgUser;
597 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
599 wfProfileIn( __METHOD__
);
601 $this->setupSkinUserCss( $out );
605 'maxage' => $wgSquidMaxage,
608 // Add any extension CSS
609 foreach ( $out->getExtStyle() as $url ) {
610 $out->addStyle( $url );
613 // If we use the site's dynamic CSS, throw that in, too
614 // Per-site custom styles
615 if( $wgUseSiteCss ) {
616 global $wgHandheldStyle;
617 $query = wfArrayToCGI( array(
618 'usemsgcache' => 'yes',
619 'ctype' => 'text/css',
620 'smaxage' => $wgSquidMaxage
622 # Site settings must override extension css! (bug 15025)
623 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
624 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
625 if( $wgHandheldStyle ) {
626 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
628 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
631 global $wgAllowUserCssPrefs;
632 if( $wgAllowUserCssPrefs ){
633 if( $wgUser->isLoggedIn() ) {
634 // Ensure that logged-in users' generated CSS isn't clobbered
635 // by anons' publicly cacheable generated CSS.
636 $siteargs['smaxage'] = '0';
637 $siteargs['ts'] = $wgUser->mTouched
;
639 // Per-user styles based on preferences
640 $siteargs['gen'] = 'css';
641 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
642 $siteargs['useskin'] = $us;
644 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
647 // Per-user custom style pages
648 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
649 $action = $wgRequest->getVal( 'action' );
650 # If we're previewing the CSS page, use it
651 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
652 // @FIXME: properly escape the cdata!
653 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
655 $names = array( 'common', $this->getSkinName() );
656 foreach( $names as $name ) {
657 $out->addStyle( self
::makeUrl(
658 $this->userpage
. '/' . $name . '.css',
659 'action=raw&ctype=text/css' )
665 wfProfileOut( __METHOD__
);
669 * Add skin specific stylesheets
670 * @param $out OutputPage
672 function setupSkinUserCss( OutputPage
$out ) {
673 $out->addStyle( 'common/shared.css' );
674 $out->addStyle( 'common/oldshared.css' );
675 $out->addStyle( $this->getStylesheet() );
676 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
679 function getPageClasses( $title ) {
680 $numeric = 'ns-' . $title->getNamespace();
681 if( $title->getNamespace() == NS_SPECIAL
) {
682 $type = 'ns-special';
683 } elseif( $title->isTalkPage() ) {
686 $type = 'ns-subject';
688 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
689 return "$numeric $type $name";
701 * This will be called immediately after the <body> tag. Split into
702 * two functions to make it easier to subclass.
704 function beforeContent() {
705 return $this->doBeforeContent();
708 function doBeforeContent() {
710 wfProfileIn( __METHOD__
);
713 $qb = $this->qbSetting();
715 $langlinks = $this->otherLanguages();
722 $borderhack = 'class="top"';
725 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
726 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
728 $shove = ( $qb != 0 );
729 $left = ( $qb == 1 ||
$qb == 3 );
730 if( $wgContLang->isRTL() ) {
735 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
736 $this->logoText() . '</td>';
738 $s .= $this->getQuickbarCompensator( $rows );
740 $l = $wgContLang->alignStart();
741 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
743 $s .= $this->topLinks();
744 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
746 $r = $wgContLang->alignEnd();
747 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
748 $s .= $this->nameAndLogin();
749 $s .= "\n<br />" . $this->searchForm() . '</td>';
752 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
755 if ( $shove && !$left ) { # Right
756 $s .= $this->getQuickbarCompensator( $rows );
758 $s .= "</tr>\n</table>\n</div>\n";
759 $s .= "\n<div id='article'>\n";
761 $notice = wfGetSiteNotice();
763 $s .= "\n<div id='siteNotice'>$notice</div>\n";
765 $s .= $this->pageTitle();
766 $s .= $this->pageSubtitle();
767 $s .= $this->getCategories();
768 wfProfileOut( __METHOD__
);
772 function getCategoryLinks() {
773 global $wgOut, $wgUseCategoryBrowser;
774 global $wgContLang, $wgUser;
776 if( count( $wgOut->mCategoryLinks
) == 0 ) {
781 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
783 // Use Unicode bidi embedding override characters,
784 // to make sure links don't smash each other up in ugly ways.
785 $dir = $wgContLang->getDir();
786 $embed = "<span dir='$dir'>";
789 $allCats = $wgOut->getCategoryLinks();
791 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
792 if ( !empty( $allCats['normal'] ) ) {
793 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
795 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
796 $s .= '<div id="mw-normal-catlinks">' .
797 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
798 . $colon . $t . '</div>';
802 if ( isset( $allCats['hidden'] ) ) {
803 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
804 $class ='mw-hidden-cats-user-shown';
805 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
806 $class = 'mw-hidden-cats-ns-shown';
808 $class = 'mw-hidden-cats-hidden';
810 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
811 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
812 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
816 # optional 'dmoz-like' category browser. Will be shown under the list
817 # of categories an article belong to
818 if( $wgUseCategoryBrowser ) {
819 $s .= '<br /><hr />';
821 # get a big array of the parents tree
822 $parenttree = $this->mTitle
->getParentCategoryTree();
823 # Skin object passed by reference cause it can not be
824 # accessed under the method subfunction drawCategoryBrowser
825 $tempout = explode( "\n", Skin
::drawCategoryBrowser( $parenttree, $this ) );
826 # Clean out bogus first entry and sort them
827 unset( $tempout[0] );
829 # Output one per line
830 $s .= implode( "<br />\n", $tempout );
837 * Render the array as a serie of links.
838 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
839 * @param &skin Object: skin passed by reference
840 * @return String separated by >, terminate with "\n"
842 function drawCategoryBrowser( $tree, &$skin ) {
844 foreach( $tree as $element => $parent ) {
845 if( empty( $parent ) ) {
846 # element start a new list
849 # grab the others elements
850 $return .= Skin
::drawCategoryBrowser( $parent, $skin ) . ' > ';
852 # add our current element to the list
853 $eltitle = Title
::newFromText( $element );
854 $return .= $skin->link( $eltitle, $eltitle->getText() );
859 function getCategories() {
860 $catlinks = $this->getCategoryLinks();
862 $classes = 'catlinks';
864 // Check what we're showing
865 global $wgOut, $wgUser;
866 $allCats = $wgOut->getCategoryLinks();
867 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
868 $this->mTitle
->getNamespace() == NS_CATEGORY
;
870 if( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
871 $classes .= ' catlinks-allhidden';
874 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
877 function getQuickbarCompensator( $rows = 1 ) {
878 return "<td width='152' rowspan='{$rows}'> </td>";
882 * This runs a hook to allow extensions placing their stuff after content
883 * and article metadata (e.g. categories).
884 * Note: This function has nothing to do with afterContent().
886 * This hook is placed here in order to allow using the same hook for all
887 * skins, both the SkinTemplate based ones and the older ones, which directly
888 * use this class to get their data.
890 * The output of this function gets processed in SkinTemplate::outputPage() for
891 * the SkinTemplate based skins, all other skins should directly echo it.
893 * Returns an empty string by default, if not changed by any hook function.
895 protected function afterContentHook() {
898 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ) {
899 // adding just some spaces shouldn't toggle the output
900 // of the whole <div/>, so we use trim() here
901 if( trim( $data ) != '' ) {
902 // Doing this here instead of in the skins to
903 // ensure that the div has the same ID in all
905 $data = "<div id='mw-data-after-content'>\n" .
910 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
917 * Generate debug data HTML for displaying at the bottom of the main content
919 * @return String HTML containing debug data, if enabled (otherwise empty).
921 protected function generateDebugHTML() {
922 global $wgShowDebug, $wgOut;
923 if ( $wgShowDebug ) {
924 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
925 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
926 $listInternals . "</ul>\n";
931 private function formatDebugHTML( $debugText ) {
932 $lines = explode( "\n", $debugText );
935 foreach( $lines as $line ) {
937 $display = ltrim( $line );
938 $ident = strlen( $line ) - strlen( $display );
939 $diff = $ident - $curIdent;
941 if ( $display == '' ) {
942 $display = "\xc2\xa0";
945 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
948 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
950 $display = htmlspecialchars( $display );
954 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
955 } elseif ( $diff == 0 ) {
956 $ret .= "</li><li>\n";
958 $ret .= str_repeat( "<ul><li>\n", $diff );
960 $ret .= $display . "\n";
964 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
969 * This gets called shortly before the </body> tag.
970 * @return String HTML to be put before </body>
972 function afterContent() {
973 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
974 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
978 * This gets called shortly before the </body> tag.
979 * @return String HTML-wrapped JS code to be put before </body>
981 function bottomScripts() {
982 $bottomScriptText = "\n" . Html
::inlineScript( 'if (window.runOnloadHook) runOnloadHook();' ) . "\n";
983 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
984 return $bottomScriptText;
987 /** @return string Retrievied from HTML text */
988 function printSource() {
989 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
990 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
993 function printFooter() {
994 return "<p>" . $this->printSource() .
995 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
998 /** overloaded by derived classes */
999 function doAfterContent() {
1000 return '</div></div>';
1003 function pageTitleLinks() {
1004 global $wgOut, $wgUser, $wgRequest, $wgLang;
1006 $oldid = $wgRequest->getVal( 'oldid' );
1007 $diff = $wgRequest->getVal( 'diff' );
1008 $action = $wgRequest->getText( 'action' );
1010 $s[] = $this->printableLink();
1011 $disclaimer = $this->disclaimerLink(); # may be empty
1015 $privacy = $this->privacyLink(); # may be empty too
1020 if ( $wgOut->isArticleRelated() ) {
1021 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1022 $name = $this->mTitle
->getDBkey();
1023 $image = wfFindFile( $this->mTitle
);
1025 $link = htmlspecialchars( $image->getURL() );
1026 $style = $this->getInternalLinkAttributes( $link, $name );
1027 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1031 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1032 $s[] .= $this->link(
1034 wfMsg( 'currentrev' ),
1037 array( 'known', 'noclasses' )
1041 if ( $wgUser->getNewtalk() ) {
1042 # do not show "You have new messages" text when we are viewing our
1044 if( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1046 $wgUser->getTalkPage(),
1047 wfMsgHtml( 'newmessageslink' ),
1049 array( 'redirect' => 'no' ),
1050 array( 'known', 'noclasses' )
1054 $wgUser->getTalkPage(),
1055 wfMsgHtml( 'newmessagesdifflink' ),
1057 array( 'diff' => 'cur' ),
1058 array( 'known', 'noclasses' )
1060 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1062 $wgOut->setSquidMaxage( 0 );
1063 $wgOut->enableClientCache( false );
1067 $undelete = $this->getUndeleteLink();
1068 if( !empty( $undelete ) ) {
1071 return $wgLang->pipeList( $s );
1074 function getUndeleteLink() {
1075 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1077 $action = $wgRequest->getVal( 'action', 'view' );
1079 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1080 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1081 $n = $this->mTitle
->isDeleted();
1083 if ( $wgUser->isAllowed( 'undelete' ) ) {
1084 $msg = 'thisisdeleted';
1086 $msg = 'viewdeleted';
1091 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1092 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1095 array( 'known', 'noclasses' )
1103 function printableLink() {
1104 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1108 if ( !$wgOut->isPrintable() ) {
1109 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1110 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1113 if( $wgOut->isSyndicated() ) {
1114 foreach( $wgFeedClasses as $format => $class ) {
1115 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1116 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1117 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1120 return $wgLang->pipeList( $s );
1124 * Gets the h1 element with the page title.
1127 function pageTitle() {
1129 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1133 function pageSubtitle() {
1136 $sub = $wgOut->getSubtitle();
1138 global $wgExtraSubtitle;
1139 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1141 $subpages = $this->subPageSubtitle();
1142 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1143 $s = "<p class='subtitle'>{$sub}</p>\n";
1147 function subPageSubtitle() {
1149 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1154 if( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1155 $ptext = $this->mTitle
->getPrefixedText();
1156 if( preg_match( '/\//', $ptext ) ) {
1157 $links = explode( '/', $ptext );
1158 array_pop( $links );
1162 foreach( $links as $link ) {
1163 $growinglink .= $link;
1165 $linkObj = Title
::newFromText( $growinglink );
1166 if( is_object( $linkObj ) && $linkObj->exists() ) {
1167 $getlink = $this->link(
1169 htmlspecialchars( $display ),
1172 array( 'known', 'noclasses' )
1176 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1178 $subpages .= '< ';
1180 $subpages .= $getlink;
1185 $growinglink .= '/';
1193 * Returns true if the IP should be shown in the header
1195 function showIPinHeader() {
1196 global $wgShowIPinHeader;
1197 return $wgShowIPinHeader && session_id() != '';
1200 function nameAndLogin() {
1201 global $wgUser, $wgLang, $wgContLang;
1203 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1206 if ( $wgUser->isAnon() ) {
1207 if( $this->showIPinHeader() ) {
1210 $talkLink = $this->link( $wgUser->getTalkPage(),
1211 $wgLang->getNsText( NS_TALK
) );
1213 $ret .= "$name ($talkLink)";
1215 $ret .= wfMsg( 'notloggedin' );
1218 $returnTo = $this->mTitle
->getPrefixedDBkey();
1220 if ( $logoutPage != $returnTo ) {
1221 $query['returnto'] = $returnTo;
1224 $loginlink = $wgUser->isAllowed( 'createaccount' )
1225 ?
'nav-login-createaccount'
1227 $ret .= "\n<br />" . $this->link(
1228 SpecialPage
::getTitleFor( 'Userlogin' ),
1229 wfMsg( $loginlink ), array(), $query
1232 $returnTo = $this->mTitle
->getPrefixedDBkey();
1233 $talkLink = $this->link( $wgUser->getTalkPage(),
1234 $wgLang->getNsText( NS_TALK
) );
1236 $ret .= $this->link( $wgUser->getUserPage(),
1237 htmlspecialchars( $wgUser->getName() ) );
1238 $ret .= " ($talkLink)<br />";
1239 $ret .= $wgLang->pipeList( array(
1241 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1242 array(), array( 'returnto' => $returnTo )
1244 $this->specialLink( 'preferences' ),
1247 $ret = $wgLang->pipeList( array(
1250 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1258 function getSearchLink() {
1259 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1260 return $searchPage->getLocalURL();
1263 function escapeSearchLink() {
1264 return htmlspecialchars( $this->getSearchLink() );
1267 function searchForm() {
1268 global $wgRequest, $wgUseTwoButtonsSearchForm;
1269 $search = $wgRequest->getText( 'search' );
1271 $s = '<form id="searchform' . $this->searchboxes
. '" name="search" class="inline" method="post" action="'
1272 . $this->escapeSearchLink() . "\">\n"
1273 . '<input type="text" id="searchInput' . $this->searchboxes
. '" name="search" size="19" value="'
1274 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1275 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1277 if( $wgUseTwoButtonsSearchForm ) {
1278 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1280 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1285 // Ensure unique id's for search boxes made after the first
1286 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1291 function topLinks() {
1295 $this->mainPageLink(),
1296 $this->specialLink( 'recentchanges' )
1299 if ( $wgOut->isArticleRelated() ) {
1300 $s[] = $this->editThisPage();
1301 $s[] = $this->historyLink();
1303 # Many people don't like this dropdown box
1304 #$s[] = $this->specialPagesList();
1306 if( $this->variantLinks() ) {
1307 $s[] = $this->variantLinks();
1310 if( $this->extensionTabLinks() ) {
1311 $s[] = $this->extensionTabLinks();
1314 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1315 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1319 * Compatibility for extensions adding functionality through tabs.
1320 * Eventually these old skins should be replaced with SkinTemplate-based
1324 function extensionTabLinks() {
1328 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1329 foreach( $tabs as $tab ) {
1330 $s[] = Xml
::element( 'a',
1331 array( 'href' => $tab['href'] ),
1338 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1339 $out .= $wgLang->pipeList( $s );
1346 * Language/charset variant links for classic-style skins
1349 function variantLinks() {
1351 /* show links to different language variants */
1352 global $wgDisableLangConversion, $wgLang, $wgContLang;
1353 $variants = $wgContLang->getVariants();
1354 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1355 foreach( $variants as $code ) {
1356 $varname = $wgContLang->getVariantname( $code );
1357 if( $varname == 'disable' ) {
1360 $s = $wgLang->pipeList( array(
1362 '<a href="' . $this->mTitle
->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1369 function bottomLinks() {
1370 global $wgOut, $wgUser, $wgUseTrackbacks;
1371 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1374 if ( $wgOut->isArticleRelated() ) {
1375 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1376 if ( $wgUser->isLoggedIn() ) {
1377 $element[] = $this->watchThisPage();
1379 $element[] = $this->talkLink();
1380 $element[] = $this->historyLink();
1381 $element[] = $this->whatLinksHere();
1382 $element[] = $this->watchPageLinksLink();
1384 if( $wgUseTrackbacks ) {
1385 $element[] = $this->trackbackLink();
1389 $this->mTitle
->getNamespace() == NS_USER ||
1390 $this->mTitle
->getNamespace() == NS_USER_TALK
1393 $id = User
::idFromName( $this->mTitle
->getText() );
1394 $ip = User
::isIP( $this->mTitle
->getText() );
1396 # Both anons and non-anons have contributions list
1398 $element[] = $this->userContribsLink();
1400 if( $this->showEmailUser( $id ) ) {
1401 $element[] = $this->emailUserLink();
1405 $s = implode( $element, $sep );
1407 if ( $this->mTitle
->getArticleId() ) {
1409 // Delete/protect/move links for privileged users
1410 if( $wgUser->isAllowed( 'delete' ) ) {
1411 $s .= $this->deleteThisPage();
1413 if( $wgUser->isAllowed( 'protect' ) ) {
1414 $s .= $sep . $this->protectThisPage();
1416 if( $wgUser->isAllowed( 'move' ) ) {
1417 $s .= $sep . $this->moveThisPage();
1420 $s .= "<br />\n" . $this->otherLanguages();
1426 function pageStats() {
1427 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1428 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1430 $oldid = $wgRequest->getVal( 'oldid' );
1431 $diff = $wgRequest->getVal( 'diff' );
1432 if ( !$wgOut->isArticle() ) {
1435 if( !$wgArticle instanceof Article
) {
1438 if ( isset( $oldid ) ||
isset( $diff ) ) {
1441 if ( 0 == $wgArticle->getID() ) {
1446 if ( !$wgDisableCounters ) {
1447 $count = $wgLang->formatNum( $wgArticle->getCount() );
1449 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1453 if( $wgMaxCredits != 0 ) {
1454 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1456 $s .= $this->lastModified();
1459 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1460 $dbr = wfGetDB( DB_SLAVE
);
1461 $res = $dbr->select(
1463 array( 'COUNT(*) AS n' ),
1465 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ),
1466 'wl_namespace' => $this->mTitle
->getNamespace()
1470 $x = $dbr->fetchObject( $res );
1472 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1473 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1477 return $s . ' ' . $this->getCopyright();
1480 function getCopyright( $type = 'detect' ) {
1481 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1483 if ( $type == 'detect' ) {
1484 $diff = $wgRequest->getVal( 'diff' );
1485 $isCur = $wgArticle && $wgArticle->isCurrent();
1486 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1493 if ( $type == 'history' ) {
1494 $msg = 'history_copyright';
1500 if( $wgRightsPage ) {
1501 $title = Title
::newFromText( $wgRightsPage );
1502 $link = $this->linkKnown( $title, $wgRightsText );
1503 } elseif( $wgRightsUrl ) {
1504 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1505 } elseif( $wgRightsText ) {
1506 $link = $wgRightsText;
1511 // Allow for site and per-namespace customization of copyright notice.
1512 if( isset( $wgArticle ) ) {
1513 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1516 $out .= wfMsgForContent( $msg, $link );
1520 function getCopyrightIcon() {
1521 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1523 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1524 $out = $wgCopyrightIcon;
1525 } elseif ( $wgRightsIcon ) {
1526 $icon = htmlspecialchars( $wgRightsIcon );
1527 if ( $wgRightsUrl ) {
1528 $url = htmlspecialchars( $wgRightsUrl );
1529 $out .= '<a href="'.$url.'">';
1531 $text = htmlspecialchars( $wgRightsText );
1532 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1533 if ( $wgRightsUrl ) {
1541 * Gets the powered by MediaWiki icon.
1544 function getPoweredBy() {
1545 global $wgStylePath;
1546 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1547 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1551 function lastModified() {
1552 global $wgLang, $wgArticle;
1553 if( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest() ) {
1554 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1556 $timestamp = $wgArticle->getTimestamp();
1559 $d = $wgLang->date( $timestamp, true );
1560 $t = $wgLang->time( $timestamp, true );
1561 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1565 if ( wfGetLB()->getLaggedSlaveMode() ) {
1566 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1571 function logoText( $align = '' ) {
1572 if ( $align != '' ) {
1573 $a = " align='{$align}'";
1578 $mp = wfMsg( 'mainpage' );
1579 $mptitle = Title
::newMainPage();
1580 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1582 $logourl = $this->getLogo();
1583 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1588 * Show a drop-down box of special pages
1590 function specialPagesList() {
1591 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1592 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1593 foreach ( $pages as $name => $page ) {
1594 $pages[$name] = $page->getDescription();
1597 $go = wfMsg( 'go' );
1598 $sp = wfMsg( 'specialpages' );
1599 $spp = $wgContLang->specialPage( 'Specialpages' );
1601 $s = '<form id="specialpages" method="get" ' .
1602 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1603 $s .= "<select name=\"wpDropdown\">\n";
1604 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1607 foreach ( $pages as $name => $desc ) {
1608 $p = $wgContLang->specialPage( $name );
1609 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1611 $s .= "</select>\n";
1612 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1618 * Gets the link to the wiki's main page.
1621 function mainPageLink() {
1623 Title
::newMainPage(),
1624 wfMsg( 'mainpage' ),
1627 array( 'known', 'noclasses' )
1632 private function footerLink( $desc, $page ) {
1633 // if the link description has been set to "-" in the default language,
1634 if ( wfMsgForContent( $desc ) == '-') {
1635 // then it is disabled, for all languages.
1638 // Otherwise, we display the link for the user, described in their
1639 // language (which may or may not be the same as the default language),
1640 // but we make the link target be the one site-wide page.
1641 $title = Title
::newFromText( wfMsgForContent( $page ) );
1642 return $this->linkKnown(
1644 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1650 * Gets the link to the wiki's privacy policy page.
1652 function privacyLink() {
1653 return $this->footerLink( 'privacy', 'privacypage' );
1657 * Gets the link to the wiki's about page.
1659 function aboutLink() {
1660 return $this->footerLink( 'aboutsite', 'aboutpage' );
1664 * Gets the link to the wiki's general disclaimers page.
1666 function disclaimerLink() {
1667 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1670 function editThisPage() {
1673 if ( !$wgOut->isArticleRelated() ) {
1674 $s = wfMsg( 'protectedpage' );
1676 if( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1677 $t = wfMsg( 'editthispage' );
1678 } elseif( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1679 $t = wfMsg( 'create-this-page' );
1681 $t = wfMsg( 'viewsource' );
1688 $this->editUrlOptions(),
1689 array( 'known', 'noclasses' )
1696 * Return URL options for the 'edit page' link.
1697 * This may include an 'oldid' specifier, if the current page view is such.
1702 function editUrlOptions() {
1705 $options = array( 'action' => 'edit' );
1707 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1708 $options['oldid'] = intval( $this->mRevisionId
);
1714 function deleteThisPage() {
1715 global $wgUser, $wgRequest;
1717 $diff = $wgRequest->getVal( 'diff' );
1718 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1719 $t = wfMsg( 'deletethispage' );
1725 array( 'action' => 'delete' ),
1726 array( 'known', 'noclasses' )
1734 function protectThisPage() {
1735 global $wgUser, $wgRequest;
1737 $diff = $wgRequest->getVal( 'diff' );
1738 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1739 if ( $this->mTitle
->isProtected() ) {
1740 $text = wfMsg( 'unprotectthispage' );
1741 $query = array( 'action' => 'unprotect' );
1743 $text = wfMsg( 'protectthispage' );
1744 $query = array( 'action' => 'protect' );
1752 array( 'known', 'noclasses' )
1760 function watchThisPage() {
1762 ++
$this->mWatchLinkNum
;
1764 if ( $wgOut->isArticleRelated() ) {
1765 if ( $this->mTitle
->userIsWatching() ) {
1766 $text = wfMsg( 'unwatchthispage' );
1767 $query = array( 'action' => 'unwatch' );
1768 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1770 $text = wfMsg( 'watchthispage' );
1771 $query = array( 'action' => 'watch' );
1772 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1778 array( 'id' => $id ),
1780 array( 'known', 'noclasses' )
1783 $s = wfMsg( 'notanarticle' );
1788 function moveThisPage() {
1789 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1791 SpecialPage
::getTitleFor( 'Movepage' ),
1792 wfMsg( 'movethispage' ),
1794 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1795 array( 'known', 'noclasses' )
1798 // no message if page is protected - would be redundant
1803 function historyLink() {
1806 wfMsgHtml( 'history' ),
1807 array( 'rel' => 'archives' ),
1808 array( 'action' => 'history' )
1812 function whatLinksHere() {
1814 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1815 wfMsgHtml( 'whatlinkshere' ),
1818 array( 'known', 'noclasses' )
1822 function userContribsLink() {
1824 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1825 wfMsgHtml( 'contributions' ),
1828 array( 'known', 'noclasses' )
1832 function showEmailUser( $id ) {
1834 $targetUser = User
::newFromId( $id );
1835 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1836 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1839 function emailUserLink() {
1841 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1842 wfMsg( 'emailuser' ),
1845 array( 'known', 'noclasses' )
1849 function watchPageLinksLink() {
1851 if ( !$wgOut->isArticleRelated() ) {
1852 return '(' . wfMsg( 'notanarticle' ) . ')';
1855 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
1856 wfMsg( 'recentchangeslinked-toolbox' ),
1859 array( 'known', 'noclasses' )
1864 function trackbackLink() {
1865 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
1866 . wfMsg( 'trackbacklink' ) . '</a>';
1869 function otherLanguages() {
1870 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1872 if ( $wgHideInterlanguageLinks ) {
1876 $a = $wgOut->getLanguageLinks();
1877 if ( 0 == count( $a ) ) {
1881 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1883 if( $wgContLang->isRTL() ) {
1884 $s .= '<span dir="LTR">';
1886 foreach( $a as $l ) {
1888 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1892 $nt = Title
::newFromText( $l );
1893 $url = $nt->escapeFullURL();
1894 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1896 if ( $text == '' ) {
1899 $style = $this->getExternalLinkAttributes();
1900 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1902 if( $wgContLang->isRTL() ) {
1908 function talkLink() {
1909 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
1910 # No discussion links for special pages
1914 $linkOptions = array();
1916 if( $this->mTitle
->isTalkPage() ) {
1917 $link = $this->mTitle
->getSubjectPage();
1918 switch( $link->getNamespace() ) {
1920 $text = wfMsg( 'articlepage' );
1923 $text = wfMsg( 'userpage' );
1926 $text = wfMsg( 'projectpage' );
1929 $text = wfMsg( 'imagepage' );
1930 # Make link known if image exists, even if the desc. page doesn't.
1931 if( wfFindFile( $link ) )
1932 $linkOptions[] = 'known';
1935 $text = wfMsg( 'mediawikipage' );
1938 $text = wfMsg( 'templatepage' );
1941 $text = wfMsg( 'viewhelppage' );
1944 $text = wfMsg( 'categorypage' );
1947 $text = wfMsg( 'articlepage' );
1950 $link = $this->mTitle
->getTalkPage();
1951 $text = wfMsg( 'talkpage' );
1954 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1959 function commentLink() {
1962 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
1966 # __NEWSECTIONLINK___ changes behaviour here
1967 # If it is present, the link points to this page, otherwise
1968 # it points to the talk page
1969 if( $this->mTitle
->isTalkPage() ) {
1970 $title = $this->mTitle
;
1971 } elseif( $wgOut->showNewSectionLink() ) {
1972 $title = $this->mTitle
;
1974 $title = $this->mTitle
->getTalkPage();
1979 wfMsg( 'postcomment' ),
1985 array( 'known', 'noclasses' )
1989 function uploadLink() {
1990 global $wgUploadNavigationUrl;
1992 if( $wgUploadNavigationUrl ) {
1993 # Using an empty class attribute to avoid automatic setting of "external" class
1994 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '') );
1997 SpecialPage
::getTitleFor('Upload'),
1998 wfMsgHtml( 'upload' ),
2001 array( 'known', 'noclasses' )
2006 /* these are used extensively in SkinTemplate, but also some other places */
2007 static function makeMainPageUrl( $urlaction = '' ) {
2008 $title = Title
::newMainPage();
2009 self
::checkTitle( $title, '' );
2010 return $title->getLocalURL( $urlaction );
2013 static function makeSpecialUrl( $name, $urlaction = '' ) {
2014 $title = SpecialPage
::getTitleFor( $name );
2015 return $title->getLocalURL( $urlaction );
2018 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2019 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
2020 return $title->getLocalURL( $urlaction );
2023 static function makeI18nUrl( $name, $urlaction = '' ) {
2024 $title = Title
::newFromText( wfMsgForContent( $name ) );
2025 self
::checkTitle( $title, $name );
2026 return $title->getLocalURL( $urlaction );
2029 static function makeUrl( $name, $urlaction = '' ) {
2030 $title = Title
::newFromText( $name );
2031 self
::checkTitle( $title, $name );
2032 return $title->getLocalURL( $urlaction );
2036 * If url string starts with http, consider as external URL, else
2039 static function makeInternalOrExternalUrl( $name ) {
2040 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2043 return self
::makeUrl( $name );
2047 # this can be passed the NS number as defined in Language.php
2048 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2049 $title = Title
::makeTitleSafe( $namespace, $name );
2050 self
::checkTitle( $title, $name );
2051 return $title->getLocalURL( $urlaction );
2054 /* these return an array with the 'href' and boolean 'exists' */
2055 static function makeUrlDetails( $name, $urlaction = '' ) {
2056 $title = Title
::newFromText( $name );
2057 self
::checkTitle( $title, $name );
2059 'href' => $title->getLocalURL( $urlaction ),
2060 'exists' => $title->getArticleID() != 0 ?
true : false
2065 * Make URL details where the article exists (or at least it's convenient to think so)
2067 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2068 $title = Title
::newFromText( $name );
2069 self
::checkTitle( $title, $name );
2071 'href' => $title->getLocalURL( $urlaction ),
2076 # make sure we have some title to operate on
2077 static function checkTitle( &$title, $name ) {
2078 if( !is_object( $title ) ) {
2079 $title = Title
::newFromText( $name );
2080 if( !is_object( $title ) ) {
2081 $title = Title
::newFromText( '--error: link target missing--' );
2087 * Build an array that represents the sidebar(s), the navigation bar among them
2091 function buildSidebar() {
2092 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2094 wfProfileIn( __METHOD__
);
2096 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2098 if ( $wgEnableSidebarCache ) {
2099 $cachedsidebar = $parserMemc->get( $key );
2100 if ( $cachedsidebar ) {
2101 wfProfileOut( __METHOD__
);
2102 return $cachedsidebar;
2107 $this->addToSidebar( $bar, wfMsgForContentNoTrans( 'sidebar' ) );
2109 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2110 if ( $wgEnableSidebarCache ) {
2111 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2113 wfProfileOut( __METHOD__
);
2118 * Add content to the sidebar from text
2120 * @param &$bar array
2121 * @param $text string
2125 function addToSidebar( &$bar, $text ) {
2126 $lines = explode( "\n", $text );
2128 foreach( $lines as $line ) {
2129 if( strpos( $line, '*' ) !== 0 ) {
2132 if( strpos( $line, '**') !== 0 ) {
2133 $heading = trim( $line, '* ' );
2134 if( !array_key_exists( $heading, $bar ) ) {
2135 $bar[$heading] = array();
2138 if( strpos( $line, '|' ) !== false ) { // sanity check
2139 global $wgMessageCache;
2140 $line = $wgMessageCache->transform( $line );
2142 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2143 $link = wfMsgForContent( $line[0] );
2144 if( $link == '-' ) {
2148 $text = wfMsgExt( $line[1], 'parsemag' );
2149 if( wfEmptyMsg( $line[1], $text ) ) {
2152 if( wfEmptyMsg( $line[0], $link ) ) {
2156 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2159 $title = Title
::newFromText( $link );
2161 $title = $title->fixSpecialName();
2162 $href = $title->getLocalURL();
2164 $href = 'INVALID-TITLE';
2168 $bar[$heading][] = array(
2171 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2182 * Should we include common/wikiprintable.css? Skins that have their own
2183 * print stylesheet should override this and return false. (This is an
2184 * ugly hack to get Monobook to play nicely with
2185 * OutputPage::headElement().)
2189 public function commonPrintStylesheet() {
2194 * Gets new talk page messages for the current user.
2195 * @return MediaWiki message or if no new talk page messages, nothing
2197 function getNewtalks() {
2198 global $wgUser, $wgOut;
2199 $newtalks = $wgUser->getNewMessageLinks();
2202 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2203 $userTitle = $this->mUser
->getUserPage();
2204 $userTalkTitle = $userTitle->getTalkPage();
2206 if( !$userTalkTitle->equals( $this->mTitle
) ) {
2207 $newMessagesLink = $this->link(
2209 wfMsgHtml( 'newmessageslink' ),
2211 array( 'redirect' => 'no' ),
2212 array( 'known', 'noclasses' )
2215 $newMessagesDiffLink = $this->link(
2217 wfMsgHtml( 'newmessagesdifflink' ),
2219 array( 'diff' => 'cur' ),
2220 array( 'known', 'noclasses' )
2224 'youhavenewmessages',
2226 $newMessagesDiffLink
2228 # Disable Squid cache
2229 $wgOut->setSquidMaxage( 0 );
2231 } elseif( count( $newtalks ) ) {
2232 // _>" " for BC <= 1.16
2233 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2235 foreach( $newtalks as $newtalk ) {
2236 $msgs[] = Xml
::element(
2238 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2241 $parts = implode( $sep, $msgs );
2242 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2243 $wgOut->setSquidMaxage( 0 );