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.
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
24 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
25 protected $skinname = 'standard';
26 protected $mRelevantTitle = null;
27 protected $mRelevantUser = null;
30 * Fetch the set of available skins.
31 * @return array of strings
33 static function getSkinNames() {
34 global $wgValidSkinNames;
35 static $skinsInitialised = false;
37 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
38 # Get a list of available skins
39 # Build using the regular expression '^(.*).php$'
40 # Array keys are all lower case, array value keep the case used by filename
42 wfProfileIn( __METHOD__
. '-init' );
44 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
48 # while code from www.php.net
49 while ( false !== ( $file = $skinDir->read() ) ) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
53 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
55 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
59 $skinsInitialised = true;
60 wfProfileOut( __METHOD__
. '-init' );
62 return $wgValidSkinNames;
66 * Fetch the list of usable skins in regards to $wgSkipSkins.
67 * Useful for Special:Preferences and other places where you
68 * only want to show skins users _can_ use.
69 * @return array of strings
71 public static function getUsableSkins() {
74 $usableSkins = self
::getSkinNames();
76 foreach ( $wgSkipSkins as $skip ) {
77 unset( $usableSkins[$skip] );
84 * Normalize a skin preference value to a form that can be loaded.
85 * If a skin can't be found, it will fall back to the configured
86 * default (or the old 'Classic' skin if that's broken).
87 * @param $key String: 'monobook', 'standard', etc.
90 static function normalizeKey( $key ) {
91 global $wgDefaultSkin;
93 $skinNames = Skin
::getSkinNames();
96 // Don't return the default immediately;
97 // in a misconfiguration we need to fall back.
98 $key = $wgDefaultSkin;
101 if ( isset( $skinNames[$key] ) ) {
105 // Older versions of the software used a numeric setting
106 // in the user preferences.
113 if ( isset( $fallback[$key] ) ) {
114 $key = $fallback[$key];
117 if ( isset( $skinNames[$key] ) ) {
119 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
120 return $wgDefaultSkin;
127 * Factory method for loading a skin of a given type
128 * @param $key String: 'monobook', 'standard', etc.
131 static function &newFromKey( $key ) {
132 global $wgStyleDirectory;
134 $key = Skin
::normalizeKey( $key );
136 $skinNames = Skin
::getSkinNames();
137 $skinName = $skinNames[$key];
138 $className = "Skin{$skinName}";
140 # Grab the skin class and initialise it.
141 if ( !class_exists( $className ) ) {
142 // Preload base classes to work around APC/PHP5 bug
143 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
145 if ( file_exists( $deps ) ) {
146 include_once( $deps );
148 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
150 # Check if we got if not failback to default skin
151 if ( !class_exists( $className ) ) {
152 # DO NOT die if the class isn't found. This breaks maintenance
153 # scripts and can cause a user account to be unrecoverable
154 # except by SQL manipulation if a previously valid skin name
155 # is no longer valid.
156 wfDebug( "Skin class does not exist: $className\n" );
157 $className = 'SkinVector';
158 require_once( "{$wgStyleDirectory}/Vector.php" );
161 $skin = new $className;
165 /** @return string path to the skin stylesheet */
166 function getStylesheet() {
167 return 'common/wikistandard.css';
170 /** @return string skin name */
171 public function getSkinName() {
172 return $this->skinname
;
175 function initPage( OutputPage
$out ) {
176 wfProfileIn( __METHOD__
);
178 $this->mRevisionId
= $out->mRevisionId
;
179 $this->preloadExistence();
182 wfProfileOut( __METHOD__
);
186 * Preload the existence of three commonly-requested pages in a single query
188 function preloadExistence() {
189 $user = $this->getContext()->getUser();
192 $titles = array( $user->getUserPage(), $user->getTalkPage() );
195 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
197 } elseif ( $this->getTitle()->isTalkPage() ) {
198 $titles[] = $this->getTitle()->getSubjectPage();
200 $titles[] = $this->getTitle()->getTalkPage();
203 $lb = new LinkBatch( $titles );
204 $lb->setCaller( __METHOD__
);
209 * Set some local variables
211 protected function setMembers() {
212 $this->userpage
= $this->getContext()->getUser()->getUserPage()->getPrefixedText();
213 $this->usercss
= false;
217 * Whether the revision displayed is the latest revision of the page
221 public function isRevisionCurrent() {
222 return $this->mRevisionId
== 0 ||
$this->mRevisionId
== $this->getTitle()->getLatestRevID();
226 * Set the RequestContext used in this instance
228 * @param RequestContext $context
230 public function setContext( RequestContext
$context ) {
231 $this->mContext
= $context;
235 * Get the RequestContext used in this instance
237 * @return RequestContext
239 public function getContext() {
240 if ( !isset($this->mContext
) ) {
241 wfDebug( __METHOD__
. " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
242 $this->mContext
= RequestContext
::getMain();
244 return $this->mContext
;
251 public function getTitle() {
252 return $this->getContext()->getTitle();
259 public function getUser() {
260 return $this->getContext()->getUser();
264 * Set the "relevant" title
265 * @see self::getRelevantTitle()
266 * @param $t Title object to use
268 public function setRelevantTitle( $t ) {
269 $this->mRelevantTitle
= $t;
273 * Return the "relevant" title.
274 * A "relevant" title is not necessarily the actual title of the page.
275 * Special pages like Special:MovePage use set the page they are acting on
276 * as their "relevant" title, this allows the skin system to display things
277 * such as content tabs which belong to to that page instead of displaying
278 * a basic special page tab which has almost no meaning.
280 public function getRelevantTitle() {
281 if ( isset($this->mRelevantTitle
) ) {
282 return $this->mRelevantTitle
;
284 return $this->getTitle();
288 * Set the "relevant" user
289 * @see self::getRelevantUser()
290 * @param $u User object to use
292 public function setRelevantUser( $u ) {
293 $this->mRelevantUser
= $u;
297 * Return the "relevant" user.
298 * A "relevant" user is similar to a relevant title. Special pages like
299 * Special:Contributions mark the user which they are relevant to so that
300 * things like the toolbox can display the information they usually are only
301 * able to display on a user's userpage and talkpage.
303 public function getRelevantUser() {
304 if ( isset($this->mRelevantUser
) ) {
305 return $this->mRelevantUser
;
307 $title = $this->getRelevantTitle();
308 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
309 $rootUser = strtok( $title->getText(), '/' );
310 if ( User
::isIP( $rootUser ) ) {
311 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
313 $user = User
::newFromName( $rootUser );
314 if ( $user->isLoggedIn() ) {
315 $this->mRelevantUser
= $user;
318 return $this->mRelevantUser
;
324 * Outputs the HTML generated by other functions.
325 * @param $out Object: instance of OutputPage
327 abstract function outputPage( OutputPage
$out );
329 static function makeVariablesScript( $data ) {
331 return Html
::inlineScript(
332 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
340 * To make it harder for someone to slip a user a fake
341 * user-JavaScript or user-CSS preview, a random token
342 * is associated with the login session. If it's not
343 * passed back with the preview request, we won't render
346 * @param $action String: 'edit', 'submit' etc.
349 public function userCanPreview( $action ) {
350 if ( $action != 'submit' ) {
353 if ( !$this->getContext()->getRequest()->wasPosted() ) {
356 if ( !$this->getTitle()->userCanEditCssSubpage() ) {
359 if ( !$this->getTitle()->userCanEditJsSubpage() ) {
363 return $this->getContext()->getUser()->matchEditToken(
364 $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
368 * Generated JavaScript action=raw&gen=js
369 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
370 * nated together. For some bizarre reason, it does *not* return any
371 * custom user JS from subpages. Huh?
373 * There's absolutely no reason to have separate Monobook/Common JSes.
374 * Any JS that cares can just check the skin variable generated at the
375 * top. For now Monobook.js will be maintained, but it should be consi-
378 * @param $skinName String: If set, overrides the skin name
381 public function generateUserJs( $skinName = null ) {
383 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
389 * Generate user stylesheet for action=raw&gen=css
391 public function generateUserStylesheet() {
393 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
399 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
400 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
402 protected function reallyGenerateUserStylesheet() {
404 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
412 function setupUserCss( OutputPage
$out ) {
413 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
415 wfProfileIn( __METHOD__
);
417 $this->setupSkinUserCss( $out );
418 // Add any extension CSS
419 foreach ( $out->getExtStyle() as $url ) {
420 $out->addStyle( $url );
423 // Per-site custom styles
424 if ( $wgUseSiteCss ) {
425 $out->addModuleStyles( array( 'site', 'noscript' ) );
426 if( $this->getContext()->getUser()->isLoggedIn() ){
427 $out->addModuleStyles( 'user.groups' );
431 // Per-user custom styles
432 if ( $wgAllowUserCss ) {
433 if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) {
434 // @FIXME: properly escape the cdata!
435 $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
437 $out->addModuleStyles( 'user' );
441 // Per-user preference styles
442 if ( $wgAllowUserCssPrefs ) {
443 $out->addModuleStyles( 'user.options' );
446 wfProfileOut( __METHOD__
);
450 * Get the query to generate a dynamic stylesheet
454 public static function getDynamicStylesheetQuery() {
455 global $wgSquidMaxage;
459 'maxage' => $wgSquidMaxage,
460 'usemsgcache' => 'yes',
461 'ctype' => 'text/css',
462 'smaxage' => $wgSquidMaxage,
467 * Add skin specific stylesheets
468 * @param $out OutputPage
471 abstract function setupSkinUserCss( OutputPage
$out );
473 function getPageClasses( $title ) {
474 $numeric = 'ns-' . $title->getNamespace();
476 if ( $title->getNamespace() == NS_SPECIAL
) {
477 $type = 'ns-special';
478 // bug 23315: provide a class based on the canonical special page name without subpages
479 list( $canonicalName ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
480 if ( $canonicalName ) {
481 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
483 $type .= ' mw-invalidspecialpage';
485 } elseif ( $title->isTalkPage() ) {
488 $type = 'ns-subject';
491 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
493 return "$numeric $type $name";
497 * This will be called by OutputPage::headElement when it is creating the
498 * <body> tag, skins can override it if they have a need to add in any
499 * body attributes or classes of their own.
501 function addToBodyAttributes( $out, &$bodyAttrs ) {
502 // does nothing by default
514 * The format without an explicit $out argument is deprecated
516 function getCategoryLinks( OutputPage
$out=null ) {
517 global $wgUseCategoryBrowser, $wgContLang;
519 if ( count( $out->mCategoryLinks
) == 0 ) {
524 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
526 // Use Unicode bidi embedding override characters,
527 // to make sure links don't smash each other up in ugly ways.
528 $dir = $wgContLang->getDir();
529 $embed = "<span dir='$dir'>";
532 $allCats = $out->getCategoryLinks();
534 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
536 if ( !empty( $allCats['normal'] ) ) {
537 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
539 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
540 $s .= '<div id="mw-normal-catlinks">' .
541 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
542 . $colon . $t . '</div>';
546 if ( isset( $allCats['hidden'] ) ) {
547 if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
548 $class = 'mw-hidden-cats-user-shown';
549 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
550 $class = 'mw-hidden-cats-ns-shown';
552 $class = 'mw-hidden-cats-hidden';
555 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
556 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
557 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
561 # optional 'dmoz-like' category browser. Will be shown under the list
562 # of categories an article belong to
563 if ( $wgUseCategoryBrowser ) {
564 $s .= '<br /><hr />';
566 # get a big array of the parents tree
567 $parenttree = $this->getTitle()->getParentCategoryTree();
568 # Skin object passed by reference cause it can not be
569 # accessed under the method subfunction drawCategoryBrowser
570 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
571 # Clean out bogus first entry and sort them
572 unset( $tempout[0] );
574 # Output one per line
575 $s .= implode( "<br />\n", $tempout );
582 * Render the array as a serie of links.
583 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
584 * @param &skin Object: skin passed by reference
585 * @return String separated by >, terminate with "\n"
587 function drawCategoryBrowser( $tree, &$skin ) {
590 foreach ( $tree as $element => $parent ) {
591 if ( empty( $parent ) ) {
592 # element start a new list
595 # grab the others elements
596 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
599 # add our current element to the list
600 $eltitle = Title
::newFromText( $element );
601 $return .= $skin->link( $eltitle, $eltitle->getText() );
608 * The ->getCategories() form is deprecated, please instead use
609 * the ->getCategories( $out ) form with whatout OutputPage is on hand
611 function getCategories( OutputPage
$out=null ) {
613 $catlinks = $this->getCategoryLinks( $out );
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 * Returns an empty string 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( OutputPage
$out ) {
672 if ( $wgShowDebug ) {
673 $listInternals = $this->formatDebugHTML( $out->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 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
738 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
740 return $bottomScriptText;
743 /** @return string Retrievied from HTML text */
744 function printSource() {
745 $url = htmlspecialchars( $this->getTitle()->getFullURL() );
746 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
749 function getUndeleteLink() {
750 $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
752 if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
753 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
754 $n = $this->getTitle()->isDeleted();
757 if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
758 $msg = 'thisisdeleted';
760 $msg = 'viewdeleted';
766 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
767 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ),
770 array( 'known', 'noclasses' )
780 * The format without an explicit $out argument is deprecated
782 function subPageSubtitle( OutputPage
$out=null ) {
783 $out = $this->getContext()->getOutput();
786 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
790 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
791 $ptext = $this->getTitle()->getPrefixedText();
792 if ( preg_match( '/\//', $ptext ) ) {
793 $links = explode( '/', $ptext );
799 foreach ( $links as $link ) {
800 $growinglink .= $link;
802 $linkObj = Title
::newFromText( $growinglink );
804 if ( is_object( $linkObj ) && $linkObj->exists() ) {
805 $getlink = $this->link(
807 htmlspecialchars( $display ),
810 array( 'known', 'noclasses' )
816 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
818 $subpages .= '< ';
821 $subpages .= $getlink;
835 * Returns true if the IP should be shown in the header
837 function showIPinHeader() {
838 global $wgShowIPinHeader;
839 return $wgShowIPinHeader && session_id() != '';
842 function getSearchLink() {
843 $searchPage = SpecialPage
::getTitleFor( 'Search' );
844 return $searchPage->getLocalURL();
847 function escapeSearchLink() {
848 return htmlspecialchars( $this->getSearchLink() );
851 function getCopyright( $type = 'detect' ) {
852 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
854 if ( $type == 'detect' ) {
855 $diff = $this->getContext()->getRequest()->getVal( 'diff' );
857 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
864 if ( $type == 'history' ) {
865 $msg = 'history_copyright';
872 if ( $wgRightsPage ) {
873 $title = Title
::newFromText( $wgRightsPage );
874 $link = $this->linkKnown( $title, $wgRightsText );
875 } elseif ( $wgRightsUrl ) {
876 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
877 } elseif ( $wgRightsText ) {
878 $link = $wgRightsText;
884 // Allow for site and per-namespace customization of copyright notice.
887 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
890 $out .= wfMsgForContent( $msg, $link );
892 $out .= wfMsg( $msg, $link );
898 function getCopyrightIcon() {
899 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
903 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
904 $out = $wgCopyrightIcon;
905 } elseif ( $wgRightsIcon ) {
906 $icon = htmlspecialchars( $wgRightsIcon );
908 if ( $wgRightsUrl ) {
909 $url = htmlspecialchars( $wgRightsUrl );
910 $out .= '<a href="' . $url . '">';
913 $text = htmlspecialchars( $wgRightsText );
914 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
916 if ( $wgRightsUrl ) {
925 * Gets the powered by MediaWiki icon.
928 function getPoweredBy() {
931 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
932 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
933 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
938 * Get the timestamp of the latest revision, formatted in user language
940 * @param $article Article object. Used if we're working with the current revision
943 protected function lastModified( $article ) {
944 if ( !$this->isRevisionCurrent() ) {
945 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->mRevisionId
);
947 $timestamp = $article->getTimestamp();
951 $d = $this->getContext()->getLang()->date( $timestamp, true );
952 $t = $this->getContext()->getLang()->time( $timestamp, true );
953 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
958 if ( wfGetLB()->getLaggedSlaveMode() ) {
959 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
965 function logoText( $align = '' ) {
966 if ( $align != '' ) {
967 $a = " align='{$align}'";
972 $mp = wfMsg( 'mainpage' );
973 $mptitle = Title
::newMainPage();
974 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
976 $logourl = $this->getLogo();
977 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
983 * Renders a $wgFooterIcons icon acording to the method's arguments
984 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
985 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
987 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
988 if ( is_string( $icon ) ) {
990 } else { // Assuming array
991 $url = isset($icon["url"]) ?
$icon["url"] : null;
992 unset( $icon["url"] );
993 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
994 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
996 $html = htmlspecialchars( $icon["alt"] );
999 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1006 * Gets the link to the wiki's main page.
1009 function mainPageLink() {
1011 Title
::newMainPage(),
1012 wfMsg( 'mainpage' ),
1015 array( 'known', 'noclasses' )
1021 public function footerLink( $desc, $page ) {
1022 // if the link description has been set to "-" in the default language,
1023 if ( wfMsgForContent( $desc ) == '-' ) {
1024 // then it is disabled, for all languages.
1027 // Otherwise, we display the link for the user, described in their
1028 // language (which may or may not be the same as the default language),
1029 // but we make the link target be the one site-wide page.
1030 $title = Title
::newFromText( wfMsgForContent( $page ) );
1032 return $this->linkKnown(
1034 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1040 * Gets the link to the wiki's privacy policy page.
1042 function privacyLink() {
1043 return $this->footerLink( 'privacy', 'privacypage' );
1047 * Gets the link to the wiki's about page.
1049 function aboutLink() {
1050 return $this->footerLink( 'aboutsite', 'aboutpage' );
1054 * Gets the link to the wiki's general disclaimers page.
1056 function disclaimerLink() {
1057 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1061 * Return URL options for the 'edit page' link.
1062 * This may include an 'oldid' specifier, if the current page view is such.
1067 function editUrlOptions() {
1068 $options = array( 'action' => 'edit' );
1070 if ( !$this->isRevisionCurrent() ) {
1071 $options['oldid'] = intval( $this->mRevisionId
);
1077 function showEmailUser( $id ) {
1078 $targetUser = User
::newFromId( $id );
1079 return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1080 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1084 * Return a fully resolved style path url to images or styles stored in the common folder.
1085 * This method returns a url resolved using the configured skin style path
1086 * and includes the style version inside of the url.
1087 * @param $name String: The name or path of a skin resource file
1088 * @return String The fully resolved style path url including styleversion
1090 function getCommonStylePath( $name ) {
1091 global $wgStylePath, $wgStyleVersion;
1092 return "$wgStylePath/common/$name?$wgStyleVersion";
1096 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1097 * This method returns a url resolved using the configured skin style path
1098 * and includes the style version inside of the url.
1099 * @param $name String: The name or path of a skin resource file
1100 * @return String The fully resolved style path url including styleversion
1102 function getSkinStylePath( $name ) {
1103 global $wgStylePath, $wgStyleVersion;
1104 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1107 /* these are used extensively in SkinTemplate, but also some other places */
1108 static function makeMainPageUrl( $urlaction = '' ) {
1109 $title = Title
::newMainPage();
1110 self
::checkTitle( $title, '' );
1112 return $title->getLocalURL( $urlaction );
1115 static function makeSpecialUrl( $name, $urlaction = '' ) {
1116 $title = SpecialPage
::getTitleFor( $name );
1117 return $title->getLocalURL( $urlaction );
1120 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1121 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1122 return $title->getLocalURL( $urlaction );
1125 static function makeI18nUrl( $name, $urlaction = '' ) {
1126 $title = Title
::newFromText( wfMsgForContent( $name ) );
1127 self
::checkTitle( $title, $name );
1128 return $title->getLocalURL( $urlaction );
1131 static function makeUrl( $name, $urlaction = '' ) {
1132 $title = Title
::newFromText( $name );
1133 self
::checkTitle( $title, $name );
1135 return $title->getLocalURL( $urlaction );
1139 * If url string starts with http, consider as external URL, else
1142 static function makeInternalOrExternalUrl( $name ) {
1143 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1146 return self
::makeUrl( $name );
1150 # this can be passed the NS number as defined in Language.php
1151 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1152 $title = Title
::makeTitleSafe( $namespace, $name );
1153 self
::checkTitle( $title, $name );
1155 return $title->getLocalURL( $urlaction );
1158 /* these return an array with the 'href' and boolean 'exists' */
1159 static function makeUrlDetails( $name, $urlaction = '' ) {
1160 $title = Title
::newFromText( $name );
1161 self
::checkTitle( $title, $name );
1164 'href' => $title->getLocalURL( $urlaction ),
1165 'exists' => $title->getArticleID() != 0,
1170 * Make URL details where the article exists (or at least it's convenient to think so)
1172 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1173 $title = Title
::newFromText( $name );
1174 self
::checkTitle( $title, $name );
1177 'href' => $title->getLocalURL( $urlaction ),
1182 # make sure we have some title to operate on
1183 static function checkTitle( &$title, $name ) {
1184 if ( !is_object( $title ) ) {
1185 $title = Title
::newFromText( $name );
1186 if ( !is_object( $title ) ) {
1187 $title = Title
::newFromText( '--error: link target missing--' );
1193 * Build an array that represents the sidebar(s), the navigation bar among them
1197 function buildSidebar() {
1198 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1199 wfProfileIn( __METHOD__
);
1201 $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
1203 if ( $wgEnableSidebarCache ) {
1204 $cachedsidebar = $parserMemc->get( $key );
1205 if ( $cachedsidebar ) {
1206 wfProfileOut( __METHOD__
);
1207 return $cachedsidebar;
1212 $this->addToSidebar( $bar, 'sidebar' );
1214 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1215 if ( $wgEnableSidebarCache ) {
1216 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1219 wfProfileOut( __METHOD__
);
1223 * Add content from a sidebar system message
1224 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1226 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1228 * @param &$bar array
1229 * @param $message String
1231 function addToSidebar( &$bar, $message ) {
1232 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1236 * Add content from plain text
1238 * @param &$bar array
1239 * @param $text string
1241 function addToSidebarPlain( &$bar, $text ) {
1242 $lines = explode( "\n", $text );
1243 $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.
1247 foreach ( $lines as $line ) {
1248 if ( strpos( $line, '*' ) !== 0 ) {
1252 if ( strpos( $line, '**' ) !== 0 ) {
1253 $heading = trim( $line, '* ' );
1254 if ( !array_key_exists( $heading, $bar ) ) {
1255 $bar[$heading] = array();
1258 $line = trim( $line, '* ' );
1260 if ( strpos( $line, '|' ) !== false ) { // sanity check
1261 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1262 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1263 $link = wfMsgForContent( $line[0] );
1265 if ( $link == '-' ) {
1269 $text = wfMsgExt( $line[1], 'parsemag' );
1271 if ( wfEmptyMsg( $line[1] ) ) {
1275 if ( wfEmptyMsg( $line[0] ) ) {
1279 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1282 $title = Title
::newFromText( $link );
1285 $title = $title->fixSpecialName();
1286 $href = $title->getLocalURL();
1288 $href = 'INVALID-TITLE';
1292 $bar[$heading][] = array(
1295 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1298 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1301 $line = substr( $line, 2, strlen( $line ) - 4 );
1303 $options = new ParserOptions();
1304 $options->setEditSection( false );
1305 $options->setInterfaceMessage( true );
1306 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
1313 if ( count( $wikiBar ) > 0 ) {
1314 $bar = array_merge( $bar, $wikiBar );
1321 * Should we include common/wikiprintable.css? Skins that have their own
1322 * print stylesheet should override this and return false. (This is an
1323 * ugly hack to get Monobook to play nicely with
1324 * OutputPage::headElement().)
1328 public function commonPrintStylesheet() {
1333 * Gets new talk page messages for the current user.
1334 * @return MediaWiki message or if no new talk page messages, nothing
1336 function getNewtalks() {
1337 $out = $this->getContext()->getOutput();
1339 $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
1342 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1343 $userTitle = $this->getUser()->getUserPage();
1344 $userTalkTitle = $userTitle->getTalkPage();
1346 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1347 $newMessagesLink = $this->link(
1349 wfMsgHtml( 'newmessageslink' ),
1351 array( 'redirect' => 'no' ),
1352 array( 'known', 'noclasses' )
1355 $newMessagesDiffLink = $this->link(
1357 wfMsgHtml( 'newmessagesdifflink' ),
1359 array( 'diff' => 'cur' ),
1360 array( 'known', 'noclasses' )
1364 'youhavenewmessages',
1366 $newMessagesDiffLink
1368 # Disable Squid cache
1369 $out->setSquidMaxage( 0 );
1371 } elseif ( count( $newtalks ) ) {
1372 // _>" " for BC <= 1.16
1373 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1376 foreach ( $newtalks as $newtalk ) {
1377 $msgs[] = Xml
::element(
1379 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1382 $parts = implode( $sep, $msgs );
1383 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1384 $out->setSquidMaxage( 0 );
1391 * Get a cached notice
1393 * @param $name String: message name, or 'default' for $wgSiteNotice
1394 * @return String: HTML fragment
1396 private function getCachedNotice( $name ) {
1397 global $wgRenderHashAppend, $parserMemc;
1399 wfProfileIn( __METHOD__
);
1403 if( $name === 'default' ) {
1405 global $wgSiteNotice;
1406 $notice = $wgSiteNotice;
1407 if( empty( $notice ) ) {
1408 wfProfileOut( __METHOD__
);
1412 $msg = wfMessage( $name )->inContentLanguage();
1413 if( $msg->isDisabled() ) {
1414 wfProfileOut( __METHOD__
);
1417 $notice = $msg->plain();
1420 // Use the extra hash appender to let eg SSL variants separately cache.
1421 $key = wfMemcKey( $name . $wgRenderHashAppend );
1422 $cachedNotice = $parserMemc->get( $key );
1423 if( is_array( $cachedNotice ) ) {
1424 if( md5( $notice ) == $cachedNotice['hash'] ) {
1425 $notice = $cachedNotice['html'];
1434 $parsed = $this->getContext()->getOutput()->parse( $notice );
1435 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1439 $notice = '<div id="localNotice">' .$notice . '</div>';
1440 wfProfileOut( __METHOD__
);
1445 * Get a notice based on page's namespace
1447 * @return String: HTML fragment
1449 function getNamespaceNotice() {
1450 wfProfileIn( __METHOD__
);
1452 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1453 $namespaceNotice = $this->getCachedNotice( $key );
1454 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1455 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1457 $namespaceNotice = '';
1460 wfProfileOut( __METHOD__
);
1461 return $namespaceNotice;
1465 * Get the site notice
1467 * @return String: HTML fragment
1469 function getSiteNotice() {
1470 wfProfileIn( __METHOD__
);
1473 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1474 if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) {
1475 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1477 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1478 if ( !$anonNotice ) {
1479 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1481 $siteNotice = $anonNotice;
1484 if ( !$siteNotice ) {
1485 $siteNotice = $this->getCachedNotice( 'default' );
1489 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1490 wfProfileOut( __METHOD__
);
1495 * Create a section edit link. This supersedes editSectionLink() and
1496 * editSectionLinkForOther().
1498 * @param $nt Title The title being linked to (may not be the same as
1499 * $wgTitle, if the section is included from a template)
1500 * @param $section string The designation of the section being pointed to,
1501 * to be included in the link, like "§ion=$section"
1502 * @param $tooltip string The tooltip to use for the link: will be escaped
1503 * and wrapped in the 'editsectionhint' message
1504 * @param $lang string Language code
1505 * @return string HTML to use for edit link
1507 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1508 // HTML generated here should probably have userlangattributes
1509 // added to it for LTR text on RTL pages
1511 if ( !is_null( $tooltip ) ) {
1512 # Bug 25462: undo double-escaping.
1513 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1514 $attribs['title'] = wfMsgReal( 'editsectionhint', array( $tooltip ), true, $lang );
1516 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1518 array( 'action' => 'edit', 'section' => $section ),
1519 array( 'noclasses', 'known' )
1522 # Run the old hook. This takes up half of the function . . . hopefully
1523 # we can rid of it someday.
1526 $attribs = htmlspecialchars( wfMsgReal( 'editsectionhint', array( $tooltip ), true, $lang ) );
1527 $attribs = " title=\"$attribs\"";
1530 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1531 if ( !is_null( $result ) ) {
1532 # For reverse compatibility, add the brackets *after* the hook is
1533 # run, and even add them to hook-provided text. (This is the main
1534 # reason that the EditSectionLink hook is deprecated in favor of
1535 # DoEditSectionLink: it can't change the brackets or the span.)
1536 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1537 return "<span class=\"editsection\">$result</span>";
1540 # Add the brackets and the span, and *then* run the nice new hook, with
1541 # clean and non-redundant arguments.
1542 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1543 $result = "<span class=\"editsection\">$result</span>";
1545 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1550 * Use PHP's magic __call handler to intercept legacy calls to the linker
1551 * for backwards compatibility.
1553 * @param $fname String Name of called method
1554 * @param $args Array Arguments to the method
1556 function __call( $fname, $args ) {
1557 $realFunction = array( 'Linker', $fname );
1558 if ( is_callable( $realFunction ) ) {
1559 return call_user_func_array( $realFunction, $args );
1561 $className = get_class( $this );
1562 throw new MWException( "Call to undefined method $className::$fname" );