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.
19 protected $skinname = 'standard';
20 protected $mRelevantTitle = null;
21 protected $mRelevantUser = null;
24 * Fetch the set of available skins.
25 * @return array of strings
27 static function getSkinNames() {
28 global $wgValidSkinNames;
29 static $skinsInitialised = false;
31 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
32 # Get a list of available skins
33 # Build using the regular expression '^(.*).php$'
34 # Array keys are all lower case, array value keep the case used by filename
36 wfProfileIn( __METHOD__
. '-init' );
38 global $wgStyleDirectory;
40 $skinDir = dir( $wgStyleDirectory );
42 # while code from www.php.net
43 while ( false !== ( $file = $skinDir->read() ) ) {
44 // Skip non-PHP files, hidden files, and '.dep' includes
47 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
49 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
53 $skinsInitialised = true;
54 wfProfileOut( __METHOD__
. '-init' );
56 return $wgValidSkinNames;
60 * Fetch the list of usable skins in regards to $wgSkipSkins.
61 * Useful for Special:Preferences and other places where you
62 * only want to show skins users _can_ use.
63 * @return array of strings
65 public static function getUsableSkins() {
68 $usableSkins = self
::getSkinNames();
70 foreach ( $wgSkipSkins as $skip ) {
71 unset( $usableSkins[$skip] );
78 * Normalize a skin preference value to a form that can be loaded.
79 * If a skin can't be found, it will fall back to the configured
80 * default (or the old 'Classic' skin if that's broken).
81 * @param $key String: 'monobook', 'standard', etc.
84 static function normalizeKey( $key ) {
85 global $wgDefaultSkin;
87 $skinNames = Skin
::getSkinNames();
90 // Don't return the default immediately;
91 // in a misconfiguration we need to fall back.
92 $key = $wgDefaultSkin;
95 if ( isset( $skinNames[$key] ) ) {
99 // Older versions of the software used a numeric setting
100 // in the user preferences.
107 if ( isset( $fallback[$key] ) ) {
108 $key = $fallback[$key];
111 if ( isset( $skinNames[$key] ) ) {
113 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
114 return $wgDefaultSkin;
121 * Factory method for loading a skin of a given type
122 * @param $key String: 'monobook', 'standard', etc.
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory;
128 $key = Skin
::normalizeKey( $key );
130 $skinNames = Skin
::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = "Skin{$skinName}";
134 # Grab the skin class and initialise it.
135 if ( !MWInit
::classExists( $className ) ) {
137 if ( !defined( 'MW_COMPILED' ) ) {
138 // Preload base classes to work around APC/PHP5 bug
139 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
140 if ( file_exists( $deps ) ) {
141 include_once( $deps );
143 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
146 # Check if we got if not failback to default skin
147 if ( !MWInit
::classExists( $className ) ) {
148 # DO NOT die if the class isn't found. This breaks maintenance
149 # scripts and can cause a user account to be unrecoverable
150 # except by SQL manipulation if a previously valid skin name
151 # is no longer valid.
152 wfDebug( "Skin class does not exist: $className\n" );
153 $className = 'SkinVector';
154 if ( !defined( 'MW_COMPILED' ) ) {
155 require_once( "{$wgStyleDirectory}/Vector.php" );
159 $skin = new $className;
163 /** @return string path to the skin stylesheet */
164 function getStylesheet() {
165 return 'common/wikistandard.css';
168 /** @return string skin name */
169 public function getSkinName() {
170 return $this->skinname
;
173 function initPage( OutputPage
$out ) {
174 wfProfileIn( __METHOD__
);
176 $this->preloadExistence();
179 wfProfileOut( __METHOD__
);
183 * Preload the existence of three commonly-requested pages in a single query
185 function preloadExistence() {
186 $user = $this->getContext()->getUser();
189 $titles = array( $user->getUserPage(), $user->getTalkPage() );
192 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
194 } elseif ( $this->getTitle()->isTalkPage() ) {
195 $titles[] = $this->getTitle()->getSubjectPage();
197 $titles[] = $this->getTitle()->getTalkPage();
200 $lb = new LinkBatch( $titles );
201 $lb->setCaller( __METHOD__
);
206 * Set some local variables
208 protected function setMembers() {
209 $this->userpage
= $this->getContext()->getUser()->getUserPage()->getPrefixedText();
210 $this->usercss
= false;
214 * Set the RequestContext used in this instance
216 * @param RequestContext $context
218 public function setContext( RequestContext
$context ) {
219 $this->mContext
= $context;
223 * Get the RequestContext used in this instance
225 * @return RequestContext
227 public function getContext() {
228 if ( !isset($this->mContext
) ) {
229 wfDebug( __METHOD__
. " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
230 $this->mContext
= RequestContext
::getMain();
232 return $this->mContext
;
239 public function getTitle() {
240 return $this->getContext()->getTitle();
247 public function getUser() {
248 return $this->getContext()->getUser();
252 * Get the current revision ID
256 public function getRevisionId() {
257 return $this->getContext()->getOutput()->getRevisionId();
261 * Whether the revision displayed is the latest revision of the page
265 public function isRevisionCurrent() {
266 $revID = $this->getRevisionId();
267 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
271 * Set the "relevant" title
272 * @see self::getRelevantTitle()
273 * @param $t Title object to use
275 public function setRelevantTitle( $t ) {
276 $this->mRelevantTitle
= $t;
280 * Return the "relevant" title.
281 * A "relevant" title is not necessarily the actual title of the page.
282 * Special pages like Special:MovePage use set the page they are acting on
283 * as their "relevant" title, this allows the skin system to display things
284 * such as content tabs which belong to to that page instead of displaying
285 * a basic special page tab which has almost no meaning.
287 public function getRelevantTitle() {
288 if ( isset($this->mRelevantTitle
) ) {
289 return $this->mRelevantTitle
;
291 return $this->getTitle();
295 * Set the "relevant" user
296 * @see self::getRelevantUser()
297 * @param $u User object to use
299 public function setRelevantUser( $u ) {
300 $this->mRelevantUser
= $u;
304 * Return the "relevant" user.
305 * A "relevant" user is similar to a relevant title. Special pages like
306 * Special:Contributions mark the user which they are relevant to so that
307 * things like the toolbox can display the information they usually are only
308 * able to display on a user's userpage and talkpage.
311 public function getRelevantUser() {
312 if ( isset($this->mRelevantUser
) ) {
313 return $this->mRelevantUser
;
315 $title = $this->getRelevantTitle();
316 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
317 $rootUser = strtok( $title->getText(), '/' );
318 if ( User
::isIP( $rootUser ) ) {
319 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
321 $user = User
::newFromName( $rootUser );
322 if ( $user->isLoggedIn() ) {
323 $this->mRelevantUser
= $user;
326 return $this->mRelevantUser
;
332 * Outputs the HTML generated by other functions.
333 * @param $out Object: instance of OutputPage
335 abstract function outputPage( OutputPage
$out );
337 static function makeVariablesScript( $data ) {
339 return Html
::inlineScript(
340 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
348 * To make it harder for someone to slip a user a fake
349 * user-JavaScript or user-CSS preview, a random token
350 * is associated with the login session. If it's not
351 * passed back with the preview request, we won't render
354 * @param $action String: 'edit', 'submit' etc.
357 public function userCanPreview( $action ) {
358 if ( $action != 'submit' ) {
361 if ( !$this->getContext()->getRequest()->wasPosted() ) {
364 if ( !$this->getTitle()->userCanEditCssSubpage() ) {
367 if ( !$this->getTitle()->userCanEditJsSubpage() ) {
371 return $this->getContext()->getUser()->matchEditToken(
372 $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
376 * Generated JavaScript action=raw&gen=js
377 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
378 * nated together. For some bizarre reason, it does *not* return any
379 * custom user JS from subpages. Huh?
381 * There's absolutely no reason to have separate Monobook/Common JSes.
382 * Any JS that cares can just check the skin variable generated at the
383 * top. For now Monobook.js will be maintained, but it should be consi-
386 * @param $skinName String: If set, overrides the skin name
389 public function generateUserJs( $skinName = null ) {
391 // Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
397 * Generate user stylesheet for action=raw&gen=css
399 public function generateUserStylesheet() {
401 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
407 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
408 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
410 protected function reallyGenerateUserStylesheet() {
412 // Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
420 function setupUserCss( OutputPage
$out ) {
421 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
423 wfProfileIn( __METHOD__
);
425 $this->setupSkinUserCss( $out );
426 // Add any extension CSS
427 foreach ( $out->getExtStyle() as $url ) {
428 $out->addStyle( $url );
431 // Per-site custom styles
432 if ( $wgUseSiteCss ) {
433 $out->addModuleStyles( array( 'site', 'noscript' ) );
434 if( $this->getContext()->getUser()->isLoggedIn() ){
435 $out->addModuleStyles( 'user.groups' );
439 // Per-user custom styles
440 if ( $wgAllowUserCss ) {
441 if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) {
442 // @FIXME: properly escape the cdata!
443 $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
445 $out->addModuleStyles( 'user' );
449 // Per-user preference styles
450 if ( $wgAllowUserCssPrefs ) {
451 $out->addModuleStyles( 'user.options' );
454 wfProfileOut( __METHOD__
);
458 * Get the query to generate a dynamic stylesheet
462 public static function getDynamicStylesheetQuery() {
463 global $wgSquidMaxage;
467 'maxage' => $wgSquidMaxage,
468 'usemsgcache' => 'yes',
469 'ctype' => 'text/css',
470 'smaxage' => $wgSquidMaxage,
475 * Add skin specific stylesheets
476 * @param $out OutputPage
479 abstract function setupSkinUserCss( OutputPage
$out );
483 * @param $title Title
486 function getPageClasses( $title ) {
487 $numeric = 'ns-' . $title->getNamespace();
489 if ( $title->getNamespace() == NS_SPECIAL
) {
490 $type = 'ns-special';
491 // bug 23315: provide a class based on the canonical special page name without subpages
492 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
493 if ( $canonicalName ) {
494 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
496 $type .= ' mw-invalidspecialpage';
498 } elseif ( $title->isTalkPage() ) {
501 $type = 'ns-subject';
504 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
506 return "$numeric $type $name";
510 * This will be called by OutputPage::headElement when it is creating the
511 * <body> tag, skins can override it if they have a need to add in any
512 * body attributes or classes of their own.
514 function addToBodyAttributes( $out, &$bodyAttrs ) {
515 // does nothing by default
527 * The format without an explicit $out argument is deprecated
529 function getCategoryLinks( OutputPage
$out=null ) {
530 global $wgUseCategoryBrowser, $wgContLang;
533 $out = $this->getContext()->output
;
536 if ( count( $out->mCategoryLinks
) == 0 ) {
541 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
543 // Use Unicode bidi embedding override characters,
544 // to make sure links don't smash each other up in ugly ways.
545 $dir = $wgContLang->getDir();
546 $embed = "<span dir='$dir'>";
549 $allCats = $out->getCategoryLinks();
551 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
553 if ( !empty( $allCats['normal'] ) ) {
554 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
556 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
557 $s .= '<div id="mw-normal-catlinks">' .
558 Linker
::link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
559 . $colon . $t . '</div>';
563 if ( isset( $allCats['hidden'] ) ) {
564 if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
565 $class = 'mw-hidden-cats-user-shown';
566 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
567 $class = 'mw-hidden-cats-ns-shown';
569 $class = 'mw-hidden-cats-hidden';
572 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
573 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
574 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
578 # optional 'dmoz-like' category browser. Will be shown under the list
579 # of categories an article belong to
580 if ( $wgUseCategoryBrowser ) {
581 $s .= '<br /><hr />';
583 # get a big array of the parents tree
584 $parenttree = $this->getTitle()->getParentCategoryTree();
585 # Skin object passed by reference cause it can not be
586 # accessed under the method subfunction drawCategoryBrowser
587 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
588 # Clean out bogus first entry and sort them
589 unset( $tempout[0] );
591 # Output one per line
592 $s .= implode( "<br />\n", $tempout );
599 * Render the array as a serie of links.
600 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
601 * @return String separated by >, terminate with "\n"
603 function drawCategoryBrowser( $tree ) {
606 foreach ( $tree as $element => $parent ) {
607 if ( empty( $parent ) ) {
608 # element start a new list
611 # grab the others elements
612 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
615 # add our current element to the list
616 $eltitle = Title
::newFromText( $element );
617 $return .= Linker
::link( $eltitle, $eltitle->getText() );
624 * The ->getCategories() form is deprecated, please instead use
625 * the ->getCategories( $out ) form with whatout OutputPage is on hand
627 function getCategories( OutputPage
$out=null ) {
629 $catlinks = $this->getCategoryLinks( $out );
631 $classes = 'catlinks';
633 // Check what we're showing
634 $allCats = $out->getCategoryLinks();
635 $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ||
636 $this->getTitle()->getNamespace() == NS_CATEGORY
;
638 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
639 $classes .= ' catlinks-allhidden';
642 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
646 * This runs a hook to allow extensions placing their stuff after content
647 * and article metadata (e.g. categories).
648 * Note: This function has nothing to do with afterContent().
650 * This hook is placed here in order to allow using the same hook for all
651 * skins, both the SkinTemplate based ones and the older ones, which directly
652 * use this class to get their data.
654 * The output of this function gets processed in SkinTemplate::outputPage() for
655 * the SkinTemplate based skins, all other skins should directly echo it.
657 * Returns an empty string by default, if not changed by any hook function.
659 protected function afterContentHook() {
662 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
663 // adding just some spaces shouldn't toggle the output
664 // of the whole <div/>, so we use trim() here
665 if ( trim( $data ) != '' ) {
666 // Doing this here instead of in the skins to
667 // ensure that the div has the same ID in all
669 $data = "<div id='mw-data-after-content'>\n" .
674 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
681 * Generate debug data HTML for displaying at the bottom of the main content
683 * @return String HTML containing debug data, if enabled (otherwise empty).
685 protected function generateDebugHTML( OutputPage
$out ) {
688 if ( $wgShowDebug ) {
689 $listInternals = $this->formatDebugHTML( $out->mDebugtext
);
690 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
691 $listInternals . "</ul>\n";
697 private function formatDebugHTML( $debugText ) {
698 global $wgDebugTimestamps;
700 $lines = explode( "\n", $debugText );
704 foreach ( $lines as $line ) {
706 if ( $wgDebugTimestamps ) {
708 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
710 $line = substr( $line, strlen( $pre ) );
713 $display = ltrim( $line );
714 $ident = strlen( $line ) - strlen( $display );
715 $diff = $ident - $curIdent;
717 $display = $pre . $display;
718 if ( $display == '' ) {
719 $display = "\xc2\xa0";
722 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
725 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
727 $display = htmlspecialchars( $display );
731 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
732 } elseif ( $diff == 0 ) {
733 $ret .= "</li><li>\n";
735 $ret .= str_repeat( "<ul><li>\n", $diff );
737 $ret .= "<tt>$display</tt>\n";
742 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
748 * This gets called shortly before the </body> tag.
749 * @param $out OutputPage object
750 * @return String HTML-wrapped JS code to be put before </body>
752 function bottomScripts( $out ) {
753 // TODO and the suckage continues. This function is really just a wrapper around
754 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
756 $bottomScriptText = $out->getBottomScripts( $this );
757 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
759 return $bottomScriptText;
762 /** @return string Retrievied from HTML text */
763 function printSource() {
764 $url = htmlspecialchars( $this->getTitle()->getFullURL() );
765 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
768 function getUndeleteLink() {
769 $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
771 if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
772 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
773 $n = $this->getTitle()->isDeleted();
776 if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
777 $msg = 'thisisdeleted';
779 $msg = 'viewdeleted';
785 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
786 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ),
789 array( 'known', 'noclasses' )
799 * The format without an explicit $out argument is deprecated
801 function subPageSubtitle( OutputPage
$out=null ) {
802 $out = $this->getContext()->getOutput();
805 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
809 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
810 $ptext = $this->getTitle()->getPrefixedText();
811 if ( preg_match( '/\//', $ptext ) ) {
812 $links = explode( '/', $ptext );
818 foreach ( $links as $link ) {
819 $growinglink .= $link;
821 $linkObj = Title
::newFromText( $growinglink );
823 if ( is_object( $linkObj ) && $linkObj->exists() ) {
824 $getlink = $this->link(
826 htmlspecialchars( $display ),
829 array( 'known', 'noclasses' )
835 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
837 $subpages .= '< ';
840 $subpages .= $getlink;
854 * Returns true if the IP should be shown in the header
856 function showIPinHeader() {
857 global $wgShowIPinHeader;
858 return $wgShowIPinHeader && session_id() != '';
861 function getSearchLink() {
862 $searchPage = SpecialPage
::getTitleFor( 'Search' );
863 return $searchPage->getLocalURL();
866 function escapeSearchLink() {
867 return htmlspecialchars( $this->getSearchLink() );
870 function getCopyright( $type = 'detect' ) {
871 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
873 if ( $type == 'detect' ) {
874 $diff = $this->getContext()->getRequest()->getVal( 'diff' );
876 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
883 if ( $type == 'history' ) {
884 $msg = 'history_copyright';
891 if ( $wgRightsPage ) {
892 $title = Title
::newFromText( $wgRightsPage );
893 $link = Linker
::linkKnown( $title, $wgRightsText );
894 } elseif ( $wgRightsUrl ) {
895 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
896 } elseif ( $wgRightsText ) {
897 $link = $wgRightsText;
903 // Allow for site and per-namespace customization of copyright notice.
906 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
909 $out .= wfMsgForContent( $msg, $link );
911 $out .= wfMsg( $msg, $link );
917 function getCopyrightIcon() {
918 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
922 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
923 $out = $wgCopyrightIcon;
924 } elseif ( $wgRightsIcon ) {
925 $icon = htmlspecialchars( $wgRightsIcon );
927 if ( $wgRightsUrl ) {
928 $url = htmlspecialchars( $wgRightsUrl );
929 $out .= '<a href="' . $url . '">';
932 $text = htmlspecialchars( $wgRightsText );
933 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
935 if ( $wgRightsUrl ) {
944 * Gets the powered by MediaWiki icon.
947 function getPoweredBy() {
950 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
951 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
952 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
957 * Get the timestamp of the latest revision, formatted in user language
959 * @param $article Article object. Used if we're working with the current revision
962 protected function lastModified( $article ) {
963 if ( !$this->isRevisionCurrent() ) {
964 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
966 $timestamp = $article->getTimestamp();
970 $d = $this->getContext()->getLang()->date( $timestamp, true );
971 $t = $this->getContext()->getLang()->time( $timestamp, true );
972 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
977 if ( wfGetLB()->getLaggedSlaveMode() ) {
978 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
984 function logoText( $align = '' ) {
985 if ( $align != '' ) {
986 $a = " align='{$align}'";
991 $mp = wfMsg( 'mainpage' );
992 $mptitle = Title
::newMainPage();
993 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
995 $logourl = $this->getLogo();
996 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1002 * Renders a $wgFooterIcons icon acording to the method's arguments
1003 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
1004 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
1006 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
1007 if ( is_string( $icon ) ) {
1009 } else { // Assuming array
1010 $url = isset($icon["url"]) ?
$icon["url"] : null;
1011 unset( $icon["url"] );
1012 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
1013 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
1015 $html = htmlspecialchars( $icon["alt"] );
1018 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
1025 * Gets the link to the wiki's main page.
1028 function mainPageLink() {
1030 Title
::newMainPage(),
1031 wfMsg( 'mainpage' ),
1034 array( 'known', 'noclasses' )
1040 public function footerLink( $desc, $page ) {
1041 // if the link description has been set to "-" in the default language,
1042 if ( wfMsgForContent( $desc ) == '-' ) {
1043 // then it is disabled, for all languages.
1046 // Otherwise, we display the link for the user, described in their
1047 // language (which may or may not be the same as the default language),
1048 // but we make the link target be the one site-wide page.
1049 $title = Title
::newFromText( wfMsgForContent( $page ) );
1051 return Linker
::linkKnown(
1053 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1059 * Gets the link to the wiki's privacy policy page.
1061 function privacyLink() {
1062 return $this->footerLink( 'privacy', 'privacypage' );
1066 * Gets the link to the wiki's about page.
1068 function aboutLink() {
1069 return $this->footerLink( 'aboutsite', 'aboutpage' );
1073 * Gets the link to the wiki's general disclaimers page.
1075 function disclaimerLink() {
1076 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1080 * Return URL options for the 'edit page' link.
1081 * This may include an 'oldid' specifier, if the current page view is such.
1086 function editUrlOptions() {
1087 $options = array( 'action' => 'edit' );
1089 if ( !$this->isRevisionCurrent() ) {
1090 $options['oldid'] = intval( $this->getRevisionId() );
1096 function showEmailUser( $id ) {
1097 $targetUser = User
::newFromId( $id );
1098 return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1099 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1103 * Return a fully resolved style path url to images or styles stored in the common folder.
1104 * This method returns a url resolved using the configured skin style path
1105 * and includes the style version inside of the url.
1106 * @param $name String: The name or path of a skin resource file
1107 * @return String The fully resolved style path url including styleversion
1109 function getCommonStylePath( $name ) {
1110 global $wgStylePath, $wgStyleVersion;
1111 return "$wgStylePath/common/$name?$wgStyleVersion";
1115 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1116 * This method returns a url resolved using the configured skin style path
1117 * and includes the style version inside of the url.
1118 * @param $name String: The name or path of a skin resource file
1119 * @return String The fully resolved style path url including styleversion
1121 function getSkinStylePath( $name ) {
1122 global $wgStylePath, $wgStyleVersion;
1123 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1126 /* these are used extensively in SkinTemplate, but also some other places */
1127 static function makeMainPageUrl( $urlaction = '' ) {
1128 $title = Title
::newMainPage();
1129 self
::checkTitle( $title, '' );
1131 return $title->getLocalURL( $urlaction );
1134 static function makeSpecialUrl( $name, $urlaction = '' ) {
1135 $title = SpecialPage
::getSafeTitleFor( $name );
1136 return $title->getLocalURL( $urlaction );
1139 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1140 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1141 return $title->getLocalURL( $urlaction );
1144 static function makeI18nUrl( $name, $urlaction = '' ) {
1145 $title = Title
::newFromText( wfMsgForContent( $name ) );
1146 self
::checkTitle( $title, $name );
1147 return $title->getLocalURL( $urlaction );
1150 static function makeUrl( $name, $urlaction = '' ) {
1151 $title = Title
::newFromText( $name );
1152 self
::checkTitle( $title, $name );
1154 return $title->getLocalURL( $urlaction );
1158 * If url string starts with http, consider as external URL, else
1161 static function makeInternalOrExternalUrl( $name ) {
1162 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1165 return self
::makeUrl( $name );
1169 # this can be passed the NS number as defined in Language.php
1170 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1171 $title = Title
::makeTitleSafe( $namespace, $name );
1172 self
::checkTitle( $title, $name );
1174 return $title->getLocalURL( $urlaction );
1177 /* these return an array with the 'href' and boolean 'exists' */
1178 static function makeUrlDetails( $name, $urlaction = '' ) {
1179 $title = Title
::newFromText( $name );
1180 self
::checkTitle( $title, $name );
1183 'href' => $title->getLocalURL( $urlaction ),
1184 'exists' => $title->getArticleID() != 0,
1189 * Make URL details where the article exists (or at least it's convenient to think so)
1191 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1192 $title = Title
::newFromText( $name );
1193 self
::checkTitle( $title, $name );
1196 'href' => $title->getLocalURL( $urlaction ),
1201 # make sure we have some title to operate on
1202 static function checkTitle( &$title, $name ) {
1203 if ( !is_object( $title ) ) {
1204 $title = Title
::newFromText( $name );
1205 if ( !is_object( $title ) ) {
1206 $title = Title
::newFromText( '--error: link target missing--' );
1212 * Build an array that represents the sidebar(s), the navigation bar among them
1216 function buildSidebar() {
1217 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1218 wfProfileIn( __METHOD__
);
1220 $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
1222 if ( $wgEnableSidebarCache ) {
1223 $cachedsidebar = $parserMemc->get( $key );
1224 if ( $cachedsidebar ) {
1225 wfProfileOut( __METHOD__
);
1226 return $cachedsidebar;
1231 $this->addToSidebar( $bar, 'sidebar' );
1233 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1234 if ( $wgEnableSidebarCache ) {
1235 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1238 wfProfileOut( __METHOD__
);
1242 * Add content from a sidebar system message
1243 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1245 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1247 * @param &$bar array
1248 * @param $message String
1250 function addToSidebar( &$bar, $message ) {
1251 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1255 * Add content from plain text
1257 * @param &$bar array
1258 * @param $text string
1260 function addToSidebarPlain( &$bar, $text ) {
1261 $lines = explode( "\n", $text );
1262 $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.
1266 foreach ( $lines as $line ) {
1267 if ( strpos( $line, '*' ) !== 0 ) {
1271 if ( strpos( $line, '**' ) !== 0 ) {
1272 $heading = trim( $line, '* ' );
1273 if ( !array_key_exists( $heading, $bar ) ) {
1274 $bar[$heading] = array();
1277 $line = trim( $line, '* ' );
1279 if ( strpos( $line, '|' ) !== false ) { // sanity check
1280 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1281 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1282 $link = wfMsgForContent( $line[0] );
1284 if ( $link == '-' ) {
1288 $text = wfMsgExt( $line[1], 'parsemag' );
1290 if ( wfEmptyMsg( $line[1] ) ) {
1294 if ( wfEmptyMsg( $line[0] ) ) {
1298 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1301 $title = Title
::newFromText( $link );
1304 $title = $title->fixSpecialName();
1305 $href = $title->getLocalURL();
1307 $href = 'INVALID-TITLE';
1311 $bar[$heading][] = array(
1314 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1317 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1320 $line = substr( $line, 2, strlen( $line ) - 4 );
1322 $options = new ParserOptions();
1323 $options->setEditSection( false );
1324 $options->setInterfaceMessage( true );
1325 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
1332 if ( count( $wikiBar ) > 0 ) {
1333 $bar = array_merge( $bar, $wikiBar );
1340 * Should we include common/wikiprintable.css? Skins that have their own
1341 * print stylesheet should override this and return false. (This is an
1342 * ugly hack to get Monobook to play nicely with
1343 * OutputPage::headElement().)
1347 public function commonPrintStylesheet() {
1352 * Gets new talk page messages for the current user.
1353 * @return MediaWiki message or if no new talk page messages, nothing
1355 function getNewtalks() {
1356 $out = $this->getContext()->getOutput();
1358 $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
1361 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1362 $userTitle = $this->getUser()->getUserPage();
1363 $userTalkTitle = $userTitle->getTalkPage();
1365 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1366 $newMessagesLink = $this->link(
1368 wfMsgHtml( 'newmessageslink' ),
1370 array( 'redirect' => 'no' ),
1371 array( 'known', 'noclasses' )
1374 $newMessagesDiffLink = $this->link(
1376 wfMsgHtml( 'newmessagesdifflink' ),
1378 array( 'diff' => 'cur' ),
1379 array( 'known', 'noclasses' )
1383 'youhavenewmessages',
1385 $newMessagesDiffLink
1387 # Disable Squid cache
1388 $out->setSquidMaxage( 0 );
1390 } elseif ( count( $newtalks ) ) {
1391 // _>" " for BC <= 1.16
1392 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1395 foreach ( $newtalks as $newtalk ) {
1396 $msgs[] = Xml
::element(
1398 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1401 $parts = implode( $sep, $msgs );
1402 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1403 $out->setSquidMaxage( 0 );
1410 * Get a cached notice
1412 * @param $name String: message name, or 'default' for $wgSiteNotice
1413 * @return String: HTML fragment
1415 private function getCachedNotice( $name ) {
1416 global $wgRenderHashAppend, $parserMemc;
1418 wfProfileIn( __METHOD__
);
1422 if( $name === 'default' ) {
1424 global $wgSiteNotice;
1425 $notice = $wgSiteNotice;
1426 if( empty( $notice ) ) {
1427 wfProfileOut( __METHOD__
);
1431 $msg = wfMessage( $name )->inContentLanguage();
1432 if( $msg->isDisabled() ) {
1433 wfProfileOut( __METHOD__
);
1436 $notice = $msg->plain();
1439 // Use the extra hash appender to let eg SSL variants separately cache.
1440 $key = wfMemcKey( $name . $wgRenderHashAppend );
1441 $cachedNotice = $parserMemc->get( $key );
1442 if( is_array( $cachedNotice ) ) {
1443 if( md5( $notice ) == $cachedNotice['hash'] ) {
1444 $notice = $cachedNotice['html'];
1453 $parsed = $this->getContext()->getOutput()->parse( $notice );
1454 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1458 $notice = '<div id="localNotice">' .$notice . '</div>';
1459 wfProfileOut( __METHOD__
);
1464 * Get a notice based on page's namespace
1466 * @return String: HTML fragment
1468 function getNamespaceNotice() {
1469 wfProfileIn( __METHOD__
);
1471 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1472 $namespaceNotice = $this->getCachedNotice( $key );
1473 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1474 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1476 $namespaceNotice = '';
1479 wfProfileOut( __METHOD__
);
1480 return $namespaceNotice;
1484 * Get the site notice
1486 * @return String: HTML fragment
1488 function getSiteNotice() {
1489 wfProfileIn( __METHOD__
);
1492 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1493 if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) {
1494 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1496 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1497 if ( !$anonNotice ) {
1498 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1500 $siteNotice = $anonNotice;
1503 if ( !$siteNotice ) {
1504 $siteNotice = $this->getCachedNotice( 'default' );
1508 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1509 wfProfileOut( __METHOD__
);
1514 * Create a section edit link. This supersedes editSectionLink() and
1515 * editSectionLinkForOther().
1517 * @param $nt Title The title being linked to (may not be the same as
1518 * $wgTitle, if the section is included from a template)
1519 * @param $section string The designation of the section being pointed to,
1520 * to be included in the link, like "§ion=$section"
1521 * @param $tooltip string The tooltip to use for the link: will be escaped
1522 * and wrapped in the 'editsectionhint' message
1523 * @param $lang string Language code
1524 * @return string HTML to use for edit link
1526 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1527 // HTML generated here should probably have userlangattributes
1528 // added to it for LTR text on RTL pages
1530 if ( !is_null( $tooltip ) ) {
1531 # Bug 25462: undo double-escaping.
1532 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1533 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1535 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1537 array( 'action' => 'edit', 'section' => $section ),
1538 array( 'noclasses', 'known' )
1541 # Run the old hook. This takes up half of the function . . . hopefully
1542 # we can rid of it someday.
1545 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1546 $attribs = " title=\"$attribs\"";
1549 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1550 if ( !is_null( $result ) ) {
1551 # For reverse compatibility, add the brackets *after* the hook is
1552 # run, and even add them to hook-provided text. (This is the main
1553 # reason that the EditSectionLink hook is deprecated in favor of
1554 # DoEditSectionLink: it can't change the brackets or the span.)
1555 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1556 return "<span class=\"editsection\">$result</span>";
1559 # Add the brackets and the span, and *then* run the nice new hook, with
1560 # clean and non-redundant arguments.
1561 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1562 $result = "<span class=\"editsection\">$result</span>";
1564 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1569 * Use PHP's magic __call handler to intercept legacy calls to the linker
1570 * for backwards compatibility.
1572 * @param $fname String Name of called method
1573 * @param $args Array Arguments to the method
1575 function __call( $fname, $args ) {
1576 $realFunction = array( 'Linker', $fname );
1577 if ( is_callable( $realFunction ) ) {
1578 return call_user_func_array( $realFunction, $args );
1580 $className = get_class( $this );
1581 throw new MWException( "Call to undefined method $className::$fname" );