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 * Make a <script> tag containing global variables
307 * @deprecated in 1.19
308 * @param $unused Unused
309 * @return string HTML fragment
311 public static function makeGlobalVariablesScript( $unused ) {
314 wfDeprecated( __METHOD__
, '1.19' );
316 return self
::makeVariablesScript( $wgOut->getJSVars() );
320 * Get the query to generate a dynamic stylesheet
324 public static function getDynamicStylesheetQuery() {
325 global $wgSquidMaxage;
329 'maxage' => $wgSquidMaxage,
330 'usemsgcache' => 'yes',
331 'ctype' => 'text/css',
332 'smaxage' => $wgSquidMaxage,
337 * Add skin specific stylesheets
338 * Calling this method with an $out of anything but the same OutputPage
339 * inside ->getOutput() is deprecated. The $out arg is kept
340 * for compatibility purposes with skins.
341 * @param $out OutputPage
344 abstract function setupSkinUserCss( OutputPage
$out );
348 * @param $title Title
351 function getPageClasses( $title ) {
352 $numeric = 'ns-' . $title->getNamespace();
354 if ( $title->isSpecialPage() ) {
355 $type = 'ns-special';
356 // bug 23315: provide a class based on the canonical special page name without subpages
357 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
358 if ( $canonicalName ) {
359 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
361 $type .= ' mw-invalidspecialpage';
363 } elseif ( $title->isTalkPage() ) {
366 $type = 'ns-subject';
369 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
371 return "$numeric $type $name";
375 * This will be called by OutputPage::headElement when it is creating the
376 * <body> tag, skins can override it if they have a need to add in any
377 * body attributes or classes of their own.
378 * @param $out OutputPage
379 * @param $bodyAttrs Array
381 function addToBodyAttributes( $out, &$bodyAttrs ) {
382 // does nothing by default
397 function getCategoryLinks() {
398 global $wgUseCategoryBrowser;
400 $out = $this->getOutput();
401 $allCats = $out->getCategoryLinks();
403 if ( !count( $allCats ) ) {
411 $colon = $this->msg( 'colon-separator' )->escaped();
413 if ( !empty( $allCats['normal'] ) ) {
414 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
416 $msg = $this->msg( 'pagecategories', count( $allCats['normal'] ) )->escaped();
417 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
418 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
419 Linker
::link( Title
::newFromText( $linkPage ), $msg )
420 . $colon . '<ul>' . $t . '</ul>' . '</div>';
424 if ( isset( $allCats['hidden'] ) ) {
425 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
426 $class = ' mw-hidden-cats-user-shown';
427 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
428 $class = ' mw-hidden-cats-ns-shown';
430 $class = ' mw-hidden-cats-hidden';
433 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
434 $this->msg( 'hidden-categories', count( $allCats['hidden'] ) )->escaped() .
435 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
439 # optional 'dmoz-like' category browser. Will be shown under the list
440 # of categories an article belong to
441 if ( $wgUseCategoryBrowser ) {
442 $s .= '<br /><hr />';
444 # get a big array of the parents tree
445 $parenttree = $this->getTitle()->getParentCategoryTree();
446 # Skin object passed by reference cause it can not be
447 # accessed under the method subfunction drawCategoryBrowser
448 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
449 # Clean out bogus first entry and sort them
450 unset( $tempout[0] );
452 # Output one per line
453 $s .= implode( "<br />\n", $tempout );
460 * Render the array as a serie of links.
461 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
462 * @return String separated by >, terminate with "\n"
464 function drawCategoryBrowser( $tree ) {
467 foreach ( $tree as $element => $parent ) {
468 if ( empty( $parent ) ) {
469 # element start a new list
472 # grab the others elements
473 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
476 # add our current element to the list
477 $eltitle = Title
::newFromText( $element );
478 $return .= Linker
::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
487 function getCategories() {
488 $out = $this->getOutput();
490 $catlinks = $this->getCategoryLinks();
492 $classes = 'catlinks';
494 // Check what we're showing
495 $allCats = $out->getCategoryLinks();
496 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
497 $this->getTitle()->getNamespace() == NS_CATEGORY
;
499 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
500 $classes .= ' catlinks-allhidden';
503 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
507 * This runs a hook to allow extensions placing their stuff after content
508 * and article metadata (e.g. categories).
509 * Note: This function has nothing to do with afterContent().
511 * This hook is placed here in order to allow using the same hook for all
512 * skins, both the SkinTemplate based ones and the older ones, which directly
513 * use this class to get their data.
515 * The output of this function gets processed in SkinTemplate::outputPage() for
516 * the SkinTemplate based skins, all other skins should directly echo it.
518 * @return String, empty by default, if not changed by any hook function.
520 protected function afterContentHook() {
523 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
524 // adding just some spaces shouldn't toggle the output
525 // of the whole <div/>, so we use trim() here
526 if ( trim( $data ) != '' ) {
527 // Doing this here instead of in the skins to
528 // ensure that the div has the same ID in all
530 $data = "<div id='mw-data-after-content'>\n" .
535 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
542 * Generate debug data HTML for displaying at the bottom of the main content
544 * @return String HTML containing debug data, if enabled (otherwise empty).
546 protected function generateDebugHTML() {
549 $html = MWDebug
::getDebugHTML( $this->getContext() );
551 if ( $wgShowDebug ) {
552 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext
);
553 $html .= "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
554 $listInternals . "</ul>\n";
561 * @param $debugText string
564 private function formatDebugHTML( $debugText ) {
565 global $wgDebugTimestamps;
567 $lines = explode( "\n", $debugText );
571 foreach ( $lines as $line ) {
573 if ( $wgDebugTimestamps ) {
575 if ( preg_match( '/^(\d+\.\d+ {1,3}\d+.\dM\s{2})/', $line, $matches ) ) {
577 $line = substr( $line, strlen( $pre ) );
580 $display = ltrim( $line );
581 $ident = strlen( $line ) - strlen( $display );
582 $diff = $ident - $curIdent;
584 $display = $pre . $display;
585 if ( $display == '' ) {
586 $display = "\xc2\xa0";
589 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
592 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
594 $display = htmlspecialchars( $display );
598 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
599 } elseif ( $diff == 0 ) {
600 $ret .= "</li><li>\n";
602 $ret .= str_repeat( "<ul><li>\n", $diff );
604 $ret .= "<tt>$display</tt>\n";
609 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
615 * This gets called shortly before the </body> tag.
617 * @return String HTML-wrapped JS code to be put before </body>
619 function bottomScripts() {
620 // TODO and the suckage continues. This function is really just a wrapper around
621 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
623 $bottomScriptText = $this->getOutput()->getBottomScripts();
624 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
626 return $bottomScriptText;
630 * Text with the permalink to the source page,
631 * usually shown on the footer of a printed page
633 * @return string HTML text with an URL
635 function printSource() {
636 $oldid = $this->getRevisionId();
638 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
640 // oldid not available for non existing pages
641 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
643 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
649 function getUndeleteLink() {
650 $action = $this->getRequest()->getVal( 'action', 'view' );
652 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
653 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
654 $n = $this->getTitle()->isDeleted();
658 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
659 $msg = 'thisisdeleted';
661 $msg = 'viewdeleted';
664 return $this->msg( $msg )->rawParams(
666 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
667 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
678 function subPageSubtitle() {
679 $out = $this->getOutput();
682 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
686 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
687 $ptext = $this->getTitle()->getPrefixedText();
688 if ( preg_match( '/\//', $ptext ) ) {
689 $links = explode( '/', $ptext );
695 foreach ( $links as $link ) {
696 $growinglink .= $link;
698 $linkObj = Title
::newFromText( $growinglink );
700 if ( is_object( $linkObj ) && $linkObj->exists() ) {
701 $getlink = Linker
::linkKnown(
703 htmlspecialchars( $display )
709 $subpages .= $this->msg( 'pipe-separator' )->escaped();
711 $subpages .= '< ';
714 $subpages .= $getlink;
728 * Returns true if the IP should be shown in the header
731 function showIPinHeader() {
732 global $wgShowIPinHeader;
733 return $wgShowIPinHeader && session_id() != '';
739 function getSearchLink() {
740 $searchPage = SpecialPage
::getTitleFor( 'Search' );
741 return $searchPage->getLocalURL();
747 function escapeSearchLink() {
748 return htmlspecialchars( $this->getSearchLink() );
752 * @param $type string
755 function getCopyright( $type = 'detect' ) {
756 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
758 if ( $type == 'detect' ) {
759 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
766 if ( $type == 'history' ) {
767 $msg = 'history_copyright';
772 if ( $wgRightsPage ) {
773 $title = Title
::newFromText( $wgRightsPage );
774 $link = Linker
::linkKnown( $title, $wgRightsText );
775 } elseif ( $wgRightsUrl ) {
776 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
777 } elseif ( $wgRightsText ) {
778 $link = $wgRightsText;
784 // Allow for site and per-namespace customization of copyright notice.
787 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
789 $msgObj = $this->msg( $msg )->rawParams( $link );
791 $msg = $msgObj->inContentLanguage()->text();
792 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
793 $msg = Html
::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
797 return $msgObj->text();
802 * @return null|string
804 function getCopyrightIcon() {
805 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
809 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
810 $out = $wgCopyrightIcon;
811 } elseif ( $wgRightsIcon ) {
812 $icon = htmlspecialchars( $wgRightsIcon );
814 if ( $wgRightsUrl ) {
815 $url = htmlspecialchars( $wgRightsUrl );
816 $out .= '<a href="' . $url . '">';
819 $text = htmlspecialchars( $wgRightsText );
820 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
822 if ( $wgRightsUrl ) {
831 * Gets the powered by MediaWiki icon.
834 function getPoweredBy() {
837 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
838 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
839 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
844 * Get the timestamp of the latest revision, formatted in user language
848 protected function lastModified() {
849 $timestamp = $this->getOutput()->getRevisionTimestamp();
851 # No cached timestamp, load it from the database
852 if ( $timestamp === null ) {
853 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
857 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
858 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
859 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
864 if ( wfGetLB()->getLaggedSlaveMode() ) {
865 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
872 * @param $align string
875 function logoText( $align = '' ) {
876 if ( $align != '' ) {
877 $a = " align='{$align}'";
882 $mp = $this->msg( 'mainpage' )->escaped();
883 $mptitle = Title
::newMainPage();
884 $url = ( is_object( $mptitle ) ?
htmlspecialchars( $mptitle->getLocalURL() ) : '' );
886 $logourl = $this->getLogo();
887 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
893 * Renders a $wgFooterIcons icon acording to the method's arguments
894 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
895 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
896 * @return String HTML
898 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
899 if ( is_string( $icon ) ) {
901 } else { // Assuming array
902 $url = isset($icon["url"]) ?
$icon["url"] : null;
903 unset( $icon["url"] );
904 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
905 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
907 $html = htmlspecialchars( $icon["alt"] );
910 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
917 * Gets the link to the wiki's main page.
920 function mainPageLink() {
921 $s = Linker
::linkKnown(
922 Title
::newMainPage(),
923 $this->msg( 'mainpage' )->escaped()
934 public function footerLink( $desc, $page ) {
935 // if the link description has been set to "-" in the default language,
936 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
937 // then it is disabled, for all languages.
940 // Otherwise, we display the link for the user, described in their
941 // language (which may or may not be the same as the default language),
942 // but we make the link target be the one site-wide page.
943 $title = Title
::newFromText( $this->msg( $page )->inContentLanguage()->text() );
945 return Linker
::linkKnown(
947 $this->msg( $desc )->escaped()
953 * Gets the link to the wiki's privacy policy page.
954 * @return String HTML
956 function privacyLink() {
957 return $this->footerLink( 'privacy', 'privacypage' );
961 * Gets the link to the wiki's about page.
962 * @return String HTML
964 function aboutLink() {
965 return $this->footerLink( 'aboutsite', 'aboutpage' );
969 * Gets the link to the wiki's general disclaimers page.
970 * @return String HTML
972 function disclaimerLink() {
973 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
977 * Return URL options for the 'edit page' link.
978 * This may include an 'oldid' specifier, if the current page view is such.
983 function editUrlOptions() {
984 $options = array( 'action' => 'edit' );
986 if ( !$this->isRevisionCurrent() ) {
987 $options['oldid'] = intval( $this->getRevisionId() );
994 * @param $id User|int
997 function showEmailUser( $id ) {
998 if ( $id instanceof User
) {
1001 $targetUser = User
::newFromId( $id );
1003 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1004 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1008 * Return a fully resolved style path url to images or styles stored in the common folder.
1009 * This method returns a url resolved using the configured skin style path
1010 * and includes the style version inside of the url.
1011 * @param $name String: The name or path of a skin resource file
1012 * @return String The fully resolved style path url including styleversion
1014 function getCommonStylePath( $name ) {
1015 global $wgStylePath, $wgStyleVersion;
1016 return "$wgStylePath/common/$name?$wgStyleVersion";
1020 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1021 * This method returns a url resolved using the configured skin style path
1022 * and includes the style version inside of the url.
1023 * @param $name String: The name or path of a skin resource file
1024 * @return String The fully resolved style path url including styleversion
1026 function getSkinStylePath( $name ) {
1027 global $wgStylePath, $wgStyleVersion;
1028 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1031 /* these are used extensively in SkinTemplate, but also some other places */
1034 * @param $urlaction string
1037 static function makeMainPageUrl( $urlaction = '' ) {
1038 $title = Title
::newMainPage();
1039 self
::checkTitle( $title, '' );
1041 return $title->getLocalURL( $urlaction );
1045 * @param $name string
1046 * @param $urlaction string
1049 static function makeSpecialUrl( $name, $urlaction = '' ) {
1050 $title = SpecialPage
::getSafeTitleFor( $name );
1051 return $title->getLocalURL( $urlaction );
1055 * @param $name string
1056 * @param $subpage string
1057 * @param $urlaction string
1060 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1061 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1062 return $title->getLocalURL( $urlaction );
1066 * @param $name string
1067 * @param $urlaction string
1070 static function makeI18nUrl( $name, $urlaction = '' ) {
1071 $title = Title
::newFromText( wfMsgForContent( $name ) );
1072 self
::checkTitle( $title, $name );
1073 return $title->getLocalURL( $urlaction );
1077 * @param $name string
1078 * @param $urlaction string
1081 static function makeUrl( $name, $urlaction = '' ) {
1082 $title = Title
::newFromText( $name );
1083 self
::checkTitle( $title, $name );
1085 return $title->getLocalURL( $urlaction );
1089 * If url string starts with http, consider as external URL, else
1091 * @param $name String
1092 * @return String URL
1094 static function makeInternalOrExternalUrl( $name ) {
1095 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1098 return self
::makeUrl( $name );
1103 * this can be passed the NS number as defined in Language.php
1105 * @param $urlaction string
1106 * @param $namespace int
1109 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1110 $title = Title
::makeTitleSafe( $namespace, $name );
1111 self
::checkTitle( $title, $name );
1113 return $title->getLocalURL( $urlaction );
1117 * these return an array with the 'href' and boolean 'exists'
1119 * @param $urlaction string
1122 static function makeUrlDetails( $name, $urlaction = '' ) {
1123 $title = Title
::newFromText( $name );
1124 self
::checkTitle( $title, $name );
1127 'href' => $title->getLocalURL( $urlaction ),
1128 'exists' => $title->getArticleID() != 0,
1133 * Make URL details where the article exists (or at least it's convenient to think so)
1134 * @param $name String Article name
1135 * @param $urlaction String
1138 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1139 $title = Title
::newFromText( $name );
1140 self
::checkTitle( $title, $name );
1143 'href' => $title->getLocalURL( $urlaction ),
1149 * make sure we have some title to operate on
1151 * @param $title Title
1152 * @param $name string
1154 static function checkTitle( &$title, $name ) {
1155 if ( !is_object( $title ) ) {
1156 $title = Title
::newFromText( $name );
1157 if ( !is_object( $title ) ) {
1158 $title = Title
::newFromText( '--error: link target missing--' );
1164 * Build an array that represents the sidebar(s), the navigation bar among them
1168 function buildSidebar() {
1169 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1170 wfProfileIn( __METHOD__
);
1172 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1174 if ( $wgEnableSidebarCache ) {
1175 $cachedsidebar = $parserMemc->get( $key );
1176 if ( $cachedsidebar ) {
1177 wfProfileOut( __METHOD__
);
1178 return $cachedsidebar;
1183 $this->addToSidebar( $bar, 'sidebar' );
1185 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1186 if ( $wgEnableSidebarCache ) {
1187 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1190 wfProfileOut( __METHOD__
);
1194 * Add content from a sidebar system message
1195 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1197 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1200 * @param $message String
1202 function addToSidebar( &$bar, $message ) {
1203 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1207 * Add content from plain text
1210 * @param $text string
1213 function addToSidebarPlain( &$bar, $text ) {
1214 $lines = explode( "\n", $text );
1218 foreach ( $lines as $line ) {
1219 if ( strpos( $line, '*' ) !== 0 ) {
1222 $line = rtrim( $line, "\r" ); // for Windows compat
1224 if ( strpos( $line, '**' ) !== 0 ) {
1225 $heading = trim( $line, '* ' );
1226 if ( !array_key_exists( $heading, $bar ) ) {
1227 $bar[$heading] = array();
1230 $line = trim( $line, '* ' );
1232 if ( strpos( $line, '|' ) !== false ) { // sanity check
1233 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1234 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1235 $extraAttribs = array();
1237 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1238 if ( $msgLink->exists() ) {
1239 $link = $msgLink->text();
1240 if ( $link == '-' ) {
1247 $msgText = $this->msg( $line[1] );
1248 if ( $msgText->exists() ) {
1249 $text = $msgText->text();
1254 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1257 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1258 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1259 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1260 $extraAttribs['rel'] = 'nofollow';
1263 global $wgExternalLinkTarget;
1264 if ( $wgExternalLinkTarget) {
1265 $extraAttribs['target'] = $wgExternalLinkTarget;
1268 $title = Title
::newFromText( $link );
1271 $title = $title->fixSpecialName();
1272 $href = $title->getLinkURL();
1274 $href = 'INVALID-TITLE';
1278 $bar[$heading][] = array_merge( array(
1281 'id' => 'n-' . Sanitizer
::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1294 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1295 * print stylesheet should override this and return false. (This is an
1296 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1300 public function commonPrintStylesheet() {
1305 * Gets new talk page messages for the current user.
1306 * @return MediaWiki message or if no new talk page messages, nothing
1308 function getNewtalks() {
1309 $out = $this->getOutput();
1311 $newtalks = $this->getUser()->getNewMessageLinks();
1314 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1315 $userTitle = $this->getUser()->getUserPage();
1316 $userTalkTitle = $userTitle->getTalkPage();
1318 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1319 $newMessagesLink = Linker
::linkKnown(
1321 $this->msg( 'newmessageslink' )->escaped(),
1323 array( 'redirect' => 'no' )
1326 $newMessagesDiffLink = Linker
::linkKnown(
1328 $this->msg( 'newmessagesdifflink' )->escaped(),
1330 array( 'diff' => 'cur' )
1334 'youhavenewmessages',
1336 $newMessagesDiffLink
1338 # Disable Squid cache
1339 $out->setSquidMaxage( 0 );
1341 } elseif ( count( $newtalks ) ) {
1342 // _>" " for BC <= 1.16
1343 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1346 foreach ( $newtalks as $newtalk ) {
1347 $msgs[] = Xml
::element(
1349 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1352 $parts = implode( $sep, $msgs );
1353 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1354 $out->setSquidMaxage( 0 );
1361 * Get a cached notice
1363 * @param $name String: message name, or 'default' for $wgSiteNotice
1364 * @return String: HTML fragment
1366 private function getCachedNotice( $name ) {
1367 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1369 wfProfileIn( __METHOD__
);
1373 if( $name === 'default' ) {
1375 global $wgSiteNotice;
1376 $notice = $wgSiteNotice;
1377 if( empty( $notice ) ) {
1378 wfProfileOut( __METHOD__
);
1382 $msg = $this->msg( $name )->inContentLanguage();
1383 if( $msg->isDisabled() ) {
1384 wfProfileOut( __METHOD__
);
1387 $notice = $msg->plain();
1390 // Use the extra hash appender to let eg SSL variants separately cache.
1391 $key = wfMemcKey( $name . $wgRenderHashAppend );
1392 $cachedNotice = $parserMemc->get( $key );
1393 if( is_array( $cachedNotice ) ) {
1394 if( md5( $notice ) == $cachedNotice['hash'] ) {
1395 $notice = $cachedNotice['html'];
1404 $parsed = $this->getOutput()->parse( $notice );
1405 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1409 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1410 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1411 wfProfileOut( __METHOD__
);
1416 * Get a notice based on page's namespace
1418 * @return String: HTML fragment
1420 function getNamespaceNotice() {
1421 wfProfileIn( __METHOD__
);
1423 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1424 $namespaceNotice = $this->getCachedNotice( $key );
1425 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1426 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1428 $namespaceNotice = '';
1431 wfProfileOut( __METHOD__
);
1432 return $namespaceNotice;
1436 * Get the site notice
1438 * @return String: HTML fragment
1440 function getSiteNotice() {
1441 wfProfileIn( __METHOD__
);
1444 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1445 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1446 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1448 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1449 if ( !$anonNotice ) {
1450 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1452 $siteNotice = $anonNotice;
1455 if ( !$siteNotice ) {
1456 $siteNotice = $this->getCachedNotice( 'default' );
1460 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1461 wfProfileOut( __METHOD__
);
1466 * Create a section edit link. This supersedes editSectionLink() and
1467 * editSectionLinkForOther().
1469 * @param $nt Title The title being linked to (may not be the same as
1470 * $wgTitle, if the section is included from a template)
1471 * @param $section string The designation of the section being pointed to,
1472 * to be included in the link, like "§ion=$section"
1473 * @param $tooltip string The tooltip to use for the link: will be escaped
1474 * and wrapped in the 'editsectionhint' message
1475 * @param $lang string Language code
1476 * @return string HTML to use for edit link
1478 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1479 // HTML generated here should probably have userlangattributes
1480 // added to it for LTR text on RTL pages
1482 if ( !is_null( $tooltip ) ) {
1483 # Bug 25462: undo double-escaping.
1484 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1485 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1487 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1489 array( 'action' => 'edit', 'section' => $section ),
1490 array( 'noclasses', 'known' )
1493 # Run the old hook. This takes up half of the function . . . hopefully
1494 # we can rid of it someday.
1497 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1498 $attribs = " title=\"$attribs\"";
1501 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1502 if ( !is_null( $result ) ) {
1503 # For reverse compatibility, add the brackets *after* the hook is
1504 # run, and even add them to hook-provided text. (This is the main
1505 # reason that the EditSectionLink hook is deprecated in favor of
1506 # DoEditSectionLink: it can't change the brackets or the span.)
1507 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1508 return "<span class=\"editsection\">$result</span>";
1511 # Add the brackets and the span, and *then* run the nice new hook, with
1512 # clean and non-redundant arguments.
1513 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1514 $result = "<span class=\"editsection\">$result</span>";
1516 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1521 * Use PHP's magic __call handler to intercept legacy calls to the linker
1522 * for backwards compatibility.
1524 * @param $fname String Name of called method
1525 * @param $args Array Arguments to the method
1527 function __call( $fname, $args ) {
1528 $realFunction = array( 'Linker', $fname );
1529 if ( is_callable( $realFunction ) ) {
1530 return call_user_func_array( $realFunction, $args );
1532 $className = get_class( $this );
1533 throw new MWException( "Call to undefined method $className::$fname" );