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 Use SkinFactory instead
149 static function &newFromKey( $key ) {
150 wfDeprecated( __METHOD__
, '1.24' );
151 global $wgFallbackSkin;
153 $key = Skin
::normalizeKey( $key );
154 $factory = SkinFactory
::getDefaultInstance();
156 $skin = $factory->makeSkin( $key );
157 } catch ( SkinException
$e ) {
158 $skin = $factory->makeSkin( $wgFallbackSkin );
165 * @return string Skin name
167 public function getSkinName() {
168 return $this->skinname
;
172 * @param OutputPage $out
174 function initPage( OutputPage
$out ) {
175 wfProfileIn( __METHOD__
);
177 $this->preloadExistence();
179 wfProfileOut( __METHOD__
);
183 * Defines the ResourceLoader modules that should be added to the skin
184 * It is recommended that skins wishing to override call parent::getDefaultModules()
185 * and substitute out any modules they wish to change by using a key to look them up
186 * @return array Array of modules with helper keys for easy overriding
188 public function getDefaultModules() {
189 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
190 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
192 $out = $this->getOutput();
193 $user = $out->getUser();
195 // modules that enhance the page content in some way
197 'mediawiki.page.ready',
199 // modules that exist for legacy reasons
201 // modules relating to search functionality
203 // modules relating to functionality relating to watching an article
205 // modules which relate to the current users preferences
208 if ( $wgIncludeLegacyJavaScript ) {
209 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
212 if ( $wgPreloadJavaScriptMwUtil ) {
213 $modules['legacy'][] = 'mediawiki.util';
216 // Add various resources if required
218 $modules['legacy'][] = 'mediawiki.legacy.ajax';
220 if ( $wgEnableAPI ) {
221 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
222 && $user->isAllowed( 'writeapi' )
224 $modules['watch'][] = 'mediawiki.page.watch.ajax';
227 $modules['search'][] = 'mediawiki.searchSuggest';
231 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
232 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
235 // Crazy edit-on-double-click stuff
236 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
237 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
243 * Preload the existence of three commonly-requested pages in a single query
245 function preloadExistence() {
246 $user = $this->getUser();
249 $titles = array( $user->getUserPage(), $user->getTalkPage() );
252 if ( $this->getTitle()->isSpecialPage() ) {
254 } elseif ( $this->getTitle()->isTalkPage() ) {
255 $titles[] = $this->getTitle()->getSubjectPage();
257 $titles[] = $this->getTitle()->getTalkPage();
260 $lb = new LinkBatch( $titles );
261 $lb->setCaller( __METHOD__
);
266 * Get the current revision ID
270 public function getRevisionId() {
271 return $this->getOutput()->getRevisionId();
275 * Whether the revision displayed is the latest revision of the page
279 public function isRevisionCurrent() {
280 $revID = $this->getRevisionId();
281 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
285 * Set the "relevant" title
286 * @see self::getRelevantTitle()
289 public function setRelevantTitle( $t ) {
290 $this->mRelevantTitle
= $t;
294 * Return the "relevant" title.
295 * A "relevant" title is not necessarily the actual title of the page.
296 * Special pages like Special:MovePage use set the page they are acting on
297 * as their "relevant" title, this allows the skin system to display things
298 * such as content tabs which belong to to that page instead of displaying
299 * a basic special page tab which has almost no meaning.
303 public function getRelevantTitle() {
304 if ( isset( $this->mRelevantTitle
) ) {
305 return $this->mRelevantTitle
;
307 return $this->getTitle();
311 * Set the "relevant" user
312 * @see self::getRelevantUser()
315 public function setRelevantUser( $u ) {
316 $this->mRelevantUser
= $u;
320 * Return the "relevant" user.
321 * A "relevant" user is similar to a relevant title. Special pages like
322 * Special:Contributions mark the user which they are relevant to so that
323 * things like the toolbox can display the information they usually are only
324 * able to display on a user's userpage and talkpage.
327 public function getRelevantUser() {
328 if ( isset( $this->mRelevantUser
) ) {
329 return $this->mRelevantUser
;
331 $title = $this->getRelevantTitle();
332 if ( $title->hasSubjectNamespace( NS_USER
) ) {
333 $rootUser = $title->getRootText();
334 if ( User
::isIP( $rootUser ) ) {
335 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
337 $user = User
::newFromName( $rootUser, false );
338 if ( $user && $user->isLoggedIn() ) {
339 $this->mRelevantUser
= $user;
342 return $this->mRelevantUser
;
348 * Outputs the HTML generated by other functions.
349 * @param OutputPage $out
351 abstract function outputPage( OutputPage
$out = null );
357 static function makeVariablesScript( $data ) {
359 return Html
::inlineScript(
360 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
368 * Get the query to generate a dynamic stylesheet
372 public static function getDynamicStylesheetQuery() {
373 global $wgSquidMaxage;
377 'maxage' => $wgSquidMaxage,
378 'usemsgcache' => 'yes',
379 'ctype' => 'text/css',
380 'smaxage' => $wgSquidMaxage,
385 * Add skin specific stylesheets
386 * Calling this method with an $out of anything but the same OutputPage
387 * inside ->getOutput() is deprecated. The $out arg is kept
388 * for compatibility purposes with skins.
389 * @param OutputPage $out
392 abstract function setupSkinUserCss( OutputPage
$out );
396 * @param Title $title
399 function getPageClasses( $title ) {
400 $numeric = 'ns-' . $title->getNamespace();
402 if ( $title->isSpecialPage() ) {
403 $type = 'ns-special';
404 // bug 23315: provide a class based on the canonical special page name without subpages
405 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
406 if ( $canonicalName ) {
407 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
409 $type .= ' mw-invalidspecialpage';
411 } elseif ( $title->isTalkPage() ) {
414 $type = 'ns-subject';
417 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
419 return "$numeric $type $name";
423 * Return values for <html> element
424 * @return array of associative name-to-value elements for <html> element
426 public function getHtmlElementAttributes() {
427 $lang = $this->getLanguage();
429 'lang' => $lang->getHtmlCode(),
430 'dir' => $lang->getDir(),
431 'class' => 'client-nojs',
436 * This will be called by OutputPage::headElement when it is creating the
437 * "<body>" tag, skins can override it if they have a need to add in any
438 * body attributes or classes of their own.
439 * @param OutputPage $out
440 * @param array $bodyAttrs
442 function addToBodyAttributes( $out, &$bodyAttrs ) {
443 // does nothing by default
458 function getCategoryLinks() {
459 global $wgUseCategoryBrowser;
461 $out = $this->getOutput();
462 $allCats = $out->getCategoryLinks();
464 if ( !count( $allCats ) ) {
472 $colon = $this->msg( 'colon-separator' )->escaped();
474 if ( !empty( $allCats['normal'] ) ) {
475 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
477 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
478 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
479 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
480 Linker
::link( Title
::newFromText( $linkPage ), $msg )
481 . $colon . '<ul>' . $t . '</ul>' . '</div>';
485 if ( isset( $allCats['hidden'] ) ) {
486 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
487 $class = ' mw-hidden-cats-user-shown';
488 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
489 $class = ' mw-hidden-cats-ns-shown';
491 $class = ' mw-hidden-cats-hidden';
494 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
495 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
496 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
500 # optional 'dmoz-like' category browser. Will be shown under the list
501 # of categories an article belong to
502 if ( $wgUseCategoryBrowser ) {
503 $s .= '<br /><hr />';
505 # get a big array of the parents tree
506 $parenttree = $this->getTitle()->getParentCategoryTree();
507 # Skin object passed by reference cause it can not be
508 # accessed under the method subfunction drawCategoryBrowser
509 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
510 # Clean out bogus first entry and sort them
511 unset( $tempout[0] );
513 # Output one per line
514 $s .= implode( "<br />\n", $tempout );
521 * Render the array as a series of links.
522 * @param array $tree Categories tree returned by Title::getParentCategoryTree
523 * @return string Separated by >, terminate with "\n"
525 function drawCategoryBrowser( $tree ) {
528 foreach ( $tree as $element => $parent ) {
529 if ( empty( $parent ) ) {
530 # element start a new list
533 # grab the others elements
534 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
537 # add our current element to the list
538 $eltitle = Title
::newFromText( $element );
539 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
548 function getCategories() {
549 $out = $this->getOutput();
551 $catlinks = $this->getCategoryLinks();
553 $classes = 'catlinks';
555 // Check what we're showing
556 $allCats = $out->getCategoryLinks();
557 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
558 $this->getTitle()->getNamespace() == NS_CATEGORY
;
560 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
561 $classes .= ' catlinks-allhidden';
564 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
568 * This runs a hook to allow extensions placing their stuff after content
569 * and article metadata (e.g. categories).
570 * Note: This function has nothing to do with afterContent().
572 * This hook is placed here in order to allow using the same hook for all
573 * skins, both the SkinTemplate based ones and the older ones, which directly
574 * use this class to get their data.
576 * The output of this function gets processed in SkinTemplate::outputPage() for
577 * the SkinTemplate based skins, all other skins should directly echo it.
579 * @return string Empty by default, if not changed by any hook function.
581 protected function afterContentHook() {
584 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
585 // adding just some spaces shouldn't toggle the output
586 // of the whole <div/>, so we use trim() here
587 if ( trim( $data ) != '' ) {
588 // Doing this here instead of in the skins to
589 // ensure that the div has the same ID in all
591 $data = "<div id='mw-data-after-content'>\n" .
596 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
603 * Generate debug data HTML for displaying at the bottom of the main content
605 * @return string HTML containing debug data, if enabled (otherwise empty).
607 protected function generateDebugHTML() {
608 return MWDebug
::getHTMLDebugLog();
612 * This gets called shortly before the "</body>" tag.
614 * @return string HTML-wrapped JS code to be put before "</body>"
616 function bottomScripts() {
617 // TODO and the suckage continues. This function is really just a wrapper around
618 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
620 $bottomScriptText = $this->getOutput()->getBottomScripts();
621 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
623 return $bottomScriptText;
627 * Text with the permalink to the source page,
628 * usually shown on the footer of a printed page
630 * @return string HTML text with an URL
632 function printSource() {
633 $oldid = $this->getRevisionId();
635 $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
636 $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
638 // oldid not available for non existing pages
639 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
642 return $this->msg( 'retrievedfrom', '<a dir="ltr" href="' . $url
643 . '">' . $url . '</a>' )->text();
649 function getUndeleteLink() {
650 $action = $this->getRequest()->getVal( 'action', 'view' );
652 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
653 ( $this->getTitle()->getArticleID() == 0 ||
$action == 'history' ) ) {
654 $n = $this->getTitle()->isDeleted();
657 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
658 $msg = 'thisisdeleted';
660 $msg = 'viewdeleted';
663 return $this->msg( $msg )->rawParams(
665 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
666 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
677 function subPageSubtitle() {
678 $out = $this->getOutput();
681 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
685 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
686 $ptext = $this->getTitle()->getPrefixedText();
687 if ( preg_match( '/\//', $ptext ) ) {
688 $links = explode( '/', $ptext );
693 $lang = $this->getLanguage();
695 foreach ( $links as $link ) {
696 $growinglink .= $link;
698 $linkObj = Title
::newFromText( $growinglink );
700 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
701 $getlink = Linker
::linkKnown(
703 htmlspecialchars( $display )
709 $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
711 $subpages .= '< ';
714 $subpages .= $getlink;
728 * Returns true if the IP should be shown in the header
731 function showIPinHeader() {
732 global $wgShowIPinHeader;
733 return $wgShowIPinHeader && session_id() != '';
739 function getSearchLink() {
740 $searchPage = SpecialPage
::getTitleFor( 'Search' );
741 return $searchPage->getLocalURL();
747 function escapeSearchLink() {
748 return htmlspecialchars( $this->getSearchLink() );
752 * @param string $type
755 function getCopyright( $type = 'detect' ) {
756 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
758 if ( $type == 'detect' ) {
759 if ( !$this->isRevisionCurrent()
760 && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
768 if ( $type == 'history' ) {
769 $msg = 'history_copyright';
774 if ( $wgRightsPage ) {
775 $title = Title
::newFromText( $wgRightsPage );
776 $link = Linker
::linkKnown( $title, $wgRightsText );
777 } elseif ( $wgRightsUrl ) {
778 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
779 } elseif ( $wgRightsText ) {
780 $link = $wgRightsText;
786 // Allow for site and per-namespace customization of copyright notice.
787 // @todo Remove deprecated $forContent param from hook handlers and then remove here.
791 'SkinCopyrightFooter',
792 array( $this->getTitle(), $type, &$msg, &$link, &$forContent )
795 return $this->msg( $msg )->rawParams( $link )->text();
799 * @return null|string
801 function getCopyrightIcon() {
802 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
806 if ( $wgCopyrightIcon ) {
807 $out = $wgCopyrightIcon;
808 } elseif ( $wgRightsIcon ) {
809 $icon = htmlspecialchars( $wgRightsIcon );
811 if ( $wgRightsUrl ) {
812 $url = htmlspecialchars( $wgRightsUrl );
813 $out .= '<a href="' . $url . '">';
816 $text = htmlspecialchars( $wgRightsText );
817 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
819 if ( $wgRightsUrl ) {
828 * Gets the powered by MediaWiki icon.
831 function getPoweredBy() {
834 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
835 $text = '<a href="//www.mediawiki.org/"><img src="' . $url
836 . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
837 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
842 * Get the timestamp of the latest revision, formatted in user language
846 protected function lastModified() {
847 $timestamp = $this->getOutput()->getRevisionTimestamp();
849 # No cached timestamp, load it from the database
850 if ( $timestamp === null ) {
851 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
855 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
856 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
857 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
862 if ( wfGetLB()->getLaggedSlaveMode() ) {
863 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
870 * @param string $align
873 function logoText( $align = '' ) {
874 if ( $align != '' ) {
875 $a = " style='float: {$align};'";
880 $mp = $this->msg( 'mainpage' )->escaped();
881 $mptitle = Title
::newMainPage();
882 $url = ( is_object( $mptitle ) ?
htmlspecialchars( $mptitle->getLocalURL() ) : '' );
884 $logourl = $this->getLogo();
885 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
891 * Renders a $wgFooterIcons icon according to the method's arguments
892 * @param array $icon The icon to build the html for, see $wgFooterIcons
893 * for the format of this array.
894 * @param bool|string $withImage Whether to use the icon's image or output
895 * a text-only footericon.
896 * @return string HTML
898 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
899 if ( is_string( $icon ) ) {
901 } else { // Assuming array
902 $url = isset( $icon["url"] ) ?
$icon["url"] : null;
903 unset( $icon["url"] );
904 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
905 // do this the lazy way, just pass icon data as an attribute array
906 $html = Html
::element( 'img', $icon );
908 $html = htmlspecialchars( $icon["alt"] );
911 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
918 * Gets the link to the wiki's main page.
921 function mainPageLink() {
922 $s = Linker
::linkKnown(
923 Title
::newMainPage(),
924 $this->msg( 'mainpage' )->escaped()
931 * Returns an HTML link for use in the footer
932 * @param string $desc The i18n message key for the link text
933 * @param string $page The i18n message key for the page to link to
934 * @return string HTML anchor
936 public function footerLink( $desc, $page ) {
937 // if the link description has been set to "-" in the default language,
938 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
939 // then it is disabled, for all languages.
942 // Otherwise, we display the link for the user, described in their
943 // language (which may or may not be the same as the default language),
944 // but we make the link target be the one site-wide page.
945 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
947 return Linker
::linkKnown(
949 $this->msg( $desc )->escaped()
955 * Gets the link to the wiki's privacy policy page.
956 * @return string HTML
958 function privacyLink() {
959 return $this->footerLink( 'privacy', 'privacypage' );
963 * Gets the link to the wiki's about page.
964 * @return string HTML
966 function aboutLink() {
967 return $this->footerLink( 'aboutsite', 'aboutpage' );
971 * Gets the link to the wiki's general disclaimers page.
972 * @return string HTML
974 function disclaimerLink() {
975 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
979 * Return URL options for the 'edit page' link.
980 * This may include an 'oldid' specifier, if the current page view is such.
985 function editUrlOptions() {
986 $options = array( 'action' => 'edit' );
988 if ( !$this->isRevisionCurrent() ) {
989 $options['oldid'] = intval( $this->getRevisionId() );
996 * @param User|int $id
999 function showEmailUser( $id ) {
1000 if ( $id instanceof User
) {
1003 $targetUser = User
::newFromId( $id );
1006 # The sending user must have a confirmed email address and the target
1007 # user must have a confirmed email address and allow emails from users.
1008 return $this->getUser()->canSendEmail() &&
1009 $targetUser->canReceiveEmail();
1013 * Return a fully resolved style path url to images or styles stored in the common folder.
1014 * This method returns a url resolved using the configured skin style path
1015 * and includes the style version inside of the url.
1016 * @param string $name The name or path of a skin resource file
1017 * @return string The fully resolved style path url including styleversion
1019 function getCommonStylePath( $name ) {
1020 global $wgStylePath, $wgStyleVersion;
1021 return "$wgStylePath/common/$name?$wgStyleVersion";
1025 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1026 * This method returns a url resolved using the configured skin style path
1027 * and includes the style version inside of the url.
1029 * Requires $stylename to be set, otherwise throws MWException.
1031 * @param string $name The name or path of a skin resource file
1032 * @return string The fully resolved style path url including styleversion
1034 function getSkinStylePath( $name ) {
1035 global $wgStylePath, $wgStyleVersion;
1037 if ( $this->stylename
=== null ) {
1038 $class = get_class( $this );
1039 throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
1042 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1045 /* these are used extensively in SkinTemplate, but also some other places */
1048 * @param string $urlaction
1051 static function makeMainPageUrl( $urlaction = '' ) {
1052 $title = Title
::newMainPage();
1053 self
::checkTitle( $title, '' );
1055 return $title->getLocalURL( $urlaction );
1059 * Make a URL for a Special Page using the given query and protocol.
1061 * If $proto is set to null, make a local URL. Otherwise, make a full
1062 * URL with the protocol specified.
1064 * @param string $name Name of the Special page
1065 * @param string $urlaction Query to append
1066 * @param string|null $proto Protocol to use or null for a local URL
1069 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1070 $title = SpecialPage
::getSafeTitleFor( $name );
1071 if ( is_null( $proto ) ) {
1072 return $title->getLocalURL( $urlaction );
1074 return $title->getFullURL( $urlaction, false, $proto );
1079 * @param string $name
1080 * @param string $subpage
1081 * @param string $urlaction
1084 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1085 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1086 return $title->getLocalURL( $urlaction );
1090 * @param string $name
1091 * @param string $urlaction
1094 static function makeI18nUrl( $name, $urlaction = '' ) {
1095 $title = Title
::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1096 self
::checkTitle( $title, $name );
1097 return $title->getLocalURL( $urlaction );
1101 * @param string $name
1102 * @param string $urlaction
1105 static function makeUrl( $name, $urlaction = '' ) {
1106 $title = Title
::newFromText( $name );
1107 self
::checkTitle( $title, $name );
1109 return $title->getLocalURL( $urlaction );
1113 * If url string starts with http, consider as external URL, else
1115 * @param string $name
1116 * @return string URL
1118 static function makeInternalOrExternalUrl( $name ) {
1119 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1122 return self
::makeUrl( $name );
1127 * this can be passed the NS number as defined in Language.php
1128 * @param string $name
1129 * @param string $urlaction
1130 * @param int $namespace
1133 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1134 $title = Title
::makeTitleSafe( $namespace, $name );
1135 self
::checkTitle( $title, $name );
1137 return $title->getLocalURL( $urlaction );
1141 * these return an array with the 'href' and boolean 'exists'
1142 * @param string $name
1143 * @param string $urlaction
1146 static function makeUrlDetails( $name, $urlaction = '' ) {
1147 $title = Title
::newFromText( $name );
1148 self
::checkTitle( $title, $name );
1151 'href' => $title->getLocalURL( $urlaction ),
1152 'exists' => $title->getArticleID() != 0,
1157 * Make URL details where the article exists (or at least it's convenient to think so)
1158 * @param string $name Article name
1159 * @param string $urlaction
1162 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1163 $title = Title
::newFromText( $name );
1164 self
::checkTitle( $title, $name );
1167 'href' => $title->getLocalURL( $urlaction ),
1173 * make sure we have some title to operate on
1175 * @param Title $title
1176 * @param string $name
1178 static function checkTitle( &$title, $name ) {
1179 if ( !is_object( $title ) ) {
1180 $title = Title
::newFromText( $name );
1181 if ( !is_object( $title ) ) {
1182 $title = Title
::newFromText( '--error: link target missing--' );
1188 * Build an array that represents the sidebar(s), the navigation bar among them.
1190 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1192 * The format of the returned array is array( heading => content, ... ), where:
1193 * - heading is the heading of a navigation portlet. It is either:
1194 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1195 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1196 * - plain text, which should be HTML-escaped by the skin
1197 * - content is the contents of the portlet. It is either:
1198 * - HTML text (<ul><li>...</li>...</ul>)
1199 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1200 * - (for a magic string as a key, any value)
1202 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1203 * and can technically insert anything in here; skin creators are expected to handle
1204 * values described above.
1208 function buildSidebar() {
1209 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1210 wfProfileIn( __METHOD__
);
1212 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1214 if ( $wgEnableSidebarCache ) {
1215 $cachedsidebar = $wgMemc->get( $key );
1216 if ( $cachedsidebar ) {
1217 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
1219 wfProfileOut( __METHOD__
);
1220 return $cachedsidebar;
1225 $this->addToSidebar( $bar, 'sidebar' );
1227 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1228 if ( $wgEnableSidebarCache ) {
1229 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1232 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$bar ) );
1234 wfProfileOut( __METHOD__
);
1239 * Add content from a sidebar system message
1240 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1242 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1245 * @param string $message
1247 function addToSidebar( &$bar, $message ) {
1248 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1252 * Add content from plain text
1255 * @param string $text
1258 function addToSidebarPlain( &$bar, $text ) {
1259 $lines = explode( "\n", $text );
1263 foreach ( $lines as $line ) {
1264 if ( strpos( $line, '*' ) !== 0 ) {
1267 $line = rtrim( $line, "\r" ); // for Windows compat
1269 if ( strpos( $line, '**' ) !== 0 ) {
1270 $heading = trim( $line, '* ' );
1271 if ( !array_key_exists( $heading, $bar ) ) {
1272 $bar[$heading] = array();
1275 $line = trim( $line, '* ' );
1277 if ( strpos( $line, '|' ) !== false ) { // sanity check
1278 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1279 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1280 if ( count( $line ) !== 2 ) {
1281 // Second sanity check, could be hit by people doing
1282 // funky stuff with parserfuncs... (bug 33321)
1286 $extraAttribs = array();
1288 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1289 if ( $msgLink->exists() ) {
1290 $link = $msgLink->text();
1291 if ( $link == '-' ) {
1297 $msgText = $this->msg( $line[1] );
1298 if ( $msgText->exists() ) {
1299 $text = $msgText->text();
1304 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1307 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1308 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1309 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1310 $extraAttribs['rel'] = 'nofollow';
1313 global $wgExternalLinkTarget;
1314 if ( $wgExternalLinkTarget ) {
1315 $extraAttribs['target'] = $wgExternalLinkTarget;
1318 $title = Title
::newFromText( $link );
1321 $title = $title->fixSpecialName();
1322 $href = $title->getLinkURL();
1324 $href = 'INVALID-TITLE';
1328 $bar[$heading][] = array_merge( array(
1331 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1344 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1345 * should be loaded by OutputPage. That module no longer exists and the return value of this
1346 * method is ignored.
1348 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1349 * can be used instead (SkinTemplate-based skins do it automatically).
1351 * @deprecated since 1.22
1354 public function commonPrintStylesheet() {
1355 wfDeprecated( __METHOD__
, '1.22' );
1360 * Gets new talk page messages for the current user and returns an
1361 * appropriate alert message (or an empty string if there are no messages)
1364 function getNewtalks() {
1366 $newMessagesAlert = '';
1367 $user = $this->getUser();
1368 $newtalks = $user->getNewMessageLinks();
1369 $out = $this->getOutput();
1371 // Allow extensions to disable or modify the new messages alert
1372 if ( !wfRunHooks( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1375 if ( $newMessagesAlert ) {
1376 return $newMessagesAlert;
1379 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1380 $uTalkTitle = $user->getTalkPage();
1381 $lastSeenRev = isset( $newtalks[0]['rev'] ) ?
$newtalks[0]['rev'] : null;
1383 if ( $lastSeenRev !== null ) {
1384 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1385 $latestRev = Revision
::newFromTitle( $uTalkTitle, false, Revision
::READ_NORMAL
);
1386 if ( $latestRev !== null ) {
1387 // Singular if only 1 unseen revision, plural if several unseen revisions.
1388 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1389 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1390 $lastSeenRev, $latestRev, 10, 'include_new' );
1393 // Singular if no revision -> diff link will show latest change only in any case
1396 $plural = $plural ?
999 : 1;
1397 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1398 // the number of revisions or authors is not necessarily the same as the number of
1400 $newMessagesLink = Linker
::linkKnown(
1402 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1404 array( 'redirect' => 'no' )
1407 $newMessagesDiffLink = Linker
::linkKnown(
1409 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1411 $lastSeenRev !== null
1412 ?
array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1413 : array( 'diff' => 'cur' )
1416 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1417 $newMessagesAlert = $this->msg(
1418 'youhavenewmessagesfromusers',
1420 $newMessagesDiffLink
1421 )->numParams( $nofAuthors, $plural );
1423 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1424 $newMessagesAlert = $this->msg(
1425 $nofAuthors > 10 ?
'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1427 $newMessagesDiffLink
1428 )->numParams( $plural );
1430 $newMessagesAlert = $newMessagesAlert->text();
1431 # Disable Squid cache
1432 $out->setSquidMaxage( 0 );
1433 } elseif ( count( $newtalks ) ) {
1434 $sep = $this->msg( 'newtalkseparator' )->escaped();
1437 foreach ( $newtalks as $newtalk ) {
1438 $msgs[] = Xml
::element(
1440 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1443 $parts = implode( $sep, $msgs );
1444 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1445 $out->setSquidMaxage( 0 );
1448 return $newMessagesAlert;
1452 * Get a cached notice
1454 * @param string $name Message name, or 'default' for $wgSiteNotice
1455 * @return string HTML fragment
1457 private function getCachedNotice( $name ) {
1458 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1460 wfProfileIn( __METHOD__
);
1464 if ( $name === 'default' ) {
1466 global $wgSiteNotice;
1467 $notice = $wgSiteNotice;
1468 if ( empty( $notice ) ) {
1469 wfProfileOut( __METHOD__
);
1473 $msg = $this->msg( $name )->inContentLanguage();
1474 if ( $msg->isDisabled() ) {
1475 wfProfileOut( __METHOD__
);
1478 $notice = $msg->plain();
1481 // Use the extra hash appender to let eg SSL variants separately cache.
1482 $key = wfMemcKey( $name . $wgRenderHashAppend );
1483 $cachedNotice = $parserMemc->get( $key );
1484 if ( is_array( $cachedNotice ) ) {
1485 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1486 $notice = $cachedNotice['html'];
1495 $parsed = $this->getOutput()->parse( $notice );
1496 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1500 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1501 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1502 wfProfileOut( __METHOD__
);
1507 * Get a notice based on page's namespace
1509 * @return string HTML fragment
1511 function getNamespaceNotice() {
1512 wfProfileIn( __METHOD__
);
1514 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1515 $namespaceNotice = $this->getCachedNotice( $key );
1516 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1517 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1519 $namespaceNotice = '';
1522 wfProfileOut( __METHOD__
);
1523 return $namespaceNotice;
1527 * Get the site notice
1529 * @return string HTML fragment
1531 function getSiteNotice() {
1532 wfProfileIn( __METHOD__
);
1535 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1536 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1537 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1539 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1540 if ( !$anonNotice ) {
1541 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1543 $siteNotice = $anonNotice;
1546 if ( !$siteNotice ) {
1547 $siteNotice = $this->getCachedNotice( 'default' );
1551 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1552 wfProfileOut( __METHOD__
);
1557 * Create a section edit link. This supersedes editSectionLink() and
1558 * editSectionLinkForOther().
1560 * @param Title $nt The title being linked to (may not be the same as
1561 * the current page, if the section is included from a template)
1562 * @param string $section The designation of the section being pointed to,
1563 * to be included in the link, like "§ion=$section"
1564 * @param string $tooltip The tooltip to use for the link: will be escaped
1565 * and wrapped in the 'editsectionhint' message
1566 * @param string $lang Language code
1567 * @return string HTML to use for edit link
1569 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1570 // HTML generated here should probably have userlangattributes
1571 // added to it for LTR text on RTL pages
1573 $lang = wfGetLangObj( $lang );
1576 if ( !is_null( $tooltip ) ) {
1577 # Bug 25462: undo double-escaping.
1578 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1579 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1580 ->inLanguage( $lang )->text();
1582 $link = Linker
::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(),
1584 array( 'action' => 'edit', 'section' => $section ),
1585 array( 'noclasses', 'known' )
1588 # Add the brackets and the span and run the hook.
1589 $result = '<span class="mw-editsection">'
1590 . '<span class="mw-editsection-bracket">[</span>'
1592 . '<span class="mw-editsection-bracket">]</span>'
1595 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1600 * Use PHP's magic __call handler to intercept legacy calls to the linker
1601 * for backwards compatibility.
1603 * @param string $fname Name of called method
1604 * @param array $args Arguments to the method
1605 * @throws MWException
1608 function __call( $fname, $args ) {
1609 $realFunction = array( 'Linker', $fname );
1610 if ( is_callable( $realFunction ) ) {
1611 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1612 return call_user_func_array( $realFunction, $args );
1614 $className = get_class( $this );
1615 throw new MWException( "Call to undefined method $className::$fname" );