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 Linker
{
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';
27 * todo Fixme: should be protected :-\
31 protected $mRelevantTitle = null;
32 protected $mRelevantUser = null;
34 /** Constructor, call parent constructor */
35 function __construct() {
36 parent
::__construct();
40 * Fetch the set of available skins.
41 * @return array of strings
43 static function getSkinNames() {
44 global $wgValidSkinNames;
45 static $skinsInitialised = false;
47 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
48 # Get a list of available skins
49 # Build using the regular expression '^(.*).php$'
50 # Array keys are all lower case, array value keep the case used by filename
52 wfProfileIn( __METHOD__
. '-init' );
54 global $wgStyleDirectory;
56 $skinDir = dir( $wgStyleDirectory );
58 # while code from www.php.net
59 while ( false !== ( $file = $skinDir->read() ) ) {
60 // Skip non-PHP files, hidden files, and '.dep' includes
63 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
65 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
69 $skinsInitialised = true;
70 wfProfileOut( __METHOD__
. '-init' );
72 return $wgValidSkinNames;
76 * Fetch the list of usable skins in regards to $wgSkipSkins.
77 * Useful for Special:Preferences and other places where you
78 * only want to show skins users _can_ use.
79 * @return array of strings
81 public static function getUsableSkins() {
84 $usableSkins = self
::getSkinNames();
86 foreach ( $wgSkipSkins as $skip ) {
87 unset( $usableSkins[$skip] );
94 * Normalize a skin preference value to a form that can be loaded.
95 * If a skin can't be found, it will fall back to the configured
96 * default (or the old 'Classic' skin if that's broken).
97 * @param $key String: 'monobook', 'standard', etc.
100 static function normalizeKey( $key ) {
101 global $wgDefaultSkin;
103 $skinNames = Skin
::getSkinNames();
106 // Don't return the default immediately;
107 // in a misconfiguration we need to fall back.
108 $key = $wgDefaultSkin;
111 if ( isset( $skinNames[$key] ) ) {
115 // Older versions of the software used a numeric setting
116 // in the user preferences.
123 if ( isset( $fallback[$key] ) ) {
124 $key = $fallback[$key];
127 if ( isset( $skinNames[$key] ) ) {
129 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
130 return $wgDefaultSkin;
137 * Factory method for loading a skin of a given type
138 * @param $key String: 'monobook', 'standard', etc.
141 static function &newFromKey( $key ) {
142 global $wgStyleDirectory;
144 $key = Skin
::normalizeKey( $key );
146 $skinNames = Skin
::getSkinNames();
147 $skinName = $skinNames[$key];
148 $className = "Skin{$skinName}";
150 # Grab the skin class and initialise it.
151 if ( !class_exists( $className ) ) {
152 // Preload base classes to work around APC/PHP5 bug
153 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
155 if ( file_exists( $deps ) ) {
156 include_once( $deps );
158 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
160 # Check if we got if not failback to default skin
161 if ( !class_exists( $className ) ) {
162 # DO NOT die if the class isn't found. This breaks maintenance
163 # scripts and can cause a user account to be unrecoverable
164 # except by SQL manipulation if a previously valid skin name
165 # is no longer valid.
166 wfDebug( "Skin class does not exist: $className\n" );
167 $className = 'SkinVector';
168 require_once( "{$wgStyleDirectory}/Vector.php" );
171 $skin = new $className;
175 /** @return string path to the skin stylesheet */
176 function getStylesheet() {
177 return 'common/wikistandard.css';
180 /** @return string skin name */
181 public function getSkinName() {
182 return $this->skinname
;
185 function initPage( OutputPage
$out ) {
186 global $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI;
188 wfProfileIn( __METHOD__
);
190 # Generally the order of the favicon and apple-touch-icon links
191 # should not matter, but Konqueror (3.5.9 at least) incorrectly
192 # uses whichever one appears later in the HTML source. Make sure
193 # apple-touch-icon is specified first to avoid this.
194 if ( false !== $wgAppleTouchIcon ) {
195 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
198 if ( false !== $wgFavicon ) {
199 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
202 # OpenSearch description link
203 $out->addLink( array(
205 'type' => 'application/opensearchdescription+xml',
206 'href' => wfScript( 'opensearch_desc' ),
207 'title' => wfMsgForContent( 'opensearch-desc' ),
210 if ( $wgEnableAPI ) {
211 # Real Simple Discovery link, provides auto-discovery information
212 # for the MediaWiki API (and potentially additional custom API
213 # support such as WordPress or Twitter-compatible APIs for a
214 # blogging extension, etc)
215 $out->addLink( array(
217 'type' => 'application/rsd+xml',
218 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ),
222 $this->addMetadataLinks( $out );
224 $this->mRevisionId
= $out->mRevisionId
;
226 $this->preloadExistence();
228 wfProfileOut( __METHOD__
);
232 * Preload the existence of three commonly-requested pages in a single query
234 function preloadExistence() {
238 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
241 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
243 } elseif ( $this->mTitle
->isTalkPage() ) {
244 $titles[] = $this->mTitle
->getSubjectPage();
246 $titles[] = $this->mTitle
->getTalkPage();
249 $lb = new LinkBatch( $titles );
250 $lb->setCaller( __METHOD__
);
255 * Adds metadata links below to the HTML output.
257 * <li>Creative Commons
258 * <br />See http://wiki.creativecommons.org/Extend_Metadata.
260 * <li>Dublin Core</li>
261 * <li>Use hreflang to specify canonical and alternate links
262 * <br />See http://www.google.com/support/webmasters/bin/answer.py?answer=189077
267 * @param $out Object: instance of OutputPage
269 function addMetadataLinks( OutputPage
$out ) {
270 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
271 global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang;
272 global $wgRightsPage, $wgRightsUrl;
274 if ( $out->isArticleRelated() ) {
275 # note: buggy CC software only reads first "meta" link
276 if ( $wgEnableCreativeCommonsRdf ) {
277 $out->addMetadataLink( array(
278 'title' => 'Creative Commons',
279 'type' => 'application/rdf+xml',
280 'href' => $this->mTitle
->getLocalURL( 'action=creativecommons' ) )
284 if ( $wgEnableDublinCoreRdf ) {
285 $out->addMetadataLink( array(
286 'title' => 'Dublin Core',
287 'type' => 'application/rdf+xml',
288 'href' => $this->mTitle
->getLocalURL( 'action=dublincore' ) )
293 if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
294 && $wgContLang->hasVariants() ) {
296 $urlvar = $wgContLang->getURLVariant();
299 $variants = $wgContLang->getVariants();
300 foreach ( $variants as $_v ) {
301 $out->addLink( array(
302 'rel' => 'alternate',
304 'href' => $this->mTitle
->getLocalURL( '', $_v ) )
308 $out->addLink( array(
309 'rel' => 'canonical',
310 'href' => $this->mTitle
->getFullURL() )
316 if ( $wgRightsPage ) {
317 $copy = Title
::newFromText( $wgRightsPage );
320 $copyright = $copy->getLocalURL();
324 if ( !$copyright && $wgRightsUrl ) {
325 $copyright = $wgRightsUrl;
329 $out->addLink( array(
330 'rel' => 'copyright',
331 'href' => $copyright )
337 * Set some local variables
339 protected function setMembers() {
341 $this->mUser
= $wgUser;
342 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
343 $this->usercss
= false;
347 * Whether the revision displayed is the latest revision of the page
351 public function isRevisionCurrent() {
352 return $this->mRevisionId
== 0 ||
$this->mRevisionId
== $this->mTitle
->getLatestRevID();
357 * @param $t Title object to use
359 public function setTitle( $t ) {
367 public function getTitle() {
368 return $this->mTitle
;
372 * Set the "relevant" title
373 * @see self::getRelevantTitle()
374 * @param $t Title object to use
376 public function setRelevantTitle( $t ) {
377 $this->mRelevantTitle
= $t;
381 * Return the "relevant" title.
382 * A "relevant" title is not necessarily the actual title of the page.
383 * Special pages like Special:MovePage use set the page they are acting on
384 * as their "relevant" title, this allows the skin system to display things
385 * such as content tabs which belong to to that page instead of displaying
386 * a basic special page tab which has almost no meaning.
388 public function getRelevantTitle() {
389 if ( isset($this->mRelevantTitle
) ) {
390 return $this->mRelevantTitle
;
392 return $this->mTitle
;
396 * Set the "relevant" user
397 * @see self::getRelevantUser()
398 * @param $u User object to use
400 public function setRelevantUser( $u ) {
401 $this->mRelevantUser
= $u;
405 * Return the "relevant" user.
406 * A "relevant" user is similar to a relevant title. Special pages like
407 * Special:Contributions mark the user which they are relevant to so that
408 * things like the toolbox can display the information they usually are only
409 * able to display on a user's userpage and talkpage.
411 public function getRelevantUser() {
412 if ( isset($this->mRelevantUser
) ) {
413 return $this->mRelevantUser
;
415 $title = $this->getRelevantTitle();
416 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
417 $rootUser = strtok( $title->getText(), '/' );
418 if ( User
::isIP( $rootUser ) ) {
419 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
421 $user = User
::newFromName( $rootUser );
422 if ( $user->isLoggedIn() ) {
423 $this->mRelevantUser
= $user;
426 return $this->mRelevantUser
;
432 * Outputs the HTML generated by other functions.
433 * @param $out Object: instance of OutputPage
436 function outputPage( OutputPage
$out ) {
437 global $wgDebugComments;
438 wfProfileIn( __METHOD__
);
441 $this->initPage( $out );
443 // See self::afterContentHook() for documentation
444 $afterContent = $this->afterContentHook();
446 $out->out( $out->headElement( $this ) );
448 if ( $wgDebugComments ) {
449 $out->out( "<!-- Debug output:\n" .
450 $out->mDebugtext
. "-->\n" );
453 $out->out( $this->beforeContent() );
455 $out->out( $out->mBodytext
. "\n" );
457 $out->out( $this->afterContent() );
459 $out->out( $afterContent );
461 $out->out( $this->bottomScripts( $out ) );
463 $out->out( wfReportTime() );
465 $out->out( "\n</body></html>" );
466 wfProfileOut( __METHOD__
);
469 static function makeVariablesScript( $data ) {
471 return Html
::inlineScript(
472 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
480 * To make it harder for someone to slip a user a fake
481 * user-JavaScript or user-CSS preview, a random token
482 * is associated with the login session. If it's not
483 * passed back with the preview request, we won't render
486 * @param $action String: 'edit', 'submit' etc.
489 public function userCanPreview( $action ) {
490 global $wgRequest, $wgUser;
492 if ( $action != 'submit' ) {
495 if ( !$wgRequest->wasPosted() ) {
498 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
501 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
505 return $wgUser->matchEditToken(
506 $wgRequest->getVal( 'wpEditToken' ) );
510 * Generated JavaScript action=raw&gen=js
511 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
512 * nated together. For some bizarre reason, it does *not* return any
513 * custom user JS from subpages. Huh?
515 * There's absolutely no reason to have separate Monobook/Common JSes.
516 * Any JS that cares can just check the skin variable generated at the
517 * top. For now Monobook.js will be maintained, but it should be consi-
520 * @param $skinName String: If set, overrides the skin name
523 public function generateUserJs( $skinName = null ) {
525 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
531 * Generate user stylesheet for action=raw&gen=css
533 public function generateUserStylesheet() {
535 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
541 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
542 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
544 protected function reallyGenerateUserStylesheet() {
546 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
554 function setupUserCss( OutputPage
$out ) {
555 global $wgRequest, $wgUser;
556 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
558 wfProfileIn( __METHOD__
);
560 $this->setupSkinUserCss( $out );
561 // Add any extension CSS
562 foreach ( $out->getExtStyle() as $url ) {
563 $out->addStyle( $url );
566 // Per-site custom styles
567 if ( $wgUseSiteCss ) {
568 $out->addModuleStyles( array( 'site', 'noscript' ) );
569 if( $wgUser->isLoggedIn() ){
570 $out->addModuleStyles( 'user.groups' );
574 // Per-user custom styles
575 if ( $wgAllowUserCss ) {
576 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
577 // @FIXME: properly escape the cdata!
578 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
580 $out->addModuleStyles( 'user' );
584 // Per-user preference styles
585 if ( $wgAllowUserCssPrefs ) {
586 $out->addModuleStyles( 'user.options' );
589 wfProfileOut( __METHOD__
);
593 * Get the query to generate a dynamic stylesheet
597 public static function getDynamicStylesheetQuery() {
598 global $wgSquidMaxage;
602 'maxage' => $wgSquidMaxage,
603 'usemsgcache' => 'yes',
604 'ctype' => 'text/css',
605 'smaxage' => $wgSquidMaxage,
610 * Add skin specific stylesheets
611 * @param $out OutputPage
614 abstract function setupSkinUserCss( OutputPage
$out );
616 function getPageClasses( $title ) {
617 $numeric = 'ns-' . $title->getNamespace();
619 if ( $title->getNamespace() == NS_SPECIAL
) {
620 $type = 'ns-special';
621 // bug 23315: provide a class based on the canonical special page name without subpages
622 list( $canonicalName ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
623 if ( $canonicalName ) {
624 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
626 $type .= ' mw-invalidspecialpage';
628 } elseif ( $title->isTalkPage() ) {
631 $type = 'ns-subject';
634 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
636 return "$numeric $type $name";
640 * This will be called by OutputPage::headElement when it is creating the
641 * <body> tag, skins can override it if they have a need to add in any
642 * body attributes or classes of their own.
644 function addToBodyAttributes( $out, &$bodyAttrs ) {
645 // does nothing by default
657 * The format without an explicit $out argument is deprecated
659 function getCategoryLinks( OutputPage
$out=null ) {
660 global $wgUseCategoryBrowser, $wgContLang, $wgUser;
662 if ( is_null( $out ) ) {
663 // Backwards compatibility for when there was no $out arg
668 if ( count( $out->mCategoryLinks
) == 0 ) {
673 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
675 // Use Unicode bidi embedding override characters,
676 // to make sure links don't smash each other up in ugly ways.
677 $dir = $wgContLang->getDir();
678 $embed = "<span dir='$dir'>";
681 $allCats = $out->getCategoryLinks();
683 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
685 if ( !empty( $allCats['normal'] ) ) {
686 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
688 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
689 $s .= '<div id="mw-normal-catlinks">' .
690 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
691 . $colon . $t . '</div>';
695 if ( isset( $allCats['hidden'] ) ) {
696 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
697 $class = 'mw-hidden-cats-user-shown';
698 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
699 $class = 'mw-hidden-cats-ns-shown';
701 $class = 'mw-hidden-cats-hidden';
704 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
705 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
706 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
710 # optional 'dmoz-like' category browser. Will be shown under the list
711 # of categories an article belong to
712 if ( $wgUseCategoryBrowser ) {
713 $s .= '<br /><hr />';
715 # get a big array of the parents tree
716 $parenttree = $this->mTitle
->getParentCategoryTree();
717 # Skin object passed by reference cause it can not be
718 # accessed under the method subfunction drawCategoryBrowser
719 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
720 # Clean out bogus first entry and sort them
721 unset( $tempout[0] );
723 # Output one per line
724 $s .= implode( "<br />\n", $tempout );
731 * Render the array as a serie of links.
732 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
733 * @param &skin Object: skin passed by reference
734 * @return String separated by >, terminate with "\n"
736 function drawCategoryBrowser( $tree, &$skin ) {
739 foreach ( $tree as $element => $parent ) {
740 if ( empty( $parent ) ) {
741 # element start a new list
744 # grab the others elements
745 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
748 # add our current element to the list
749 $eltitle = Title
::newFromText( $element );
750 $return .= $skin->link( $eltitle, $eltitle->getText() );
757 * The ->getCategories() form is deprecated, please instead use
758 * the ->getCategories( $out ) form with whatout OutputPage is on hand
760 function getCategories( OutputPage
$out=null ) {
761 if ( is_null( $out ) ) {
762 // Backwards compatibility for when there was no $out arg
767 $catlinks = $this->getCategoryLinks( $out );
769 $classes = 'catlinks';
773 // Check what we're showing
774 $allCats = $out->getCategoryLinks();
775 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
776 $this->mTitle
->getNamespace() == NS_CATEGORY
;
778 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
779 $classes .= ' catlinks-allhidden';
782 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
786 * This runs a hook to allow extensions placing their stuff after content
787 * and article metadata (e.g. categories).
788 * Note: This function has nothing to do with afterContent().
790 * This hook is placed here in order to allow using the same hook for all
791 * skins, both the SkinTemplate based ones and the older ones, which directly
792 * use this class to get their data.
794 * The output of this function gets processed in SkinTemplate::outputPage() for
795 * the SkinTemplate based skins, all other skins should directly echo it.
797 * Returns an empty string by default, if not changed by any hook function.
799 protected function afterContentHook() {
802 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
803 // adding just some spaces shouldn't toggle the output
804 // of the whole <div/>, so we use trim() here
805 if ( trim( $data ) != '' ) {
806 // Doing this here instead of in the skins to
807 // ensure that the div has the same ID in all
809 $data = "<div id='mw-data-after-content'>\n" .
814 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
821 * Generate debug data HTML for displaying at the bottom of the main content
823 * @return String HTML containing debug data, if enabled (otherwise empty).
825 protected function generateDebugHTML( OutputPage
$out ) {
828 if ( $wgShowDebug ) {
829 $listInternals = $this->formatDebugHTML( $out->mDebugtext
);
830 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
831 $listInternals . "</ul>\n";
837 private function formatDebugHTML( $debugText ) {
838 global $wgDebugTimestamps;
840 $lines = explode( "\n", $debugText );
844 foreach ( $lines as $line ) {
846 if ( $wgDebugTimestamps ) {
848 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
850 $line = substr( $line, strlen( $pre ) );
853 $display = ltrim( $line );
854 $ident = strlen( $line ) - strlen( $display );
855 $diff = $ident - $curIdent;
857 $display = $pre . $display;
858 if ( $display == '' ) {
859 $display = "\xc2\xa0";
862 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
865 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
867 $display = htmlspecialchars( $display );
871 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
872 } elseif ( $diff == 0 ) {
873 $ret .= "</li><li>\n";
875 $ret .= str_repeat( "<ul><li>\n", $diff );
877 $ret .= "<tt>$display</tt>\n";
882 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
888 * This gets called shortly before the </body> tag.
889 * @param $out OutputPage object
890 * @return String HTML-wrapped JS code to be put before </body>
892 function bottomScripts( $out ) {
893 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
894 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
896 return $bottomScriptText;
899 /** @return string Retrievied from HTML text */
900 function printSource() {
901 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
902 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
905 function getUndeleteLink() {
906 global $wgUser, $wgLang, $wgRequest;
908 $action = $wgRequest->getVal( 'action', 'view' );
910 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
911 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
912 $n = $this->mTitle
->isDeleted();
915 if ( $wgUser->isAllowed( 'undelete' ) ) {
916 $msg = 'thisisdeleted';
918 $msg = 'viewdeleted';
924 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
925 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
928 array( 'known', 'noclasses' )
938 * The format without an explicit $out argument is deprecated
940 function subPageSubtitle( OutputPage
$out=null ) {
941 if ( is_null( $out ) ) {
942 // Backwards compatibility for when there was no $out arg
949 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
953 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
954 $ptext = $this->mTitle
->getPrefixedText();
955 if ( preg_match( '/\//', $ptext ) ) {
956 $links = explode( '/', $ptext );
962 foreach ( $links as $link ) {
963 $growinglink .= $link;
965 $linkObj = Title
::newFromText( $growinglink );
967 if ( is_object( $linkObj ) && $linkObj->exists() ) {
968 $getlink = $this->link(
970 htmlspecialchars( $display ),
973 array( 'known', 'noclasses' )
979 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
981 $subpages .= '< ';
984 $subpages .= $getlink;
998 * Returns true if the IP should be shown in the header
1000 function showIPinHeader() {
1001 global $wgShowIPinHeader;
1002 return $wgShowIPinHeader && session_id() != '';
1005 function getSearchLink() {
1006 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1007 return $searchPage->getLocalURL();
1010 function escapeSearchLink() {
1011 return htmlspecialchars( $this->getSearchLink() );
1014 function getCopyright( $type = 'detect' ) {
1015 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1017 if ( $type == 'detect' ) {
1018 $diff = $wgRequest->getVal( 'diff' );
1020 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1027 if ( $type == 'history' ) {
1028 $msg = 'history_copyright';
1035 if ( $wgRightsPage ) {
1036 $title = Title
::newFromText( $wgRightsPage );
1037 $link = $this->linkKnown( $title, $wgRightsText );
1038 } elseif ( $wgRightsUrl ) {
1039 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1040 } elseif ( $wgRightsText ) {
1041 $link = $wgRightsText;
1047 // Allow for site and per-namespace customization of copyright notice.
1050 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle
, $type, &$msg, &$link, &$forContent ) );
1052 if ( $forContent ) {
1053 $out .= wfMsgForContent( $msg, $link );
1055 $out .= wfMsg( $msg, $link );
1061 function getCopyrightIcon() {
1062 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1066 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1067 $out = $wgCopyrightIcon;
1068 } elseif ( $wgRightsIcon ) {
1069 $icon = htmlspecialchars( $wgRightsIcon );
1071 if ( $wgRightsUrl ) {
1072 $url = htmlspecialchars( $wgRightsUrl );
1073 $out .= '<a href="' . $url . '">';
1076 $text = htmlspecialchars( $wgRightsText );
1077 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1079 if ( $wgRightsUrl ) {
1088 * Gets the powered by MediaWiki icon.
1091 function getPoweredBy() {
1092 global $wgStylePath;
1094 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1095 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1096 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1101 * Get the timestamp of the latest revision, formatted in user language
1103 * @param $article Article object. Used if we're working with the current revision
1106 protected function lastModified( $article ) {
1109 if ( !$this->isRevisionCurrent() ) {
1110 $timestamp = Revision
::getTimestampFromId( $this->mTitle
, $this->mRevisionId
);
1112 $timestamp = $article->getTimestamp();
1116 $d = $wgLang->date( $timestamp, true );
1117 $t = $wgLang->time( $timestamp, true );
1118 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1123 if ( wfGetLB()->getLaggedSlaveMode() ) {
1124 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1130 function logoText( $align = '' ) {
1131 if ( $align != '' ) {
1132 $a = " align='{$align}'";
1137 $mp = wfMsg( 'mainpage' );
1138 $mptitle = Title
::newMainPage();
1139 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1141 $logourl = $this->getLogo();
1142 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1148 * Renders a $wgFooterIcons icon acording to the method's arguments
1149 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1150 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1152 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1153 if ( is_string( $icon ) ) {
1155 } else { // Assuming array
1156 $url = isset($icon["url"]) ?
$icon["url"] : null;
1157 unset( $icon["url"] );
1158 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1159 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1161 $html = htmlspecialchars( $icon["alt"] );
1164 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1171 * Gets the link to the wiki's main page.
1174 function mainPageLink() {
1176 Title
::newMainPage(),
1177 wfMsg( 'mainpage' ),
1180 array( 'known', 'noclasses' )
1186 public function footerLink( $desc, $page ) {
1187 // if the link description has been set to "-" in the default language,
1188 if ( wfMsgForContent( $desc ) == '-' ) {
1189 // then it is disabled, for all languages.
1192 // Otherwise, we display the link for the user, described in their
1193 // language (which may or may not be the same as the default language),
1194 // but we make the link target be the one site-wide page.
1195 $title = Title
::newFromText( wfMsgForContent( $page ) );
1197 return $this->linkKnown(
1199 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1205 * Gets the link to the wiki's privacy policy page.
1207 function privacyLink() {
1208 return $this->footerLink( 'privacy', 'privacypage' );
1212 * Gets the link to the wiki's about page.
1214 function aboutLink() {
1215 return $this->footerLink( 'aboutsite', 'aboutpage' );
1219 * Gets the link to the wiki's general disclaimers page.
1221 function disclaimerLink() {
1222 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1226 * Return URL options for the 'edit page' link.
1227 * This may include an 'oldid' specifier, if the current page view is such.
1232 function editUrlOptions() {
1233 $options = array( 'action' => 'edit' );
1235 if ( !$this->isRevisionCurrent() ) {
1236 $options['oldid'] = intval( $this->mRevisionId
);
1242 function showEmailUser( $id ) {
1244 $targetUser = User
::newFromId( $id );
1245 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1246 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1250 * Return a fully resolved style path url to images or styles stored in the common folder.
1251 * This method returns a url resolved using the configured skin style path
1252 * and includes the style version inside of the url.
1253 * @param $name String: The name or path of a skin resource file
1254 * @return String The fully resolved style path url including styleversion
1256 function getCommonStylePath( $name ) {
1257 global $wgStylePath, $wgStyleVersion;
1258 return "$wgStylePath/common/$name?$wgStyleVersion";
1262 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1263 * This method returns a url resolved using the configured skin style path
1264 * and includes the style version inside of the url.
1265 * @param $name String: The name or path of a skin resource file
1266 * @return String The fully resolved style path url including styleversion
1268 function getSkinStylePath( $name ) {
1269 global $wgStylePath, $wgStyleVersion;
1270 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1273 /* these are used extensively in SkinTemplate, but also some other places */
1274 static function makeMainPageUrl( $urlaction = '' ) {
1275 $title = Title
::newMainPage();
1276 self
::checkTitle( $title, '' );
1278 return $title->getLocalURL( $urlaction );
1281 static function makeSpecialUrl( $name, $urlaction = '' ) {
1282 $title = SpecialPage
::getTitleFor( $name );
1283 return $title->getLocalURL( $urlaction );
1286 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1287 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1288 return $title->getLocalURL( $urlaction );
1291 static function makeI18nUrl( $name, $urlaction = '' ) {
1292 $title = Title
::newFromText( wfMsgForContent( $name ) );
1293 self
::checkTitle( $title, $name );
1294 return $title->getLocalURL( $urlaction );
1297 static function makeUrl( $name, $urlaction = '' ) {
1298 $title = Title
::newFromText( $name );
1299 self
::checkTitle( $title, $name );
1301 return $title->getLocalURL( $urlaction );
1305 * If url string starts with http, consider as external URL, else
1308 static function makeInternalOrExternalUrl( $name ) {
1309 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1312 return self
::makeUrl( $name );
1316 # this can be passed the NS number as defined in Language.php
1317 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1318 $title = Title
::makeTitleSafe( $namespace, $name );
1319 self
::checkTitle( $title, $name );
1321 return $title->getLocalURL( $urlaction );
1324 /* these return an array with the 'href' and boolean 'exists' */
1325 static function makeUrlDetails( $name, $urlaction = '' ) {
1326 $title = Title
::newFromText( $name );
1327 self
::checkTitle( $title, $name );
1330 'href' => $title->getLocalURL( $urlaction ),
1331 'exists' => $title->getArticleID() != 0,
1336 * Make URL details where the article exists (or at least it's convenient to think so)
1338 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1339 $title = Title
::newFromText( $name );
1340 self
::checkTitle( $title, $name );
1343 'href' => $title->getLocalURL( $urlaction ),
1348 # make sure we have some title to operate on
1349 static function checkTitle( &$title, $name ) {
1350 if ( !is_object( $title ) ) {
1351 $title = Title
::newFromText( $name );
1352 if ( !is_object( $title ) ) {
1353 $title = Title
::newFromText( '--error: link target missing--' );
1359 * Build an array that represents the sidebar(s), the navigation bar among them
1363 function buildSidebar() {
1364 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1366 wfProfileIn( __METHOD__
);
1368 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1370 if ( $wgEnableSidebarCache ) {
1371 $cachedsidebar = $parserMemc->get( $key );
1372 if ( $cachedsidebar ) {
1373 wfProfileOut( __METHOD__
);
1374 return $cachedsidebar;
1379 $this->addToSidebar( $bar, 'sidebar' );
1381 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1382 if ( $wgEnableSidebarCache ) {
1383 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1386 wfProfileOut( __METHOD__
);
1390 * Add content from a sidebar system message
1391 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1393 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1395 * @param &$bar array
1396 * @param $message String
1398 function addToSidebar( &$bar, $message ) {
1399 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1403 * Add content from plain text
1405 * @param &$bar array
1406 * @param $text string
1408 function addToSidebarPlain( &$bar, $text ) {
1409 $lines = explode( "\n", $text );
1410 $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.
1414 foreach ( $lines as $line ) {
1415 if ( strpos( $line, '*' ) !== 0 ) {
1419 if ( strpos( $line, '**' ) !== 0 ) {
1420 $heading = trim( $line, '* ' );
1421 if ( !array_key_exists( $heading, $bar ) ) {
1422 $bar[$heading] = array();
1425 $line = trim( $line, '* ' );
1427 if ( strpos( $line, '|' ) !== false ) { // sanity check
1428 $line = MessageCache
::singleton()->transform( $line, false, null, $this->mTitle
);
1429 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1430 $link = wfMsgForContent( $line[0] );
1432 if ( $link == '-' ) {
1436 $text = wfMsgExt( $line[1], 'parsemag' );
1438 if ( wfEmptyMsg( $line[1] ) ) {
1442 if ( wfEmptyMsg( $line[0] ) ) {
1446 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1449 $title = Title
::newFromText( $link );
1452 $title = $title->fixSpecialName();
1453 $href = $title->getLocalURL();
1455 $href = 'INVALID-TITLE';
1459 $bar[$heading][] = array(
1462 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1465 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1468 $line = substr( $line, 2, strlen( $line ) - 4 );
1470 $options = new ParserOptions();
1471 $options->setEditSection( false );
1472 $options->setInterfaceMessage( true );
1473 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->mTitle
, $options )->getText();
1480 if ( count( $wikiBar ) > 0 ) {
1481 $bar = array_merge( $bar, $wikiBar );
1488 * Should we include common/wikiprintable.css? Skins that have their own
1489 * print stylesheet should override this and return false. (This is an
1490 * ugly hack to get Monobook to play nicely with
1491 * OutputPage::headElement().)
1495 public function commonPrintStylesheet() {
1500 * Gets new talk page messages for the current user.
1501 * @return MediaWiki message or if no new talk page messages, nothing
1502 * The format without an explicit $out argument is deprecated
1504 function getNewtalks( OutputPage
$out=null ) {
1507 if ( is_null( $out ) ) {
1508 // Backwards compatibility for when there was no $out arg
1513 $newtalks = $wgUser->getNewMessageLinks();
1516 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1517 $userTitle = $this->mUser
->getUserPage();
1518 $userTalkTitle = $userTitle->getTalkPage();
1520 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1521 $newMessagesLink = $this->link(
1523 wfMsgHtml( 'newmessageslink' ),
1525 array( 'redirect' => 'no' ),
1526 array( 'known', 'noclasses' )
1529 $newMessagesDiffLink = $this->link(
1531 wfMsgHtml( 'newmessagesdifflink' ),
1533 array( 'diff' => 'cur' ),
1534 array( 'known', 'noclasses' )
1538 'youhavenewmessages',
1540 $newMessagesDiffLink
1542 # Disable Squid cache
1543 $out->setSquidMaxage( 0 );
1545 } elseif ( count( $newtalks ) ) {
1546 // _>" " for BC <= 1.16
1547 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1550 foreach ( $newtalks as $newtalk ) {
1551 $msgs[] = Xml
::element(
1553 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1556 $parts = implode( $sep, $msgs );
1557 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1558 $out->setSquidMaxage( 0 );
1565 * Get a cached notice
1567 * @param $name String: message name, or 'default' for $wgSiteNotice
1568 * @return String: HTML fragment
1570 private function getCachedNotice( $name ) {
1571 global $wgOut, $wgRenderHashAppend, $parserMemc;
1573 wfProfileIn( __METHOD__
);
1577 if( $name === 'default' ) {
1579 global $wgSiteNotice;
1580 $notice = $wgSiteNotice;
1581 if( empty( $notice ) ) {
1582 wfProfileOut( __METHOD__
);
1586 $msg = wfMessage( $name )->inContentLanguage();
1587 if( $msg->isDisabled() ) {
1588 wfProfileOut( __METHOD__
);
1591 $notice = $msg->plain();
1594 // Use the extra hash appender to let eg SSL variants separately cache.
1595 $key = wfMemcKey( $name . $wgRenderHashAppend );
1596 $cachedNotice = $parserMemc->get( $key );
1597 if( is_array( $cachedNotice ) ) {
1598 if( md5( $notice ) == $cachedNotice['hash'] ) {
1599 $notice = $cachedNotice['html'];
1608 if( is_object( $wgOut ) ) {
1609 $parsed = $wgOut->parse( $notice );
1610 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1613 wfDebug( 'Skin::getCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
1618 $notice = '<div id="localNotice">' .$notice . '</div>';
1619 wfProfileOut( __METHOD__
);
1624 * Get a notice based on page's namespace
1626 * @return String: HTML fragment
1628 function getNamespaceNotice() {
1629 wfProfileIn( __METHOD__
);
1631 $key = 'namespacenotice-' . $this->mTitle
->getNsText();
1632 $namespaceNotice = $this->getCachedNotice( $key );
1633 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1634 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1636 $namespaceNotice = '';
1639 wfProfileOut( __METHOD__
);
1640 return $namespaceNotice;
1644 * Get the site notice
1646 * @return String: HTML fragment
1648 function getSiteNotice() {
1651 wfProfileIn( __METHOD__
);
1654 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1655 if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
1656 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1658 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1659 if ( !$anonNotice ) {
1660 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1662 $siteNotice = $anonNotice;
1665 if ( !$siteNotice ) {
1666 $siteNotice = $this->getCachedNotice( 'default' );
1670 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1671 wfProfileOut( __METHOD__
);