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.
80 * @return array of strings
82 static function getSkinNameMessages() {
84 foreach ( self
::getSkinNames() as $skinKey => $skinName ) {
85 // Messages: skinname-cologneblue, skinname-monobook, skinname-modern, skinname-vector
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.
95 * @return array of strings
97 public static function getUsableSkins() {
100 $allowedSkins = self
::getSkinNames();
102 foreach ( $wgSkipSkins as $skip ) {
103 unset( $allowedSkins[$skip] );
106 return $allowedSkins;
110 * Normalize a skin preference value to a form that can be loaded.
111 * If a skin can't be found, it will fall back to the configured
112 * default (or the old 'Classic' skin if that's broken).
113 * @param string $key 'monobook', 'standard', etc.
116 static function normalizeKey( $key ) {
117 global $wgDefaultSkin;
119 $skinNames = Skin
::getSkinNames();
121 if ( $key == '' ||
$key == 'default' ) {
122 // Don't return the default immediately;
123 // in a misconfiguration we need to fall back.
124 $key = $wgDefaultSkin;
127 if ( isset( $skinNames[$key] ) ) {
131 // Older versions of the software used a numeric setting
132 // in the user preferences.
138 if ( isset( $fallback[$key] ) ) {
139 $key = $fallback[$key];
142 if ( isset( $skinNames[$key] ) ) {
144 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
145 return $wgDefaultSkin;
152 * Factory method for loading a skin of a given type
153 * @param string $key 'monobook', 'standard', etc.
156 static function &newFromKey( $key ) {
157 global $wgStyleDirectory;
159 $key = Skin
::normalizeKey( $key );
161 $skinNames = Skin
::getSkinNames();
162 $skinName = $skinNames[$key];
163 $className = "Skin{$skinName}";
165 # Grab the skin class and initialise it.
166 if ( !class_exists( $className ) ) {
168 require_once "{$wgStyleDirectory}/{$skinName}.php";
170 # Check if we got if not fallback to default skin
171 if ( !class_exists( $className ) ) {
172 # DO NOT die if the class isn't found. This breaks maintenance
173 # scripts and can cause a user account to be unrecoverable
174 # except by SQL manipulation if a previously valid skin name
175 # is no longer valid.
176 wfDebug( "Skin class does not exist: $className\n" );
177 $className = 'SkinVector';
178 require_once "{$wgStyleDirectory}/Vector.php";
181 $skin = new $className( $key );
185 /** @return string skin name */
186 public function getSkinName() {
187 return $this->skinname
;
191 * @param $out OutputPage
193 function initPage( OutputPage
$out ) {
194 wfProfileIn( __METHOD__
);
196 $this->preloadExistence();
198 wfProfileOut( __METHOD__
);
202 * Defines the ResourceLoader modules that should be added to the skin
203 * It is recommended that skins wishing to override call parent::getDefaultModules()
204 * and substitute out any modules they wish to change by using a key to look them up
205 * @return Array of modules with helper keys for easy overriding
207 public function getDefaultModules() {
208 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
209 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
211 $out = $this->getOutput();
212 $user = $out->getUser();
214 // modules that enhance the page content in some way
216 'mediawiki.page.ready',
218 // modules that exist for legacy reasons
220 // modules relating to search functionality
222 // modules relating to functionality relating to watching an article
224 // modules which relate to the current users preferences
227 if ( $wgIncludeLegacyJavaScript ) {
228 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
231 if ( $wgPreloadJavaScriptMwUtil ) {
232 $modules['legacy'][] = 'mediawiki.util';
235 // Add various resources if required
237 $modules['legacy'][] = 'mediawiki.legacy.ajax';
239 if ( $wgEnableAPI ) {
240 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
241 && $user->isAllowed( 'writeapi' )
243 $modules['watch'][] = 'mediawiki.page.watch.ajax';
246 if ( !$user->getOption( 'disablesuggest', false ) ) {
247 $modules['search'][] = 'mediawiki.searchSuggest';
252 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
253 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
256 // Crazy edit-on-double-click stuff
257 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
258 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
264 * Preload the existence of three commonly-requested pages in a single query
266 function preloadExistence() {
267 $user = $this->getUser();
270 $titles = array( $user->getUserPage(), $user->getTalkPage() );
273 if ( $this->getTitle()->isSpecialPage() ) {
275 } elseif ( $this->getTitle()->isTalkPage() ) {
276 $titles[] = $this->getTitle()->getSubjectPage();
278 $titles[] = $this->getTitle()->getTalkPage();
281 $lb = new LinkBatch( $titles );
282 $lb->setCaller( __METHOD__
);
287 * Get the current revision ID
291 public function getRevisionId() {
292 return $this->getOutput()->getRevisionId();
296 * Whether the revision displayed is the latest revision of the page
300 public function isRevisionCurrent() {
301 $revID = $this->getRevisionId();
302 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
306 * Set the "relevant" title
307 * @see self::getRelevantTitle()
308 * @param $t Title object to use
310 public function setRelevantTitle( $t ) {
311 $this->mRelevantTitle
= $t;
315 * Return the "relevant" title.
316 * A "relevant" title is not necessarily the actual title of the page.
317 * Special pages like Special:MovePage use set the page they are acting on
318 * as their "relevant" title, this allows the skin system to display things
319 * such as content tabs which belong to to that page instead of displaying
320 * a basic special page tab which has almost no meaning.
324 public function getRelevantTitle() {
325 if ( isset( $this->mRelevantTitle
) ) {
326 return $this->mRelevantTitle
;
328 return $this->getTitle();
332 * Set the "relevant" user
333 * @see self::getRelevantUser()
334 * @param $u User object to use
336 public function setRelevantUser( $u ) {
337 $this->mRelevantUser
= $u;
341 * Return the "relevant" user.
342 * A "relevant" user is similar to a relevant title. Special pages like
343 * Special:Contributions mark the user which they are relevant to so that
344 * things like the toolbox can display the information they usually are only
345 * able to display on a user's userpage and talkpage.
348 public function getRelevantUser() {
349 if ( isset( $this->mRelevantUser
) ) {
350 return $this->mRelevantUser
;
352 $title = $this->getRelevantTitle();
353 if ( $title->hasSubjectNamespace( NS_USER
) ) {
354 $rootUser = $title->getRootText();
355 if ( User
::isIP( $rootUser ) ) {
356 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
358 $user = User
::newFromName( $rootUser, false );
359 if ( $user && $user->isLoggedIn() ) {
360 $this->mRelevantUser
= $user;
363 return $this->mRelevantUser
;
369 * Outputs the HTML generated by other functions.
370 * @param $out OutputPage
372 abstract function outputPage( OutputPage
$out = null );
378 static function makeVariablesScript( $data ) {
380 return Html
::inlineScript(
381 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
389 * Make a "<script>" tag containing global variables
391 * @deprecated in 1.19
393 * @return string HTML fragment
395 public static function makeGlobalVariablesScript( $unused ) {
398 wfDeprecated( __METHOD__
, '1.19' );
400 return self
::makeVariablesScript( $wgOut->getJSVars() );
404 * Get the query to generate a dynamic stylesheet
408 public static function getDynamicStylesheetQuery() {
409 global $wgSquidMaxage;
413 'maxage' => $wgSquidMaxage,
414 'usemsgcache' => 'yes',
415 'ctype' => 'text/css',
416 'smaxage' => $wgSquidMaxage,
421 * Add skin specific stylesheets
422 * Calling this method with an $out of anything but the same OutputPage
423 * inside ->getOutput() is deprecated. The $out arg is kept
424 * for compatibility purposes with skins.
425 * @param $out OutputPage
428 abstract function setupSkinUserCss( OutputPage
$out );
432 * @param $title Title
435 function getPageClasses( $title ) {
436 $numeric = 'ns-' . $title->getNamespace();
438 if ( $title->isSpecialPage() ) {
439 $type = 'ns-special';
440 // bug 23315: provide a class based on the canonical special page name without subpages
441 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
442 if ( $canonicalName ) {
443 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
445 $type .= ' mw-invalidspecialpage';
447 } elseif ( $title->isTalkPage() ) {
450 $type = 'ns-subject';
453 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
455 return "$numeric $type $name";
459 * This will be called by OutputPage::headElement when it is creating the
460 * "<body>" tag, skins can override it if they have a need to add in any
461 * body attributes or classes of their own.
462 * @param $out OutputPage
463 * @param $bodyAttrs Array
465 function addToBodyAttributes( $out, &$bodyAttrs ) {
466 // does nothing by default
481 function getCategoryLinks() {
482 global $wgUseCategoryBrowser;
484 $out = $this->getOutput();
485 $allCats = $out->getCategoryLinks();
487 if ( !count( $allCats ) ) {
495 $colon = $this->msg( 'colon-separator' )->escaped();
497 if ( !empty( $allCats['normal'] ) ) {
498 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
500 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
501 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
502 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
503 Linker
::link( Title
::newFromText( $linkPage ), $msg )
504 . $colon . '<ul>' . $t . '</ul>' . '</div>';
508 if ( isset( $allCats['hidden'] ) ) {
509 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
510 $class = ' mw-hidden-cats-user-shown';
511 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
512 $class = ' mw-hidden-cats-ns-shown';
514 $class = ' mw-hidden-cats-hidden';
517 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
518 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
519 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
523 # optional 'dmoz-like' category browser. Will be shown under the list
524 # of categories an article belong to
525 if ( $wgUseCategoryBrowser ) {
526 $s .= '<br /><hr />';
528 # get a big array of the parents tree
529 $parenttree = $this->getTitle()->getParentCategoryTree();
530 # Skin object passed by reference cause it can not be
531 # accessed under the method subfunction drawCategoryBrowser
532 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
533 # Clean out bogus first entry and sort them
534 unset( $tempout[0] );
536 # Output one per line
537 $s .= implode( "<br />\n", $tempout );
544 * Render the array as a series of links.
545 * @param array $tree categories tree returned by Title::getParentCategoryTree
546 * @return String separated by >, terminate with "\n"
548 function drawCategoryBrowser( $tree ) {
551 foreach ( $tree as $element => $parent ) {
552 if ( empty( $parent ) ) {
553 # element start a new list
556 # grab the others elements
557 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
560 # add our current element to the list
561 $eltitle = Title
::newFromText( $element );
562 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
571 function getCategories() {
572 $out = $this->getOutput();
574 $catlinks = $this->getCategoryLinks();
576 $classes = 'catlinks';
578 // Check what we're showing
579 $allCats = $out->getCategoryLinks();
580 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
581 $this->getTitle()->getNamespace() == NS_CATEGORY
;
583 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
584 $classes .= ' catlinks-allhidden';
587 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
591 * This runs a hook to allow extensions placing their stuff after content
592 * and article metadata (e.g. categories).
593 * Note: This function has nothing to do with afterContent().
595 * This hook is placed here in order to allow using the same hook for all
596 * skins, both the SkinTemplate based ones and the older ones, which directly
597 * use this class to get their data.
599 * The output of this function gets processed in SkinTemplate::outputPage() for
600 * the SkinTemplate based skins, all other skins should directly echo it.
602 * @return String, empty by default, if not changed by any hook function.
604 protected function afterContentHook() {
607 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
608 // adding just some spaces shouldn't toggle the output
609 // of the whole <div/>, so we use trim() here
610 if ( trim( $data ) != '' ) {
611 // Doing this here instead of in the skins to
612 // ensure that the div has the same ID in all
614 $data = "<div id='mw-data-after-content'>\n" .
619 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
626 * Generate debug data HTML for displaying at the bottom of the main content
628 * @return String HTML containing debug data, if enabled (otherwise empty).
630 protected function generateDebugHTML() {
631 return MWDebug
::getHTMLDebugLog();
635 * This gets called shortly before the "</body>" tag.
637 * @return String HTML-wrapped JS code to be put before "</body>"
639 function bottomScripts() {
640 // TODO and the suckage continues. This function is really just a wrapper around
641 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
643 $bottomScriptText = $this->getOutput()->getBottomScripts();
644 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
646 return $bottomScriptText;
650 * Text with the permalink to the source page,
651 * usually shown on the footer of a printed page
653 * @return string HTML text with an URL
655 function printSource() {
656 $oldid = $this->getRevisionId();
658 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
660 // oldid not available for non existing pages
661 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
663 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
669 function getUndeleteLink() {
670 $action = $this->getRequest()->getVal( 'action', 'view' );
672 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
673 ( $this->getTitle()->getArticleID() == 0 ||
$action == 'history' ) ) {
674 $n = $this->getTitle()->isDeleted();
677 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
678 $msg = 'thisisdeleted';
680 $msg = 'viewdeleted';
683 return $this->msg( $msg )->rawParams(
685 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
686 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
697 function subPageSubtitle() {
699 $out = $this->getOutput();
702 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
706 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
707 $ptext = $this->getTitle()->getPrefixedText();
708 if ( preg_match( '/\//', $ptext ) ) {
709 $links = explode( '/', $ptext );
715 foreach ( $links as $link ) {
716 $growinglink .= $link;
718 $linkObj = Title
::newFromText( $growinglink );
720 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
721 $getlink = Linker
::linkKnown(
723 htmlspecialchars( $display )
729 $subpages .= $wgLang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
731 $subpages .= '< ';
734 $subpages .= $getlink;
748 * Returns true if the IP should be shown in the header
751 function showIPinHeader() {
752 global $wgShowIPinHeader;
753 return $wgShowIPinHeader && session_id() != '';
759 function getSearchLink() {
760 $searchPage = SpecialPage
::getTitleFor( 'Search' );
761 return $searchPage->getLocalURL();
767 function escapeSearchLink() {
768 return htmlspecialchars( $this->getSearchLink() );
772 * @param $type string
775 function getCopyright( $type = 'detect' ) {
776 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
778 if ( $type == 'detect' ) {
779 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
786 if ( $type == 'history' ) {
787 $msg = 'history_copyright';
792 if ( $wgRightsPage ) {
793 $title = Title
::newFromText( $wgRightsPage );
794 $link = Linker
::linkKnown( $title, $wgRightsText );
795 } elseif ( $wgRightsUrl ) {
796 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
797 } elseif ( $wgRightsText ) {
798 $link = $wgRightsText;
804 // Allow for site and per-namespace customization of copyright notice.
807 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
809 $msgObj = $this->msg( $msg )->rawParams( $link );
811 $msg = $msgObj->inContentLanguage()->text();
812 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
813 $msg = Html
::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
817 return $msgObj->text();
822 * @return null|string
824 function getCopyrightIcon() {
825 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
829 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
830 $out = $wgCopyrightIcon;
831 } elseif ( $wgRightsIcon ) {
832 $icon = htmlspecialchars( $wgRightsIcon );
834 if ( $wgRightsUrl ) {
835 $url = htmlspecialchars( $wgRightsUrl );
836 $out .= '<a href="' . $url . '">';
839 $text = htmlspecialchars( $wgRightsText );
840 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
842 if ( $wgRightsUrl ) {
851 * Gets the powered by MediaWiki icon.
854 function getPoweredBy() {
857 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
858 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
859 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
864 * Get the timestamp of the latest revision, formatted in user language
868 protected function lastModified() {
869 $timestamp = $this->getOutput()->getRevisionTimestamp();
871 # No cached timestamp, load it from the database
872 if ( $timestamp === null ) {
873 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
877 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
878 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
879 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
884 if ( wfGetLB()->getLaggedSlaveMode() ) {
885 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
892 * @param $align string
895 function logoText( $align = '' ) {
896 if ( $align != '' ) {
897 $a = " style='float: {$align};'";
902 $mp = $this->msg( 'mainpage' )->escaped();
903 $mptitle = Title
::newMainPage();
904 $url = ( is_object( $mptitle ) ?
htmlspecialchars( $mptitle->getLocalURL() ) : '' );
906 $logourl = $this->getLogo();
907 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
913 * Renders a $wgFooterIcons icon according to the method's arguments
914 * @param array $icon The icon to build the html for, see $wgFooterIcons for the format of this array
915 * @param bool|String $withImage Whether to use the icon's image or output a text-only footericon
916 * @return String HTML
918 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
919 if ( is_string( $icon ) ) {
921 } else { // Assuming array
922 $url = isset( $icon["url"] ) ?
$icon["url"] : null;
923 unset( $icon["url"] );
924 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
925 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
927 $html = htmlspecialchars( $icon["alt"] );
930 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
937 * Gets the link to the wiki's main page.
940 function mainPageLink() {
941 $s = Linker
::linkKnown(
942 Title
::newMainPage(),
943 $this->msg( 'mainpage' )->escaped()
954 public function footerLink( $desc, $page ) {
955 // if the link description has been set to "-" in the default language,
956 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
957 // then it is disabled, for all languages.
960 // Otherwise, we display the link for the user, described in their
961 // language (which may or may not be the same as the default language),
962 // but we make the link target be the one site-wide page.
963 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
965 return Linker
::linkKnown(
967 $this->msg( $desc )->escaped()
973 * Gets the link to the wiki's privacy policy page.
974 * @return String HTML
976 function privacyLink() {
977 return $this->footerLink( 'privacy', 'privacypage' );
981 * Gets the link to the wiki's about page.
982 * @return String HTML
984 function aboutLink() {
985 return $this->footerLink( 'aboutsite', 'aboutpage' );
989 * Gets the link to the wiki's general disclaimers page.
990 * @return String HTML
992 function disclaimerLink() {
993 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
997 * Return URL options for the 'edit page' link.
998 * This may include an 'oldid' specifier, if the current page view is such.
1003 function editUrlOptions() {
1004 $options = array( 'action' => 'edit' );
1006 if ( !$this->isRevisionCurrent() ) {
1007 $options['oldid'] = intval( $this->getRevisionId() );
1014 * @param $id User|int
1017 function showEmailUser( $id ) {
1018 if ( $id instanceof User
) {
1021 $targetUser = User
::newFromId( $id );
1023 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1024 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1028 * Return a fully resolved style path url to images or styles stored in the common folder.
1029 * This method returns a url resolved using the configured skin style path
1030 * and includes the style version inside of the url.
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 getCommonStylePath( $name ) {
1035 global $wgStylePath, $wgStyleVersion;
1036 return "$wgStylePath/common/$name?$wgStyleVersion";
1040 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1041 * This method returns a url resolved using the configured skin style path
1042 * and includes the style version inside of the url.
1043 * @param string $name The name or path of a skin resource file
1044 * @return String The fully resolved style path url including styleversion
1046 function getSkinStylePath( $name ) {
1047 global $wgStylePath, $wgStyleVersion;
1048 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1051 /* these are used extensively in SkinTemplate, but also some other places */
1054 * @param $urlaction string
1057 static function makeMainPageUrl( $urlaction = '' ) {
1058 $title = Title
::newMainPage();
1059 self
::checkTitle( $title, '' );
1061 return $title->getLocalURL( $urlaction );
1065 * Make a URL for a Special Page using the given query and protocol.
1067 * If $proto is set to null, make a local URL. Otherwise, make a full
1068 * URL with the protocol specified.
1070 * @param string $name Name of the Special page
1071 * @param string $urlaction Query to append
1072 * @param $proto Protocol to use or null for a local URL
1075 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1076 $title = SpecialPage
::getSafeTitleFor( $name );
1077 if ( is_null( $proto ) ) {
1078 return $title->getLocalURL( $urlaction );
1080 return $title->getFullURL( $urlaction, false, $proto );
1085 * @param $name string
1086 * @param $subpage string
1087 * @param $urlaction string
1090 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1091 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1092 return $title->getLocalURL( $urlaction );
1096 * @param $name string
1097 * @param $urlaction string
1100 static function makeI18nUrl( $name, $urlaction = '' ) {
1101 $title = Title
::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1102 self
::checkTitle( $title, $name );
1103 return $title->getLocalURL( $urlaction );
1107 * @param $name string
1108 * @param $urlaction string
1111 static function makeUrl( $name, $urlaction = '' ) {
1112 $title = Title
::newFromText( $name );
1113 self
::checkTitle( $title, $name );
1115 return $title->getLocalURL( $urlaction );
1119 * If url string starts with http, consider as external URL, else
1121 * @param $name String
1122 * @return String URL
1124 static function makeInternalOrExternalUrl( $name ) {
1125 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1128 return self
::makeUrl( $name );
1133 * this can be passed the NS number as defined in Language.php
1135 * @param $urlaction string
1136 * @param $namespace int
1139 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1140 $title = Title
::makeTitleSafe( $namespace, $name );
1141 self
::checkTitle( $title, $name );
1143 return $title->getLocalURL( $urlaction );
1147 * these return an array with the 'href' and boolean 'exists'
1149 * @param $urlaction string
1152 static function makeUrlDetails( $name, $urlaction = '' ) {
1153 $title = Title
::newFromText( $name );
1154 self
::checkTitle( $title, $name );
1157 'href' => $title->getLocalURL( $urlaction ),
1158 'exists' => $title->getArticleID() != 0,
1163 * Make URL details where the article exists (or at least it's convenient to think so)
1164 * @param string $name Article name
1165 * @param $urlaction String
1168 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1169 $title = Title
::newFromText( $name );
1170 self
::checkTitle( $title, $name );
1173 'href' => $title->getLocalURL( $urlaction ),
1179 * make sure we have some title to operate on
1181 * @param $title Title
1182 * @param $name string
1184 static function checkTitle( &$title, $name ) {
1185 if ( !is_object( $title ) ) {
1186 $title = Title
::newFromText( $name );
1187 if ( !is_object( $title ) ) {
1188 $title = Title
::newFromText( '--error: link target missing--' );
1194 * Build an array that represents the sidebar(s), the navigation bar among them.
1196 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1198 * The format of the returned array is array( heading => content, ... ), where:
1199 * - heading is the heading of a navigation portlet. It is either:
1200 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1201 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1202 * - plain text, which should be HTML-escaped by the skin
1203 * - content is the contents of the portlet. It is either:
1204 * - HTML text (<ul><li>...</li>...</ul>)
1205 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1206 * - (for a magic string as a key, any value)
1208 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1209 * and can technically insert anything in here; skin creators are expected to handle
1210 * values described above.
1214 function buildSidebar() {
1215 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1216 wfProfileIn( __METHOD__
);
1218 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1220 if ( $wgEnableSidebarCache ) {
1221 $cachedsidebar = $wgMemc->get( $key );
1222 if ( $cachedsidebar ) {
1223 wfProfileOut( __METHOD__
);
1224 return $cachedsidebar;
1229 $this->addToSidebar( $bar, 'sidebar' );
1231 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1232 if ( $wgEnableSidebarCache ) {
1233 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1236 wfProfileOut( __METHOD__
);
1240 * Add content from a sidebar system message
1241 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1243 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1246 * @param $message String
1248 function addToSidebar( &$bar, $message ) {
1249 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1253 * Add content from plain text
1256 * @param $text string
1259 function addToSidebarPlain( &$bar, $text ) {
1260 $lines = explode( "\n", $text );
1264 foreach ( $lines as $line ) {
1265 if ( strpos( $line, '*' ) !== 0 ) {
1268 $line = rtrim( $line, "\r" ); // for Windows compat
1270 if ( strpos( $line, '**' ) !== 0 ) {
1271 $heading = trim( $line, '* ' );
1272 if ( !array_key_exists( $heading, $bar ) ) {
1273 $bar[$heading] = array();
1276 $line = trim( $line, '* ' );
1278 if ( strpos( $line, '|' ) !== false ) { // sanity check
1279 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1280 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1281 if ( count( $line ) !== 2 ) {
1282 // Second sanity check, could be hit by people doing
1283 // funky stuff with parserfuncs... (bug 33321)
1287 $extraAttribs = array();
1289 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1290 if ( $msgLink->exists() ) {
1291 $link = $msgLink->text();
1292 if ( $link == '-' ) {
1298 $msgText = $this->msg( $line[1] );
1299 if ( $msgText->exists() ) {
1300 $text = $msgText->text();
1305 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1308 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1309 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1310 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1311 $extraAttribs['rel'] = 'nofollow';
1314 global $wgExternalLinkTarget;
1315 if ( $wgExternalLinkTarget ) {
1316 $extraAttribs['target'] = $wgExternalLinkTarget;
1319 $title = Title
::newFromText( $link );
1322 $title = $title->fixSpecialName();
1323 $href = $title->getLinkURL();
1325 $href = 'INVALID-TITLE';
1329 $bar[$heading][] = array_merge( array(
1332 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1345 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1346 * should be loaded by OutputPage. That module no longer exists and the return value of this
1347 * method is ignored.
1349 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1350 * can be used instead (SkinTemplate-based skins do it automatically).
1352 * @deprecated since 1.22
1355 public function commonPrintStylesheet() {
1356 wfDeprecated( __METHOD__
, '1.22' );
1361 * Gets new talk page messages for the current user and returns an
1362 * appropriate alert message (or an empty string if there are no messages)
1365 function getNewtalks() {
1367 $newMessagesAlert = '';
1368 $user = $this->getUser();
1369 $newtalks = $user->getNewMessageLinks();
1370 $out = $this->getOutput();
1372 // Allow extensions to disable or modify the new messages alert
1373 if ( !wfRunHooks( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1376 if ( $newMessagesAlert ) {
1377 return $newMessagesAlert;
1380 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1381 $uTalkTitle = $user->getTalkPage();
1382 $lastSeenRev = isset( $newtalks[0]['rev'] ) ?
$newtalks[0]['rev'] : null;
1384 if ( $lastSeenRev !== null ) {
1385 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1386 $latestRev = Revision
::newFromTitle( $uTalkTitle, false, Revision
::READ_NORMAL
);
1387 if ( $latestRev !== null ) {
1388 // Singular if only 1 unseen revision, plural if several unseen revisions.
1389 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1390 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1391 $lastSeenRev, $latestRev, 10, 'include_new' );
1394 // Singular if no revision -> diff link will show latest change only in any case
1397 $plural = $plural ?
2 : 1;
1398 // 2 signifies "more than one revision". We don't know how many, and even if we did,
1399 // the number of revisions or authors is not necessarily the same as the number of
1401 $newMessagesLink = Linker
::linkKnown(
1403 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1405 array( 'redirect' => 'no' )
1408 $newMessagesDiffLink = Linker
::linkKnown(
1410 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1412 $lastSeenRev !== null
1413 ?
array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1414 : array( 'diff' => 'cur' )
1417 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1418 $newMessagesAlert = $this->msg(
1419 'youhavenewmessagesfromusers',
1421 $newMessagesDiffLink
1422 )->numParams( $nofAuthors );
1424 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1425 $newMessagesAlert = $this->msg(
1426 $nofAuthors > 10 ?
'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1428 $newMessagesDiffLink
1431 $newMessagesAlert = $newMessagesAlert->text();
1432 # Disable Squid cache
1433 $out->setSquidMaxage( 0 );
1434 } elseif ( count( $newtalks ) ) {
1435 $sep = $this->msg( 'newtalkseparator' )->escaped();
1438 foreach ( $newtalks as $newtalk ) {
1439 $msgs[] = Xml
::element(
1441 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1444 $parts = implode( $sep, $msgs );
1445 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1446 $out->setSquidMaxage( 0 );
1449 return $newMessagesAlert;
1453 * Get a cached notice
1455 * @param string $name message name, or 'default' for $wgSiteNotice
1456 * @return String: HTML fragment
1458 private function getCachedNotice( $name ) {
1459 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1461 wfProfileIn( __METHOD__
);
1465 if ( $name === 'default' ) {
1467 global $wgSiteNotice;
1468 $notice = $wgSiteNotice;
1469 if ( empty( $notice ) ) {
1470 wfProfileOut( __METHOD__
);
1474 $msg = $this->msg( $name )->inContentLanguage();
1475 if ( $msg->isDisabled() ) {
1476 wfProfileOut( __METHOD__
);
1479 $notice = $msg->plain();
1482 // Use the extra hash appender to let eg SSL variants separately cache.
1483 $key = wfMemcKey( $name . $wgRenderHashAppend );
1484 $cachedNotice = $parserMemc->get( $key );
1485 if ( is_array( $cachedNotice ) ) {
1486 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1487 $notice = $cachedNotice['html'];
1496 $parsed = $this->getOutput()->parse( $notice );
1497 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1501 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1502 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1503 wfProfileOut( __METHOD__
);
1508 * Get a notice based on page's namespace
1510 * @return String: HTML fragment
1512 function getNamespaceNotice() {
1513 wfProfileIn( __METHOD__
);
1515 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1516 $namespaceNotice = $this->getCachedNotice( $key );
1517 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1518 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1520 $namespaceNotice = '';
1523 wfProfileOut( __METHOD__
);
1524 return $namespaceNotice;
1528 * Get the site notice
1530 * @return String: HTML fragment
1532 function getSiteNotice() {
1533 wfProfileIn( __METHOD__
);
1536 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1537 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1538 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1540 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1541 if ( !$anonNotice ) {
1542 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1544 $siteNotice = $anonNotice;
1547 if ( !$siteNotice ) {
1548 $siteNotice = $this->getCachedNotice( 'default' );
1552 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1553 wfProfileOut( __METHOD__
);
1558 * Create a section edit link. This supersedes editSectionLink() and
1559 * editSectionLinkForOther().
1561 * @param $nt Title The title being linked to (may not be the same as
1562 * $wgTitle, if the section is included from a template)
1563 * @param string $section The designation of the section being pointed to,
1564 * to be included in the link, like "§ion=$section"
1565 * @param string $tooltip The tooltip to use for the link: will be escaped
1566 * and wrapped in the 'editsectionhint' message
1567 * @param $lang string Language code
1568 * @return string HTML to use for edit link
1570 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1571 // HTML generated here should probably have userlangattributes
1572 // added to it for LTR text on RTL pages
1574 $lang = wfGetLangObj( $lang );
1577 if ( !is_null( $tooltip ) ) {
1578 # Bug 25462: undo double-escaping.
1579 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1580 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1581 ->inLanguage( $lang )->text();
1583 $link = Linker
::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(),
1585 array( 'action' => 'edit', 'section' => $section ),
1586 array( 'noclasses', 'known' )
1589 # Add the brackets and the span and run the hook.
1590 $result = '<span class="mw-editsection">'
1591 . '<span class="mw-editsection-bracket">[</span>'
1593 . '<span class="mw-editsection-bracket">]</span>'
1596 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1601 * Use PHP's magic __call handler to intercept legacy calls to the linker
1602 * for backwards compatibility.
1604 * @param string $fname Name of called method
1605 * @param array $args Arguments to the method
1606 * @throws MWException
1609 function __call( $fname, $args ) {
1610 $realFunction = array( 'Linker', $fname );
1611 if ( is_callable( $realFunction ) ) {
1612 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1613 return call_user_func_array( $realFunction, $args );
1615 $className = get_class( $this );
1616 throw new MWException( "Call to undefined method $className::$fname" );