Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / Skin.php
blob677664ae5ad70c014423d40d3adf7614d1e47216
1 <?php
2 /**
3 * Base class for all skins.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 /**
24 * @defgroup Skins Skins
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 die( 1 );
31 /**
32 * The main skin class that provide methods and properties for all other skins.
33 * This base class is also the "Standard" skin.
35 * See docs/skin.txt for more information.
37 * @ingroup Skins
39 abstract class Skin extends ContextSource {
40 protected $skinname = 'standard';
41 protected $mRelevantTitle = null;
42 protected $mRelevantUser = null;
44 /**
45 * Fetch the set of available skins.
46 * @return array associative array of strings
48 static function getSkinNames() {
49 global $wgValidSkinNames;
50 static $skinsInitialised = false;
52 if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) {
53 # Get a list of available skins
54 # Build using the regular expression '^(.*).php$'
55 # Array keys are all lower case, array value keep the case used by filename
57 wfProfileIn( __METHOD__ . '-init' );
59 global $wgStyleDirectory;
61 $skinDir = dir( $wgStyleDirectory );
63 # while code from www.php.net
64 while ( false !== ( $file = $skinDir->read() ) ) {
65 // Skip non-PHP files, hidden files, and '.dep' includes
66 $matches = array();
68 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
69 $aSkin = $matches[1];
70 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
73 $skinDir->close();
74 $skinsInitialised = true;
75 wfProfileOut( __METHOD__ . '-init' );
77 return $wgValidSkinNames;
80 /**
81 * Fetch the skinname messages for available skins.
82 * @return array of strings
84 static function getSkinNameMessages() {
85 $messages = array();
86 foreach( self::getSkinNames() as $skinKey => $skinName ) {
87 $messages[] = "skinname-$skinKey";
89 return $messages;
92 /**
93 * Fetch the list of usable skins in regards to $wgSkipSkins.
94 * Useful for Special:Preferences and other places where you
95 * only want to show skins users _can_ use.
96 * @return array of strings
98 public static function getUsableSkins() {
99 global $wgSkipSkins;
101 $usableSkins = self::getSkinNames();
103 foreach ( $wgSkipSkins as $skip ) {
104 unset( $usableSkins[$skip] );
107 return $usableSkins;
111 * Normalize a skin preference value to a form that can be loaded.
112 * If a skin can't be found, it will fall back to the configured
113 * default (or the old 'Classic' skin if that's broken).
114 * @param $key String: 'monobook', 'standard', etc.
115 * @return string
117 static function normalizeKey( $key ) {
118 global $wgDefaultSkin;
120 $skinNames = Skin::getSkinNames();
122 if ( $key == '' || $key == 'default' ) {
123 // Don't return the default immediately;
124 // in a misconfiguration we need to fall back.
125 $key = $wgDefaultSkin;
128 if ( isset( $skinNames[$key] ) ) {
129 return $key;
132 // Older versions of the software used a numeric setting
133 // in the user preferences.
134 $fallback = array(
135 0 => $wgDefaultSkin,
136 1 => 'nostalgia',
137 2 => 'cologneblue'
140 if ( isset( $fallback[$key] ) ) {
141 $key = $fallback[$key];
144 if ( isset( $skinNames[$key] ) ) {
145 return $key;
146 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
147 return $wgDefaultSkin;
148 } else {
149 return 'vector';
154 * Factory method for loading a skin of a given type
155 * @param $key String: 'monobook', 'standard', etc.
156 * @return Skin
158 static function &newFromKey( $key ) {
159 global $wgStyleDirectory;
161 $key = Skin::normalizeKey( $key );
163 $skinNames = Skin::getSkinNames();
164 $skinName = $skinNames[$key];
165 $className = "Skin{$skinName}";
167 # Grab the skin class and initialise it.
168 if ( !MWInit::classExists( $className ) ) {
170 if ( !defined( 'MW_COMPILED' ) ) {
171 // Preload base classes to work around APC/PHP5 bug
172 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
173 if ( file_exists( $deps ) ) {
174 include_once( $deps );
176 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
179 # Check if we got if not failback to default skin
180 if ( !MWInit::classExists( $className ) ) {
181 # DO NOT die if the class isn't found. This breaks maintenance
182 # scripts and can cause a user account to be unrecoverable
183 # except by SQL manipulation if a previously valid skin name
184 # is no longer valid.
185 wfDebug( "Skin class does not exist: $className\n" );
186 $className = 'SkinVector';
187 if ( !defined( 'MW_COMPILED' ) ) {
188 require_once( "{$wgStyleDirectory}/Vector.php" );
192 $skin = new $className( $key );
193 return $skin;
196 /** @return string skin name */
197 public function getSkinName() {
198 return $this->skinname;
202 * @param $out OutputPage
204 function initPage( OutputPage $out ) {
205 wfProfileIn( __METHOD__ );
207 $this->preloadExistence();
209 wfProfileOut( __METHOD__ );
213 * Preload the existence of three commonly-requested pages in a single query
215 function preloadExistence() {
216 $user = $this->getUser();
218 // User/talk link
219 $titles = array( $user->getUserPage(), $user->getTalkPage() );
221 // Other tab link
222 if ( $this->getTitle()->isSpecialPage() ) {
223 // nothing
224 } elseif ( $this->getTitle()->isTalkPage() ) {
225 $titles[] = $this->getTitle()->getSubjectPage();
226 } else {
227 $titles[] = $this->getTitle()->getTalkPage();
230 $lb = new LinkBatch( $titles );
231 $lb->setCaller( __METHOD__ );
232 $lb->execute();
236 * Get the current revision ID
238 * @return Integer
240 public function getRevisionId() {
241 return $this->getOutput()->getRevisionId();
245 * Whether the revision displayed is the latest revision of the page
247 * @return Boolean
249 public function isRevisionCurrent() {
250 $revID = $this->getRevisionId();
251 return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
255 * Set the "relevant" title
256 * @see self::getRelevantTitle()
257 * @param $t Title object to use
259 public function setRelevantTitle( $t ) {
260 $this->mRelevantTitle = $t;
264 * Return the "relevant" title.
265 * A "relevant" title is not necessarily the actual title of the page.
266 * Special pages like Special:MovePage use set the page they are acting on
267 * as their "relevant" title, this allows the skin system to display things
268 * such as content tabs which belong to to that page instead of displaying
269 * a basic special page tab which has almost no meaning.
271 * @return Title
273 public function getRelevantTitle() {
274 if ( isset($this->mRelevantTitle) ) {
275 return $this->mRelevantTitle;
277 return $this->getTitle();
281 * Set the "relevant" user
282 * @see self::getRelevantUser()
283 * @param $u User object to use
285 public function setRelevantUser( $u ) {
286 $this->mRelevantUser = $u;
290 * Return the "relevant" user.
291 * A "relevant" user is similar to a relevant title. Special pages like
292 * Special:Contributions mark the user which they are relevant to so that
293 * things like the toolbox can display the information they usually are only
294 * able to display on a user's userpage and talkpage.
295 * @return User
297 public function getRelevantUser() {
298 if ( isset($this->mRelevantUser) ) {
299 return $this->mRelevantUser;
301 $title = $this->getRelevantTitle();
302 if( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK ) {
303 $rootUser = strtok( $title->getText(), '/' );
304 if ( User::isIP( $rootUser ) ) {
305 $this->mRelevantUser = User::newFromName( $rootUser, false );
306 } else {
307 $user = User::newFromName( $rootUser, false );
308 if ( $user && $user->isLoggedIn() ) {
309 $this->mRelevantUser = $user;
312 return $this->mRelevantUser;
314 return null;
318 * Outputs the HTML generated by other functions.
319 * @param $out OutputPage
321 abstract function outputPage( OutputPage $out = null );
324 * @param $data array
325 * @return string
327 static function makeVariablesScript( $data ) {
328 if ( $data ) {
329 return Html::inlineScript(
330 ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) )
332 } else {
333 return '';
338 * Make a <script> tag containing global variables
340 * @deprecated in 1.19
341 * @param $unused
342 * @return string HTML fragment
344 public static function makeGlobalVariablesScript( $unused ) {
345 global $wgOut;
347 wfDeprecated( __METHOD__, '1.19' );
349 return self::makeVariablesScript( $wgOut->getJSVars() );
353 * Get the query to generate a dynamic stylesheet
355 * @return array
357 public static function getDynamicStylesheetQuery() {
358 global $wgSquidMaxage;
360 return array(
361 'action' => 'raw',
362 'maxage' => $wgSquidMaxage,
363 'usemsgcache' => 'yes',
364 'ctype' => 'text/css',
365 'smaxage' => $wgSquidMaxage,
370 * Add skin specific stylesheets
371 * Calling this method with an $out of anything but the same OutputPage
372 * inside ->getOutput() is deprecated. The $out arg is kept
373 * for compatibility purposes with skins.
374 * @param $out OutputPage
375 * @delete
377 abstract function setupSkinUserCss( OutputPage $out );
380 * TODO: document
381 * @param $title Title
382 * @return String
384 function getPageClasses( $title ) {
385 $numeric = 'ns-' . $title->getNamespace();
387 if ( $title->isSpecialPage() ) {
388 $type = 'ns-special';
389 // bug 23315: provide a class based on the canonical special page name without subpages
390 list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
391 if ( $canonicalName ) {
392 $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
393 } else {
394 $type .= ' mw-invalidspecialpage';
396 } elseif ( $title->isTalkPage() ) {
397 $type = 'ns-talk';
398 } else {
399 $type = 'ns-subject';
402 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
404 return "$numeric $type $name";
408 * This will be called by OutputPage::headElement when it is creating the
409 * <body> tag, skins can override it if they have a need to add in any
410 * body attributes or classes of their own.
411 * @param $out OutputPage
412 * @param $bodyAttrs Array
414 function addToBodyAttributes( $out, &$bodyAttrs ) {
415 // does nothing by default
419 * URL to the logo
420 * @return String
422 function getLogo() {
423 global $wgLogo;
424 return $wgLogo;
428 * @return string
430 function getCategoryLinks() {
431 global $wgUseCategoryBrowser;
433 $out = $this->getOutput();
434 $allCats = $out->getCategoryLinks();
436 if ( !count( $allCats ) ) {
437 return '';
440 $embed = "<li>";
441 $pop = "</li>";
443 $s = '';
444 $colon = $this->msg( 'colon-separator' )->escaped();
446 if ( !empty( $allCats['normal'] ) ) {
447 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
449 $msg = $this->msg( 'pagecategories', count( $allCats['normal'] ) )->escaped();
450 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
451 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
452 Linker::link( Title::newFromText( $linkPage ), $msg )
453 . $colon . '<ul>' . $t . '</ul>' . '</div>';
456 # Hidden categories
457 if ( isset( $allCats['hidden'] ) ) {
458 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
459 $class = ' mw-hidden-cats-user-shown';
460 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
461 $class = ' mw-hidden-cats-ns-shown';
462 } else {
463 $class = ' mw-hidden-cats-hidden';
466 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
467 $this->msg( 'hidden-categories', count( $allCats['hidden'] ) )->escaped() .
468 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
469 '</div>';
472 # optional 'dmoz-like' category browser. Will be shown under the list
473 # of categories an article belong to
474 if ( $wgUseCategoryBrowser ) {
475 $s .= '<br /><hr />';
477 # get a big array of the parents tree
478 $parenttree = $this->getTitle()->getParentCategoryTree();
479 # Skin object passed by reference cause it can not be
480 # accessed under the method subfunction drawCategoryBrowser
481 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
482 # Clean out bogus first entry and sort them
483 unset( $tempout[0] );
484 asort( $tempout );
485 # Output one per line
486 $s .= implode( "<br />\n", $tempout );
489 return $s;
493 * Render the array as a serie of links.
494 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
495 * @return String separated by &gt;, terminate with "\n"
497 function drawCategoryBrowser( $tree ) {
498 $return = '';
500 foreach ( $tree as $element => $parent ) {
501 if ( empty( $parent ) ) {
502 # element start a new list
503 $return .= "\n";
504 } else {
505 # grab the others elements
506 $return .= $this->drawCategoryBrowser( $parent ) . ' &gt; ';
509 # add our current element to the list
510 $eltitle = Title::newFromText( $element );
511 $return .= Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
514 return $return;
518 * @return string
520 function getCategories() {
521 $out = $this->getOutput();
523 $catlinks = $this->getCategoryLinks();
525 $classes = 'catlinks';
527 // Check what we're showing
528 $allCats = $out->getCategoryLinks();
529 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
530 $this->getTitle()->getNamespace() == NS_CATEGORY;
532 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
533 $classes .= ' catlinks-allhidden';
536 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
540 * This runs a hook to allow extensions placing their stuff after content
541 * and article metadata (e.g. categories).
542 * Note: This function has nothing to do with afterContent().
544 * This hook is placed here in order to allow using the same hook for all
545 * skins, both the SkinTemplate based ones and the older ones, which directly
546 * use this class to get their data.
548 * The output of this function gets processed in SkinTemplate::outputPage() for
549 * the SkinTemplate based skins, all other skins should directly echo it.
551 * @return String, empty by default, if not changed by any hook function.
553 protected function afterContentHook() {
554 $data = '';
556 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
557 // adding just some spaces shouldn't toggle the output
558 // of the whole <div/>, so we use trim() here
559 if ( trim( $data ) != '' ) {
560 // Doing this here instead of in the skins to
561 // ensure that the div has the same ID in all
562 // skins
563 $data = "<div id='mw-data-after-content'>\n" .
564 "\t$data\n" .
565 "</div>\n";
567 } else {
568 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
571 return $data;
575 * Generate debug data HTML for displaying at the bottom of the main content
576 * area.
577 * @return String HTML containing debug data, if enabled (otherwise empty).
579 protected function generateDebugHTML() {
580 global $wgShowDebug;
582 $html = MWDebug::getDebugHTML( $this->getContext() );
584 if ( $wgShowDebug ) {
585 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext );
586 $html .= "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
587 $listInternals . "</ul>\n";
590 return $html;
594 * @param $debugText string
595 * @return string
597 private function formatDebugHTML( $debugText ) {
598 global $wgDebugTimestamps;
600 $lines = explode( "\n", $debugText );
601 $curIdent = 0;
602 $ret = '<li>';
604 foreach ( $lines as $line ) {
605 $pre = '';
606 if ( $wgDebugTimestamps ) {
607 $matches = array();
608 if ( preg_match( '/^(\d+\.\d+ {1,3}\d+.\dM\s{2})/', $line, $matches ) ) {
609 $pre = $matches[1];
610 $line = substr( $line, strlen( $pre ) );
613 $display = ltrim( $line );
614 $ident = strlen( $line ) - strlen( $display );
615 $diff = $ident - $curIdent;
617 $display = $pre . $display;
618 if ( $display == '' ) {
619 $display = "\xc2\xa0";
622 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
623 $ident = $curIdent;
624 $diff = 0;
625 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
626 } else {
627 $display = htmlspecialchars( $display );
630 if ( $diff < 0 ) {
631 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
632 } elseif ( $diff == 0 ) {
633 $ret .= "</li><li>\n";
634 } else {
635 $ret .= str_repeat( "<ul><li>\n", $diff );
637 $ret .= "<tt>$display</tt>\n";
639 $curIdent = $ident;
642 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
644 return $ret;
648 * This gets called shortly before the </body> tag.
650 * @return String HTML-wrapped JS code to be put before </body>
652 function bottomScripts() {
653 // TODO and the suckage continues. This function is really just a wrapper around
654 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
655 // up at some point
656 $bottomScriptText = $this->getOutput()->getBottomScripts();
657 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
659 return $bottomScriptText;
663 * Text with the permalink to the source page,
664 * usually shown on the footer of a printed page
666 * @return string HTML text with an URL
668 function printSource() {
669 $oldid = $this->getRevisionId();
670 if ( $oldid ) {
671 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
672 } else {
673 // oldid not available for non existing pages
674 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
676 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
680 * @return String
682 function getUndeleteLink() {
683 $action = $this->getRequest()->getVal( 'action', 'view' );
685 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
686 ( $this->getTitle()->getArticleID() == 0 || $action == 'history' ) ) {
687 $n = $this->getTitle()->isDeleted();
690 if ( $n ) {
691 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
692 $msg = 'thisisdeleted';
693 } else {
694 $msg = 'viewdeleted';
697 return $this->msg( $msg )->rawParams(
698 Linker::linkKnown(
699 SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
700 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
701 )->text();
705 return '';
709 * @return string
711 function subPageSubtitle() {
712 global $wgLang;
713 $out = $this->getOutput();
714 $subpages = '';
716 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
717 return $subpages;
720 if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
721 $ptext = $this->getTitle()->getPrefixedText();
722 if ( preg_match( '/\//', $ptext ) ) {
723 $links = explode( '/', $ptext );
724 array_pop( $links );
725 $c = 0;
726 $growinglink = '';
727 $display = '';
729 foreach ( $links as $link ) {
730 $growinglink .= $link;
731 $display .= $link;
732 $linkObj = Title::newFromText( $growinglink );
734 if ( is_object( $linkObj ) && $linkObj->exists() ) {
735 $getlink = Linker::linkKnown(
736 $linkObj,
737 htmlspecialchars( $display )
740 $c++;
742 if ( $c > 1 ) {
743 $subpages .= $wgLang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
744 } else {
745 $subpages .= '&lt; ';
748 $subpages .= $getlink;
749 $display = '';
750 } else {
751 $display .= '/';
753 $growinglink .= '/';
758 return $subpages;
762 * Returns true if the IP should be shown in the header
763 * @return Bool
765 function showIPinHeader() {
766 global $wgShowIPinHeader;
767 return $wgShowIPinHeader && session_id() != '';
771 * @return String
773 function getSearchLink() {
774 $searchPage = SpecialPage::getTitleFor( 'Search' );
775 return $searchPage->getLocalURL();
779 * @return string
781 function escapeSearchLink() {
782 return htmlspecialchars( $this->getSearchLink() );
786 * @param $type string
787 * @return string
789 function getCopyright( $type = 'detect' ) {
790 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
792 if ( $type == 'detect' ) {
793 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
794 $type = 'history';
795 } else {
796 $type = 'normal';
800 if ( $type == 'history' ) {
801 $msg = 'history_copyright';
802 } else {
803 $msg = 'copyright';
806 if ( $wgRightsPage ) {
807 $title = Title::newFromText( $wgRightsPage );
808 $link = Linker::linkKnown( $title, $wgRightsText );
809 } elseif ( $wgRightsUrl ) {
810 $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
811 } elseif ( $wgRightsText ) {
812 $link = $wgRightsText;
813 } else {
814 # Give up now
815 return '';
818 // Allow for site and per-namespace customization of copyright notice.
819 $forContent = true;
821 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
823 $msgObj = $this->msg( $msg )->rawParams( $link );
824 if ( $forContent ) {
825 $msg = $msgObj->inContentLanguage()->text();
826 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
827 $msg = Html::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
829 return $msg;
830 } else {
831 return $msgObj->text();
836 * @return null|string
838 function getCopyrightIcon() {
839 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
841 $out = '';
843 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
844 $out = $wgCopyrightIcon;
845 } elseif ( $wgRightsIcon ) {
846 $icon = htmlspecialchars( $wgRightsIcon );
848 if ( $wgRightsUrl ) {
849 $url = htmlspecialchars( $wgRightsUrl );
850 $out .= '<a href="' . $url . '">';
853 $text = htmlspecialchars( $wgRightsText );
854 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
856 if ( $wgRightsUrl ) {
857 $out .= '</a>';
861 return $out;
865 * Gets the powered by MediaWiki icon.
866 * @return string
868 function getPoweredBy() {
869 global $wgStylePath;
871 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
872 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
873 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
874 return $text;
878 * Get the timestamp of the latest revision, formatted in user language
880 * @return String
882 protected function lastModified() {
883 $timestamp = $this->getOutput()->getRevisionTimestamp();
885 # No cached timestamp, load it from the database
886 if ( $timestamp === null ) {
887 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
890 if ( $timestamp ) {
891 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
892 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
893 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
894 } else {
895 $s = '';
898 if ( wfGetLB()->getLaggedSlaveMode() ) {
899 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
902 return $s;
906 * @param $align string
907 * @return string
909 function logoText( $align = '' ) {
910 if ( $align != '' ) {
911 $a = " align='{$align}'";
912 } else {
913 $a = '';
916 $mp = $this->msg( 'mainpage' )->escaped();
917 $mptitle = Title::newMainPage();
918 $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
920 $logourl = $this->getLogo();
921 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
923 return $s;
927 * Renders a $wgFooterIcons icon acording to the method's arguments
928 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
929 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
930 * @return String HTML
932 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
933 if ( is_string( $icon ) ) {
934 $html = $icon;
935 } else { // Assuming array
936 $url = isset($icon["url"]) ? $icon["url"] : null;
937 unset( $icon["url"] );
938 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
939 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
940 } else {
941 $html = htmlspecialchars( $icon["alt"] );
943 if ( $url ) {
944 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
947 return $html;
951 * Gets the link to the wiki's main page.
952 * @return string
954 function mainPageLink() {
955 $s = Linker::linkKnown(
956 Title::newMainPage(),
957 $this->msg( 'mainpage' )->escaped()
960 return $s;
964 * @param $desc
965 * @param $page
966 * @return string
968 public function footerLink( $desc, $page ) {
969 // if the link description has been set to "-" in the default language,
970 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
971 // then it is disabled, for all languages.
972 return '';
973 } else {
974 // Otherwise, we display the link for the user, described in their
975 // language (which may or may not be the same as the default language),
976 // but we make the link target be the one site-wide page.
977 $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
979 return Linker::linkKnown(
980 $title,
981 $this->msg( $desc )->escaped()
987 * Gets the link to the wiki's privacy policy page.
988 * @return String HTML
990 function privacyLink() {
991 return $this->footerLink( 'privacy', 'privacypage' );
995 * Gets the link to the wiki's about page.
996 * @return String HTML
998 function aboutLink() {
999 return $this->footerLink( 'aboutsite', 'aboutpage' );
1003 * Gets the link to the wiki's general disclaimers page.
1004 * @return String HTML
1006 function disclaimerLink() {
1007 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1011 * Return URL options for the 'edit page' link.
1012 * This may include an 'oldid' specifier, if the current page view is such.
1014 * @return array
1015 * @private
1017 function editUrlOptions() {
1018 $options = array( 'action' => 'edit' );
1020 if ( !$this->isRevisionCurrent() ) {
1021 $options['oldid'] = intval( $this->getRevisionId() );
1024 return $options;
1028 * @param $id User|int
1029 * @return bool
1031 function showEmailUser( $id ) {
1032 if ( $id instanceof User ) {
1033 $targetUser = $id;
1034 } else {
1035 $targetUser = User::newFromId( $id );
1037 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1038 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1042 * Return a fully resolved style path url to images or styles stored in the common folder.
1043 * This method returns a url resolved using the configured skin style path
1044 * and includes the style version inside of the url.
1045 * @param $name String: The name or path of a skin resource file
1046 * @return String The fully resolved style path url including styleversion
1048 function getCommonStylePath( $name ) {
1049 global $wgStylePath, $wgStyleVersion;
1050 return "$wgStylePath/common/$name?$wgStyleVersion";
1054 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1055 * This method returns a url resolved using the configured skin style path
1056 * and includes the style version inside of the url.
1057 * @param $name String: The name or path of a skin resource file
1058 * @return String The fully resolved style path url including styleversion
1060 function getSkinStylePath( $name ) {
1061 global $wgStylePath, $wgStyleVersion;
1062 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1065 /* these are used extensively in SkinTemplate, but also some other places */
1068 * @param $urlaction string
1069 * @return String
1071 static function makeMainPageUrl( $urlaction = '' ) {
1072 $title = Title::newMainPage();
1073 self::checkTitle( $title, '' );
1075 return $title->getLocalURL( $urlaction );
1079 * @param $name string
1080 * @param $urlaction string
1081 * @return String
1083 static function makeSpecialUrl( $name, $urlaction = '' ) {
1084 $title = SpecialPage::getSafeTitleFor( $name );
1085 return $title->getLocalURL( $urlaction );
1089 * @param $name string
1090 * @param $subpage string
1091 * @param $urlaction string
1092 * @return String
1094 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1095 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1096 return $title->getLocalURL( $urlaction );
1100 * @param $name string
1101 * @param $urlaction string
1102 * @return String
1104 static function makeI18nUrl( $name, $urlaction = '' ) {
1105 $title = Title::newFromText( wfMsgForContent( $name ) );
1106 self::checkTitle( $title, $name );
1107 return $title->getLocalURL( $urlaction );
1111 * @param $name string
1112 * @param $urlaction string
1113 * @return String
1115 static function makeUrl( $name, $urlaction = '' ) {
1116 $title = Title::newFromText( $name );
1117 self::checkTitle( $title, $name );
1119 return $title->getLocalURL( $urlaction );
1123 * If url string starts with http, consider as external URL, else
1124 * internal
1125 * @param $name String
1126 * @return String URL
1128 static function makeInternalOrExternalUrl( $name ) {
1129 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1130 return $name;
1131 } else {
1132 return self::makeUrl( $name );
1137 * this can be passed the NS number as defined in Language.php
1138 * @param $name
1139 * @param $urlaction string
1140 * @param $namespace int
1141 * @return String
1143 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1144 $title = Title::makeTitleSafe( $namespace, $name );
1145 self::checkTitle( $title, $name );
1147 return $title->getLocalURL( $urlaction );
1151 * these return an array with the 'href' and boolean 'exists'
1152 * @param $name
1153 * @param $urlaction string
1154 * @return array
1156 static function makeUrlDetails( $name, $urlaction = '' ) {
1157 $title = Title::newFromText( $name );
1158 self::checkTitle( $title, $name );
1160 return array(
1161 'href' => $title->getLocalURL( $urlaction ),
1162 'exists' => $title->getArticleID() != 0,
1167 * Make URL details where the article exists (or at least it's convenient to think so)
1168 * @param $name String Article name
1169 * @param $urlaction String
1170 * @return Array
1172 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1173 $title = Title::newFromText( $name );
1174 self::checkTitle( $title, $name );
1176 return array(
1177 'href' => $title->getLocalURL( $urlaction ),
1178 'exists' => true
1183 * make sure we have some title to operate on
1185 * @param $title Title
1186 * @param $name string
1188 static function checkTitle( &$title, $name ) {
1189 if ( !is_object( $title ) ) {
1190 $title = Title::newFromText( $name );
1191 if ( !is_object( $title ) ) {
1192 $title = Title::newFromText( '--error: link target missing--' );
1198 * Build an array that represents the sidebar(s), the navigation bar among them
1200 * @return array
1202 function buildSidebar() {
1203 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1204 wfProfileIn( __METHOD__ );
1206 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1208 if ( $wgEnableSidebarCache ) {
1209 $cachedsidebar = $wgMemc->get( $key );
1210 if ( $cachedsidebar ) {
1211 wfProfileOut( __METHOD__ );
1212 return $cachedsidebar;
1216 $bar = array();
1217 $this->addToSidebar( $bar, 'sidebar' );
1219 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1220 if ( $wgEnableSidebarCache ) {
1221 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1224 wfProfileOut( __METHOD__ );
1225 return $bar;
1228 * Add content from a sidebar system message
1229 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1231 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1233 * @param $bar array
1234 * @param $message String
1236 function addToSidebar( &$bar, $message ) {
1237 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1241 * Add content from plain text
1242 * @since 1.17
1243 * @param $bar array
1244 * @param $text string
1245 * @return Array
1247 function addToSidebarPlain( &$bar, $text ) {
1248 $lines = explode( "\n", $text );
1250 $heading = '';
1252 foreach ( $lines as $line ) {
1253 if ( strpos( $line, '*' ) !== 0 ) {
1254 continue;
1256 $line = rtrim( $line, "\r" ); // for Windows compat
1258 if ( strpos( $line, '**' ) !== 0 ) {
1259 $heading = trim( $line, '* ' );
1260 if ( !array_key_exists( $heading, $bar ) ) {
1261 $bar[$heading] = array();
1263 } else {
1264 $line = trim( $line, '* ' );
1266 if ( strpos( $line, '|' ) !== false ) { // sanity check
1267 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1268 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1269 if ( count( $line ) !== 2 ) {
1270 // Second sanity check, could be hit by people doing
1271 // funky stuff with parserfuncs... (bug 33321)
1272 continue;
1275 $extraAttribs = array();
1277 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1278 if ( $msgLink->exists() ) {
1279 $link = $msgLink->text();
1280 if ( $link == '-' ) {
1281 continue;
1283 } else {
1284 $link = $line[0];
1286 $msgText = $this->msg( $line[1] );
1287 if ( $msgText->exists() ) {
1288 $text = $msgText->text();
1289 } else {
1290 $text = $line[1];
1293 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1294 $href = $link;
1296 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1297 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1298 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1299 $extraAttribs['rel'] = 'nofollow';
1302 global $wgExternalLinkTarget;
1303 if ( $wgExternalLinkTarget) {
1304 $extraAttribs['target'] = $wgExternalLinkTarget;
1306 } else {
1307 $title = Title::newFromText( $link );
1309 if ( $title ) {
1310 $title = $title->fixSpecialName();
1311 $href = $title->getLinkURL();
1312 } else {
1313 $href = 'INVALID-TITLE';
1317 $bar[$heading][] = array_merge( array(
1318 'text' => $text,
1319 'href' => $href,
1320 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1321 'active' => false
1322 ), $extraAttribs );
1323 } else {
1324 continue;
1329 return $bar;
1333 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1334 * print stylesheet should override this and return false. (This is an
1335 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1337 * @return bool
1339 public function commonPrintStylesheet() {
1340 return true;
1344 * Gets new talk page messages for the current user.
1345 * @return MediaWiki message or if no new talk page messages, nothing
1347 function getNewtalks() {
1348 $out = $this->getOutput();
1350 $newtalks = $this->getUser()->getNewMessageLinks();
1351 $ntl = '';
1353 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1354 $userTitle = $this->getUser()->getUserPage();
1355 $userTalkTitle = $userTitle->getTalkPage();
1357 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1358 $newMessagesLink = Linker::linkKnown(
1359 $userTalkTitle,
1360 $this->msg( 'newmessageslink' )->escaped(),
1361 array(),
1362 array( 'redirect' => 'no' )
1365 $newMessagesDiffLink = Linker::linkKnown(
1366 $userTalkTitle,
1367 $this->msg( 'newmessagesdifflink' )->escaped(),
1368 array(),
1369 array( 'diff' => 'cur' )
1372 $ntl = $this->msg(
1373 'youhavenewmessages',
1374 $newMessagesLink,
1375 $newMessagesDiffLink
1376 )->text();
1377 # Disable Squid cache
1378 $out->setSquidMaxage( 0 );
1380 } elseif ( count( $newtalks ) ) {
1381 // _>" " for BC <= 1.16
1382 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1383 $msgs = array();
1385 foreach ( $newtalks as $newtalk ) {
1386 $msgs[] = Xml::element(
1387 'a',
1388 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1391 $parts = implode( $sep, $msgs );
1392 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1393 $out->setSquidMaxage( 0 );
1396 return $ntl;
1400 * Get a cached notice
1402 * @param $name String: message name, or 'default' for $wgSiteNotice
1403 * @return String: HTML fragment
1405 private function getCachedNotice( $name ) {
1406 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1408 wfProfileIn( __METHOD__ );
1410 $needParse = false;
1412 if( $name === 'default' ) {
1413 // special case
1414 global $wgSiteNotice;
1415 $notice = $wgSiteNotice;
1416 if( empty( $notice ) ) {
1417 wfProfileOut( __METHOD__ );
1418 return false;
1420 } else {
1421 $msg = $this->msg( $name )->inContentLanguage();
1422 if( $msg->isDisabled() ) {
1423 wfProfileOut( __METHOD__ );
1424 return false;
1426 $notice = $msg->plain();
1429 // Use the extra hash appender to let eg SSL variants separately cache.
1430 $key = wfMemcKey( $name . $wgRenderHashAppend );
1431 $cachedNotice = $parserMemc->get( $key );
1432 if( is_array( $cachedNotice ) ) {
1433 if( md5( $notice ) == $cachedNotice['hash'] ) {
1434 $notice = $cachedNotice['html'];
1435 } else {
1436 $needParse = true;
1438 } else {
1439 $needParse = true;
1442 if ( $needParse ) {
1443 $parsed = $this->getOutput()->parse( $notice );
1444 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1445 $notice = $parsed;
1448 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1449 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1450 wfProfileOut( __METHOD__ );
1451 return $notice;
1455 * Get a notice based on page's namespace
1457 * @return String: HTML fragment
1459 function getNamespaceNotice() {
1460 wfProfileIn( __METHOD__ );
1462 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1463 $namespaceNotice = $this->getCachedNotice( $key );
1464 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1465 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1466 } else {
1467 $namespaceNotice = '';
1470 wfProfileOut( __METHOD__ );
1471 return $namespaceNotice;
1475 * Get the site notice
1477 * @return String: HTML fragment
1479 function getSiteNotice() {
1480 wfProfileIn( __METHOD__ );
1481 $siteNotice = '';
1483 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1484 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1485 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1486 } else {
1487 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1488 if ( !$anonNotice ) {
1489 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1490 } else {
1491 $siteNotice = $anonNotice;
1494 if ( !$siteNotice ) {
1495 $siteNotice = $this->getCachedNotice( 'default' );
1499 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1500 wfProfileOut( __METHOD__ );
1501 return $siteNotice;
1505 * Create a section edit link. This supersedes editSectionLink() and
1506 * editSectionLinkForOther().
1508 * @param $nt Title The title being linked to (may not be the same as
1509 * $wgTitle, if the section is included from a template)
1510 * @param $section string The designation of the section being pointed to,
1511 * to be included in the link, like "&section=$section"
1512 * @param $tooltip string The tooltip to use for the link: will be escaped
1513 * and wrapped in the 'editsectionhint' message
1514 * @param $lang string Language code
1515 * @return string HTML to use for edit link
1517 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1518 // HTML generated here should probably have userlangattributes
1519 // added to it for LTR text on RTL pages
1520 $attribs = array();
1521 if ( !is_null( $tooltip ) ) {
1522 # Bug 25462: undo double-escaping.
1523 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1524 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'replaceafter' ), $tooltip );
1526 $link = Linker::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1527 $attribs,
1528 array( 'action' => 'edit', 'section' => $section ),
1529 array( 'noclasses', 'known' )
1532 # Run the old hook. This takes up half of the function . . . hopefully
1533 # we can rid of it someday.
1534 $attribs = '';
1535 if ( $tooltip ) {
1536 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape', 'replaceafter' ), $tooltip );
1537 $attribs = " title=\"$attribs\"";
1539 $result = null;
1540 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1541 if ( !is_null( $result ) ) {
1542 # For reverse compatibility, add the brackets *after* the hook is
1543 # run, and even add them to hook-provided text. (This is the main
1544 # reason that the EditSectionLink hook is deprecated in favor of
1545 # DoEditSectionLink: it can't change the brackets or the span.)
1546 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1547 return "<span class=\"editsection\">$result</span>";
1550 # Add the brackets and the span, and *then* run the nice new hook, with
1551 # clean and non-redundant arguments.
1552 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1553 $result = "<span class=\"editsection\">$result</span>";
1555 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1556 return $result;
1560 * Use PHP's magic __call handler to intercept legacy calls to the linker
1561 * for backwards compatibility.
1563 * @param $fname String Name of called method
1564 * @param $args Array Arguments to the method
1565 * @return mixed
1567 function __call( $fname, $args ) {
1568 $realFunction = array( 'Linker', $fname );
1569 if ( is_callable( $realFunction ) ) {
1570 return call_user_func_array( $realFunction, $args );
1571 } else {
1572 $className = get_class( $this );
1573 throw new MWException( "Call to undefined method $className::$fname" );