Factorise $this->getTitle() call in Article::confirmDelete()
[mediawiki.git] / includes / Skin.php
blobfd737c04d2af96c4a9be1f4073387866ba225671
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 * @var string Stylesheets set to use. Subdirectory in skins/ where various stylesheets are
41 * located. Only needs to be set if you intend to use the getSkinStylePath() method.
43 public $stylename = null;
45 /**
46 * Fetch the set of available skins.
47 * @return array Associative array of strings
49 static function getSkinNames() {
50 global $wgValidSkinNames;
51 static $skinsInitialised = false;
53 if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) {
54 # Get a list of available skins
55 # Build using the regular expression '^(.*).php$'
56 # Array keys are all lower case, array value keep the case used by filename
58 wfProfileIn( __METHOD__ . '-init' );
60 global $wgStyleDirectory;
62 $skinDir = dir( $wgStyleDirectory );
64 if ( $skinDir !== false && $skinDir !== null ) {
65 # while code from www.php.net
66 while ( false !== ( $file = $skinDir->read() ) ) {
67 // Skip non-PHP files, hidden files, and '.dep' includes
68 $matches = array();
70 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
71 $aSkin = $matches[1];
73 // Explicitly disallow loading core skins via the autodiscovery mechanism.
75 // They should be loaded already (in a non-autodicovery way), but old files might still
76 // exist on the server because our MW version upgrade process is widely documented as
77 // requiring just copying over all files, without removing old ones.
79 // This is one of the reasons we should have never used autodiscovery in the first
80 // place. This hack can be safely removed when autodiscovery is gone.
81 if ( in_array( $aSkin, array( 'CologneBlue', 'Modern', 'MonoBook', 'Vector' ) ) ) {
82 wfLogWarning(
83 "An old copy of the $aSkin skin was found in your skins/ directory. " .
84 "You should remove it to avoid problems in the future." .
85 "See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for details."
87 continue;
90 wfLogWarning(
91 "A skin using autodiscovery mechanism, $aSkin, was found in your skins/ directory. " .
92 "The mechanism will be removed in MediaWiki 1.25 and the skin will no longer be recognized. " .
93 "See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for information how to fix this."
95 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
98 $skinDir->close();
100 $skinsInitialised = true;
101 wfProfileOut( __METHOD__ . '-init' );
103 return $wgValidSkinNames;
107 * Fetch the skinname messages for available skins.
108 * @return string[]
110 static function getSkinNameMessages() {
111 $messages = array();
112 foreach ( self::getSkinNames() as $skinKey => $skinName ) {
113 $messages[] = "skinname-$skinKey";
115 return $messages;
119 * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
120 * Useful for Special:Preferences and other places where you
121 * only want to show skins users _can_ use.
122 * @return string[]
123 * @since 1.23
125 public static function getAllowedSkins() {
126 global $wgSkipSkins;
128 $allowedSkins = self::getSkinNames();
130 foreach ( $wgSkipSkins as $skip ) {
131 unset( $allowedSkins[$skip] );
134 return $allowedSkins;
138 * @deprecated since 1.23, use getAllowedSkins
139 * @return string[]
141 public static function getUsableSkins() {
142 wfDeprecated( __METHOD__, '1.23' );
143 return self::getAllowedSkins();
147 * Normalize a skin preference value to a form that can be loaded.
149 * If a skin can't be found, it will fall back to the configured default ($wgDefaultSkin), or the
150 * hardcoded default ($wgFallbackSkin) if the default skin is unavailable too.
152 * @param string $key 'monobook', 'vector', etc.
153 * @return string
155 static function normalizeKey( $key ) {
156 global $wgDefaultSkin, $wgFallbackSkin;
158 $skinNames = Skin::getSkinNames();
160 // Make keys lowercase for case-insensitive matching.
161 $skinNames = array_change_key_case( $skinNames, CASE_LOWER );
162 $key = strtolower( $key );
163 $defaultSkin = strtolower( $wgDefaultSkin );
164 $fallbackSkin = strtolower( $wgFallbackSkin );
166 if ( $key == '' || $key == 'default' ) {
167 // Don't return the default immediately;
168 // in a misconfiguration we need to fall back.
169 $key = $defaultSkin;
172 if ( isset( $skinNames[$key] ) ) {
173 return $key;
176 // Older versions of the software used a numeric setting
177 // in the user preferences.
178 $fallback = array(
179 0 => $defaultSkin,
180 2 => 'cologneblue'
183 if ( isset( $fallback[$key] ) ) {
184 $key = $fallback[$key];
187 if ( isset( $skinNames[$key] ) ) {
188 return $key;
189 } elseif ( isset( $skinNames[$defaultSkin] ) ) {
190 return $defaultSkin;
191 } else {
192 return $fallbackSkin;
197 * Factory method for loading a skin of a given type
198 * @param string $key 'monobook', 'vector', etc.
199 * @return Skin
201 static function &newFromKey( $key ) {
202 global $wgStyleDirectory, $wgFallbackSkin;
204 $key = Skin::normalizeKey( $key );
206 $skinNames = Skin::getSkinNames();
207 $skinName = $skinNames[$key];
208 $className = "Skin{$skinName}";
210 # Grab the skin class and initialise it.
211 if ( !class_exists( $className ) ) {
213 require_once "{$wgStyleDirectory}/{$skinName}.php";
215 # Check if we got if not fallback to default skin
216 if ( !class_exists( $className ) ) {
217 # DO NOT die if the class isn't found. This breaks maintenance
218 # scripts and can cause a user account to be unrecoverable
219 # except by SQL manipulation if a previously valid skin name
220 # is no longer valid.
221 wfDebug( "Skin class does not exist: $className\n" );
223 $fallback = $skinNames[ Skin::normalizeKey( $wgFallbackSkin ) ];
224 $className = "Skin{$fallback}";
227 $skin = new $className( $key );
228 return $skin;
232 * @return string Skin name
234 public function getSkinName() {
235 return $this->skinname;
239 * @param OutputPage $out
241 function initPage( OutputPage $out ) {
242 wfProfileIn( __METHOD__ );
244 $this->preloadExistence();
246 wfProfileOut( __METHOD__ );
250 * Defines the ResourceLoader modules that should be added to the skin
251 * It is recommended that skins wishing to override call parent::getDefaultModules()
252 * and substitute out any modules they wish to change by using a key to look them up
253 * @return array Array of modules with helper keys for easy overriding
255 public function getDefaultModules() {
256 global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
257 $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
259 $out = $this->getOutput();
260 $user = $out->getUser();
261 $modules = array(
262 // modules that enhance the page content in some way
263 'content' => array(
264 'mediawiki.page.ready',
266 // modules that exist for legacy reasons
267 'legacy' => array(),
268 // modules relating to search functionality
269 'search' => array(),
270 // modules relating to functionality relating to watching an article
271 'watch' => array(),
272 // modules which relate to the current users preferences
273 'user' => array(),
275 if ( $wgIncludeLegacyJavaScript ) {
276 $modules['legacy'][] = 'mediawiki.legacy.wikibits';
279 if ( $wgPreloadJavaScriptMwUtil ) {
280 $modules['legacy'][] = 'mediawiki.util';
283 // Add various resources if required
284 if ( $wgUseAjax ) {
285 $modules['legacy'][] = 'mediawiki.legacy.ajax';
287 if ( $wgEnableAPI ) {
288 if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
289 && $user->isAllowed( 'writeapi' )
291 $modules['watch'][] = 'mediawiki.page.watch.ajax';
294 $modules['search'][] = 'mediawiki.searchSuggest';
298 if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
299 $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
302 // Crazy edit-on-double-click stuff
303 if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
304 $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
306 return $modules;
310 * Preload the existence of three commonly-requested pages in a single query
312 function preloadExistence() {
313 $user = $this->getUser();
315 // User/talk link
316 $titles = array( $user->getUserPage(), $user->getTalkPage() );
318 // Other tab link
319 if ( $this->getTitle()->isSpecialPage() ) {
320 // nothing
321 } elseif ( $this->getTitle()->isTalkPage() ) {
322 $titles[] = $this->getTitle()->getSubjectPage();
323 } else {
324 $titles[] = $this->getTitle()->getTalkPage();
327 $lb = new LinkBatch( $titles );
328 $lb->setCaller( __METHOD__ );
329 $lb->execute();
333 * Get the current revision ID
335 * @return int
337 public function getRevisionId() {
338 return $this->getOutput()->getRevisionId();
342 * Whether the revision displayed is the latest revision of the page
344 * @return bool
346 public function isRevisionCurrent() {
347 $revID = $this->getRevisionId();
348 return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
352 * Set the "relevant" title
353 * @see self::getRelevantTitle()
354 * @param Title $t
356 public function setRelevantTitle( $t ) {
357 $this->mRelevantTitle = $t;
361 * Return the "relevant" title.
362 * A "relevant" title is not necessarily the actual title of the page.
363 * Special pages like Special:MovePage use set the page they are acting on
364 * as their "relevant" title, this allows the skin system to display things
365 * such as content tabs which belong to to that page instead of displaying
366 * a basic special page tab which has almost no meaning.
368 * @return Title
370 public function getRelevantTitle() {
371 if ( isset( $this->mRelevantTitle ) ) {
372 return $this->mRelevantTitle;
374 return $this->getTitle();
378 * Set the "relevant" user
379 * @see self::getRelevantUser()
380 * @param User $u
382 public function setRelevantUser( $u ) {
383 $this->mRelevantUser = $u;
387 * Return the "relevant" user.
388 * A "relevant" user is similar to a relevant title. Special pages like
389 * Special:Contributions mark the user which they are relevant to so that
390 * things like the toolbox can display the information they usually are only
391 * able to display on a user's userpage and talkpage.
392 * @return User
394 public function getRelevantUser() {
395 if ( isset( $this->mRelevantUser ) ) {
396 return $this->mRelevantUser;
398 $title = $this->getRelevantTitle();
399 if ( $title->hasSubjectNamespace( NS_USER ) ) {
400 $rootUser = $title->getRootText();
401 if ( User::isIP( $rootUser ) ) {
402 $this->mRelevantUser = User::newFromName( $rootUser, false );
403 } else {
404 $user = User::newFromName( $rootUser, false );
405 if ( $user && $user->isLoggedIn() ) {
406 $this->mRelevantUser = $user;
409 return $this->mRelevantUser;
411 return null;
415 * Outputs the HTML generated by other functions.
416 * @param OutputPage $out
418 abstract function outputPage( OutputPage $out = null );
421 * @param array $data
422 * @return string
424 static function makeVariablesScript( $data ) {
425 if ( $data ) {
426 return Html::inlineScript(
427 ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) )
429 } else {
430 return '';
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;
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 ( $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 The i18n message key for the link text
1000 * @param string $page The 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.
1096 * Requires $stylename to be set, otherwise throws MWException.
1098 * @param string $name The name or path of a skin resource file
1099 * @return string The fully resolved style path url including styleversion
1101 function getSkinStylePath( $name ) {
1102 global $wgStylePath, $wgStyleVersion;
1104 if ( $this->stylename === null ) {
1105 $class = get_class( $this );
1106 throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
1109 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1112 /* these are used extensively in SkinTemplate, but also some other places */
1115 * @param string $urlaction
1116 * @return string
1118 static function makeMainPageUrl( $urlaction = '' ) {
1119 $title = Title::newMainPage();
1120 self::checkTitle( $title, '' );
1122 return $title->getLocalURL( $urlaction );
1126 * Make a URL for a Special Page using the given query and protocol.
1128 * If $proto is set to null, make a local URL. Otherwise, make a full
1129 * URL with the protocol specified.
1131 * @param string $name Name of the Special page
1132 * @param string $urlaction Query to append
1133 * @param string|null $proto Protocol to use or null for a local URL
1134 * @return string
1136 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1137 $title = SpecialPage::getSafeTitleFor( $name );
1138 if ( is_null( $proto ) ) {
1139 return $title->getLocalURL( $urlaction );
1140 } else {
1141 return $title->getFullURL( $urlaction, false, $proto );
1146 * @param string $name
1147 * @param string $subpage
1148 * @param string $urlaction
1149 * @return string
1151 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1152 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1153 return $title->getLocalURL( $urlaction );
1157 * @param string $name
1158 * @param string $urlaction
1159 * @return string
1161 static function makeI18nUrl( $name, $urlaction = '' ) {
1162 $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1163 self::checkTitle( $title, $name );
1164 return $title->getLocalURL( $urlaction );
1168 * @param string $name
1169 * @param string $urlaction
1170 * @return string
1172 static function makeUrl( $name, $urlaction = '' ) {
1173 $title = Title::newFromText( $name );
1174 self::checkTitle( $title, $name );
1176 return $title->getLocalURL( $urlaction );
1180 * If url string starts with http, consider as external URL, else
1181 * internal
1182 * @param string $name
1183 * @return string URL
1185 static function makeInternalOrExternalUrl( $name ) {
1186 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1187 return $name;
1188 } else {
1189 return self::makeUrl( $name );
1194 * this can be passed the NS number as defined in Language.php
1195 * @param string $name
1196 * @param string $urlaction
1197 * @param int $namespace
1198 * @return string
1200 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1201 $title = Title::makeTitleSafe( $namespace, $name );
1202 self::checkTitle( $title, $name );
1204 return $title->getLocalURL( $urlaction );
1208 * these return an array with the 'href' and boolean 'exists'
1209 * @param string $name
1210 * @param string $urlaction
1211 * @return array
1213 static function makeUrlDetails( $name, $urlaction = '' ) {
1214 $title = Title::newFromText( $name );
1215 self::checkTitle( $title, $name );
1217 return array(
1218 'href' => $title->getLocalURL( $urlaction ),
1219 'exists' => $title->getArticleID() != 0,
1224 * Make URL details where the article exists (or at least it's convenient to think so)
1225 * @param string $name Article name
1226 * @param string $urlaction
1227 * @return array
1229 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1230 $title = Title::newFromText( $name );
1231 self::checkTitle( $title, $name );
1233 return array(
1234 'href' => $title->getLocalURL( $urlaction ),
1235 'exists' => true
1240 * make sure we have some title to operate on
1242 * @param Title $title
1243 * @param string $name
1245 static function checkTitle( &$title, $name ) {
1246 if ( !is_object( $title ) ) {
1247 $title = Title::newFromText( $name );
1248 if ( !is_object( $title ) ) {
1249 $title = Title::newFromText( '--error: link target missing--' );
1255 * Build an array that represents the sidebar(s), the navigation bar among them.
1257 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1259 * The format of the returned array is array( heading => content, ... ), where:
1260 * - heading is the heading of a navigation portlet. It is either:
1261 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1262 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1263 * - plain text, which should be HTML-escaped by the skin
1264 * - content is the contents of the portlet. It is either:
1265 * - HTML text (<ul><li>...</li>...</ul>)
1266 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1267 * - (for a magic string as a key, any value)
1269 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1270 * and can technically insert anything in here; skin creators are expected to handle
1271 * values described above.
1273 * @return array
1275 function buildSidebar() {
1276 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1277 wfProfileIn( __METHOD__ );
1279 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1281 if ( $wgEnableSidebarCache ) {
1282 $cachedsidebar = $wgMemc->get( $key );
1283 if ( $cachedsidebar ) {
1284 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
1286 wfProfileOut( __METHOD__ );
1287 return $cachedsidebar;
1291 $bar = array();
1292 $this->addToSidebar( $bar, 'sidebar' );
1294 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1295 if ( $wgEnableSidebarCache ) {
1296 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1299 wfRunHooks( 'SidebarBeforeOutput', array( $this, &$bar ) );
1301 wfProfileOut( __METHOD__ );
1302 return $bar;
1306 * Add content from a sidebar system message
1307 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1309 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1311 * @param array $bar
1312 * @param string $message
1314 function addToSidebar( &$bar, $message ) {
1315 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1319 * Add content from plain text
1320 * @since 1.17
1321 * @param array $bar
1322 * @param string $text
1323 * @return array
1325 function addToSidebarPlain( &$bar, $text ) {
1326 $lines = explode( "\n", $text );
1328 $heading = '';
1330 foreach ( $lines as $line ) {
1331 if ( strpos( $line, '*' ) !== 0 ) {
1332 continue;
1334 $line = rtrim( $line, "\r" ); // for Windows compat
1336 if ( strpos( $line, '**' ) !== 0 ) {
1337 $heading = trim( $line, '* ' );
1338 if ( !array_key_exists( $heading, $bar ) ) {
1339 $bar[$heading] = array();
1341 } else {
1342 $line = trim( $line, '* ' );
1344 if ( strpos( $line, '|' ) !== false ) { // sanity check
1345 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1346 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1347 if ( count( $line ) !== 2 ) {
1348 // Second sanity check, could be hit by people doing
1349 // funky stuff with parserfuncs... (bug 33321)
1350 continue;
1353 $extraAttribs = array();
1355 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1356 if ( $msgLink->exists() ) {
1357 $link = $msgLink->text();
1358 if ( $link == '-' ) {
1359 continue;
1361 } else {
1362 $link = $line[0];
1364 $msgText = $this->msg( $line[1] );
1365 if ( $msgText->exists() ) {
1366 $text = $msgText->text();
1367 } else {
1368 $text = $line[1];
1371 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1372 $href = $link;
1374 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1375 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1376 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1377 $extraAttribs['rel'] = 'nofollow';
1380 global $wgExternalLinkTarget;
1381 if ( $wgExternalLinkTarget ) {
1382 $extraAttribs['target'] = $wgExternalLinkTarget;
1384 } else {
1385 $title = Title::newFromText( $link );
1387 if ( $title ) {
1388 $title = $title->fixSpecialName();
1389 $href = $title->getLinkURL();
1390 } else {
1391 $href = 'INVALID-TITLE';
1395 $bar[$heading][] = array_merge( array(
1396 'text' => $text,
1397 'href' => $href,
1398 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1399 'active' => false
1400 ), $extraAttribs );
1401 } else {
1402 continue;
1407 return $bar;
1411 * This function previously controlled whether the 'mediawiki.legacy.wikiprintable' module
1412 * should be loaded by OutputPage. That module no longer exists and the return value of this
1413 * method is ignored.
1415 * If your skin doesn't provide its own print styles, the 'mediawiki.legacy.commonPrint' module
1416 * can be used instead (SkinTemplate-based skins do it automatically).
1418 * @deprecated since 1.22
1419 * @return bool
1421 public function commonPrintStylesheet() {
1422 wfDeprecated( __METHOD__, '1.22' );
1423 return false;
1427 * Gets new talk page messages for the current user and returns an
1428 * appropriate alert message (or an empty string if there are no messages)
1429 * @return string
1431 function getNewtalks() {
1433 $newMessagesAlert = '';
1434 $user = $this->getUser();
1435 $newtalks = $user->getNewMessageLinks();
1436 $out = $this->getOutput();
1438 // Allow extensions to disable or modify the new messages alert
1439 if ( !wfRunHooks( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) {
1440 return '';
1442 if ( $newMessagesAlert ) {
1443 return $newMessagesAlert;
1446 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1447 $uTalkTitle = $user->getTalkPage();
1448 $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
1449 $nofAuthors = 0;
1450 if ( $lastSeenRev !== null ) {
1451 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1452 $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
1453 if ( $latestRev !== null ) {
1454 // Singular if only 1 unseen revision, plural if several unseen revisions.
1455 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1456 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1457 $lastSeenRev, $latestRev, 10, 'include_new' );
1459 } else {
1460 // Singular if no revision -> diff link will show latest change only in any case
1461 $plural = false;
1463 $plural = $plural ? 999 : 1;
1464 // 999 signifies "more than one revision". We don't know how many, and even if we did,
1465 // the number of revisions or authors is not necessarily the same as the number of
1466 // "messages".
1467 $newMessagesLink = Linker::linkKnown(
1468 $uTalkTitle,
1469 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1470 array(),
1471 array( 'redirect' => 'no' )
1474 $newMessagesDiffLink = Linker::linkKnown(
1475 $uTalkTitle,
1476 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1477 array(),
1478 $lastSeenRev !== null
1479 ? array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1480 : array( 'diff' => 'cur' )
1483 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1484 $newMessagesAlert = $this->msg(
1485 'youhavenewmessagesfromusers',
1486 $newMessagesLink,
1487 $newMessagesDiffLink
1488 )->numParams( $nofAuthors, $plural );
1489 } else {
1490 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1491 $newMessagesAlert = $this->msg(
1492 $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1493 $newMessagesLink,
1494 $newMessagesDiffLink
1495 )->numParams( $plural );
1497 $newMessagesAlert = $newMessagesAlert->text();
1498 # Disable Squid cache
1499 $out->setSquidMaxage( 0 );
1500 } elseif ( count( $newtalks ) ) {
1501 $sep = $this->msg( 'newtalkseparator' )->escaped();
1502 $msgs = array();
1504 foreach ( $newtalks as $newtalk ) {
1505 $msgs[] = Xml::element(
1506 'a',
1507 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1510 $parts = implode( $sep, $msgs );
1511 $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1512 $out->setSquidMaxage( 0 );
1515 return $newMessagesAlert;
1519 * Get a cached notice
1521 * @param string $name Message name, or 'default' for $wgSiteNotice
1522 * @return string HTML fragment
1524 private function getCachedNotice( $name ) {
1525 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1527 wfProfileIn( __METHOD__ );
1529 $needParse = false;
1531 if ( $name === 'default' ) {
1532 // special case
1533 global $wgSiteNotice;
1534 $notice = $wgSiteNotice;
1535 if ( empty( $notice ) ) {
1536 wfProfileOut( __METHOD__ );
1537 return false;
1539 } else {
1540 $msg = $this->msg( $name )->inContentLanguage();
1541 if ( $msg->isDisabled() ) {
1542 wfProfileOut( __METHOD__ );
1543 return false;
1545 $notice = $msg->plain();
1548 // Use the extra hash appender to let eg SSL variants separately cache.
1549 $key = wfMemcKey( $name . $wgRenderHashAppend );
1550 $cachedNotice = $parserMemc->get( $key );
1551 if ( is_array( $cachedNotice ) ) {
1552 if ( md5( $notice ) == $cachedNotice['hash'] ) {
1553 $notice = $cachedNotice['html'];
1554 } else {
1555 $needParse = true;
1557 } else {
1558 $needParse = true;
1561 if ( $needParse ) {
1562 $parsed = $this->getOutput()->parse( $notice );
1563 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1564 $notice = $parsed;
1567 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1568 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1569 wfProfileOut( __METHOD__ );
1570 return $notice;
1574 * Get a notice based on page's namespace
1576 * @return string HTML fragment
1578 function getNamespaceNotice() {
1579 wfProfileIn( __METHOD__ );
1581 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1582 $namespaceNotice = $this->getCachedNotice( $key );
1583 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1584 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1585 } else {
1586 $namespaceNotice = '';
1589 wfProfileOut( __METHOD__ );
1590 return $namespaceNotice;
1594 * Get the site notice
1596 * @return string HTML fragment
1598 function getSiteNotice() {
1599 wfProfileIn( __METHOD__ );
1600 $siteNotice = '';
1602 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1603 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1604 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1605 } else {
1606 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1607 if ( !$anonNotice ) {
1608 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1609 } else {
1610 $siteNotice = $anonNotice;
1613 if ( !$siteNotice ) {
1614 $siteNotice = $this->getCachedNotice( 'default' );
1618 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1619 wfProfileOut( __METHOD__ );
1620 return $siteNotice;
1624 * Create a section edit link. This supersedes editSectionLink() and
1625 * editSectionLinkForOther().
1627 * @param Title $nt The title being linked to (may not be the same as
1628 * the current page, if the section is included from a template)
1629 * @param string $section The designation of the section being pointed to,
1630 * to be included in the link, like "&section=$section"
1631 * @param string $tooltip The tooltip to use for the link: will be escaped
1632 * and wrapped in the 'editsectionhint' message
1633 * @param string $lang Language code
1634 * @return string HTML to use for edit link
1636 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1637 // HTML generated here should probably have userlangattributes
1638 // added to it for LTR text on RTL pages
1640 $lang = wfGetLangObj( $lang );
1642 $attribs = array();
1643 if ( !is_null( $tooltip ) ) {
1644 # Bug 25462: undo double-escaping.
1645 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1646 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1647 ->inLanguage( $lang )->text();
1649 $link = Linker::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(),
1650 $attribs,
1651 array( 'action' => 'edit', 'section' => $section ),
1652 array( 'noclasses', 'known' )
1655 # Add the brackets and the span and run the hook.
1656 $result = '<span class="mw-editsection">'
1657 . '<span class="mw-editsection-bracket">[</span>'
1658 . $link
1659 . '<span class="mw-editsection-bracket">]</span>'
1660 . '</span>';
1662 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1663 return $result;
1667 * Use PHP's magic __call handler to intercept legacy calls to the linker
1668 * for backwards compatibility.
1670 * @param string $fname Name of called method
1671 * @param array $args Arguments to the method
1672 * @throws MWException
1673 * @return mixed
1675 function __call( $fname, $args ) {
1676 $realFunction = array( 'Linker', $fname );
1677 if ( is_callable( $realFunction ) ) {
1678 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1679 return call_user_func_array( $realFunction, $args );
1680 } else {
1681 $className = get_class( $this );
1682 throw new MWException( "Call to undefined method $className::$fname" );