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
{
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 ( !MWInit
::classExists( $className ) ) {
143 if ( !defined( 'MW_COMPILED' ) ) {
144 // Preload base classes to work around APC/PHP5 bug
145 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
146 if ( file_exists( $deps ) ) {
147 include_once( $deps );
149 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
152 # Check if we got if not failback to default skin
153 if ( !MWInit
::classExists( $className ) ) {
154 # DO NOT die if the class isn't found. This breaks maintenance
155 # scripts and can cause a user account to be unrecoverable
156 # except by SQL manipulation if a previously valid skin name
157 # is no longer valid.
158 wfDebug( "Skin class does not exist: $className\n" );
159 $className = 'SkinVector';
160 if ( !defined( 'MW_COMPILED' ) ) {
161 require_once( "{$wgStyleDirectory}/Vector.php" );
165 $skin = new $className;
169 /** @return string path to the skin stylesheet */
170 function getStylesheet() {
171 return 'common/wikistandard.css';
174 /** @return string skin name */
175 public function getSkinName() {
176 return $this->skinname
;
179 function initPage( OutputPage
$out ) {
180 wfProfileIn( __METHOD__
);
182 $this->mRevisionId
= $out->mRevisionId
;
183 $this->preloadExistence();
186 wfProfileOut( __METHOD__
);
190 * Preload the existence of three commonly-requested pages in a single query
192 function preloadExistence() {
194 $titles = array( $this->getUser()->getUserPage(), $this->getUser()->getTalkPage() );
197 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
199 } elseif ( $this->getTitle()->isTalkPage() ) {
200 $titles[] = $this->getTitle()->getSubjectPage();
202 $titles[] = $this->getTitle()->getTalkPage();
205 $lb = new LinkBatch( $titles );
206 $lb->setCaller( __METHOD__
);
211 * Set some local variables
213 protected function setMembers() {
214 $this->userpage
= $this->getUser()->getUserPage()->getPrefixedText();
215 $this->usercss
= false;
219 * Whether the revision displayed is the latest revision of the page
223 public function isRevisionCurrent() {
224 return $this->mRevisionId
== 0 ||
$this->mRevisionId
== $this->getTitle()->getLatestRevID();
228 * Get the RequestContext used in this instance
230 * @return RequestContext
232 public function getContext() {
233 if ( !parent
::getContext() instanceof RequestContext
) {
234 wfDebug( __METHOD__
. " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
235 $this->setContext( RequestContext
::getMain() );
237 return parent
::getContext();
241 * Set the "relevant" title
242 * @see self::getRelevantTitle()
243 * @param $t Title object to use
245 public function setRelevantTitle( $t ) {
246 $this->mRelevantTitle
= $t;
250 * Return the "relevant" title.
251 * A "relevant" title is not necessarily the actual title of the page.
252 * Special pages like Special:MovePage use set the page they are acting on
253 * as their "relevant" title, this allows the skin system to display things
254 * such as content tabs which belong to to that page instead of displaying
255 * a basic special page tab which has almost no meaning.
257 public function getRelevantTitle() {
258 if ( isset($this->mRelevantTitle
) ) {
259 return $this->mRelevantTitle
;
261 return $this->getTitle();
265 * Set the "relevant" user
266 * @see self::getRelevantUser()
267 * @param $u User object to use
269 public function setRelevantUser( $u ) {
270 $this->mRelevantUser
= $u;
274 * Return the "relevant" user.
275 * A "relevant" user is similar to a relevant title. Special pages like
276 * Special:Contributions mark the user which they are relevant to so that
277 * things like the toolbox can display the information they usually are only
278 * able to display on a user's userpage and talkpage.
281 public function getRelevantUser() {
282 if ( isset($this->mRelevantUser
) ) {
283 return $this->mRelevantUser
;
285 $title = $this->getRelevantTitle();
286 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
287 $rootUser = strtok( $title->getText(), '/' );
288 if ( User
::isIP( $rootUser ) ) {
289 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
291 $user = User
::newFromName( $rootUser );
292 if ( $user->isLoggedIn() ) {
293 $this->mRelevantUser
= $user;
296 return $this->mRelevantUser
;
302 * Outputs the HTML generated by other functions.
303 * @param $out Object: instance of OutputPage
305 abstract function outputPage( OutputPage
$out );
307 static function makeVariablesScript( $data ) {
309 return Html
::inlineScript(
310 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
318 * To make it harder for someone to slip a user a fake
319 * user-JavaScript or user-CSS preview, a random token
320 * is associated with the login session. If it's not
321 * passed back with the preview request, we won't render
324 * @param $action String: 'edit', 'submit' etc.
327 public function userCanPreview( $action ) {
328 if ( $action != 'submit' ) {
331 if ( !$this->getRequest()->wasPosted() ) {
334 if ( !$this->getTitle()->userCanEditCssSubpage() ) {
337 if ( !$this->getTitle()->userCanEditJsSubpage() ) {
341 return $this->getUser()->matchEditToken(
342 $this->getRequest()->getVal( 'wpEditToken' ) );
346 * Generated JavaScript action=raw&gen=js
347 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
348 * nated together. For some bizarre reason, it does *not* return any
349 * custom user JS from subpages. Huh?
351 * There's absolutely no reason to have separate Monobook/Common JSes.
352 * Any JS that cares can just check the skin variable generated at the
353 * top. For now Monobook.js will be maintained, but it should be consi-
356 * @param $skinName String: If set, overrides the skin name
359 public function generateUserJs( $skinName = null ) {
361 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
367 * Generate user stylesheet for action=raw&gen=css
369 public function generateUserStylesheet() {
371 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
377 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
378 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
380 protected function reallyGenerateUserStylesheet() {
382 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
390 function setupUserCss( OutputPage
$out ) {
391 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
393 wfProfileIn( __METHOD__
);
395 $this->setupSkinUserCss( $out );
396 // Add any extension CSS
397 foreach ( $out->getExtStyle() as $url ) {
398 $out->addStyle( $url );
401 // Per-site custom styles
402 if ( $wgUseSiteCss ) {
403 $out->addModuleStyles( array( 'site', 'noscript' ) );
404 if( $this->getUser()->isLoggedIn() ){
405 $out->addModuleStyles( 'user.groups' );
409 // Per-user custom styles
410 if ( $wgAllowUserCss ) {
411 if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getRequest()->getVal( 'action' ) ) ) {
412 // @FIXME: properly escape the cdata!
413 $out->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
415 $out->addModuleStyles( 'user' );
419 // Per-user preference styles
420 if ( $wgAllowUserCssPrefs ) {
421 $out->addModuleStyles( 'user.options' );
424 wfProfileOut( __METHOD__
);
428 * Get the query to generate a dynamic stylesheet
432 public static function getDynamicStylesheetQuery() {
433 global $wgSquidMaxage;
437 'maxage' => $wgSquidMaxage,
438 'usemsgcache' => 'yes',
439 'ctype' => 'text/css',
440 'smaxage' => $wgSquidMaxage,
445 * Add skin specific stylesheets
446 * @param $out OutputPage
449 abstract function setupSkinUserCss( OutputPage
$out );
453 * @param $title Title
456 function getPageClasses( $title ) {
457 $numeric = 'ns-' . $title->getNamespace();
459 if ( $title->getNamespace() == NS_SPECIAL
) {
460 $type = 'ns-special';
461 // bug 23315: provide a class based on the canonical special page name without subpages
462 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
463 if ( $canonicalName ) {
464 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
466 $type .= ' mw-invalidspecialpage';
468 } elseif ( $title->isTalkPage() ) {
471 $type = 'ns-subject';
474 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
476 return "$numeric $type $name";
480 * This will be called by OutputPage::headElement when it is creating the
481 * <body> tag, skins can override it if they have a need to add in any
482 * body attributes or classes of their own.
484 function addToBodyAttributes( $out, &$bodyAttrs ) {
485 // does nothing by default
497 * The format without an explicit $out argument is deprecated
499 function getCategoryLinks( OutputPage
$out=null ) {
500 global $wgUseCategoryBrowser, $wgContLang;
503 $out = $this->getOutput();
506 if ( count( $out->mCategoryLinks
) == 0 ) {
511 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
513 // Use Unicode bidi embedding override characters,
514 // to make sure links don't smash each other up in ugly ways.
515 $dir = $wgContLang->getDir();
516 $embed = "<span dir='$dir'>";
519 $allCats = $out->getCategoryLinks();
521 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
523 if ( !empty( $allCats['normal'] ) ) {
524 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
526 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
527 $s .= '<div id="mw-normal-catlinks">' .
528 Linker
::link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
529 . $colon . $t . '</div>';
533 if ( isset( $allCats['hidden'] ) ) {
534 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
535 $class = 'mw-hidden-cats-user-shown';
536 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
537 $class = 'mw-hidden-cats-ns-shown';
539 $class = 'mw-hidden-cats-hidden';
542 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
543 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
544 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
548 # optional 'dmoz-like' category browser. Will be shown under the list
549 # of categories an article belong to
550 if ( $wgUseCategoryBrowser ) {
551 $s .= '<br /><hr />';
553 # get a big array of the parents tree
554 $parenttree = $this->getTitle()->getParentCategoryTree();
555 # Skin object passed by reference cause it can not be
556 # accessed under the method subfunction drawCategoryBrowser
557 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
558 # Clean out bogus first entry and sort them
559 unset( $tempout[0] );
561 # Output one per line
562 $s .= implode( "<br />\n", $tempout );
569 * Render the array as a serie of links.
570 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
571 * @return String separated by >, terminate with "\n"
573 function drawCategoryBrowser( $tree ) {
576 foreach ( $tree as $element => $parent ) {
577 if ( empty( $parent ) ) {
578 # element start a new list
581 # grab the others elements
582 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
585 # add our current element to the list
586 $eltitle = Title
::newFromText( $element );
587 $return .= Linker
::link( $eltitle, $eltitle->getText() );
594 * The ->getCategories() form is deprecated, please instead use
595 * the ->getCategories( $out ) form with whatout OutputPage is on hand
597 function getCategories( OutputPage
$out=null ) {
599 $catlinks = $this->getCategoryLinks( $out );
601 $classes = 'catlinks';
603 // Check what we're showing
604 $allCats = $out->getCategoryLinks();
605 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
606 $this->getTitle()->getNamespace() == NS_CATEGORY
;
608 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
609 $classes .= ' catlinks-allhidden';
612 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
616 * This runs a hook to allow extensions placing their stuff after content
617 * and article metadata (e.g. categories).
618 * Note: This function has nothing to do with afterContent().
620 * This hook is placed here in order to allow using the same hook for all
621 * skins, both the SkinTemplate based ones and the older ones, which directly
622 * use this class to get their data.
624 * The output of this function gets processed in SkinTemplate::outputPage() for
625 * the SkinTemplate based skins, all other skins should directly echo it.
627 * Returns an empty string by default, if not changed by any hook function.
629 protected function afterContentHook() {
632 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
633 // adding just some spaces shouldn't toggle the output
634 // of the whole <div/>, so we use trim() here
635 if ( trim( $data ) != '' ) {
636 // Doing this here instead of in the skins to
637 // ensure that the div has the same ID in all
639 $data = "<div id='mw-data-after-content'>\n" .
644 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
651 * Generate debug data HTML for displaying at the bottom of the main content
653 * @return String HTML containing debug data, if enabled (otherwise empty).
655 protected function generateDebugHTML( OutputPage
$out ) {
658 if ( $wgShowDebug ) {
659 $listInternals = $this->formatDebugHTML( $out->mDebugtext
);
660 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
661 $listInternals . "</ul>\n";
667 private function formatDebugHTML( $debugText ) {
668 global $wgDebugTimestamps;
670 $lines = explode( "\n", $debugText );
674 foreach ( $lines as $line ) {
676 if ( $wgDebugTimestamps ) {
678 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
680 $line = substr( $line, strlen( $pre ) );
683 $display = ltrim( $line );
684 $ident = strlen( $line ) - strlen( $display );
685 $diff = $ident - $curIdent;
687 $display = $pre . $display;
688 if ( $display == '' ) {
689 $display = "\xc2\xa0";
692 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
695 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
697 $display = htmlspecialchars( $display );
701 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
702 } elseif ( $diff == 0 ) {
703 $ret .= "</li><li>\n";
705 $ret .= str_repeat( "<ul><li>\n", $diff );
707 $ret .= "<tt>$display</tt>\n";
712 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
718 * This gets called shortly before the </body> tag.
719 * @param $out OutputPage object
720 * @return String HTML-wrapped JS code to be put before </body>
722 function bottomScripts( $out ) {
723 // TODO and the suckage continues. This function is really just a wrapper around
724 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
726 $bottomScriptText = $out->getBottomScripts( $this );
727 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
729 return $bottomScriptText;
732 /** @return string Retrievied from HTML text */
733 function printSource() {
734 $url = htmlspecialchars( $this->getTitle()->getFullURL() );
735 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
738 function getUndeleteLink() {
739 $action = $this->getRequest()->getVal( 'action', 'view' );
741 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
742 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
743 $n = $this->getTitle()->isDeleted();
746 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
747 $msg = 'thisisdeleted';
749 $msg = 'viewdeleted';
755 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
756 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) ),
759 array( 'known', 'noclasses' )
769 * The format with an explicit $out argument is deprecated
771 function subPageSubtitle( OutputPage
$out=null ) {
772 $out = $this->getOutput();
775 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
779 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
780 $ptext = $this->getTitle()->getPrefixedText();
781 if ( preg_match( '/\//', $ptext ) ) {
782 $links = explode( '/', $ptext );
788 foreach ( $links as $link ) {
789 $growinglink .= $link;
791 $linkObj = Title
::newFromText( $growinglink );
793 if ( is_object( $linkObj ) && $linkObj->exists() ) {
794 $getlink = Linker
::link(
796 htmlspecialchars( $display ),
799 array( 'known', 'noclasses' )
805 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
807 $subpages .= '< ';
810 $subpages .= $getlink;
824 * Returns true if the IP should be shown in the header
826 function showIPinHeader() {
827 global $wgShowIPinHeader;
828 return $wgShowIPinHeader && session_id() != '';
831 function getSearchLink() {
832 $searchPage = SpecialPage
::getTitleFor( 'Search' );
833 return $searchPage->getLocalURL();
836 function escapeSearchLink() {
837 return htmlspecialchars( $this->getSearchLink() );
840 function getCopyright( $type = 'detect' ) {
841 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
843 if ( $type == 'detect' ) {
844 $diff = $this->getRequest()->getVal( 'diff' );
846 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
853 if ( $type == 'history' ) {
854 $msg = 'history_copyright';
861 if ( $wgRightsPage ) {
862 $title = Title
::newFromText( $wgRightsPage );
863 $link = Linker
::linkKnown( $title, $wgRightsText );
864 } elseif ( $wgRightsUrl ) {
865 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
866 } elseif ( $wgRightsText ) {
867 $link = $wgRightsText;
873 // Allow for site and per-namespace customization of copyright notice.
876 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
879 $out .= wfMsgForContent( $msg, $link );
881 $out .= wfMsg( $msg, $link );
887 function getCopyrightIcon() {
888 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
892 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
893 $out = $wgCopyrightIcon;
894 } elseif ( $wgRightsIcon ) {
895 $icon = htmlspecialchars( $wgRightsIcon );
897 if ( $wgRightsUrl ) {
898 $url = htmlspecialchars( $wgRightsUrl );
899 $out .= '<a href="' . $url . '">';
902 $text = htmlspecialchars( $wgRightsText );
903 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
905 if ( $wgRightsUrl ) {
914 * Gets the powered by MediaWiki icon.
917 function getPoweredBy() {
920 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
921 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
922 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
927 * Get the timestamp of the latest revision, formatted in user language
929 * @param $article Article object. Used if we're working with the current revision
932 protected function lastModified( $article ) {
933 if ( !$this->isRevisionCurrent() ) {
934 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->mRevisionId
);
936 $timestamp = $article->getTimestamp();
940 $d = $this->getLang()->date( $timestamp, true );
941 $t = $this->getLang()->time( $timestamp, true );
942 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
947 if ( wfGetLB()->getLaggedSlaveMode() ) {
948 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
954 function logoText( $align = '' ) {
955 if ( $align != '' ) {
956 $a = " align='{$align}'";
961 $mp = wfMsg( 'mainpage' );
962 $mptitle = Title
::newMainPage();
963 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
965 $logourl = $this->getLogo();
966 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
972 * Renders a $wgFooterIcons icon acording to the method's arguments
973 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
974 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
976 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
977 if ( is_string( $icon ) ) {
979 } else { // Assuming array
980 $url = isset($icon["url"]) ?
$icon["url"] : null;
981 unset( $icon["url"] );
982 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
983 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
985 $html = htmlspecialchars( $icon["alt"] );
988 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
995 * Gets the link to the wiki's main page.
998 function mainPageLink() {
1000 Title
::newMainPage(),
1001 wfMsg( 'mainpage' ),
1004 array( 'known', 'noclasses' )
1010 public function footerLink( $desc, $page ) {
1011 // if the link description has been set to "-" in the default language,
1012 if ( wfMsgForContent( $desc ) == '-' ) {
1013 // then it is disabled, for all languages.
1016 // Otherwise, we display the link for the user, described in their
1017 // language (which may or may not be the same as the default language),
1018 // but we make the link target be the one site-wide page.
1019 $title = Title
::newFromText( wfMsgForContent( $page ) );
1021 return Linker
::linkKnown(
1023 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1029 * Gets the link to the wiki's privacy policy page.
1031 function privacyLink() {
1032 return $this->footerLink( 'privacy', 'privacypage' );
1036 * Gets the link to the wiki's about page.
1038 function aboutLink() {
1039 return $this->footerLink( 'aboutsite', 'aboutpage' );
1043 * Gets the link to the wiki's general disclaimers page.
1045 function disclaimerLink() {
1046 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1050 * Return URL options for the 'edit page' link.
1051 * This may include an 'oldid' specifier, if the current page view is such.
1056 function editUrlOptions() {
1057 $options = array( 'action' => 'edit' );
1059 if ( !$this->isRevisionCurrent() ) {
1060 $options['oldid'] = intval( $this->mRevisionId
);
1066 function showEmailUser( $id ) {
1067 $targetUser = User
::newFromId( $id );
1068 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1069 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1073 * Return a fully resolved style path url to images or styles stored in the common folder.
1074 * This method returns a url resolved using the configured skin style path
1075 * and includes the style version inside of the url.
1076 * @param $name String: The name or path of a skin resource file
1077 * @return String The fully resolved style path url including styleversion
1079 function getCommonStylePath( $name ) {
1080 global $wgStylePath, $wgStyleVersion;
1081 return "$wgStylePath/common/$name?$wgStyleVersion";
1085 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1086 * This method returns a url resolved using the configured skin style path
1087 * and includes the style version inside of the url.
1088 * @param $name String: The name or path of a skin resource file
1089 * @return String The fully resolved style path url including styleversion
1091 function getSkinStylePath( $name ) {
1092 global $wgStylePath, $wgStyleVersion;
1093 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1096 /* these are used extensively in SkinTemplate, but also some other places */
1097 static function makeMainPageUrl( $urlaction = '' ) {
1098 $title = Title
::newMainPage();
1099 self
::checkTitle( $title, '' );
1101 return $title->getLocalURL( $urlaction );
1104 static function makeSpecialUrl( $name, $urlaction = '' ) {
1105 $title = SpecialPage
::getSafeTitleFor( $name );
1106 return $title->getLocalURL( $urlaction );
1109 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1110 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1111 return $title->getLocalURL( $urlaction );
1114 static function makeI18nUrl( $name, $urlaction = '' ) {
1115 $title = Title
::newFromText( wfMsgForContent( $name ) );
1116 self
::checkTitle( $title, $name );
1117 return $title->getLocalURL( $urlaction );
1120 static function makeUrl( $name, $urlaction = '' ) {
1121 $title = Title
::newFromText( $name );
1122 self
::checkTitle( $title, $name );
1124 return $title->getLocalURL( $urlaction );
1128 * If url string starts with http, consider as external URL, else
1131 static function makeInternalOrExternalUrl( $name ) {
1132 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1135 return self
::makeUrl( $name );
1139 # this can be passed the NS number as defined in Language.php
1140 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1141 $title = Title
::makeTitleSafe( $namespace, $name );
1142 self
::checkTitle( $title, $name );
1144 return $title->getLocalURL( $urlaction );
1147 /* these return an array with the 'href' and boolean 'exists' */
1148 static function makeUrlDetails( $name, $urlaction = '' ) {
1149 $title = Title
::newFromText( $name );
1150 self
::checkTitle( $title, $name );
1153 'href' => $title->getLocalURL( $urlaction ),
1154 'exists' => $title->getArticleID() != 0,
1159 * Make URL details where the article exists (or at least it's convenient to think so)
1161 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1162 $title = Title
::newFromText( $name );
1163 self
::checkTitle( $title, $name );
1166 'href' => $title->getLocalURL( $urlaction ),
1171 # make sure we have some title to operate on
1172 static function checkTitle( &$title, $name ) {
1173 if ( !is_object( $title ) ) {
1174 $title = Title
::newFromText( $name );
1175 if ( !is_object( $title ) ) {
1176 $title = Title
::newFromText( '--error: link target missing--' );
1182 * Build an array that represents the sidebar(s), the navigation bar among them
1186 function buildSidebar() {
1187 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1188 wfProfileIn( __METHOD__
);
1190 $key = wfMemcKey( 'sidebar', $this->getLang()->getCode() );
1192 if ( $wgEnableSidebarCache ) {
1193 $cachedsidebar = $parserMemc->get( $key );
1194 if ( $cachedsidebar ) {
1195 wfProfileOut( __METHOD__
);
1196 return $cachedsidebar;
1201 $this->addToSidebar( $bar, 'sidebar' );
1203 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1204 if ( $wgEnableSidebarCache ) {
1205 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1208 wfProfileOut( __METHOD__
);
1212 * Add content from a sidebar system message
1213 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1215 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1217 * @param &$bar array
1218 * @param $message String
1220 function addToSidebar( &$bar, $message ) {
1221 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1225 * Add content from plain text
1227 * @param &$bar array
1228 * @param $text string
1230 function addToSidebarPlain( &$bar, $text ) {
1231 $lines = explode( "\n", $text );
1232 $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.
1236 foreach ( $lines as $line ) {
1237 if ( strpos( $line, '*' ) !== 0 ) {
1241 if ( strpos( $line, '**' ) !== 0 ) {
1242 $heading = trim( $line, '* ' );
1243 if ( !array_key_exists( $heading, $bar ) ) {
1244 $bar[$heading] = array();
1247 $line = trim( $line, '* ' );
1249 if ( strpos( $line, '|' ) !== false ) { // sanity check
1250 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1251 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1252 $link = wfMsgForContent( $line[0] );
1254 if ( $link == '-' ) {
1258 $text = wfMsgExt( $line[1], 'parsemag' );
1260 if ( wfEmptyMsg( $line[1] ) ) {
1264 if ( wfEmptyMsg( $line[0] ) ) {
1268 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1271 $title = Title
::newFromText( $link );
1274 $title = $title->fixSpecialName();
1275 $href = $title->getLocalURL();
1277 $href = 'INVALID-TITLE';
1281 $bar[$heading][] = array(
1284 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1287 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1290 $line = substr( $line, 2, strlen( $line ) - 4 );
1292 $options = new ParserOptions();
1293 $options->setEditSection( false );
1294 $options->setInterfaceMessage( true );
1295 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
1302 if ( count( $wikiBar ) > 0 ) {
1303 $bar = array_merge( $bar, $wikiBar );
1310 * Should we include common/wikiprintable.css? Skins that have their own
1311 * print stylesheet should override this and return false. (This is an
1312 * ugly hack to get Monobook to play nicely with
1313 * OutputPage::headElement().)
1317 public function commonPrintStylesheet() {
1322 * Gets new talk page messages for the current user.
1323 * @return MediaWiki message or if no new talk page messages, nothing
1325 function getNewtalks() {
1326 $out = $this->getOutput();
1328 $newtalks = $this->getUser()->getNewMessageLinks();
1331 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1332 $userTitle = $this->getUser()->getUserPage();
1333 $userTalkTitle = $userTitle->getTalkPage();
1335 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1336 $newMessagesLink = Linker
::link(
1338 wfMsgHtml( 'newmessageslink' ),
1340 array( 'redirect' => 'no' ),
1341 array( 'known', 'noclasses' )
1344 $newMessagesDiffLink = Linker
::link(
1346 wfMsgHtml( 'newmessagesdifflink' ),
1348 array( 'diff' => 'cur' ),
1349 array( 'known', 'noclasses' )
1353 'youhavenewmessages',
1355 $newMessagesDiffLink
1357 # Disable Squid cache
1358 $out->setSquidMaxage( 0 );
1360 } elseif ( count( $newtalks ) ) {
1361 // _>" " for BC <= 1.16
1362 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1365 foreach ( $newtalks as $newtalk ) {
1366 $msgs[] = Xml
::element(
1368 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1371 $parts = implode( $sep, $msgs );
1372 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1373 $out->setSquidMaxage( 0 );
1380 * Get a cached notice
1382 * @param $name String: message name, or 'default' for $wgSiteNotice
1383 * @return String: HTML fragment
1385 private function getCachedNotice( $name ) {
1386 global $wgRenderHashAppend, $parserMemc;
1388 wfProfileIn( __METHOD__
);
1392 if( $name === 'default' ) {
1394 global $wgSiteNotice;
1395 $notice = $wgSiteNotice;
1396 if( empty( $notice ) ) {
1397 wfProfileOut( __METHOD__
);
1401 $msg = wfMessage( $name )->inContentLanguage();
1402 if( $msg->isDisabled() ) {
1403 wfProfileOut( __METHOD__
);
1406 $notice = $msg->plain();
1409 // Use the extra hash appender to let eg SSL variants separately cache.
1410 $key = wfMemcKey( $name . $wgRenderHashAppend );
1411 $cachedNotice = $parserMemc->get( $key );
1412 if( is_array( $cachedNotice ) ) {
1413 if( md5( $notice ) == $cachedNotice['hash'] ) {
1414 $notice = $cachedNotice['html'];
1423 $parsed = $this->getOutput()->parse( $notice );
1424 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1428 $notice = '<div id="localNotice">' .$notice . '</div>';
1429 wfProfileOut( __METHOD__
);
1434 * Get a notice based on page's namespace
1436 * @return String: HTML fragment
1438 function getNamespaceNotice() {
1439 wfProfileIn( __METHOD__
);
1441 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1442 $namespaceNotice = $this->getCachedNotice( $key );
1443 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1444 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1446 $namespaceNotice = '';
1449 wfProfileOut( __METHOD__
);
1450 return $namespaceNotice;
1454 * Get the site notice
1456 * @return String: HTML fragment
1458 function getSiteNotice() {
1459 wfProfileIn( __METHOD__
);
1462 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1463 if ( $this->getUser() instanceof User
&& $this->getUser()->isLoggedIn() ) {
1464 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1466 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1467 if ( !$anonNotice ) {
1468 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1470 $siteNotice = $anonNotice;
1473 if ( !$siteNotice ) {
1474 $siteNotice = $this->getCachedNotice( 'default' );
1478 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1479 wfProfileOut( __METHOD__
);
1484 * Create a section edit link. This supersedes editSectionLink() and
1485 * editSectionLinkForOther().
1487 * @param $nt Title The title being linked to (may not be the same as
1488 * $wgTitle, if the section is included from a template)
1489 * @param $section string The designation of the section being pointed to,
1490 * to be included in the link, like "§ion=$section"
1491 * @param $tooltip string The tooltip to use for the link: will be escaped
1492 * and wrapped in the 'editsectionhint' message
1493 * @param $lang string Language code
1494 * @return string HTML to use for edit link
1496 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1497 // HTML generated here should probably have userlangattributes
1498 // added to it for LTR text on RTL pages
1500 if ( !is_null( $tooltip ) ) {
1501 # Bug 25462: undo double-escaping.
1502 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1503 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1505 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1507 array( 'action' => 'edit', 'section' => $section ),
1508 array( 'noclasses', 'known' )
1511 # Run the old hook. This takes up half of the function . . . hopefully
1512 # we can rid of it someday.
1515 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1516 $attribs = " title=\"$attribs\"";
1519 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1520 if ( !is_null( $result ) ) {
1521 # For reverse compatibility, add the brackets *after* the hook is
1522 # run, and even add them to hook-provided text. (This is the main
1523 # reason that the EditSectionLink hook is deprecated in favor of
1524 # DoEditSectionLink: it can't change the brackets or the span.)
1525 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1526 return "<span class=\"editsection\">$result</span>";
1529 # Add the brackets and the span, and *then* run the nice new hook, with
1530 # clean and non-redundant arguments.
1531 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1532 $result = "<span class=\"editsection\">$result</span>";
1534 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1539 * Use PHP's magic __call handler to intercept legacy calls to the linker
1540 * for backwards compatibility.
1542 * @param $fname String Name of called method
1543 * @param $args Array Arguments to the method
1545 function __call( $fname, $args ) {
1546 $realFunction = array( 'Linker', $fname );
1547 if ( is_callable( $realFunction ) ) {
1548 return call_user_func_array( $realFunction, $args );
1550 $className = get_class( $this );
1551 throw new MWException( "Call to undefined method $className::$fname" );