3b25570989e55f7631fbff4c85ab88a16464f34a
3 * @defgroup Skins Skins
6 if ( !defined( 'MEDIAWIKI' ) ) {
11 * The main skin class that provide methods and properties for all other skins.
12 * This base class is also the "Standard" skin.
14 * See docs/skin.txt for more information.
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
24 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
25 protected $skinname = 'standard';
27 * todo Fixme: should be protected :-\
31 protected $mRelevantTitle = null;
32 protected $mRelevantUser = null;
35 * Fetch the set of available skins.
36 * @return array of strings
38 static function getSkinNames() {
39 global $wgValidSkinNames;
40 static $skinsInitialised = false;
42 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
43 # Get a list of available skins
44 # Build using the regular expression '^(.*).php$'
45 # Array keys are all lower case, array value keep the case used by filename
47 wfProfileIn( __METHOD__
. '-init' );
49 global $wgStyleDirectory;
51 $skinDir = dir( $wgStyleDirectory );
53 # while code from www.php.net
54 while ( false !== ( $file = $skinDir->read() ) ) {
55 // Skip non-PHP files, hidden files, and '.dep' includes
58 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
60 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
64 $skinsInitialised = true;
65 wfProfileOut( __METHOD__
. '-init' );
67 return $wgValidSkinNames;
71 * Fetch the list of usable skins in regards to $wgSkipSkins.
72 * Useful for Special:Preferences and other places where you
73 * only want to show skins users _can_ use.
74 * @return array of strings
76 public static function getUsableSkins() {
79 $usableSkins = self
::getSkinNames();
81 foreach ( $wgSkipSkins as $skip ) {
82 unset( $usableSkins[$skip] );
89 * Normalize a skin preference value to a form that can be loaded.
90 * If a skin can't be found, it will fall back to the configured
91 * default (or the old 'Classic' skin if that's broken).
92 * @param $key String: 'monobook', 'standard', etc.
95 static function normalizeKey( $key ) {
96 global $wgDefaultSkin;
98 $skinNames = Skin
::getSkinNames();
101 // Don't return the default immediately;
102 // in a misconfiguration we need to fall back.
103 $key = $wgDefaultSkin;
106 if ( isset( $skinNames[$key] ) ) {
110 // Older versions of the software used a numeric setting
111 // in the user preferences.
118 if ( isset( $fallback[$key] ) ) {
119 $key = $fallback[$key];
122 if ( isset( $skinNames[$key] ) ) {
124 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
125 return $wgDefaultSkin;
132 * Factory method for loading a skin of a given type
133 * @param $key String: 'monobook', 'standard', etc.
136 static function &newFromKey( $key ) {
137 global $wgStyleDirectory;
139 $key = Skin
::normalizeKey( $key );
141 $skinNames = Skin
::getSkinNames();
142 $skinName = $skinNames[$key];
143 $className = "Skin{$skinName}";
145 # Grab the skin class and initialise it.
146 if ( !class_exists( $className ) ) {
147 // Preload base classes to work around APC/PHP5 bug
148 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
150 if ( file_exists( $deps ) ) {
151 include_once( $deps );
153 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
155 # Check if we got if not failback to default skin
156 if ( !class_exists( $className ) ) {
157 # DO NOT die if the class isn't found. This breaks maintenance
158 # scripts and can cause a user account to be unrecoverable
159 # except by SQL manipulation if a previously valid skin name
160 # is no longer valid.
161 wfDebug( "Skin class does not exist: $className\n" );
162 $className = 'SkinVector';
163 require_once( "{$wgStyleDirectory}/Vector.php" );
166 $skin = new $className;
170 /** @return string path to the skin stylesheet */
171 function getStylesheet() {
172 return 'common/wikistandard.css';
175 /** @return string skin name */
176 public function getSkinName() {
177 return $this->skinname
;
180 function initPage( OutputPage
$out ) {
181 wfProfileIn( __METHOD__
);
183 $this->mRevisionId
= $out->mRevisionId
;
184 $this->preloadExistence();
187 wfProfileOut( __METHOD__
);
191 * Preload the existence of three commonly-requested pages in a single query
193 function preloadExistence() {
197 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
200 if ( $this->mTitle
->getNamespace() == NS_SPECIAL
) {
202 } elseif ( $this->mTitle
->isTalkPage() ) {
203 $titles[] = $this->mTitle
->getSubjectPage();
205 $titles[] = $this->mTitle
->getTalkPage();
208 $lb = new LinkBatch( $titles );
209 $lb->setCaller( __METHOD__
);
214 * Set some local variables
216 protected function setMembers() {
218 $this->mUser
= $wgUser;
219 $this->userpage
= $wgUser->getUserPage()->getPrefixedText();
220 $this->usercss
= false;
224 * Whether the revision displayed is the latest revision of the page
228 public function isRevisionCurrent() {
229 return $this->mRevisionId
== 0 ||
$this->mRevisionId
== $this->mTitle
->getLatestRevID();
234 * @param $t Title object to use
236 public function setTitle( $t ) {
244 public function getTitle() {
245 return $this->mTitle
;
249 * Set the "relevant" title
250 * @see self::getRelevantTitle()
251 * @param $t Title object to use
253 public function setRelevantTitle( $t ) {
254 $this->mRelevantTitle
= $t;
258 * Return the "relevant" title.
259 * A "relevant" title is not necessarily the actual title of the page.
260 * Special pages like Special:MovePage use set the page they are acting on
261 * as their "relevant" title, this allows the skin system to display things
262 * such as content tabs which belong to to that page instead of displaying
263 * a basic special page tab which has almost no meaning.
265 public function getRelevantTitle() {
266 if ( isset($this->mRelevantTitle
) ) {
267 return $this->mRelevantTitle
;
269 return $this->mTitle
;
273 * Set the "relevant" user
274 * @see self::getRelevantUser()
275 * @param $u User object to use
277 public function setRelevantUser( $u ) {
278 $this->mRelevantUser
= $u;
282 * Return the "relevant" user.
283 * A "relevant" user is similar to a relevant title. Special pages like
284 * Special:Contributions mark the user which they are relevant to so that
285 * things like the toolbox can display the information they usually are only
286 * able to display on a user's userpage and talkpage.
288 public function getRelevantUser() {
289 if ( isset($this->mRelevantUser
) ) {
290 return $this->mRelevantUser
;
292 $title = $this->getRelevantTitle();
293 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
294 $rootUser = strtok( $title->getText(), '/' );
295 if ( User
::isIP( $rootUser ) ) {
296 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
298 $user = User
::newFromName( $rootUser );
299 if ( $user->isLoggedIn() ) {
300 $this->mRelevantUser
= $user;
303 return $this->mRelevantUser
;
309 * Outputs the HTML generated by other functions.
310 * @param $out Object: instance of OutputPage
313 function outputPage( OutputPage
$out ) {
314 global $wgDebugComments;
315 wfProfileIn( __METHOD__
);
317 $this->initPage( $out );
319 // See self::afterContentHook() for documentation
320 $afterContent = $this->afterContentHook();
322 $out->out( $out->headElement( $this ) );
324 if ( $wgDebugComments ) {
325 $out->out( "<!-- Debug output:\n" .
326 $out->mDebugtext
. "-->\n" );
329 $out->out( $this->beforeContent() );
331 $out->out( $out->mBodytext
. "\n" );
333 $out->out( $this->afterContent() );
335 $out->out( $afterContent );
337 $out->out( $this->bottomScripts( $out ) );
339 $out->out( wfReportTime() );
341 $out->out( "\n</body></html>" );
342 wfProfileOut( __METHOD__
);
345 static function makeVariablesScript( $data ) {
347 return Html
::inlineScript(
348 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
356 * To make it harder for someone to slip a user a fake
357 * user-JavaScript or user-CSS preview, a random token
358 * is associated with the login session. If it's not
359 * passed back with the preview request, we won't render
362 * @param $action String: 'edit', 'submit' etc.
365 public function userCanPreview( $action ) {
366 global $wgRequest, $wgUser;
368 if ( $action != 'submit' ) {
371 if ( !$wgRequest->wasPosted() ) {
374 if ( !$this->mTitle
->userCanEditCssSubpage() ) {
377 if ( !$this->mTitle
->userCanEditJsSubpage() ) {
381 return $wgUser->matchEditToken(
382 $wgRequest->getVal( 'wpEditToken' ) );
386 * Generated JavaScript action=raw&gen=js
387 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
388 * nated together. For some bizarre reason, it does *not* return any
389 * custom user JS from subpages. Huh?
391 * There's absolutely no reason to have separate Monobook/Common JSes.
392 * Any JS that cares can just check the skin variable generated at the
393 * top. For now Monobook.js will be maintained, but it should be consi-
396 * @param $skinName String: If set, overrides the skin name
399 public function generateUserJs( $skinName = null ) {
401 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
407 * Generate user stylesheet for action=raw&gen=css
409 public function generateUserStylesheet() {
411 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
417 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
418 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
420 protected function reallyGenerateUserStylesheet() {
422 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
430 function setupUserCss( OutputPage
$out ) {
431 global $wgRequest, $wgUser;
432 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
434 wfProfileIn( __METHOD__
);
436 $this->setupSkinUserCss( $out );
437 // Add any extension CSS
438 foreach ( $out->getExtStyle() as $url ) {
439 $out->addStyle( $url );
442 // Per-site custom styles
443 if ( $wgUseSiteCss ) {
444 $out->addModuleStyles( array( 'site', 'noscript' ) );
445 if( $wgUser->isLoggedIn() ){
446 $out->addModuleStyles( 'user.groups' );
450 // Per-user custom styles
451 if ( $wgAllowUserCss ) {
452 if ( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
453 // @FIXME: properly escape the cdata!
454 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
456 $out->addModuleStyles( 'user' );
460 // Per-user preference styles
461 if ( $wgAllowUserCssPrefs ) {
462 $out->addModuleStyles( 'user.options' );
465 wfProfileOut( __METHOD__
);
469 * Get the query to generate a dynamic stylesheet
473 public static function getDynamicStylesheetQuery() {
474 global $wgSquidMaxage;
478 'maxage' => $wgSquidMaxage,
479 'usemsgcache' => 'yes',
480 'ctype' => 'text/css',
481 'smaxage' => $wgSquidMaxage,
486 * Add skin specific stylesheets
487 * @param $out OutputPage
490 abstract function setupSkinUserCss( OutputPage
$out );
492 function getPageClasses( $title ) {
493 $numeric = 'ns-' . $title->getNamespace();
495 if ( $title->getNamespace() == NS_SPECIAL
) {
496 $type = 'ns-special';
497 // bug 23315: provide a class based on the canonical special page name without subpages
498 list( $canonicalName ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
499 if ( $canonicalName ) {
500 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
502 $type .= ' mw-invalidspecialpage';
504 } elseif ( $title->isTalkPage() ) {
507 $type = 'ns-subject';
510 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
512 return "$numeric $type $name";
516 * This will be called by OutputPage::headElement when it is creating the
517 * <body> tag, skins can override it if they have a need to add in any
518 * body attributes or classes of their own.
520 function addToBodyAttributes( $out, &$bodyAttrs ) {
521 // does nothing by default
533 * The format without an explicit $out argument is deprecated
535 function getCategoryLinks( OutputPage
$out=null ) {
536 global $wgUseCategoryBrowser, $wgContLang, $wgUser;
538 if ( is_null( $out ) ) {
539 // Backwards compatibility for when there was no $out arg
544 if ( count( $out->mCategoryLinks
) == 0 ) {
549 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
551 // Use Unicode bidi embedding override characters,
552 // to make sure links don't smash each other up in ugly ways.
553 $dir = $wgContLang->getDir();
554 $embed = "<span dir='$dir'>";
557 $allCats = $out->getCategoryLinks();
559 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
561 if ( !empty( $allCats['normal'] ) ) {
562 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
564 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
565 $s .= '<div id="mw-normal-catlinks">' .
566 $this->link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
567 . $colon . $t . '</div>';
571 if ( isset( $allCats['hidden'] ) ) {
572 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
573 $class = 'mw-hidden-cats-user-shown';
574 } elseif ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
575 $class = 'mw-hidden-cats-ns-shown';
577 $class = 'mw-hidden-cats-hidden';
580 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
581 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
582 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
586 # optional 'dmoz-like' category browser. Will be shown under the list
587 # of categories an article belong to
588 if ( $wgUseCategoryBrowser ) {
589 $s .= '<br /><hr />';
591 # get a big array of the parents tree
592 $parenttree = $this->mTitle
->getParentCategoryTree();
593 # Skin object passed by reference cause it can not be
594 # accessed under the method subfunction drawCategoryBrowser
595 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
596 # Clean out bogus first entry and sort them
597 unset( $tempout[0] );
599 # Output one per line
600 $s .= implode( "<br />\n", $tempout );
607 * Render the array as a serie of links.
608 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
609 * @param &skin Object: skin passed by reference
610 * @return String separated by >, terminate with "\n"
612 function drawCategoryBrowser( $tree, &$skin ) {
615 foreach ( $tree as $element => $parent ) {
616 if ( empty( $parent ) ) {
617 # element start a new list
620 # grab the others elements
621 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' > ';
624 # add our current element to the list
625 $eltitle = Title
::newFromText( $element );
626 $return .= $skin->link( $eltitle, $eltitle->getText() );
633 * The ->getCategories() form is deprecated, please instead use
634 * the ->getCategories( $out ) form with whatout OutputPage is on hand
636 function getCategories( OutputPage
$out=null ) {
637 if ( is_null( $out ) ) {
638 // Backwards compatibility for when there was no $out arg
643 $catlinks = $this->getCategoryLinks( $out );
645 $classes = 'catlinks';
649 // Check what we're showing
650 $allCats = $out->getCategoryLinks();
651 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
652 $this->mTitle
->getNamespace() == NS_CATEGORY
;
654 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
655 $classes .= ' catlinks-allhidden';
658 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
662 * This runs a hook to allow extensions placing their stuff after content
663 * and article metadata (e.g. categories).
664 * Note: This function has nothing to do with afterContent().
666 * This hook is placed here in order to allow using the same hook for all
667 * skins, both the SkinTemplate based ones and the older ones, which directly
668 * use this class to get their data.
670 * The output of this function gets processed in SkinTemplate::outputPage() for
671 * the SkinTemplate based skins, all other skins should directly echo it.
673 * Returns an empty string by default, if not changed by any hook function.
675 protected function afterContentHook() {
678 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
679 // adding just some spaces shouldn't toggle the output
680 // of the whole <div/>, so we use trim() here
681 if ( trim( $data ) != '' ) {
682 // Doing this here instead of in the skins to
683 // ensure that the div has the same ID in all
685 $data = "<div id='mw-data-after-content'>\n" .
690 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
697 * Generate debug data HTML for displaying at the bottom of the main content
699 * @return String HTML containing debug data, if enabled (otherwise empty).
701 protected function generateDebugHTML( OutputPage
$out ) {
704 if ( $wgShowDebug ) {
705 $listInternals = $this->formatDebugHTML( $out->mDebugtext
);
706 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
707 $listInternals . "</ul>\n";
713 private function formatDebugHTML( $debugText ) {
714 global $wgDebugTimestamps;
716 $lines = explode( "\n", $debugText );
720 foreach ( $lines as $line ) {
722 if ( $wgDebugTimestamps ) {
724 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
726 $line = substr( $line, strlen( $pre ) );
729 $display = ltrim( $line );
730 $ident = strlen( $line ) - strlen( $display );
731 $diff = $ident - $curIdent;
733 $display = $pre . $display;
734 if ( $display == '' ) {
735 $display = "\xc2\xa0";
738 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
741 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
743 $display = htmlspecialchars( $display );
747 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
748 } elseif ( $diff == 0 ) {
749 $ret .= "</li><li>\n";
751 $ret .= str_repeat( "<ul><li>\n", $diff );
753 $ret .= "<tt>$display</tt>\n";
758 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
764 * This gets called shortly before the </body> tag.
765 * @param $out OutputPage object
766 * @return String HTML-wrapped JS code to be put before </body>
768 function bottomScripts( $out ) {
769 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
770 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
772 return $bottomScriptText;
775 /** @return string Retrievied from HTML text */
776 function printSource() {
777 $url = htmlspecialchars( $this->mTitle
->getFullURL() );
778 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
781 function getUndeleteLink() {
782 global $wgUser, $wgLang, $wgRequest;
784 $action = $wgRequest->getVal( 'action', 'view' );
786 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
787 ( $this->mTitle
->getArticleId() == 0 ||
$action == 'history' ) ) {
788 $n = $this->mTitle
->isDeleted();
791 if ( $wgUser->isAllowed( 'undelete' ) ) {
792 $msg = 'thisisdeleted';
794 $msg = 'viewdeleted';
800 SpecialPage
::getTitleFor( 'Undelete', $this->mTitle
->getPrefixedDBkey() ),
801 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
804 array( 'known', 'noclasses' )
814 * The format without an explicit $out argument is deprecated
816 function subPageSubtitle( OutputPage
$out=null ) {
817 if ( is_null( $out ) ) {
818 // Backwards compatibility for when there was no $out arg
825 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
829 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
830 $ptext = $this->mTitle
->getPrefixedText();
831 if ( preg_match( '/\//', $ptext ) ) {
832 $links = explode( '/', $ptext );
838 foreach ( $links as $link ) {
839 $growinglink .= $link;
841 $linkObj = Title
::newFromText( $growinglink );
843 if ( is_object( $linkObj ) && $linkObj->exists() ) {
844 $getlink = $this->link(
846 htmlspecialchars( $display ),
849 array( 'known', 'noclasses' )
855 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
857 $subpages .= '< ';
860 $subpages .= $getlink;
874 * Returns true if the IP should be shown in the header
876 function showIPinHeader() {
877 global $wgShowIPinHeader;
878 return $wgShowIPinHeader && session_id() != '';
881 function getSearchLink() {
882 $searchPage = SpecialPage
::getTitleFor( 'Search' );
883 return $searchPage->getLocalURL();
886 function escapeSearchLink() {
887 return htmlspecialchars( $this->getSearchLink() );
890 function getCopyright( $type = 'detect' ) {
891 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
893 if ( $type == 'detect' ) {
894 $diff = $wgRequest->getVal( 'diff' );
896 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
903 if ( $type == 'history' ) {
904 $msg = 'history_copyright';
911 if ( $wgRightsPage ) {
912 $title = Title
::newFromText( $wgRightsPage );
913 $link = $this->linkKnown( $title, $wgRightsText );
914 } elseif ( $wgRightsUrl ) {
915 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
916 } elseif ( $wgRightsText ) {
917 $link = $wgRightsText;
923 // Allow for site and per-namespace customization of copyright notice.
926 wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle
, $type, &$msg, &$link, &$forContent ) );
929 $out .= wfMsgForContent( $msg, $link );
931 $out .= wfMsg( $msg, $link );
937 function getCopyrightIcon() {
938 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
942 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
943 $out = $wgCopyrightIcon;
944 } elseif ( $wgRightsIcon ) {
945 $icon = htmlspecialchars( $wgRightsIcon );
947 if ( $wgRightsUrl ) {
948 $url = htmlspecialchars( $wgRightsUrl );
949 $out .= '<a href="' . $url . '">';
952 $text = htmlspecialchars( $wgRightsText );
953 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
955 if ( $wgRightsUrl ) {
964 * Gets the powered by MediaWiki icon.
967 function getPoweredBy() {
970 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
971 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
972 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
977 * Get the timestamp of the latest revision, formatted in user language
979 * @param $article Article object. Used if we're working with the current revision
982 protected function lastModified( $article ) {
985 if ( !$this->isRevisionCurrent() ) {
986 $timestamp = Revision
::getTimestampFromId( $this->mTitle
, $this->mRevisionId
);
988 $timestamp = $article->getTimestamp();
992 $d = $wgLang->date( $timestamp, true );
993 $t = $wgLang->time( $timestamp, true );
994 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
999 if ( wfGetLB()->getLaggedSlaveMode() ) {
1000 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1006 function logoText( $align = '' ) {
1007 if ( $align != '' ) {
1008 $a = " align='{$align}'";
1013 $mp = wfMsg( 'mainpage' );
1014 $mptitle = Title
::newMainPage();
1015 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
1017 $logourl = $this->getLogo();
1018 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1024 * Renders a $wgFooterIcons icon acording to the method's arguments
1025 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1026 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1028 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1029 if ( is_string( $icon ) ) {
1031 } else { // Assuming array
1032 $url = isset($icon["url"]) ?
$icon["url"] : null;
1033 unset( $icon["url"] );
1034 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1035 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1037 $html = htmlspecialchars( $icon["alt"] );
1040 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1047 * Gets the link to the wiki's main page.
1050 function mainPageLink() {
1052 Title
::newMainPage(),
1053 wfMsg( 'mainpage' ),
1056 array( 'known', 'noclasses' )
1062 public function footerLink( $desc, $page ) {
1063 // if the link description has been set to "-" in the default language,
1064 if ( wfMsgForContent( $desc ) == '-' ) {
1065 // then it is disabled, for all languages.
1068 // Otherwise, we display the link for the user, described in their
1069 // language (which may or may not be the same as the default language),
1070 // but we make the link target be the one site-wide page.
1071 $title = Title
::newFromText( wfMsgForContent( $page ) );
1073 return $this->linkKnown(
1075 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1081 * Gets the link to the wiki's privacy policy page.
1083 function privacyLink() {
1084 return $this->footerLink( 'privacy', 'privacypage' );
1088 * Gets the link to the wiki's about page.
1090 function aboutLink() {
1091 return $this->footerLink( 'aboutsite', 'aboutpage' );
1095 * Gets the link to the wiki's general disclaimers page.
1097 function disclaimerLink() {
1098 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1102 * Return URL options for the 'edit page' link.
1103 * This may include an 'oldid' specifier, if the current page view is such.
1108 function editUrlOptions() {
1109 $options = array( 'action' => 'edit' );
1111 if ( !$this->isRevisionCurrent() ) {
1112 $options['oldid'] = intval( $this->mRevisionId
);
1118 function showEmailUser( $id ) {
1120 $targetUser = User
::newFromId( $id );
1121 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1122 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1126 * Return a fully resolved style path url to images or styles stored in the common folder.
1127 * This method returns a url resolved using the configured skin style path
1128 * and includes the style version inside of the url.
1129 * @param $name String: The name or path of a skin resource file
1130 * @return String The fully resolved style path url including styleversion
1132 function getCommonStylePath( $name ) {
1133 global $wgStylePath, $wgStyleVersion;
1134 return "$wgStylePath/common/$name?$wgStyleVersion";
1138 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1139 * This method returns a url resolved using the configured skin style path
1140 * and includes the style version inside of the url.
1141 * @param $name String: The name or path of a skin resource file
1142 * @return String The fully resolved style path url including styleversion
1144 function getSkinStylePath( $name ) {
1145 global $wgStylePath, $wgStyleVersion;
1146 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1149 /* these are used extensively in SkinTemplate, but also some other places */
1150 static function makeMainPageUrl( $urlaction = '' ) {
1151 $title = Title
::newMainPage();
1152 self
::checkTitle( $title, '' );
1154 return $title->getLocalURL( $urlaction );
1157 static function makeSpecialUrl( $name, $urlaction = '' ) {
1158 $title = SpecialPage
::getTitleFor( $name );
1159 return $title->getLocalURL( $urlaction );
1162 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1163 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1164 return $title->getLocalURL( $urlaction );
1167 static function makeI18nUrl( $name, $urlaction = '' ) {
1168 $title = Title
::newFromText( wfMsgForContent( $name ) );
1169 self
::checkTitle( $title, $name );
1170 return $title->getLocalURL( $urlaction );
1173 static function makeUrl( $name, $urlaction = '' ) {
1174 $title = Title
::newFromText( $name );
1175 self
::checkTitle( $title, $name );
1177 return $title->getLocalURL( $urlaction );
1181 * If url string starts with http, consider as external URL, else
1184 static function makeInternalOrExternalUrl( $name ) {
1185 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1188 return self
::makeUrl( $name );
1192 # this can be passed the NS number as defined in Language.php
1193 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1194 $title = Title
::makeTitleSafe( $namespace, $name );
1195 self
::checkTitle( $title, $name );
1197 return $title->getLocalURL( $urlaction );
1200 /* these return an array with the 'href' and boolean 'exists' */
1201 static function makeUrlDetails( $name, $urlaction = '' ) {
1202 $title = Title
::newFromText( $name );
1203 self
::checkTitle( $title, $name );
1206 'href' => $title->getLocalURL( $urlaction ),
1207 'exists' => $title->getArticleID() != 0,
1212 * Make URL details where the article exists (or at least it's convenient to think so)
1214 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1215 $title = Title
::newFromText( $name );
1216 self
::checkTitle( $title, $name );
1219 'href' => $title->getLocalURL( $urlaction ),
1224 # make sure we have some title to operate on
1225 static function checkTitle( &$title, $name ) {
1226 if ( !is_object( $title ) ) {
1227 $title = Title
::newFromText( $name );
1228 if ( !is_object( $title ) ) {
1229 $title = Title
::newFromText( '--error: link target missing--' );
1235 * Build an array that represents the sidebar(s), the navigation bar among them
1239 function buildSidebar() {
1240 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1242 wfProfileIn( __METHOD__
);
1244 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1246 if ( $wgEnableSidebarCache ) {
1247 $cachedsidebar = $parserMemc->get( $key );
1248 if ( $cachedsidebar ) {
1249 wfProfileOut( __METHOD__
);
1250 return $cachedsidebar;
1255 $this->addToSidebar( $bar, 'sidebar' );
1257 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1258 if ( $wgEnableSidebarCache ) {
1259 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1262 wfProfileOut( __METHOD__
);
1266 * Add content from a sidebar system message
1267 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1269 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1271 * @param &$bar array
1272 * @param $message String
1274 function addToSidebar( &$bar, $message ) {
1275 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1279 * Add content from plain text
1281 * @param &$bar array
1282 * @param $text string
1284 function addToSidebarPlain( &$bar, $text ) {
1285 $lines = explode( "\n", $text );
1286 $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.
1290 foreach ( $lines as $line ) {
1291 if ( strpos( $line, '*' ) !== 0 ) {
1295 if ( strpos( $line, '**' ) !== 0 ) {
1296 $heading = trim( $line, '* ' );
1297 if ( !array_key_exists( $heading, $bar ) ) {
1298 $bar[$heading] = array();
1301 $line = trim( $line, '* ' );
1303 if ( strpos( $line, '|' ) !== false ) { // sanity check
1304 $line = MessageCache
::singleton()->transform( $line, false, null, $this->mTitle
);
1305 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1306 $link = wfMsgForContent( $line[0] );
1308 if ( $link == '-' ) {
1312 $text = wfMsgExt( $line[1], 'parsemag' );
1314 if ( wfEmptyMsg( $line[1] ) ) {
1318 if ( wfEmptyMsg( $line[0] ) ) {
1322 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1325 $title = Title
::newFromText( $link );
1328 $title = $title->fixSpecialName();
1329 $href = $title->getLocalURL();
1331 $href = 'INVALID-TITLE';
1335 $bar[$heading][] = array(
1338 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1341 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1344 $line = substr( $line, 2, strlen( $line ) - 4 );
1346 $options = new ParserOptions();
1347 $options->setEditSection( false );
1348 $options->setInterfaceMessage( true );
1349 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->mTitle
, $options )->getText();
1356 if ( count( $wikiBar ) > 0 ) {
1357 $bar = array_merge( $bar, $wikiBar );
1364 * Should we include common/wikiprintable.css? Skins that have their own
1365 * print stylesheet should override this and return false. (This is an
1366 * ugly hack to get Monobook to play nicely with
1367 * OutputPage::headElement().)
1371 public function commonPrintStylesheet() {
1376 * Gets new talk page messages for the current user.
1377 * @return MediaWiki message or if no new talk page messages, nothing
1378 * The format without an explicit $out argument is deprecated
1380 function getNewtalks( OutputPage
$out=null ) {
1383 if ( is_null( $out ) ) {
1384 // Backwards compatibility for when there was no $out arg
1389 $newtalks = $wgUser->getNewMessageLinks();
1392 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1393 $userTitle = $this->mUser
->getUserPage();
1394 $userTalkTitle = $userTitle->getTalkPage();
1396 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1397 $newMessagesLink = $this->link(
1399 wfMsgHtml( 'newmessageslink' ),
1401 array( 'redirect' => 'no' ),
1402 array( 'known', 'noclasses' )
1405 $newMessagesDiffLink = $this->link(
1407 wfMsgHtml( 'newmessagesdifflink' ),
1409 array( 'diff' => 'cur' ),
1410 array( 'known', 'noclasses' )
1414 'youhavenewmessages',
1416 $newMessagesDiffLink
1418 # Disable Squid cache
1419 $out->setSquidMaxage( 0 );
1421 } elseif ( count( $newtalks ) ) {
1422 // _>" " for BC <= 1.16
1423 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1426 foreach ( $newtalks as $newtalk ) {
1427 $msgs[] = Xml
::element(
1429 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1432 $parts = implode( $sep, $msgs );
1433 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1434 $out->setSquidMaxage( 0 );
1441 * Get a cached notice
1443 * @param $name String: message name, or 'default' for $wgSiteNotice
1444 * @return String: HTML fragment
1446 private function getCachedNotice( $name ) {
1447 global $wgOut, $wgRenderHashAppend, $parserMemc;
1449 wfProfileIn( __METHOD__
);
1453 if( $name === 'default' ) {
1455 global $wgSiteNotice;
1456 $notice = $wgSiteNotice;
1457 if( empty( $notice ) ) {
1458 wfProfileOut( __METHOD__
);
1462 $msg = wfMessage( $name )->inContentLanguage();
1463 if( $msg->isDisabled() ) {
1464 wfProfileOut( __METHOD__
);
1467 $notice = $msg->plain();
1470 // Use the extra hash appender to let eg SSL variants separately cache.
1471 $key = wfMemcKey( $name . $wgRenderHashAppend );
1472 $cachedNotice = $parserMemc->get( $key );
1473 if( is_array( $cachedNotice ) ) {
1474 if( md5( $notice ) == $cachedNotice['hash'] ) {
1475 $notice = $cachedNotice['html'];
1484 if( is_object( $wgOut ) ) {
1485 $parsed = $wgOut->parse( $notice );
1486 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1489 wfDebug( 'Skin::getCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
1494 $notice = '<div id="localNotice">' .$notice . '</div>';
1495 wfProfileOut( __METHOD__
);
1500 * Get a notice based on page's namespace
1502 * @return String: HTML fragment
1504 function getNamespaceNotice() {
1505 wfProfileIn( __METHOD__
);
1507 $key = 'namespacenotice-' . $this->mTitle
->getNsText();
1508 $namespaceNotice = $this->getCachedNotice( $key );
1509 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1510 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1512 $namespaceNotice = '';
1515 wfProfileOut( __METHOD__
);
1516 return $namespaceNotice;
1520 * Get the site notice
1522 * @return String: HTML fragment
1524 function getSiteNotice() {
1527 wfProfileIn( __METHOD__
);
1530 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1531 if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
1532 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1534 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1535 if ( !$anonNotice ) {
1536 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1538 $siteNotice = $anonNotice;
1541 if ( !$siteNotice ) {
1542 $siteNotice = $this->getCachedNotice( 'default' );
1546 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1547 wfProfileOut( __METHOD__
);
1552 * Create a section edit link. This supersedes editSectionLink() and
1553 * editSectionLinkForOther().
1555 * @param $nt Title The title being linked to (may not be the same as
1556 * $wgTitle, if the section is included from a template)
1557 * @param $section string The designation of the section being pointed to,
1558 * to be included in the link, like "§ion=$section"
1559 * @param $tooltip string The tooltip to use for the link: will be escaped
1560 * and wrapped in the 'editsectionhint' message
1561 * @param $lang string Language code
1562 * @return string HTML to use for edit link
1564 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1565 // HTML generated here should probably have userlangattributes
1566 // added to it for LTR text on RTL pages
1568 if ( !is_null( $tooltip ) ) {
1569 # Bug 25462: undo double-escaping.
1570 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1571 $attribs['title'] = wfMsgReal( 'editsectionhint', array( $tooltip ), true, $lang );
1573 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1575 array( 'action' => 'edit', 'section' => $section ),
1576 array( 'noclasses', 'known' )
1579 # Run the old hook. This takes up half of the function . . . hopefully
1580 # we can rid of it someday.
1583 $attribs = htmlspecialchars( wfMsgReal( 'editsectionhint', array( $tooltip ), true, $lang ) );
1584 $attribs = " title=\"$attribs\"";
1587 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1588 if ( !is_null( $result ) ) {
1589 # For reverse compatibility, add the brackets *after* the hook is
1590 # run, and even add them to hook-provided text. (This is the main
1591 # reason that the EditSectionLink hook is deprecated in favor of
1592 # DoEditSectionLink: it can't change the brackets or the span.)
1593 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1594 return "<span class=\"editsection\">$result</span>";
1597 # Add the brackets and the span, and *then* run the nice new hook, with
1598 # clean and non-redundant arguments.
1599 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1600 $result = "<span class=\"editsection\">$result</span>";
1602 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1607 * Use PHP's magic __call handler to intercept legacy calls to the linker
1608 * for backwards compatibility.
1610 * @param $fname String Name of called method
1611 * @param $args Array Arguments to the method
1613 function __call( $fname, $args ) {
1614 if ( method_exists( 'Linker', $fname ) ) {
1615 return call_user_func_array( array( 'Linker', $fname ), $args );
1617 $className = get_class( $this );
1618 throw new MWException( "Call to undefined method $className::$fName" );