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 ) {
364 public function getTitle() {
365 return $this->mTitle
;
369 * Set the "relevant" title
370 * @see self::getRelevantTitle()
371 * @param $t Title object to use
373 public function setRelevantTitle( $t ) {
374 $this->mRelevantTitle
= $t;
378 * Return the "relevant" title.
379 * A "relevant" title is not necessarily the actual title of the page.
380 * Special pages like Special:MovePage use set the page they are acting on
381 * as their "relevant" title, this allows the skin system to display things
382 * such as content tabs which belong to to that page instead of displaying
383 * a basic special page tab which has almost no meaning.
385 public function getRelevantTitle() {
386 if ( isset($this->mRelevantTitle
) ) {
387 return $this->mRelevantTitle
;
389 return $this->mTitle
;
393 * Set the "relevant" user
394 * @see self::getRelevantUser()
395 * @param $u User object to use
397 public function setRelevantUser( $u ) {
398 $this->mRelevantUser
= $u;
402 * Return the "relevant" user.
403 * A "relevant" user is similar to a relevant title. Special pages like
404 * Special:Contributions mark the user which they are relevant to so that
405 * things like the toolbox can display the information they usually are only
406 * able to display on a user's userpage and talkpage.
408 public function getRelevantUser() {
409 if ( isset($this->mRelevantUser
) ) {
410 return $this->mRelevantUser
;
412 $title = $this->getRelevantTitle();
413 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
414 $rootUser = strtok( $title->getText(), '/' );
415 if ( User
::isIP( $rootUser ) ) {
416 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
418 $user = User
::newFromName( $rootUser );
419 if ( $user->isLoggedIn() ) {
420 $this->mRelevantUser
= $user;
423 return $this->mRelevantUser
;
429 * Outputs the HTML generated by other functions.
430 * @param $out Object: instance of OutputPage
433 function outputPage( OutputPage
$out ) {
434 global $wgDebugComments;
435 wfProfileIn( __METHOD__
);
438 $this->initPage( $out );
440 // See self::afterContentHook() for documentation
441 $afterContent = $this->afterContentHook();
443 $out->out( $out->headElement( $this ) );
445 if ( $wgDebugComments ) {
446 $out->out( "<!-- Debug output:\n" .
447 $out->mDebugtext
. "-->\n" );
450 $out->out( $this->beforeContent() );
452 $out->out( $out->mBodytext
. "\n" );
454 $out->out( $this->afterContent() );
456 $out->out( $afterContent );
458 $out->out( $this->bottomScripts( $out ) );
460 $out->out( wfReportTime() );
462 $out->out( "\n</body></html>" );
463 wfProfileOut( __METHOD__
);
466 static function makeVariablesScript( $data ) {
468 return Html
::inlineScript(
469 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
477 * To make it harder for someone to slip a user a fake
478 * user-JavaScript or user-CSS preview, a random token
479 * is associated with the login session. If it's not
480 * passed back with the preview request, we won't render
483 * @param $action String: 'edit', 'submit' etc.
486 public function userCanPreview( $action ) {
487 global $wgRequest, $wgUser;
489 if ( $action != 'submit' ) {
492 if ( !$wgRequest->wasPosted() ) {
495 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
498 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
502 return $wgUser->matchEditToken(
503 $wgRequest->getVal( 'wpEditToken' ) );
507 * Generated JavaScript action=raw&gen=js
508 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
509 * nated together. For some bizarre reason, it does *not* return any
510 * custom user JS from subpages. Huh?
512 * There's absolutely no reason to have separate Monobook/Common JSes.
513 * Any JS that cares can just check the skin variable generated at the
514 * top. For now Monobook.js will be maintained, but it should be consi-
517 * @param $skinName String: If set, overrides the skin name
520 public function generateUserJs( $skinName = null ) {
522 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
528 * Generate user stylesheet for action=raw&gen=css
530 public function generateUserStylesheet() {
532 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
538 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
539 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
541 protected function reallyGenerateUserStylesheet() {
543 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
551 function setupUserCss( OutputPage
$out ) {
552 global $wgRequest, $wgUser;
553 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
555 wfProfileIn( __METHOD__
);
557 $this->setupSkinUserCss( $out );
558 // Add any extension CSS
559 foreach ( $out->getExtStyle() as $url ) {
560 $out->addStyle( $url );
563 // Per-site custom styles
564 if ( $wgUseSiteCss ) {
565 $out->addModuleStyles( 'site' );
566 if( $wgUser->isLoggedIn() ){
567 $out->addModuleStyles( 'user.groups' );
571 // Per-user custom styles
572 if ( $wgAllowUserCss ) {
573 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
574 // @FIXME: properly escape the cdata!
575 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
577 $out->addModuleStyles( 'user' );
581 // Per-user preference styles
582 if ( $wgAllowUserCssPrefs ) {
583 $out->addModuleStyles( 'user.options' );
586 wfProfileOut( __METHOD__
);
590 * Get the query to generate a dynamic stylesheet
594 public static function getDynamicStylesheetQuery() {
595 global $wgSquidMaxage;
599 'maxage' => $wgSquidMaxage,
600 'usemsgcache' => 'yes',
601 'ctype' => 'text/css',
602 'smaxage' => $wgSquidMaxage,
607 * Add skin specific stylesheets
608 * @param $out OutputPage
611 abstract function setupSkinUserCss( OutputPage
$out );
613 function getPageClasses( $title ) {
614 $numeric = 'ns-' . $title->getNamespace();
616 if ( $title->getNamespace() == NS_SPECIAL
) {
617 $type = 'ns-special';
618 // bug 23315: provide a class based on the canonical special page name without subpages
619 list( $canonicalName ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
620 if ( $canonicalName ) {
621 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
623 $type .= ' mw-invalidspecialpage';
625 } elseif ( $title->isTalkPage() ) {
628 $type = 'ns-subject';
631 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
633 return "$numeric $type $name";
637 * This will be called by OutputPage::headElement when it is creating the
638 * <body> tag, skins can override it if they have a need to add in any
639 * body attributes or classes of their own.
641 function addToBodyAttributes( $out, &$bodyAttrs ) {
642 // does nothing by default
653 function getCategoryLinks() {
654 global $wgOut, $wgUseCategoryBrowser;
655 global $wgContLang, $wgUser;
657 if ( count( $wgOut->mCategoryLinks
) == 0 ) {
662 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
664 // Use Unicode bidi embedding override characters,
665 // to make sure links don't smash each other up in ugly ways.
666 $dir = $wgContLang->getDir();
667 $embed = "<span dir='$dir'>";
670 $allCats = $wgOut->getCategoryLinks();
672 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
674 if ( !empty( $allCats['normal'] ) ) {
675 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
677 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
678 $s .= '<div id="mw-normal-catlinks">' .
679 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
680 . $colon . $t . '</div>';
684 if ( isset( $allCats['hidden'] ) ) {
685 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
686 $class = 'mw-hidden-cats-user-shown';
687 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
688 $class = 'mw-hidden-cats-ns-shown';
690 $class = 'mw-hidden-cats-hidden';
693 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
694 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
695 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
699 # optional 'dmoz-like' category browser. Will be shown under the list
700 # of categories an article belong to
701 if ( $wgUseCategoryBrowser ) {
702 $s .= '<br /><hr />';
704 # get a big array of the parents tree
705 $parenttree = $this->mTitle
->getParentCategoryTree();
706 # Skin object passed by reference cause it can not be
707 # accessed under the method subfunction drawCategoryBrowser
708 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
709 # Clean out bogus first entry and sort them
710 unset( $tempout[0] );
712 # Output one per line
713 $s .= implode( "<br />\n", $tempout );
720 * Render the array as a serie of links.
721 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
722 * @param &skin Object: skin passed by reference
723 * @return String separated by >, terminate with "\n"
725 function drawCategoryBrowser( $tree, &$skin ) {
728 foreach ( $tree as $element => $parent ) {
729 if ( empty( $parent ) ) {
730 # element start a new list
733 # grab the others elements
734 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
737 # add our current element to the list
738 $eltitle = Title
::newFromText( $element );
739 $return .= $skin->link( $eltitle, $eltitle->getText() );
745 function getCategories() {
746 $catlinks = $this->getCategoryLinks();
748 $classes = 'catlinks';
750 global $wgOut, $wgUser;
752 // Check what we're showing
753 $allCats = $wgOut->getCategoryLinks();
754 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
755 $this->mTitle
->getNamespace() == NS_CATEGORY
;
757 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
758 $classes .= ' catlinks-allhidden';
761 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
765 * This runs a hook to allow extensions placing their stuff after content
766 * and article metadata (e.g. categories).
767 * Note: This function has nothing to do with afterContent().
769 * This hook is placed here in order to allow using the same hook for all
770 * skins, both the SkinTemplate based ones and the older ones, which directly
771 * use this class to get their data.
773 * The output of this function gets processed in SkinTemplate::outputPage() for
774 * the SkinTemplate based skins, all other skins should directly echo it.
776 * Returns an empty string by default, if not changed by any hook function.
778 protected function afterContentHook() {
781 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
782 // adding just some spaces shouldn't toggle the output
783 // of the whole <div/>, so we use trim() here
784 if ( trim( $data ) != '' ) {
785 // Doing this here instead of in the skins to
786 // ensure that the div has the same ID in all
788 $data = "<div id='mw-data-after-content'>\n" .
793 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
800 * Generate debug data HTML for displaying at the bottom of the main content
802 * @return String HTML containing debug data, if enabled (otherwise empty).
804 protected function generateDebugHTML() {
805 global $wgShowDebug, $wgOut;
807 if ( $wgShowDebug ) {
808 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext
);
809 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
810 $listInternals . "</ul>\n";
816 private function formatDebugHTML( $debugText ) {
817 $lines = explode( "\n", $debugText );
821 foreach ( $lines as $line ) {
822 $display = ltrim( $line );
823 $ident = strlen( $line ) - strlen( $display );
824 $diff = $ident - $curIdent;
826 if ( $display == '' ) {
827 $display = "\xc2\xa0";
830 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
833 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
835 $display = htmlspecialchars( $display );
839 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
840 } elseif ( $diff == 0 ) {
841 $ret .= "</li><li>\n";
843 $ret .= str_repeat( "<ul><li>\n", $diff );
845 $ret .= $display . "\n";
850 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
856 * This gets called shortly before the </body> tag.
857 * @param $out OutputPage object
858 * @return String HTML-wrapped JS code to be put before </body>
860 function bottomScripts( $out ) {
861 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
862 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
864 return $bottomScriptText;
867 /** @return string Retrievied from HTML text */
868 function printSource() {
869 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
870 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
873 function getUndeleteLink() {
874 global $wgUser, $wgLang, $wgRequest;
876 $action = $wgRequest->getVal( 'action', 'view' );
878 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
879 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
880 $n = $this->mTitle
->isDeleted();
883 if ( $wgUser->isAllowed( 'undelete' ) ) {
884 $msg = 'thisisdeleted';
886 $msg = 'viewdeleted';
892 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
893 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
896 array( 'known', 'noclasses' )
905 function subPageSubtitle() {
908 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this ) ) ) {
914 if ( $wgOut->isArticle() && MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
915 $ptext = $this->mTitle
->getPrefixedText();
916 if ( preg_match( '/\//', $ptext ) ) {
917 $links = explode( '/', $ptext );
923 foreach ( $links as $link ) {
924 $growinglink .= $link;
926 $linkObj = Title
::newFromText( $growinglink );
928 if ( is_object( $linkObj ) && $linkObj->exists() ) {
929 $getlink = $this->link(
931 htmlspecialchars( $display ),
934 array( 'known', 'noclasses' )
940 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
942 $subpages .= '< ';
945 $subpages .= $getlink;
959 * Returns true if the IP should be shown in the header
961 function showIPinHeader() {
962 global $wgShowIPinHeader;
963 return $wgShowIPinHeader && session_id() != '';
966 function getSearchLink() {
967 $searchPage = SpecialPage
::getTitleFor( 'Search' );
968 return $searchPage->getLocalURL();
971 function escapeSearchLink() {
972 return htmlspecialchars( $this->getSearchLink() );
975 function getCopyright( $type = 'detect' ) {
976 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
978 if ( $type == 'detect' ) {
979 $diff = $wgRequest->getVal( 'diff' );
981 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
988 if ( $type == 'history' ) {
989 $msg = 'history_copyright';
996 if ( $wgRightsPage ) {
997 $title = Title
::newFromText( $wgRightsPage );
998 $link = $this->linkKnown( $title, $wgRightsText );
999 } elseif ( $wgRightsUrl ) {
1000 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1001 } elseif ( $wgRightsText ) {
1002 $link = $wgRightsText;
1008 // Allow for site and per-namespace customization of copyright notice.
1011 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle
, $type, &$msg, &$link, &$forContent ) );
1013 if ( $forContent ) {
1014 $out .= wfMsgForContent( $msg, $link );
1016 $out .= wfMsg( $msg, $link );
1022 function getCopyrightIcon() {
1023 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1027 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1028 $out = $wgCopyrightIcon;
1029 } elseif ( $wgRightsIcon ) {
1030 $icon = htmlspecialchars( $wgRightsIcon );
1032 if ( $wgRightsUrl ) {
1033 $url = htmlspecialchars( $wgRightsUrl );
1034 $out .= '<a href="' . $url . '">';
1037 $text = htmlspecialchars( $wgRightsText );
1038 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1040 if ( $wgRightsUrl ) {
1049 * Gets the powered by MediaWiki icon.
1052 function getPoweredBy() {
1053 global $wgStylePath;
1055 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1056 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1057 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
1062 * Get the timestamp of the latest revision, formatted in user language
1064 * @param $article Article object. Used if we're working with the current revision
1067 protected function lastModified( $article ) {
1070 if ( !$this->isRevisionCurrent() ) {
1071 $timestamp = Revision
::getTimestampFromId( $this->mTitle
, $this->mRevisionId
);
1073 $timestamp = $article->getTimestamp();
1077 $d = $wgLang->date( $timestamp, true );
1078 $t = $wgLang->time( $timestamp, true );
1079 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1084 if ( wfGetLB()->getLaggedSlaveMode() ) {
1085 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1091 function logoText( $align = '' ) {
1092 if ( $align != '' ) {
1093 $a = " align='{$align}'";
1098 $mp = wfMsg( 'mainpage' );
1099 $mptitle = Title
::newMainPage();
1100 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1102 $logourl = $this->getLogo();
1103 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1109 * Renders a $wgFooterIcons icon acording to the method's arguments
1110 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1111 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1113 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1114 if ( is_string( $icon ) ) {
1116 } else { // Assuming array
1117 $url = isset($icon["url"]) ?
$icon["url"] : null;
1118 unset( $icon["url"] );
1119 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1120 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1122 $html = htmlspecialchars( $icon["alt"] );
1125 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1132 * Gets the link to the wiki's main page.
1135 function mainPageLink() {
1137 Title
::newMainPage(),
1138 wfMsg( 'mainpage' ),
1141 array( 'known', 'noclasses' )
1147 public function footerLink( $desc, $page ) {
1148 // if the link description has been set to "-" in the default language,
1149 if ( wfMsgForContent( $desc ) == '-' ) {
1150 // then it is disabled, for all languages.
1153 // Otherwise, we display the link for the user, described in their
1154 // language (which may or may not be the same as the default language),
1155 // but we make the link target be the one site-wide page.
1156 $title = Title
::newFromText( wfMsgForContent( $page ) );
1158 return $this->linkKnown(
1160 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1166 * Gets the link to the wiki's privacy policy page.
1168 function privacyLink() {
1169 return $this->footerLink( 'privacy', 'privacypage' );
1173 * Gets the link to the wiki's about page.
1175 function aboutLink() {
1176 return $this->footerLink( 'aboutsite', 'aboutpage' );
1180 * Gets the link to the wiki's general disclaimers page.
1182 function disclaimerLink() {
1183 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1187 * Return URL options for the 'edit page' link.
1188 * This may include an 'oldid' specifier, if the current page view is such.
1193 function editUrlOptions() {
1194 $options = array( 'action' => 'edit' );
1196 if ( !$this->isRevisionCurrent() ) {
1197 $options['oldid'] = intval( $this->mRevisionId
);
1203 function showEmailUser( $id ) {
1205 $targetUser = User
::newFromId( $id );
1206 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1207 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1211 * Return a fully resolved style path url to images or styles stored in the common folder.
1212 * This method returns a url resolved using the configured skin style path
1213 * and includes the style version inside of the url.
1214 * @param $name String: The name or path of a skin resource file
1215 * @return String The fully resolved style path url including styleversion
1217 function getCommonStylePath( $name ) {
1218 global $wgStylePath, $wgStyleVersion;
1219 return "$wgStylePath/common/$name?$wgStyleVersion";
1223 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1224 * This method returns a url resolved using the configured skin style path
1225 * and includes the style version inside of the url.
1226 * @param $name String: The name or path of a skin resource file
1227 * @return String The fully resolved style path url including styleversion
1229 function getSkinStylePath( $name ) {
1230 global $wgStylePath, $wgStyleVersion;
1231 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1234 /* these are used extensively in SkinTemplate, but also some other places */
1235 static function makeMainPageUrl( $urlaction = '' ) {
1236 $title = Title
::newMainPage();
1237 self
::checkTitle( $title, '' );
1239 return $title->getLocalURL( $urlaction );
1242 static function makeSpecialUrl( $name, $urlaction = '' ) {
1243 $title = SpecialPage
::getTitleFor( $name );
1244 return $title->getLocalURL( $urlaction );
1247 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1248 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1249 return $title->getLocalURL( $urlaction );
1252 static function makeI18nUrl( $name, $urlaction = '' ) {
1253 $title = Title
::newFromText( wfMsgForContent( $name ) );
1254 self
::checkTitle( $title, $name );
1255 return $title->getLocalURL( $urlaction );
1258 static function makeUrl( $name, $urlaction = '' ) {
1259 $title = Title
::newFromText( $name );
1260 self
::checkTitle( $title, $name );
1262 return $title->getLocalURL( $urlaction );
1266 * If url string starts with http, consider as external URL, else
1269 static function makeInternalOrExternalUrl( $name ) {
1270 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1273 return self
::makeUrl( $name );
1277 # this can be passed the NS number as defined in Language.php
1278 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1279 $title = Title
::makeTitleSafe( $namespace, $name );
1280 self
::checkTitle( $title, $name );
1282 return $title->getLocalURL( $urlaction );
1285 /* these return an array with the 'href' and boolean 'exists' */
1286 static function makeUrlDetails( $name, $urlaction = '' ) {
1287 $title = Title
::newFromText( $name );
1288 self
::checkTitle( $title, $name );
1291 'href' => $title->getLocalURL( $urlaction ),
1292 'exists' => $title->getArticleID() != 0,
1297 * Make URL details where the article exists (or at least it's convenient to think so)
1299 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1300 $title = Title
::newFromText( $name );
1301 self
::checkTitle( $title, $name );
1304 'href' => $title->getLocalURL( $urlaction ),
1309 # make sure we have some title to operate on
1310 static function checkTitle( &$title, $name ) {
1311 if ( !is_object( $title ) ) {
1312 $title = Title
::newFromText( $name );
1313 if ( !is_object( $title ) ) {
1314 $title = Title
::newFromText( '--error: link target missing--' );
1320 * Build an array that represents the sidebar(s), the navigation bar among them
1324 function buildSidebar() {
1325 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1327 wfProfileIn( __METHOD__
);
1329 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1331 if ( $wgEnableSidebarCache ) {
1332 $cachedsidebar = $parserMemc->get( $key );
1333 if ( $cachedsidebar ) {
1334 wfProfileOut( __METHOD__
);
1335 return $cachedsidebar;
1340 $this->addToSidebar( $bar, 'sidebar' );
1342 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1343 if ( $wgEnableSidebarCache ) {
1344 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1347 wfProfileOut( __METHOD__
);
1351 * Add content from a sidebar system message
1352 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1354 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1356 * @param &$bar array
1357 * @param $message String
1359 function addToSidebar( &$bar, $message ) {
1360 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1364 * Add content from plain text
1366 * @param &$bar array
1367 * @param $text string
1369 function addToSidebarPlain( &$bar, $text ) {
1370 $lines = explode( "\n", $text );
1371 $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.
1375 foreach ( $lines as $line ) {
1376 if ( strpos( $line, '*' ) !== 0 ) {
1380 if ( strpos( $line, '**' ) !== 0 ) {
1381 $heading = trim( $line, '* ' );
1382 if ( !array_key_exists( $heading, $bar ) ) {
1383 $bar[$heading] = array();
1386 $line = trim( $line, '* ' );
1388 if ( strpos( $line, '|' ) !== false ) { // sanity check
1389 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1390 $link = wfMsgForContent( $line[0] );
1392 if ( $link == '-' ) {
1396 $text = wfMsgExt( $line[1], 'parsemag' );
1398 if ( wfEmptyMsg( $line[1], $text ) ) {
1402 if ( wfEmptyMsg( $line[0], $link ) ) {
1406 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1409 $title = Title
::newFromText( $link );
1412 $title = $title->fixSpecialName();
1413 $href = $title->getLocalURL();
1415 $href = 'INVALID-TITLE';
1419 $bar[$heading][] = array(
1422 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1425 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1428 $line = substr( $line, 2, strlen( $line ) - 4 );
1430 $options = new ParserOptions();
1431 $options->setEditSection( false );
1432 $options->setInterfaceMessage( true );
1433 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->mTitle
, $options )->getText();
1440 if ( count( $wikiBar ) > 0 ) {
1441 $bar = array_merge( $bar, $wikiBar );
1448 * Should we include common/wikiprintable.css? Skins that have their own
1449 * print stylesheet should override this and return false. (This is an
1450 * ugly hack to get Monobook to play nicely with
1451 * OutputPage::headElement().)
1455 public function commonPrintStylesheet() {
1460 * Gets new talk page messages for the current user.
1461 * @return MediaWiki message or if no new talk page messages, nothing
1463 function getNewtalks() {
1464 global $wgUser, $wgOut;
1466 $newtalks = $wgUser->getNewMessageLinks();
1469 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1470 $userTitle = $this->mUser
->getUserPage();
1471 $userTalkTitle = $userTitle->getTalkPage();
1473 if ( !$userTalkTitle->equals( $this->mTitle
) ) {
1474 $newMessagesLink = $this->link(
1476 wfMsgHtml( 'newmessageslink' ),
1478 array( 'redirect' => 'no' ),
1479 array( 'known', 'noclasses' )
1482 $newMessagesDiffLink = $this->link(
1484 wfMsgHtml( 'newmessagesdifflink' ),
1486 array( 'diff' => 'cur' ),
1487 array( 'known', 'noclasses' )
1491 'youhavenewmessages',
1493 $newMessagesDiffLink
1495 # Disable Squid cache
1496 $wgOut->setSquidMaxage( 0 );
1498 } elseif ( count( $newtalks ) ) {
1499 // _>" " for BC <= 1.16
1500 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1503 foreach ( $newtalks as $newtalk ) {
1504 $msgs[] = Xml
::element(
1506 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1509 $parts = implode( $sep, $msgs );
1510 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1511 $wgOut->setSquidMaxage( 0 );
1518 * Get a cached notice
1520 * @param $name String: message name, or 'default' for $wgSiteNotice
1521 * @return String: HTML fragment
1523 private function getCachedNotice( $name ) {
1524 global $wgOut, $wgRenderHashAppend, $parserMemc;
1526 wfProfileIn( __METHOD__
);
1530 if( $name === 'default' ) {
1532 global $wgSiteNotice;
1533 $notice = $wgSiteNotice;
1534 if( empty( $notice ) ) {
1535 wfProfileOut( __METHOD__
);
1539 $msg = wfMessage( $name )->inContentLanguage();
1540 if( $msg->isDisabled() ) {
1541 wfProfileOut( __METHOD__
);
1544 $notice = $msg->plain();
1547 // Use the extra hash appender to let eg SSL variants separately cache.
1548 $key = wfMemcKey( $name . $wgRenderHashAppend );
1549 $cachedNotice = $parserMemc->get( $key );
1550 if( is_array( $cachedNotice ) ) {
1551 if( md5( $notice ) == $cachedNotice['hash'] ) {
1552 $notice = $cachedNotice['html'];
1561 if( is_object( $wgOut ) ) {
1562 $parsed = $wgOut->parse( $notice );
1563 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1566 wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
1571 $notice = '<div id="localNotice">' .$notice . '</div>';
1572 wfProfileOut( __METHOD__
);
1577 * Get a notice based on page's namespace
1579 * @return String: HTML fragment
1581 function getNamespaceNotice() {
1582 wfProfileIn( __METHOD__
);
1584 $key = 'namespacenotice-' . $this->mTitle
->getNsText();
1585 $namespaceNotice = wfGetCachedNotice( $key );
1586 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1587 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1589 $namespaceNotice = '';
1592 wfProfileOut( __METHOD__
);
1593 return $namespaceNotice;
1597 * Get the site notice
1599 * @return String: HTML fragment
1601 function getSiteNotice() {
1604 wfProfileIn( __METHOD__
);
1607 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1608 if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
1609 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1611 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1612 if ( !$anonNotice ) {
1613 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1615 $siteNotice = $anonNotice;
1618 if ( !$siteNotice ) {
1619 $siteNotice = $this->getCachedNotice( 'default' );
1623 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1624 wfProfileOut( __METHOD__
);