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 abstract class Skin
extends Linker
{
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
24 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
25 protected $skinname = 'standard';
27 * todo Fixme: should be protected :-\
31 protected $mRelevantTitle = null;
32 protected $mRelevantUser = null;
34 /** Constructor, call parent constructor */
35 function __construct() {
36 parent
::__construct();
40 * Fetch the set of available skins.
41 * @return array of strings
43 static function getSkinNames() {
44 global $wgValidSkinNames;
45 static $skinsInitialised = false;
47 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
48 # Get a list of available skins
49 # Build using the regular expression '^(.*).php$'
50 # Array keys are all lower case, array value keep the case used by filename
52 wfProfileIn( __METHOD__
. '-init' );
54 global $wgStyleDirectory;
56 $skinDir = dir( $wgStyleDirectory );
58 # while code from www.php.net
59 while ( false !== ( $file = $skinDir->read() ) ) {
60 // Skip non-PHP files, hidden files, and '.dep' includes
63 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
65 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
69 $skinsInitialised = true;
70 wfProfileOut( __METHOD__
. '-init' );
72 return $wgValidSkinNames;
76 * Fetch the list of usable skins in regards to $wgSkipSkins.
77 * Useful for Special:Preferences and other places where you
78 * only want to show skins users _can_ use.
79 * @return array of strings
81 public static function getUsableSkins() {
84 $usableSkins = self
::getSkinNames();
86 foreach ( $wgSkipSkins as $skip ) {
87 unset( $usableSkins[$skip] );
94 * Normalize a skin preference value to a form that can be loaded.
95 * If a skin can't be found, it will fall back to the configured
96 * default (or the old 'Classic' skin if that's broken).
97 * @param $key String: 'monobook', 'standard', etc.
100 static function normalizeKey( $key ) {
101 global $wgDefaultSkin;
103 $skinNames = Skin
::getSkinNames();
106 // Don't return the default immediately;
107 // in a misconfiguration we need to fall back.
108 $key = $wgDefaultSkin;
111 if ( isset( $skinNames[$key] ) ) {
115 // Older versions of the software used a numeric setting
116 // in the user preferences.
123 if ( isset( $fallback[$key] ) ) {
124 $key = $fallback[$key];
127 if ( isset( $skinNames[$key] ) ) {
129 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
130 return $wgDefaultSkin;
137 * Factory method for loading a skin of a given type
138 * @param $key String: 'monobook', 'standard', etc.
141 static function &newFromKey( $key ) {
142 global $wgStyleDirectory;
144 $key = Skin
::normalizeKey( $key );
146 $skinNames = Skin
::getSkinNames();
147 $skinName = $skinNames[$key];
148 $className = "Skin{$skinName}";
150 # Grab the skin class and initialise it.
151 if ( !class_exists( $className ) ) {
152 // Preload base classes to work around APC/PHP5 bug
153 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
155 if ( file_exists( $deps ) ) {
156 include_once( $deps );
158 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
160 # Check if we got if not failback to default skin
161 if ( !class_exists( $className ) ) {
162 # DO NOT die if the class isn't found. This breaks maintenance
163 # scripts and can cause a user account to be unrecoverable
164 # except by SQL manipulation if a previously valid skin name
165 # is no longer valid.
166 wfDebug( "Skin class does not exist: $className\n" );
167 $className = 'SkinVector';
168 require_once( "{$wgStyleDirectory}/Vector.php" );
171 $skin = new $className;
175 /** @return string path to the skin stylesheet */
176 function getStylesheet() {
177 return 'common/wikistandard.css';
180 /** @return string skin name */
181 public function getSkinName() {
182 return $this->skinname
;
185 function initPage( OutputPage
$out ) {
186 wfProfileIn( __METHOD__
);
188 $this->mRevisionId
= $out->mRevisionId
;
189 $this->preloadExistence();
192 wfProfileOut( __METHOD__
);
196 * Preload the existence of three commonly-requested pages in a single query
198 function preloadExistence() {
202 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
205 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
207 } elseif ( $this->mTitle
->isTalkPage() ) {
208 $titles[] = $this->mTitle
->getSubjectPage();
210 $titles[] = $this->mTitle
->getTalkPage();
213 $lb = new LinkBatch( $titles );
214 $lb->setCaller( __METHOD__
);
219 * Set some local variables
221 protected function setMembers() {
223 $this->mUser
= $wgUser;
224 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
225 $this->usercss
= false;
229 * Whether the revision displayed is the latest revision of the page
233 public function isRevisionCurrent() {
234 return $this->mRevisionId
== 0 ||
$this->mRevisionId
== $this->mTitle
->getLatestRevID();
239 * @param $t Title object to use
241 public function setTitle( $t ) {
249 public function getTitle() {
250 return $this->mTitle
;
254 * Set the "relevant" title
255 * @see self::getRelevantTitle()
256 * @param $t Title object to use
258 public function setRelevantTitle( $t ) {
259 $this->mRelevantTitle
= $t;
263 * Return the "relevant" title.
264 * A "relevant" title is not necessarily the actual title of the page.
265 * Special pages like Special:MovePage use set the page they are acting on
266 * as their "relevant" title, this allows the skin system to display things
267 * such as content tabs which belong to to that page instead of displaying
268 * a basic special page tab which has almost no meaning.
270 public function getRelevantTitle() {
271 if ( isset($this->mRelevantTitle
) ) {
272 return $this->mRelevantTitle
;
274 return $this->mTitle
;
278 * Set the "relevant" user
279 * @see self::getRelevantUser()
280 * @param $u User object to use
282 public function setRelevantUser( $u ) {
283 $this->mRelevantUser
= $u;
287 * Return the "relevant" user.
288 * A "relevant" user is similar to a relevant title. Special pages like
289 * Special:Contributions mark the user which they are relevant to so that
290 * things like the toolbox can display the information they usually are only
291 * able to display on a user's userpage and talkpage.
293 public function getRelevantUser() {
294 if ( isset($this->mRelevantUser
) ) {
295 return $this->mRelevantUser
;
297 $title = $this->getRelevantTitle();
298 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
299 $rootUser = strtok( $title->getText(), '/' );
300 if ( User
::isIP( $rootUser ) ) {
301 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
303 $user = User
::newFromName( $rootUser );
304 if ( $user->isLoggedIn() ) {
305 $this->mRelevantUser
= $user;
308 return $this->mRelevantUser
;
314 * Outputs the HTML generated by other functions.
315 * @param $out Object: instance of OutputPage
318 function outputPage( OutputPage
$out ) {
319 global $wgDebugComments;
320 wfProfileIn( __METHOD__
);
322 $this->initPage( $out );
324 // See self::afterContentHook() for documentation
325 $afterContent = $this->afterContentHook();
327 $out->out( $out->headElement( $this ) );
329 if ( $wgDebugComments ) {
330 $out->out( "<!-- Debug output:\n" .
331 $out->mDebugtext
. "-->\n" );
334 $out->out( $this->beforeContent() );
336 $out->out( $out->mBodytext
. "\n" );
338 $out->out( $this->afterContent() );
340 $out->out( $afterContent );
342 $out->out( $this->bottomScripts( $out ) );
344 $out->out( wfReportTime() );
346 $out->out( "\n</body></html>" );
347 wfProfileOut( __METHOD__
);
350 static function makeVariablesScript( $data ) {
352 return Html
::inlineScript(
353 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
361 * To make it harder for someone to slip a user a fake
362 * user-JavaScript or user-CSS preview, a random token
363 * is associated with the login session. If it's not
364 * passed back with the preview request, we won't render
367 * @param $action String: 'edit', 'submit' etc.
370 public function userCanPreview( $action ) {
371 global $wgRequest, $wgUser;
373 if ( $action != 'submit' ) {
376 if ( !$wgRequest->wasPosted() ) {
379 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
382 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
386 return $wgUser->matchEditToken(
387 $wgRequest->getVal( 'wpEditToken' ) );
391 * Generated JavaScript action=raw&gen=js
392 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
393 * nated together. For some bizarre reason, it does *not* return any
394 * custom user JS from subpages. Huh?
396 * There's absolutely no reason to have separate Monobook/Common JSes.
397 * Any JS that cares can just check the skin variable generated at the
398 * top. For now Monobook.js will be maintained, but it should be consi-
401 * @param $skinName String: If set, overrides the skin name
404 public function generateUserJs( $skinName = null ) {
406 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
412 * Generate user stylesheet for action=raw&gen=css
414 public function generateUserStylesheet() {
416 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
422 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
423 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
425 protected function reallyGenerateUserStylesheet() {
427 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
435 function setupUserCss( OutputPage
$out ) {
436 global $wgRequest, $wgUser;
437 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
439 wfProfileIn( __METHOD__
);
441 $this->setupSkinUserCss( $out );
442 // Add any extension CSS
443 foreach ( $out->getExtStyle() as $url ) {
444 $out->addStyle( $url );
447 // Per-site custom styles
448 if ( $wgUseSiteCss ) {
449 $out->addModuleStyles( array( 'site', 'noscript' ) );
450 if( $wgUser->isLoggedIn() ){
451 $out->addModuleStyles( 'user.groups' );
455 // Per-user custom styles
456 if ( $wgAllowUserCss ) {
457 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
458 // @FIXME: properly escape the cdata!
459 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
461 $out->addModuleStyles( 'user' );
465 // Per-user preference styles
466 if ( $wgAllowUserCssPrefs ) {
467 $out->addModuleStyles( 'user.options' );
470 wfProfileOut( __METHOD__
);
474 * Get the query to generate a dynamic stylesheet
478 public static function getDynamicStylesheetQuery() {
479 global $wgSquidMaxage;
483 'maxage' => $wgSquidMaxage,
484 'usemsgcache' => 'yes',
485 'ctype' => 'text/css',
486 'smaxage' => $wgSquidMaxage,
491 * Add skin specific stylesheets
492 * @param $out OutputPage
495 abstract function setupSkinUserCss( OutputPage
$out );
497 function getPageClasses( $title ) {
498 $numeric = 'ns-' . $title->getNamespace();
500 if ( $title->getNamespace() == NS_SPECIAL
) {
501 $type = 'ns-special';
502 // bug 23315: provide a class based on the canonical special page name without subpages
503 list( $canonicalName ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
504 if ( $canonicalName ) {
505 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
507 $type .= ' mw-invalidspecialpage';
509 } elseif ( $title->isTalkPage() ) {
512 $type = 'ns-subject';
515 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
517 return "$numeric $type $name";
521 * This will be called by OutputPage::headElement when it is creating the
522 * <body> tag, skins can override it if they have a need to add in any
523 * body attributes or classes of their own.
525 function addToBodyAttributes( $out, &$bodyAttrs ) {
526 // does nothing by default
538 * The format without an explicit $out argument is deprecated
540 function getCategoryLinks( OutputPage
$out=null ) {
541 global $wgUseCategoryBrowser, $wgContLang, $wgUser;
543 if ( is_null( $out ) ) {
544 // Backwards compatibility for when there was no $out arg
549 if ( count( $out->mCategoryLinks
) == 0 ) {
554 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
556 // Use Unicode bidi embedding override characters,
557 // to make sure links don't smash each other up in ugly ways.
558 $dir = $wgContLang->getDir();
559 $embed = "<span dir='$dir'>";
562 $allCats = $out->getCategoryLinks();
564 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
566 if ( !empty( $allCats['normal'] ) ) {
567 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
569 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
570 $s .= '<div id="mw-normal-catlinks">' .
571 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
572 . $colon . $t . '</div>';
576 if ( isset( $allCats['hidden'] ) ) {
577 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
578 $class = 'mw-hidden-cats-user-shown';
579 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
580 $class = 'mw-hidden-cats-ns-shown';
582 $class = 'mw-hidden-cats-hidden';
585 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
586 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
587 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
591 # optional 'dmoz-like' category browser. Will be shown under the list
592 # of categories an article belong to
593 if ( $wgUseCategoryBrowser ) {
594 $s .= '<br /><hr />';
596 # get a big array of the parents tree
597 $parenttree = $this->mTitle
->getParentCategoryTree();
598 # Skin object passed by reference cause it can not be
599 # accessed under the method subfunction drawCategoryBrowser
600 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
601 # Clean out bogus first entry and sort them
602 unset( $tempout[0] );
604 # Output one per line
605 $s .= implode( "<br />\n", $tempout );
612 * Render the array as a serie of links.
613 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
614 * @param &skin Object: skin passed by reference
615 * @return String separated by >, terminate with "\n"
617 function drawCategoryBrowser( $tree, &$skin ) {
620 foreach ( $tree as $element => $parent ) {
621 if ( empty( $parent ) ) {
622 # element start a new list
625 # grab the others elements
626 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
629 # add our current element to the list
630 $eltitle = Title
::newFromText( $element );
631 $return .= $skin->link( $eltitle, $eltitle->getText() );
638 * The ->getCategories() form is deprecated, please instead use
639 * the ->getCategories( $out ) form with whatout OutputPage is on hand
641 function getCategories( OutputPage
$out=null ) {
642 if ( is_null( $out ) ) {
643 // Backwards compatibility for when there was no $out arg
648 $catlinks = $this->getCategoryLinks( $out );
650 $classes = 'catlinks';
654 // Check what we're showing
655 $allCats = $out->getCategoryLinks();
656 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
657 $this->mTitle
->getNamespace() == NS_CATEGORY
;
659 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
660 $classes .= ' catlinks-allhidden';
663 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
667 * This runs a hook to allow extensions placing their stuff after content
668 * and article metadata (e.g. categories).
669 * Note: This function has nothing to do with afterContent().
671 * This hook is placed here in order to allow using the same hook for all
672 * skins, both the SkinTemplate based ones and the older ones, which directly
673 * use this class to get their data.
675 * The output of this function gets processed in SkinTemplate::outputPage() for
676 * the SkinTemplate based skins, all other skins should directly echo it.
678 * Returns an empty string by default, if not changed by any hook function.
680 protected function afterContentHook() {
683 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
684 // adding just some spaces shouldn't toggle the output
685 // of the whole <div/>, so we use trim() here
686 if ( trim( $data ) != '' ) {
687 // Doing this here instead of in the skins to
688 // ensure that the div has the same ID in all
690 $data = "<div id='mw-data-after-content'>\n" .
695 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
702 * Generate debug data HTML for displaying at the bottom of the main content
704 * @return String HTML containing debug data, if enabled (otherwise empty).
706 protected function generateDebugHTML( OutputPage
$out ) {
709 if ( $wgShowDebug ) {
710 $listInternals = $this->formatDebugHTML( $out->mDebugtext
);
711 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
712 $listInternals . "</ul>\n";
718 private function formatDebugHTML( $debugText ) {
719 global $wgDebugTimestamps;
721 $lines = explode( "\n", $debugText );
725 foreach ( $lines as $line ) {
727 if ( $wgDebugTimestamps ) {
729 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
731 $line = substr( $line, strlen( $pre ) );
734 $display = ltrim( $line );
735 $ident = strlen( $line ) - strlen( $display );
736 $diff = $ident - $curIdent;
738 $display = $pre . $display;
739 if ( $display == '' ) {
740 $display = "\xc2\xa0";
743 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
746 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
748 $display = htmlspecialchars( $display );
752 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
753 } elseif ( $diff == 0 ) {
754 $ret .= "</li><li>\n";
756 $ret .= str_repeat( "<ul><li>\n", $diff );
758 $ret .= "<tt>$display</tt>\n";
763 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
769 * This gets called shortly before the </body> tag.
770 * @param $out OutputPage object
771 * @return String HTML-wrapped JS code to be put before </body>
773 function bottomScripts( $out ) {
774 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
775 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
777 return $bottomScriptText;
780 /** @return string Retrievied from HTML text */
781 function printSource() {
782 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
783 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
786 function getUndeleteLink() {
787 global $wgUser, $wgLang, $wgRequest;
789 $action = $wgRequest->getVal( 'action', 'view' );
791 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
792 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
793 $n = $this->mTitle
->isDeleted();
796 if ( $wgUser->isAllowed( 'undelete' ) ) {
797 $msg = 'thisisdeleted';
799 $msg = 'viewdeleted';
805 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
806 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
809 array( 'known', 'noclasses' )
819 * The format without an explicit $out argument is deprecated
821 function subPageSubtitle( OutputPage
$out=null ) {
822 if ( is_null( $out ) ) {
823 // Backwards compatibility for when there was no $out arg
830 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
834 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
835 $ptext = $this->mTitle
->getPrefixedText();
836 if ( preg_match( '/\//', $ptext ) ) {
837 $links = explode( '/', $ptext );
843 foreach ( $links as $link ) {
844 $growinglink .= $link;
846 $linkObj = Title
::newFromText( $growinglink );
848 if ( is_object( $linkObj ) && $linkObj->exists() ) {
849 $getlink = $this->link(
851 htmlspecialchars( $display ),
854 array( 'known', 'noclasses' )
860 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
862 $subpages .= '< ';
865 $subpages .= $getlink;
879 * Returns true if the IP should be shown in the header
881 function showIPinHeader() {
882 global $wgShowIPinHeader;
883 return $wgShowIPinHeader && session_id() != '';
886 function getSearchLink() {
887 $searchPage = SpecialPage
::getTitleFor( 'Search' );
888 return $searchPage->getLocalURL();
891 function escapeSearchLink() {
892 return htmlspecialchars( $this->getSearchLink() );
895 function getCopyright( $type = 'detect' ) {
896 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
898 if ( $type == 'detect' ) {
899 $diff = $wgRequest->getVal( 'diff' );
901 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
908 if ( $type == 'history' ) {
909 $msg = 'history_copyright';
916 if ( $wgRightsPage ) {
917 $title = Title
::newFromText( $wgRightsPage );
918 $link = $this->linkKnown( $title, $wgRightsText );
919 } elseif ( $wgRightsUrl ) {
920 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
921 } elseif ( $wgRightsText ) {
922 $link = $wgRightsText;
928 // Allow for site and per-namespace customization of copyright notice.
931 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle
, $type, &$msg, &$link, &$forContent ) );
934 $out .= wfMsgForContent( $msg, $link );
936 $out .= wfMsg( $msg, $link );
942 function getCopyrightIcon() {
943 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
947 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
948 $out = $wgCopyrightIcon;
949 } elseif ( $wgRightsIcon ) {
950 $icon = htmlspecialchars( $wgRightsIcon );
952 if ( $wgRightsUrl ) {
953 $url = htmlspecialchars( $wgRightsUrl );
954 $out .= '<a href="' . $url . '">';
957 $text = htmlspecialchars( $wgRightsText );
958 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
960 if ( $wgRightsUrl ) {
969 * Gets the powered by MediaWiki icon.
972 function getPoweredBy() {
975 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
976 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
977 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
982 * Get the timestamp of the latest revision, formatted in user language
984 * @param $article Article object. Used if we're working with the current revision
987 protected function lastModified( $article ) {
990 if ( !$this->isRevisionCurrent() ) {
991 $timestamp = Revision
::getTimestampFromId( $this->mTitle
, $this->mRevisionId
);
993 $timestamp = $article->getTimestamp();
997 $d = $wgLang->date( $timestamp, true );
998 $t = $wgLang->time( $timestamp, true );
999 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1004 if ( wfGetLB()->getLaggedSlaveMode() ) {
1005 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1011 function logoText( $align = '' ) {
1012 if ( $align != '' ) {
1013 $a = " align='{$align}'";
1018 $mp = wfMsg( 'mainpage' );
1019 $mptitle = Title
::newMainPage();
1020 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1022 $logourl = $this->getLogo();
1023 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1029 * Renders a $wgFooterIcons icon acording to the method's arguments
1030 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1031 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1033 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1034 if ( is_string( $icon ) ) {
1036 } else { // Assuming array
1037 $url = isset($icon["url"]) ?
$icon["url"] : null;
1038 unset( $icon["url"] );
1039 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1040 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1042 $html = htmlspecialchars( $icon["alt"] );
1045 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1052 * Gets the link to the wiki's main page.
1055 function mainPageLink() {
1057 Title
::newMainPage(),
1058 wfMsg( 'mainpage' ),
1061 array( 'known', 'noclasses' )
1067 public function footerLink( $desc, $page ) {
1068 // if the link description has been set to "-" in the default language,
1069 if ( wfMsgForContent( $desc ) == '-' ) {
1070 // then it is disabled, for all languages.
1073 // Otherwise, we display the link for the user, described in their
1074 // language (which may or may not be the same as the default language),
1075 // but we make the link target be the one site-wide page.
1076 $title = Title
::newFromText( wfMsgForContent( $page ) );
1078 return $this->linkKnown(
1080 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1086 * Gets the link to the wiki's privacy policy page.
1088 function privacyLink() {
1089 return $this->footerLink( 'privacy', 'privacypage' );
1093 * Gets the link to the wiki's about page.
1095 function aboutLink() {
1096 return $this->footerLink( 'aboutsite', 'aboutpage' );
1100 * Gets the link to the wiki's general disclaimers page.
1102 function disclaimerLink() {
1103 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1107 * Return URL options for the 'edit page' link.
1108 * This may include an 'oldid' specifier, if the current page view is such.
1113 function editUrlOptions() {
1114 $options = array( 'action' => 'edit' );
1116 if ( !$this->isRevisionCurrent() ) {
1117 $options['oldid'] = intval( $this->mRevisionId
);
1123 function showEmailUser( $id ) {
1125 $targetUser = User
::newFromId( $id );
1126 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1127 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1131 * Return a fully resolved style path url to images or styles stored in the common folder.
1132 * This method returns a url resolved using the configured skin style path
1133 * and includes the style version inside of the url.
1134 * @param $name String: The name or path of a skin resource file
1135 * @return String The fully resolved style path url including styleversion
1137 function getCommonStylePath( $name ) {
1138 global $wgStylePath, $wgStyleVersion;
1139 return "$wgStylePath/common/$name?$wgStyleVersion";
1143 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1144 * This method returns a url resolved using the configured skin style path
1145 * and includes the style version inside of the url.
1146 * @param $name String: The name or path of a skin resource file
1147 * @return String The fully resolved style path url including styleversion
1149 function getSkinStylePath( $name ) {
1150 global $wgStylePath, $wgStyleVersion;
1151 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1154 /* these are used extensively in SkinTemplate, but also some other places */
1155 static function makeMainPageUrl( $urlaction = '' ) {
1156 $title = Title
::newMainPage();
1157 self
::checkTitle( $title, '' );
1159 return $title->getLocalURL( $urlaction );
1162 static function makeSpecialUrl( $name, $urlaction = '' ) {
1163 $title = SpecialPage
::getTitleFor( $name );
1164 return $title->getLocalURL( $urlaction );
1167 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1168 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1169 return $title->getLocalURL( $urlaction );
1172 static function makeI18nUrl( $name, $urlaction = '' ) {
1173 $title = Title
::newFromText( wfMsgForContent( $name ) );
1174 self
::checkTitle( $title, $name );
1175 return $title->getLocalURL( $urlaction );
1178 static function makeUrl( $name, $urlaction = '' ) {
1179 $title = Title
::newFromText( $name );
1180 self
::checkTitle( $title, $name );
1182 return $title->getLocalURL( $urlaction );
1186 * If url string starts with http, consider as external URL, else
1189 static function makeInternalOrExternalUrl( $name ) {
1190 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1193 return self
::makeUrl( $name );
1197 # this can be passed the NS number as defined in Language.php
1198 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1199 $title = Title
::makeTitleSafe( $namespace, $name );
1200 self
::checkTitle( $title, $name );
1202 return $title->getLocalURL( $urlaction );
1205 /* these return an array with the 'href' and boolean 'exists' */
1206 static function makeUrlDetails( $name, $urlaction = '' ) {
1207 $title = Title
::newFromText( $name );
1208 self
::checkTitle( $title, $name );
1211 'href' => $title->getLocalURL( $urlaction ),
1212 'exists' => $title->getArticleID() != 0,
1217 * Make URL details where the article exists (or at least it's convenient to think so)
1219 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1220 $title = Title
::newFromText( $name );
1221 self
::checkTitle( $title, $name );
1224 'href' => $title->getLocalURL( $urlaction ),
1229 # make sure we have some title to operate on
1230 static function checkTitle( &$title, $name ) {
1231 if ( !is_object( $title ) ) {
1232 $title = Title
::newFromText( $name );
1233 if ( !is_object( $title ) ) {
1234 $title = Title
::newFromText( '--error: link target missing--' );
1240 * Build an array that represents the sidebar(s), the navigation bar among them
1244 function buildSidebar() {
1245 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1247 wfProfileIn( __METHOD__
);
1249 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1251 if ( $wgEnableSidebarCache ) {
1252 $cachedsidebar = $parserMemc->get( $key );
1253 if ( $cachedsidebar ) {
1254 wfProfileOut( __METHOD__
);
1255 return $cachedsidebar;
1260 $this->addToSidebar( $bar, 'sidebar' );
1262 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1263 if ( $wgEnableSidebarCache ) {
1264 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1267 wfProfileOut( __METHOD__
);
1271 * Add content from a sidebar system message
1272 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1274 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1276 * @param &$bar array
1277 * @param $message String
1279 function addToSidebar( &$bar, $message ) {
1280 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1284 * Add content from plain text
1286 * @param &$bar array
1287 * @param $text string
1289 function addToSidebarPlain( &$bar, $text ) {
1290 $lines = explode( "\n", $text );
1291 $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.
1295 foreach ( $lines as $line ) {
1296 if ( strpos( $line, '*' ) !== 0 ) {
1300 if ( strpos( $line, '**' ) !== 0 ) {
1301 $heading = trim( $line, '* ' );
1302 if ( !array_key_exists( $heading, $bar ) ) {
1303 $bar[$heading] = array();
1306 $line = trim( $line, '* ' );
1308 if ( strpos( $line, '|' ) !== false ) { // sanity check
1309 $line = MessageCache
::singleton()->transform( $line, false, null, $this->mTitle
);
1310 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1311 $link = wfMsgForContent( $line[0] );
1313 if ( $link == '-' ) {
1317 $text = wfMsgExt( $line[1], 'parsemag' );
1319 if ( wfEmptyMsg( $line[1] ) ) {
1323 if ( wfEmptyMsg( $line[0] ) ) {
1327 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1330 $title = Title
::newFromText( $link );
1333 $title = $title->fixSpecialName();
1334 $href = $title->getLocalURL();
1336 $href = 'INVALID-TITLE';
1340 $bar[$heading][] = array(
1343 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1346 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1349 $line = substr( $line, 2, strlen( $line ) - 4 );
1351 $options = new ParserOptions();
1352 $options->setEditSection( false );
1353 $options->setInterfaceMessage( true );
1354 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->mTitle
, $options )->getText();
1361 if ( count( $wikiBar ) > 0 ) {
1362 $bar = array_merge( $bar, $wikiBar );
1369 * Should we include common/wikiprintable.css? Skins that have their own
1370 * print stylesheet should override this and return false. (This is an
1371 * ugly hack to get Monobook to play nicely with
1372 * OutputPage::headElement().)
1376 public function commonPrintStylesheet() {
1381 * Gets new talk page messages for the current user.
1382 * @return MediaWiki message or if no new talk page messages, nothing
1383 * The format without an explicit $out argument is deprecated
1385 function getNewtalks( OutputPage
$out=null ) {
1388 if ( is_null( $out ) ) {
1389 // Backwards compatibility for when there was no $out arg
1394 $newtalks = $wgUser->getNewMessageLinks();
1397 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1398 $userTitle = $this->mUser
->getUserPage();
1399 $userTalkTitle = $userTitle->getTalkPage();
1401 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1402 $newMessagesLink = $this->link(
1404 wfMsgHtml( 'newmessageslink' ),
1406 array( 'redirect' => 'no' ),
1407 array( 'known', 'noclasses' )
1410 $newMessagesDiffLink = $this->link(
1412 wfMsgHtml( 'newmessagesdifflink' ),
1414 array( 'diff' => 'cur' ),
1415 array( 'known', 'noclasses' )
1419 'youhavenewmessages',
1421 $newMessagesDiffLink
1423 # Disable Squid cache
1424 $out->setSquidMaxage( 0 );
1426 } elseif ( count( $newtalks ) ) {
1427 // _>" " for BC <= 1.16
1428 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1431 foreach ( $newtalks as $newtalk ) {
1432 $msgs[] = Xml
::element(
1434 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1437 $parts = implode( $sep, $msgs );
1438 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1439 $out->setSquidMaxage( 0 );
1446 * Get a cached notice
1448 * @param $name String: message name, or 'default' for $wgSiteNotice
1449 * @return String: HTML fragment
1451 private function getCachedNotice( $name ) {
1452 global $wgOut, $wgRenderHashAppend, $parserMemc;
1454 wfProfileIn( __METHOD__
);
1458 if( $name === 'default' ) {
1460 global $wgSiteNotice;
1461 $notice = $wgSiteNotice;
1462 if( empty( $notice ) ) {
1463 wfProfileOut( __METHOD__
);
1467 $msg = wfMessage( $name )->inContentLanguage();
1468 if( $msg->isDisabled() ) {
1469 wfProfileOut( __METHOD__
);
1472 $notice = $msg->plain();
1475 // Use the extra hash appender to let eg SSL variants separately cache.
1476 $key = wfMemcKey( $name . $wgRenderHashAppend );
1477 $cachedNotice = $parserMemc->get( $key );
1478 if( is_array( $cachedNotice ) ) {
1479 if( md5( $notice ) == $cachedNotice['hash'] ) {
1480 $notice = $cachedNotice['html'];
1489 if( is_object( $wgOut ) ) {
1490 $parsed = $wgOut->parse( $notice );
1491 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1494 wfDebug( 'Skin::getCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
1499 $notice = '<div id="localNotice">' .$notice . '</div>';
1500 wfProfileOut( __METHOD__
);
1505 * Get a notice based on page's namespace
1507 * @return String: HTML fragment
1509 function getNamespaceNotice() {
1510 wfProfileIn( __METHOD__
);
1512 $key = 'namespacenotice-' . $this->mTitle
->getNsText();
1513 $namespaceNotice = $this->getCachedNotice( $key );
1514 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1515 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1517 $namespaceNotice = '';
1520 wfProfileOut( __METHOD__
);
1521 return $namespaceNotice;
1525 * Get the site notice
1527 * @return String: HTML fragment
1529 function getSiteNotice() {
1532 wfProfileIn( __METHOD__
);
1535 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1536 if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
1537 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1539 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1540 if ( !$anonNotice ) {
1541 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1543 $siteNotice = $anonNotice;
1546 if ( !$siteNotice ) {
1547 $siteNotice = $this->getCachedNotice( 'default' );
1551 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1552 wfProfileOut( __METHOD__
);