3 * @defgroup Skins Skins
6 if ( !defined( 'MEDIAWIKI' ) ) {
11 * The main skin class that provide methods and properties for all other skins.
12 * This base class is also the "Standard" skin.
14 * See docs/skin.txt for more information.
18 abstract class Skin
extends ContextSource
{
19 protected $skinname = 'standard';
20 protected $mRelevantTitle = null;
21 protected $mRelevantUser = null;
24 * Fetch the set of available skins.
25 * @return array of strings
27 static function getSkinNames() {
28 global $wgValidSkinNames;
29 static $skinsInitialised = false;
31 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
32 # Get a list of available skins
33 # Build using the regular expression '^(.*).php$'
34 # Array keys are all lower case, array value keep the case used by filename
36 wfProfileIn( __METHOD__
. '-init' );
38 global $wgStyleDirectory;
40 $skinDir = dir( $wgStyleDirectory );
42 # while code from www.php.net
43 while ( false !== ( $file = $skinDir->read() ) ) {
44 // Skip non-PHP files, hidden files, and '.dep' includes
47 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
49 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
53 $skinsInitialised = true;
54 wfProfileOut( __METHOD__
. '-init' );
56 return $wgValidSkinNames;
60 * Fetch the list of usable skins in regards to $wgSkipSkins.
61 * Useful for Special:Preferences and other places where you
62 * only want to show skins users _can_ use.
63 * @return array of strings
65 public static function getUsableSkins() {
68 $usableSkins = self
::getSkinNames();
70 foreach ( $wgSkipSkins as $skip ) {
71 unset( $usableSkins[$skip] );
78 * Normalize a skin preference value to a form that can be loaded.
79 * If a skin can't be found, it will fall back to the configured
80 * default (or the old 'Classic' skin if that's broken).
81 * @param $key String: 'monobook', 'standard', etc.
84 static function normalizeKey( $key ) {
85 global $wgDefaultSkin;
87 $skinNames = Skin
::getSkinNames();
90 // Don't return the default immediately;
91 // in a misconfiguration we need to fall back.
92 $key = $wgDefaultSkin;
95 if ( isset( $skinNames[$key] ) ) {
99 // Older versions of the software used a numeric setting
100 // in the user preferences.
107 if ( isset( $fallback[$key] ) ) {
108 $key = $fallback[$key];
111 if ( isset( $skinNames[$key] ) ) {
113 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
114 return $wgDefaultSkin;
121 * Factory method for loading a skin of a given type
122 * @param $key String: 'monobook', 'standard', etc.
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory;
128 $key = Skin
::normalizeKey( $key );
130 $skinNames = Skin
::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = "Skin{$skinName}";
134 # Grab the skin class and initialise it.
135 if ( !MWInit
::classExists( $className ) ) {
137 if ( !defined( 'MW_COMPILED' ) ) {
138 // Preload base classes to work around APC/PHP5 bug
139 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
140 if ( file_exists( $deps ) ) {
141 include_once( $deps );
143 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
146 # Check if we got if not failback to default skin
147 if ( !MWInit
::classExists( $className ) ) {
148 # DO NOT die if the class isn't found. This breaks maintenance
149 # scripts and can cause a user account to be unrecoverable
150 # except by SQL manipulation if a previously valid skin name
151 # is no longer valid.
152 wfDebug( "Skin class does not exist: $className\n" );
153 $className = 'SkinVector';
154 if ( !defined( 'MW_COMPILED' ) ) {
155 require_once( "{$wgStyleDirectory}/Vector.php" );
159 $skin = new $className( $key );
163 /** @return string skin name */
164 public function getSkinName() {
165 return $this->skinname
;
169 * @param $out OutputPage
171 function initPage( OutputPage
$out ) {
172 wfProfileIn( __METHOD__
);
174 $this->preloadExistence();
176 wfProfileOut( __METHOD__
);
180 * Preload the existence of three commonly-requested pages in a single query
182 function preloadExistence() {
183 $user = $this->getUser();
186 $titles = array( $user->getUserPage(), $user->getTalkPage() );
189 if ( $this->getTitle()->isSpecialPage() ) {
191 } elseif ( $this->getTitle()->isTalkPage() ) {
192 $titles[] = $this->getTitle()->getSubjectPage();
194 $titles[] = $this->getTitle()->getTalkPage();
197 $lb = new LinkBatch( $titles );
198 $lb->setCaller( __METHOD__
);
203 * Get the current revision ID
207 public function getRevisionId() {
208 return $this->getOutput()->getRevisionId();
212 * Whether the revision displayed is the latest revision of the page
216 public function isRevisionCurrent() {
217 $revID = $this->getRevisionId();
218 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
222 * Set the "relevant" title
223 * @see self::getRelevantTitle()
224 * @param $t Title object to use
226 public function setRelevantTitle( $t ) {
227 $this->mRelevantTitle
= $t;
231 * Return the "relevant" title.
232 * A "relevant" title is not necessarily the actual title of the page.
233 * Special pages like Special:MovePage use set the page they are acting on
234 * as their "relevant" title, this allows the skin system to display things
235 * such as content tabs which belong to to that page instead of displaying
236 * a basic special page tab which has almost no meaning.
240 public function getRelevantTitle() {
241 if ( isset($this->mRelevantTitle
) ) {
242 return $this->mRelevantTitle
;
244 return $this->getTitle();
248 * Set the "relevant" user
249 * @see self::getRelevantUser()
250 * @param $u User object to use
252 public function setRelevantUser( $u ) {
253 $this->mRelevantUser
= $u;
257 * Return the "relevant" user.
258 * A "relevant" user is similar to a relevant title. Special pages like
259 * Special:Contributions mark the user which they are relevant to so that
260 * things like the toolbox can display the information they usually are only
261 * able to display on a user's userpage and talkpage.
264 public function getRelevantUser() {
265 if ( isset($this->mRelevantUser
) ) {
266 return $this->mRelevantUser
;
268 $title = $this->getRelevantTitle();
269 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
270 $rootUser = strtok( $title->getText(), '/' );
271 if ( User
::isIP( $rootUser ) ) {
272 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
274 $user = User
::newFromName( $rootUser, false );
275 if ( $user && $user->isLoggedIn() ) {
276 $this->mRelevantUser
= $user;
279 return $this->mRelevantUser
;
285 * Outputs the HTML generated by other functions.
286 * @param $out OutputPage
288 abstract function outputPage( OutputPage
$out = null );
294 static function makeVariablesScript( $data ) {
296 return Html
::inlineScript(
297 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
305 * Get the query to generate a dynamic stylesheet
309 public static function getDynamicStylesheetQuery() {
310 global $wgSquidMaxage;
314 'maxage' => $wgSquidMaxage,
315 'usemsgcache' => 'yes',
316 'ctype' => 'text/css',
317 'smaxage' => $wgSquidMaxage,
322 * Add skin specific stylesheets
323 * Calling this method with an $out of anything but the same OutputPage
324 * inside ->getOutput() is deprecated. The $out arg is kept
325 * for compatibility purposes with skins.
326 * @param $out OutputPage
329 abstract function setupSkinUserCss( OutputPage
$out );
333 * @param $title Title
336 function getPageClasses( $title ) {
337 $numeric = 'ns-' . $title->getNamespace();
339 if ( $title->isSpecialPage() ) {
340 $type = 'ns-special';
341 // bug 23315: provide a class based on the canonical special page name without subpages
342 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
343 if ( $canonicalName ) {
344 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
346 $type .= ' mw-invalidspecialpage';
348 } elseif ( $title->isTalkPage() ) {
351 $type = 'ns-subject';
354 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
356 return "$numeric $type $name";
360 * This will be called by OutputPage::headElement when it is creating the
361 * <body> tag, skins can override it if they have a need to add in any
362 * body attributes or classes of their own.
363 * @param $out OutputPage
364 * @param $bodyAttrs Array
366 function addToBodyAttributes( $out, &$bodyAttrs ) {
367 // does nothing by default
382 function getCategoryLinks() {
383 global $wgUseCategoryBrowser;
385 $out = $this->getOutput();
386 $allCats = $out->getCategoryLinks();
388 if ( !count( $allCats ) ) {
396 $colon = $this->msg( 'colon-separator' )->escaped();
398 if ( !empty( $allCats['normal'] ) ) {
399 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
401 $msg = $this->msg( 'pagecategories', count( $allCats['normal'] ) )->escaped();
402 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
403 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
404 Linker
::link( Title
::newFromText( $linkPage ), $msg )
405 . $colon . '<ul>' . $t . '</ul>' . '</div>';
409 if ( isset( $allCats['hidden'] ) ) {
410 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
411 $class = ' mw-hidden-cats-user-shown';
412 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
413 $class = ' mw-hidden-cats-ns-shown';
415 $class = ' mw-hidden-cats-hidden';
418 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
419 $this->msg( 'hidden-categories', count( $allCats['hidden'] ) )->escaped() .
420 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
424 # optional 'dmoz-like' category browser. Will be shown under the list
425 # of categories an article belong to
426 if ( $wgUseCategoryBrowser ) {
427 $s .= '<br /><hr />';
429 # get a big array of the parents tree
430 $parenttree = $this->getTitle()->getParentCategoryTree();
431 # Skin object passed by reference cause it can not be
432 # accessed under the method subfunction drawCategoryBrowser
433 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
434 # Clean out bogus first entry and sort them
435 unset( $tempout[0] );
437 # Output one per line
438 $s .= implode( "<br />\n", $tempout );
445 * Render the array as a serie of links.
446 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
447 * @return String separated by >, terminate with "\n"
449 function drawCategoryBrowser( $tree ) {
452 foreach ( $tree as $element => $parent ) {
453 if ( empty( $parent ) ) {
454 # element start a new list
457 # grab the others elements
458 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
461 # add our current element to the list
462 $eltitle = Title
::newFromText( $element );
463 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
472 function getCategories() {
473 $out = $this->getOutput();
475 $catlinks = $this->getCategoryLinks();
477 $classes = 'catlinks';
479 // Check what we're showing
480 $allCats = $out->getCategoryLinks();
481 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
482 $this->getTitle()->getNamespace() == NS_CATEGORY
;
484 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
485 $classes .= ' catlinks-allhidden';
488 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
492 * This runs a hook to allow extensions placing their stuff after content
493 * and article metadata (e.g. categories).
494 * Note: This function has nothing to do with afterContent().
496 * This hook is placed here in order to allow using the same hook for all
497 * skins, both the SkinTemplate based ones and the older ones, which directly
498 * use this class to get their data.
500 * The output of this function gets processed in SkinTemplate::outputPage() for
501 * the SkinTemplate based skins, all other skins should directly echo it.
503 * @return String, empty by default, if not changed by any hook function.
505 protected function afterContentHook() {
508 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
509 // adding just some spaces shouldn't toggle the output
510 // of the whole <div/>, so we use trim() here
511 if ( trim( $data ) != '' ) {
512 // Doing this here instead of in the skins to
513 // ensure that the div has the same ID in all
515 $data = "<div id='mw-data-after-content'>\n" .
520 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
527 * Generate debug data HTML for displaying at the bottom of the main content
529 * @return String HTML containing debug data, if enabled (otherwise empty).
531 protected function generateDebugHTML() {
534 if ( $wgShowDebug ) {
535 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext
);
536 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
537 $listInternals . "</ul>\n";
547 private function formatDebugHTML( $debugText ) {
548 global $wgDebugTimestamps;
550 $lines = explode( "\n", $debugText );
554 foreach ( $lines as $line ) {
556 if ( $wgDebugTimestamps ) {
558 if ( preg_match( '/^(\d+\.\d+ {1,3}\d+.\dM\s{2})/', $line, $matches ) ) {
560 $line = substr( $line, strlen( $pre ) );
563 $display = ltrim( $line );
564 $ident = strlen( $line ) - strlen( $display );
565 $diff = $ident - $curIdent;
567 $display = $pre . $display;
568 if ( $display == '' ) {
569 $display = "\xc2\xa0";
572 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
575 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
577 $display = htmlspecialchars( $display );
581 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
582 } elseif ( $diff == 0 ) {
583 $ret .= "</li><li>\n";
585 $ret .= str_repeat( "<ul><li>\n", $diff );
587 $ret .= "<tt>$display</tt>\n";
592 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
598 * This gets called shortly before the </body> tag.
600 * @return String HTML-wrapped JS code to be put before </body>
602 function bottomScripts() {
603 // TODO and the suckage continues. This function is really just a wrapper around
604 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
606 $bottomScriptText = $this->getOutput()->getBottomScripts();
607 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
609 return $bottomScriptText;
613 * Text with the permalink to the source page,
614 * usually shown on the footer of a printed page
616 * @return string HTML text with an URL
618 function printSource() {
619 $oldid = $this->getRevisionId();
621 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
623 // oldid not available for non existing pages
624 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
626 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
632 function getUndeleteLink() {
633 $action = $this->getRequest()->getVal( 'action', 'view' );
635 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
636 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
637 $n = $this->getTitle()->isDeleted();
641 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
642 $msg = 'thisisdeleted';
644 $msg = 'viewdeleted';
647 return $this->msg( $msg )->rawParams(
649 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
650 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
661 function subPageSubtitle() {
662 $out = $this->getOutput();
665 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
669 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
670 $ptext = $this->getTitle()->getPrefixedText();
671 if ( preg_match( '/\//', $ptext ) ) {
672 $links = explode( '/', $ptext );
678 foreach ( $links as $link ) {
679 $growinglink .= $link;
681 $linkObj = Title
::newFromText( $growinglink );
683 if ( is_object( $linkObj ) && $linkObj->exists() ) {
684 $getlink = Linker
::linkKnown(
686 htmlspecialchars( $display )
692 $subpages .= $this->msg( 'pipe-separator' )->escaped();
694 $subpages .= '< ';
697 $subpages .= $getlink;
711 * Returns true if the IP should be shown in the header
714 function showIPinHeader() {
715 global $wgShowIPinHeader;
716 return $wgShowIPinHeader && session_id() != '';
722 function getSearchLink() {
723 $searchPage = SpecialPage
::getTitleFor( 'Search' );
724 return $searchPage->getLocalURL();
730 function escapeSearchLink() {
731 return htmlspecialchars( $this->getSearchLink() );
735 * @param string $type
738 function getCopyright( $type = 'detect' ) {
739 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
741 if ( $type == 'detect' ) {
742 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
749 if ( $type == 'history' ) {
750 $msg = 'history_copyright';
755 if ( $wgRightsPage ) {
756 $title = Title
::newFromText( $wgRightsPage );
757 $link = Linker
::linkKnown( $title, $wgRightsText );
758 } elseif ( $wgRightsUrl ) {
759 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
760 } elseif ( $wgRightsText ) {
761 $link = $wgRightsText;
767 // Allow for site and per-namespace customization of copyright notice.
770 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
772 $msgObj = $this->msg( $msg )->rawParams( $link );
774 $msg = $msgObj->inContentLanguage()->text();
775 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
776 $msg = Html
::rawElement( 'span', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $msg );
780 return $msgObj->text();
785 * @return null|string
787 function getCopyrightIcon() {
788 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
792 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
793 $out = $wgCopyrightIcon;
794 } elseif ( $wgRightsIcon ) {
795 $icon = htmlspecialchars( $wgRightsIcon );
797 if ( $wgRightsUrl ) {
798 $url = htmlspecialchars( $wgRightsUrl );
799 $out .= '<a href="' . $url . '">';
802 $text = htmlspecialchars( $wgRightsText );
803 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
805 if ( $wgRightsUrl ) {
814 * Gets the powered by MediaWiki icon.
817 function getPoweredBy() {
820 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
821 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
822 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
827 * Get the timestamp of the latest revision, formatted in user language
829 * @param $page WikiPage object. Used if we're working with the current revision
832 protected function lastModified( $page ) {
833 if ( !$this->isRevisionCurrent() ) {
834 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
836 $timestamp = $page->getTimestamp();
840 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
841 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
842 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
847 if ( wfGetLB()->getLaggedSlaveMode() ) {
848 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
855 * @param $align string
858 function logoText( $align = '' ) {
859 if ( $align != '' ) {
860 $a = " align='{$align}'";
865 $mp = $this->msg( 'mainpage' )->escaped();
866 $mptitle = Title
::newMainPage();
867 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
869 $logourl = $this->getLogo();
870 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
876 * Renders a $wgFooterIcons icon acording to the method's arguments
877 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
878 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
879 * @return String HTML
881 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
882 if ( is_string( $icon ) ) {
884 } else { // Assuming array
885 $url = isset($icon["url"]) ?
$icon["url"] : null;
886 unset( $icon["url"] );
887 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
888 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
890 $html = htmlspecialchars( $icon["alt"] );
893 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
900 * Gets the link to the wiki's main page.
903 function mainPageLink() {
904 $s = Linker
::linkKnown(
905 Title
::newMainPage(),
906 $this->msg( 'mainpage' )->escaped()
917 public function footerLink( $desc, $page ) {
918 // if the link description has been set to "-" in the default language,
919 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
920 // then it is disabled, for all languages.
923 // Otherwise, we display the link for the user, described in their
924 // language (which may or may not be the same as the default language),
925 // but we make the link target be the one site-wide page.
926 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
928 return Linker
::linkKnown(
930 $this->msg( $desc )->escaped()
936 * Gets the link to the wiki's privacy policy page.
937 * @return String HTML
939 function privacyLink() {
940 return $this->footerLink( 'privacy', 'privacypage' );
944 * Gets the link to the wiki's about page.
945 * @return String HTML
947 function aboutLink() {
948 return $this->footerLink( 'aboutsite', 'aboutpage' );
952 * Gets the link to the wiki's general disclaimers page.
953 * @return String HTML
955 function disclaimerLink() {
956 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
960 * Return URL options for the 'edit page' link.
961 * This may include an 'oldid' specifier, if the current page view is such.
966 function editUrlOptions() {
967 $options = array( 'action' => 'edit' );
969 if ( !$this->isRevisionCurrent() ) {
970 $options['oldid'] = intval( $this->getRevisionId() );
980 function showEmailUser( $id ) {
981 if ( $id instanceof User
) {
984 $targetUser = User
::newFromId( $id );
986 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
987 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
991 * Return a fully resolved style path url to images or styles stored in the common folder.
992 * This method returns a url resolved using the configured skin style path
993 * and includes the style version inside of the url.
994 * @param $name String: The name or path of a skin resource file
995 * @return String The fully resolved style path url including styleversion
997 function getCommonStylePath( $name ) {
998 global $wgStylePath, $wgStyleVersion;
999 return "$wgStylePath/common/$name?$wgStyleVersion";
1003 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1004 * This method returns a url resolved using the configured skin style path
1005 * and includes the style version inside of the url.
1006 * @param $name String: The name or path of a skin resource file
1007 * @return String The fully resolved style path url including styleversion
1009 function getSkinStylePath( $name ) {
1010 global $wgStylePath, $wgStyleVersion;
1011 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1014 /* these are used extensively in SkinTemplate, but also some other places */
1017 * @param $urlaction string
1020 static function makeMainPageUrl( $urlaction = '' ) {
1021 $title = Title
::newMainPage();
1022 self
::checkTitle( $title, '' );
1024 return $title->getLocalURL( $urlaction );
1029 * @param $urlaction string
1032 static function makeSpecialUrl( $name, $urlaction = '' ) {
1033 $title = SpecialPage
::getSafeTitleFor( $name );
1034 return $title->getLocalURL( $urlaction );
1040 * @param $urlaction string
1043 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1044 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1045 return $title->getLocalURL( $urlaction );
1050 * @param $urlaction string
1053 static function makeI18nUrl( $name, $urlaction = '' ) {
1054 $title = Title
::newFromText( wfMsgForContent( $name ) );
1055 self
::checkTitle( $title, $name );
1056 return $title->getLocalURL( $urlaction );
1061 * @param $urlaction string
1064 static function makeUrl( $name, $urlaction = '' ) {
1065 $title = Title
::newFromText( $name );
1066 self
::checkTitle( $title, $name );
1068 return $title->getLocalURL( $urlaction );
1072 * If url string starts with http, consider as external URL, else
1074 * @param $name String
1075 * @return String URL
1077 static function makeInternalOrExternalUrl( $name ) {
1078 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1081 return self
::makeUrl( $name );
1086 * this can be passed the NS number as defined in Language.php
1088 * @param $urlaction string
1089 * @param $namespace int
1092 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1093 $title = Title
::makeTitleSafe( $namespace, $name );
1094 self
::checkTitle( $title, $name );
1096 return $title->getLocalURL( $urlaction );
1100 * these return an array with the 'href' and boolean 'exists'
1102 * @param $urlaction string
1105 static function makeUrlDetails( $name, $urlaction = '' ) {
1106 $title = Title
::newFromText( $name );
1107 self
::checkTitle( $title, $name );
1110 'href' => $title->getLocalURL( $urlaction ),
1111 'exists' => $title->getArticleID() != 0,
1116 * Make URL details where the article exists (or at least it's convenient to think so)
1117 * @param $name String Article name
1118 * @param $urlaction String
1121 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1122 $title = Title
::newFromText( $name );
1123 self
::checkTitle( $title, $name );
1126 'href' => $title->getLocalURL( $urlaction ),
1132 * make sure we have some title to operate on
1134 * @param $title Title
1137 static function checkTitle( &$title, $name ) {
1138 if ( !is_object( $title ) ) {
1139 $title = Title
::newFromText( $name );
1140 if ( !is_object( $title ) ) {
1141 $title = Title
::newFromText( '--error: link target missing--' );
1147 * Build an array that represents the sidebar(s), the navigation bar among them
1151 function buildSidebar() {
1152 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1153 wfProfileIn( __METHOD__
);
1155 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1157 if ( $wgEnableSidebarCache ) {
1158 $cachedsidebar = $parserMemc->get( $key );
1159 if ( $cachedsidebar ) {
1160 wfProfileOut( __METHOD__
);
1161 return $cachedsidebar;
1166 $this->addToSidebar( $bar, 'sidebar' );
1168 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1169 if ( $wgEnableSidebarCache ) {
1170 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1173 wfProfileOut( __METHOD__
);
1177 * Add content from a sidebar system message
1178 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1180 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1183 * @param $message String
1185 function addToSidebar( &$bar, $message ) {
1186 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1190 * Add content from plain text
1193 * @param $text string
1196 function addToSidebarPlain( &$bar, $text ) {
1197 $lines = explode( "\n", $text );
1201 foreach ( $lines as $line ) {
1202 if ( strpos( $line, '*' ) !== 0 ) {
1205 $line = rtrim( $line, "\r" ); // for Windows compat
1207 if ( strpos( $line, '**' ) !== 0 ) {
1208 $heading = trim( $line, '* ' );
1209 if ( !array_key_exists( $heading, $bar ) ) {
1210 $bar[$heading] = array();
1213 $line = trim( $line, '* ' );
1215 if ( strpos( $line, '|' ) !== false ) { // sanity check
1216 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1217 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1218 $extraAttribs = array();
1220 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1221 if ( $msgLink->exists() ) {
1222 $link = $msgLink->text();
1223 if ( $link == '-' ) {
1230 $msgText = $this->msg( $line[1] );
1231 if ( $msgText->exists() ) {
1232 $text = $msgText->text();
1237 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1240 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1241 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1242 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1243 $extraAttribs['rel'] = 'nofollow';
1246 global $wgExternalLinkTarget;
1247 if ( $wgExternalLinkTarget) {
1248 $extraAttribs['target'] = $wgExternalLinkTarget;
1251 $title = Title
::newFromText( $link );
1254 $title = $title->fixSpecialName();
1255 $href = $title->getLinkURL();
1257 $href = 'INVALID-TITLE';
1261 $bar[$heading][] = array_merge( array(
1264 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1277 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1278 * print stylesheet should override this and return false. (This is an
1279 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1283 public function commonPrintStylesheet() {
1288 * Gets new talk page messages for the current user.
1289 * @return MediaWiki message or if no new talk page messages, nothing
1291 function getNewtalks() {
1292 $out = $this->getOutput();
1294 $newtalks = $this->getUser()->getNewMessageLinks();
1297 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1298 $userTitle = $this->getUser()->getUserPage();
1299 $userTalkTitle = $userTitle->getTalkPage();
1301 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1302 $newMessagesLink = Linker
::linkKnown(
1304 $this->msg( 'newmessageslink' )->escaped(),
1306 array( 'redirect' => 'no' )
1309 $newMessagesDiffLink = Linker
::linkKnown(
1311 $this->msg( 'newmessagesdifflink' )->escaped(),
1313 array( 'diff' => 'cur' )
1317 'youhavenewmessages',
1319 $newMessagesDiffLink
1321 # Disable Squid cache
1322 $out->setSquidMaxage( 0 );
1324 } elseif ( count( $newtalks ) ) {
1325 // _>" " for BC <= 1.16
1326 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1329 foreach ( $newtalks as $newtalk ) {
1330 $msgs[] = Xml
::element(
1332 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1335 $parts = implode( $sep, $msgs );
1336 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1337 $out->setSquidMaxage( 0 );
1344 * Get a cached notice
1346 * @param $name String: message name, or 'default' for $wgSiteNotice
1347 * @return String: HTML fragment
1349 private function getCachedNotice( $name ) {
1350 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1352 wfProfileIn( __METHOD__
);
1356 if( $name === 'default' ) {
1358 global $wgSiteNotice;
1359 $notice = $wgSiteNotice;
1360 if( empty( $notice ) ) {
1361 wfProfileOut( __METHOD__
);
1365 $msg = $this->msg( $name )->inContentLanguage();
1366 if( $msg->isDisabled() ) {
1367 wfProfileOut( __METHOD__
);
1370 $notice = $msg->plain();
1373 // Use the extra hash appender to let eg SSL variants separately cache.
1374 $key = wfMemcKey( $name . $wgRenderHashAppend );
1375 $cachedNotice = $parserMemc->get( $key );
1376 if( is_array( $cachedNotice ) ) {
1377 if( md5( $notice ) == $cachedNotice['hash'] ) {
1378 $notice = $cachedNotice['html'];
1387 $parsed = $this->getOutput()->parse( $notice );
1388 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1392 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1393 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $notice );
1394 wfProfileOut( __METHOD__
);
1399 * Get a notice based on page's namespace
1401 * @return String: HTML fragment
1403 function getNamespaceNotice() {
1404 wfProfileIn( __METHOD__
);
1406 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1407 $namespaceNotice = $this->getCachedNotice( $key );
1408 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1409 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1411 $namespaceNotice = '';
1414 wfProfileOut( __METHOD__
);
1415 return $namespaceNotice;
1419 * Get the site notice
1421 * @return String: HTML fragment
1423 function getSiteNotice() {
1424 wfProfileIn( __METHOD__
);
1427 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1428 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1429 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1431 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1432 if ( !$anonNotice ) {
1433 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1435 $siteNotice = $anonNotice;
1438 if ( !$siteNotice ) {
1439 $siteNotice = $this->getCachedNotice( 'default' );
1443 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1444 wfProfileOut( __METHOD__
);
1449 * Create a section edit link. This supersedes editSectionLink() and
1450 * editSectionLinkForOther().
1452 * @param $nt Title The title being linked to (may not be the same as
1453 * $wgTitle, if the section is included from a template)
1454 * @param $section string The designation of the section being pointed to,
1455 * to be included in the link, like "§ion=$section"
1456 * @param $tooltip string The tooltip to use for the link: will be escaped
1457 * and wrapped in the 'editsectionhint' message
1458 * @param $lang string Language code
1459 * @return string HTML to use for edit link
1461 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1462 // HTML generated here should probably have userlangattributes
1463 // added to it for LTR text on RTL pages
1465 if ( !is_null( $tooltip ) ) {
1466 # Bug 25462: undo double-escaping.
1467 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1468 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1470 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1472 array( 'action' => 'edit', 'section' => $section ),
1473 array( 'noclasses', 'known' )
1476 # Run the old hook. This takes up half of the function . . . hopefully
1477 # we can rid of it someday.
1480 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1481 $attribs = " title=\"$attribs\"";
1484 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1485 if ( !is_null( $result ) ) {
1486 # For reverse compatibility, add the brackets *after* the hook is
1487 # run, and even add them to hook-provided text. (This is the main
1488 # reason that the EditSectionLink hook is deprecated in favor of
1489 # DoEditSectionLink: it can't change the brackets or the span.)
1490 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1491 return "<span class=\"editsection\">$result</span>";
1494 # Add the brackets and the span, and *then* run the nice new hook, with
1495 # clean and non-redundant arguments.
1496 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1497 $result = "<span class=\"editsection\">$result</span>";
1499 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1504 * Use PHP's magic __call handler to intercept legacy calls to the linker
1505 * for backwards compatibility.
1507 * @param $fname String Name of called method
1508 * @param $args Array Arguments to the method
1510 function __call( $fname, $args ) {
1511 $realFunction = array( 'Linker', $fname );
1512 if ( is_callable( $realFunction ) ) {
1513 return call_user_func_array( $realFunction, $args );
1515 $className = get_class( $this );
1516 throw new MWException( "Call to undefined method $className::$fname" );