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.
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';
26 protected $mRelevantTitle = null;
27 protected $mRelevantUser = null;
30 * Fetch the set of available skins.
31 * @return array of strings
33 static function getSkinNames() {
34 global $wgValidSkinNames;
35 static $skinsInitialised = false;
37 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
38 # Get a list of available skins
39 # Build using the regular expression '^(.*).php$'
40 # Array keys are all lower case, array value keep the case used by filename
42 wfProfileIn( __METHOD__
. '-init' );
44 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
48 # while code from www.php.net
49 while ( false !== ( $file = $skinDir->read() ) ) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
53 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
55 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
59 $skinsInitialised = true;
60 wfProfileOut( __METHOD__
. '-init' );
62 return $wgValidSkinNames;
66 * Fetch the list of usable skins in regards to $wgSkipSkins.
67 * Useful for Special:Preferences and other places where you
68 * only want to show skins users _can_ use.
69 * @return array of strings
71 public static function getUsableSkins() {
74 $usableSkins = self
::getSkinNames();
76 foreach ( $wgSkipSkins as $skip ) {
77 unset( $usableSkins[$skip] );
84 * Normalize a skin preference value to a form that can be loaded.
85 * If a skin can't be found, it will fall back to the configured
86 * default (or the old 'Classic' skin if that's broken).
87 * @param $key String: 'monobook', 'standard', etc.
90 static function normalizeKey( $key ) {
91 global $wgDefaultSkin;
93 $skinNames = Skin
::getSkinNames();
96 // Don't return the default immediately;
97 // in a misconfiguration we need to fall back.
98 $key = $wgDefaultSkin;
101 if ( isset( $skinNames[$key] ) ) {
105 // Older versions of the software used a numeric setting
106 // in the user preferences.
113 if ( isset( $fallback[$key] ) ) {
114 $key = $fallback[$key];
117 if ( isset( $skinNames[$key] ) ) {
119 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
120 return $wgDefaultSkin;
127 * Factory method for loading a skin of a given type
128 * @param $key String: 'monobook', 'standard', etc.
131 static function &newFromKey( $key ) {
132 global $wgStyleDirectory;
134 $key = Skin
::normalizeKey( $key );
136 $skinNames = Skin
::getSkinNames();
137 $skinName = $skinNames[$key];
138 $className = "Skin{$skinName}";
140 # Grab the skin class and initialise it.
141 if ( !class_exists( $className ) ) {
142 // Preload base classes to work around APC/PHP5 bug
143 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
145 if ( file_exists( $deps ) ) {
146 include_once( $deps );
148 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
150 # Check if we got if not failback to default skin
151 if ( !class_exists( $className ) ) {
152 # DO NOT die if the class isn't found. This breaks maintenance
153 # scripts and can cause a user account to be unrecoverable
154 # except by SQL manipulation if a previously valid skin name
155 # is no longer valid.
156 wfDebug( "Skin class does not exist: $className\n" );
157 $className = 'SkinVector';
158 require_once( "{$wgStyleDirectory}/Vector.php" );
161 $skin = new $className;
165 /** @return string path to the skin stylesheet */
166 function getStylesheet() {
167 return 'common/wikistandard.css';
170 /** @return string skin name */
171 public function getSkinName() {
172 return $this->skinname
;
175 function initPage( OutputPage
$out ) {
176 wfProfileIn( __METHOD__
);
178 $this->mRevisionId
= $out->mRevisionId
;
179 $this->preloadExistence();
182 wfProfileOut( __METHOD__
);
186 * Preload the existence of three commonly-requested pages in a single query
188 function preloadExistence() {
189 $user = $this->getContext()->getUser();
192 $titles = array( $user->getUserPage(), $user->getTalkPage() );
195 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
197 } elseif ( $this->getTitle()->isTalkPage() ) {
198 $titles[] = $this->getTitle()->getSubjectPage();
200 $titles[] = $this->getTitle()->getTalkPage();
203 $lb = new LinkBatch( $titles );
204 $lb->setCaller( __METHOD__
);
209 * Set some local variables
211 protected function setMembers() {
212 $this->userpage
= $this->getContext()->getUser()->getUserPage()->getPrefixedText();
213 $this->usercss
= false;
217 * Whether the revision displayed is the latest revision of the page
221 public function isRevisionCurrent() {
222 return $this->mRevisionId
== 0 ||
$this->mRevisionId
== $this->getTitle()->getLatestRevID();
226 * Set the RequestContext used in this instance
228 * @param RequestContext $context
230 public function setContext( RequestContext
$context ) {
231 $this->mContext
= $context;
235 * Get the RequestContext used in this instance
237 * @return RequestContext
239 public function getContext() {
240 if ( !isset($this->mContext
) ) {
241 wfDebug( __METHOD__
. " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
242 $this->mContext
= RequestContext
::getMain();
244 return $this->mContext
;
251 public function getTitle() {
252 return $this->getContext()->getTitle();
259 public function getUser() {
260 return $this->getContext()->getUser();
264 * Set the "relevant" title
265 * @see self::getRelevantTitle()
266 * @param $t Title object to use
268 public function setRelevantTitle( $t ) {
269 $this->mRelevantTitle
= $t;
273 * Return the "relevant" title.
274 * A "relevant" title is not necessarily the actual title of the page.
275 * Special pages like Special:MovePage use set the page they are acting on
276 * as their "relevant" title, this allows the skin system to display things
277 * such as content tabs which belong to to that page instead of displaying
278 * a basic special page tab which has almost no meaning.
280 public function getRelevantTitle() {
281 if ( isset($this->mRelevantTitle
) ) {
282 return $this->mRelevantTitle
;
284 return $this->getTitle();
288 * Set the "relevant" user
289 * @see self::getRelevantUser()
290 * @param $u User object to use
292 public function setRelevantUser( $u ) {
293 $this->mRelevantUser
= $u;
297 * Return the "relevant" user.
298 * A "relevant" user is similar to a relevant title. Special pages like
299 * Special:Contributions mark the user which they are relevant to so that
300 * things like the toolbox can display the information they usually are only
301 * able to display on a user's userpage and talkpage.
303 public function getRelevantUser() {
304 if ( isset($this->mRelevantUser
) ) {
305 return $this->mRelevantUser
;
307 $title = $this->getRelevantTitle();
308 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
309 $rootUser = strtok( $title->getText(), '/' );
310 if ( User
::isIP( $rootUser ) ) {
311 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
313 $user = User
::newFromName( $rootUser );
314 if ( $user->isLoggedIn() ) {
315 $this->mRelevantUser
= $user;
318 return $this->mRelevantUser
;
324 * Outputs the HTML generated by other functions.
325 * @param $out Object: instance of OutputPage
328 function outputPage( OutputPage
$out ) {
329 global $wgDebugComments;
330 wfProfileIn( __METHOD__
);
332 $this->initPage( $out );
334 // See self::afterContentHook() for documentation
335 $afterContent = $this->afterContentHook();
337 $out->out( $out->headElement( $this ) );
339 if ( $wgDebugComments ) {
340 $out->out( "<!-- Debug output:\n" .
341 $out->mDebugtext
. "-->\n" );
344 $out->out( $this->beforeContent() );
346 $out->out( $out->mBodytext
. "\n" );
348 $out->out( $this->afterContent() );
350 $out->out( $afterContent );
352 $out->out( $this->bottomScripts( $out ) );
354 $out->out( wfReportTime() );
356 $out->out( "\n</body></html>" );
357 wfProfileOut( __METHOD__
);
360 static function makeVariablesScript( $data ) {
362 return Html
::inlineScript(
363 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
371 * To make it harder for someone to slip a user a fake
372 * user-JavaScript or user-CSS preview, a random token
373 * is associated with the login session. If it's not
374 * passed back with the preview request, we won't render
377 * @param $action String: 'edit', 'submit' etc.
380 public function userCanPreview( $action ) {
381 if ( $action != 'submit' ) {
384 if ( !$this->getContext()->getRequest()->wasPosted() ) {
387 if ( !$this->getTitle()->userCanEditCssSubpage() ) {
390 if ( !$this->getTitle()->userCanEditJsSubpage() ) {
394 return $this->getContext()->getUser()->matchEditToken(
395 $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
399 * Generated JavaScript action=raw&gen=js
400 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
401 * nated together. For some bizarre reason, it does *not* return any
402 * custom user JS from subpages. Huh?
404 * There's absolutely no reason to have separate Monobook/Common JSes.
405 * Any JS that cares can just check the skin variable generated at the
406 * top. For now Monobook.js will be maintained, but it should be consi-
409 * @param $skinName String: If set, overrides the skin name
412 public function generateUserJs( $skinName = null ) {
414 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
420 * Generate user stylesheet for action=raw&gen=css
422 public function generateUserStylesheet() {
424 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
430 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
431 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
433 protected function reallyGenerateUserStylesheet() {
435 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
443 function setupUserCss( OutputPage
$out ) {
444 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
446 wfProfileIn( __METHOD__
);
448 $this->setupSkinUserCss( $out );
449 // Add any extension CSS
450 foreach ( $out->getExtStyle() as $url ) {
451 $out->addStyle( $url );
454 // Per-site custom styles
455 if ( $wgUseSiteCss ) {
456 $out->addModuleStyles( array( 'site', 'noscript' ) );
457 if( $this->getContext()->getUser()->isLoggedIn() ){
458 $out->addModuleStyles( 'user.groups' );
462 // Per-user custom styles
463 if ( $wgAllowUserCss ) {
464 if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) {
465 // @FIXME: properly escape the cdata!
466 $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
468 $out->addModuleStyles( 'user' );
472 // Per-user preference styles
473 if ( $wgAllowUserCssPrefs ) {
474 $out->addModuleStyles( 'user.options' );
477 wfProfileOut( __METHOD__
);
481 * Get the query to generate a dynamic stylesheet
485 public static function getDynamicStylesheetQuery() {
486 global $wgSquidMaxage;
490 'maxage' => $wgSquidMaxage,
491 'usemsgcache' => 'yes',
492 'ctype' => 'text/css',
493 'smaxage' => $wgSquidMaxage,
498 * Add skin specific stylesheets
499 * @param $out OutputPage
502 abstract function setupSkinUserCss( OutputPage
$out );
504 function getPageClasses( $title ) {
505 $numeric = 'ns-' . $title->getNamespace();
507 if ( $title->getNamespace() == NS_SPECIAL
) {
508 $type = 'ns-special';
509 // bug 23315: provide a class based on the canonical special page name without subpages
510 list( $canonicalName ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
511 if ( $canonicalName ) {
512 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
514 $type .= ' mw-invalidspecialpage';
516 } elseif ( $title->isTalkPage() ) {
519 $type = 'ns-subject';
522 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
524 return "$numeric $type $name";
528 * This will be called by OutputPage::headElement when it is creating the
529 * <body> tag, skins can override it if they have a need to add in any
530 * body attributes or classes of their own.
532 function addToBodyAttributes( $out, &$bodyAttrs ) {
533 // does nothing by default
545 * The format without an explicit $out argument is deprecated
547 function getCategoryLinks( OutputPage
$out=null ) {
548 global $wgUseCategoryBrowser, $wgContLang;
550 if ( count( $out->mCategoryLinks
) == 0 ) {
555 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
557 // Use Unicode bidi embedding override characters,
558 // to make sure links don't smash each other up in ugly ways.
559 $dir = $wgContLang->getDir();
560 $embed = "<span dir='$dir'>";
563 $allCats = $out->getCategoryLinks();
565 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
567 if ( !empty( $allCats['normal'] ) ) {
568 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
570 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
571 $s .= '<div id="mw-normal-catlinks">' .
572 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
573 . $colon . $t . '</div>';
577 if ( isset( $allCats['hidden'] ) ) {
578 if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
579 $class = 'mw-hidden-cats-user-shown';
580 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
581 $class = 'mw-hidden-cats-ns-shown';
583 $class = 'mw-hidden-cats-hidden';
586 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
587 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
588 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
592 # optional 'dmoz-like' category browser. Will be shown under the list
593 # of categories an article belong to
594 if ( $wgUseCategoryBrowser ) {
595 $s .= '<br /><hr />';
597 # get a big array of the parents tree
598 $parenttree = $this->getTitle()->getParentCategoryTree();
599 # Skin object passed by reference cause it can not be
600 # accessed under the method subfunction drawCategoryBrowser
601 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
602 # Clean out bogus first entry and sort them
603 unset( $tempout[0] );
605 # Output one per line
606 $s .= implode( "<br />\n", $tempout );
613 * Render the array as a serie of links.
614 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
615 * @param &skin Object: skin passed by reference
616 * @return String separated by >, terminate with "\n"
618 function drawCategoryBrowser( $tree, &$skin ) {
621 foreach ( $tree as $element => $parent ) {
622 if ( empty( $parent ) ) {
623 # element start a new list
626 # grab the others elements
627 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
630 # add our current element to the list
631 $eltitle = Title
::newFromText( $element );
632 $return .= $skin->link( $eltitle, $eltitle->getText() );
639 * The ->getCategories() form is deprecated, please instead use
640 * the ->getCategories( $out ) form with whatout OutputPage is on hand
642 function getCategories( OutputPage
$out=null ) {
644 $catlinks = $this->getCategoryLinks( $out );
646 $classes = 'catlinks';
648 // Check what we're showing
649 $allCats = $out->getCategoryLinks();
650 $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ||
651 $this->getTitle()->getNamespace() == NS_CATEGORY
;
653 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
654 $classes .= ' catlinks-allhidden';
657 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
661 * This runs a hook to allow extensions placing their stuff after content
662 * and article metadata (e.g. categories).
663 * Note: This function has nothing to do with afterContent().
665 * This hook is placed here in order to allow using the same hook for all
666 * skins, both the SkinTemplate based ones and the older ones, which directly
667 * use this class to get their data.
669 * The output of this function gets processed in SkinTemplate::outputPage() for
670 * the SkinTemplate based skins, all other skins should directly echo it.
672 * Returns an empty string by default, if not changed by any hook function.
674 protected function afterContentHook() {
677 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
678 // adding just some spaces shouldn't toggle the output
679 // of the whole <div/>, so we use trim() here
680 if ( trim( $data ) != '' ) {
681 // Doing this here instead of in the skins to
682 // ensure that the div has the same ID in all
684 $data = "<div id='mw-data-after-content'>\n" .
689 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
696 * Generate debug data HTML for displaying at the bottom of the main content
698 * @return String HTML containing debug data, if enabled (otherwise empty).
700 protected function generateDebugHTML( OutputPage
$out ) {
703 if ( $wgShowDebug ) {
704 $listInternals = $this->formatDebugHTML( $out->mDebugtext
);
705 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
706 $listInternals . "</ul>\n";
712 private function formatDebugHTML( $debugText ) {
713 global $wgDebugTimestamps;
715 $lines = explode( "\n", $debugText );
719 foreach ( $lines as $line ) {
721 if ( $wgDebugTimestamps ) {
723 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
725 $line = substr( $line, strlen( $pre ) );
728 $display = ltrim( $line );
729 $ident = strlen( $line ) - strlen( $display );
730 $diff = $ident - $curIdent;
732 $display = $pre . $display;
733 if ( $display == '' ) {
734 $display = "\xc2\xa0";
737 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
740 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
742 $display = htmlspecialchars( $display );
746 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
747 } elseif ( $diff == 0 ) {
748 $ret .= "</li><li>\n";
750 $ret .= str_repeat( "<ul><li>\n", $diff );
752 $ret .= "<tt>$display</tt>\n";
757 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
763 * This gets called shortly before the </body> tag.
764 * @param $out OutputPage object
765 * @return String HTML-wrapped JS code to be put before </body>
767 function bottomScripts( $out ) {
768 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
769 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
771 return $bottomScriptText;
774 /** @return string Retrievied from HTML text */
775 function printSource() {
776 $url = htmlspecialchars( $this->getTitle()->getFullURL() );
777 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
780 function getUndeleteLink() {
781 $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
783 if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
784 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
785 $n = $this->getTitle()->isDeleted();
788 if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
789 $msg = 'thisisdeleted';
791 $msg = 'viewdeleted';
797 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
798 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ),
801 array( 'known', 'noclasses' )
811 * The format without an explicit $out argument is deprecated
813 function subPageSubtitle( OutputPage
$out=null ) {
814 $out = $this->getContext()->getOutput();
817 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
821 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
822 $ptext = $this->getTitle()->getPrefixedText();
823 if ( preg_match( '/\//', $ptext ) ) {
824 $links = explode( '/', $ptext );
830 foreach ( $links as $link ) {
831 $growinglink .= $link;
833 $linkObj = Title
::newFromText( $growinglink );
835 if ( is_object( $linkObj ) && $linkObj->exists() ) {
836 $getlink = $this->link(
838 htmlspecialchars( $display ),
841 array( 'known', 'noclasses' )
847 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
849 $subpages .= '< ';
852 $subpages .= $getlink;
866 * Returns true if the IP should be shown in the header
868 function showIPinHeader() {
869 global $wgShowIPinHeader;
870 return $wgShowIPinHeader && session_id() != '';
873 function getSearchLink() {
874 $searchPage = SpecialPage
::getTitleFor( 'Search' );
875 return $searchPage->getLocalURL();
878 function escapeSearchLink() {
879 return htmlspecialchars( $this->getSearchLink() );
882 function getCopyright( $type = 'detect' ) {
883 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
885 if ( $type == 'detect' ) {
886 $diff = $this->getContext()->getRequest()->getVal( 'diff' );
888 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
895 if ( $type == 'history' ) {
896 $msg = 'history_copyright';
903 if ( $wgRightsPage ) {
904 $title = Title
::newFromText( $wgRightsPage );
905 $link = $this->linkKnown( $title, $wgRightsText );
906 } elseif ( $wgRightsUrl ) {
907 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
908 } elseif ( $wgRightsText ) {
909 $link = $wgRightsText;
915 // Allow for site and per-namespace customization of copyright notice.
918 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
921 $out .= wfMsgForContent( $msg, $link );
923 $out .= wfMsg( $msg, $link );
929 function getCopyrightIcon() {
930 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
934 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
935 $out = $wgCopyrightIcon;
936 } elseif ( $wgRightsIcon ) {
937 $icon = htmlspecialchars( $wgRightsIcon );
939 if ( $wgRightsUrl ) {
940 $url = htmlspecialchars( $wgRightsUrl );
941 $out .= '<a href="' . $url . '">';
944 $text = htmlspecialchars( $wgRightsText );
945 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
947 if ( $wgRightsUrl ) {
956 * Gets the powered by MediaWiki icon.
959 function getPoweredBy() {
962 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
963 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
964 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
969 * Get the timestamp of the latest revision, formatted in user language
971 * @param $article Article object. Used if we're working with the current revision
974 protected function lastModified( $article ) {
975 if ( !$this->isRevisionCurrent() ) {
976 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->mRevisionId
);
978 $timestamp = $article->getTimestamp();
982 $d = $this->getContext()->getLang()->date( $timestamp, true );
983 $t = $this->getContext()->getLang()->time( $timestamp, true );
984 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
989 if ( wfGetLB()->getLaggedSlaveMode() ) {
990 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
996 function logoText( $align = '' ) {
997 if ( $align != '' ) {
998 $a = " align='{$align}'";
1003 $mp = wfMsg( 'mainpage' );
1004 $mptitle = Title
::newMainPage();
1005 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1007 $logourl = $this->getLogo();
1008 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1014 * Renders a $wgFooterIcons icon acording to the method's arguments
1015 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1016 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1018 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1019 if ( is_string( $icon ) ) {
1021 } else { // Assuming array
1022 $url = isset($icon["url"]) ?
$icon["url"] : null;
1023 unset( $icon["url"] );
1024 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1025 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1027 $html = htmlspecialchars( $icon["alt"] );
1030 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1037 * Gets the link to the wiki's main page.
1040 function mainPageLink() {
1042 Title
::newMainPage(),
1043 wfMsg( 'mainpage' ),
1046 array( 'known', 'noclasses' )
1052 public function footerLink( $desc, $page ) {
1053 // if the link description has been set to "-" in the default language,
1054 if ( wfMsgForContent( $desc ) == '-' ) {
1055 // then it is disabled, for all languages.
1058 // Otherwise, we display the link for the user, described in their
1059 // language (which may or may not be the same as the default language),
1060 // but we make the link target be the one site-wide page.
1061 $title = Title
::newFromText( wfMsgForContent( $page ) );
1063 return $this->linkKnown(
1065 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1071 * Gets the link to the wiki's privacy policy page.
1073 function privacyLink() {
1074 return $this->footerLink( 'privacy', 'privacypage' );
1078 * Gets the link to the wiki's about page.
1080 function aboutLink() {
1081 return $this->footerLink( 'aboutsite', 'aboutpage' );
1085 * Gets the link to the wiki's general disclaimers page.
1087 function disclaimerLink() {
1088 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1092 * Return URL options for the 'edit page' link.
1093 * This may include an 'oldid' specifier, if the current page view is such.
1098 function editUrlOptions() {
1099 $options = array( 'action' => 'edit' );
1101 if ( !$this->isRevisionCurrent() ) {
1102 $options['oldid'] = intval( $this->mRevisionId
);
1108 function showEmailUser( $id ) {
1109 $targetUser = User
::newFromId( $id );
1110 return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1111 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1115 * Return a fully resolved style path url to images or styles stored in the common folder.
1116 * This method returns a url resolved using the configured skin style path
1117 * and includes the style version inside of the url.
1118 * @param $name String: The name or path of a skin resource file
1119 * @return String The fully resolved style path url including styleversion
1121 function getCommonStylePath( $name ) {
1122 global $wgStylePath, $wgStyleVersion;
1123 return "$wgStylePath/common/$name?$wgStyleVersion";
1127 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1128 * This method returns a url resolved using the configured skin style path
1129 * and includes the style version inside of the url.
1130 * @param $name String: The name or path of a skin resource file
1131 * @return String The fully resolved style path url including styleversion
1133 function getSkinStylePath( $name ) {
1134 global $wgStylePath, $wgStyleVersion;
1135 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1138 /* these are used extensively in SkinTemplate, but also some other places */
1139 static function makeMainPageUrl( $urlaction = '' ) {
1140 $title = Title
::newMainPage();
1141 self
::checkTitle( $title, '' );
1143 return $title->getLocalURL( $urlaction );
1146 static function makeSpecialUrl( $name, $urlaction = '' ) {
1147 $title = SpecialPage
::getTitleFor( $name );
1148 return $title->getLocalURL( $urlaction );
1151 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1152 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1153 return $title->getLocalURL( $urlaction );
1156 static function makeI18nUrl( $name, $urlaction = '' ) {
1157 $title = Title
::newFromText( wfMsgForContent( $name ) );
1158 self
::checkTitle( $title, $name );
1159 return $title->getLocalURL( $urlaction );
1162 static function makeUrl( $name, $urlaction = '' ) {
1163 $title = Title
::newFromText( $name );
1164 self
::checkTitle( $title, $name );
1166 return $title->getLocalURL( $urlaction );
1170 * If url string starts with http, consider as external URL, else
1173 static function makeInternalOrExternalUrl( $name ) {
1174 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1177 return self
::makeUrl( $name );
1181 # this can be passed the NS number as defined in Language.php
1182 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1183 $title = Title
::makeTitleSafe( $namespace, $name );
1184 self
::checkTitle( $title, $name );
1186 return $title->getLocalURL( $urlaction );
1189 /* these return an array with the 'href' and boolean 'exists' */
1190 static function makeUrlDetails( $name, $urlaction = '' ) {
1191 $title = Title
::newFromText( $name );
1192 self
::checkTitle( $title, $name );
1195 'href' => $title->getLocalURL( $urlaction ),
1196 'exists' => $title->getArticleID() != 0,
1201 * Make URL details where the article exists (or at least it's convenient to think so)
1203 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1204 $title = Title
::newFromText( $name );
1205 self
::checkTitle( $title, $name );
1208 'href' => $title->getLocalURL( $urlaction ),
1213 # make sure we have some title to operate on
1214 static function checkTitle( &$title, $name ) {
1215 if ( !is_object( $title ) ) {
1216 $title = Title
::newFromText( $name );
1217 if ( !is_object( $title ) ) {
1218 $title = Title
::newFromText( '--error: link target missing--' );
1224 * Build an array that represents the sidebar(s), the navigation bar among them
1228 function buildSidebar() {
1229 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1230 wfProfileIn( __METHOD__
);
1232 $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
1234 if ( $wgEnableSidebarCache ) {
1235 $cachedsidebar = $parserMemc->get( $key );
1236 if ( $cachedsidebar ) {
1237 wfProfileOut( __METHOD__
);
1238 return $cachedsidebar;
1243 $this->addToSidebar( $bar, 'sidebar' );
1245 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1246 if ( $wgEnableSidebarCache ) {
1247 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1250 wfProfileOut( __METHOD__
);
1254 * Add content from a sidebar system message
1255 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1257 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1259 * @param &$bar array
1260 * @param $message String
1262 function addToSidebar( &$bar, $message ) {
1263 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1267 * Add content from plain text
1269 * @param &$bar array
1270 * @param $text string
1272 function addToSidebarPlain( &$bar, $text ) {
1273 $lines = explode( "\n", $text );
1274 $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.
1278 foreach ( $lines as $line ) {
1279 if ( strpos( $line, '*' ) !== 0 ) {
1283 if ( strpos( $line, '**' ) !== 0 ) {
1284 $heading = trim( $line, '* ' );
1285 if ( !array_key_exists( $heading, $bar ) ) {
1286 $bar[$heading] = array();
1289 $line = trim( $line, '* ' );
1291 if ( strpos( $line, '|' ) !== false ) { // sanity check
1292 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1293 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1294 $link = wfMsgForContent( $line[0] );
1296 if ( $link == '-' ) {
1300 $text = wfMsgExt( $line[1], 'parsemag' );
1302 if ( wfEmptyMsg( $line[1] ) ) {
1306 if ( wfEmptyMsg( $line[0] ) ) {
1310 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1313 $title = Title
::newFromText( $link );
1316 $title = $title->fixSpecialName();
1317 $href = $title->getLocalURL();
1319 $href = 'INVALID-TITLE';
1323 $bar[$heading][] = array(
1326 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1329 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1332 $line = substr( $line, 2, strlen( $line ) - 4 );
1334 $options = new ParserOptions();
1335 $options->setEditSection( false );
1336 $options->setInterfaceMessage( true );
1337 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
1344 if ( count( $wikiBar ) > 0 ) {
1345 $bar = array_merge( $bar, $wikiBar );
1352 * Should we include common/wikiprintable.css? Skins that have their own
1353 * print stylesheet should override this and return false. (This is an
1354 * ugly hack to get Monobook to play nicely with
1355 * OutputPage::headElement().)
1359 public function commonPrintStylesheet() {
1364 * Gets new talk page messages for the current user.
1365 * @return MediaWiki message or if no new talk page messages, nothing
1367 function getNewtalks() {
1368 $out = $this->getContext()->getOutput();
1370 $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
1373 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1374 $userTitle = $this->getUser()->getUserPage();
1375 $userTalkTitle = $userTitle->getTalkPage();
1377 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1378 $newMessagesLink = $this->link(
1380 wfMsgHtml( 'newmessageslink' ),
1382 array( 'redirect' => 'no' ),
1383 array( 'known', 'noclasses' )
1386 $newMessagesDiffLink = $this->link(
1388 wfMsgHtml( 'newmessagesdifflink' ),
1390 array( 'diff' => 'cur' ),
1391 array( 'known', 'noclasses' )
1395 'youhavenewmessages',
1397 $newMessagesDiffLink
1399 # Disable Squid cache
1400 $out->setSquidMaxage( 0 );
1402 } elseif ( count( $newtalks ) ) {
1403 // _>" " for BC <= 1.16
1404 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1407 foreach ( $newtalks as $newtalk ) {
1408 $msgs[] = Xml
::element(
1410 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1413 $parts = implode( $sep, $msgs );
1414 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1415 $out->setSquidMaxage( 0 );
1422 * Get a cached notice
1424 * @param $name String: message name, or 'default' for $wgSiteNotice
1425 * @return String: HTML fragment
1427 private function getCachedNotice( $name ) {
1428 global $wgRenderHashAppend, $parserMemc;
1430 wfProfileIn( __METHOD__
);
1434 if( $name === 'default' ) {
1436 global $wgSiteNotice;
1437 $notice = $wgSiteNotice;
1438 if( empty( $notice ) ) {
1439 wfProfileOut( __METHOD__
);
1443 $msg = wfMessage( $name )->inContentLanguage();
1444 if( $msg->isDisabled() ) {
1445 wfProfileOut( __METHOD__
);
1448 $notice = $msg->plain();
1451 // Use the extra hash appender to let eg SSL variants separately cache.
1452 $key = wfMemcKey( $name . $wgRenderHashAppend );
1453 $cachedNotice = $parserMemc->get( $key );
1454 if( is_array( $cachedNotice ) ) {
1455 if( md5( $notice ) == $cachedNotice['hash'] ) {
1456 $notice = $cachedNotice['html'];
1465 $parsed = $this->getContext()->getOutput()->parse( $notice );
1466 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1470 $notice = '<div id="localNotice">' .$notice . '</div>';
1471 wfProfileOut( __METHOD__
);
1476 * Get a notice based on page's namespace
1478 * @return String: HTML fragment
1480 function getNamespaceNotice() {
1481 wfProfileIn( __METHOD__
);
1483 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1484 $namespaceNotice = $this->getCachedNotice( $key );
1485 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1486 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1488 $namespaceNotice = '';
1491 wfProfileOut( __METHOD__
);
1492 return $namespaceNotice;
1496 * Get the site notice
1498 * @return String: HTML fragment
1500 function getSiteNotice() {
1501 wfProfileIn( __METHOD__
);
1504 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1505 if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) {
1506 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1508 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1509 if ( !$anonNotice ) {
1510 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1512 $siteNotice = $anonNotice;
1515 if ( !$siteNotice ) {
1516 $siteNotice = $this->getCachedNotice( 'default' );
1520 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1521 wfProfileOut( __METHOD__
);
1526 * Create a section edit link. This supersedes editSectionLink() and
1527 * editSectionLinkForOther().
1529 * @param $nt Title The title being linked to (may not be the same as
1530 * $wgTitle, if the section is included from a template)
1531 * @param $section string The designation of the section being pointed to,
1532 * to be included in the link, like "§ion=$section"
1533 * @param $tooltip string The tooltip to use for the link: will be escaped
1534 * and wrapped in the 'editsectionhint' message
1535 * @param $lang string Language code
1536 * @return string HTML to use for edit link
1538 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1539 // HTML generated here should probably have userlangattributes
1540 // added to it for LTR text on RTL pages
1542 if ( !is_null( $tooltip ) ) {
1543 # Bug 25462: undo double-escaping.
1544 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1545 $attribs['title'] = wfMsgReal( 'editsectionhint', array( $tooltip ), true, $lang );
1547 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1549 array( 'action' => 'edit', 'section' => $section ),
1550 array( 'noclasses', 'known' )
1553 # Run the old hook. This takes up half of the function . . . hopefully
1554 # we can rid of it someday.
1557 $attribs = htmlspecialchars( wfMsgReal( 'editsectionhint', array( $tooltip ), true, $lang ) );
1558 $attribs = " title=\"$attribs\"";
1561 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1562 if ( !is_null( $result ) ) {
1563 # For reverse compatibility, add the brackets *after* the hook is
1564 # run, and even add them to hook-provided text. (This is the main
1565 # reason that the EditSectionLink hook is deprecated in favor of
1566 # DoEditSectionLink: it can't change the brackets or the span.)
1567 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1568 return "<span class=\"editsection\">$result</span>";
1571 # Add the brackets and the span, and *then* run the nice new hook, with
1572 # clean and non-redundant arguments.
1573 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1574 $result = "<span class=\"editsection\">$result</span>";
1576 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1581 * Use PHP's magic __call handler to intercept legacy calls to the linker
1582 * for backwards compatibility.
1584 * @param $fname String Name of called method
1585 * @param $args Array Arguments to the method
1587 function __call( $fname, $args ) {
1588 if ( method_exists( 'Linker', $fname ) ) {
1589 return call_user_func_array( array( 'Linker', $fname ), $args );
1591 $className = get_class( $this );
1592 throw new MWException( "Call to undefined method $className::$fname" );