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 that provide 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 # while code from www.php.net
60 while ( false !== ( $file = $skinDir->read() ) ) {
61 // Skip non-PHP files, hidden files, and '.dep' includes
64 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
66 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
70 $skinsInitialised = true;
71 wfProfileOut( __METHOD__
. '-init' );
73 return $wgValidSkinNames;
77 * Fetch the skinname messages for available skins.
78 * @return array of strings
80 static function getSkinNameMessages() {
82 foreach( self
::getSkinNames() as $skinKey => $skinName ) {
83 $messages[] = "skinname-$skinKey";
89 * Fetch the list of usable skins in regards to $wgSkipSkins.
90 * Useful for Special:Preferences and other places where you
91 * only want to show skins users _can_ use.
92 * @return array of strings
94 public static function getUsableSkins() {
97 $usableSkins = self
::getSkinNames();
99 foreach ( $wgSkipSkins as $skip ) {
100 unset( $usableSkins[$skip] );
107 * Normalize a skin preference value to a form that can be loaded.
108 * If a skin can't be found, it will fall back to the configured
109 * default (or the old 'Classic' skin if that's broken).
110 * @param $key String: 'monobook', 'standard', etc.
113 static function normalizeKey( $key ) {
114 global $wgDefaultSkin;
116 $skinNames = Skin
::getSkinNames();
118 if ( $key == '' ||
$key == 'default' ) {
119 // Don't return the default immediately;
120 // in a misconfiguration we need to fall back.
121 $key = $wgDefaultSkin;
124 if ( isset( $skinNames[$key] ) ) {
128 // Older versions of the software used a numeric setting
129 // in the user preferences.
136 if ( isset( $fallback[$key] ) ) {
137 $key = $fallback[$key];
140 if ( isset( $skinNames[$key] ) ) {
142 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
143 return $wgDefaultSkin;
150 * Factory method for loading a skin of a given type
151 * @param $key String: 'monobook', 'standard', etc.
154 static function &newFromKey( $key ) {
155 global $wgStyleDirectory;
157 $key = Skin
::normalizeKey( $key );
159 $skinNames = Skin
::getSkinNames();
160 $skinName = $skinNames[$key];
161 $className = "Skin{$skinName}";
163 # Grab the skin class and initialise it.
164 if ( !MWInit
::classExists( $className ) ) {
166 if ( !defined( 'MW_COMPILED' ) ) {
167 // Preload base classes to work around APC/PHP5 bug
168 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
169 if ( file_exists( $deps ) ) {
170 include_once( $deps );
172 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
175 # Check if we got if not failback to default skin
176 if ( !MWInit
::classExists( $className ) ) {
177 # DO NOT die if the class isn't found. This breaks maintenance
178 # scripts and can cause a user account to be unrecoverable
179 # except by SQL manipulation if a previously valid skin name
180 # is no longer valid.
181 wfDebug( "Skin class does not exist: $className\n" );
182 $className = 'SkinVector';
183 if ( !defined( 'MW_COMPILED' ) ) {
184 require_once( "{$wgStyleDirectory}/Vector.php" );
188 $skin = new $className( $key );
192 /** @return string skin name */
193 public function getSkinName() {
194 return $this->skinname
;
198 * @param $out OutputPage
200 function initPage( OutputPage
$out ) {
201 wfProfileIn( __METHOD__
);
203 $this->preloadExistence();
205 wfProfileOut( __METHOD__
);
209 * Preload the existence of three commonly-requested pages in a single query
211 function preloadExistence() {
212 $user = $this->getUser();
215 $titles = array( $user->getUserPage(), $user->getTalkPage() );
218 if ( $this->getTitle()->isSpecialPage() ) {
220 } elseif ( $this->getTitle()->isTalkPage() ) {
221 $titles[] = $this->getTitle()->getSubjectPage();
223 $titles[] = $this->getTitle()->getTalkPage();
226 $lb = new LinkBatch( $titles );
227 $lb->setCaller( __METHOD__
);
232 * Get the current revision ID
236 public function getRevisionId() {
237 return $this->getOutput()->getRevisionId();
241 * Whether the revision displayed is the latest revision of the page
245 public function isRevisionCurrent() {
246 $revID = $this->getRevisionId();
247 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
251 * Set the "relevant" title
252 * @see self::getRelevantTitle()
253 * @param $t Title object to use
255 public function setRelevantTitle( $t ) {
256 $this->mRelevantTitle
= $t;
260 * Return the "relevant" title.
261 * A "relevant" title is not necessarily the actual title of the page.
262 * Special pages like Special:MovePage use set the page they are acting on
263 * as their "relevant" title, this allows the skin system to display things
264 * such as content tabs which belong to to that page instead of displaying
265 * a basic special page tab which has almost no meaning.
269 public function getRelevantTitle() {
270 if ( isset($this->mRelevantTitle
) ) {
271 return $this->mRelevantTitle
;
273 return $this->getTitle();
277 * Set the "relevant" user
278 * @see self::getRelevantUser()
279 * @param $u User object to use
281 public function setRelevantUser( $u ) {
282 $this->mRelevantUser
= $u;
286 * Return the "relevant" user.
287 * A "relevant" user is similar to a relevant title. Special pages like
288 * Special:Contributions mark the user which they are relevant to so that
289 * things like the toolbox can display the information they usually are only
290 * able to display on a user's userpage and talkpage.
293 public function getRelevantUser() {
294 if ( isset($this->mRelevantUser
) ) {
295 return $this->mRelevantUser
;
297 $title = $this->getRelevantTitle();
298 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
299 $rootUser = strtok( $title->getText(), '/' );
300 if ( User
::isIP( $rootUser ) ) {
301 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
303 $user = User
::newFromName( $rootUser, false );
304 if ( $user && $user->isLoggedIn() ) {
305 $this->mRelevantUser
= $user;
308 return $this->mRelevantUser
;
314 * Outputs the HTML generated by other functions.
315 * @param $out OutputPage
317 abstract function outputPage( OutputPage
$out = null );
323 static function makeVariablesScript( $data ) {
325 return Html
::inlineScript(
326 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
334 * Make a <script> tag containing global variables
336 * @deprecated in 1.19
338 * @return string HTML fragment
340 public static function makeGlobalVariablesScript( $unused ) {
343 wfDeprecated( __METHOD__
, '1.19' );
345 return self
::makeVariablesScript( $wgOut->getJSVars() );
349 * Get the query to generate a dynamic stylesheet
353 public static function getDynamicStylesheetQuery() {
354 global $wgSquidMaxage;
358 'maxage' => $wgSquidMaxage,
359 'usemsgcache' => 'yes',
360 'ctype' => 'text/css',
361 'smaxage' => $wgSquidMaxage,
366 * Add skin specific stylesheets
367 * Calling this method with an $out of anything but the same OutputPage
368 * inside ->getOutput() is deprecated. The $out arg is kept
369 * for compatibility purposes with skins.
370 * @param $out OutputPage
373 abstract function setupSkinUserCss( OutputPage
$out );
377 * @param $title Title
380 function getPageClasses( $title ) {
381 $numeric = 'ns-' . $title->getNamespace();
383 if ( $title->isSpecialPage() ) {
384 $type = 'ns-special';
385 // bug 23315: provide a class based on the canonical special page name without subpages
386 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
387 if ( $canonicalName ) {
388 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
390 $type .= ' mw-invalidspecialpage';
392 } elseif ( $title->isTalkPage() ) {
395 $type = 'ns-subject';
398 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
400 return "$numeric $type $name";
404 * This will be called by OutputPage::headElement when it is creating the
405 * <body> tag, skins can override it if they have a need to add in any
406 * body attributes or classes of their own.
407 * @param $out OutputPage
408 * @param $bodyAttrs Array
410 function addToBodyAttributes( $out, &$bodyAttrs ) {
411 // does nothing by default
426 function getCategoryLinks() {
427 global $wgUseCategoryBrowser;
429 $out = $this->getOutput();
430 $allCats = $out->getCategoryLinks();
432 if ( !count( $allCats ) ) {
440 $colon = $this->msg( 'colon-separator' )->escaped();
442 if ( !empty( $allCats['normal'] ) ) {
443 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
445 $msg = $this->msg( 'pagecategories', count( $allCats['normal'] ) )->escaped();
446 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
447 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
448 Linker
::link( Title
::newFromText( $linkPage ), $msg )
449 . $colon . '<ul>' . $t . '</ul>' . '</div>';
453 if ( isset( $allCats['hidden'] ) ) {
454 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
455 $class = ' mw-hidden-cats-user-shown';
456 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
457 $class = ' mw-hidden-cats-ns-shown';
459 $class = ' mw-hidden-cats-hidden';
462 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
463 $this->msg( 'hidden-categories', count( $allCats['hidden'] ) )->escaped() .
464 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
468 # optional 'dmoz-like' category browser. Will be shown under the list
469 # of categories an article belong to
470 if ( $wgUseCategoryBrowser ) {
471 $s .= '<br /><hr />';
473 # get a big array of the parents tree
474 $parenttree = $this->getTitle()->getParentCategoryTree();
475 # Skin object passed by reference cause it can not be
476 # accessed under the method subfunction drawCategoryBrowser
477 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
478 # Clean out bogus first entry and sort them
479 unset( $tempout[0] );
481 # Output one per line
482 $s .= implode( "<br />\n", $tempout );
489 * Render the array as a serie of links.
490 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
491 * @return String separated by >, terminate with "\n"
493 function drawCategoryBrowser( $tree ) {
496 foreach ( $tree as $element => $parent ) {
497 if ( empty( $parent ) ) {
498 # element start a new list
501 # grab the others elements
502 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
505 # add our current element to the list
506 $eltitle = Title
::newFromText( $element );
507 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
516 function getCategories() {
517 $out = $this->getOutput();
519 $catlinks = $this->getCategoryLinks();
521 $classes = 'catlinks';
523 // Check what we're showing
524 $allCats = $out->getCategoryLinks();
525 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
526 $this->getTitle()->getNamespace() == NS_CATEGORY
;
528 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
529 $classes .= ' catlinks-allhidden';
532 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
536 * This runs a hook to allow extensions placing their stuff after content
537 * and article metadata (e.g. categories).
538 * Note: This function has nothing to do with afterContent().
540 * This hook is placed here in order to allow using the same hook for all
541 * skins, both the SkinTemplate based ones and the older ones, which directly
542 * use this class to get their data.
544 * The output of this function gets processed in SkinTemplate::outputPage() for
545 * the SkinTemplate based skins, all other skins should directly echo it.
547 * @return String, empty by default, if not changed by any hook function.
549 protected function afterContentHook() {
552 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
553 // adding just some spaces shouldn't toggle the output
554 // of the whole <div/>, so we use trim() here
555 if ( trim( $data ) != '' ) {
556 // Doing this here instead of in the skins to
557 // ensure that the div has the same ID in all
559 $data = "<div id='mw-data-after-content'>\n" .
564 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
571 * Generate debug data HTML for displaying at the bottom of the main content
573 * @return String HTML containing debug data, if enabled (otherwise empty).
575 protected function generateDebugHTML() {
578 $html = MWDebug
::getDebugHTML( $this->getContext() );
580 if ( $wgShowDebug ) {
581 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext
);
582 $html .= "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
583 $listInternals . "</ul>\n";
590 * @param $debugText string
593 private function formatDebugHTML( $debugText ) {
594 global $wgDebugTimestamps;
596 $lines = explode( "\n", $debugText );
600 foreach ( $lines as $line ) {
602 if ( $wgDebugTimestamps ) {
604 if ( preg_match( '/^(\d+\.\d+ {1,3}\d+.\dM\s{2})/', $line, $matches ) ) {
606 $line = substr( $line, strlen( $pre ) );
609 $display = ltrim( $line );
610 $ident = strlen( $line ) - strlen( $display );
611 $diff = $ident - $curIdent;
613 $display = $pre . $display;
614 if ( $display == '' ) {
615 $display = "\xc2\xa0";
618 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
621 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
623 $display = htmlspecialchars( $display );
627 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
628 } elseif ( $diff == 0 ) {
629 $ret .= "</li><li>\n";
631 $ret .= str_repeat( "<ul><li>\n", $diff );
633 $ret .= "<tt>$display</tt>\n";
638 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
644 * This gets called shortly before the </body> tag.
646 * @return String HTML-wrapped JS code to be put before </body>
648 function bottomScripts() {
649 // TODO and the suckage continues. This function is really just a wrapper around
650 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
652 $bottomScriptText = $this->getOutput()->getBottomScripts();
653 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
655 return $bottomScriptText;
659 * Text with the permalink to the source page,
660 * usually shown on the footer of a printed page
662 * @return string HTML text with an URL
664 function printSource() {
665 $oldid = $this->getRevisionId();
667 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
669 // oldid not available for non existing pages
670 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
672 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
678 function getUndeleteLink() {
679 $action = $this->getRequest()->getVal( 'action', 'view' );
681 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
682 ( $this->getTitle()->getArticleID() == 0 ||
$action == 'history' ) ) {
683 $n = $this->getTitle()->isDeleted();
687 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
688 $msg = 'thisisdeleted';
690 $msg = 'viewdeleted';
693 return $this->msg( $msg )->rawParams(
695 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
696 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
707 function subPageSubtitle() {
709 $out = $this->getOutput();
712 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
716 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
717 $ptext = $this->getTitle()->getPrefixedText();
718 if ( preg_match( '/\//', $ptext ) ) {
719 $links = explode( '/', $ptext );
725 foreach ( $links as $link ) {
726 $growinglink .= $link;
728 $linkObj = Title
::newFromText( $growinglink );
730 if ( is_object( $linkObj ) && $linkObj->exists() ) {
731 $getlink = Linker
::linkKnown(
733 htmlspecialchars( $display )
739 $subpages .= $wgLang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
741 $subpages .= '< ';
744 $subpages .= $getlink;
758 * Returns true if the IP should be shown in the header
761 function showIPinHeader() {
762 global $wgShowIPinHeader;
763 return $wgShowIPinHeader && session_id() != '';
769 function getSearchLink() {
770 $searchPage = SpecialPage
::getTitleFor( 'Search' );
771 return $searchPage->getLocalURL();
777 function escapeSearchLink() {
778 return htmlspecialchars( $this->getSearchLink() );
782 * @param $type string
785 function getCopyright( $type = 'detect' ) {
786 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
788 if ( $type == 'detect' ) {
789 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
796 if ( $type == 'history' ) {
797 $msg = 'history_copyright';
802 if ( $wgRightsPage ) {
803 $title = Title
::newFromText( $wgRightsPage );
804 $link = Linker
::linkKnown( $title, $wgRightsText );
805 } elseif ( $wgRightsUrl ) {
806 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
807 } elseif ( $wgRightsText ) {
808 $link = $wgRightsText;
814 // Allow for site and per-namespace customization of copyright notice.
817 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
819 $msgObj = $this->msg( $msg )->rawParams( $link );
821 $msg = $msgObj->inContentLanguage()->text();
822 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
823 $msg = Html
::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
827 return $msgObj->text();
832 * @return null|string
834 function getCopyrightIcon() {
835 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
839 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
840 $out = $wgCopyrightIcon;
841 } elseif ( $wgRightsIcon ) {
842 $icon = htmlspecialchars( $wgRightsIcon );
844 if ( $wgRightsUrl ) {
845 $url = htmlspecialchars( $wgRightsUrl );
846 $out .= '<a href="' . $url . '">';
849 $text = htmlspecialchars( $wgRightsText );
850 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
852 if ( $wgRightsUrl ) {
861 * Gets the powered by MediaWiki icon.
864 function getPoweredBy() {
867 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
868 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
869 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
874 * Get the timestamp of the latest revision, formatted in user language
878 protected function lastModified() {
879 $timestamp = $this->getOutput()->getRevisionTimestamp();
881 # No cached timestamp, load it from the database
882 if ( $timestamp === null ) {
883 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
887 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
888 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
889 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
894 if ( wfGetLB()->getLaggedSlaveMode() ) {
895 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
902 * @param $align string
905 function logoText( $align = '' ) {
906 if ( $align != '' ) {
907 $a = " align='{$align}'";
912 $mp = $this->msg( 'mainpage' )->escaped();
913 $mptitle = Title
::newMainPage();
914 $url = ( is_object( $mptitle ) ?
htmlspecialchars( $mptitle->getLocalURL() ) : '' );
916 $logourl = $this->getLogo();
917 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
923 * Renders a $wgFooterIcons icon acording to the method's arguments
924 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
925 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
926 * @return String HTML
928 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
929 if ( is_string( $icon ) ) {
931 } else { // Assuming array
932 $url = isset($icon["url"]) ?
$icon["url"] : null;
933 unset( $icon["url"] );
934 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
935 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
937 $html = htmlspecialchars( $icon["alt"] );
940 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
947 * Gets the link to the wiki's main page.
950 function mainPageLink() {
951 $s = Linker
::linkKnown(
952 Title
::newMainPage(),
953 $this->msg( 'mainpage' )->escaped()
964 public function footerLink( $desc, $page ) {
965 // if the link description has been set to "-" in the default language,
966 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
967 // then it is disabled, for all languages.
970 // Otherwise, we display the link for the user, described in their
971 // language (which may or may not be the same as the default language),
972 // but we make the link target be the one site-wide page.
973 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
975 return Linker
::linkKnown(
977 $this->msg( $desc )->escaped()
983 * Gets the link to the wiki's privacy policy page.
984 * @return String HTML
986 function privacyLink() {
987 return $this->footerLink( 'privacy', 'privacypage' );
991 * Gets the link to the wiki's about page.
992 * @return String HTML
994 function aboutLink() {
995 return $this->footerLink( 'aboutsite', 'aboutpage' );
999 * Gets the link to the wiki's general disclaimers page.
1000 * @return String HTML
1002 function disclaimerLink() {
1003 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1007 * Return URL options for the 'edit page' link.
1008 * This may include an 'oldid' specifier, if the current page view is such.
1013 function editUrlOptions() {
1014 $options = array( 'action' => 'edit' );
1016 if ( !$this->isRevisionCurrent() ) {
1017 $options['oldid'] = intval( $this->getRevisionId() );
1024 * @param $id User|int
1027 function showEmailUser( $id ) {
1028 if ( $id instanceof User
) {
1031 $targetUser = User
::newFromId( $id );
1033 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1034 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1038 * Return a fully resolved style path url to images or styles stored in the common folder.
1039 * This method returns a url resolved using the configured skin style path
1040 * and includes the style version inside of the url.
1041 * @param $name String: The name or path of a skin resource file
1042 * @return String The fully resolved style path url including styleversion
1044 function getCommonStylePath( $name ) {
1045 global $wgStylePath, $wgStyleVersion;
1046 return "$wgStylePath/common/$name?$wgStyleVersion";
1050 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1051 * This method returns a url resolved using the configured skin style path
1052 * and includes the style version inside of the url.
1053 * @param $name String: The name or path of a skin resource file
1054 * @return String The fully resolved style path url including styleversion
1056 function getSkinStylePath( $name ) {
1057 global $wgStylePath, $wgStyleVersion;
1058 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1061 /* these are used extensively in SkinTemplate, but also some other places */
1064 * @param $urlaction string
1067 static function makeMainPageUrl( $urlaction = '' ) {
1068 $title = Title
::newMainPage();
1069 self
::checkTitle( $title, '' );
1071 return $title->getLocalURL( $urlaction );
1075 * @param $name string
1076 * @param $urlaction string
1079 static function makeSpecialUrl( $name, $urlaction = '' ) {
1080 $title = SpecialPage
::getSafeTitleFor( $name );
1081 return $title->getLocalURL( $urlaction );
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( wfMsgForContent( $name ) );
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( '/^(?:' . 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 $name String 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
1198 function buildSidebar() {
1199 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1200 wfProfileIn( __METHOD__
);
1202 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1204 if ( $wgEnableSidebarCache ) {
1205 $cachedsidebar = $wgMemc->get( $key );
1206 if ( $cachedsidebar ) {
1207 wfProfileOut( __METHOD__
);
1208 return $cachedsidebar;
1213 $this->addToSidebar( $bar, 'sidebar' );
1215 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1216 if ( $wgEnableSidebarCache ) {
1217 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1220 wfProfileOut( __METHOD__
);
1224 * Add content from a sidebar system message
1225 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1227 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1230 * @param $message String
1232 function addToSidebar( &$bar, $message ) {
1233 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1237 * Add content from plain text
1240 * @param $text string
1243 function addToSidebarPlain( &$bar, $text ) {
1244 $lines = explode( "\n", $text );
1248 foreach ( $lines as $line ) {
1249 if ( strpos( $line, '*' ) !== 0 ) {
1252 $line = rtrim( $line, "\r" ); // for Windows compat
1254 if ( strpos( $line, '**' ) !== 0 ) {
1255 $heading = trim( $line, '* ' );
1256 if ( !array_key_exists( $heading, $bar ) ) {
1257 $bar[$heading] = array();
1260 $line = trim( $line, '* ' );
1262 if ( strpos( $line, '|' ) !== false ) { // sanity check
1263 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1264 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1265 if ( count( $line ) !== 2 ) {
1266 // Second sanity check, could be hit by people doing
1267 // funky stuff with parserfuncs... (bug 33321)
1271 $extraAttribs = array();
1273 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1274 if ( $msgLink->exists() ) {
1275 $link = $msgLink->text();
1276 if ( $link == '-' ) {
1282 $msgText = $this->msg( $line[1] );
1283 if ( $msgText->exists() ) {
1284 $text = $msgText->text();
1289 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1292 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1293 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1294 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1295 $extraAttribs['rel'] = 'nofollow';
1298 global $wgExternalLinkTarget;
1299 if ( $wgExternalLinkTarget) {
1300 $extraAttribs['target'] = $wgExternalLinkTarget;
1303 $title = Title
::newFromText( $link );
1306 $title = $title->fixSpecialName();
1307 $href = $title->getLinkURL();
1309 $href = 'INVALID-TITLE';
1313 $bar[$heading][] = array_merge( array(
1316 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1329 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1330 * print stylesheet should override this and return false. (This is an
1331 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1335 public function commonPrintStylesheet() {
1340 * Gets new talk page messages for the current user.
1341 * @return MediaWiki message or if no new talk page messages, nothing
1343 function getNewtalks() {
1344 $out = $this->getOutput();
1346 $newtalks = $this->getUser()->getNewMessageLinks();
1349 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1350 $userTitle = $this->getUser()->getUserPage();
1351 $userTalkTitle = $userTitle->getTalkPage();
1353 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1354 $newMessagesLink = Linker
::linkKnown(
1356 $this->msg( 'newmessageslink' )->escaped(),
1358 array( 'redirect' => 'no' )
1361 $newMessagesDiffLink = Linker
::linkKnown(
1363 $this->msg( 'newmessagesdifflink' )->escaped(),
1365 array( 'diff' => 'cur' )
1369 'youhavenewmessages',
1371 $newMessagesDiffLink
1373 # Disable Squid cache
1374 $out->setSquidMaxage( 0 );
1376 } elseif ( count( $newtalks ) ) {
1377 // _>" " for BC <= 1.16
1378 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1381 foreach ( $newtalks as $newtalk ) {
1382 $msgs[] = Xml
::element(
1384 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1387 $parts = implode( $sep, $msgs );
1388 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1389 $out->setSquidMaxage( 0 );
1396 * Get a cached notice
1398 * @param $name String: message name, or 'default' for $wgSiteNotice
1399 * @return String: HTML fragment
1401 private function getCachedNotice( $name ) {
1402 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1404 wfProfileIn( __METHOD__
);
1408 if( $name === 'default' ) {
1410 global $wgSiteNotice;
1411 $notice = $wgSiteNotice;
1412 if( empty( $notice ) ) {
1413 wfProfileOut( __METHOD__
);
1417 $msg = $this->msg( $name )->inContentLanguage();
1418 if( $msg->isDisabled() ) {
1419 wfProfileOut( __METHOD__
);
1422 $notice = $msg->plain();
1425 // Use the extra hash appender to let eg SSL variants separately cache.
1426 $key = wfMemcKey( $name . $wgRenderHashAppend );
1427 $cachedNotice = $parserMemc->get( $key );
1428 if( is_array( $cachedNotice ) ) {
1429 if( md5( $notice ) == $cachedNotice['hash'] ) {
1430 $notice = $cachedNotice['html'];
1439 $parsed = $this->getOutput()->parse( $notice );
1440 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1444 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1445 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1446 wfProfileOut( __METHOD__
);
1451 * Get a notice based on page's namespace
1453 * @return String: HTML fragment
1455 function getNamespaceNotice() {
1456 wfProfileIn( __METHOD__
);
1458 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1459 $namespaceNotice = $this->getCachedNotice( $key );
1460 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1461 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1463 $namespaceNotice = '';
1466 wfProfileOut( __METHOD__
);
1467 return $namespaceNotice;
1471 * Get the site notice
1473 * @return String: HTML fragment
1475 function getSiteNotice() {
1476 wfProfileIn( __METHOD__
);
1479 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1480 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1481 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1483 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1484 if ( !$anonNotice ) {
1485 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1487 $siteNotice = $anonNotice;
1490 if ( !$siteNotice ) {
1491 $siteNotice = $this->getCachedNotice( 'default' );
1495 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1496 wfProfileOut( __METHOD__
);
1501 * Create a section edit link. This supersedes editSectionLink() and
1502 * editSectionLinkForOther().
1504 * @param $nt Title The title being linked to (may not be the same as
1505 * $wgTitle, if the section is included from a template)
1506 * @param $section string The designation of the section being pointed to,
1507 * to be included in the link, like "§ion=$section"
1508 * @param $tooltip string The tooltip to use for the link: will be escaped
1509 * and wrapped in the 'editsectionhint' message
1510 * @param $lang string Language code
1511 * @return string HTML to use for edit link
1513 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1514 // HTML generated here should probably have userlangattributes
1515 // added to it for LTR text on RTL pages
1517 if ( !is_null( $tooltip ) ) {
1518 # Bug 25462: undo double-escaping.
1519 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1520 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'replaceafter' ), $tooltip );
1522 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1524 array( 'action' => 'edit', 'section' => $section ),
1525 array( 'noclasses', 'known' )
1528 # Run the old hook. This takes up half of the function . . . hopefully
1529 # we can rid of it someday.
1532 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape', 'replaceafter' ), $tooltip );
1533 $attribs = " title=\"$attribs\"";
1536 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1537 if ( !is_null( $result ) ) {
1538 # For reverse compatibility, add the brackets *after* the hook is
1539 # run, and even add them to hook-provided text. (This is the main
1540 # reason that the EditSectionLink hook is deprecated in favor of
1541 # DoEditSectionLink: it can't change the brackets or the span.)
1542 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1543 return "<span class=\"editsection\">$result</span>";
1546 # Add the brackets and the span, and *then* run the nice new hook, with
1547 # clean and non-redundant arguments.
1548 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1549 $result = "<span class=\"editsection\">$result</span>";
1551 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1556 * Use PHP's magic __call handler to intercept legacy calls to the linker
1557 * for backwards compatibility.
1559 * @param $fname String Name of called method
1560 * @param $args Array Arguments to the method
1563 function __call( $fname, $args ) {
1564 $realFunction = array( 'Linker', $fname );
1565 if ( is_callable( $realFunction ) ) {
1566 return call_user_func_array( $realFunction, $args );
1568 $className = get_class( $this );
1569 throw new MWException( "Call to undefined method $className::$fname" );