SearchResultSet: remove hasResults(), unused
[mediawiki.git] / includes / Skin.php
blob0d165fe04f9633cbbe3b94d4349fdbaa10e9b730
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 /**
28 * The main skin class which provides methods and properties for all other skins.
30 * See docs/skin.txt for more information.
32 * @ingroup Skins
34 abstract class Skin extends ContextSource {
35 protected $skinname = null;
36 protected $mRelevantTitle = null;
37 protected $mRelevantUser = null;
39 /**
40 * Fetch the set of available skins.
41 * @return array Associative array of strings
43 static function getSkinNames() {
44 global $wgValidSkinNames;
45 static $skinsInitialised = false;
47 if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) {
48 # Get a list of available skins
49 # Build using the regular expression '^(.*).php$'
50 # Array keys are all lower case, array value keep the case used by filename
52 wfProfileIn( __METHOD__ . '-init' );
54 global $wgStyleDirectory;
56 $skinDir = dir( $wgStyleDirectory );
58 if ( $skinDir !== false && $skinDir !== null ) {
59 # while code from www.php.net
60 while ( false !== ( $file = $skinDir->read() ) ) {
61 // Skip non-PHP files, hidden files, and '.dep' includes
62 $matches = array();
64 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
65 $aSkin = $matches[1];
67 // Explicitly disallow loading core skins via the autodiscovery mechanism.
69 // They should be loaded already (in a non-autodicovery way), but old files might still
70 // exist on the server because our MW version upgrade process is widely documented as
71 // requiring just copying over all files, without removing old ones.
73 // This is one of the reasons we should have never used autodiscovery in the first
74 // place. This hack can be safely removed when autodiscovery is gone.
75 if ( in_array( $aSkin, array( 'CologneBlue', 'Modern', 'MonoBook', 'Vector' ) ) ) {
76 wfLogWarning(
77 "An old copy of the $aSkin skin was found in your skins/ directory. " .
78 "You should remove it to avoid problems in the future." .
79 "See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for details."
81 continue;
84 wfLogWarning(
85 "A skin using autodiscovery mechanism, $aSkin, was found in your skins/ directory. " .
86 "The mechanism will be removed in MediaWiki 1.25 and the skin will no longer be recognized. " .
87 "See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for information how to fix this."
89 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
92 $skinDir->close();
94 $skinsInitialised = true;
95 wfProfileOut( __METHOD__ . '-init' );
97 return $wgValidSkinNames;
101 * Fetch the skinname messages for available skins.
102 * @return string[]
104 static function getSkinNameMessages() {
105 $messages = array();
106 foreach ( self::getSkinNames() as $skinKey => $skinName ) {
107 // Messages: skinname-vector, skinname-monobook
108 $messages[] = "skinname-$skinKey";
110 return $messages;
114 * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
115 * Useful for Special:Preferences and other places where you
116 * only want to show skins users _can_ use.
117 * @return string[]
118 * @since 1.23
120 public static function getAllowedSkins() {
121 global $wgSkipSkins;
123 $allowedSkins = self::getSkinNames();
125 foreach ( $wgSkipSkins as $skip ) {
126 unset( $allowedSkins[$skip] );
129 return $allowedSkins;
133 * @deprecated since 1.23, use getAllowedSkins
134 * @return string[]
136 public static function getUsableSkins() {
137 wfDeprecated( __METHOD__, '1.23' );
138 return self::getAllowedSkins();
142 * Normalize a skin preference value to a form that can be loaded.
143 * If a skin can't be found, it will fall back to the configured
144 * default, or the hardcoded default if that's broken.
145 * @param string $key 'monobook', 'vector', etc.
146 * @return string
148 static function normalizeKey( $key ) {
149 global $wgDefaultSkin;
151 $skinNames = Skin::getSkinNames();
153 if ( $key == '' || $key == 'default' ) {
154 // Don't return the default immediately;
155 // in a misconfiguration we need to fall back.
156 $key = $wgDefaultSkin;
159 if ( isset( $skinNames[$key] ) ) {
160 return $key;
163 // Older versions of the software used a numeric setting
164 // in the user preferences.
165 $fallback = array(
166 0 => $wgDefaultSkin,
167 2 => 'cologneblue'
170 if ( isset( $fallback[$key] ) ) {
171 $key = $fallback[$key];
174 if ( isset( $skinNames[$key] ) ) {
175 return $key;
176 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
177 return $wgDefaultSkin;
178 } else {
179 return 'vector';
184 * Factory method for loading a skin of a given type
185 * @param string $key 'monobook', 'vector', etc.
186 * @return Skin
188 static function &newFromKey( $key ) {
189 global $wgStyleDirectory;
191 $key = Skin::normalizeKey( $key );
193 $skinNames = Skin::getSkinNames();
194 $skinName = $skinNames[$key];
195 $className = "Skin{$skinName}";
197 # Grab the skin class and initialise it.
198 if ( !class_exists( $className ) ) {
200 require_once "{$wgStyleDirectory}/{$skinName}.php";
202 # Check if we got if not fallback to default skin
203 if ( !class_exists( $className ) ) {
204 # DO NOT die if the class isn't found. This breaks maintenance
205 # scripts and can cause a user account to be unrecoverable
206 # except by SQL manipulation if a previously valid skin name
207 # is no longer valid.
208 wfDebug( "Skin class does not exist: $className\n" );
209 $className = 'SkinVector';
212 $skin = new $className( $key );
213 return $skin;
217 * @return string Skin name
219 public function getSkinName() {
220 return $this->skinname;
224 * @param OutputPage $out
226 function initPage( OutputPage $out ) {
227 wfProfileIn( __METHOD__ );
229 $this->preloadExistence();
231 wfProfileOut( __METHOD__ );
235 * Defines the ResourceLoader modules that should be added to the skin
236 * It is recommended that skins wishing to override call parent::getDefaultModules()
237 * and substitute out any modules they wish to change by using a key to look them up
238 * @return array Array of modules with helper keys for easy overriding
240 public function getDefaultModules() {
241 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
242 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
244 $out = $this->getOutput();
245 $user = $out->getUser();
246 $modules = array(
247 // modules that enhance the page content in some way
248 'content' => array(
249 'mediawiki.page.ready',
251 // modules that exist for legacy reasons
252 'legacy' => array(),
253 // modules relating to search functionality
254 'search' => array(),
255 // modules relating to functionality relating to watching an article
256 'watch' => array(),
257 // modules which relate to the current users preferences
258 'user' => array(),
260 if ( $wgIncludeLegacyJavaScript ) {
261 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
264 if ( $wgPreloadJavaScriptMwUtil ) {
265 $modules['legacy'][] = 'mediawiki.util';
268 // Add various resources if required
269 if ( $wgUseAjax ) {
270 $modules['legacy'][] = 'mediawiki.legacy.ajax';
272 if ( $wgEnableAPI ) {
273 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
274 && $user->isAllowed( 'writeapi' )
276 $modules['watch'][] = 'mediawiki.page.watch.ajax';
279 $modules['search'][] = 'mediawiki.searchSuggest';
283 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
284 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
287 // Crazy edit-on-double-click stuff
288 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
289 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
291 return $modules;
295 * Preload the existence of three commonly-requested pages in a single query
297 function preloadExistence() {
298 $user = $this->getUser();
300 // User/talk link
301 $titles = array( $user->getUserPage(), $user->getTalkPage() );
303 // Other tab link
304 if ( $this->getTitle()->isSpecialPage() ) {
305 // nothing
306 } elseif ( $this->getTitle()->isTalkPage() ) {
307 $titles[] = $this->getTitle()->getSubjectPage();
308 } else {
309 $titles[] = $this->getTitle()->getTalkPage();
312 $lb = new LinkBatch( $titles );
313 $lb->setCaller( __METHOD__ );
314 $lb->execute();
318 * Get the current revision ID
320 * @return int
322 public function getRevisionId() {
323 return $this->getOutput()->getRevisionId();
327 * Whether the revision displayed is the latest revision of the page
329 * @return bool
331 public function isRevisionCurrent() {
332 $revID = $this->getRevisionId();
333 return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
337 * Set the "relevant" title
338 * @see self::getRelevantTitle()
339 * @param Title $t
341 public function setRelevantTitle( $t ) {
342 $this->mRelevantTitle = $t;
346 * Return the "relevant" title.
347 * A "relevant" title is not necessarily the actual title of the page.
348 * Special pages like Special:MovePage use set the page they are acting on
349 * as their "relevant" title, this allows the skin system to display things
350 * such as content tabs which belong to to that page instead of displaying
351 * a basic special page tab which has almost no meaning.
353 * @return Title
355 public function getRelevantTitle() {
356 if ( isset( $this->mRelevantTitle ) ) {
357 return $this->mRelevantTitle;
359 return $this->getTitle();
363 * Set the "relevant" user
364 * @see self::getRelevantUser()
365 * @param User $u
367 public function setRelevantUser( $u ) {
368 $this->mRelevantUser = $u;
372 * Return the "relevant" user.
373 * A "relevant" user is similar to a relevant title. Special pages like
374 * Special:Contributions mark the user which they are relevant to so that
375 * things like the toolbox can display the information they usually are only
376 * able to display on a user's userpage and talkpage.
377 * @return User
379 public function getRelevantUser() {
380 if ( isset( $this->mRelevantUser ) ) {
381 return $this->mRelevantUser;
383 $title = $this->getRelevantTitle();
384 if ( $title->hasSubjectNamespace( NS_USER ) ) {
385 $rootUser = $title->getRootText();
386 if ( User::isIP( $rootUser ) ) {
387 $this->mRelevantUser = User::newFromName( $rootUser, false );
388 } else {
389 $user = User::newFromName( $rootUser, false );
390 if ( $user && $user->isLoggedIn() ) {
391 $this->mRelevantUser = $user;
394 return $this->mRelevantUser;
396 return null;
400 * Outputs the HTML generated by other functions.
401 * @param OutputPage $out
403 abstract function outputPage( OutputPage $out = null );
406 * @param array $data
407 * @return string
409 static function makeVariablesScript( $data ) {
410 if ( $data ) {
411 return Html::inlineScript(
412 ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) )
414 } else {
415 return '';
420 * Make a "<script>" tag containing global variables
422 * @deprecated since 1.19
423 * @param mixed $unused
424 * @return string HTML fragment
426 public static function makeGlobalVariablesScript( $unused ) {
427 global $wgOut;
429 wfDeprecated( __METHOD__, '1.19' );
431 return self::makeVariablesScript( $wgOut->getJSVars() );
435 * Get the query to generate a dynamic stylesheet
437 * @return array
439 public static function getDynamicStylesheetQuery() {
440 global $wgSquidMaxage;
442 return array(
443 'action' => 'raw',
444 'maxage' => $wgSquidMaxage,
445 'usemsgcache' => 'yes',
446 'ctype' => 'text/css',
447 'smaxage' => $wgSquidMaxage,
452 * Add skin specific stylesheets
453 * Calling this method with an $out of anything but the same OutputPage
454 * inside ->getOutput() is deprecated. The $out arg is kept
455 * for compatibility purposes with skins.
456 * @param OutputPage $out
457 * @todo delete
459 abstract function setupSkinUserCss( OutputPage $out );
462 * TODO: document
463 * @param Title $title
464 * @return string
466 function getPageClasses( $title ) {
467 $numeric = 'ns-' . $title->getNamespace();
469 if ( $title->isSpecialPage() ) {
470 $type = 'ns-special';
471 // bug 23315: provide a class based on the canonical special page name without subpages
472 list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
473 if ( $canonicalName ) {
474 $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
475 } else {
476 $type .= ' mw-invalidspecialpage';
478 } elseif ( $title->isTalkPage() ) {
479 $type = 'ns-talk';
480 } else {
481 $type = 'ns-subject';
484 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
486 return "$numeric $type $name";
490 * Return values for <html> element
491 * @return array of associative name-to-value elements for <html> element
493 public function getHtmlElementAttributes() {
494 $lang = $this->getLanguage();
495 return array(
496 'lang' => $lang->getHtmlCode(),
497 'dir' => $lang->getDir(),
498 'class' => 'client-nojs',
503 * This will be called by OutputPage::headElement when it is creating the
504 * "<body>" tag, skins can override it if they have a need to add in any
505 * body attributes or classes of their own.
506 * @param OutputPage $out
507 * @param array $bodyAttrs
509 function addToBodyAttributes( $out, &$bodyAttrs ) {
510 // does nothing by default
514 * URL to the logo
515 * @return string
517 function getLogo() {
518 global $wgLogo;
519 return $wgLogo;
523 * @return string
525 function getCategoryLinks() {
526 global $wgUseCategoryBrowser;
528 $out = $this->getOutput();
529 $allCats = $out->getCategoryLinks();
531 if ( !count( $allCats ) ) {
532 return '';
535 $embed = "<li>";
536 $pop = "</li>";
538 $s = '';
539 $colon = $this->msg( 'colon-separator' )->escaped();
541 if ( !empty( $allCats['normal'] ) ) {
542 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
544 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
545 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
546 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
547 Linker::link( Title::newFromText( $linkPage ), $msg )
548 . $colon . '<ul>' . $t . '</ul>' . '</div>';
551 # Hidden categories
552 if ( isset( $allCats['hidden'] ) ) {
553 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
554 $class = ' mw-hidden-cats-user-shown';
555 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
556 $class = ' mw-hidden-cats-ns-shown';
557 } else {
558 $class = ' mw-hidden-cats-hidden';
561 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
562 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
563 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
564 '</div>';
567 # optional 'dmoz-like' category browser. Will be shown under the list
568 # of categories an article belong to
569 if ( $wgUseCategoryBrowser ) {
570 $s .= '<br /><hr />';
572 # get a big array of the parents tree
573 $parenttree = $this->getTitle()->getParentCategoryTree();
574 # Skin object passed by reference cause it can not be
575 # accessed under the method subfunction drawCategoryBrowser
576 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
577 # Clean out bogus first entry and sort them
578 unset( $tempout[0] );
579 asort( $tempout );
580 # Output one per line
581 $s .= implode( "<br />\n", $tempout );
584 return $s;
588 * Render the array as a series of links.
589 * @param array $tree Categories tree returned by Title::getParentCategoryTree
590 * @return string Separated by &gt;, terminate with "\n"
592 function drawCategoryBrowser( $tree ) {
593 $return = '';
595 foreach ( $tree as $element => $parent ) {
596 if ( empty( $parent ) ) {
597 # element start a new list
598 $return .= "\n";
599 } else {
600 # grab the others elements
601 $return .= $this->drawCategoryBrowser( $parent ) . ' &gt; ';
604 # add our current element to the list
605 $eltitle = Title::newFromText( $element );
606 $return .= Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
609 return $return;
613 * @return string
615 function getCategories() {
616 $out = $this->getOutput();
618 $catlinks = $this->getCategoryLinks();
620 $classes = 'catlinks';
622 // Check what we're showing
623 $allCats = $out->getCategoryLinks();
624 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
625 $this->getTitle()->getNamespace() == NS_CATEGORY;
627 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
628 $classes .= ' catlinks-allhidden';
631 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
635 * This runs a hook to allow extensions placing their stuff after content
636 * and article metadata (e.g. categories).
637 * Note: This function has nothing to do with afterContent().
639 * This hook is placed here in order to allow using the same hook for all
640 * skins, both the SkinTemplate based ones and the older ones, which directly
641 * use this class to get their data.
643 * The output of this function gets processed in SkinTemplate::outputPage() for
644 * the SkinTemplate based skins, all other skins should directly echo it.
646 * @return string Empty by default, if not changed by any hook function.
648 protected function afterContentHook() {
649 $data = '';
651 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
652 // adding just some spaces shouldn't toggle the output
653 // of the whole <div/>, so we use trim() here
654 if ( trim( $data ) != '' ) {
655 // Doing this here instead of in the skins to
656 // ensure that the div has the same ID in all
657 // skins
658 $data = "<div id='mw-data-after-content'>\n" .
659 "\t$data\n" .
660 "</div>\n";
662 } else {
663 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
666 return $data;
670 * Generate debug data HTML for displaying at the bottom of the main content
671 * area.
672 * @return string HTML containing debug data, if enabled (otherwise empty).
674 protected function generateDebugHTML() {
675 return MWDebug::getHTMLDebugLog();
679 * This gets called shortly before the "</body>" tag.
681 * @return string HTML-wrapped JS code to be put before "</body>"
683 function bottomScripts() {
684 // TODO and the suckage continues. This function is really just a wrapper around
685 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
686 // up at some point
687 $bottomScriptText = $this->getOutput()->getBottomScripts();
688 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
690 return $bottomScriptText;
694 * Text with the permalink to the source page,
695 * usually shown on the footer of a printed page
697 * @return string HTML text with an URL
699 function printSource() {
700 $oldid = $this->getRevisionId();
701 if ( $oldid ) {
702 $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
703 $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
704 } else {
705 // oldid not available for non existing pages
706 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
709 return $this->msg( 'retrievedfrom', '<a dir="ltr" href="' . $url
710 . '">' . $url . '</a>' )->text();
714 * @return string
716 function getUndeleteLink() {
717 $action = $this->getRequest()->getVal( 'action', 'view' );
719 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
720 ( $this->getTitle()->getArticleID() == 0 || $action == 'history' ) ) {
721 $n = $this->getTitle()->isDeleted();
723 if ( $n ) {
724 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
725 $msg = 'thisisdeleted';
726 } else {
727 $msg = 'viewdeleted';
730 return $this->msg( $msg )->rawParams(
731 Linker::linkKnown(
732 SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
733 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
734 )->text();
738 return '';
742 * @return string
744 function subPageSubtitle() {
745 $out = $this->getOutput();
746 $subpages = '';
748 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
749 return $subpages;
752 if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
753 $ptext = $this->getTitle()->getPrefixedText();
754 if ( preg_match( '/\//', $ptext ) ) {
755 $links = explode( '/', $ptext );
756 array_pop( $links );
757 $c = 0;
758 $growinglink = '';
759 $display = '';
760 $lang = $this->getLanguage();
762 foreach ( $links as $link ) {
763 $growinglink .= $link;
764 $display .= $link;
765 $linkObj = Title::newFromText( $growinglink );
767 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
768 $getlink = Linker::linkKnown(
769 $linkObj,
770 htmlspecialchars( $display )
773 $c++;
775 if ( $c > 1 ) {
776 $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
777 } else {
778 $subpages .= '&lt; ';
781 $subpages .= $getlink;
782 $display = '';
783 } else {
784 $display .= '/';
786 $growinglink .= '/';
791 return $subpages;
795 * Returns true if the IP should be shown in the header
796 * @return bool
798 function showIPinHeader() {
799 global $wgShowIPinHeader;
800 return $wgShowIPinHeader && session_id() != '';
804 * @return string
806 function getSearchLink() {
807 $searchPage = SpecialPage::getTitleFor( 'Search' );
808 return $searchPage->getLocalURL();
812 * @return string
814 function escapeSearchLink() {
815 return htmlspecialchars( $this->getSearchLink() );
819 * @param string $type
820 * @return string
822 function getCopyright( $type = 'detect' ) {
823 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
825 if ( $type == 'detect' ) {
826 if ( !$this->isRevisionCurrent()
827 && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
829 $type = 'history';
830 } else {
831 $type = 'normal';
835 if ( $type == 'history' ) {
836 $msg = 'history_copyright';
837 } else {
838 $msg = 'copyright';
841 if ( $wgRightsPage ) {
842 $title = Title::newFromText( $wgRightsPage );
843 $link = Linker::linkKnown( $title, $wgRightsText );
844 } elseif ( $wgRightsUrl ) {
845 $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
846 } elseif ( $wgRightsText ) {
847 $link = $wgRightsText;
848 } else {
849 # Give up now
850 return '';
853 // Allow for site and per-namespace customization of copyright notice.
854 // @todo Remove deprecated $forContent param from hook handlers and then remove here.
855 $forContent = true;
857 wfRunHooks(
858 'SkinCopyrightFooter',
859 array( $this->getTitle(), $type, &$msg, &$link, &$forContent )
862 return $this->msg( $msg )->rawParams( $link )->text();
866 * @return null|string
868 function getCopyrightIcon() {
869 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
871 $out = '';
873 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
874 $out = $wgCopyrightIcon;
875 } elseif ( $wgRightsIcon ) {
876 $icon = htmlspecialchars( $wgRightsIcon );
878 if ( $wgRightsUrl ) {
879 $url = htmlspecialchars( $wgRightsUrl );
880 $out .= '<a href="' . $url . '">';
883 $text = htmlspecialchars( $wgRightsText );
884 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
886 if ( $wgRightsUrl ) {
887 $out .= '</a>';
891 return $out;
895 * Gets the powered by MediaWiki icon.
896 * @return string
898 function getPoweredBy() {
899 global $wgStylePath;
901 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
902 $text = '<a href="//www.mediawiki.org/"><img src="' . $url
903 . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
904 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
905 return $text;
909 * Get the timestamp of the latest revision, formatted in user language
911 * @return string
913 protected function lastModified() {
914 $timestamp = $this->getOutput()->getRevisionTimestamp();
916 # No cached timestamp, load it from the database
917 if ( $timestamp === null ) {
918 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
921 if ( $timestamp ) {
922 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
923 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
924 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
925 } else {
926 $s = '';
929 if ( wfGetLB()->getLaggedSlaveMode() ) {
930 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
933 return $s;
937 * @param string $align
938 * @return string
940 function logoText( $align = '' ) {
941 if ( $align != '' ) {
942 $a = " style='float: {$align};'";
943 } else {
944 $a = '';
947 $mp = $this->msg( 'mainpage' )->escaped();
948 $mptitle = Title::newMainPage();
949 $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
951 $logourl = $this->getLogo();
952 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
954 return $s;
958 * Renders a $wgFooterIcons icon according to the method's arguments
959 * @param array $icon The icon to build the html for, see $wgFooterIcons
960 * for the format of this array.
961 * @param bool|string $withImage Whether to use the icon's image or output
962 * a text-only footericon.
963 * @return string HTML
965 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
966 if ( is_string( $icon ) ) {
967 $html = $icon;
968 } else { // Assuming array
969 $url = isset( $icon["url"] ) ? $icon["url"] : null;
970 unset( $icon["url"] );
971 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
972 // do this the lazy way, just pass icon data as an attribute array
973 $html = Html::element( 'img', $icon );
974 } else {
975 $html = htmlspecialchars( $icon["alt"] );
977 if ( $url ) {
978 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
981 return $html;
985 * Gets the link to the wiki's main page.
986 * @return string
988 function mainPageLink() {
989 $s = Linker::linkKnown(
990 Title::newMainPage(),
991 $this->msg( 'mainpage' )->escaped()
994 return $s;
998 * Returns an HTML link for use in the footer
999 * @param string $desc i18n message key for the link text
1000 * @param string $page i18n message key for the page to link to
1001 * @return string HTML anchor
1003 public function footerLink( $desc, $page ) {
1004 // if the link description has been set to "-" in the default language,
1005 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
1006 // then it is disabled, for all languages.
1007 return '';
1008 } else {
1009 // Otherwise, we display the link for the user, described in their
1010 // language (which may or may not be the same as the default language),
1011 // but we make the link target be the one site-wide page.
1012 $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
1014 return Linker::linkKnown(
1015 $title,
1016 $this->msg( $desc )->escaped()
1022 * Gets the link to the wiki's privacy policy page.
1023 * @return string HTML
1025 function privacyLink() {
1026 return $this->footerLink( 'privacy', 'privacypage' );
1030 * Gets the link to the wiki's about page.
1031 * @return string HTML
1033 function aboutLink() {
1034 return $this->footerLink( 'aboutsite', 'aboutpage' );
1038 * Gets the link to the wiki's general disclaimers page.
1039 * @return string HTML
1041 function disclaimerLink() {
1042 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1046 * Return URL options for the 'edit page' link.
1047 * This may include an 'oldid' specifier, if the current page view is such.
1049 * @return array
1050 * @private
1052 function editUrlOptions() {
1053 $options = array( 'action' => 'edit' );
1055 if ( !$this->isRevisionCurrent() ) {
1056 $options['oldid'] = intval( $this->getRevisionId() );
1059 return $options;
1063 * @param User|int $id
1064 * @return bool
1066 function showEmailUser( $id ) {
1067 if ( $id instanceof User ) {
1068 $targetUser = $id;
1069 } else {
1070 $targetUser = User::newFromId( $id );
1073 # The sending user must have a confirmed email address and the target
1074 # user must have a confirmed email address and allow emails from users.
1075 return $this->getUser()->canSendEmail() &&
1076 $targetUser->canReceiveEmail();
1080 * Return a fully resolved style path url to images or styles stored in the common folder.
1081 * This method returns a url resolved using the configured skin style path
1082 * and includes the style version inside of the url.
1083 * @param string $name The name or path of a skin resource file
1084 * @return string The fully resolved style path url including styleversion
1086 function getCommonStylePath( $name ) {
1087 global $wgStylePath, $wgStyleVersion;
1088 return "$wgStylePath/common/$name?$wgStyleVersion";
1092 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
1093 * This method returns a url resolved using the configured skin style path
1094 * and includes the style version inside of the url.
1095 * @param string $name The name or path of a skin resource file
1096 * @return string The fully resolved style path url including styleversion
1098 function getSkinStylePath( $name ) {
1099 global $wgStylePath, $wgStyleVersion;
1100 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1103 /* these are used extensively in SkinTemplate, but also some other places */
1106 * @param string $urlaction
1107 * @return string
1109 static function makeMainPageUrl( $urlaction = '' ) {
1110 $title = Title::newMainPage();
1111 self::checkTitle( $title, '' );
1113 return $title->getLocalURL( $urlaction );
1117 * Make a URL for a Special Page using the given query and protocol.
1119 * If $proto is set to null, make a local URL. Otherwise, make a full
1120 * URL with the protocol specified.
1122 * @param string $name Name of the Special page
1123 * @param string $urlaction Query to append
1124 * @param string|null $proto Protocol to use or null for a local URL
1125 * @return string
1127 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1128 $title = SpecialPage::getSafeTitleFor( $name );
1129 if ( is_null( $proto ) ) {
1130 return $title->getLocalURL( $urlaction );
1131 } else {
1132 return $title->getFullURL( $urlaction, false, $proto );
1137 * @param string $name
1138 * @param string $subpage
1139 * @param string $urlaction
1140 * @return string
1142 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1143 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1144 return $title->getLocalURL( $urlaction );
1148 * @param string $name
1149 * @param string $urlaction
1150 * @return string
1152 static function makeI18nUrl( $name, $urlaction = '' ) {
1153 $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1154 self::checkTitle( $title, $name );
1155 return $title->getLocalURL( $urlaction );
1159 * @param string $name
1160 * @param string $urlaction
1161 * @return string
1163 static function makeUrl( $name, $urlaction = '' ) {
1164 $title = Title::newFromText( $name );
1165 self::checkTitle( $title, $name );
1167 return $title->getLocalURL( $urlaction );
1171 * If url string starts with http, consider as external URL, else
1172 * internal
1173 * @param string $name
1174 * @return string URL
1176 static function makeInternalOrExternalUrl( $name ) {
1177 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1178 return $name;
1179 } else {
1180 return self::makeUrl( $name );
1185 * this can be passed the NS number as defined in Language.php
1186 * @param string $name
1187 * @param string $urlaction
1188 * @param int $namespace
1189 * @return string
1191 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1192 $title = Title::makeTitleSafe( $namespace, $name );
1193 self::checkTitle( $title, $name );
1195 return $title->getLocalURL( $urlaction );
1199 * these return an array with the 'href' and boolean 'exists'
1200 * @param string $name
1201 * @param string $urlaction
1202 * @return array
1204 static function makeUrlDetails( $name, $urlaction = '' ) {
1205 $title = Title::newFromText( $name );
1206 self::checkTitle( $title, $name );
1208 return array(
1209 'href' => $title->getLocalURL( $urlaction ),
1210 'exists' => $title->getArticleID() != 0,
1215 * Make URL details where the article exists (or at least it's convenient to think so)
1216 * @param string $name Article name
1217 * @param string $urlaction
1218 * @return array
1220 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1221 $title = Title::newFromText( $name );
1222 self::checkTitle( $title, $name );
1224 return array(
1225 'href' => $title->getLocalURL( $urlaction ),
1226 'exists' => true
1231 * make sure we have some title to operate on
1233 * @param Title $title
1234 * @param string $name
1236 static function checkTitle( &$title, $name ) {
1237 if ( !is_object( $title ) ) {
1238 $title = Title::newFromText( $name );
1239 if ( !is_object( $title ) ) {
1240 $title = Title::newFromText( '--error: link target missing--' );
1246 * Build an array that represents the sidebar(s), the navigation bar among them.
1248 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1250 * The format of the returned array is array( heading => content, ... ), where:
1251 * - heading is the heading of a navigation portlet. It is either:
1252 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1253 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1254 * - plain text, which should be HTML-escaped by the skin
1255 * - content is the contents of the portlet. It is either:
1256 * - HTML text (<ul><li>...</li>...</ul>)
1257 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1258 * - (for a magic string as a key, any value)
1260 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1261 * and can technically insert anything in here; skin creators are expected to handle
1262 * values described above.
1264 * @return array
1266 function buildSidebar() {
1267 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1268 wfProfileIn( __METHOD__ );
1270 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1272 if ( $wgEnableSidebarCache ) {
1273 $cachedsidebar = $wgMemc->get( $key );
1274 if ( $cachedsidebar ) {
1275 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
1277 wfProfileOut( __METHOD__ );
1278 return $cachedsidebar;
1282 $bar = array();
1283 $this->addToSidebar( $bar, 'sidebar' );
1285 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1286 if ( $wgEnableSidebarCache ) {
1287 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1290 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$bar ) );
1292 wfProfileOut( __METHOD__ );
1293 return $bar;
1297 * Add content from a sidebar system message
1298 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1300 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1302 * @param array $bar
1303 * @param string $message
1305 function addToSidebar( &$bar, $message ) {
1306 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1310 * Add content from plain text
1311 * @since 1.17
1312 * @param array $bar
1313 * @param string $text
1314 * @return array
1316 function addToSidebarPlain( &$bar, $text ) {
1317 $lines = explode( "\n", $text );
1319 $heading = '';
1321 foreach ( $lines as $line ) {
1322 if ( strpos( $line, '*' ) !== 0 ) {
1323 continue;
1325 $line = rtrim( $line, "\r" ); // for Windows compat
1327 if ( strpos( $line, '**' ) !== 0 ) {
1328 $heading = trim( $line, '* ' );
1329 if ( !array_key_exists( $heading, $bar ) ) {
1330 $bar[$heading] = array();
1332 } else {
1333 $line = trim( $line, '* ' );
1335 if ( strpos( $line, '|' ) !== false ) { // sanity check
1336 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1337 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1338 if ( count( $line ) !== 2 ) {
1339 // Second sanity check, could be hit by people doing
1340 // funky stuff with parserfuncs... (bug 33321)
1341 continue;
1344 $extraAttribs = array();
1346 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1347 if ( $msgLink->exists() ) {
1348 $link = $msgLink->text();
1349 if ( $link == '-' ) {
1350 continue;
1352 } else {
1353 $link = $line[0];
1355 $msgText = $this->msg( $line[1] );
1356 if ( $msgText->exists() ) {
1357 $text = $msgText->text();
1358 } else {
1359 $text = $line[1];
1362 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1363 $href = $link;
1365 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1366 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1367 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1368 $extraAttribs['rel'] = 'nofollow';
1371 global $wgExternalLinkTarget;
1372 if ( $wgExternalLinkTarget ) {
1373 $extraAttribs['target'] = $wgExternalLinkTarget;
1375 } else {
1376 $title = Title::newFromText( $link );
1378 if ( $title ) {
1379 $title = $title->fixSpecialName();
1380 $href = $title->getLinkURL();
1381 } else {
1382 $href = 'INVALID-TITLE';
1386 $bar[$heading][] = array_merge( array(
1387 'text' => $text,
1388 'href' => $href,
1389 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1390 'active' => false
1391 ), $extraAttribs );
1392 } else {
1393 continue;
1398 return $bar;
1402 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1403 * should be loaded by OutputPage. That module no longer exists and the return value of this
1404 * method is ignored.
1406 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1407 * can be used instead (SkinTemplate-based skins do it automatically).
1409 * @deprecated since 1.22
1410 * @return bool
1412 public function commonPrintStylesheet() {
1413 wfDeprecated( __METHOD__, '1.22' );
1414 return false;
1418 * Gets new talk page messages for the current user and returns an
1419 * appropriate alert message (or an empty string if there are no messages)
1420 * @return string
1422 function getNewtalks() {
1424 $newMessagesAlert = '';
1425 $user = $this->getUser();
1426 $newtalks = $user->getNewMessageLinks();
1427 $out = $this->getOutput();
1429 // Allow extensions to disable or modify the new messages alert
1430 if ( !wfRunHooks( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1431 return '';
1433 if ( $newMessagesAlert ) {
1434 return $newMessagesAlert;
1437 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1438 $uTalkTitle = $user->getTalkPage();
1439 $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
1440 $nofAuthors = 0;
1441 if ( $lastSeenRev !== null ) {
1442 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1443 $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
1444 if ( $latestRev !== null ) {
1445 // Singular if only 1 unseen revision, plural if several unseen revisions.
1446 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1447 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1448 $lastSeenRev, $latestRev, 10, 'include_new' );
1450 } else {
1451 // Singular if no revision -> diff link will show latest change only in any case
1452 $plural = false;
1454 $plural = $plural ? 999 : 1;
1455 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1456 // the number of revisions or authors is not necessarily the same as the number of
1457 // "messages".
1458 $newMessagesLink = Linker::linkKnown(
1459 $uTalkTitle,
1460 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1461 array(),
1462 array( 'redirect' => 'no' )
1465 $newMessagesDiffLink = Linker::linkKnown(
1466 $uTalkTitle,
1467 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1468 array(),
1469 $lastSeenRev !== null
1470 ? array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1471 : array( 'diff' => 'cur' )
1474 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1475 $newMessagesAlert = $this->msg(
1476 'youhavenewmessagesfromusers',
1477 $newMessagesLink,
1478 $newMessagesDiffLink
1479 )->numParams( $nofAuthors, $plural );
1480 } else {
1481 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1482 $newMessagesAlert = $this->msg(
1483 $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1484 $newMessagesLink,
1485 $newMessagesDiffLink
1486 )->numParams( $plural );
1488 $newMessagesAlert = $newMessagesAlert->text();
1489 # Disable Squid cache
1490 $out->setSquidMaxage( 0 );
1491 } elseif ( count( $newtalks ) ) {
1492 $sep = $this->msg( 'newtalkseparator' )->escaped();
1493 $msgs = array();
1495 foreach ( $newtalks as $newtalk ) {
1496 $msgs[] = Xml::element(
1497 'a',
1498 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1501 $parts = implode( $sep, $msgs );
1502 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1503 $out->setSquidMaxage( 0 );
1506 return $newMessagesAlert;
1510 * Get a cached notice
1512 * @param string $name Message name, or 'default' for $wgSiteNotice
1513 * @return string HTML fragment
1515 private function getCachedNotice( $name ) {
1516 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1518 wfProfileIn( __METHOD__ );
1520 $needParse = false;
1522 if ( $name === 'default' ) {
1523 // special case
1524 global $wgSiteNotice;
1525 $notice = $wgSiteNotice;
1526 if ( empty( $notice ) ) {
1527 wfProfileOut( __METHOD__ );
1528 return false;
1530 } else {
1531 $msg = $this->msg( $name )->inContentLanguage();
1532 if ( $msg->isDisabled() ) {
1533 wfProfileOut( __METHOD__ );
1534 return false;
1536 $notice = $msg->plain();
1539 // Use the extra hash appender to let eg SSL variants separately cache.
1540 $key = wfMemcKey( $name . $wgRenderHashAppend );
1541 $cachedNotice = $parserMemc->get( $key );
1542 if ( is_array( $cachedNotice ) ) {
1543 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1544 $notice = $cachedNotice['html'];
1545 } else {
1546 $needParse = true;
1548 } else {
1549 $needParse = true;
1552 if ( $needParse ) {
1553 $parsed = $this->getOutput()->parse( $notice );
1554 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1555 $notice = $parsed;
1558 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1559 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1560 wfProfileOut( __METHOD__ );
1561 return $notice;
1565 * Get a notice based on page's namespace
1567 * @return string HTML fragment
1569 function getNamespaceNotice() {
1570 wfProfileIn( __METHOD__ );
1572 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1573 $namespaceNotice = $this->getCachedNotice( $key );
1574 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1575 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1576 } else {
1577 $namespaceNotice = '';
1580 wfProfileOut( __METHOD__ );
1581 return $namespaceNotice;
1585 * Get the site notice
1587 * @return string HTML fragment
1589 function getSiteNotice() {
1590 wfProfileIn( __METHOD__ );
1591 $siteNotice = '';
1593 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1594 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1595 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1596 } else {
1597 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1598 if ( !$anonNotice ) {
1599 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1600 } else {
1601 $siteNotice = $anonNotice;
1604 if ( !$siteNotice ) {
1605 $siteNotice = $this->getCachedNotice( 'default' );
1609 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1610 wfProfileOut( __METHOD__ );
1611 return $siteNotice;
1615 * Create a section edit link. This supersedes editSectionLink() and
1616 * editSectionLinkForOther().
1618 * @param Title $nt The title being linked to (may not be the same as
1619 * the current page, if the section is included from a template)
1620 * @param string $section The designation of the section being pointed to,
1621 * to be included in the link, like "&section=$section"
1622 * @param string $tooltip The tooltip to use for the link: will be escaped
1623 * and wrapped in the 'editsectionhint' message
1624 * @param string $lang Language code
1625 * @return string HTML to use for edit link
1627 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1628 // HTML generated here should probably have userlangattributes
1629 // added to it for LTR text on RTL pages
1631 $lang = wfGetLangObj( $lang );
1633 $attribs = array();
1634 if ( !is_null( $tooltip ) ) {
1635 # Bug 25462: undo double-escaping.
1636 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1637 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1638 ->inLanguage( $lang )->text();
1640 $link = Linker::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(),
1641 $attribs,
1642 array( 'action' => 'edit', 'section' => $section ),
1643 array( 'noclasses', 'known' )
1646 # Add the brackets and the span and run the hook.
1647 $result = '<span class="mw-editsection">'
1648 . '<span class="mw-editsection-bracket">[</span>'
1649 . $link
1650 . '<span class="mw-editsection-bracket">]</span>'
1651 . '</span>';
1653 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1654 return $result;
1658 * Use PHP's magic __call handler to intercept legacy calls to the linker
1659 * for backwards compatibility.
1661 * @param string $fname Name of called method
1662 * @param array $args Arguments to the method
1663 * @throws MWException
1664 * @return mixed
1666 function __call( $fname, $args ) {
1667 $realFunction = array( 'Linker', $fname );
1668 if ( is_callable( $realFunction ) ) {
1669 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1670 return call_user_func_array( $realFunction, $args );
1671 } else {
1672 $className = get_class( $this );
1673 throw new MWException( "Call to undefined method $className::$fname" );