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.
29 * This base class is also the "Standard" skin.
31 * See docs/skin.txt for more information.
35 abstract class Skin
extends ContextSource
{
36 protected $skinname = 'standard';
37 protected $mRelevantTitle = null;
38 protected $mRelevantUser = null;
41 * Fetch the set of available skins.
42 * @return array Associative array of strings
44 static function getSkinNames() {
45 global $wgValidSkinNames;
46 static $skinsInitialised = false;
48 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
49 # Get a list of available skins
50 # Build using the regular expression '^(.*).php$'
51 # Array keys are all lower case, array value keep the case used by filename
53 wfProfileIn( __METHOD__
. '-init' );
55 global $wgStyleDirectory;
57 $skinDir = dir( $wgStyleDirectory );
59 if ( $skinDir !== false && $skinDir !== null ) {
60 # while code from www.php.net
61 while ( false !== ( $file = $skinDir->read() ) ) {
62 // Skip non-PHP files, hidden files, and '.dep' includes
65 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
67 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
72 $skinsInitialised = true;
73 wfProfileOut( __METHOD__
. '-init' );
75 return $wgValidSkinNames;
79 * Fetch the skinname messages for available skins.
82 static function getSkinNameMessages() {
84 foreach ( self
::getSkinNames() as $skinKey => $skinName ) {
85 // Messages: skinname-vector, skinname-monobook
86 $messages[] = "skinname-$skinKey";
92 * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
93 * Useful for Special:Preferences and other places where you
94 * only want to show skins users _can_ use.
98 public static function getAllowedSkins() {
101 $allowedSkins = self
::getSkinNames();
103 foreach ( $wgSkipSkins as $skip ) {
104 unset( $allowedSkins[$skip] );
107 return $allowedSkins;
111 * @deprecated since 1.23, use getAllowedSkins
114 public static function getUsableSkins() {
115 wfDeprecated( __METHOD__
, '1.23' );
116 return self
::getAllowedSkins();
120 * Normalize a skin preference value to a form that can be loaded.
121 * If a skin can't be found, it will fall back to the configured
122 * default (or the old 'Classic' skin if that's broken).
123 * @param string $key 'monobook', 'standard', etc.
126 static function normalizeKey( $key ) {
127 global $wgDefaultSkin;
129 $skinNames = Skin
::getSkinNames();
131 if ( $key == '' ||
$key == 'default' ) {
132 // Don't return the default immediately;
133 // in a misconfiguration we need to fall back.
134 $key = $wgDefaultSkin;
137 if ( isset( $skinNames[$key] ) ) {
141 // Older versions of the software used a numeric setting
142 // in the user preferences.
148 if ( isset( $fallback[$key] ) ) {
149 $key = $fallback[$key];
152 if ( isset( $skinNames[$key] ) ) {
154 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
155 return $wgDefaultSkin;
162 * Factory method for loading a skin of a given type
163 * @param string $key 'monobook', 'standard', etc.
166 static function &newFromKey( $key ) {
167 global $wgStyleDirectory;
169 $key = Skin
::normalizeKey( $key );
171 $skinNames = Skin
::getSkinNames();
172 $skinName = $skinNames[$key];
173 $className = "Skin{$skinName}";
175 # Grab the skin class and initialise it.
176 if ( !class_exists( $className ) ) {
178 require_once "{$wgStyleDirectory}/{$skinName}.php";
180 # Check if we got if not fallback to default skin
181 if ( !class_exists( $className ) ) {
182 # DO NOT die if the class isn't found. This breaks maintenance
183 # scripts and can cause a user account to be unrecoverable
184 # except by SQL manipulation if a previously valid skin name
185 # is no longer valid.
186 wfDebug( "Skin class does not exist: $className\n" );
187 $className = 'SkinVector';
188 require_once "{$wgStyleDirectory}/Vector.php";
191 $skin = new $className( $key );
196 * @return string Skin name
198 public function getSkinName() {
199 return $this->skinname
;
203 * @param OutputPage $out
205 function initPage( OutputPage
$out ) {
206 wfProfileIn( __METHOD__
);
208 $this->preloadExistence();
210 wfProfileOut( __METHOD__
);
214 * Defines the ResourceLoader modules that should be added to the skin
215 * It is recommended that skins wishing to override call parent::getDefaultModules()
216 * and substitute out any modules they wish to change by using a key to look them up
217 * @return array Array of modules with helper keys for easy overriding
219 public function getDefaultModules() {
220 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
221 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
223 $out = $this->getOutput();
224 $user = $out->getUser();
226 // modules that enhance the page content in some way
228 'mediawiki.page.ready',
230 // modules that exist for legacy reasons
232 // modules relating to search functionality
234 // modules relating to functionality relating to watching an article
236 // modules which relate to the current users preferences
239 if ( $wgIncludeLegacyJavaScript ) {
240 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
243 if ( $wgPreloadJavaScriptMwUtil ) {
244 $modules['legacy'][] = 'mediawiki.util';
247 // Add various resources if required
249 $modules['legacy'][] = 'mediawiki.legacy.ajax';
251 if ( $wgEnableAPI ) {
252 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
253 && $user->isAllowed( 'writeapi' )
255 $modules['watch'][] = 'mediawiki.page.watch.ajax';
258 $modules['search'][] = 'mediawiki.searchSuggest';
262 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
263 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
266 // Crazy edit-on-double-click stuff
267 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
268 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
274 * Preload the existence of three commonly-requested pages in a single query
276 function preloadExistence() {
277 $user = $this->getUser();
280 $titles = array( $user->getUserPage(), $user->getTalkPage() );
283 if ( $this->getTitle()->isSpecialPage() ) {
285 } elseif ( $this->getTitle()->isTalkPage() ) {
286 $titles[] = $this->getTitle()->getSubjectPage();
288 $titles[] = $this->getTitle()->getTalkPage();
291 $lb = new LinkBatch( $titles );
292 $lb->setCaller( __METHOD__
);
297 * Get the current revision ID
301 public function getRevisionId() {
302 return $this->getOutput()->getRevisionId();
306 * Whether the revision displayed is the latest revision of the page
310 public function isRevisionCurrent() {
311 $revID = $this->getRevisionId();
312 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
316 * Set the "relevant" title
317 * @see self::getRelevantTitle()
320 public function setRelevantTitle( $t ) {
321 $this->mRelevantTitle
= $t;
325 * Return the "relevant" title.
326 * A "relevant" title is not necessarily the actual title of the page.
327 * Special pages like Special:MovePage use set the page they are acting on
328 * as their "relevant" title, this allows the skin system to display things
329 * such as content tabs which belong to to that page instead of displaying
330 * a basic special page tab which has almost no meaning.
334 public function getRelevantTitle() {
335 if ( isset( $this->mRelevantTitle
) ) {
336 return $this->mRelevantTitle
;
338 return $this->getTitle();
342 * Set the "relevant" user
343 * @see self::getRelevantUser()
346 public function setRelevantUser( $u ) {
347 $this->mRelevantUser
= $u;
351 * Return the "relevant" user.
352 * A "relevant" user is similar to a relevant title. Special pages like
353 * Special:Contributions mark the user which they are relevant to so that
354 * things like the toolbox can display the information they usually are only
355 * able to display on a user's userpage and talkpage.
358 public function getRelevantUser() {
359 if ( isset( $this->mRelevantUser
) ) {
360 return $this->mRelevantUser
;
362 $title = $this->getRelevantTitle();
363 if ( $title->hasSubjectNamespace( NS_USER
) ) {
364 $rootUser = $title->getRootText();
365 if ( User
::isIP( $rootUser ) ) {
366 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
368 $user = User
::newFromName( $rootUser, false );
369 if ( $user && $user->isLoggedIn() ) {
370 $this->mRelevantUser
= $user;
373 return $this->mRelevantUser
;
379 * Outputs the HTML generated by other functions.
380 * @param OutputPage $out
382 abstract function outputPage( OutputPage
$out = null );
388 static function makeVariablesScript( $data ) {
390 return Html
::inlineScript(
391 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
399 * Make a "<script>" tag containing global variables
401 * @deprecated since 1.19
402 * @param mixed $unused
403 * @return string HTML fragment
405 public static function makeGlobalVariablesScript( $unused ) {
408 wfDeprecated( __METHOD__
, '1.19' );
410 return self
::makeVariablesScript( $wgOut->getJSVars() );
414 * Get the query to generate a dynamic stylesheet
418 public static function getDynamicStylesheetQuery() {
419 global $wgSquidMaxage;
423 'maxage' => $wgSquidMaxage,
424 'usemsgcache' => 'yes',
425 'ctype' => 'text/css',
426 'smaxage' => $wgSquidMaxage,
431 * Add skin specific stylesheets
432 * Calling this method with an $out of anything but the same OutputPage
433 * inside ->getOutput() is deprecated. The $out arg is kept
434 * for compatibility purposes with skins.
435 * @param OutputPage $out
438 abstract function setupSkinUserCss( OutputPage
$out );
442 * @param Title $title
445 function getPageClasses( $title ) {
446 $numeric = 'ns-' . $title->getNamespace();
448 if ( $title->isSpecialPage() ) {
449 $type = 'ns-special';
450 // bug 23315: provide a class based on the canonical special page name without subpages
451 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
452 if ( $canonicalName ) {
453 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
455 $type .= ' mw-invalidspecialpage';
457 } elseif ( $title->isTalkPage() ) {
460 $type = 'ns-subject';
463 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
465 return "$numeric $type $name";
469 * Return values for <html> element
470 * @return array of associative name-to-value elements for <html> element
472 public function getHtmlElementAttributes() {
473 $lang = $this->getLanguage();
475 'lang' => $lang->getHtmlCode(),
476 'dir' => $lang->getDir(),
477 'class' => 'client-nojs',
482 * This will be called by OutputPage::headElement when it is creating the
483 * "<body>" tag, skins can override it if they have a need to add in any
484 * body attributes or classes of their own.
485 * @param OutputPage $out
486 * @param array $bodyAttrs
488 function addToBodyAttributes( $out, &$bodyAttrs ) {
489 // does nothing by default
504 function getCategoryLinks() {
505 global $wgUseCategoryBrowser;
507 $out = $this->getOutput();
508 $allCats = $out->getCategoryLinks();
510 if ( !count( $allCats ) ) {
518 $colon = $this->msg( 'colon-separator' )->escaped();
520 if ( !empty( $allCats['normal'] ) ) {
521 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
523 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
524 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
525 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
526 Linker
::link( Title
::newFromText( $linkPage ), $msg )
527 . $colon . '<ul>' . $t . '</ul>' . '</div>';
531 if ( isset( $allCats['hidden'] ) ) {
532 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
533 $class = ' mw-hidden-cats-user-shown';
534 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
535 $class = ' mw-hidden-cats-ns-shown';
537 $class = ' mw-hidden-cats-hidden';
540 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
541 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
542 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
546 # optional 'dmoz-like' category browser. Will be shown under the list
547 # of categories an article belong to
548 if ( $wgUseCategoryBrowser ) {
549 $s .= '<br /><hr />';
551 # get a big array of the parents tree
552 $parenttree = $this->getTitle()->getParentCategoryTree();
553 # Skin object passed by reference cause it can not be
554 # accessed under the method subfunction drawCategoryBrowser
555 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
556 # Clean out bogus first entry and sort them
557 unset( $tempout[0] );
559 # Output one per line
560 $s .= implode( "<br />\n", $tempout );
567 * Render the array as a series of links.
568 * @param array $tree Categories tree returned by Title::getParentCategoryTree
569 * @return string Separated by >, terminate with "\n"
571 function drawCategoryBrowser( $tree ) {
574 foreach ( $tree as $element => $parent ) {
575 if ( empty( $parent ) ) {
576 # element start a new list
579 # grab the others elements
580 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
583 # add our current element to the list
584 $eltitle = Title
::newFromText( $element );
585 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
594 function getCategories() {
595 $out = $this->getOutput();
597 $catlinks = $this->getCategoryLinks();
599 $classes = 'catlinks';
601 // Check what we're showing
602 $allCats = $out->getCategoryLinks();
603 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
604 $this->getTitle()->getNamespace() == NS_CATEGORY
;
606 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
607 $classes .= ' catlinks-allhidden';
610 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
614 * This runs a hook to allow extensions placing their stuff after content
615 * and article metadata (e.g. categories).
616 * Note: This function has nothing to do with afterContent().
618 * This hook is placed here in order to allow using the same hook for all
619 * skins, both the SkinTemplate based ones and the older ones, which directly
620 * use this class to get their data.
622 * The output of this function gets processed in SkinTemplate::outputPage() for
623 * the SkinTemplate based skins, all other skins should directly echo it.
625 * @return string Empty by default, if not changed by any hook function.
627 protected function afterContentHook() {
630 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
631 // adding just some spaces shouldn't toggle the output
632 // of the whole <div/>, so we use trim() here
633 if ( trim( $data ) != '' ) {
634 // Doing this here instead of in the skins to
635 // ensure that the div has the same ID in all
637 $data = "<div id='mw-data-after-content'>\n" .
642 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
649 * Generate debug data HTML for displaying at the bottom of the main content
651 * @return string HTML containing debug data, if enabled (otherwise empty).
653 protected function generateDebugHTML() {
654 return MWDebug
::getHTMLDebugLog();
658 * This gets called shortly before the "</body>" tag.
660 * @return string HTML-wrapped JS code to be put before "</body>"
662 function bottomScripts() {
663 // TODO and the suckage continues. This function is really just a wrapper around
664 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
666 $bottomScriptText = $this->getOutput()->getBottomScripts();
667 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
669 return $bottomScriptText;
673 * Text with the permalink to the source page,
674 * usually shown on the footer of a printed page
676 * @return string HTML text with an URL
678 function printSource() {
679 $oldid = $this->getRevisionId();
681 $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
682 $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
684 // oldid not available for non existing pages
685 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
688 return $this->msg( 'retrievedfrom', '<a dir="ltr" href="' . $url
689 . '">' . $url . '</a>' )->text();
695 function getUndeleteLink() {
696 $action = $this->getRequest()->getVal( 'action', 'view' );
698 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
699 ( $this->getTitle()->getArticleID() == 0 ||
$action == 'history' ) ) {
700 $n = $this->getTitle()->isDeleted();
703 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
704 $msg = 'thisisdeleted';
706 $msg = 'viewdeleted';
709 return $this->msg( $msg )->rawParams(
711 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
712 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
723 function subPageSubtitle() {
724 $out = $this->getOutput();
727 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
731 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
732 $ptext = $this->getTitle()->getPrefixedText();
733 if ( preg_match( '/\//', $ptext ) ) {
734 $links = explode( '/', $ptext );
739 $lang = $this->getLanguage();
741 foreach ( $links as $link ) {
742 $growinglink .= $link;
744 $linkObj = Title
::newFromText( $growinglink );
746 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
747 $getlink = Linker
::linkKnown(
749 htmlspecialchars( $display )
755 $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
757 $subpages .= '< ';
760 $subpages .= $getlink;
774 * Returns true if the IP should be shown in the header
777 function showIPinHeader() {
778 global $wgShowIPinHeader;
779 return $wgShowIPinHeader && session_id() != '';
785 function getSearchLink() {
786 $searchPage = SpecialPage
::getTitleFor( 'Search' );
787 return $searchPage->getLocalURL();
793 function escapeSearchLink() {
794 return htmlspecialchars( $this->getSearchLink() );
798 * @param string $type
801 function getCopyright( $type = 'detect' ) {
802 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
804 if ( $type == 'detect' ) {
805 if ( !$this->isRevisionCurrent()
806 && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
814 if ( $type == 'history' ) {
815 $msg = 'history_copyright';
820 if ( $wgRightsPage ) {
821 $title = Title
::newFromText( $wgRightsPage );
822 $link = Linker
::linkKnown( $title, $wgRightsText );
823 } elseif ( $wgRightsUrl ) {
824 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
825 } elseif ( $wgRightsText ) {
826 $link = $wgRightsText;
832 // Allow for site and per-namespace customization of copyright notice.
833 // @todo Remove deprecated $forContent param from hook handlers and then remove here.
837 'SkinCopyrightFooter',
838 array( $this->getTitle(), $type, &$msg, &$link, &$forContent )
841 return $this->msg( $msg )->rawParams( $link )->text();
845 * @return null|string
847 function getCopyrightIcon() {
848 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
852 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
853 $out = $wgCopyrightIcon;
854 } elseif ( $wgRightsIcon ) {
855 $icon = htmlspecialchars( $wgRightsIcon );
857 if ( $wgRightsUrl ) {
858 $url = htmlspecialchars( $wgRightsUrl );
859 $out .= '<a href="' . $url . '">';
862 $text = htmlspecialchars( $wgRightsText );
863 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
865 if ( $wgRightsUrl ) {
874 * Gets the powered by MediaWiki icon.
877 function getPoweredBy() {
880 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
881 $text = '<a href="//www.mediawiki.org/"><img src="' . $url
882 . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
883 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
888 * Get the timestamp of the latest revision, formatted in user language
892 protected function lastModified() {
893 $timestamp = $this->getOutput()->getRevisionTimestamp();
895 # No cached timestamp, load it from the database
896 if ( $timestamp === null ) {
897 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
901 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
902 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
903 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
908 if ( wfGetLB()->getLaggedSlaveMode() ) {
909 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
916 * @param string $align
919 function logoText( $align = '' ) {
920 if ( $align != '' ) {
921 $a = " style='float: {$align};'";
926 $mp = $this->msg( 'mainpage' )->escaped();
927 $mptitle = Title
::newMainPage();
928 $url = ( is_object( $mptitle ) ?
htmlspecialchars( $mptitle->getLocalURL() ) : '' );
930 $logourl = $this->getLogo();
931 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
937 * Renders a $wgFooterIcons icon according to the method's arguments
938 * @param array $icon The icon to build the html for, see $wgFooterIcons
939 * for the format of this array.
940 * @param bool|string $withImage Whether to use the icon's image or output
941 * a text-only footericon.
942 * @return string HTML
944 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
945 if ( is_string( $icon ) ) {
947 } else { // Assuming array
948 $url = isset( $icon["url"] ) ?
$icon["url"] : null;
949 unset( $icon["url"] );
950 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
951 // do this the lazy way, just pass icon data as an attribute array
952 $html = Html
::element( 'img', $icon );
954 $html = htmlspecialchars( $icon["alt"] );
957 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
964 * Gets the link to the wiki's main page.
967 function mainPageLink() {
968 $s = Linker
::linkKnown(
969 Title
::newMainPage(),
970 $this->msg( 'mainpage' )->escaped()
977 * Returns an HTML link for use in the footer
978 * @param string $desc i18n message key for the link text
979 * @param string $page i18n message key for the page to link to
980 * @return string HTML anchor
982 public function footerLink( $desc, $page ) {
983 // if the link description has been set to "-" in the default language,
984 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
985 // then it is disabled, for all languages.
988 // Otherwise, we display the link for the user, described in their
989 // language (which may or may not be the same as the default language),
990 // but we make the link target be the one site-wide page.
991 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
993 return Linker
::linkKnown(
995 $this->msg( $desc )->escaped()
1001 * Gets the link to the wiki's privacy policy page.
1002 * @return string HTML
1004 function privacyLink() {
1005 return $this->footerLink( 'privacy', 'privacypage' );
1009 * Gets the link to the wiki's about page.
1010 * @return string HTML
1012 function aboutLink() {
1013 return $this->footerLink( 'aboutsite', 'aboutpage' );
1017 * Gets the link to the wiki's general disclaimers page.
1018 * @return string HTML
1020 function disclaimerLink() {
1021 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1025 * Return URL options for the 'edit page' link.
1026 * This may include an 'oldid' specifier, if the current page view is such.
1031 function editUrlOptions() {
1032 $options = array( 'action' => 'edit' );
1034 if ( !$this->isRevisionCurrent() ) {
1035 $options['oldid'] = intval( $this->getRevisionId() );
1042 * @param User|int $id
1045 function showEmailUser( $id ) {
1046 if ( $id instanceof User
) {
1049 $targetUser = User
::newFromId( $id );
1052 # The sending user must have a confirmed email address and the target
1053 # user must have a confirmed email address and allow emails from users.
1054 return $this->getUser()->canSendEmail() &&
1055 $targetUser->canReceiveEmail();
1059 * Return a fully resolved style path url to images or styles stored in the common folder.
1060 * This method returns a url resolved using the configured skin style path
1061 * and includes the style version inside of the url.
1062 * @param string $name The name or path of a skin resource file
1063 * @return string The fully resolved style path url including styleversion
1065 function getCommonStylePath( $name ) {
1066 global $wgStylePath, $wgStyleVersion;
1067 return "$wgStylePath/common/$name?$wgStyleVersion";
1071 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1072 * This method returns a url resolved using the configured skin style path
1073 * and includes the style version inside of the url.
1074 * @param string $name The name or path of a skin resource file
1075 * @return string The fully resolved style path url including styleversion
1077 function getSkinStylePath( $name ) {
1078 global $wgStylePath, $wgStyleVersion;
1079 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1082 /* these are used extensively in SkinTemplate, but also some other places */
1085 * @param string $urlaction
1088 static function makeMainPageUrl( $urlaction = '' ) {
1089 $title = Title
::newMainPage();
1090 self
::checkTitle( $title, '' );
1092 return $title->getLocalURL( $urlaction );
1096 * Make a URL for a Special Page using the given query and protocol.
1098 * If $proto is set to null, make a local URL. Otherwise, make a full
1099 * URL with the protocol specified.
1101 * @param string $name Name of the Special page
1102 * @param string $urlaction Query to append
1103 * @param string|null $proto Protocol to use or null for a local URL
1106 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1107 $title = SpecialPage
::getSafeTitleFor( $name );
1108 if ( is_null( $proto ) ) {
1109 return $title->getLocalURL( $urlaction );
1111 return $title->getFullURL( $urlaction, false, $proto );
1116 * @param string $name
1117 * @param string $subpage
1118 * @param string $urlaction
1121 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1122 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1123 return $title->getLocalURL( $urlaction );
1127 * @param string $name
1128 * @param string $urlaction
1131 static function makeI18nUrl( $name, $urlaction = '' ) {
1132 $title = Title
::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1133 self
::checkTitle( $title, $name );
1134 return $title->getLocalURL( $urlaction );
1138 * @param string $name
1139 * @param string $urlaction
1142 static function makeUrl( $name, $urlaction = '' ) {
1143 $title = Title
::newFromText( $name );
1144 self
::checkTitle( $title, $name );
1146 return $title->getLocalURL( $urlaction );
1150 * If url string starts with http, consider as external URL, else
1152 * @param string $name
1153 * @return string URL
1155 static function makeInternalOrExternalUrl( $name ) {
1156 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1159 return self
::makeUrl( $name );
1164 * this can be passed the NS number as defined in Language.php
1165 * @param string $name
1166 * @param string $urlaction
1167 * @param int $namespace
1170 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1171 $title = Title
::makeTitleSafe( $namespace, $name );
1172 self
::checkTitle( $title, $name );
1174 return $title->getLocalURL( $urlaction );
1178 * these return an array with the 'href' and boolean 'exists'
1179 * @param string $name
1180 * @param string $urlaction
1183 static function makeUrlDetails( $name, $urlaction = '' ) {
1184 $title = Title
::newFromText( $name );
1185 self
::checkTitle( $title, $name );
1188 'href' => $title->getLocalURL( $urlaction ),
1189 'exists' => $title->getArticleID() != 0,
1194 * Make URL details where the article exists (or at least it's convenient to think so)
1195 * @param string $name Article name
1196 * @param string $urlaction
1199 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1200 $title = Title
::newFromText( $name );
1201 self
::checkTitle( $title, $name );
1204 'href' => $title->getLocalURL( $urlaction ),
1210 * make sure we have some title to operate on
1212 * @param Title $title
1213 * @param string $name
1215 static function checkTitle( &$title, $name ) {
1216 if ( !is_object( $title ) ) {
1217 $title = Title
::newFromText( $name );
1218 if ( !is_object( $title ) ) {
1219 $title = Title
::newFromText( '--error: link target missing--' );
1225 * Build an array that represents the sidebar(s), the navigation bar among them.
1227 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1229 * The format of the returned array is array( heading => content, ... ), where:
1230 * - heading is the heading of a navigation portlet. It is either:
1231 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1232 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1233 * - plain text, which should be HTML-escaped by the skin
1234 * - content is the contents of the portlet. It is either:
1235 * - HTML text (<ul><li>...</li>...</ul>)
1236 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1237 * - (for a magic string as a key, any value)
1239 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1240 * and can technically insert anything in here; skin creators are expected to handle
1241 * values described above.
1245 function buildSidebar() {
1246 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1247 wfProfileIn( __METHOD__
);
1249 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1251 if ( $wgEnableSidebarCache ) {
1252 $cachedsidebar = $wgMemc->get( $key );
1253 if ( $cachedsidebar ) {
1254 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
1256 wfProfileOut( __METHOD__
);
1257 return $cachedsidebar;
1262 $this->addToSidebar( $bar, 'sidebar' );
1264 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1265 if ( $wgEnableSidebarCache ) {
1266 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1269 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$bar ) );
1271 wfProfileOut( __METHOD__
);
1276 * Add content from a sidebar system message
1277 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1279 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1282 * @param string $message
1284 function addToSidebar( &$bar, $message ) {
1285 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1289 * Add content from plain text
1292 * @param string $text
1295 function addToSidebarPlain( &$bar, $text ) {
1296 $lines = explode( "\n", $text );
1300 foreach ( $lines as $line ) {
1301 if ( strpos( $line, '*' ) !== 0 ) {
1304 $line = rtrim( $line, "\r" ); // for Windows compat
1306 if ( strpos( $line, '**' ) !== 0 ) {
1307 $heading = trim( $line, '* ' );
1308 if ( !array_key_exists( $heading, $bar ) ) {
1309 $bar[$heading] = array();
1312 $line = trim( $line, '* ' );
1314 if ( strpos( $line, '|' ) !== false ) { // sanity check
1315 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1316 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1317 if ( count( $line ) !== 2 ) {
1318 // Second sanity check, could be hit by people doing
1319 // funky stuff with parserfuncs... (bug 33321)
1323 $extraAttribs = array();
1325 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1326 if ( $msgLink->exists() ) {
1327 $link = $msgLink->text();
1328 if ( $link == '-' ) {
1334 $msgText = $this->msg( $line[1] );
1335 if ( $msgText->exists() ) {
1336 $text = $msgText->text();
1341 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1344 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1345 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1346 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1347 $extraAttribs['rel'] = 'nofollow';
1350 global $wgExternalLinkTarget;
1351 if ( $wgExternalLinkTarget ) {
1352 $extraAttribs['target'] = $wgExternalLinkTarget;
1355 $title = Title
::newFromText( $link );
1358 $title = $title->fixSpecialName();
1359 $href = $title->getLinkURL();
1361 $href = 'INVALID-TITLE';
1365 $bar[$heading][] = array_merge( array(
1368 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1381 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1382 * should be loaded by OutputPage. That module no longer exists and the return value of this
1383 * method is ignored.
1385 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1386 * can be used instead (SkinTemplate-based skins do it automatically).
1388 * @deprecated since 1.22
1391 public function commonPrintStylesheet() {
1392 wfDeprecated( __METHOD__
, '1.22' );
1397 * Gets new talk page messages for the current user and returns an
1398 * appropriate alert message (or an empty string if there are no messages)
1401 function getNewtalks() {
1403 $newMessagesAlert = '';
1404 $user = $this->getUser();
1405 $newtalks = $user->getNewMessageLinks();
1406 $out = $this->getOutput();
1408 // Allow extensions to disable or modify the new messages alert
1409 if ( !wfRunHooks( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1412 if ( $newMessagesAlert ) {
1413 return $newMessagesAlert;
1416 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1417 $uTalkTitle = $user->getTalkPage();
1418 $lastSeenRev = isset( $newtalks[0]['rev'] ) ?
$newtalks[0]['rev'] : null;
1420 if ( $lastSeenRev !== null ) {
1421 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1422 $latestRev = Revision
::newFromTitle( $uTalkTitle, false, Revision
::READ_NORMAL
);
1423 if ( $latestRev !== null ) {
1424 // Singular if only 1 unseen revision, plural if several unseen revisions.
1425 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1426 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1427 $lastSeenRev, $latestRev, 10, 'include_new' );
1430 // Singular if no revision -> diff link will show latest change only in any case
1433 $plural = $plural ?
999 : 1;
1434 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1435 // the number of revisions or authors is not necessarily the same as the number of
1437 $newMessagesLink = Linker
::linkKnown(
1439 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1441 array( 'redirect' => 'no' )
1444 $newMessagesDiffLink = Linker
::linkKnown(
1446 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1448 $lastSeenRev !== null
1449 ?
array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1450 : array( 'diff' => 'cur' )
1453 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1454 $newMessagesAlert = $this->msg(
1455 'youhavenewmessagesfromusers',
1457 $newMessagesDiffLink
1458 )->numParams( $nofAuthors, $plural );
1460 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1461 $newMessagesAlert = $this->msg(
1462 $nofAuthors > 10 ?
'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1464 $newMessagesDiffLink
1465 )->numParams( $plural );
1467 $newMessagesAlert = $newMessagesAlert->text();
1468 # Disable Squid cache
1469 $out->setSquidMaxage( 0 );
1470 } elseif ( count( $newtalks ) ) {
1471 $sep = $this->msg( 'newtalkseparator' )->escaped();
1474 foreach ( $newtalks as $newtalk ) {
1475 $msgs[] = Xml
::element(
1477 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1480 $parts = implode( $sep, $msgs );
1481 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1482 $out->setSquidMaxage( 0 );
1485 return $newMessagesAlert;
1489 * Get a cached notice
1491 * @param string $name Message name, or 'default' for $wgSiteNotice
1492 * @return string HTML fragment
1494 private function getCachedNotice( $name ) {
1495 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1497 wfProfileIn( __METHOD__
);
1501 if ( $name === 'default' ) {
1503 global $wgSiteNotice;
1504 $notice = $wgSiteNotice;
1505 if ( empty( $notice ) ) {
1506 wfProfileOut( __METHOD__
);
1510 $msg = $this->msg( $name )->inContentLanguage();
1511 if ( $msg->isDisabled() ) {
1512 wfProfileOut( __METHOD__
);
1515 $notice = $msg->plain();
1518 // Use the extra hash appender to let eg SSL variants separately cache.
1519 $key = wfMemcKey( $name . $wgRenderHashAppend );
1520 $cachedNotice = $parserMemc->get( $key );
1521 if ( is_array( $cachedNotice ) ) {
1522 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1523 $notice = $cachedNotice['html'];
1532 $parsed = $this->getOutput()->parse( $notice );
1533 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1537 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1538 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1539 wfProfileOut( __METHOD__
);
1544 * Get a notice based on page's namespace
1546 * @return string HTML fragment
1548 function getNamespaceNotice() {
1549 wfProfileIn( __METHOD__
);
1551 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1552 $namespaceNotice = $this->getCachedNotice( $key );
1553 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1554 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1556 $namespaceNotice = '';
1559 wfProfileOut( __METHOD__
);
1560 return $namespaceNotice;
1564 * Get the site notice
1566 * @return string HTML fragment
1568 function getSiteNotice() {
1569 wfProfileIn( __METHOD__
);
1572 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1573 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1574 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1576 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1577 if ( !$anonNotice ) {
1578 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1580 $siteNotice = $anonNotice;
1583 if ( !$siteNotice ) {
1584 $siteNotice = $this->getCachedNotice( 'default' );
1588 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1589 wfProfileOut( __METHOD__
);
1594 * Create a section edit link. This supersedes editSectionLink() and
1595 * editSectionLinkForOther().
1597 * @param Title $nt The title being linked to (may not be the same as
1598 * the current page, if the section is included from a template)
1599 * @param string $section The designation of the section being pointed to,
1600 * to be included in the link, like "§ion=$section"
1601 * @param string $tooltip The tooltip to use for the link: will be escaped
1602 * and wrapped in the 'editsectionhint' message
1603 * @param string $lang Language code
1604 * @return string HTML to use for edit link
1606 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1607 // HTML generated here should probably have userlangattributes
1608 // added to it for LTR text on RTL pages
1610 $lang = wfGetLangObj( $lang );
1613 if ( !is_null( $tooltip ) ) {
1614 # Bug 25462: undo double-escaping.
1615 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1616 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1617 ->inLanguage( $lang )->text();
1619 $link = Linker
::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(),
1621 array( 'action' => 'edit', 'section' => $section ),
1622 array( 'noclasses', 'known' )
1625 # Add the brackets and the span and run the hook.
1626 $result = '<span class="mw-editsection">'
1627 . '<span class="mw-editsection-bracket">[</span>'
1629 . '<span class="mw-editsection-bracket">]</span>'
1632 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1637 * Use PHP's magic __call handler to intercept legacy calls to the linker
1638 * for backwards compatibility.
1640 * @param string $fname Name of called method
1641 * @param array $args Arguments to the method
1642 * @throws MWException
1645 function __call( $fname, $args ) {
1646 $realFunction = array( 'Linker', $fname );
1647 if ( is_callable( $realFunction ) ) {
1648 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1649 return call_user_func_array( $realFunction, $args );
1651 $className = get_class( $this );
1652 throw new MWException( "Call to undefined method $className::$fname" );