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 associative 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 skinname messages for available skins.
61 * @return array of strings
63 static function getSkinNameMessages() {
65 foreach( self
::getSkinNames() as $skinKey => $skinName ) {
66 $messages[] = "skinname-$skinKey";
72 * Fetch the list of usable skins in regards to $wgSkipSkins.
73 * Useful for Special:Preferences and other places where you
74 * only want to show skins users _can_ use.
75 * @return array of strings
77 public static function getUsableSkins() {
80 $usableSkins = self
::getSkinNames();
82 foreach ( $wgSkipSkins as $skip ) {
83 unset( $usableSkins[$skip] );
90 * Normalize a skin preference value to a form that can be loaded.
91 * If a skin can't be found, it will fall back to the configured
92 * default (or the old 'Classic' skin if that's broken).
93 * @param $key String: 'monobook', 'standard', etc.
96 static function normalizeKey( $key ) {
97 global $wgDefaultSkin;
99 $skinNames = Skin
::getSkinNames();
101 if ( $key == '' ||
$key == 'default' ) {
102 // Don't return the default immediately;
103 // in a misconfiguration we need to fall back.
104 $key = $wgDefaultSkin;
107 if ( isset( $skinNames[$key] ) ) {
111 // Older versions of the software used a numeric setting
112 // in the user preferences.
119 if ( isset( $fallback[$key] ) ) {
120 $key = $fallback[$key];
123 if ( isset( $skinNames[$key] ) ) {
125 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
126 return $wgDefaultSkin;
133 * Factory method for loading a skin of a given type
134 * @param $key String: 'monobook', 'standard', etc.
137 static function &newFromKey( $key ) {
138 global $wgStyleDirectory;
140 $key = Skin
::normalizeKey( $key );
142 $skinNames = Skin
::getSkinNames();
143 $skinName = $skinNames[$key];
144 $className = "Skin{$skinName}";
146 # Grab the skin class and initialise it.
147 if ( !MWInit
::classExists( $className ) ) {
149 if ( !defined( 'MW_COMPILED' ) ) {
150 // Preload base classes to work around APC/PHP5 bug
151 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
152 if ( file_exists( $deps ) ) {
153 include_once( $deps );
155 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
158 # Check if we got if not failback to default skin
159 if ( !MWInit
::classExists( $className ) ) {
160 # DO NOT die if the class isn't found. This breaks maintenance
161 # scripts and can cause a user account to be unrecoverable
162 # except by SQL manipulation if a previously valid skin name
163 # is no longer valid.
164 wfDebug( "Skin class does not exist: $className\n" );
165 $className = 'SkinVector';
166 if ( !defined( 'MW_COMPILED' ) ) {
167 require_once( "{$wgStyleDirectory}/Vector.php" );
171 $skin = new $className( $key );
175 /** @return string skin name */
176 public function getSkinName() {
177 return $this->skinname
;
181 * @param $out OutputPage
183 function initPage( OutputPage
$out ) {
184 wfProfileIn( __METHOD__
);
186 $this->preloadExistence();
188 wfProfileOut( __METHOD__
);
192 * Preload the existence of three commonly-requested pages in a single query
194 function preloadExistence() {
195 $user = $this->getUser();
198 $titles = array( $user->getUserPage(), $user->getTalkPage() );
201 if ( $this->getTitle()->isSpecialPage() ) {
203 } elseif ( $this->getTitle()->isTalkPage() ) {
204 $titles[] = $this->getTitle()->getSubjectPage();
206 $titles[] = $this->getTitle()->getTalkPage();
209 $lb = new LinkBatch( $titles );
210 $lb->setCaller( __METHOD__
);
215 * Get the current revision ID
219 public function getRevisionId() {
220 return $this->getOutput()->getRevisionId();
224 * Whether the revision displayed is the latest revision of the page
228 public function isRevisionCurrent() {
229 $revID = $this->getRevisionId();
230 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
234 * Set the "relevant" title
235 * @see self::getRelevantTitle()
236 * @param $t Title object to use
238 public function setRelevantTitle( $t ) {
239 $this->mRelevantTitle
= $t;
243 * Return the "relevant" title.
244 * A "relevant" title is not necessarily the actual title of the page.
245 * Special pages like Special:MovePage use set the page they are acting on
246 * as their "relevant" title, this allows the skin system to display things
247 * such as content tabs which belong to to that page instead of displaying
248 * a basic special page tab which has almost no meaning.
252 public function getRelevantTitle() {
253 if ( isset($this->mRelevantTitle
) ) {
254 return $this->mRelevantTitle
;
256 return $this->getTitle();
260 * Set the "relevant" user
261 * @see self::getRelevantUser()
262 * @param $u User object to use
264 public function setRelevantUser( $u ) {
265 $this->mRelevantUser
= $u;
269 * Return the "relevant" user.
270 * A "relevant" user is similar to a relevant title. Special pages like
271 * Special:Contributions mark the user which they are relevant to so that
272 * things like the toolbox can display the information they usually are only
273 * able to display on a user's userpage and talkpage.
276 public function getRelevantUser() {
277 if ( isset($this->mRelevantUser
) ) {
278 return $this->mRelevantUser
;
280 $title = $this->getRelevantTitle();
281 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
282 $rootUser = strtok( $title->getText(), '/' );
283 if ( User
::isIP( $rootUser ) ) {
284 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
286 $user = User
::newFromName( $rootUser, false );
287 if ( $user && $user->isLoggedIn() ) {
288 $this->mRelevantUser
= $user;
291 return $this->mRelevantUser
;
297 * Outputs the HTML generated by other functions.
298 * @param $out OutputPage
300 abstract function outputPage( OutputPage
$out = null );
306 static function makeVariablesScript( $data ) {
308 return Html
::inlineScript(
309 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
317 * Make a <script> tag containing global variables
319 * @deprecated in 1.19
321 * @return string HTML fragment
323 public static function makeGlobalVariablesScript( $unused ) {
326 wfDeprecated( __METHOD__
, '1.19' );
328 return self
::makeVariablesScript( $wgOut->getJSVars() );
332 * Get the query to generate a dynamic stylesheet
336 public static function getDynamicStylesheetQuery() {
337 global $wgSquidMaxage;
341 'maxage' => $wgSquidMaxage,
342 'usemsgcache' => 'yes',
343 'ctype' => 'text/css',
344 'smaxage' => $wgSquidMaxage,
349 * Add skin specific stylesheets
350 * Calling this method with an $out of anything but the same OutputPage
351 * inside ->getOutput() is deprecated. The $out arg is kept
352 * for compatibility purposes with skins.
353 * @param $out OutputPage
356 abstract function setupSkinUserCss( OutputPage
$out );
360 * @param $title Title
363 function getPageClasses( $title ) {
364 $numeric = 'ns-' . $title->getNamespace();
366 if ( $title->isSpecialPage() ) {
367 $type = 'ns-special';
368 // bug 23315: provide a class based on the canonical special page name without subpages
369 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
370 if ( $canonicalName ) {
371 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
373 $type .= ' mw-invalidspecialpage';
375 } elseif ( $title->isTalkPage() ) {
378 $type = 'ns-subject';
381 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
383 return "$numeric $type $name";
387 * This will be called by OutputPage::headElement when it is creating the
388 * <body> tag, skins can override it if they have a need to add in any
389 * body attributes or classes of their own.
390 * @param $out OutputPage
391 * @param $bodyAttrs Array
393 function addToBodyAttributes( $out, &$bodyAttrs ) {
394 // does nothing by default
409 function getCategoryLinks() {
410 global $wgUseCategoryBrowser;
412 $out = $this->getOutput();
413 $allCats = $out->getCategoryLinks();
415 if ( !count( $allCats ) ) {
423 $colon = $this->msg( 'colon-separator' )->escaped();
425 if ( !empty( $allCats['normal'] ) ) {
426 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
428 $msg = $this->msg( 'pagecategories', count( $allCats['normal'] ) )->escaped();
429 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
430 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
431 Linker
::link( Title
::newFromText( $linkPage ), $msg )
432 . $colon . '<ul>' . $t . '</ul>' . '</div>';
436 if ( isset( $allCats['hidden'] ) ) {
437 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
438 $class = ' mw-hidden-cats-user-shown';
439 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
440 $class = ' mw-hidden-cats-ns-shown';
442 $class = ' mw-hidden-cats-hidden';
445 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
446 $this->msg( 'hidden-categories', count( $allCats['hidden'] ) )->escaped() .
447 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
451 # optional 'dmoz-like' category browser. Will be shown under the list
452 # of categories an article belong to
453 if ( $wgUseCategoryBrowser ) {
454 $s .= '<br /><hr />';
456 # get a big array of the parents tree
457 $parenttree = $this->getTitle()->getParentCategoryTree();
458 # Skin object passed by reference cause it can not be
459 # accessed under the method subfunction drawCategoryBrowser
460 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
461 # Clean out bogus first entry and sort them
462 unset( $tempout[0] );
464 # Output one per line
465 $s .= implode( "<br />\n", $tempout );
472 * Render the array as a serie of links.
473 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
474 * @return String separated by >, terminate with "\n"
476 function drawCategoryBrowser( $tree ) {
479 foreach ( $tree as $element => $parent ) {
480 if ( empty( $parent ) ) {
481 # element start a new list
484 # grab the others elements
485 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
488 # add our current element to the list
489 $eltitle = Title
::newFromText( $element );
490 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
499 function getCategories() {
500 $out = $this->getOutput();
502 $catlinks = $this->getCategoryLinks();
504 $classes = 'catlinks';
506 // Check what we're showing
507 $allCats = $out->getCategoryLinks();
508 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
509 $this->getTitle()->getNamespace() == NS_CATEGORY
;
511 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
512 $classes .= ' catlinks-allhidden';
515 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
519 * This runs a hook to allow extensions placing their stuff after content
520 * and article metadata (e.g. categories).
521 * Note: This function has nothing to do with afterContent().
523 * This hook is placed here in order to allow using the same hook for all
524 * skins, both the SkinTemplate based ones and the older ones, which directly
525 * use this class to get their data.
527 * The output of this function gets processed in SkinTemplate::outputPage() for
528 * the SkinTemplate based skins, all other skins should directly echo it.
530 * @return String, empty by default, if not changed by any hook function.
532 protected function afterContentHook() {
535 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
536 // adding just some spaces shouldn't toggle the output
537 // of the whole <div/>, so we use trim() here
538 if ( trim( $data ) != '' ) {
539 // Doing this here instead of in the skins to
540 // ensure that the div has the same ID in all
542 $data = "<div id='mw-data-after-content'>\n" .
547 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
554 * Generate debug data HTML for displaying at the bottom of the main content
556 * @return String HTML containing debug data, if enabled (otherwise empty).
558 protected function generateDebugHTML() {
561 $html = MWDebug
::getDebugHTML( $this->getContext() );
563 if ( $wgShowDebug ) {
564 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext
);
565 $html .= "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
566 $listInternals . "</ul>\n";
573 * @param $debugText string
576 private function formatDebugHTML( $debugText ) {
577 global $wgDebugTimestamps;
579 $lines = explode( "\n", $debugText );
583 foreach ( $lines as $line ) {
585 if ( $wgDebugTimestamps ) {
587 if ( preg_match( '/^(\d+\.\d+ {1,3}\d+.\dM\s{2})/', $line, $matches ) ) {
589 $line = substr( $line, strlen( $pre ) );
592 $display = ltrim( $line );
593 $ident = strlen( $line ) - strlen( $display );
594 $diff = $ident - $curIdent;
596 $display = $pre . $display;
597 if ( $display == '' ) {
598 $display = "\xc2\xa0";
601 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
604 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
606 $display = htmlspecialchars( $display );
610 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
611 } elseif ( $diff == 0 ) {
612 $ret .= "</li><li>\n";
614 $ret .= str_repeat( "<ul><li>\n", $diff );
616 $ret .= "<tt>$display</tt>\n";
621 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
627 * This gets called shortly before the </body> tag.
629 * @return String HTML-wrapped JS code to be put before </body>
631 function bottomScripts() {
632 // TODO and the suckage continues. This function is really just a wrapper around
633 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
635 $bottomScriptText = $this->getOutput()->getBottomScripts();
636 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
638 return $bottomScriptText;
642 * Text with the permalink to the source page,
643 * usually shown on the footer of a printed page
645 * @return string HTML text with an URL
647 function printSource() {
648 $oldid = $this->getRevisionId();
650 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
652 // oldid not available for non existing pages
653 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
655 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
661 function getUndeleteLink() {
662 $action = $this->getRequest()->getVal( 'action', 'view' );
664 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
665 ( $this->getTitle()->getArticleID() == 0 ||
$action == 'history' ) ) {
666 $n = $this->getTitle()->isDeleted();
670 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
671 $msg = 'thisisdeleted';
673 $msg = 'viewdeleted';
676 return $this->msg( $msg )->rawParams(
678 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
679 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
690 function subPageSubtitle() {
692 $out = $this->getOutput();
695 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
699 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
700 $ptext = $this->getTitle()->getPrefixedText();
701 if ( preg_match( '/\//', $ptext ) ) {
702 $links = explode( '/', $ptext );
708 foreach ( $links as $link ) {
709 $growinglink .= $link;
711 $linkObj = Title
::newFromText( $growinglink );
713 if ( is_object( $linkObj ) && $linkObj->exists() ) {
714 $getlink = Linker
::linkKnown(
716 htmlspecialchars( $display )
722 $subpages .= $wgLang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
724 $subpages .= '< ';
727 $subpages .= $getlink;
741 * Returns true if the IP should be shown in the header
744 function showIPinHeader() {
745 global $wgShowIPinHeader;
746 return $wgShowIPinHeader && session_id() != '';
752 function getSearchLink() {
753 $searchPage = SpecialPage
::getTitleFor( 'Search' );
754 return $searchPage->getLocalURL();
760 function escapeSearchLink() {
761 return htmlspecialchars( $this->getSearchLink() );
765 * @param $type string
768 function getCopyright( $type = 'detect' ) {
769 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
771 if ( $type == 'detect' ) {
772 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
779 if ( $type == 'history' ) {
780 $msg = 'history_copyright';
785 if ( $wgRightsPage ) {
786 $title = Title
::newFromText( $wgRightsPage );
787 $link = Linker
::linkKnown( $title, $wgRightsText );
788 } elseif ( $wgRightsUrl ) {
789 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
790 } elseif ( $wgRightsText ) {
791 $link = $wgRightsText;
797 // Allow for site and per-namespace customization of copyright notice.
800 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
802 $msgObj = $this->msg( $msg )->rawParams( $link );
804 $msg = $msgObj->inContentLanguage()->text();
805 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
806 $msg = Html
::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
810 return $msgObj->text();
815 * @return null|string
817 function getCopyrightIcon() {
818 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
822 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
823 $out = $wgCopyrightIcon;
824 } elseif ( $wgRightsIcon ) {
825 $icon = htmlspecialchars( $wgRightsIcon );
827 if ( $wgRightsUrl ) {
828 $url = htmlspecialchars( $wgRightsUrl );
829 $out .= '<a href="' . $url . '">';
832 $text = htmlspecialchars( $wgRightsText );
833 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
835 if ( $wgRightsUrl ) {
844 * Gets the powered by MediaWiki icon.
847 function getPoweredBy() {
850 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
851 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
852 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
857 * Get the timestamp of the latest revision, formatted in user language
861 protected function lastModified() {
862 $timestamp = $this->getOutput()->getRevisionTimestamp();
864 # No cached timestamp, load it from the database
865 if ( $timestamp === null ) {
866 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
870 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
871 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
872 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
877 if ( wfGetLB()->getLaggedSlaveMode() ) {
878 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
885 * @param $align string
888 function logoText( $align = '' ) {
889 if ( $align != '' ) {
890 $a = " align='{$align}'";
895 $mp = $this->msg( 'mainpage' )->escaped();
896 $mptitle = Title
::newMainPage();
897 $url = ( is_object( $mptitle ) ?
htmlspecialchars( $mptitle->getLocalURL() ) : '' );
899 $logourl = $this->getLogo();
900 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
906 * Renders a $wgFooterIcons icon acording to the method's arguments
907 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
908 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
909 * @return String HTML
911 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
912 if ( is_string( $icon ) ) {
914 } else { // Assuming array
915 $url = isset($icon["url"]) ?
$icon["url"] : null;
916 unset( $icon["url"] );
917 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
918 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
920 $html = htmlspecialchars( $icon["alt"] );
923 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
930 * Gets the link to the wiki's main page.
933 function mainPageLink() {
934 $s = Linker
::linkKnown(
935 Title
::newMainPage(),
936 $this->msg( 'mainpage' )->escaped()
947 public function footerLink( $desc, $page ) {
948 // if the link description has been set to "-" in the default language,
949 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
950 // then it is disabled, for all languages.
953 // Otherwise, we display the link for the user, described in their
954 // language (which may or may not be the same as the default language),
955 // but we make the link target be the one site-wide page.
956 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
958 return Linker
::linkKnown(
960 $this->msg( $desc )->escaped()
966 * Gets the link to the wiki's privacy policy page.
967 * @return String HTML
969 function privacyLink() {
970 return $this->footerLink( 'privacy', 'privacypage' );
974 * Gets the link to the wiki's about page.
975 * @return String HTML
977 function aboutLink() {
978 return $this->footerLink( 'aboutsite', 'aboutpage' );
982 * Gets the link to the wiki's general disclaimers page.
983 * @return String HTML
985 function disclaimerLink() {
986 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
990 * Return URL options for the 'edit page' link.
991 * This may include an 'oldid' specifier, if the current page view is such.
996 function editUrlOptions() {
997 $options = array( 'action' => 'edit' );
999 if ( !$this->isRevisionCurrent() ) {
1000 $options['oldid'] = intval( $this->getRevisionId() );
1007 * @param $id User|int
1010 function showEmailUser( $id ) {
1011 if ( $id instanceof User
) {
1014 $targetUser = User
::newFromId( $id );
1016 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1017 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1021 * Return a fully resolved style path url to images or styles stored in the common folder.
1022 * This method returns a url resolved using the configured skin style path
1023 * and includes the style version inside of the url.
1024 * @param $name String: The name or path of a skin resource file
1025 * @return String The fully resolved style path url including styleversion
1027 function getCommonStylePath( $name ) {
1028 global $wgStylePath, $wgStyleVersion;
1029 return "$wgStylePath/common/$name?$wgStyleVersion";
1033 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1034 * This method returns a url resolved using the configured skin style path
1035 * and includes the style version inside of the url.
1036 * @param $name String: The name or path of a skin resource file
1037 * @return String The fully resolved style path url including styleversion
1039 function getSkinStylePath( $name ) {
1040 global $wgStylePath, $wgStyleVersion;
1041 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1044 /* these are used extensively in SkinTemplate, but also some other places */
1047 * @param $urlaction string
1050 static function makeMainPageUrl( $urlaction = '' ) {
1051 $title = Title
::newMainPage();
1052 self
::checkTitle( $title, '' );
1054 return $title->getLocalURL( $urlaction );
1058 * @param $name string
1059 * @param $urlaction string
1062 static function makeSpecialUrl( $name, $urlaction = '' ) {
1063 $title = SpecialPage
::getSafeTitleFor( $name );
1064 return $title->getLocalURL( $urlaction );
1068 * @param $name string
1069 * @param $subpage string
1070 * @param $urlaction string
1073 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1074 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1075 return $title->getLocalURL( $urlaction );
1079 * @param $name string
1080 * @param $urlaction string
1083 static function makeI18nUrl( $name, $urlaction = '' ) {
1084 $title = Title
::newFromText( wfMsgForContent( $name ) );
1085 self
::checkTitle( $title, $name );
1086 return $title->getLocalURL( $urlaction );
1090 * @param $name string
1091 * @param $urlaction string
1094 static function makeUrl( $name, $urlaction = '' ) {
1095 $title = Title
::newFromText( $name );
1096 self
::checkTitle( $title, $name );
1098 return $title->getLocalURL( $urlaction );
1102 * If url string starts with http, consider as external URL, else
1104 * @param $name String
1105 * @return String URL
1107 static function makeInternalOrExternalUrl( $name ) {
1108 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1111 return self
::makeUrl( $name );
1116 * this can be passed the NS number as defined in Language.php
1118 * @param $urlaction string
1119 * @param $namespace int
1122 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1123 $title = Title
::makeTitleSafe( $namespace, $name );
1124 self
::checkTitle( $title, $name );
1126 return $title->getLocalURL( $urlaction );
1130 * these return an array with the 'href' and boolean 'exists'
1132 * @param $urlaction string
1135 static function makeUrlDetails( $name, $urlaction = '' ) {
1136 $title = Title
::newFromText( $name );
1137 self
::checkTitle( $title, $name );
1140 'href' => $title->getLocalURL( $urlaction ),
1141 'exists' => $title->getArticleID() != 0,
1146 * Make URL details where the article exists (or at least it's convenient to think so)
1147 * @param $name String Article name
1148 * @param $urlaction String
1151 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1152 $title = Title
::newFromText( $name );
1153 self
::checkTitle( $title, $name );
1156 'href' => $title->getLocalURL( $urlaction ),
1162 * make sure we have some title to operate on
1164 * @param $title Title
1165 * @param $name string
1167 static function checkTitle( &$title, $name ) {
1168 if ( !is_object( $title ) ) {
1169 $title = Title
::newFromText( $name );
1170 if ( !is_object( $title ) ) {
1171 $title = Title
::newFromText( '--error: link target missing--' );
1177 * Build an array that represents the sidebar(s), the navigation bar among them
1181 function buildSidebar() {
1182 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1183 wfProfileIn( __METHOD__
);
1185 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1187 if ( $wgEnableSidebarCache ) {
1188 $cachedsidebar = $wgMemc->get( $key );
1189 if ( $cachedsidebar ) {
1190 wfProfileOut( __METHOD__
);
1191 return $cachedsidebar;
1196 $this->addToSidebar( $bar, 'sidebar' );
1198 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1199 if ( $wgEnableSidebarCache ) {
1200 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1203 wfProfileOut( __METHOD__
);
1207 * Add content from a sidebar system message
1208 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1210 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1213 * @param $message String
1215 function addToSidebar( &$bar, $message ) {
1216 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1220 * Add content from plain text
1223 * @param $text string
1226 function addToSidebarPlain( &$bar, $text ) {
1227 $lines = explode( "\n", $text );
1231 foreach ( $lines as $line ) {
1232 if ( strpos( $line, '*' ) !== 0 ) {
1235 $line = rtrim( $line, "\r" ); // for Windows compat
1237 if ( strpos( $line, '**' ) !== 0 ) {
1238 $heading = trim( $line, '* ' );
1239 if ( !array_key_exists( $heading, $bar ) ) {
1240 $bar[$heading] = array();
1243 $line = trim( $line, '* ' );
1245 if ( strpos( $line, '|' ) !== false ) { // sanity check
1246 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1247 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1248 if ( count( $line ) !== 2 ) {
1249 // Second sanity check, could be hit by people doing
1250 // funky stuff with parserfuncs... (bug 33321)
1254 $extraAttribs = array();
1256 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1257 if ( $msgLink->exists() ) {
1258 $link = $msgLink->text();
1259 if ( $link == '-' ) {
1265 $msgText = $this->msg( $line[1] );
1266 if ( $msgText->exists() ) {
1267 $text = $msgText->text();
1272 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1275 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1276 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1277 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1278 $extraAttribs['rel'] = 'nofollow';
1281 global $wgExternalLinkTarget;
1282 if ( $wgExternalLinkTarget) {
1283 $extraAttribs['target'] = $wgExternalLinkTarget;
1286 $title = Title
::newFromText( $link );
1289 $title = $title->fixSpecialName();
1290 $href = $title->getLinkURL();
1292 $href = 'INVALID-TITLE';
1296 $bar[$heading][] = array_merge( array(
1299 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1312 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1313 * print stylesheet should override this and return false. (This is an
1314 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1318 public function commonPrintStylesheet() {
1323 * Gets new talk page messages for the current user.
1324 * @return MediaWiki message or if no new talk page messages, nothing
1326 function getNewtalks() {
1327 $out = $this->getOutput();
1329 $newtalks = $this->getUser()->getNewMessageLinks();
1332 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1333 $userTitle = $this->getUser()->getUserPage();
1334 $userTalkTitle = $userTitle->getTalkPage();
1336 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1337 $newMessagesLink = Linker
::linkKnown(
1339 $this->msg( 'newmessageslink' )->escaped(),
1341 array( 'redirect' => 'no' )
1344 $newMessagesDiffLink = Linker
::linkKnown(
1346 $this->msg( 'newmessagesdifflink' )->escaped(),
1348 array( 'diff' => 'cur' )
1352 'youhavenewmessages',
1354 $newMessagesDiffLink
1356 # Disable Squid cache
1357 $out->setSquidMaxage( 0 );
1359 } elseif ( count( $newtalks ) ) {
1360 // _>" " for BC <= 1.16
1361 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1364 foreach ( $newtalks as $newtalk ) {
1365 $msgs[] = Xml
::element(
1367 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1370 $parts = implode( $sep, $msgs );
1371 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1372 $out->setSquidMaxage( 0 );
1379 * Get a cached notice
1381 * @param $name String: message name, or 'default' for $wgSiteNotice
1382 * @return String: HTML fragment
1384 private function getCachedNotice( $name ) {
1385 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1387 wfProfileIn( __METHOD__
);
1391 if( $name === 'default' ) {
1393 global $wgSiteNotice;
1394 $notice = $wgSiteNotice;
1395 if( empty( $notice ) ) {
1396 wfProfileOut( __METHOD__
);
1400 $msg = $this->msg( $name )->inContentLanguage();
1401 if( $msg->isDisabled() ) {
1402 wfProfileOut( __METHOD__
);
1405 $notice = $msg->plain();
1408 // Use the extra hash appender to let eg SSL variants separately cache.
1409 $key = wfMemcKey( $name . $wgRenderHashAppend );
1410 $cachedNotice = $parserMemc->get( $key );
1411 if( is_array( $cachedNotice ) ) {
1412 if( md5( $notice ) == $cachedNotice['hash'] ) {
1413 $notice = $cachedNotice['html'];
1422 $parsed = $this->getOutput()->parse( $notice );
1423 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1427 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1428 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1429 wfProfileOut( __METHOD__
);
1434 * Get a notice based on page's namespace
1436 * @return String: HTML fragment
1438 function getNamespaceNotice() {
1439 wfProfileIn( __METHOD__
);
1441 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1442 $namespaceNotice = $this->getCachedNotice( $key );
1443 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1444 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1446 $namespaceNotice = '';
1449 wfProfileOut( __METHOD__
);
1450 return $namespaceNotice;
1454 * Get the site notice
1456 * @return String: HTML fragment
1458 function getSiteNotice() {
1459 wfProfileIn( __METHOD__
);
1462 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1463 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1464 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1466 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1467 if ( !$anonNotice ) {
1468 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1470 $siteNotice = $anonNotice;
1473 if ( !$siteNotice ) {
1474 $siteNotice = $this->getCachedNotice( 'default' );
1478 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1479 wfProfileOut( __METHOD__
);
1484 * Create a section edit link. This supersedes editSectionLink() and
1485 * editSectionLinkForOther().
1487 * @param $nt Title The title being linked to (may not be the same as
1488 * $wgTitle, if the section is included from a template)
1489 * @param $section string The designation of the section being pointed to,
1490 * to be included in the link, like "§ion=$section"
1491 * @param $tooltip string The tooltip to use for the link: will be escaped
1492 * and wrapped in the 'editsectionhint' message
1493 * @param $lang string Language code
1494 * @return string HTML to use for edit link
1496 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1497 // HTML generated here should probably have userlangattributes
1498 // added to it for LTR text on RTL pages
1500 if ( !is_null( $tooltip ) ) {
1501 # Bug 25462: undo double-escaping.
1502 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1503 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'replaceafter' ), $tooltip );
1505 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1507 array( 'action' => 'edit', 'section' => $section ),
1508 array( 'noclasses', 'known' )
1511 # Run the old hook. This takes up half of the function . . . hopefully
1512 # we can rid of it someday.
1515 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape', 'replaceafter' ), $tooltip );
1516 $attribs = " title=\"$attribs\"";
1519 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1520 if ( !is_null( $result ) ) {
1521 # For reverse compatibility, add the brackets *after* the hook is
1522 # run, and even add them to hook-provided text. (This is the main
1523 # reason that the EditSectionLink hook is deprecated in favor of
1524 # DoEditSectionLink: it can't change the brackets or the span.)
1525 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1526 return "<span class=\"editsection\">$result</span>";
1529 # Add the brackets and the span, and *then* run the nice new hook, with
1530 # clean and non-redundant arguments.
1531 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1532 $result = "<span class=\"editsection\">$result</span>";
1534 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1539 * Use PHP's magic __call handler to intercept legacy calls to the linker
1540 * for backwards compatibility.
1542 * @param $fname String Name of called method
1543 * @param $args Array Arguments to the method
1546 function __call( $fname, $args ) {
1547 $realFunction = array( 'Linker', $fname );
1548 if ( is_callable( $realFunction ) ) {
1549 return call_user_func_array( $realFunction, $args );
1551 $className = get_class( $this );
1552 throw new MWException( "Call to undefined method $className::$fname" );