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 ContextSource
{
19 protected $skinname = 'standard';
20 protected $mRelevantTitle = null;
21 protected $mRelevantUser = null;
24 * Fetch the set of available skins.
25 * @return array of strings
27 static function getSkinNames() {
28 global $wgValidSkinNames;
29 static $skinsInitialised = false;
31 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
32 # Get a list of available skins
33 # Build using the regular expression '^(.*).php$'
34 # Array keys are all lower case, array value keep the case used by filename
36 wfProfileIn( __METHOD__
. '-init' );
38 global $wgStyleDirectory;
40 $skinDir = dir( $wgStyleDirectory );
42 # while code from www.php.net
43 while ( false !== ( $file = $skinDir->read() ) ) {
44 // Skip non-PHP files, hidden files, and '.dep' includes
47 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
49 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
53 $skinsInitialised = true;
54 wfProfileOut( __METHOD__
. '-init' );
56 return $wgValidSkinNames;
60 * Fetch the list of usable skins in regards to $wgSkipSkins.
61 * Useful for Special:Preferences and other places where you
62 * only want to show skins users _can_ use.
63 * @return array of strings
65 public static function getUsableSkins() {
68 $usableSkins = self
::getSkinNames();
70 foreach ( $wgSkipSkins as $skip ) {
71 unset( $usableSkins[$skip] );
78 * Normalize a skin preference value to a form that can be loaded.
79 * If a skin can't be found, it will fall back to the configured
80 * default (or the old 'Classic' skin if that's broken).
81 * @param $key String: 'monobook', 'standard', etc.
84 static function normalizeKey( $key ) {
85 global $wgDefaultSkin;
87 $skinNames = Skin
::getSkinNames();
90 // Don't return the default immediately;
91 // in a misconfiguration we need to fall back.
92 $key = $wgDefaultSkin;
95 if ( isset( $skinNames[$key] ) ) {
99 // Older versions of the software used a numeric setting
100 // in the user preferences.
107 if ( isset( $fallback[$key] ) ) {
108 $key = $fallback[$key];
111 if ( isset( $skinNames[$key] ) ) {
113 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
114 return $wgDefaultSkin;
121 * Factory method for loading a skin of a given type
122 * @param $key String: 'monobook', 'standard', etc.
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory;
128 $key = Skin
::normalizeKey( $key );
130 $skinNames = Skin
::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = "Skin{$skinName}";
134 # Grab the skin class and initialise it.
135 if ( !MWInit
::classExists( $className ) ) {
137 if ( !defined( 'MW_COMPILED' ) ) {
138 // Preload base classes to work around APC/PHP5 bug
139 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
140 if ( file_exists( $deps ) ) {
141 include_once( $deps );
143 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
146 # Check if we got if not failback to default skin
147 if ( !MWInit
::classExists( $className ) ) {
148 # DO NOT die if the class isn't found. This breaks maintenance
149 # scripts and can cause a user account to be unrecoverable
150 # except by SQL manipulation if a previously valid skin name
151 # is no longer valid.
152 wfDebug( "Skin class does not exist: $className\n" );
153 $className = 'SkinVector';
154 if ( !defined( 'MW_COMPILED' ) ) {
155 require_once( "{$wgStyleDirectory}/Vector.php" );
159 $skin = new $className( $key );
163 /** @return string skin name */
164 public function getSkinName() {
165 return $this->skinname
;
168 function initPage( OutputPage
$out ) {
169 wfProfileIn( __METHOD__
);
171 $this->preloadExistence();
173 wfProfileOut( __METHOD__
);
177 * Preload the existence of three commonly-requested pages in a single query
179 function preloadExistence() {
180 $user = $this->getUser();
183 $titles = array( $user->getUserPage(), $user->getTalkPage() );
186 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
188 } elseif ( $this->getTitle()->isTalkPage() ) {
189 $titles[] = $this->getTitle()->getSubjectPage();
191 $titles[] = $this->getTitle()->getTalkPage();
194 $lb = new LinkBatch( $titles );
195 $lb->setCaller( __METHOD__
);
200 * Get the current revision ID
204 public function getRevisionId() {
205 return $this->getOutput()->getRevisionId();
209 * Whether the revision displayed is the latest revision of the page
213 public function isRevisionCurrent() {
214 $revID = $this->getRevisionId();
215 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
219 * Set the "relevant" title
220 * @see self::getRelevantTitle()
221 * @param $t Title object to use
223 public function setRelevantTitle( $t ) {
224 $this->mRelevantTitle
= $t;
228 * Return the "relevant" title.
229 * A "relevant" title is not necessarily the actual title of the page.
230 * Special pages like Special:MovePage use set the page they are acting on
231 * as their "relevant" title, this allows the skin system to display things
232 * such as content tabs which belong to to that page instead of displaying
233 * a basic special page tab which has almost no meaning.
237 public function getRelevantTitle() {
238 if ( isset($this->mRelevantTitle
) ) {
239 return $this->mRelevantTitle
;
241 return $this->getTitle();
245 * Set the "relevant" user
246 * @see self::getRelevantUser()
247 * @param $u User object to use
249 public function setRelevantUser( $u ) {
250 $this->mRelevantUser
= $u;
254 * Return the "relevant" user.
255 * A "relevant" user is similar to a relevant title. Special pages like
256 * Special:Contributions mark the user which they are relevant to so that
257 * things like the toolbox can display the information they usually are only
258 * able to display on a user's userpage and talkpage.
261 public function getRelevantUser() {
262 if ( isset($this->mRelevantUser
) ) {
263 return $this->mRelevantUser
;
265 $title = $this->getRelevantTitle();
266 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
267 $rootUser = strtok( $title->getText(), '/' );
268 if ( User
::isIP( $rootUser ) ) {
269 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
271 $user = User
::newFromName( $rootUser, false );
272 if ( $user->isLoggedIn() ) {
273 $this->mRelevantUser
= $user;
276 return $this->mRelevantUser
;
282 * Outputs the HTML generated by other functions.
283 * @param $out OutputPage
285 abstract function outputPage( OutputPage
$out = null );
287 static function makeVariablesScript( $data ) {
289 return Html
::inlineScript(
290 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
298 * Generated JavaScript action=raw&gen=js
299 * This used to load MediaWiki:Common.js and the skin-specific style
300 * before the ResourceLoader.
302 * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some
304 * @param $skinName String: If set, overrides the skin name
307 public function generateUserJs( $skinName = null ) {
312 * Generate user stylesheet for action=raw&gen=css
314 * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some
318 public function generateUserStylesheet() {
323 * Get the query to generate a dynamic stylesheet
327 public static function getDynamicStylesheetQuery() {
328 global $wgSquidMaxage;
332 'maxage' => $wgSquidMaxage,
333 'usemsgcache' => 'yes',
334 'ctype' => 'text/css',
335 'smaxage' => $wgSquidMaxage,
340 * Add skin specific stylesheets
341 * Calling this method with an $out of anything but the same OutputPage
342 * inside ->getOutput() is deprecated. The $out arg is kept
343 * for compatibility purposes with skins.
344 * @param $out OutputPage
347 abstract function setupSkinUserCss( OutputPage
$out );
351 * @param $title Title
354 function getPageClasses( $title ) {
355 $numeric = 'ns-' . $title->getNamespace();
357 if ( $title->getNamespace() == NS_SPECIAL
) {
358 $type = 'ns-special';
359 // bug 23315: provide a class based on the canonical special page name without subpages
360 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
361 if ( $canonicalName ) {
362 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
364 $type .= ' mw-invalidspecialpage';
366 } elseif ( $title->isTalkPage() ) {
369 $type = 'ns-subject';
372 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
374 return "$numeric $type $name";
378 * This will be called by OutputPage::headElement when it is creating the
379 * <body> tag, skins can override it if they have a need to add in any
380 * body attributes or classes of their own.
381 * @param $out OutputPage
382 * @param $bodyAttrs Array
384 function addToBodyAttributes( $out, &$bodyAttrs ) {
385 // does nothing by default
397 function getCategoryLinks() {
398 global $wgUseCategoryBrowser;
400 $out = $this->getOutput();
401 $allCats = $out->getCategoryLinks();
403 if ( !count( $allCats ) ) {
411 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
413 if ( !empty( $allCats['normal'] ) ) {
414 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
416 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
417 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
418 Linker
::link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
419 . $colon . '<ul>' . $t . '</ul>' . '</div>';
423 if ( isset( $allCats['hidden'] ) ) {
424 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
425 $class = ' mw-hidden-cats-user-shown';
426 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
427 $class = ' mw-hidden-cats-ns-shown';
429 $class = ' mw-hidden-cats-hidden';
432 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
433 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
434 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
438 # optional 'dmoz-like' category browser. Will be shown under the list
439 # of categories an article belong to
440 if ( $wgUseCategoryBrowser ) {
441 $s .= '<br /><hr />';
443 # get a big array of the parents tree
444 $parenttree = $this->getTitle()->getParentCategoryTree();
445 # Skin object passed by reference cause it can not be
446 # accessed under the method subfunction drawCategoryBrowser
447 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
448 # Clean out bogus first entry and sort them
449 unset( $tempout[0] );
451 # Output one per line
452 $s .= implode( "<br />\n", $tempout );
459 * Render the array as a serie of links.
460 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
461 * @return String separated by >, terminate with "\n"
463 function drawCategoryBrowser( $tree ) {
466 foreach ( $tree as $element => $parent ) {
467 if ( empty( $parent ) ) {
468 # element start a new list
471 # grab the others elements
472 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
475 # add our current element to the list
476 $eltitle = Title
::newFromText( $element );
477 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
483 function getCategories() {
484 $out = $this->getOutput();
486 $catlinks = $this->getCategoryLinks();
488 $classes = 'catlinks';
490 // Check what we're showing
491 $allCats = $out->getCategoryLinks();
492 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
493 $this->getTitle()->getNamespace() == NS_CATEGORY
;
495 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
496 $classes .= ' catlinks-allhidden';
499 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
503 * This runs a hook to allow extensions placing their stuff after content
504 * and article metadata (e.g. categories).
505 * Note: This function has nothing to do with afterContent().
507 * This hook is placed here in order to allow using the same hook for all
508 * skins, both the SkinTemplate based ones and the older ones, which directly
509 * use this class to get their data.
511 * The output of this function gets processed in SkinTemplate::outputPage() for
512 * the SkinTemplate based skins, all other skins should directly echo it.
514 * @return String, empty by default, if not changed by any hook function.
516 protected function afterContentHook() {
519 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
520 // adding just some spaces shouldn't toggle the output
521 // of the whole <div/>, so we use trim() here
522 if ( trim( $data ) != '' ) {
523 // Doing this here instead of in the skins to
524 // ensure that the div has the same ID in all
526 $data = "<div id='mw-data-after-content'>\n" .
531 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
538 * Generate debug data HTML for displaying at the bottom of the main content
540 * @return String HTML containing debug data, if enabled (otherwise empty).
542 protected function generateDebugHTML() {
545 if ( $wgShowDebug ) {
546 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext
);
547 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
548 $listInternals . "</ul>\n";
554 private function formatDebugHTML( $debugText ) {
555 global $wgDebugTimestamps;
557 $lines = explode( "\n", $debugText );
561 foreach ( $lines as $line ) {
563 if ( $wgDebugTimestamps ) {
565 if ( preg_match( '/^(\d+\.\d+ \d+.\dM\s{2})/', $line, $matches ) ) {
567 $line = substr( $line, strlen( $pre ) );
570 $display = ltrim( $line );
571 $ident = strlen( $line ) - strlen( $display );
572 $diff = $ident - $curIdent;
574 $display = $pre . $display;
575 if ( $display == '' ) {
576 $display = "\xc2\xa0";
579 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
582 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
584 $display = htmlspecialchars( $display );
588 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
589 } elseif ( $diff == 0 ) {
590 $ret .= "</li><li>\n";
592 $ret .= str_repeat( "<ul><li>\n", $diff );
594 $ret .= "<tt>$display</tt>\n";
599 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
605 * This gets called shortly before the </body> tag.
607 * @return String HTML-wrapped JS code to be put before </body>
609 function bottomScripts() {
610 // TODO and the suckage continues. This function is really just a wrapper around
611 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
613 $bottomScriptText = $this->getOutput()->getBottomScripts();
614 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
616 return $bottomScriptText;
620 * Text with the permalink to the source page,
621 * usually shown on the footer of a printed page
623 * @return string HTML text with an URL
625 function printSource() {
626 $oldid = $this->getRevisionId();
628 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
630 // oldid not available for non existing pages
631 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
633 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
636 function getUndeleteLink() {
637 $action = $this->getRequest()->getVal( 'action', 'view' );
639 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
640 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
641 $n = $this->getTitle()->isDeleted();
645 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
646 $msg = 'thisisdeleted';
648 $msg = 'viewdeleted';
654 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
655 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) )
664 function subPageSubtitle() {
665 $out = $this->getOutput();
668 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
672 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
673 $ptext = $this->getTitle()->getPrefixedText();
674 if ( preg_match( '/\//', $ptext ) ) {
675 $links = explode( '/', $ptext );
681 foreach ( $links as $link ) {
682 $growinglink .= $link;
684 $linkObj = Title
::newFromText( $growinglink );
686 if ( is_object( $linkObj ) && $linkObj->exists() ) {
687 $getlink = Linker
::linkKnown(
689 htmlspecialchars( $display )
695 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
697 $subpages .= '< ';
700 $subpages .= $getlink;
714 * Returns true if the IP should be shown in the header
717 function showIPinHeader() {
718 global $wgShowIPinHeader;
719 return $wgShowIPinHeader && session_id() != '';
722 function getSearchLink() {
723 $searchPage = SpecialPage
::getTitleFor( 'Search' );
724 return $searchPage->getLocalURL();
727 function escapeSearchLink() {
728 return htmlspecialchars( $this->getSearchLink() );
731 function getCopyright( $type = 'detect' ) {
732 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
734 if ( $type == 'detect' ) {
735 if ( !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
742 if ( $type == 'history' ) {
743 $msg = 'history_copyright';
748 if ( $wgRightsPage ) {
749 $title = Title
::newFromText( $wgRightsPage );
750 $link = Linker
::linkKnown( $title, $wgRightsText );
751 } elseif ( $wgRightsUrl ) {
752 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
753 } elseif ( $wgRightsText ) {
754 $link = $wgRightsText;
760 // Allow for site and per-namespace customization of copyright notice.
763 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
766 $msg = wfMsgForContent( $msg, $link );
767 if ( $this->getLang()->getCode() !== $wgContLang->getCode() ) {
768 $msg = Html
::rawElement( 'span', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $msg );
772 return wfMsg( $msg, $link );
776 function getCopyrightIcon() {
777 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
781 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
782 $out = $wgCopyrightIcon;
783 } elseif ( $wgRightsIcon ) {
784 $icon = htmlspecialchars( $wgRightsIcon );
786 if ( $wgRightsUrl ) {
787 $url = htmlspecialchars( $wgRightsUrl );
788 $out .= '<a href="' . $url . '">';
791 $text = htmlspecialchars( $wgRightsText );
792 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
794 if ( $wgRightsUrl ) {
803 * Gets the powered by MediaWiki icon.
806 function getPoweredBy() {
809 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
810 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
811 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
816 * Get the timestamp of the latest revision, formatted in user language
818 * @param $article Article object. Used if we're working with the current revision
821 protected function lastModified( $article ) {
822 if ( !$this->isRevisionCurrent() ) {
823 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
825 $timestamp = $article->getTimestamp();
829 $d = $this->getLang()->date( $timestamp, true );
830 $t = $this->getLang()->time( $timestamp, true );
831 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
836 if ( wfGetLB()->getLaggedSlaveMode() ) {
837 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
843 function logoText( $align = '' ) {
844 if ( $align != '' ) {
845 $a = " align='{$align}'";
850 $mp = wfMsgHtml( 'mainpage' );
851 $mptitle = Title
::newMainPage();
852 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
854 $logourl = $this->getLogo();
855 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
861 * Renders a $wgFooterIcons icon acording to the method's arguments
862 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
863 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
864 * @return String HTML
866 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
867 if ( is_string( $icon ) ) {
869 } else { // Assuming array
870 $url = isset($icon["url"]) ?
$icon["url"] : null;
871 unset( $icon["url"] );
872 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
873 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
875 $html = htmlspecialchars( $icon["alt"] );
878 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
885 * Gets the link to the wiki's main page.
888 function mainPageLink() {
889 $s = Linker
::linkKnown(
890 Title
::newMainPage(),
891 wfMsgHtml( 'mainpage' )
897 public function footerLink( $desc, $page ) {
898 // if the link description has been set to "-" in the default language,
899 if ( wfMsgForContent( $desc ) == '-' ) {
900 // then it is disabled, for all languages.
903 // Otherwise, we display the link for the user, described in their
904 // language (which may or may not be the same as the default language),
905 // but we make the link target be the one site-wide page.
906 $title = Title
::newFromText( wfMsgForContent( $page ) );
908 return Linker
::linkKnown(
910 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
916 * Gets the link to the wiki's privacy policy page.
917 * @return String HTML
919 function privacyLink() {
920 return $this->footerLink( 'privacy', 'privacypage' );
924 * Gets the link to the wiki's about page.
925 * @return String HTML
927 function aboutLink() {
928 return $this->footerLink( 'aboutsite', 'aboutpage' );
932 * Gets the link to the wiki's general disclaimers page.
933 * @return String HTML
935 function disclaimerLink() {
936 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
940 * Return URL options for the 'edit page' link.
941 * This may include an 'oldid' specifier, if the current page view is such.
946 function editUrlOptions() {
947 $options = array( 'action' => 'edit' );
949 if ( !$this->isRevisionCurrent() ) {
950 $options['oldid'] = intval( $this->getRevisionId() );
956 function showEmailUser( $id ) {
957 $targetUser = User
::newFromId( $id );
958 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
959 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
963 * Return a fully resolved style path url to images or styles stored in the common folder.
964 * This method returns a url resolved using the configured skin style path
965 * and includes the style version inside of the url.
966 * @param $name String: The name or path of a skin resource file
967 * @return String The fully resolved style path url including styleversion
969 function getCommonStylePath( $name ) {
970 global $wgStylePath, $wgStyleVersion;
971 return "$wgStylePath/common/$name?$wgStyleVersion";
975 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
976 * This method returns a url resolved using the configured skin style path
977 * and includes the style version inside of the url.
978 * @param $name String: The name or path of a skin resource file
979 * @return String The fully resolved style path url including styleversion
981 function getSkinStylePath( $name ) {
982 global $wgStylePath, $wgStyleVersion;
983 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
986 /* these are used extensively in SkinTemplate, but also some other places */
987 static function makeMainPageUrl( $urlaction = '' ) {
988 $title = Title
::newMainPage();
989 self
::checkTitle( $title, '' );
991 return $title->getLocalURL( $urlaction );
994 static function makeSpecialUrl( $name, $urlaction = '' ) {
995 $title = SpecialPage
::getSafeTitleFor( $name );
996 return $title->getLocalURL( $urlaction );
999 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1000 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1001 return $title->getLocalURL( $urlaction );
1004 static function makeI18nUrl( $name, $urlaction = '' ) {
1005 $title = Title
::newFromText( wfMsgForContent( $name ) );
1006 self
::checkTitle( $title, $name );
1007 return $title->getLocalURL( $urlaction );
1010 static function makeUrl( $name, $urlaction = '' ) {
1011 $title = Title
::newFromText( $name );
1012 self
::checkTitle( $title, $name );
1014 return $title->getLocalURL( $urlaction );
1018 * If url string starts with http, consider as external URL, else
1020 * @param $name String
1021 * @return String URL
1023 static function makeInternalOrExternalUrl( $name ) {
1024 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1027 return self
::makeUrl( $name );
1031 # this can be passed the NS number as defined in Language.php
1032 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1033 $title = Title
::makeTitleSafe( $namespace, $name );
1034 self
::checkTitle( $title, $name );
1036 return $title->getLocalURL( $urlaction );
1039 /* these return an array with the 'href' and boolean 'exists' */
1040 static function makeUrlDetails( $name, $urlaction = '' ) {
1041 $title = Title
::newFromText( $name );
1042 self
::checkTitle( $title, $name );
1045 'href' => $title->getLocalURL( $urlaction ),
1046 'exists' => $title->getArticleID() != 0,
1051 * Make URL details where the article exists (or at least it's convenient to think so)
1052 * @param $name String Article name
1053 * @param $urlaction String
1056 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1057 $title = Title
::newFromText( $name );
1058 self
::checkTitle( $title, $name );
1061 'href' => $title->getLocalURL( $urlaction ),
1066 # make sure we have some title to operate on
1067 static function checkTitle( &$title, $name ) {
1068 if ( !is_object( $title ) ) {
1069 $title = Title
::newFromText( $name );
1070 if ( !is_object( $title ) ) {
1071 $title = Title
::newFromText( '--error: link target missing--' );
1077 * Build an array that represents the sidebar(s), the navigation bar among them
1081 function buildSidebar() {
1082 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1083 wfProfileIn( __METHOD__
);
1085 $key = wfMemcKey( 'sidebar', $this->getLang()->getCode() );
1087 if ( $wgEnableSidebarCache ) {
1088 $cachedsidebar = $parserMemc->get( $key );
1089 if ( $cachedsidebar ) {
1090 wfProfileOut( __METHOD__
);
1091 return $cachedsidebar;
1096 $this->addToSidebar( $bar, 'sidebar' );
1098 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1099 if ( $wgEnableSidebarCache ) {
1100 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1103 wfProfileOut( __METHOD__
);
1107 * Add content from a sidebar system message
1108 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1110 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1112 * @param &$bar array
1113 * @param $message String
1115 function addToSidebar( &$bar, $message ) {
1116 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1120 * Add content from plain text
1122 * @param &$bar array
1123 * @param $text string
1126 function addToSidebarPlain( &$bar, $text ) {
1127 $lines = explode( "\n", $text );
1131 foreach ( $lines as $line ) {
1132 if ( strpos( $line, '*' ) !== 0 ) {
1135 $line = rtrim( $line, "\r" ); // for Windows compat
1137 if ( strpos( $line, '**' ) !== 0 ) {
1138 $heading = trim( $line, '* ' );
1139 if ( !array_key_exists( $heading, $bar ) ) {
1140 $bar[$heading] = array();
1143 $line = trim( $line, '* ' );
1145 if ( strpos( $line, '|' ) !== false ) { // sanity check
1146 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1147 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1148 $extraAttribs = array();
1150 $msgLink = wfMessage( $line[0] )->inContentLanguage();
1151 if ( $msgLink->exists() ) {
1152 $link = $msgLink->text();
1153 if ( $link == '-' ) {
1160 $msgText = wfMessage( $line[1] );
1161 if ( $msgText->exists() ) {
1162 $text = $msgText->text();
1167 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1170 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1171 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1172 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1173 $extraAttribs['rel'] = 'nofollow';
1176 global $wgExternalLinkTarget;
1177 if ( $wgExternalLinkTarget) {
1178 $extraAttribs['target'] = $wgExternalLinkTarget;
1181 $title = Title
::newFromText( $link );
1184 $title = $title->fixSpecialName();
1185 $href = $title->getLinkURL();
1187 $href = 'INVALID-TITLE';
1191 $bar[$heading][] = array_merge( array(
1194 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1207 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1208 * print stylesheet should override this and return false. (This is an
1209 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1213 public function commonPrintStylesheet() {
1218 * Gets new talk page messages for the current user.
1219 * @return MediaWiki message or if no new talk page messages, nothing
1221 function getNewtalks() {
1222 $out = $this->getOutput();
1224 $newtalks = $this->getUser()->getNewMessageLinks();
1227 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1228 $userTitle = $this->getUser()->getUserPage();
1229 $userTalkTitle = $userTitle->getTalkPage();
1231 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1232 $newMessagesLink = Linker
::linkKnown(
1234 wfMsgHtml( 'newmessageslink' ),
1236 array( 'redirect' => 'no' )
1239 $newMessagesDiffLink = Linker
::linkKnown(
1241 wfMsgHtml( 'newmessagesdifflink' ),
1243 array( 'diff' => 'cur' )
1247 'youhavenewmessages',
1249 $newMessagesDiffLink
1251 # Disable Squid cache
1252 $out->setSquidMaxage( 0 );
1254 } elseif ( count( $newtalks ) ) {
1255 // _>" " for BC <= 1.16
1256 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1259 foreach ( $newtalks as $newtalk ) {
1260 $msgs[] = Xml
::element(
1262 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1265 $parts = implode( $sep, $msgs );
1266 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1267 $out->setSquidMaxage( 0 );
1274 * Get a cached notice
1276 * @param $name String: message name, or 'default' for $wgSiteNotice
1277 * @return String: HTML fragment
1279 private function getCachedNotice( $name ) {
1280 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1282 wfProfileIn( __METHOD__
);
1286 if( $name === 'default' ) {
1288 global $wgSiteNotice;
1289 $notice = $wgSiteNotice;
1290 if( empty( $notice ) ) {
1291 wfProfileOut( __METHOD__
);
1295 $msg = wfMessage( $name )->inContentLanguage();
1296 if( $msg->isDisabled() ) {
1297 wfProfileOut( __METHOD__
);
1300 $notice = $msg->plain();
1303 // Use the extra hash appender to let eg SSL variants separately cache.
1304 $key = wfMemcKey( $name . $wgRenderHashAppend );
1305 $cachedNotice = $parserMemc->get( $key );
1306 if( is_array( $cachedNotice ) ) {
1307 if( md5( $notice ) == $cachedNotice['hash'] ) {
1308 $notice = $cachedNotice['html'];
1317 $parsed = $this->getOutput()->parse( $notice );
1318 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1322 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1323 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $notice );
1324 wfProfileOut( __METHOD__
);
1329 * Get a notice based on page's namespace
1331 * @return String: HTML fragment
1333 function getNamespaceNotice() {
1334 wfProfileIn( __METHOD__
);
1336 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1337 $namespaceNotice = $this->getCachedNotice( $key );
1338 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1339 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1341 $namespaceNotice = '';
1344 wfProfileOut( __METHOD__
);
1345 return $namespaceNotice;
1349 * Get the site notice
1351 * @return String: HTML fragment
1353 function getSiteNotice() {
1354 wfProfileIn( __METHOD__
);
1357 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1358 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1359 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1361 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1362 if ( !$anonNotice ) {
1363 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1365 $siteNotice = $anonNotice;
1368 if ( !$siteNotice ) {
1369 $siteNotice = $this->getCachedNotice( 'default' );
1373 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1374 wfProfileOut( __METHOD__
);
1379 * Create a section edit link. This supersedes editSectionLink() and
1380 * editSectionLinkForOther().
1382 * @param $nt Title The title being linked to (may not be the same as
1383 * $wgTitle, if the section is included from a template)
1384 * @param $section string The designation of the section being pointed to,
1385 * to be included in the link, like "§ion=$section"
1386 * @param $tooltip string The tooltip to use for the link: will be escaped
1387 * and wrapped in the 'editsectionhint' message
1388 * @param $lang string Language code
1389 * @return string HTML to use for edit link
1391 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1392 // HTML generated here should probably have userlangattributes
1393 // added to it for LTR text on RTL pages
1395 if ( !is_null( $tooltip ) ) {
1396 # Bug 25462: undo double-escaping.
1397 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1398 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1400 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1402 array( 'action' => 'edit', 'section' => $section ),
1403 array( 'noclasses', 'known' )
1406 # Run the old hook. This takes up half of the function . . . hopefully
1407 # we can rid of it someday.
1410 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1411 $attribs = " title=\"$attribs\"";
1414 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1415 if ( !is_null( $result ) ) {
1416 # For reverse compatibility, add the brackets *after* the hook is
1417 # run, and even add them to hook-provided text. (This is the main
1418 # reason that the EditSectionLink hook is deprecated in favor of
1419 # DoEditSectionLink: it can't change the brackets or the span.)
1420 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1421 return "<span class=\"editsection\">$result</span>";
1424 # Add the brackets and the span, and *then* run the nice new hook, with
1425 # clean and non-redundant arguments.
1426 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1427 $result = "<span class=\"editsection\">$result</span>";
1429 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1434 * Use PHP's magic __call handler to intercept legacy calls to the linker
1435 * for backwards compatibility.
1437 * @param $fname String Name of called method
1438 * @param $args Array Arguments to the method
1440 function __call( $fname, $args ) {
1441 $realFunction = array( 'Linker', $fname );
1442 if ( is_callable( $realFunction ) ) {
1443 return call_user_func_array( $realFunction, $args );
1445 $className = get_class( $this );
1446 throw new MWException( "Call to undefined method $className::$fname" );