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;
44 if ( !$skinsInitialised ) {
45 # Get a list of available skins
46 # Build using the regular expression '^(.*).php$'
47 # Array keys are all lower case, array value keep the case used by filename
49 wfProfileIn( __METHOD__
. '-init' );
51 global $wgStyleDirectory;
53 $skinDir = dir( $wgStyleDirectory );
55 # while code from www.php.net
56 while ( false !== ( $file = $skinDir->read() ) ) {
57 // Skip non-PHP files, hidden files, and '.dep' includes
60 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
62 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
66 $skinsInitialised = true;
67 wfProfileOut( __METHOD__
. '-init' );
69 return $wgValidSkinNames;
73 * Fetch the list of usable skins in regards to $wgSkipSkins.
74 * Useful for Special:Preferences and other places where you
75 * only want to show skins users _can_ use.
76 * @return array of strings
78 public static function getUsableSkins() {
81 $usableSkins = self
::getSkinNames();
83 foreach ( $wgSkipSkins as $skip ) {
84 unset( $usableSkins[$skip] );
91 * Normalize a skin preference value to a form that can be loaded.
92 * If a skin can't be found, it will fall back to the configured
93 * default (or the old 'Classic' skin if that's broken).
94 * @param $key String: 'monobook', 'standard', etc.
97 static function normalizeKey( $key ) {
98 global $wgDefaultSkin;
100 $skinNames = Skin
::getSkinNames();
103 // Don't return the default immediately;
104 // in a misconfiguration we need to fall back.
105 $key = $wgDefaultSkin;
108 if ( isset( $skinNames[$key] ) ) {
112 // Older versions of the software used a numeric setting
113 // in the user preferences.
120 if ( isset( $fallback[$key] ) ) {
121 $key = $fallback[$key];
124 if ( isset( $skinNames[$key] ) ) {
126 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
127 return $wgDefaultSkin;
134 * Factory method for loading a skin of a given type
135 * @param $key String: 'monobook', 'standard', etc.
138 static function &newFromKey( $key ) {
139 global $wgStyleDirectory;
141 $key = Skin
::normalizeKey( $key );
143 $skinNames = Skin
::getSkinNames();
144 $skinName = $skinNames[$key];
145 $className = 'Skin' . ucfirst( $key );
147 # Grab the skin class and initialise it.
148 if ( !class_exists( $className ) ) {
149 // Preload base classes to work around APC/PHP5 bug
150 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
152 if ( file_exists( $deps ) ) {
153 include_once( $deps );
155 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
157 # Check if we got if not failback to default skin
158 if ( !class_exists( $className ) ) {
159 # DO NOT die if the class isn't found. This breaks maintenance
160 # scripts and can cause a user account to be unrecoverable
161 # except by SQL manipulation if a previously valid skin name
162 # is no longer valid.
163 wfDebug( "Skin class does not exist: $className\n" );
164 $className = 'SkinVector';
165 require_once( "{$wgStyleDirectory}/Vector.php" );
168 $skin = new $className;
172 /** @return string path to the skin stylesheet */
173 function getStylesheet() {
174 return 'common/wikistandard.css';
177 /** @return string skin name */
178 public function getSkinName() {
179 return $this->skinname
;
182 function qbSetting() {
183 global $wgOut, $wgUser;
185 if ( $wgOut->isQuickbarSuppressed() ) {
189 $q = $wgUser->getOption( 'quickbar', 0 );
194 function initPage( OutputPage
$out ) {
195 global $wgFavicon, $wgAppleTouchIcon;
197 wfProfileIn( __METHOD__
);
199 # Generally the order of the favicon and apple-touch-icon links
200 # should not matter, but Konqueror (3.5.9 at least) incorrectly
201 # uses whichever one appears later in the HTML source. Make sure
202 # apple-touch-icon is specified first to avoid this.
203 if ( false !== $wgAppleTouchIcon ) {
204 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
207 if ( false !== $wgFavicon ) {
208 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
211 # OpenSearch description link
212 $out->addLink( array(
214 'type' => 'application/opensearchdescription+xml',
215 'href' => wfScript( 'opensearch_desc' ),
216 'title' => wfMsgForContent( 'opensearch-desc' ),
219 $this->addMetadataLinks( $out );
221 $this->mRevisionId
= $out->mRevisionId
;
223 $this->preloadExistence();
225 wfProfileOut( __METHOD__
);
229 * Preload the existence of three commonly-requested pages in a single query
231 function preloadExistence() {
235 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
238 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
240 } elseif ( $this->mTitle
->isTalkPage() ) {
241 $titles[] = $this->mTitle
->getSubjectPage();
243 $titles[] = $this->mTitle
->getTalkPage();
246 $lb = new LinkBatch( $titles );
251 * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML
253 * @param $out Object: instance of OutputPage
255 function addMetadataLinks( OutputPage
$out ) {
256 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
257 global $wgRightsPage, $wgRightsUrl;
259 if ( $out->isArticleRelated() ) {
260 # note: buggy CC software only reads first "meta" link
261 if ( $wgEnableCreativeCommonsRdf ) {
262 $out->addMetadataLink( array(
263 'title' => 'Creative Commons',
264 'type' => 'application/rdf+xml',
265 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
269 if ( $wgEnableDublinCoreRdf ) {
270 $out->addMetadataLink( array(
271 'title' => 'Dublin Core',
272 'type' => 'application/rdf+xml',
273 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
278 if ( $wgRightsPage ) {
279 $copy = Title
::newFromText( $wgRightsPage );
282 $copyright = $copy->getLocalURL();
286 if ( !$copyright && $wgRightsUrl ) {
287 $copyright = $wgRightsUrl;
291 $out->addLink( array(
292 'rel' => 'copyright',
293 'href' => $copyright )
299 * Set some local variables
301 protected function setMembers() {
303 $this->mUser
= $wgUser;
304 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
305 $this->usercss
= false;
310 * @param $t Title object to use
312 public function setTitle( $t ) {
317 public function getTitle() {
318 return $this->mTitle
;
322 * Outputs the HTML generated by other functions.
323 * @param $out Object: instance of OutputPage
325 function outputPage( OutputPage
$out ) {
326 global $wgDebugComments;
327 wfProfileIn( __METHOD__
);
330 $this->initPage( $out );
332 // See self::afterContentHook() for documentation
333 $afterContent = $this->afterContentHook();
335 $out->out( $out->headElement( $this ) );
337 if ( $wgDebugComments ) {
338 $out->out( "<!-- Wiki debugging output:\n" .
339 $out->mDebugtext
. "-->\n" );
342 $out->out( $this->beforeContent() );
344 $out->out( $out->mBodytext
. "\n" );
346 $out->out( $this->afterContent() );
348 $out->out( $afterContent );
350 $out->out( $this->bottomScripts( $out ) );
352 $out->out( wfReportTime() );
354 $out->out( "\n</body></html>" );
355 wfProfileOut( __METHOD__
);
358 static function makeVariablesScript( $data ) {
360 return Html
::inlineScript( 'mediaWiki.config.set(' . json_encode( $data ) . ');' );
367 * Make a <script> tag containing global variables
368 * @param $skinName string Name of the skin
369 * The odd calling convention is for backwards compatibility
370 * @todo FIXME: Make this not depend on $wgTitle!
372 static function makeGlobalVariablesScript( $skinName ) {
373 if ( is_array( $skinName ) ) {
374 # Weird back-compat stuff.
375 $skinName = $skinName['skinname'];
378 global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
379 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
380 global $wgOut, $wgArticle;
381 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
382 global $wgUseAjax, $wgAjaxWatch;
383 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
384 global $wgRestrictionTypes;
385 global $wgDBname, $wgEnableMWSuggest;
388 $ns = $wgTitle->getNamespace();
389 $nsname = MWNamespace
::exists( $ns ) ? MWNamespace
::getCanonicalName( $ns ) : $wgTitle->getNsText();
390 $separatorTransTable = $wgContLang->separatorTransformTable();
391 $separatorTransTable = $separatorTransTable ?
$separatorTransTable : array();
392 $compactSeparatorTransTable = array(
393 implode( "\t", array_keys( $separatorTransTable ) ),
394 implode( "\t", $separatorTransTable ),
396 $digitTransTable = $wgContLang->digitTransformTable();
397 $digitTransTable = $digitTransTable ?
$digitTransTable : array();
398 $compactDigitTransTable = array(
399 implode( "\t", array_keys( $digitTransTable ) ),
400 implode( "\t", $digitTransTable ),
403 $mainPage = Title
::newMainPage();
406 'stylepath' => $wgStylePath,
407 'wgUrlProtocols' => wfUrlProtocols(),
408 'wgArticlePath' => $wgArticlePath,
409 'wgScriptPath' => $wgScriptPath,
410 'wgScriptExtension' => $wgScriptExtension,
411 'wgScript' => $wgScript,
412 'wgVariantArticlePath' => $wgVariantArticlePath,
413 'wgActionPaths' => (object)$wgActionPaths,
414 'wgServer' => $wgServer,
415 'wgCanonicalNamespace' => $nsname,
416 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
417 SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
418 'wgNamespaceNumber' => $wgTitle->getNamespace(),
419 'wgPageName' => $wgTitle->getPrefixedDBKey(),
420 'wgTitle' => $wgTitle->getText(),
421 'wgAction' => $wgRequest->getText( 'action', 'view' ),
422 'wgArticleId' => $wgTitle->getArticleId(),
423 'wgIsArticle' => $wgOut->isArticle(),
424 'wgUserName' => $wgUser->isAnon() ?
null : $wgUser->getName(),
425 'wgUserGroups' => $wgUser->getEffectiveGroups(),
426 'wgUserLanguage' => $wgLang->getCode(),
427 'wgContentLanguage' => $wgContLang->getCode(),
428 'wgBreakFrames' => $wgBreakFrames,
429 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
430 'wgVersion' => $wgVersion,
431 'wgEnableAPI' => $wgEnableAPI,
432 'wgEnableWriteAPI' => $wgEnableWriteAPI,
433 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
434 'wgDigitTransformTable' => $compactDigitTransTable,
435 'wgMainPageTitle' => $mainPage ?
$mainPage->getPrefixedText() : null,
436 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
437 'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
438 'wgSiteName' => $wgSitename,
439 'wgCategories' => $wgOut->getCategories(),
442 if ( $wgContLang->hasVariants() ) {
443 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
446 // if on upload page output the extension list & js_upload
447 if ( SpecialPage
::resolveAlias( $wgTitle->getDBkey() ) == 'Upload' ) {
448 global $wgFileExtensions;
449 $vars['wgFileExtensions'] = $wgFileExtensions;
452 if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
453 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
454 $vars['wgDBname'] = $wgDBname;
455 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
456 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
459 foreach ( $wgRestrictionTypes as $type ) {
460 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
463 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
464 $msgs = (object)array();
466 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching',
467 'tooltip-ca-watch', 'tooltip-ca-unwatch' ) as $msgName ) {
468 $msgs-> { $msgName . 'Msg' } = wfMsg( $msgName );
470 $vars['wgAjaxWatch'] = $msgs;
473 // Allow extensions to add their custom variables to the global JS variables
474 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
476 return self
::makeVariablesScript( $vars );
480 * To make it harder for someone to slip a user a fake
481 * user-JavaScript or user-CSS preview, a random token
482 * is associated with the login session. If it's not
483 * passed back with the preview request, we won't render
486 * @param $action String: 'edit', 'submit' etc.
489 public function userCanPreview( $action ) {
490 global $wgRequest, $wgUser;
492 if ( $action != 'submit' ) {
495 if ( !$wgRequest->wasPosted() ) {
498 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
501 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
505 return $wgUser->matchEditToken(
506 $wgRequest->getVal( 'wpEditToken' ) );
510 * Generated JavaScript action=raw&gen=js
511 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
512 * nated together. For some bizarre reason, it does *not* return any
513 * custom user JS from subpages. Huh?
515 * There's absolutely no reason to have separate Monobook/Common JSes.
516 * Any JS that cares can just check the skin variable generated at the
517 * top. For now Monobook.js will be maintained, but it should be consi-
520 * @param $skinName String: If set, overrides the skin name
523 public function generateUserJs( $skinName = null ) {
526 wfProfileIn( __METHOD__
);
529 $skinName = $this->getSkinName();
532 $s = "/* generated javascript */\n";
533 $s .= "var skin = '" . Xml
::escapeJsString( $skinName ) . "';\n";
534 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
535 $s .= "\n\n/* MediaWiki:Common.js */\n";
537 $commonJs = wfMsgExt( 'common.js', 'content' );
539 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
543 $s .= "\n\n/* MediaWiki:" . ucfirst( $skinName ) . ".js */\n";
545 // avoid inclusion of non defined user JavaScript (with custom skins only)
546 // by checking for default message content
547 $msgKey = ucfirst( $skinName ) . '.js';
548 $userJS = wfMsgExt( $msgKey, 'content' );
550 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
554 wfProfileOut( __METHOD__
);
559 * Generate user stylesheet for action=raw&gen=css
561 public function generateUserStylesheet() {
562 wfProfileIn( __METHOD__
);
564 $s = "/* generated user stylesheet */\n" .
565 $this->reallyGenerateUserStylesheet();
567 wfProfileOut( __METHOD__
);
572 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
573 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
575 protected function reallyGenerateUserStylesheet() {
580 if ( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
581 $underline = $undopt ?
'underline' : 'none';
582 $s .= "a { text-decoration: $underline; }\n";
585 if ( $wgUser->getOption( 'highlightbroken' ) ) {
586 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
589 a.new, #quickbar a.new,
590 a.stub, #quickbar a.stub {
593 a.new:after, #quickbar a.new:after {
597 a.stub:after, #quickbar a.stub:after {
604 if ( $wgUser->getOption( 'justify' ) ) {
605 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
608 if ( !$wgUser->getOption( 'showtoc' ) ) {
609 $s .= "#toc { display: none; }\n";
612 if ( !$wgUser->getOption( 'editsection' ) ) {
613 $s .= ".editsection { display: none; }\n";
616 $fontstyle = $wgUser->getOption( 'editfont' );
618 if ( $fontstyle !== 'default' ) {
619 $s .= "textarea { font-family: $fontstyle; }\n";
628 function setupUserCss( OutputPage
$out ) {
629 global $wgRequest, $wgUser;
630 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage;
632 wfProfileIn( __METHOD__
);
634 $this->setupSkinUserCss( $out );
638 'maxage' => $wgSquidMaxage,
641 // Add any extension CSS
642 foreach ( $out->getExtStyle() as $url ) {
643 $out->addStyle( $url );
646 // If we use the site's dynamic CSS, throw that in, too
647 // Per-site custom styles
648 if ( $wgUseSiteCss ) {
649 global $wgHandheldStyle;
651 $query = wfArrayToCGI( self
::getDynamicStylesheetQuery() );
652 # Site settings must override extension css! (bug 15025)
653 $out->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
654 $out->addStyle( self
::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI
), 'print' );
656 if ( $wgHandheldStyle ) {
657 $out->addStyle( self
::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI
), 'handheld' );
659 $out->addStyle( self
::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI
) );
662 global $wgAllowUserCssPrefs;
664 if ( $wgAllowUserCssPrefs ) {
665 if ( $wgUser->isLoggedIn() ) {
666 // Ensure that logged-in users' generated CSS isn't clobbered
667 // by anons' publicly cacheable generated CSS.
668 $siteargs['smaxage'] = '0';
669 $siteargs['ts'] = $wgUser->mTouched
;
672 // Per-user styles based on preferences
673 $siteargs['gen'] = 'css';
675 if ( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
676 $siteargs['useskin'] = $us;
679 $out->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
682 // Per-user custom style pages
683 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
684 $action = $wgRequest->getVal( 'action' );
686 # If we're previewing the CSS page, use it
687 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
688 // @FIXME: properly escape the cdata!
689 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
691 $names = array( 'common', $this->getSkinName() );
692 foreach ( $names as $name ) {
693 $out->addStyle( self
::makeUrl(
694 $this->userpage
. '/' . $name . '.css',
695 'action=raw&ctype=text/css' )
701 wfProfileOut( __METHOD__
);
705 * Get the query to generate a dynamic stylesheet
709 public static function getDynamicStylesheetQuery() {
710 global $wgSquidMaxage;
714 'maxage' => $wgSquidMaxage,
715 'usemsgcache' => 'yes',
716 'ctype' => 'text/css',
717 'smaxage' => $wgSquidMaxage,
722 * Add skin specific stylesheets
723 * @param $out OutputPage
725 function setupSkinUserCss( OutputPage
$out ) {
726 // This includes the shared.js and oldshared.js files from skins/common/
727 $out->addModuleStyles( 'mediawiki.legacy.shared' );
728 // TODO: Figure out how to best integrate this stuff into ResourceLoader
729 $out->addStyle( $this->getStylesheet() );
730 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
733 function getPageClasses( $title ) {
734 $numeric = 'ns-' . $title->getNamespace();
736 if ( $title->getNamespace() == NS_SPECIAL
) {
737 $type = 'ns-special';
738 } elseif ( $title->isTalkPage() ) {
741 $type = 'ns-subject';
744 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
746 return "$numeric $type $name";
758 * This will be called immediately after the <body> tag. Split into
759 * two functions to make it easier to subclass.
761 function beforeContent() {
762 return $this->doBeforeContent();
765 function doBeforeContent() {
767 wfProfileIn( __METHOD__
);
770 $qb = $this->qbSetting();
772 $langlinks = $this->otherLanguages();
779 $borderhack = 'class="top"';
782 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
783 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
785 $shove = ( $qb != 0 );
786 $left = ( $qb == 1 ||
$qb == 3 );
788 if ( $wgContLang->isRTL() ) {
793 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
794 $this->logoText() . '</td>';
796 $s .= $this->getQuickbarCompensator( $rows );
799 $l = $wgContLang->alignStart();
800 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
802 $s .= $this->topLinks();
803 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
805 $r = $wgContLang->alignEnd();
806 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
807 $s .= $this->nameAndLogin();
808 $s .= "\n<br />" . $this->searchForm() . '</td>';
811 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
814 if ( $shove && !$left ) { # Right
815 $s .= $this->getQuickbarCompensator( $rows );
818 $s .= "</tr>\n</table>\n</div>\n";
819 $s .= "\n<div id='article'>\n";
821 $notice = wfGetSiteNotice();
824 $s .= "\n<div id='siteNotice'>$notice</div>\n";
826 $s .= $this->pageTitle();
827 $s .= $this->pageSubtitle();
828 $s .= $this->getCategories();
830 wfProfileOut( __METHOD__
);
834 function getCategoryLinks() {
835 global $wgOut, $wgUseCategoryBrowser;
836 global $wgContLang, $wgUser;
838 if ( count( $wgOut->mCategoryLinks
) == 0 ) {
843 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
845 // Use Unicode bidi embedding override characters,
846 // to make sure links don't smash each other up in ugly ways.
847 $dir = $wgContLang->getDir();
848 $embed = "<span dir='$dir'>";
851 $allCats = $wgOut->getCategoryLinks();
853 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
855 if ( !empty( $allCats['normal'] ) ) {
856 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
858 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
859 $s .= '<div id="mw-normal-catlinks">' .
860 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
861 . $colon . $t . '</div>';
865 if ( isset( $allCats['hidden'] ) ) {
866 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
867 $class = 'mw-hidden-cats-user-shown';
868 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
869 $class = 'mw-hidden-cats-ns-shown';
871 $class = 'mw-hidden-cats-hidden';
874 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
875 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
876 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
880 # optional 'dmoz-like' category browser. Will be shown under the list
881 # of categories an article belong to
882 if ( $wgUseCategoryBrowser ) {
883 $s .= '<br /><hr />';
885 # get a big array of the parents tree
886 $parenttree = $this->mTitle
->getParentCategoryTree();
887 # Skin object passed by reference cause it can not be
888 # accessed under the method subfunction drawCategoryBrowser
889 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
890 # Clean out bogus first entry and sort them
891 unset( $tempout[0] );
893 # Output one per line
894 $s .= implode( "<br />\n", $tempout );
901 * Render the array as a serie of links.
902 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
903 * @param &skin Object: skin passed by reference
904 * @return String separated by >, terminate with "\n"
906 function drawCategoryBrowser( $tree, &$skin ) {
909 foreach ( $tree as $element => $parent ) {
910 if ( empty( $parent ) ) {
911 # element start a new list
914 # grab the others elements
915 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
918 # add our current element to the list
919 $eltitle = Title
::newFromText( $element );
920 $return .= $skin->link( $eltitle, $eltitle->getText() );
926 function getCategories() {
927 $catlinks = $this->getCategoryLinks();
929 $classes = 'catlinks';
931 global $wgOut, $wgUser;
933 // Check what we're showing
934 $allCats = $wgOut->getCategoryLinks();
935 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
936 $this->mTitle
->getNamespace() == NS_CATEGORY
;
938 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
939 $classes .= ' catlinks-allhidden';
942 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
945 function getQuickbarCompensator( $rows = 1 ) {
946 return "<td width='152' rowspan='{$rows}'> </td>";
950 * This runs a hook to allow extensions placing their stuff after content
951 * and article metadata (e.g. categories).
952 * Note: This function has nothing to do with afterContent().
954 * This hook is placed here in order to allow using the same hook for all
955 * skins, both the SkinTemplate based ones and the older ones, which directly
956 * use this class to get their data.
958 * The output of this function gets processed in SkinTemplate::outputPage() for
959 * the SkinTemplate based skins, all other skins should directly echo it.
961 * Returns an empty string by default, if not changed by any hook function.
963 protected function afterContentHook() {
966 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
967 // adding just some spaces shouldn't toggle the output
968 // of the whole <div/>, so we use trim() here
969 if ( trim( $data ) != '' ) {
970 // Doing this here instead of in the skins to
971 // ensure that the div has the same ID in all
973 $data = "<div id='mw-data-after-content'>\n" .
978 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
985 * Generate debug data HTML for displaying at the bottom of the main content
987 * @return String HTML containing debug data, if enabled (otherwise empty).
989 protected function generateDebugHTML() {
990 global $wgShowDebug, $wgOut;
992 if ( $wgShowDebug ) {
993 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
994 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
995 $listInternals . "</ul>\n";
1001 private function formatDebugHTML( $debugText ) {
1002 $lines = explode( "\n", $debugText );
1006 foreach ( $lines as $line ) {
1008 $display = ltrim( $line );
1009 $ident = strlen( $line ) - strlen( $display );
1010 $diff = $ident - $curIdent;
1012 if ( $display == '' ) {
1013 $display = "\xc2\xa0";
1016 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
1019 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
1021 $display = htmlspecialchars( $display );
1025 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
1026 } elseif ( $diff == 0 ) {
1027 $ret .= "</li><li>\n";
1029 $ret .= str_repeat( "<ul><li>\n", $diff );
1031 $ret .= $display . "\n";
1036 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
1042 * This gets called shortly before the </body> tag.
1043 * @return String HTML to be put before </body>
1045 function afterContent() {
1046 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
1047 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
1051 * This gets called shortly before the </body> tag.
1052 * @param $out OutputPage object
1053 * @return String HTML-wrapped JS code to be put before </body>
1055 function bottomScripts( $out ) {
1056 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
1057 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
1059 return $bottomScriptText;
1062 /** @return string Retrievied from HTML text */
1063 function printSource() {
1064 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
1065 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
1068 function printFooter() {
1069 return "<p>" . $this->printSource() .
1070 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1073 /** overloaded by derived classes */
1074 function doAfterContent() {
1075 return '</div></div>';
1078 function pageTitleLinks() {
1079 global $wgOut, $wgUser, $wgRequest, $wgLang;
1081 $oldid = $wgRequest->getVal( 'oldid' );
1082 $diff = $wgRequest->getVal( 'diff' );
1083 $action = $wgRequest->getText( 'action' );
1085 $s[] = $this->printableLink();
1086 $disclaimer = $this->disclaimerLink(); # may be empty
1088 if ( $disclaimer ) {
1092 $privacy = $this->privacyLink(); # may be empty too
1098 if ( $wgOut->isArticleRelated() ) {
1099 if ( $this->mTitle
->getNamespace() == NS_FILE
) {
1100 $name = $this->mTitle
->getDBkey();
1101 $image = wfFindFile( $this->mTitle
);
1104 $link = htmlspecialchars( $image->getURL() );
1105 $style = $this->getInternalLinkAttributes( $link, $name );
1106 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1111 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
1112 $s[] .= $this->link(
1114 wfMsg( 'currentrev' ),
1117 array( 'known', 'noclasses' )
1121 if ( $wgUser->getNewtalk() ) {
1122 # do not show "You have new messages" text when we are viewing our
1124 if ( !$this->mTitle
->equals( $wgUser->getTalkPage() ) ) {
1126 $wgUser->getTalkPage(),
1127 wfMsgHtml( 'newmessageslink' ),
1129 array( 'redirect' => 'no' ),
1130 array( 'known', 'noclasses' )
1134 $wgUser->getTalkPage(),
1135 wfMsgHtml( 'newmessagesdifflink' ),
1137 array( 'diff' => 'cur' ),
1138 array( 'known', 'noclasses' )
1140 $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1142 $wgOut->setSquidMaxage( 0 );
1143 $wgOut->enableClientCache( false );
1147 $undelete = $this->getUndeleteLink();
1149 if ( !empty( $undelete ) ) {
1153 return $wgLang->pipeList( $s );
1156 function getUndeleteLink() {
1157 global $wgUser, $wgLang, $wgRequest;
1159 $action = $wgRequest->getVal( 'action', 'view' );
1161 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1162 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
1163 $n = $this->mTitle
->isDeleted();
1166 if ( $wgUser->isAllowed( 'undelete' ) ) {
1167 $msg = 'thisisdeleted';
1169 $msg = 'viewdeleted';
1175 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
1176 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1179 array( 'known', 'noclasses' )
1188 function printableLink() {
1189 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1193 if ( !$wgOut->isPrintable() ) {
1194 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1195 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1198 if ( $wgOut->isSyndicated() ) {
1199 foreach ( $wgFeedClasses as $format => $class ) {
1200 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1201 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1202 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1205 return $wgLang->pipeList( $s );
1209 * Gets the h1 element with the page title.
1212 function pageTitle() {
1214 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1218 function pageSubtitle() {
1221 $sub = $wgOut->getSubtitle();
1224 global $wgExtraSubtitle;
1225 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1228 $subpages = $this->subPageSubtitle();
1229 $sub .= !empty( $subpages ) ?
"</p><p class='subpages'>$subpages" : '';
1230 $s = "<p class='subtitle'>{$sub}</p>\n";
1235 function subPageSubtitle() {
1238 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1244 if ( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
1245 $ptext = $this->mTitle
->getPrefixedText();
1246 if ( preg_match( '/\//', $ptext ) ) {
1247 $links = explode( '/', $ptext );
1248 array_pop( $links );
1253 foreach ( $links as $link ) {
1254 $growinglink .= $link;
1256 $linkObj = Title
::newFromText( $growinglink );
1258 if ( is_object( $linkObj ) && $linkObj->exists() ) {
1259 $getlink = $this->link(
1261 htmlspecialchars( $display ),
1264 array( 'known', 'noclasses' )
1270 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1272 $subpages .= '< ';
1275 $subpages .= $getlink;
1280 $growinglink .= '/';
1289 * Returns true if the IP should be shown in the header
1291 function showIPinHeader() {
1292 global $wgShowIPinHeader;
1293 return $wgShowIPinHeader && session_id() != '';
1296 function nameAndLogin() {
1297 global $wgUser, $wgLang, $wgContLang;
1299 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1303 if ( $wgUser->isAnon() ) {
1304 if ( $this->showIPinHeader() ) {
1307 $talkLink = $this->link( $wgUser->getTalkPage(),
1308 $wgLang->getNsText( NS_TALK
) );
1310 $ret .= "$name ($talkLink)";
1312 $ret .= wfMsg( 'notloggedin' );
1315 $returnTo = $this->mTitle
->getPrefixedDBkey();
1318 if ( $logoutPage != $returnTo ) {
1319 $query['returnto'] = $returnTo;
1322 $loginlink = $wgUser->isAllowed( 'createaccount' )
1323 ?
'nav-login-createaccount'
1325 $ret .= "\n<br />" . $this->link(
1326 SpecialPage
::getTitleFor( 'Userlogin' ),
1327 wfMsg( $loginlink ), array(), $query
1330 $returnTo = $this->mTitle
->getPrefixedDBkey();
1331 $talkLink = $this->link( $wgUser->getTalkPage(),
1332 $wgLang->getNsText( NS_TALK
) );
1334 $ret .= $this->link( $wgUser->getUserPage(),
1335 htmlspecialchars( $wgUser->getName() ) );
1336 $ret .= " ($talkLink)<br />";
1337 $ret .= $wgLang->pipeList( array(
1339 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1340 array(), array( 'returnto' => $returnTo )
1342 $this->specialLink( 'preferences' ),
1346 $ret = $wgLang->pipeList( array(
1349 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1357 function getSearchLink() {
1358 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1359 return $searchPage->getLocalURL();
1362 function escapeSearchLink() {
1363 return htmlspecialchars( $this->getSearchLink() );
1366 function searchForm() {
1367 global $wgRequest, $wgUseTwoButtonsSearchForm;
1369 $search = $wgRequest->getText( 'search' );
1371 $s = '<form id="searchform' . $this->searchboxes
. '" name="search" class="inline" method="post" action="'
1372 . $this->escapeSearchLink() . "\">\n"
1373 . '<input type="text" id="searchInput' . $this->searchboxes
. '" name="search" size="19" value="'
1374 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1375 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1377 if ( $wgUseTwoButtonsSearchForm ) {
1378 $s .= ' <input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1380 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1385 // Ensure unique id's for search boxes made after the first
1386 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1391 function topLinks() {
1395 $this->mainPageLink(),
1396 $this->specialLink( 'recentchanges' )
1399 if ( $wgOut->isArticleRelated() ) {
1400 $s[] = $this->editThisPage();
1401 $s[] = $this->historyLink();
1404 # Many people don't like this dropdown box
1405 # $s[] = $this->specialPagesList();
1407 if ( $this->variantLinks() ) {
1408 $s[] = $this->variantLinks();
1411 if ( $this->extensionTabLinks() ) {
1412 $s[] = $this->extensionTabLinks();
1415 // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1416 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1420 * Compatibility for extensions adding functionality through tabs.
1421 * Eventually these old skins should be replaced with SkinTemplate-based
1425 function extensionTabLinks() {
1429 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1430 foreach ( $tabs as $tab ) {
1431 $s[] = Xml
::element( 'a',
1432 array( 'href' => $tab['href'] ),
1436 if ( count( $s ) ) {
1439 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1440 $out .= $wgLang->pipeList( $s );
1447 * Language/charset variant links for classic-style skins
1450 function variantLinks() {
1453 /* show links to different language variants */
1454 global $wgDisableLangConversion, $wgLang, $wgContLang;
1456 $variants = $wgContLang->getVariants();
1458 if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1459 foreach ( $variants as $code ) {
1460 $varname = $wgContLang->getVariantname( $code );
1462 if ( $varname == 'disable' ) {
1465 $s = $wgLang->pipeList( array(
1467 '<a href="' . $this->mTitle
->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1475 function bottomLinks() {
1476 global $wgOut, $wgUser, $wgUseTrackbacks;
1477 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1480 if ( $wgOut->isArticleRelated() ) {
1481 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1483 if ( $wgUser->isLoggedIn() ) {
1484 $element[] = $this->watchThisPage();
1487 $element[] = $this->talkLink();
1488 $element[] = $this->historyLink();
1489 $element[] = $this->whatLinksHere();
1490 $element[] = $this->watchPageLinksLink();
1492 if ( $wgUseTrackbacks ) {
1493 $element[] = $this->trackbackLink();
1497 $this->mTitle
->getNamespace() == NS_USER ||
1498 $this->mTitle
->getNamespace() == NS_USER_TALK
1500 $id = User
::idFromName( $this->mTitle
->getText() );
1501 $ip = User
::isIP( $this->mTitle
->getText() );
1503 # Both anons and non-anons have contributions list
1505 $element[] = $this->userContribsLink();
1508 if ( $this->showEmailUser( $id ) ) {
1509 $element[] = $this->emailUserLink();
1513 $s = implode( $element, $sep );
1515 if ( $this->mTitle
->getArticleId() ) {
1518 // Delete/protect/move links for privileged users
1519 if ( $wgUser->isAllowed( 'delete' ) ) {
1520 $s .= $this->deleteThisPage();
1523 if ( $wgUser->isAllowed( 'protect' ) ) {
1524 $s .= $sep . $this->protectThisPage();
1527 if ( $wgUser->isAllowed( 'move' ) ) {
1528 $s .= $sep . $this->moveThisPage();
1532 $s .= "<br />\n" . $this->otherLanguages();
1538 function pageStats() {
1539 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1540 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1542 $oldid = $wgRequest->getVal( 'oldid' );
1543 $diff = $wgRequest->getVal( 'diff' );
1545 if ( !$wgOut->isArticle() ) {
1549 if ( !$wgArticle instanceof Article
) {
1553 if ( isset( $oldid ) ||
isset( $diff ) ) {
1557 if ( 0 == $wgArticle->getID() ) {
1563 if ( !$wgDisableCounters ) {
1564 $count = $wgLang->formatNum( $wgArticle->getCount() );
1567 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1571 if ( $wgMaxCredits != 0 ) {
1572 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1574 $s .= $this->lastModified();
1577 if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1578 $dbr = wfGetDB( DB_SLAVE
);
1579 $res = $dbr->select(
1581 array( 'COUNT(*) AS n' ),
1583 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ),
1584 'wl_namespace' => $this->mTitle
->getNamespace()
1588 $x = $dbr->fetchObject( $res );
1590 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1591 array( 'parseinline' ), $wgLang->formatNum( $x->n
)
1595 return $s . ' ' . $this->getCopyright();
1598 function getCopyright( $type = 'detect' ) {
1599 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1601 if ( $type == 'detect' ) {
1602 $diff = $wgRequest->getVal( 'diff' );
1603 $isCur = $wgArticle && $wgArticle->isCurrent();
1605 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1612 if ( $type == 'history' ) {
1613 $msg = 'history_copyright';
1620 if ( $wgRightsPage ) {
1621 $title = Title
::newFromText( $wgRightsPage );
1622 $link = $this->linkKnown( $title, $wgRightsText );
1623 } elseif ( $wgRightsUrl ) {
1624 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1625 } elseif ( $wgRightsText ) {
1626 $link = $wgRightsText;
1632 // Allow for site and per-namespace customization of copyright notice.
1635 if ( isset( $wgArticle ) ) {
1636 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1639 if ( $forContent ) {
1640 $out .= wfMsgForContent( $msg, $link );
1642 $out .= wfMsg( $msg, $link );
1648 function getCopyrightIcon() {
1649 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1653 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1654 $out = $wgCopyrightIcon;
1655 } elseif ( $wgRightsIcon ) {
1656 $icon = htmlspecialchars( $wgRightsIcon );
1658 if ( $wgRightsUrl ) {
1659 $url = htmlspecialchars( $wgRightsUrl );
1660 $out .= '<a href="' . $url . '">';
1663 $text = htmlspecialchars( $wgRightsText );
1664 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1666 if ( $wgRightsUrl ) {
1675 * Gets the powered by MediaWiki icon.
1678 function getPoweredBy() {
1679 global $wgStylePath;
1681 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1682 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1687 function lastModified() {
1688 global $wgLang, $wgArticle;
1690 if ( $this->mRevisionId
&& $this->mRevisionId
!= $wgArticle->getLatest() ) {
1691 $timestamp = Revision
::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId
);
1693 $timestamp = $wgArticle->getTimestamp();
1697 $d = $wgLang->date( $timestamp, true );
1698 $t = $wgLang->time( $timestamp, true );
1699 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1704 if ( wfGetLB()->getLaggedSlaveMode() ) {
1705 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1711 function logoText( $align = '' ) {
1712 if ( $align != '' ) {
1713 $a = " align='{$align}'";
1718 $mp = wfMsg( 'mainpage' );
1719 $mptitle = Title
::newMainPage();
1720 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1722 $logourl = $this->getLogo();
1723 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1729 * Show a drop-down box of special pages
1731 function specialPagesList() {
1732 global $wgContLang, $wgServer, $wgRedirectScript;
1734 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1736 foreach ( $pages as $name => $page ) {
1737 $pages[$name] = $page->getDescription();
1740 $go = wfMsg( 'go' );
1741 $sp = wfMsg( 'specialpages' );
1742 $spp = $wgContLang->specialPage( 'Specialpages' );
1744 $s = '<form id="specialpages" method="get" ' .
1745 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1746 $s .= "<select name=\"wpDropdown\">\n";
1747 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1750 foreach ( $pages as $name => $desc ) {
1751 $p = $wgContLang->specialPage( $name );
1752 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1755 $s .= "</select>\n";
1756 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1763 * Gets the link to the wiki's main page.
1766 function mainPageLink() {
1768 Title
::newMainPage(),
1769 wfMsg( 'mainpage' ),
1772 array( 'known', 'noclasses' )
1778 private function footerLink( $desc, $page ) {
1779 // if the link description has been set to "-" in the default language,
1780 if ( wfMsgForContent( $desc ) == '-' ) {
1781 // then it is disabled, for all languages.
1784 // Otherwise, we display the link for the user, described in their
1785 // language (which may or may not be the same as the default language),
1786 // but we make the link target be the one site-wide page.
1787 $title = Title
::newFromText( wfMsgForContent( $page ) );
1789 return $this->linkKnown(
1791 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1797 * Gets the link to the wiki's privacy policy page.
1799 function privacyLink() {
1800 return $this->footerLink( 'privacy', 'privacypage' );
1804 * Gets the link to the wiki's about page.
1806 function aboutLink() {
1807 return $this->footerLink( 'aboutsite', 'aboutpage' );
1811 * Gets the link to the wiki's general disclaimers page.
1813 function disclaimerLink() {
1814 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1817 function editThisPage() {
1820 if ( !$wgOut->isArticleRelated() ) {
1821 $s = wfMsg( 'protectedpage' );
1823 if ( $this->mTitle
->quickUserCan( 'edit' ) && $this->mTitle
->exists() ) {
1824 $t = wfMsg( 'editthispage' );
1825 } elseif ( $this->mTitle
->quickUserCan( 'create' ) && !$this->mTitle
->exists() ) {
1826 $t = wfMsg( 'create-this-page' );
1828 $t = wfMsg( 'viewsource' );
1835 $this->editUrlOptions(),
1836 array( 'known', 'noclasses' )
1844 * Return URL options for the 'edit page' link.
1845 * This may include an 'oldid' specifier, if the current page view is such.
1850 function editUrlOptions() {
1853 $options = array( 'action' => 'edit' );
1855 if ( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1856 $options['oldid'] = intval( $this->mRevisionId
);
1862 function deleteThisPage() {
1863 global $wgUser, $wgRequest;
1865 $diff = $wgRequest->getVal( 'diff' );
1867 if ( $this->mTitle
->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1868 $t = wfMsg( 'deletethispage' );
1874 array( 'action' => 'delete' ),
1875 array( 'known', 'noclasses' )
1884 function protectThisPage() {
1885 global $wgUser, $wgRequest;
1887 $diff = $wgRequest->getVal( 'diff' );
1889 if ( $this->mTitle
->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
1890 if ( $this->mTitle
->isProtected() ) {
1891 $text = wfMsg( 'unprotectthispage' );
1892 $query = array( 'action' => 'unprotect' );
1894 $text = wfMsg( 'protectthispage' );
1895 $query = array( 'action' => 'protect' );
1903 array( 'known', 'noclasses' )
1912 function watchThisPage() {
1914 ++
$this->mWatchLinkNum
;
1916 if ( $wgOut->isArticleRelated() ) {
1917 if ( $this->mTitle
->userIsWatching() ) {
1918 $text = wfMsg( 'unwatchthispage' );
1919 $query = array( 'action' => 'unwatch' );
1920 $id = 'mw-unwatch-link' . $this->mWatchLinkNum
;
1922 $text = wfMsg( 'watchthispage' );
1923 $query = array( 'action' => 'watch' );
1924 $id = 'mw-watch-link' . $this->mWatchLinkNum
;
1930 array( 'id' => $id ),
1932 array( 'known', 'noclasses' )
1935 $s = wfMsg( 'notanarticle' );
1941 function moveThisPage() {
1942 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
1944 SpecialPage
::getTitleFor( 'Movepage' ),
1945 wfMsg( 'movethispage' ),
1947 array( 'target' => $this->mTitle
->getPrefixedDBkey() ),
1948 array( 'known', 'noclasses' )
1951 // no message if page is protected - would be redundant
1956 function historyLink() {
1959 wfMsgHtml( 'history' ),
1960 array( 'rel' => 'archives' ),
1961 array( 'action' => 'history' )
1965 function whatLinksHere() {
1967 SpecialPage
::getTitleFor( 'Whatlinkshere', $this->mTitle
->getPrefixedDBkey() ),
1968 wfMsgHtml( 'whatlinkshere' ),
1971 array( 'known', 'noclasses' )
1975 function userContribsLink() {
1977 SpecialPage
::getTitleFor( 'Contributions', $this->mTitle
->getDBkey() ),
1978 wfMsgHtml( 'contributions' ),
1981 array( 'known', 'noclasses' )
1985 function showEmailUser( $id ) {
1987 $targetUser = User
::newFromId( $id );
1988 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1989 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1992 function emailUserLink() {
1994 SpecialPage
::getTitleFor( 'Emailuser', $this->mTitle
->getDBkey() ),
1995 wfMsg( 'emailuser' ),
1998 array( 'known', 'noclasses' )
2002 function watchPageLinksLink() {
2005 if ( !$wgOut->isArticleRelated() ) {
2006 return '(' . wfMsg( 'notanarticle' ) . ')';
2009 SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->mTitle
->getPrefixedDBkey() ),
2010 wfMsg( 'recentchangeslinked-toolbox' ),
2013 array( 'known', 'noclasses' )
2018 function trackbackLink() {
2019 return '<a href="' . $this->mTitle
->trackbackURL() . '">'
2020 . wfMsg( 'trackbacklink' ) . '</a>';
2023 function otherLanguages() {
2024 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
2026 if ( $wgHideInterlanguageLinks ) {
2030 $a = $wgOut->getLanguageLinks();
2032 if ( 0 == count( $a ) ) {
2036 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
2039 if ( $wgContLang->isRTL() ) {
2040 $s .= '<span dir="LTR">';
2043 foreach ( $a as $l ) {
2045 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
2050 $nt = Title
::newFromText( $l );
2051 $url = $nt->escapeFullURL();
2052 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
2053 $title = htmlspecialchars( $nt->getText() );
2055 if ( $text == '' ) {
2059 $style = $this->getExternalLinkAttributes();
2060 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
2063 if ( $wgContLang->isRTL() ) {
2070 function talkLink() {
2071 if ( NS_SPECIAL
== $this->mTitle
->getNamespace() ) {
2072 # No discussion links for special pages
2076 $linkOptions = array();
2078 if ( $this->mTitle
->isTalkPage() ) {
2079 $link = $this->mTitle
->getSubjectPage();
2080 switch( $link->getNamespace() ) {
2082 $text = wfMsg( 'articlepage' );
2085 $text = wfMsg( 'userpage' );
2088 $text = wfMsg( 'projectpage' );
2091 $text = wfMsg( 'imagepage' );
2092 # Make link known if image exists, even if the desc. page doesn't.
2093 if ( wfFindFile( $link ) )
2094 $linkOptions[] = 'known';
2097 $text = wfMsg( 'mediawikipage' );
2100 $text = wfMsg( 'templatepage' );
2103 $text = wfMsg( 'viewhelppage' );
2106 $text = wfMsg( 'categorypage' );
2109 $text = wfMsg( 'articlepage' );
2112 $link = $this->mTitle
->getTalkPage();
2113 $text = wfMsg( 'talkpage' );
2116 $s = $this->link( $link, $text, array(), array(), $linkOptions );
2121 function commentLink() {
2124 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
2128 # __NEWSECTIONLINK___ changes behaviour here
2129 # If it is present, the link points to this page, otherwise
2130 # it points to the talk page
2131 if ( $this->mTitle
->isTalkPage() ) {
2132 $title = $this->mTitle
;
2133 } elseif ( $wgOut->showNewSectionLink() ) {
2134 $title = $this->mTitle
;
2136 $title = $this->mTitle
->getTalkPage();
2141 wfMsg( 'postcomment' ),
2147 array( 'known', 'noclasses' )
2151 function getUploadLink() {
2152 global $wgUploadNavigationUrl;
2154 if ( $wgUploadNavigationUrl ) {
2155 # Using an empty class attribute to avoid automatic setting of "external" class
2156 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
2159 SpecialPage
::getTitleFor( 'Upload' ),
2160 wfMsgHtml( 'upload' ),
2163 array( 'known', 'noclasses' )
2168 /* these are used extensively in SkinTemplate, but also some other places */
2169 static function makeMainPageUrl( $urlaction = '' ) {
2170 $title = Title
::newMainPage();
2171 self
::checkTitle( $title, '' );
2173 return $title->getLocalURL( $urlaction );
2176 static function makeSpecialUrl( $name, $urlaction = '' ) {
2177 $title = SpecialPage
::getTitleFor( $name );
2178 return $title->getLocalURL( $urlaction );
2181 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2182 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
2183 return $title->getLocalURL( $urlaction );
2186 static function makeI18nUrl( $name, $urlaction = '' ) {
2187 $title = Title
::newFromText( wfMsgForContent( $name ) );
2188 self
::checkTitle( $title, $name );
2189 return $title->getLocalURL( $urlaction );
2192 static function makeUrl( $name, $urlaction = '' ) {
2193 $title = Title
::newFromText( $name );
2194 self
::checkTitle( $title, $name );
2196 return $title->getLocalURL( $urlaction );
2200 * If url string starts with http, consider as external URL, else
2203 static function makeInternalOrExternalUrl( $name ) {
2204 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2207 return self
::makeUrl( $name );
2211 # this can be passed the NS number as defined in Language.php
2212 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
2213 $title = Title
::makeTitleSafe( $namespace, $name );
2214 self
::checkTitle( $title, $name );
2216 return $title->getLocalURL( $urlaction );
2219 /* these return an array with the 'href' and boolean 'exists' */
2220 static function makeUrlDetails( $name, $urlaction = '' ) {
2221 $title = Title
::newFromText( $name );
2222 self
::checkTitle( $title, $name );
2225 'href' => $title->getLocalURL( $urlaction ),
2226 'exists' => $title->getArticleID() != 0 ?
true : false
2231 * Make URL details where the article exists (or at least it's convenient to think so)
2233 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2234 $title = Title
::newFromText( $name );
2235 self
::checkTitle( $title, $name );
2238 'href' => $title->getLocalURL( $urlaction ),
2243 # make sure we have some title to operate on
2244 static function checkTitle( &$title, $name ) {
2245 if ( !is_object( $title ) ) {
2246 $title = Title
::newFromText( $name );
2247 if ( !is_object( $title ) ) {
2248 $title = Title
::newFromText( '--error: link target missing--' );
2254 * Build an array that represents the sidebar(s), the navigation bar among them
2258 function buildSidebar() {
2259 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2261 wfProfileIn( __METHOD__
);
2263 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2265 if ( $wgEnableSidebarCache ) {
2266 $cachedsidebar = $parserMemc->get( $key );
2267 if ( $cachedsidebar ) {
2268 wfProfileOut( __METHOD__
);
2269 return $cachedsidebar;
2274 $this->addToSidebar( $bar, 'sidebar' );
2276 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2277 if ( $wgEnableSidebarCache ) {
2278 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2281 wfProfileOut( __METHOD__
);
2285 * Add content from a sidebar system message
2286 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2288 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2290 * @param &$bar array
2291 * @param $message String
2293 function addToSidebar( &$bar, $message ) {
2294 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2298 * Add content from plain text
2300 * @param &$bar array
2301 * @param $text string
2303 function addToSidebarPlain( &$bar, $text ) {
2304 $lines = explode( "\n", $text );
2305 $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
2309 foreach ( $lines as $line ) {
2310 if ( strpos( $line, '*' ) !== 0 ) {
2314 if ( strpos( $line, '**' ) !== 0 ) {
2315 $heading = trim( $line, '* ' );
2316 if ( !array_key_exists( $heading, $bar ) ) {
2317 $bar[$heading] = array();
2320 $line = trim( $line, '* ' );
2322 if ( strpos( $line, '|' ) !== false ) { // sanity check
2323 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2324 $link = wfMsgForContent( $line[0] );
2326 if ( $link == '-' ) {
2330 $text = wfMsgExt( $line[1], 'parsemag' );
2332 if ( wfEmptyMsg( $line[1], $text ) ) {
2336 if ( wfEmptyMsg( $line[0], $link ) ) {
2340 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2343 $title = Title
::newFromText( $link );
2346 $title = $title->fixSpecialName();
2347 $href = $title->getLocalURL();
2349 $href = 'INVALID-TITLE';
2353 $bar[$heading][] = array(
2356 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2359 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
2360 global $wgParser, $wgTitle;
2362 $line = substr( $line, 2, strlen( $line ) - 4 );
2364 if ( is_null( $wgParser->mOptions
) ) {
2365 $wgParser->mOptions
= new ParserOptions();
2368 $wgParser->mOptions
->setEditSection( false );
2369 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $wgParser->mOptions
)->getText();
2376 if ( count( $wikiBar ) > 0 ) {
2377 $bar = array_merge( $bar, $wikiBar );
2384 * Should we include common/wikiprintable.css? Skins that have their own
2385 * print stylesheet should override this and return false. (This is an
2386 * ugly hack to get Monobook to play nicely with
2387 * OutputPage::headElement().)
2391 public function commonPrintStylesheet() {
2396 * Gets new talk page messages for the current user.
2397 * @return MediaWiki message or if no new talk page messages, nothing
2399 function getNewtalks() {
2400 global $wgUser, $wgOut;
2402 $newtalks = $wgUser->getNewMessageLinks();
2405 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2406 $userTitle = $this->mUser
->getUserPage();
2407 $userTalkTitle = $userTitle->getTalkPage();
2409 if ( !$userTalkTitle->equals( $this->mTitle
) ) {
2410 $newMessagesLink = $this->link(
2412 wfMsgHtml( 'newmessageslink' ),
2414 array( 'redirect' => 'no' ),
2415 array( 'known', 'noclasses' )
2418 $newMessagesDiffLink = $this->link(
2420 wfMsgHtml( 'newmessagesdifflink' ),
2422 array( 'diff' => 'cur' ),
2423 array( 'known', 'noclasses' )
2427 'youhavenewmessages',
2429 $newMessagesDiffLink
2431 # Disable Squid cache
2432 $wgOut->setSquidMaxage( 0 );
2434 } elseif ( count( $newtalks ) ) {
2435 // _>" " for BC <= 1.16
2436 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2439 foreach ( $newtalks as $newtalk ) {
2440 $msgs[] = Xml
::element(
2442 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2445 $parts = implode( $sep, $msgs );
2446 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2447 $wgOut->setSquidMaxage( 0 );