96566d788955e30aaa3c7c7c724f449877f29948
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
;
168 function initPage( OutputPage
$out ) {
169 wfProfileIn( __METHOD__
);
171 $this->preloadExistence();
173 wfProfileOut( __METHOD__
);
177 * Preload the existence of three commonly-requested pages in a single query
179 function preloadExistence() {
180 $user = $this->getUser();
183 $titles = array( $user->getUserPage(), $user->getTalkPage() );
186 if ( $this->getTitle()->isSpecialPage() ) {
188 } elseif ( $this->getTitle()->isTalkPage() ) {
189 $titles[] = $this->getTitle()->getSubjectPage();
191 $titles[] = $this->getTitle()->getTalkPage();
194 $lb = new LinkBatch( $titles );
195 $lb->setCaller( __METHOD__
);
200 * Get the current revision ID
204 public function getRevisionId() {
205 return $this->getOutput()->getRevisionId();
209 * Whether the revision displayed is the latest revision of the page
213 public function isRevisionCurrent() {
214 $revID = $this->getRevisionId();
215 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
219 * Set the "relevant" title
220 * @see self::getRelevantTitle()
221 * @param $t Title object to use
223 public function setRelevantTitle( $t ) {
224 $this->mRelevantTitle
= $t;
228 * Return the "relevant" title.
229 * A "relevant" title is not necessarily the actual title of the page.
230 * Special pages like Special:MovePage use set the page they are acting on
231 * as their "relevant" title, this allows the skin system to display things
232 * such as content tabs which belong to to that page instead of displaying
233 * a basic special page tab which has almost no meaning.
237 public function getRelevantTitle() {
238 if ( isset($this->mRelevantTitle
) ) {
239 return $this->mRelevantTitle
;
241 return $this->getTitle();
245 * Set the "relevant" user
246 * @see self::getRelevantUser()
247 * @param $u User object to use
249 public function setRelevantUser( $u ) {
250 $this->mRelevantUser
= $u;
254 * Return the "relevant" user.
255 * A "relevant" user is similar to a relevant title. Special pages like
256 * Special:Contributions mark the user which they are relevant to so that
257 * things like the toolbox can display the information they usually are only
258 * able to display on a user's userpage and talkpage.
261 public function getRelevantUser() {
262 if ( isset($this->mRelevantUser
) ) {
263 return $this->mRelevantUser
;
265 $title = $this->getRelevantTitle();
266 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
267 $rootUser = strtok( $title->getText(), '/' );
268 if ( User
::isIP( $rootUser ) ) {
269 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
271 $user = User
::newFromName( $rootUser, false );
272 if ( $user->isLoggedIn() ) {
273 $this->mRelevantUser
= $user;
276 return $this->mRelevantUser
;
282 * Outputs the HTML generated by other functions.
283 * @param $out OutputPage
285 abstract function outputPage( OutputPage
$out = null );
287 static function makeVariablesScript( $data ) {
289 return Html
::inlineScript(
290 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
298 * Get the query to generate a dynamic stylesheet
302 public static function getDynamicStylesheetQuery() {
303 global $wgSquidMaxage;
307 'maxage' => $wgSquidMaxage,
308 'usemsgcache' => 'yes',
309 'ctype' => 'text/css',
310 'smaxage' => $wgSquidMaxage,
315 * Add skin specific stylesheets
316 * Calling this method with an $out of anything but the same OutputPage
317 * inside ->getOutput() is deprecated. The $out arg is kept
318 * for compatibility purposes with skins.
319 * @param $out OutputPage
322 abstract function setupSkinUserCss( OutputPage
$out );
326 * @param $title Title
329 function getPageClasses( $title ) {
330 $numeric = 'ns-' . $title->getNamespace();
332 if ( $title->isSpecialPage() ) {
333 $type = 'ns-special';
334 // bug 23315: provide a class based on the canonical special page name without subpages
335 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
336 if ( $canonicalName ) {
337 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
339 $type .= ' mw-invalidspecialpage';
341 } elseif ( $title->isTalkPage() ) {
344 $type = 'ns-subject';
347 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
349 return "$numeric $type $name";
353 * This will be called by OutputPage::headElement when it is creating the
354 * <body> tag, skins can override it if they have a need to add in any
355 * body attributes or classes of their own.
356 * @param $out OutputPage
357 * @param $bodyAttrs Array
359 function addToBodyAttributes( $out, &$bodyAttrs ) {
360 // does nothing by default
372 function getCategoryLinks() {
373 global $wgUseCategoryBrowser;
375 $out = $this->getOutput();
376 $allCats = $out->getCategoryLinks();
378 if ( !count( $allCats ) ) {
386 $colon = $this->msg( 'colon-separator' )->escaped();
388 if ( !empty( $allCats['normal'] ) ) {
389 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
391 $msg = $this->msg( 'pagecategories', count( $allCats['normal'] ) )->escaped();
392 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
393 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
394 Linker
::link( Title
::newFromText( $linkPage ), $msg )
395 . $colon . '<ul>' . $t . '</ul>' . '</div>';
399 if ( isset( $allCats['hidden'] ) ) {
400 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
401 $class = ' mw-hidden-cats-user-shown';
402 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
403 $class = ' mw-hidden-cats-ns-shown';
405 $class = ' mw-hidden-cats-hidden';
408 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
409 $this->msg( 'hidden-categories', count( $allCats['hidden'] ) )->escaped() .
410 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
414 # optional 'dmoz-like' category browser. Will be shown under the list
415 # of categories an article belong to
416 if ( $wgUseCategoryBrowser ) {
417 $s .= '<br /><hr />';
419 # get a big array of the parents tree
420 $parenttree = $this->getTitle()->getParentCategoryTree();
421 # Skin object passed by reference cause it can not be
422 # accessed under the method subfunction drawCategoryBrowser
423 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
424 # Clean out bogus first entry and sort them
425 unset( $tempout[0] );
427 # Output one per line
428 $s .= implode( "<br />\n", $tempout );
435 * Render the array as a serie of links.
436 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
437 * @return String separated by >, terminate with "\n"
439 function drawCategoryBrowser( $tree ) {
442 foreach ( $tree as $element => $parent ) {
443 if ( empty( $parent ) ) {
444 # element start a new list
447 # grab the others elements
448 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
451 # add our current element to the list
452 $eltitle = Title
::newFromText( $element );
453 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
459 function getCategories() {
460 $out = $this->getOutput();
462 $catlinks = $this->getCategoryLinks();
464 $classes = 'catlinks';
466 // Check what we're showing
467 $allCats = $out->getCategoryLinks();
468 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
469 $this->getTitle()->getNamespace() == NS_CATEGORY
;
471 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
472 $classes .= ' catlinks-allhidden';
475 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
479 * This runs a hook to allow extensions placing their stuff after content
480 * and article metadata (e.g. categories).
481 * Note: This function has nothing to do with afterContent().
483 * This hook is placed here in order to allow using the same hook for all
484 * skins, both the SkinTemplate based ones and the older ones, which directly
485 * use this class to get their data.
487 * The output of this function gets processed in SkinTemplate::outputPage() for
488 * the SkinTemplate based skins, all other skins should directly echo it.
490 * @return String, empty by default, if not changed by any hook function.
492 protected function afterContentHook() {
495 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
496 // adding just some spaces shouldn't toggle the output
497 // of the whole <div/>, so we use trim() here
498 if ( trim( $data ) != '' ) {
499 // Doing this here instead of in the skins to
500 // ensure that the div has the same ID in all
502 $data = "<div id='mw-data-after-content'>\n" .
507 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
514 * Generate debug data HTML for displaying at the bottom of the main content
516 * @return String HTML containing debug data, if enabled (otherwise empty).
518 protected function generateDebugHTML() {
521 if ( $wgShowDebug ) {
522 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext
);
523 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
524 $listInternals . "</ul>\n";
530 private function formatDebugHTML( $debugText ) {
531 global $wgDebugTimestamps;
533 $lines = explode( "\n", $debugText );
537 foreach ( $lines as $line ) {
539 if ( $wgDebugTimestamps ) {
541 if ( preg_match( '/^(\d+\.\d+ \d+.\dM\s{2})/', $line, $matches ) ) {
543 $line = substr( $line, strlen( $pre ) );
546 $display = ltrim( $line );
547 $ident = strlen( $line ) - strlen( $display );
548 $diff = $ident - $curIdent;
550 $display = $pre . $display;
551 if ( $display == '' ) {
552 $display = "\xc2\xa0";
555 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
558 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
560 $display = htmlspecialchars( $display );
564 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
565 } elseif ( $diff == 0 ) {
566 $ret .= "</li><li>\n";
568 $ret .= str_repeat( "<ul><li>\n", $diff );
570 $ret .= "<tt>$display</tt>\n";
575 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
581 * This gets called shortly before the </body> tag.
583 * @return String HTML-wrapped JS code to be put before </body>
585 function bottomScripts() {
586 // TODO and the suckage continues. This function is really just a wrapper around
587 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
589 $bottomScriptText = $this->getOutput()->getBottomScripts();
590 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
592 return $bottomScriptText;
596 * Text with the permalink to the source page,
597 * usually shown on the footer of a printed page
599 * @return string HTML text with an URL
601 function printSource() {
602 $oldid = $this->getRevisionId();
604 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
606 // oldid not available for non existing pages
607 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
609 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
612 function getUndeleteLink() {
613 $action = $this->getRequest()->getVal( 'action', 'view' );
615 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
616 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
617 $n = $this->getTitle()->isDeleted();
621 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
622 $msg = 'thisisdeleted';
624 $msg = 'viewdeleted';
627 return $this->msg( $msg )->rawParams(
629 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
630 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
638 function subPageSubtitle() {
639 $out = $this->getOutput();
642 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
646 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
647 $ptext = $this->getTitle()->getPrefixedText();
648 if ( preg_match( '/\//', $ptext ) ) {
649 $links = explode( '/', $ptext );
655 foreach ( $links as $link ) {
656 $growinglink .= $link;
658 $linkObj = Title
::newFromText( $growinglink );
660 if ( is_object( $linkObj ) && $linkObj->exists() ) {
661 $getlink = Linker
::linkKnown(
663 htmlspecialchars( $display )
669 $subpages .= $this->msg( 'pipe-separator' )->escaped();
671 $subpages .= '< ';
674 $subpages .= $getlink;
688 * Returns true if the IP should be shown in the header
691 function showIPinHeader() {
692 global $wgShowIPinHeader;
693 return $wgShowIPinHeader && session_id() != '';
696 function getSearchLink() {
697 $searchPage = SpecialPage
::getTitleFor( 'Search' );
698 return $searchPage->getLocalURL();
701 function escapeSearchLink() {
702 return htmlspecialchars( $this->getSearchLink() );
705 function getCopyright( $type = 'detect' ) {
706 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
708 if ( $type == 'detect' ) {
709 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
716 if ( $type == 'history' ) {
717 $msg = 'history_copyright';
722 if ( $wgRightsPage ) {
723 $title = Title
::newFromText( $wgRightsPage );
724 $link = Linker
::linkKnown( $title, $wgRightsText );
725 } elseif ( $wgRightsUrl ) {
726 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
727 } elseif ( $wgRightsText ) {
728 $link = $wgRightsText;
734 // Allow for site and per-namespace customization of copyright notice.
737 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
739 $msgObj = $this->msg( $msg )->rawParams( $link );
741 $msg = $msgObj->inContentLanguage()->text();
742 if ( $this->getLang()->getCode() !== $wgContLang->getCode() ) {
743 $msg = Html
::rawElement( 'span', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $msg );
747 return $msgObj->text();
751 function getCopyrightIcon() {
752 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
756 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
757 $out = $wgCopyrightIcon;
758 } elseif ( $wgRightsIcon ) {
759 $icon = htmlspecialchars( $wgRightsIcon );
761 if ( $wgRightsUrl ) {
762 $url = htmlspecialchars( $wgRightsUrl );
763 $out .= '<a href="' . $url . '">';
766 $text = htmlspecialchars( $wgRightsText );
767 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
769 if ( $wgRightsUrl ) {
778 * Gets the powered by MediaWiki icon.
781 function getPoweredBy() {
784 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
785 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
786 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
791 * Get the timestamp of the latest revision, formatted in user language
793 * @param $article Article object. Used if we're working with the current revision
796 protected function lastModified( $article ) {
797 if ( !$this->isRevisionCurrent() ) {
798 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
800 $timestamp = $article->getTimestamp();
804 $d = $this->getLang()->userDate( $timestamp, $this->getUser() );
805 $t = $this->getLang()->userTime( $timestamp, $this->getUser() );
806 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
811 if ( wfGetLB()->getLaggedSlaveMode() ) {
812 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
818 function logoText( $align = '' ) {
819 if ( $align != '' ) {
820 $a = " align='{$align}'";
825 $mp = $this->msg( 'mainpage' )->escaped();
826 $mptitle = Title
::newMainPage();
827 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
829 $logourl = $this->getLogo();
830 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
836 * Renders a $wgFooterIcons icon acording to the method's arguments
837 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
838 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
839 * @return String HTML
841 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
842 if ( is_string( $icon ) ) {
844 } else { // Assuming array
845 $url = isset($icon["url"]) ?
$icon["url"] : null;
846 unset( $icon["url"] );
847 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
848 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
850 $html = htmlspecialchars( $icon["alt"] );
853 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
860 * Gets the link to the wiki's main page.
863 function mainPageLink() {
864 $s = Linker
::linkKnown(
865 Title
::newMainPage(),
866 $this->msg( 'mainpage' )->escaped()
872 public function footerLink( $desc, $page ) {
873 // if the link description has been set to "-" in the default language,
874 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
875 // then it is disabled, for all languages.
878 // Otherwise, we display the link for the user, described in their
879 // language (which may or may not be the same as the default language),
880 // but we make the link target be the one site-wide page.
881 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
883 return Linker
::linkKnown(
885 $this->msg( $desc )->escaped()
891 * Gets the link to the wiki's privacy policy page.
892 * @return String HTML
894 function privacyLink() {
895 return $this->footerLink( 'privacy', 'privacypage' );
899 * Gets the link to the wiki's about page.
900 * @return String HTML
902 function aboutLink() {
903 return $this->footerLink( 'aboutsite', 'aboutpage' );
907 * Gets the link to the wiki's general disclaimers page.
908 * @return String HTML
910 function disclaimerLink() {
911 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
915 * Return URL options for the 'edit page' link.
916 * This may include an 'oldid' specifier, if the current page view is such.
921 function editUrlOptions() {
922 $options = array( 'action' => 'edit' );
924 if ( !$this->isRevisionCurrent() ) {
925 $options['oldid'] = intval( $this->getRevisionId() );
931 function showEmailUser( $id ) {
932 if ( $id instanceof User
) {
935 $targetUser = User
::newFromId( $id );
937 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
938 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
942 * Return a fully resolved style path url to images or styles stored in the common folder.
943 * This method returns a url resolved using the configured skin style path
944 * and includes the style version inside of the url.
945 * @param $name String: The name or path of a skin resource file
946 * @return String The fully resolved style path url including styleversion
948 function getCommonStylePath( $name ) {
949 global $wgStylePath, $wgStyleVersion;
950 return "$wgStylePath/common/$name?$wgStyleVersion";
954 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
955 * This method returns a url resolved using the configured skin style path
956 * and includes the style version inside of the url.
957 * @param $name String: The name or path of a skin resource file
958 * @return String The fully resolved style path url including styleversion
960 function getSkinStylePath( $name ) {
961 global $wgStylePath, $wgStyleVersion;
962 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
965 /* these are used extensively in SkinTemplate, but also some other places */
966 static function makeMainPageUrl( $urlaction = '' ) {
967 $title = Title
::newMainPage();
968 self
::checkTitle( $title, '' );
970 return $title->getLocalURL( $urlaction );
973 static function makeSpecialUrl( $name, $urlaction = '' ) {
974 $title = SpecialPage
::getSafeTitleFor( $name );
975 return $title->getLocalURL( $urlaction );
978 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
979 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
980 return $title->getLocalURL( $urlaction );
983 static function makeI18nUrl( $name, $urlaction = '' ) {
984 $title = Title
::newFromText( wfMsgForContent( $name ) );
985 self
::checkTitle( $title, $name );
986 return $title->getLocalURL( $urlaction );
989 static function makeUrl( $name, $urlaction = '' ) {
990 $title = Title
::newFromText( $name );
991 self
::checkTitle( $title, $name );
993 return $title->getLocalURL( $urlaction );
997 * If url string starts with http, consider as external URL, else
999 * @param $name String
1000 * @return String URL
1002 static function makeInternalOrExternalUrl( $name ) {
1003 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1006 return self
::makeUrl( $name );
1010 # this can be passed the NS number as defined in Language.php
1011 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1012 $title = Title
::makeTitleSafe( $namespace, $name );
1013 self
::checkTitle( $title, $name );
1015 return $title->getLocalURL( $urlaction );
1018 /* these return an array with the 'href' and boolean 'exists' */
1019 static function makeUrlDetails( $name, $urlaction = '' ) {
1020 $title = Title
::newFromText( $name );
1021 self
::checkTitle( $title, $name );
1024 'href' => $title->getLocalURL( $urlaction ),
1025 'exists' => $title->getArticleID() != 0,
1030 * Make URL details where the article exists (or at least it's convenient to think so)
1031 * @param $name String Article name
1032 * @param $urlaction String
1035 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1036 $title = Title
::newFromText( $name );
1037 self
::checkTitle( $title, $name );
1040 'href' => $title->getLocalURL( $urlaction ),
1045 # make sure we have some title to operate on
1046 static function checkTitle( &$title, $name ) {
1047 if ( !is_object( $title ) ) {
1048 $title = Title
::newFromText( $name );
1049 if ( !is_object( $title ) ) {
1050 $title = Title
::newFromText( '--error: link target missing--' );
1056 * Build an array that represents the sidebar(s), the navigation bar among them
1060 function buildSidebar() {
1061 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1062 wfProfileIn( __METHOD__
);
1064 $key = wfMemcKey( 'sidebar', $this->getLang()->getCode() );
1066 if ( $wgEnableSidebarCache ) {
1067 $cachedsidebar = $parserMemc->get( $key );
1068 if ( $cachedsidebar ) {
1069 wfProfileOut( __METHOD__
);
1070 return $cachedsidebar;
1075 $this->addToSidebar( $bar, 'sidebar' );
1077 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1078 if ( $wgEnableSidebarCache ) {
1079 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1082 wfProfileOut( __METHOD__
);
1086 * Add content from a sidebar system message
1087 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1089 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1091 * @param &$bar array
1092 * @param $message String
1094 function addToSidebar( &$bar, $message ) {
1095 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1099 * Add content from plain text
1101 * @param &$bar array
1102 * @param $text string
1105 function addToSidebarPlain( &$bar, $text ) {
1106 $lines = explode( "\n", $text );
1110 foreach ( $lines as $line ) {
1111 if ( strpos( $line, '*' ) !== 0 ) {
1114 $line = rtrim( $line, "\r" ); // for Windows compat
1116 if ( strpos( $line, '**' ) !== 0 ) {
1117 $heading = trim( $line, '* ' );
1118 if ( !array_key_exists( $heading, $bar ) ) {
1119 $bar[$heading] = array();
1122 $line = trim( $line, '* ' );
1124 if ( strpos( $line, '|' ) !== false ) { // sanity check
1125 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1126 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1127 $extraAttribs = array();
1129 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1130 if ( $msgLink->exists() ) {
1131 $link = $msgLink->text();
1132 if ( $link == '-' ) {
1139 $msgText = $this->msg( $line[1] );
1140 if ( $msgText->exists() ) {
1141 $text = $msgText->text();
1146 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1149 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1150 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1151 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1152 $extraAttribs['rel'] = 'nofollow';
1155 global $wgExternalLinkTarget;
1156 if ( $wgExternalLinkTarget) {
1157 $extraAttribs['target'] = $wgExternalLinkTarget;
1160 $title = Title
::newFromText( $link );
1163 $title = $title->fixSpecialName();
1164 $href = $title->getLinkURL();
1166 $href = 'INVALID-TITLE';
1170 $bar[$heading][] = array_merge( array(
1173 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1186 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1187 * print stylesheet should override this and return false. (This is an
1188 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1192 public function commonPrintStylesheet() {
1197 * Gets new talk page messages for the current user.
1198 * @return MediaWiki message or if no new talk page messages, nothing
1200 function getNewtalks() {
1201 $out = $this->getOutput();
1203 $newtalks = $this->getUser()->getNewMessageLinks();
1206 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1207 $userTitle = $this->getUser()->getUserPage();
1208 $userTalkTitle = $userTitle->getTalkPage();
1210 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1211 $newMessagesLink = Linker
::linkKnown(
1213 $this->msg( 'newmessageslink' )->escaped(),
1215 array( 'redirect' => 'no' )
1218 $newMessagesDiffLink = Linker
::linkKnown(
1220 $this->msg( 'newmessagesdifflink' )->escaped(),
1222 array( 'diff' => 'cur' )
1226 'youhavenewmessages',
1228 $newMessagesDiffLink
1230 # Disable Squid cache
1231 $out->setSquidMaxage( 0 );
1233 } elseif ( count( $newtalks ) ) {
1234 // _>" " for BC <= 1.16
1235 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1238 foreach ( $newtalks as $newtalk ) {
1239 $msgs[] = Xml
::element(
1241 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1244 $parts = implode( $sep, $msgs );
1245 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1246 $out->setSquidMaxage( 0 );
1253 * Get a cached notice
1255 * @param $name String: message name, or 'default' for $wgSiteNotice
1256 * @return String: HTML fragment
1258 private function getCachedNotice( $name ) {
1259 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1261 wfProfileIn( __METHOD__
);
1265 if( $name === 'default' ) {
1267 global $wgSiteNotice;
1268 $notice = $wgSiteNotice;
1269 if( empty( $notice ) ) {
1270 wfProfileOut( __METHOD__
);
1274 $msg = $this->msg( $name )->inContentLanguage();
1275 if( $msg->isDisabled() ) {
1276 wfProfileOut( __METHOD__
);
1279 $notice = $msg->plain();
1282 // Use the extra hash appender to let eg SSL variants separately cache.
1283 $key = wfMemcKey( $name . $wgRenderHashAppend );
1284 $cachedNotice = $parserMemc->get( $key );
1285 if( is_array( $cachedNotice ) ) {
1286 if( md5( $notice ) == $cachedNotice['hash'] ) {
1287 $notice = $cachedNotice['html'];
1296 $parsed = $this->getOutput()->parse( $notice );
1297 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1301 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1302 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $notice );
1303 wfProfileOut( __METHOD__
);
1308 * Get a notice based on page's namespace
1310 * @return String: HTML fragment
1312 function getNamespaceNotice() {
1313 wfProfileIn( __METHOD__
);
1315 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1316 $namespaceNotice = $this->getCachedNotice( $key );
1317 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1318 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1320 $namespaceNotice = '';
1323 wfProfileOut( __METHOD__
);
1324 return $namespaceNotice;
1328 * Get the site notice
1330 * @return String: HTML fragment
1332 function getSiteNotice() {
1333 wfProfileIn( __METHOD__
);
1336 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1337 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1338 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1340 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1341 if ( !$anonNotice ) {
1342 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1344 $siteNotice = $anonNotice;
1347 if ( !$siteNotice ) {
1348 $siteNotice = $this->getCachedNotice( 'default' );
1352 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1353 wfProfileOut( __METHOD__
);
1358 * Create a section edit link. This supersedes editSectionLink() and
1359 * editSectionLinkForOther().
1361 * @param $nt Title The title being linked to (may not be the same as
1362 * $wgTitle, if the section is included from a template)
1363 * @param $section string The designation of the section being pointed to,
1364 * to be included in the link, like "§ion=$section"
1365 * @param $tooltip string The tooltip to use for the link: will be escaped
1366 * and wrapped in the 'editsectionhint' message
1367 * @param $lang string Language code
1368 * @return string HTML to use for edit link
1370 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1371 // HTML generated here should probably have userlangattributes
1372 // added to it for LTR text on RTL pages
1374 if ( !is_null( $tooltip ) ) {
1375 # Bug 25462: undo double-escaping.
1376 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1377 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1379 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1381 array( 'action' => 'edit', 'section' => $section ),
1382 array( 'noclasses', 'known' )
1385 # Run the old hook. This takes up half of the function . . . hopefully
1386 # we can rid of it someday.
1389 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1390 $attribs = " title=\"$attribs\"";
1393 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1394 if ( !is_null( $result ) ) {
1395 # For reverse compatibility, add the brackets *after* the hook is
1396 # run, and even add them to hook-provided text. (This is the main
1397 # reason that the EditSectionLink hook is deprecated in favor of
1398 # DoEditSectionLink: it can't change the brackets or the span.)
1399 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1400 return "<span class=\"editsection\">$result</span>";
1403 # Add the brackets and the span, and *then* run the nice new hook, with
1404 # clean and non-redundant arguments.
1405 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1406 $result = "<span class=\"editsection\">$result</span>";
1408 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1413 * Use PHP's magic __call handler to intercept legacy calls to the linker
1414 * for backwards compatibility.
1416 * @param $fname String Name of called method
1417 * @param $args Array Arguments to the method
1419 function __call( $fname, $args ) {
1420 $realFunction = array( 'Linker', $fname );
1421 if ( is_callable( $realFunction ) ) {
1422 return call_user_func_array( $realFunction, $args );
1424 $className = get_class( $this );
1425 throw new MWException( "Call to undefined method $className::$fname" );