3 * Base class for all skins.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * @defgroup Skins Skins
28 * The main skin class which provides methods and properties for all other skins.
30 * See docs/skin.txt for more information.
34 abstract class Skin
extends ContextSource
{
35 protected $skinname = null;
36 protected $mRelevantTitle = null;
37 protected $mRelevantUser = null;
40 * @var string Stylesheets set to use. Subdirectory in skins/ where various stylesheets are
41 * located. Only needs to be set if you intend to use the getSkinStylePath() method.
43 public $stylename = null;
46 * Fetch the set of available skins.
47 * @return array Associative array of strings
49 static function getSkinNames() {
50 return SkinFactory
::getDefaultInstance()->getSkinNames();
54 * Fetch the skinname messages for available skins.
57 static function getSkinNameMessages() {
59 foreach ( self
::getSkinNames() as $skinKey => $skinName ) {
60 $messages[] = "skinname-$skinKey";
66 * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
67 * Useful for Special:Preferences and other places where you
68 * only want to show skins users _can_ use.
72 public static function getAllowedSkins() {
75 $allowedSkins = self
::getSkinNames();
77 foreach ( $wgSkipSkins as $skip ) {
78 unset( $allowedSkins[$skip] );
85 * @deprecated since 1.23, use getAllowedSkins
88 public static function getUsableSkins() {
89 wfDeprecated( __METHOD__
, '1.23' );
90 return self
::getAllowedSkins();
94 * Normalize a skin preference value to a form that can be loaded.
96 * If a skin can't be found, it will fall back to the configured default ($wgDefaultSkin), or the
97 * hardcoded default ($wgFallbackSkin) if the default skin is unavailable too.
99 * @param string $key 'monobook', 'vector', etc.
102 static function normalizeKey( $key ) {
103 global $wgDefaultSkin, $wgFallbackSkin;
105 $skinNames = Skin
::getSkinNames();
107 // Make keys lowercase for case-insensitive matching.
108 $skinNames = array_change_key_case( $skinNames, CASE_LOWER
);
109 $key = strtolower( $key );
110 $defaultSkin = strtolower( $wgDefaultSkin );
111 $fallbackSkin = strtolower( $wgFallbackSkin );
113 if ( $key == '' ||
$key == 'default' ) {
114 // Don't return the default immediately;
115 // in a misconfiguration we need to fall back.
119 if ( isset( $skinNames[$key] ) ) {
123 // Older versions of the software used a numeric setting
124 // in the user preferences.
130 if ( isset( $fallback[$key] ) ) {
131 $key = $fallback[$key];
134 if ( isset( $skinNames[$key] ) ) {
136 } elseif ( isset( $skinNames[$defaultSkin] ) ) {
139 return $fallbackSkin;
144 * Factory method for loading a skin of a given type
145 * @param string $key 'monobook', 'vector', etc.
147 * @deprecated since 1.24; Use SkinFactory instead
149 static function &newFromKey( $key ) {
150 wfDeprecated( __METHOD__
, '1.24' );
152 $key = Skin
::normalizeKey( $key );
153 $factory = SkinFactory
::getDefaultInstance();
155 // normalizeKey() guarantees that a skin with this key will exist.
156 $skin = $factory->makeSkin( $key );
161 * @return string Skin name
163 public function getSkinName() {
164 return $this->skinname
;
168 * @param OutputPage $out
170 function initPage( OutputPage
$out ) {
172 $this->preloadExistence();
177 * Defines the ResourceLoader modules that should be added to the skin
178 * It is recommended that skins wishing to override call parent::getDefaultModules()
179 * and substitute out any modules they wish to change by using a key to look them up
180 * @return array Array of modules with helper keys for easy overriding
182 public function getDefaultModules() {
183 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
184 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
186 $out = $this->getOutput();
187 $user = $out->getUser();
189 // modules that enhance the page content in some way
191 'mediawiki.page.ready',
193 // modules that exist for legacy reasons
195 // modules relating to search functionality
197 // modules relating to functionality relating to watching an article
199 // modules which relate to the current users preferences
202 if ( $wgIncludeLegacyJavaScript ) {
203 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
206 if ( $wgPreloadJavaScriptMwUtil ) {
207 $modules['legacy'][] = 'mediawiki.util';
210 // Add various resources if required
212 $modules['legacy'][] = 'mediawiki.legacy.ajax';
214 if ( $wgEnableAPI ) {
215 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
216 && $user->isAllowed( 'writeapi' )
218 $modules['watch'][] = 'mediawiki.page.watch.ajax';
221 $modules['search'][] = 'mediawiki.searchSuggest';
225 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
226 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
229 // Crazy edit-on-double-click stuff
230 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
231 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
237 * Preload the existence of three commonly-requested pages in a single query
239 function preloadExistence() {
242 $user = $this->getUser();
243 $title = $this->getRelevantTitle();
246 if ( $user->isLoggedIn() ||
$this->showIPinHeader() ) {
247 $titles[] = $user->getUserPage();
248 $titles[] = $user->getTalkPage();
252 if ( $title->isSpecialPage() ) {
254 } elseif ( $title->isTalkPage() ) {
255 $titles[] = $title->getSubjectPage();
257 $titles[] = $title->getTalkPage();
260 Hooks
::run( 'SkinPreloadExistence', array( &$titles, $this ) );
262 if ( count( $titles ) ) {
263 $lb = new LinkBatch( $titles );
264 $lb->setCaller( __METHOD__
);
270 * Get the current revision ID
274 public function getRevisionId() {
275 return $this->getOutput()->getRevisionId();
279 * Whether the revision displayed is the latest revision of the page
283 public function isRevisionCurrent() {
284 $revID = $this->getRevisionId();
285 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
289 * Set the "relevant" title
290 * @see self::getRelevantTitle()
293 public function setRelevantTitle( $t ) {
294 $this->mRelevantTitle
= $t;
298 * Return the "relevant" title.
299 * A "relevant" title is not necessarily the actual title of the page.
300 * Special pages like Special:MovePage use set the page they are acting on
301 * as their "relevant" title, this allows the skin system to display things
302 * such as content tabs which belong to to that page instead of displaying
303 * a basic special page tab which has almost no meaning.
307 public function getRelevantTitle() {
308 if ( isset( $this->mRelevantTitle
) ) {
309 return $this->mRelevantTitle
;
311 return $this->getTitle();
315 * Set the "relevant" user
316 * @see self::getRelevantUser()
319 public function setRelevantUser( $u ) {
320 $this->mRelevantUser
= $u;
324 * Return the "relevant" user.
325 * A "relevant" user is similar to a relevant title. Special pages like
326 * Special:Contributions mark the user which they are relevant to so that
327 * things like the toolbox can display the information they usually are only
328 * able to display on a user's userpage and talkpage.
331 public function getRelevantUser() {
332 if ( isset( $this->mRelevantUser
) ) {
333 return $this->mRelevantUser
;
335 $title = $this->getRelevantTitle();
336 if ( $title->hasSubjectNamespace( NS_USER
) ) {
337 $rootUser = $title->getRootText();
338 if ( User
::isIP( $rootUser ) ) {
339 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
341 $user = User
::newFromName( $rootUser, false );
342 if ( $user && $user->isLoggedIn() ) {
343 $this->mRelevantUser
= $user;
346 return $this->mRelevantUser
;
352 * Outputs the HTML generated by other functions.
353 * @param OutputPage $out
355 abstract function outputPage( OutputPage
$out = null );
361 static function makeVariablesScript( $data ) {
363 return Html
::inlineScript(
364 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
372 * Get the query to generate a dynamic stylesheet
376 public static function getDynamicStylesheetQuery() {
377 global $wgSquidMaxage;
381 'maxage' => $wgSquidMaxage,
382 'usemsgcache' => 'yes',
383 'ctype' => 'text/css',
384 'smaxage' => $wgSquidMaxage,
389 * Add skin specific stylesheets
390 * Calling this method with an $out of anything but the same OutputPage
391 * inside ->getOutput() is deprecated. The $out arg is kept
392 * for compatibility purposes with skins.
393 * @param OutputPage $out
396 abstract function setupSkinUserCss( OutputPage
$out );
400 * @param Title $title
403 function getPageClasses( $title ) {
404 $numeric = 'ns-' . $title->getNamespace();
406 if ( $title->isSpecialPage() ) {
407 $type = 'ns-special';
408 // bug 23315: provide a class based on the canonical special page name without subpages
409 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
410 if ( $canonicalName ) {
411 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
413 $type .= ' mw-invalidspecialpage';
415 } elseif ( $title->isTalkPage() ) {
418 $type = 'ns-subject';
421 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
423 return "$numeric $type $name";
427 * Return values for <html> element
428 * @return array Array of associative name-to-value elements for <html> element
430 public function getHtmlElementAttributes() {
431 $lang = $this->getLanguage();
433 'lang' => $lang->getHtmlCode(),
434 'dir' => $lang->getDir(),
435 'class' => 'client-nojs',
440 * This will be called by OutputPage::headElement when it is creating the
441 * "<body>" tag, skins can override it if they have a need to add in any
442 * body attributes or classes of their own.
443 * @param OutputPage $out
444 * @param array $bodyAttrs
446 function addToBodyAttributes( $out, &$bodyAttrs ) {
447 // does nothing by default
462 function getCategoryLinks() {
463 global $wgUseCategoryBrowser;
465 $out = $this->getOutput();
466 $allCats = $out->getCategoryLinks();
468 if ( !count( $allCats ) ) {
476 $colon = $this->msg( 'colon-separator' )->escaped();
478 if ( !empty( $allCats['normal'] ) ) {
479 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
481 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
482 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
483 $title = Title
::newFromText( $linkPage );
484 $link = $title ? Linker
::link( $title, $msg ) : $msg;
485 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
486 $link . $colon . '<ul>' . $t . '</ul>' . '</div>';
490 if ( isset( $allCats['hidden'] ) ) {
491 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
492 $class = ' mw-hidden-cats-user-shown';
493 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
494 $class = ' mw-hidden-cats-ns-shown';
496 $class = ' mw-hidden-cats-hidden';
499 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
500 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
501 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
505 # optional 'dmoz-like' category browser. Will be shown under the list
506 # of categories an article belong to
507 if ( $wgUseCategoryBrowser ) {
508 $s .= '<br /><hr />';
510 # get a big array of the parents tree
511 $parenttree = $this->getTitle()->getParentCategoryTree();
512 # Skin object passed by reference cause it can not be
513 # accessed under the method subfunction drawCategoryBrowser
514 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
515 # Clean out bogus first entry and sort them
516 unset( $tempout[0] );
518 # Output one per line
519 $s .= implode( "<br />\n", $tempout );
526 * Render the array as a series of links.
527 * @param array $tree Categories tree returned by Title::getParentCategoryTree
528 * @return string Separated by >, terminate with "\n"
530 function drawCategoryBrowser( $tree ) {
533 foreach ( $tree as $element => $parent ) {
534 if ( empty( $parent ) ) {
535 # element start a new list
538 # grab the others elements
539 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
542 # add our current element to the list
543 $eltitle = Title
::newFromText( $element );
544 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
553 function getCategories() {
554 $out = $this->getOutput();
556 $catlinks = $this->getCategoryLinks();
558 $classes = 'catlinks';
560 // Check what we're showing
561 $allCats = $out->getCategoryLinks();
562 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
563 $this->getTitle()->getNamespace() == NS_CATEGORY
;
565 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
566 $classes .= ' catlinks-allhidden';
569 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
573 * This runs a hook to allow extensions placing their stuff after content
574 * and article metadata (e.g. categories).
575 * Note: This function has nothing to do with afterContent().
577 * This hook is placed here in order to allow using the same hook for all
578 * skins, both the SkinTemplate based ones and the older ones, which directly
579 * use this class to get their data.
581 * The output of this function gets processed in SkinTemplate::outputPage() for
582 * the SkinTemplate based skins, all other skins should directly echo it.
584 * @return string Empty by default, if not changed by any hook function.
586 protected function afterContentHook() {
589 if ( Hooks
::run( 'SkinAfterContent', array( &$data, $this ) ) ) {
590 // adding just some spaces shouldn't toggle the output
591 // of the whole <div/>, so we use trim() here
592 if ( trim( $data ) != '' ) {
593 // Doing this here instead of in the skins to
594 // ensure that the div has the same ID in all
596 $data = "<div id='mw-data-after-content'>\n" .
601 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
608 * Generate debug data HTML for displaying at the bottom of the main content
610 * @return string HTML containing debug data, if enabled (otherwise empty).
612 protected function generateDebugHTML() {
613 return MWDebug
::getHTMLDebugLog();
617 * This gets called shortly before the "</body>" tag.
619 * @return string HTML-wrapped JS code to be put before "</body>"
621 function bottomScripts() {
622 // TODO and the suckage continues. This function is really just a wrapper around
623 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
625 $bottomScriptText = $this->getOutput()->getBottomScripts();
626 Hooks
::run( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
628 return $bottomScriptText;
632 * Text with the permalink to the source page,
633 * usually shown on the footer of a printed page
635 * @return string HTML text with an URL
637 function printSource() {
638 $oldid = $this->getRevisionId();
640 $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
641 $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
643 // oldid not available for non existing pages
644 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
647 return $this->msg( 'retrievedfrom' )
648 ->rawParams( '<a dir="ltr" href="' . $url. '">' . $url . '</a>' )
653 * @return string HTML
655 function getUndeleteLink() {
656 $action = $this->getRequest()->getVal( 'action', 'view' );
658 if ( $this->getTitle()->userCan( 'deletedhistory', $this->getUser() ) &&
659 ( !$this->getTitle()->exists() ||
$action == 'history' ) ) {
660 $n = $this->getTitle()->isDeleted();
663 if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {
664 $msg = 'thisisdeleted';
666 $msg = 'viewdeleted';
669 return $this->msg( $msg )->rawParams(
671 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
672 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
683 function subPageSubtitle() {
684 $out = $this->getOutput();
687 if ( !Hooks
::run( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
691 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
692 $ptext = $this->getTitle()->getPrefixedText();
693 if ( preg_match( '/\//', $ptext ) ) {
694 $links = explode( '/', $ptext );
699 $lang = $this->getLanguage();
701 foreach ( $links as $link ) {
702 $growinglink .= $link;
704 $linkObj = Title
::newFromText( $growinglink );
706 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
707 $getlink = Linker
::linkKnown(
709 htmlspecialchars( $display )
715 $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
717 $subpages .= '< ';
720 $subpages .= $getlink;
734 * Returns true if the IP should be shown in the header
737 function showIPinHeader() {
738 global $wgShowIPinHeader;
739 return $wgShowIPinHeader && session_id() != '';
745 function getSearchLink() {
746 $searchPage = SpecialPage
::getTitleFor( 'Search' );
747 return $searchPage->getLocalURL();
753 function escapeSearchLink() {
754 return htmlspecialchars( $this->getSearchLink() );
758 * @param string $type
761 function getCopyright( $type = 'detect' ) {
762 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
764 if ( $type == 'detect' ) {
765 if ( !$this->isRevisionCurrent()
766 && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
774 if ( $type == 'history' ) {
775 $msg = 'history_copyright';
780 if ( $wgRightsPage ) {
781 $title = Title
::newFromText( $wgRightsPage );
782 $link = Linker
::linkKnown( $title, $wgRightsText );
783 } elseif ( $wgRightsUrl ) {
784 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
785 } elseif ( $wgRightsText ) {
786 $link = $wgRightsText;
792 // Allow for site and per-namespace customization of copyright notice.
793 // @todo Remove deprecated $forContent param from hook handlers and then remove here.
797 'SkinCopyrightFooter',
798 array( $this->getTitle(), $type, &$msg, &$link, &$forContent )
801 return $this->msg( $msg )->rawParams( $link )->text();
805 * @return null|string
807 function getCopyrightIcon() {
808 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
812 if ( $wgCopyrightIcon ) {
813 $out = $wgCopyrightIcon;
814 } elseif ( $wgRightsIcon ) {
815 $icon = htmlspecialchars( $wgRightsIcon );
817 if ( $wgRightsUrl ) {
818 $url = htmlspecialchars( $wgRightsUrl );
819 $out .= '<a href="' . $url . '">';
822 $text = htmlspecialchars( $wgRightsText );
823 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
825 if ( $wgRightsUrl ) {
834 * Gets the powered by MediaWiki icon.
837 function getPoweredBy() {
838 global $wgResourceBasePath;
840 $url1 = htmlspecialchars( "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png" );
841 $url1_5 = htmlspecialchars( "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png" );
842 $url2 = htmlspecialchars( "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png" );
843 $text = '<a href="//www.mediawiki.org/"><img src="' . $url1
844 . '" srcset="' . $url1_5 . ' 1.5x, ' . $url2 . ' 2x" '
845 . 'height="31" width="88" alt="Powered by MediaWiki" /></a>';
846 Hooks
::run( 'SkinGetPoweredBy', array( &$text, $this ) );
851 * Get the timestamp of the latest revision, formatted in user language
855 protected function lastModified() {
856 $timestamp = $this->getOutput()->getRevisionTimestamp();
858 # No cached timestamp, load it from the database
859 if ( $timestamp === null ) {
860 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
864 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
865 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
866 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->parse();
871 if ( wfGetLB()->getLaggedSlaveMode() ) {
872 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
879 * @param string $align
882 function logoText( $align = '' ) {
883 if ( $align != '' ) {
884 $a = " style='float: {$align};'";
889 $mp = $this->msg( 'mainpage' )->escaped();
890 $mptitle = Title
::newMainPage();
891 $url = ( is_object( $mptitle ) ?
htmlspecialchars( $mptitle->getLocalURL() ) : '' );
893 $logourl = $this->getLogo();
894 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
900 * Renders a $wgFooterIcons icon according to the method's arguments
901 * @param array $icon The icon to build the html for, see $wgFooterIcons
902 * for the format of this array.
903 * @param bool|string $withImage Whether to use the icon's image or output
904 * a text-only footericon.
905 * @return string HTML
907 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
908 if ( is_string( $icon ) ) {
910 } else { // Assuming array
911 $url = isset( $icon["url"] ) ?
$icon["url"] : null;
912 unset( $icon["url"] );
913 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
914 // do this the lazy way, just pass icon data as an attribute array
915 $html = Html
::element( 'img', $icon );
917 $html = htmlspecialchars( $icon["alt"] );
920 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
927 * Gets the link to the wiki's main page.
930 function mainPageLink() {
931 $s = Linker
::linkKnown(
932 Title
::newMainPage(),
933 $this->msg( 'mainpage' )->escaped()
940 * Returns an HTML link for use in the footer
941 * @param string $desc The i18n message key for the link text
942 * @param string $page The i18n message key for the page to link to
943 * @return string HTML anchor
945 public function footerLink( $desc, $page ) {
946 // if the link description has been set to "-" in the default language,
947 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
948 // then it is disabled, for all languages.
951 // Otherwise, we display the link for the user, described in their
952 // language (which may or may not be the same as the default language),
953 // but we make the link target be the one site-wide page.
954 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
960 return Linker
::linkKnown(
962 $this->msg( $desc )->escaped()
968 * Gets the link to the wiki's privacy policy page.
969 * @return string HTML
971 function privacyLink() {
972 return $this->footerLink( 'privacy', 'privacypage' );
976 * Gets the link to the wiki's about page.
977 * @return string HTML
979 function aboutLink() {
980 return $this->footerLink( 'aboutsite', 'aboutpage' );
984 * Gets the link to the wiki's general disclaimers page.
985 * @return string HTML
987 function disclaimerLink() {
988 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
992 * Return URL options for the 'edit page' link.
993 * This may include an 'oldid' specifier, if the current page view is such.
998 function editUrlOptions() {
999 $options = array( 'action' => 'edit' );
1001 if ( !$this->isRevisionCurrent() ) {
1002 $options['oldid'] = intval( $this->getRevisionId() );
1009 * @param User|int $id
1012 function showEmailUser( $id ) {
1013 if ( $id instanceof User
) {
1016 $targetUser = User
::newFromId( $id );
1019 # The sending user must have a confirmed email address and the target
1020 # user must have a confirmed email address and allow emails from users.
1021 return $this->getUser()->canSendEmail() &&
1022 $targetUser->canReceiveEmail();
1026 * This function previously returned a fully resolved style path URL to images or styles stored in
1027 * the legacy skins/common/ directory.
1029 * That directory has been removed in 1.24 and the function always returns an empty string.
1031 * @deprecated since 1.24
1032 * @param string $name The name or path of a skin resource file
1033 * @return string Empty string
1035 function getCommonStylePath( $name ) {
1036 wfDeprecated( __METHOD__
, '1.24' );
1041 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1042 * This method returns a url resolved using the configured skin style path
1043 * and includes the style version inside of the url.
1045 * Requires $stylename to be set, otherwise throws MWException.
1047 * @param string $name The name or path of a skin resource file
1048 * @return string The fully resolved style path url including styleversion
1049 * @throws MWException
1051 function getSkinStylePath( $name ) {
1052 global $wgStylePath, $wgStyleVersion;
1054 if ( $this->stylename
=== null ) {
1055 $class = get_class( $this );
1056 throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
1059 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1062 /* these are used extensively in SkinTemplate, but also some other places */
1065 * @param string $urlaction
1068 static function makeMainPageUrl( $urlaction = '' ) {
1069 $title = Title
::newMainPage();
1070 self
::checkTitle( $title, '' );
1072 return $title->getLocalURL( $urlaction );
1076 * Make a URL for a Special Page using the given query and protocol.
1078 * If $proto is set to null, make a local URL. Otherwise, make a full
1079 * URL with the protocol specified.
1081 * @param string $name Name of the Special page
1082 * @param string $urlaction Query to append
1083 * @param string|null $proto Protocol to use or null for a local URL
1086 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1087 $title = SpecialPage
::getSafeTitleFor( $name );
1088 if ( is_null( $proto ) ) {
1089 return $title->getLocalURL( $urlaction );
1091 return $title->getFullURL( $urlaction, false, $proto );
1096 * @param string $name
1097 * @param string $subpage
1098 * @param string $urlaction
1101 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1102 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1103 return $title->getLocalURL( $urlaction );
1107 * @param string $name
1108 * @param string $urlaction
1111 static function makeI18nUrl( $name, $urlaction = '' ) {
1112 $title = Title
::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1113 self
::checkTitle( $title, $name );
1114 return $title->getLocalURL( $urlaction );
1118 * @param string $name
1119 * @param string $urlaction
1122 static function makeUrl( $name, $urlaction = '' ) {
1123 $title = Title
::newFromText( $name );
1124 self
::checkTitle( $title, $name );
1126 return $title->getLocalURL( $urlaction );
1130 * If url string starts with http, consider as external URL, else
1132 * @param string $name
1133 * @return string URL
1135 static function makeInternalOrExternalUrl( $name ) {
1136 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1139 return self
::makeUrl( $name );
1144 * this can be passed the NS number as defined in Language.php
1145 * @param string $name
1146 * @param string $urlaction
1147 * @param int $namespace
1150 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1151 $title = Title
::makeTitleSafe( $namespace, $name );
1152 self
::checkTitle( $title, $name );
1154 return $title->getLocalURL( $urlaction );
1158 * these return an array with the 'href' and boolean 'exists'
1159 * @param string $name
1160 * @param string $urlaction
1163 static function makeUrlDetails( $name, $urlaction = '' ) {
1164 $title = Title
::newFromText( $name );
1165 self
::checkTitle( $title, $name );
1168 'href' => $title->getLocalURL( $urlaction ),
1169 'exists' => $title->isKnown(),
1174 * Make URL details where the article exists (or at least it's convenient to think so)
1175 * @param string $name Article name
1176 * @param string $urlaction
1179 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1180 $title = Title
::newFromText( $name );
1181 self
::checkTitle( $title, $name );
1184 'href' => $title->getLocalURL( $urlaction ),
1190 * make sure we have some title to operate on
1192 * @param Title $title
1193 * @param string $name
1195 static function checkTitle( &$title, $name ) {
1196 if ( !is_object( $title ) ) {
1197 $title = Title
::newFromText( $name );
1198 if ( !is_object( $title ) ) {
1199 $title = Title
::newFromText( '--error: link target missing--' );
1205 * Build an array that represents the sidebar(s), the navigation bar among them.
1207 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1209 * The format of the returned array is array( heading => content, ... ), where:
1210 * - heading is the heading of a navigation portlet. It is either:
1211 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1212 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1213 * - plain text, which should be HTML-escaped by the skin
1214 * - content is the contents of the portlet. It is either:
1215 * - HTML text (<ul><li>...</li>...</ul>)
1216 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1217 * - (for a magic string as a key, any value)
1219 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1220 * and can technically insert anything in here; skin creators are expected to handle
1221 * values described above.
1225 function buildSidebar() {
1226 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1228 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1230 if ( $wgEnableSidebarCache ) {
1231 $cachedsidebar = $wgMemc->get( $key );
1232 if ( $cachedsidebar ) {
1233 Hooks
::run( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
1235 return $cachedsidebar;
1240 $this->addToSidebar( $bar, 'sidebar' );
1242 Hooks
::run( 'SkinBuildSidebar', array( $this, &$bar ) );
1243 if ( $wgEnableSidebarCache ) {
1244 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1247 Hooks
::run( 'SidebarBeforeOutput', array( $this, &$bar ) );
1253 * Add content from a sidebar system message
1254 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1256 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1259 * @param string $message
1261 function addToSidebar( &$bar, $message ) {
1262 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1266 * Add content from plain text
1269 * @param string $text
1272 function addToSidebarPlain( &$bar, $text ) {
1273 $lines = explode( "\n", $text );
1277 foreach ( $lines as $line ) {
1278 if ( strpos( $line, '*' ) !== 0 ) {
1281 $line = rtrim( $line, "\r" ); // for Windows compat
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 if ( count( $line ) !== 2 ) {
1295 // Second sanity check, could be hit by people doing
1296 // funky stuff with parserfuncs... (bug 33321)
1300 $extraAttribs = array();
1302 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1303 if ( $msgLink->exists() ) {
1304 $link = $msgLink->text();
1305 if ( $link == '-' ) {
1311 $msgText = $this->msg( $line[1] );
1312 if ( $msgText->exists() ) {
1313 $text = $msgText->text();
1318 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1321 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1322 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1323 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1324 $extraAttribs['rel'] = 'nofollow';
1327 global $wgExternalLinkTarget;
1328 if ( $wgExternalLinkTarget ) {
1329 $extraAttribs['target'] = $wgExternalLinkTarget;
1332 $title = Title
::newFromText( $link );
1335 $title = $title->fixSpecialName();
1336 $href = $title->getLinkURL();
1338 $href = 'INVALID-TITLE';
1342 $bar[$heading][] = array_merge( array(
1345 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1358 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1359 * should be loaded by OutputPage. That module no longer exists and the return value of this
1360 * method is ignored.
1362 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1363 * can be used instead (SkinTemplate-based skins do it automatically).
1365 * @deprecated since 1.22
1368 public function commonPrintStylesheet() {
1369 wfDeprecated( __METHOD__
, '1.22' );
1374 * Gets new talk page messages for the current user and returns an
1375 * appropriate alert message (or an empty string if there are no messages)
1378 function getNewtalks() {
1380 $newMessagesAlert = '';
1381 $user = $this->getUser();
1382 $newtalks = $user->getNewMessageLinks();
1383 $out = $this->getOutput();
1385 // Allow extensions to disable or modify the new messages alert
1386 if ( !Hooks
::run( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1389 if ( $newMessagesAlert ) {
1390 return $newMessagesAlert;
1393 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1394 $uTalkTitle = $user->getTalkPage();
1395 $lastSeenRev = isset( $newtalks[0]['rev'] ) ?
$newtalks[0]['rev'] : null;
1397 if ( $lastSeenRev !== null ) {
1398 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1399 $latestRev = Revision
::newFromTitle( $uTalkTitle, false, Revision
::READ_NORMAL
);
1400 if ( $latestRev !== null ) {
1401 // Singular if only 1 unseen revision, plural if several unseen revisions.
1402 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1403 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1404 $lastSeenRev, $latestRev, 10, 'include_new' );
1407 // Singular if no revision -> diff link will show latest change only in any case
1410 $plural = $plural ?
999 : 1;
1411 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1412 // the number of revisions or authors is not necessarily the same as the number of
1414 $newMessagesLink = Linker
::linkKnown(
1416 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1418 array( 'redirect' => 'no' )
1421 $newMessagesDiffLink = Linker
::linkKnown(
1423 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1425 $lastSeenRev !== null
1426 ?
array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1427 : array( 'diff' => 'cur' )
1430 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1431 $newMessagesAlert = $this->msg(
1432 'youhavenewmessagesfromusers',
1434 $newMessagesDiffLink
1435 )->numParams( $nofAuthors, $plural );
1437 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1438 $newMessagesAlert = $this->msg(
1439 $nofAuthors > 10 ?
'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1441 $newMessagesDiffLink
1442 )->numParams( $plural );
1444 $newMessagesAlert = $newMessagesAlert->text();
1445 # Disable Squid cache
1446 $out->setSquidMaxage( 0 );
1447 } elseif ( count( $newtalks ) ) {
1448 $sep = $this->msg( 'newtalkseparator' )->escaped();
1451 foreach ( $newtalks as $newtalk ) {
1452 $msgs[] = Xml
::element(
1454 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1457 $parts = implode( $sep, $msgs );
1458 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1459 $out->setSquidMaxage( 0 );
1462 return $newMessagesAlert;
1466 * Get a cached notice
1468 * @param string $name Message name, or 'default' for $wgSiteNotice
1469 * @return string HTML fragment
1471 private function getCachedNotice( $name ) {
1472 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1476 if ( $name === 'default' ) {
1478 global $wgSiteNotice;
1479 $notice = $wgSiteNotice;
1480 if ( empty( $notice ) ) {
1484 $msg = $this->msg( $name )->inContentLanguage();
1485 if ( $msg->isDisabled() ) {
1488 $notice = $msg->plain();
1491 // Use the extra hash appender to let eg SSL variants separately cache.
1492 $key = wfMemcKey( $name . $wgRenderHashAppend );
1493 $cachedNotice = $parserMemc->get( $key );
1494 if ( is_array( $cachedNotice ) ) {
1495 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1496 $notice = $cachedNotice['html'];
1505 $parsed = $this->getOutput()->parse( $notice );
1506 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1510 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1511 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1516 * Get a notice based on page's namespace
1518 * @return string HTML fragment
1520 function getNamespaceNotice() {
1522 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1523 $namespaceNotice = $this->getCachedNotice( $key );
1524 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1525 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1527 $namespaceNotice = '';
1530 return $namespaceNotice;
1534 * Get the site notice
1536 * @return string HTML fragment
1538 function getSiteNotice() {
1541 if ( Hooks
::run( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1542 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1543 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1545 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1546 if ( !$anonNotice ) {
1547 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1549 $siteNotice = $anonNotice;
1552 if ( !$siteNotice ) {
1553 $siteNotice = $this->getCachedNotice( 'default' );
1557 Hooks
::run( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1562 * Create a section edit link. This supersedes editSectionLink() and
1563 * editSectionLinkForOther().
1565 * @param Title $nt The title being linked to (may not be the same as
1566 * the current page, if the section is included from a template)
1567 * @param string $section The designation of the section being pointed to,
1568 * to be included in the link, like "§ion=$section"
1569 * @param string $tooltip The tooltip to use for the link: will be escaped
1570 * and wrapped in the 'editsectionhint' message
1571 * @param string $lang Language code
1572 * @return string HTML to use for edit link
1574 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1575 // HTML generated here should probably have userlangattributes
1576 // added to it for LTR text on RTL pages
1578 $lang = wfGetLangObj( $lang );
1581 if ( !is_null( $tooltip ) ) {
1582 # Bug 25462: undo double-escaping.
1583 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1584 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1585 ->inLanguage( $lang )->text();
1589 'editsection' => array(
1590 'text' => wfMessage( 'editsection' )->inLanguage( $lang )->escaped(),
1591 'targetTitle' => $nt,
1592 'attribs' => $attribs,
1593 'query' => array( 'action' => 'edit', 'section' => $section ),
1594 'options' => array( 'noclasses', 'known' )
1598 Hooks
::run( 'SkinEditSectionLinks', array( $this, $nt, $section, $tooltip, &$links, $lang ) );
1600 $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
1602 $linksHtml = array();
1603 foreach ( $links as $k => $linkDetails ) {
1604 $linksHtml[] = Linker
::link(
1605 $linkDetails['targetTitle'],
1606 $linkDetails['text'],
1607 $linkDetails['attribs'],
1608 $linkDetails['query'],
1609 $linkDetails['options']
1614 '<span class="mw-editsection-divider">'
1615 . wfMessage( 'pipe-separator' )->inLanguage( $lang )->text()
1620 $result .= '<span class="mw-editsection-bracket">]</span></span>';
1622 Hooks
::run( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1627 * Use PHP's magic __call handler to intercept legacy calls to the linker
1628 * for backwards compatibility.
1630 * @param string $fname Name of called method
1631 * @param array $args Arguments to the method
1632 * @throws MWException
1635 function __call( $fname, $args ) {
1636 $realFunction = array( 'Linker', $fname );
1637 if ( is_callable( $realFunction ) ) {
1638 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1639 return call_user_func_array( $realFunction, $args );
1641 $className = get_class( $this );
1642 throw new MWException( "Call to undefined method $className::$fname" );