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.
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;
163 /** @return string path to the skin stylesheet */
164 function getStylesheet() {
165 return 'common/wikistandard.css';
168 /** @return string skin name */
169 public function getSkinName() {
170 return $this->skinname
;
173 function initPage( OutputPage
$out ) {
174 wfProfileIn( __METHOD__
);
176 $this->preloadExistence();
179 wfProfileOut( __METHOD__
);
183 * Preload the existence of three commonly-requested pages in a single query
185 function preloadExistence() {
186 $user = $this->getContext()->getUser();
189 $titles = array( $user->getUserPage(), $user->getTalkPage() );
192 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
194 } elseif ( $this->getTitle()->isTalkPage() ) {
195 $titles[] = $this->getTitle()->getSubjectPage();
197 $titles[] = $this->getTitle()->getTalkPage();
200 $lb = new LinkBatch( $titles );
201 $lb->setCaller( __METHOD__
);
206 * Set some local variables
208 protected function setMembers() {
209 $this->userpage
= $this->getContext()->getUser()->getUserPage()->getPrefixedText();
213 * Set the RequestContext used in this instance
215 * @param RequestContext $context
217 public function setContext( RequestContext
$context ) {
218 $this->mContext
= $context;
222 * Get the RequestContext used in this instance
224 * @return RequestContext
226 public function getContext() {
227 if ( !isset($this->mContext
) ) {
228 wfDebug( __METHOD__
. " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
229 $this->mContext
= RequestContext
::getMain();
231 return $this->mContext
;
238 public function getTitle() {
239 return $this->getContext()->getTitle();
246 public function getUser() {
247 return $this->getContext()->getUser();
251 * Get the current revision ID
255 public function getRevisionId() {
256 return $this->getContext()->getOutput()->getRevisionId();
260 * Whether the revision displayed is the latest revision of the page
264 public function isRevisionCurrent() {
265 $revID = $this->getRevisionId();
266 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
270 * Set the "relevant" title
271 * @see self::getRelevantTitle()
272 * @param $t Title object to use
274 public function setRelevantTitle( $t ) {
275 $this->mRelevantTitle
= $t;
279 * Return the "relevant" title.
280 * A "relevant" title is not necessarily the actual title of the page.
281 * Special pages like Special:MovePage use set the page they are acting on
282 * as their "relevant" title, this allows the skin system to display things
283 * such as content tabs which belong to to that page instead of displaying
284 * a basic special page tab which has almost no meaning.
288 public function getRelevantTitle() {
289 if ( isset($this->mRelevantTitle
) ) {
290 return $this->mRelevantTitle
;
292 return $this->getTitle();
296 * Set the "relevant" user
297 * @see self::getRelevantUser()
298 * @param $u User object to use
300 public function setRelevantUser( $u ) {
301 $this->mRelevantUser
= $u;
305 * Return the "relevant" user.
306 * A "relevant" user is similar to a relevant title. Special pages like
307 * Special:Contributions mark the user which they are relevant to so that
308 * things like the toolbox can display the information they usually are only
309 * able to display on a user's userpage and talkpage.
312 public function getRelevantUser() {
313 if ( isset($this->mRelevantUser
) ) {
314 return $this->mRelevantUser
;
316 $title = $this->getRelevantTitle();
317 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
318 $rootUser = strtok( $title->getText(), '/' );
319 if ( User
::isIP( $rootUser ) ) {
320 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
322 $user = User
::newFromName( $rootUser );
323 if ( $user->isLoggedIn() ) {
324 $this->mRelevantUser
= $user;
327 return $this->mRelevantUser
;
333 * Outputs the HTML generated by other functions.
334 * @param $out OutputPage
336 abstract function outputPage( OutputPage
$out );
338 static function makeVariablesScript( $data ) {
340 return Html
::inlineScript(
341 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
349 * To make it harder for someone to slip a user a fake
350 * user-JavaScript or user-CSS preview, a random token
351 * is associated with the login session. If it's not
352 * passed back with the preview request, we won't render
355 * @param $action String: 'edit', 'submit' etc.
358 public function userCanPreview( $action ) {
359 if ( $action != 'submit' ) {
362 if ( !$this->getContext()->getRequest()->wasPosted() ) {
365 if ( !$this->getTitle()->userCanEditCssSubpage() ) {
368 if ( !$this->getTitle()->userCanEditJsSubpage() ) {
372 return $this->getContext()->getUser()->matchEditToken(
373 $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
377 * Generated JavaScript action=raw&gen=js
378 * This used to load MediaWiki:Common.js and the skin-specific style
379 * before the ResourceLoader.
381 * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some
383 * @param $skinName String: If set, overrides the skin name
386 public function generateUserJs( $skinName = null ) {
391 * Generate user stylesheet for action=raw&gen=css
393 * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some
397 public function generateUserStylesheet() {
404 * @param $out OutputPage
406 function setupUserCss( OutputPage
$out ) {
407 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
409 wfProfileIn( __METHOD__
);
411 $this->setupSkinUserCss( $out );
412 // Add any extension CSS
413 foreach ( $out->getExtStyle() as $url ) {
414 $out->addStyle( $url );
417 // Per-site custom styles
418 if ( $wgUseSiteCss ) {
419 $out->addModuleStyles( array( 'site', 'noscript' ) );
420 if( $this->getContext()->getUser()->isLoggedIn() ){
421 $out->addModuleStyles( 'user.groups' );
425 // Per-user custom styles
426 if ( $wgAllowUserCss ) {
427 if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) {
428 // @todo FIXME: Properly escape the cdata!
429 $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
431 $out->addModuleStyles( 'user' );
435 // Per-user preference styles
436 if ( $wgAllowUserCssPrefs ) {
437 $out->addModuleStyles( 'user.options' );
440 wfProfileOut( __METHOD__
);
444 * Get the query to generate a dynamic stylesheet
448 public static function getDynamicStylesheetQuery() {
449 global $wgSquidMaxage;
453 'maxage' => $wgSquidMaxage,
454 'usemsgcache' => 'yes',
455 'ctype' => 'text/css',
456 'smaxage' => $wgSquidMaxage,
461 * Add skin specific stylesheets
462 * Calling this method with an $out of anything but the same OutputPage
463 * inside ->getContext()->getOutput() is deprecated. The $out arg is kept
464 * for compatibility purposes with skins.
465 * @param $out OutputPage
468 abstract function setupSkinUserCss( OutputPage
$out );
472 * @param $title Title
475 function getPageClasses( $title ) {
476 $numeric = 'ns-' . $title->getNamespace();
478 if ( $title->getNamespace() == NS_SPECIAL
) {
479 $type = 'ns-special';
480 // bug 23315: provide a class based on the canonical special page name without subpages
481 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
482 if ( $canonicalName ) {
483 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
485 $type .= ' mw-invalidspecialpage';
487 } elseif ( $title->isTalkPage() ) {
490 $type = 'ns-subject';
493 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
495 return "$numeric $type $name";
499 * This will be called by OutputPage::headElement when it is creating the
500 * <body> tag, skins can override it if they have a need to add in any
501 * body attributes or classes of their own.
502 * @param $out OutputPage
503 * @param $bodyAttrs Array
505 function addToBodyAttributes( $out, &$bodyAttrs ) {
506 // does nothing by default
518 function getCategoryLinks() {
519 global $wgUseCategoryBrowser, $wgContLang;
521 $out = $this->getContext()->getOutput();
523 if ( count( $out->mCategoryLinks
) == 0 ) {
528 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
530 // Use Unicode bidi embedding override characters,
531 // to make sure links don't smash each other up in ugly ways.
532 $dir = $wgContLang->getDir();
533 $embed = "<span dir='$dir'>";
536 $allCats = $out->getCategoryLinks();
538 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
540 if ( !empty( $allCats['normal'] ) ) {
541 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
543 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
544 $s .= '<div id="mw-normal-catlinks">' .
545 Linker
::link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
546 . $colon . $t . '</div>';
550 if ( isset( $allCats['hidden'] ) ) {
551 if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
552 $class = 'mw-hidden-cats-user-shown';
553 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
554 $class = 'mw-hidden-cats-ns-shown';
556 $class = 'mw-hidden-cats-hidden';
559 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
560 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
561 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
565 # optional 'dmoz-like' category browser. Will be shown under the list
566 # of categories an article belong to
567 if ( $wgUseCategoryBrowser ) {
568 $s .= '<br /><hr />';
570 # get a big array of the parents tree
571 $parenttree = $this->getTitle()->getParentCategoryTree();
572 # Skin object passed by reference cause it can not be
573 # accessed under the method subfunction drawCategoryBrowser
574 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
575 # Clean out bogus first entry and sort them
576 unset( $tempout[0] );
578 # Output one per line
579 $s .= implode( "<br />\n", $tempout );
586 * Render the array as a serie of links.
587 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
588 * @return String separated by >, terminate with "\n"
590 function drawCategoryBrowser( $tree ) {
593 foreach ( $tree as $element => $parent ) {
594 if ( empty( $parent ) ) {
595 # element start a new list
598 # grab the others elements
599 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
602 # add our current element to the list
603 $eltitle = Title
::newFromText( $element );
604 $return .= Linker
::link( $eltitle, $eltitle->getText() );
610 function getCategories() {
611 $out = $this->getContext()->getOutput();
613 $catlinks = $this->getCategoryLinks();
615 $classes = 'catlinks';
617 // Check what we're showing
618 $allCats = $out->getCategoryLinks();
619 $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ||
620 $this->getTitle()->getNamespace() == NS_CATEGORY
;
622 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
623 $classes .= ' catlinks-allhidden';
626 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
630 * This runs a hook to allow extensions placing their stuff after content
631 * and article metadata (e.g. categories).
632 * Note: This function has nothing to do with afterContent().
634 * This hook is placed here in order to allow using the same hook for all
635 * skins, both the SkinTemplate based ones and the older ones, which directly
636 * use this class to get their data.
638 * The output of this function gets processed in SkinTemplate::outputPage() for
639 * the SkinTemplate based skins, all other skins should directly echo it.
641 * @return String, empty by default, if not changed by any hook function.
643 protected function afterContentHook() {
646 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
647 // adding just some spaces shouldn't toggle the output
648 // of the whole <div/>, so we use trim() here
649 if ( trim( $data ) != '' ) {
650 // Doing this here instead of in the skins to
651 // ensure that the div has the same ID in all
653 $data = "<div id='mw-data-after-content'>\n" .
658 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
665 * Generate debug data HTML for displaying at the bottom of the main content
667 * @return String HTML containing debug data, if enabled (otherwise empty).
669 protected function generateDebugHTML() {
672 if ( $wgShowDebug ) {
673 $listInternals = $this->formatDebugHTML( $this->getContext()->getOutput()->mDebugtext
);
674 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
675 $listInternals . "</ul>\n";
681 private function formatDebugHTML( $debugText ) {
682 global $wgDebugTimestamps;
684 $lines = explode( "\n", $debugText );
688 foreach ( $lines as $line ) {
690 if ( $wgDebugTimestamps ) {
692 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
694 $line = substr( $line, strlen( $pre ) );
697 $display = ltrim( $line );
698 $ident = strlen( $line ) - strlen( $display );
699 $diff = $ident - $curIdent;
701 $display = $pre . $display;
702 if ( $display == '' ) {
703 $display = "\xc2\xa0";
706 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
709 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
711 $display = htmlspecialchars( $display );
715 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
716 } elseif ( $diff == 0 ) {
717 $ret .= "</li><li>\n";
719 $ret .= str_repeat( "<ul><li>\n", $diff );
721 $ret .= "<tt>$display</tt>\n";
726 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
732 * This gets called shortly before the </body> tag.
733 * @param $out OutputPage object
734 * @return String HTML-wrapped JS code to be put before </body>
736 function bottomScripts( $out ) {
737 // TODO and the suckage continues. This function is really just a wrapper around
738 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
740 $bottomScriptText = $out->getBottomScripts( $this );
741 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
743 return $bottomScriptText;
746 /** @return string Retrievied from HTML text */
747 function printSource() {
748 $url = htmlspecialchars( $this->getTitle()->getFullURL() );
749 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
752 function getUndeleteLink() {
753 $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
755 if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
756 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
758 $includeSuppressed = $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
759 $n = $this->getTitle()->isDeleted( $includeSuppressed );
762 if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
763 $msg = 'thisisdeleted';
765 $msg = 'viewdeleted';
771 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
772 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ),
775 array( 'known', 'noclasses' )
784 function subPageSubtitle() {
785 $out = $this->getContext()->getOutput();
788 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
792 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
793 $ptext = $this->getTitle()->getPrefixedText();
794 if ( preg_match( '/\//', $ptext ) ) {
795 $links = explode( '/', $ptext );
801 foreach ( $links as $link ) {
802 $growinglink .= $link;
804 $linkObj = Title
::newFromText( $growinglink );
806 if ( is_object( $linkObj ) && $linkObj->exists() ) {
807 $getlink = $this->link(
809 htmlspecialchars( $display ),
812 array( 'known', 'noclasses' )
818 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
820 $subpages .= '< ';
823 $subpages .= $getlink;
837 * Returns true if the IP should be shown in the header
840 function showIPinHeader() {
841 global $wgShowIPinHeader;
842 return $wgShowIPinHeader && session_id() != '';
845 function getSearchLink() {
846 $searchPage = SpecialPage
::getTitleFor( 'Search' );
847 return $searchPage->getLocalURL();
850 function escapeSearchLink() {
851 return htmlspecialchars( $this->getSearchLink() );
854 function getCopyright( $type = 'detect' ) {
855 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
857 if ( $type == 'detect' ) {
858 $diff = $this->getContext()->getRequest()->getVal( 'diff' );
860 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
867 if ( $type == 'history' ) {
868 $msg = 'history_copyright';
875 if ( $wgRightsPage ) {
876 $title = Title
::newFromText( $wgRightsPage );
877 $link = Linker
::linkKnown( $title, $wgRightsText );
878 } elseif ( $wgRightsUrl ) {
879 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
880 } elseif ( $wgRightsText ) {
881 $link = $wgRightsText;
887 // Allow for site and per-namespace customization of copyright notice.
890 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
893 $out .= wfMsgForContent( $msg, $link );
895 $out .= wfMsg( $msg, $link );
901 function getCopyrightIcon() {
902 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
906 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
907 $out = $wgCopyrightIcon;
908 } elseif ( $wgRightsIcon ) {
909 $icon = htmlspecialchars( $wgRightsIcon );
911 if ( $wgRightsUrl ) {
912 $url = htmlspecialchars( $wgRightsUrl );
913 $out .= '<a href="' . $url . '">';
916 $text = htmlspecialchars( $wgRightsText );
917 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
919 if ( $wgRightsUrl ) {
928 * Gets the powered by MediaWiki icon.
931 function getPoweredBy() {
934 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
935 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
936 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
941 * Get the timestamp of the latest revision, formatted in user language
943 * @param $article Article object. Used if we're working with the current revision
946 protected function lastModified( $article ) {
947 if ( !$this->isRevisionCurrent() ) {
948 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
950 $timestamp = $article->getTimestamp();
954 $d = $this->getContext()->getLang()->date( $timestamp, true );
955 $t = $this->getContext()->getLang()->time( $timestamp, true );
956 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
961 if ( wfGetLB()->getLaggedSlaveMode() ) {
962 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
968 function logoText( $align = '' ) {
969 if ( $align != '' ) {
970 $a = " align='{$align}'";
975 $mp = wfMsg( 'mainpage' );
976 $mptitle = Title
::newMainPage();
977 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
979 $logourl = $this->getLogo();
980 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
986 * Renders a $wgFooterIcons icon acording to the method's arguments
987 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
988 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
989 * @return String HTML
991 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
992 if ( is_string( $icon ) ) {
994 } else { // Assuming array
995 $url = isset($icon["url"]) ?
$icon["url"] : null;
996 unset( $icon["url"] );
997 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
998 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1000 $html = htmlspecialchars( $icon["alt"] );
1003 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1010 * Gets the link to the wiki's main page.
1013 function mainPageLink() {
1015 Title
::newMainPage(),
1016 wfMsg( 'mainpage' ),
1019 array( 'known', 'noclasses' )
1025 public function footerLink( $desc, $page ) {
1026 // if the link description has been set to "-" in the default language,
1027 if ( wfMsgForContent( $desc ) == '-' ) {
1028 // then it is disabled, for all languages.
1031 // Otherwise, we display the link for the user, described in their
1032 // language (which may or may not be the same as the default language),
1033 // but we make the link target be the one site-wide page.
1034 $title = Title
::newFromText( wfMsgForContent( $page ) );
1036 return Linker
::linkKnown(
1038 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1044 * Gets the link to the wiki's privacy policy page.
1045 * @return String HTML
1047 function privacyLink() {
1048 return $this->footerLink( 'privacy', 'privacypage' );
1052 * Gets the link to the wiki's about page.
1053 * @return String HTML
1055 function aboutLink() {
1056 return $this->footerLink( 'aboutsite', 'aboutpage' );
1060 * Gets the link to the wiki's general disclaimers page.
1061 * @return String HTML
1063 function disclaimerLink() {
1064 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1068 * Return URL options for the 'edit page' link.
1069 * This may include an 'oldid' specifier, if the current page view is such.
1074 function editUrlOptions() {
1075 $options = array( 'action' => 'edit' );
1077 if ( !$this->isRevisionCurrent() ) {
1078 $options['oldid'] = intval( $this->getRevisionId() );
1084 function showEmailUser( $id ) {
1085 $targetUser = User
::newFromId( $id );
1086 return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1087 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1091 * Return a fully resolved style path url to images or styles stored in the common folder.
1092 * This method returns a url resolved using the configured skin style path
1093 * and includes the style version inside of the url.
1094 * @param $name String: The name or path of a skin resource file
1095 * @return String The fully resolved style path url including styleversion
1097 function getCommonStylePath( $name ) {
1098 global $wgStylePath, $wgStyleVersion;
1099 return "$wgStylePath/common/$name?$wgStyleVersion";
1103 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1104 * This method returns a url resolved using the configured skin style path
1105 * and includes the style version inside of the url.
1106 * @param $name String: The name or path of a skin resource file
1107 * @return String The fully resolved style path url including styleversion
1109 function getSkinStylePath( $name ) {
1110 global $wgStylePath, $wgStyleVersion;
1111 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1114 /* these are used extensively in SkinTemplate, but also some other places */
1115 static function makeMainPageUrl( $urlaction = '' ) {
1116 $title = Title
::newMainPage();
1117 self
::checkTitle( $title, '' );
1119 return $title->getLocalURL( $urlaction );
1122 static function makeSpecialUrl( $name, $urlaction = '' ) {
1123 $title = SpecialPage
::getSafeTitleFor( $name );
1124 return $title->getLocalURL( $urlaction );
1127 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1128 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1129 return $title->getLocalURL( $urlaction );
1132 static function makeI18nUrl( $name, $urlaction = '' ) {
1133 $title = Title
::newFromText( wfMsgForContent( $name ) );
1134 self
::checkTitle( $title, $name );
1135 return $title->getLocalURL( $urlaction );
1138 static function makeUrl( $name, $urlaction = '' ) {
1139 $title = Title
::newFromText( $name );
1140 self
::checkTitle( $title, $name );
1142 return $title->getLocalURL( $urlaction );
1146 * If url string starts with http, consider as external URL, else
1148 * @param $name String
1149 * @return String URL
1151 static function makeInternalOrExternalUrl( $name ) {
1152 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1155 return self
::makeUrl( $name );
1159 # this can be passed the NS number as defined in Language.php
1160 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1161 $title = Title
::makeTitleSafe( $namespace, $name );
1162 self
::checkTitle( $title, $name );
1164 return $title->getLocalURL( $urlaction );
1167 /* these return an array with the 'href' and boolean 'exists' */
1168 static function makeUrlDetails( $name, $urlaction = '' ) {
1169 $title = Title
::newFromText( $name );
1170 self
::checkTitle( $title, $name );
1173 'href' => $title->getLocalURL( $urlaction ),
1174 'exists' => $title->getArticleID() != 0,
1179 * Make URL details where the article exists (or at least it's convenient to think so)
1180 * @param $name String Article name
1181 * @param $urlaction String
1184 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1185 $title = Title
::newFromText( $name );
1186 self
::checkTitle( $title, $name );
1189 'href' => $title->getLocalURL( $urlaction ),
1194 # make sure we have some title to operate on
1195 static function checkTitle( &$title, $name ) {
1196 if ( !is_object( $title ) ) {
1197 $title = Title
::newFromText( $name );
1198 if ( !is_object( $title ) ) {
1199 $title = Title
::newFromText( '--error: link target missing--' );
1205 * Build an array that represents the sidebar(s), the navigation bar among them
1209 function buildSidebar() {
1210 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1211 wfProfileIn( __METHOD__
);
1213 $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
1215 if ( $wgEnableSidebarCache ) {
1216 $cachedsidebar = $parserMemc->get( $key );
1217 if ( $cachedsidebar ) {
1218 wfProfileOut( __METHOD__
);
1219 return $cachedsidebar;
1224 $this->addToSidebar( $bar, 'sidebar' );
1226 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1227 if ( $wgEnableSidebarCache ) {
1228 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1231 wfProfileOut( __METHOD__
);
1235 * Add content from a sidebar system message
1236 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1238 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1240 * @param &$bar array
1241 * @param $message String
1243 function addToSidebar( &$bar, $message ) {
1244 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1248 * Add content from plain text
1250 * @param &$bar array
1251 * @param $text string
1254 function addToSidebarPlain( &$bar, $text ) {
1255 $lines = explode( "\n", $text );
1256 $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
1260 foreach ( $lines as $line ) {
1261 if ( strpos( $line, '*' ) !== 0 ) {
1265 if ( strpos( $line, '**' ) !== 0 ) {
1266 $heading = trim( $line, '* ' );
1267 if ( !array_key_exists( $heading, $bar ) ) {
1268 $bar[$heading] = array();
1271 $line = trim( $line, '* ' );
1273 if ( strpos( $line, '|' ) !== false ) { // sanity check
1274 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1275 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1276 $extraAttribs = array();
1278 $msgLink = wfMessage( $line[0] )->inContentLanguage();
1279 if ( $msgLink->exists() ) {
1280 $link = $msgLink->text();
1281 if ( $link == '-' ) {
1288 $msgText = wfMessage( $line[1] );
1289 if ( $msgText->exists() ) {
1290 $text = $msgText->text();
1295 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1297 //Parser::getExternalLinkAttribs won't work here because of the Namespace things
1298 global $wgNoFollowLinks;
1299 if ( $wgNoFollowLinks ) {
1300 $extraAttribs['rel'] = 'nofollow';
1302 global $wgNoFollowDomainExceptions;
1303 if ( $wgNoFollowDomainExceptions ) {
1304 $bits = wfParseUrl( $url );
1305 if ( is_array( $bits ) && isset( $bits['host'] ) ) {
1306 foreach ( $wgNoFollowDomainExceptions as $domain ) {
1307 if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) {
1308 unset( $extraAttribs['rel'] );
1315 global $wgExternalLinkTarget;
1316 if ( $wgExternalLinkTarget) {
1317 $extraAttribs['target'] = $wgExternalLinkTarget;
1320 $title = Title
::newFromText( $link );
1323 $title = $title->fixSpecialName();
1324 $href = $title->getLocalURL();
1326 $href = 'INVALID-TITLE';
1330 $bar[$heading][] = array_merge( array(
1333 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1336 } elseif ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1339 $line = substr( $line, 2, strlen( $line ) - 4 );
1341 $options = new ParserOptions();
1342 $options->setEditSection( false );
1343 $options->setInterfaceMessage( true );
1344 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
1351 if ( count( $wikiBar ) > 0 ) {
1352 $bar = array_merge( $bar, $wikiBar );
1359 * Should we include common/wikiprintable.css? Skins that have their own
1360 * print stylesheet should override this and return false. (This is an
1361 * ugly hack to get Monobook to play nicely with
1362 * OutputPage::headElement().)
1366 public function commonPrintStylesheet() {
1371 * Gets new talk page messages for the current user.
1372 * @return MediaWiki message or if no new talk page messages, nothing
1374 function getNewtalks() {
1375 $out = $this->getContext()->getOutput();
1377 $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
1380 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1381 $userTitle = $this->getUser()->getUserPage();
1382 $userTalkTitle = $userTitle->getTalkPage();
1384 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1385 $newMessagesLink = $this->link(
1387 wfMsgHtml( 'newmessageslink' ),
1389 array( 'redirect' => 'no' ),
1390 array( 'known', 'noclasses' )
1393 $newMessagesDiffLink = $this->link(
1395 wfMsgHtml( 'newmessagesdifflink' ),
1397 array( 'diff' => 'cur' ),
1398 array( 'known', 'noclasses' )
1402 'youhavenewmessages',
1404 $newMessagesDiffLink
1406 # Disable Squid cache
1407 $out->setSquidMaxage( 0 );
1409 } elseif ( count( $newtalks ) ) {
1410 // _>" " for BC <= 1.16
1411 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1414 foreach ( $newtalks as $newtalk ) {
1415 $msgs[] = Xml
::element(
1417 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1420 $parts = implode( $sep, $msgs );
1421 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1422 $out->setSquidMaxage( 0 );
1429 * Get a cached notice
1431 * @param $name String: message name, or 'default' for $wgSiteNotice
1432 * @return String: HTML fragment
1434 private function getCachedNotice( $name ) {
1435 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1437 wfProfileIn( __METHOD__
);
1441 if( $name === 'default' ) {
1443 global $wgSiteNotice;
1444 $notice = $wgSiteNotice;
1445 if( empty( $notice ) ) {
1446 wfProfileOut( __METHOD__
);
1450 $msg = wfMessage( $name )->inContentLanguage();
1451 if( $msg->isDisabled() ) {
1452 wfProfileOut( __METHOD__
);
1455 $notice = $msg->plain();
1458 // Use the extra hash appender to let eg SSL variants separately cache.
1459 $key = wfMemcKey( $name . $wgRenderHashAppend );
1460 $cachedNotice = $parserMemc->get( $key );
1461 if( is_array( $cachedNotice ) ) {
1462 if( md5( $notice ) == $cachedNotice['hash'] ) {
1463 $notice = $cachedNotice['html'];
1472 $parsed = $this->getContext()->getOutput()->parse( $notice );
1473 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1477 $notice = Html
::rawElement( 'div', array( 'id' => 'localNotice',
1478 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $notice );
1479 wfProfileOut( __METHOD__
);
1484 * Get a notice based on page's namespace
1486 * @return String: HTML fragment
1488 function getNamespaceNotice() {
1489 wfProfileIn( __METHOD__
);
1491 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1492 $namespaceNotice = $this->getCachedNotice( $key );
1493 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1494 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1496 $namespaceNotice = '';
1499 wfProfileOut( __METHOD__
);
1500 return $namespaceNotice;
1504 * Get the site notice
1506 * @return String: HTML fragment
1508 function getSiteNotice() {
1509 wfProfileIn( __METHOD__
);
1512 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1513 if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) {
1514 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1516 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1517 if ( !$anonNotice ) {
1518 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1520 $siteNotice = $anonNotice;
1523 if ( !$siteNotice ) {
1524 $siteNotice = $this->getCachedNotice( 'default' );
1528 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1529 wfProfileOut( __METHOD__
);
1534 * Create a section edit link. This supersedes editSectionLink() and
1535 * editSectionLinkForOther().
1537 * @param $nt Title The title being linked to (may not be the same as
1538 * $wgTitle, if the section is included from a template)
1539 * @param $section string The designation of the section being pointed to,
1540 * to be included in the link, like "§ion=$section"
1541 * @param $tooltip string The tooltip to use for the link: will be escaped
1542 * and wrapped in the 'editsectionhint' message
1543 * @param $lang string Language code
1544 * @return string HTML to use for edit link
1546 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1547 // HTML generated here should probably have userlangattributes
1548 // added to it for LTR text on RTL pages
1550 if ( !is_null( $tooltip ) ) {
1551 # Bug 25462: undo double-escaping.
1552 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1553 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1555 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1557 array( 'action' => 'edit', 'section' => $section ),
1558 array( 'noclasses', 'known' )
1561 # Run the old hook. This takes up half of the function . . . hopefully
1562 # we can rid of it someday.
1565 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1566 $attribs = " title=\"$attribs\"";
1569 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1570 if ( !is_null( $result ) ) {
1571 # For reverse compatibility, add the brackets *after* the hook is
1572 # run, and even add them to hook-provided text. (This is the main
1573 # reason that the EditSectionLink hook is deprecated in favor of
1574 # DoEditSectionLink: it can't change the brackets or the span.)
1575 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1576 return "<span class=\"editsection\">$result</span>";
1579 # Add the brackets and the span, and *then* run the nice new hook, with
1580 # clean and non-redundant arguments.
1581 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1582 $result = "<span class=\"editsection\">$result</span>";
1584 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1589 * Use PHP's magic __call handler to intercept legacy calls to the linker
1590 * for backwards compatibility.
1592 * @param $fname String Name of called method
1593 * @param $args Array Arguments to the method
1595 function __call( $fname, $args ) {
1596 $realFunction = array( 'Linker', $fname );
1597 if ( is_callable( $realFunction ) ) {
1598 return call_user_func_array( $realFunction, $args );
1600 $className = get_class( $this );
1601 throw new MWException( "Call to undefined method $className::$fname" );