Merge "Enable $wgVectorUseIconWatch by default."
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2 /**
3 * Base class for all skins.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22
23 /**
24 * @defgroup Skins Skins
25 */
26
27 /**
28 * The main skin class that provide methods and properties for all other skins.
29 * This base class is also the "Standard" skin.
30 *
31 * See docs/skin.txt for more information.
32 *
33 * @ingroup Skins
34 */
35 abstract class Skin extends ContextSource {
36 protected $skinname = 'standard';
37 protected $mRelevantTitle = null;
38 protected $mRelevantUser = null;
39
40 /**
41 * Fetch the set of available skins.
42 * @return array associative array of strings
43 */
44 static function getSkinNames() {
45 global $wgValidSkinNames;
46 static $skinsInitialised = false;
47
48 if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) {
49 # Get a list of available skins
50 # Build using the regular expression '^(.*).php$'
51 # Array keys are all lower case, array value keep the case used by filename
52 #
53 wfProfileIn( __METHOD__ . '-init' );
54
55 global $wgStyleDirectory;
56
57 $skinDir = dir( $wgStyleDirectory );
58
59 if ( $skinDir !== false && $skinDir !== null ) {
60 # while code from www.php.net
61 while ( false !== ( $file = $skinDir->read() ) ) {
62 // Skip non-PHP files, hidden files, and '.dep' includes
63 $matches = array();
64
65 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
66 $aSkin = $matches[1];
67 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
68 }
69 }
70 $skinDir->close();
71 }
72 $skinsInitialised = true;
73 wfProfileOut( __METHOD__ . '-init' );
74 }
75 return $wgValidSkinNames;
76 }
77
78 /**
79 * Fetch the skinname messages for available skins.
80 * @return array of strings
81 */
82 static function getSkinNameMessages() {
83 $messages = array();
84 foreach( self::getSkinNames() as $skinKey => $skinName ) {
85 $messages[] = "skinname-$skinKey";
86 }
87 return $messages;
88 }
89
90 /**
91 * Fetch the list of usable skins in regards to $wgSkipSkins.
92 * Useful for Special:Preferences and other places where you
93 * only want to show skins users _can_ use.
94 * @return array of strings
95 */
96 public static function getUsableSkins() {
97 global $wgSkipSkins;
98
99 $usableSkins = self::getSkinNames();
100
101 foreach ( $wgSkipSkins as $skip ) {
102 unset( $usableSkins[$skip] );
103 }
104
105 return $usableSkins;
106 }
107
108 /**
109 * Normalize a skin preference value to a form that can be loaded.
110 * If a skin can't be found, it will fall back to the configured
111 * default (or the old 'Classic' skin if that's broken).
112 * @param string $key 'monobook', 'standard', etc.
113 * @return string
114 */
115 static function normalizeKey( $key ) {
116 global $wgDefaultSkin;
117
118 $skinNames = Skin::getSkinNames();
119
120 if ( $key == '' || $key == 'default' ) {
121 // Don't return the default immediately;
122 // in a misconfiguration we need to fall back.
123 $key = $wgDefaultSkin;
124 }
125
126 if ( isset( $skinNames[$key] ) ) {
127 return $key;
128 }
129
130 // Older versions of the software used a numeric setting
131 // in the user preferences.
132 $fallback = array(
133 0 => $wgDefaultSkin,
134 1 => 'nostalgia',
135 2 => 'cologneblue'
136 );
137
138 if ( isset( $fallback[$key] ) ) {
139 $key = $fallback[$key];
140 }
141
142 if ( isset( $skinNames[$key] ) ) {
143 return $key;
144 } elseif ( isset( $skinNames[$wgDefaultSkin] ) ) {
145 return $wgDefaultSkin;
146 } else {
147 return 'vector';
148 }
149 }
150
151 /**
152 * Factory method for loading a skin of a given type
153 * @param string $key 'monobook', 'standard', etc.
154 * @return Skin
155 */
156 static function &newFromKey( $key ) {
157 global $wgStyleDirectory;
158
159 $key = Skin::normalizeKey( $key );
160
161 $skinNames = Skin::getSkinNames();
162 $skinName = $skinNames[$key];
163 $className = "Skin{$skinName}";
164
165 # Grab the skin class and initialise it.
166 if ( !MWInit::classExists( $className ) ) {
167
168 if ( !defined( 'MW_COMPILED' ) ) {
169 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
170 }
171
172 # Check if we got if not fallback to default skin
173 if ( !MWInit::classExists( $className ) ) {
174 # DO NOT die if the class isn't found. This breaks maintenance
175 # scripts and can cause a user account to be unrecoverable
176 # except by SQL manipulation if a previously valid skin name
177 # is no longer valid.
178 wfDebug( "Skin class does not exist: $className\n" );
179 $className = 'SkinVector';
180 if ( !defined( 'MW_COMPILED' ) ) {
181 require_once( "{$wgStyleDirectory}/Vector.php" );
182 }
183 }
184 }
185 $skin = new $className( $key );
186 return $skin;
187 }
188
189 /** @return string skin name */
190 public function getSkinName() {
191 return $this->skinname;
192 }
193
194 /**
195 * @param $out OutputPage
196 */
197 function initPage( OutputPage $out ) {
198 wfProfileIn( __METHOD__ );
199
200 $this->preloadExistence();
201
202 wfProfileOut( __METHOD__ );
203 }
204
205 /**
206 * Preload the existence of three commonly-requested pages in a single query
207 */
208 function preloadExistence() {
209 $user = $this->getUser();
210
211 // User/talk link
212 $titles = array( $user->getUserPage(), $user->getTalkPage() );
213
214 // Other tab link
215 if ( $this->getTitle()->isSpecialPage() ) {
216 // nothing
217 } elseif ( $this->getTitle()->isTalkPage() ) {
218 $titles[] = $this->getTitle()->getSubjectPage();
219 } else {
220 $titles[] = $this->getTitle()->getTalkPage();
221 }
222
223 $lb = new LinkBatch( $titles );
224 $lb->setCaller( __METHOD__ );
225 $lb->execute();
226 }
227
228 /**
229 * Get the current revision ID
230 *
231 * @return Integer
232 */
233 public function getRevisionId() {
234 return $this->getOutput()->getRevisionId();
235 }
236
237 /**
238 * Whether the revision displayed is the latest revision of the page
239 *
240 * @return Boolean
241 */
242 public function isRevisionCurrent() {
243 $revID = $this->getRevisionId();
244 return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
245 }
246
247 /**
248 * Set the "relevant" title
249 * @see self::getRelevantTitle()
250 * @param $t Title object to use
251 */
252 public function setRelevantTitle( $t ) {
253 $this->mRelevantTitle = $t;
254 }
255
256 /**
257 * Return the "relevant" title.
258 * A "relevant" title is not necessarily the actual title of the page.
259 * Special pages like Special:MovePage use set the page they are acting on
260 * as their "relevant" title, this allows the skin system to display things
261 * such as content tabs which belong to to that page instead of displaying
262 * a basic special page tab which has almost no meaning.
263 *
264 * @return Title
265 */
266 public function getRelevantTitle() {
267 if ( isset( $this->mRelevantTitle ) ) {
268 return $this->mRelevantTitle;
269 }
270 return $this->getTitle();
271 }
272
273 /**
274 * Set the "relevant" user
275 * @see self::getRelevantUser()
276 * @param $u User object to use
277 */
278 public function setRelevantUser( $u ) {
279 $this->mRelevantUser = $u;
280 }
281
282 /**
283 * Return the "relevant" user.
284 * A "relevant" user is similar to a relevant title. Special pages like
285 * Special:Contributions mark the user which they are relevant to so that
286 * things like the toolbox can display the information they usually are only
287 * able to display on a user's userpage and talkpage.
288 * @return User
289 */
290 public function getRelevantUser() {
291 if ( isset( $this->mRelevantUser ) ) {
292 return $this->mRelevantUser;
293 }
294 $title = $this->getRelevantTitle();
295 if( $title->hasSubjectNamespace( NS_USER ) ) {
296 $rootUser = $title->getRootText();
297 if ( User::isIP( $rootUser ) ) {
298 $this->mRelevantUser = User::newFromName( $rootUser, false );
299 } else {
300 $user = User::newFromName( $rootUser, false );
301 if ( $user && $user->isLoggedIn() ) {
302 $this->mRelevantUser = $user;
303 }
304 }
305 return $this->mRelevantUser;
306 }
307 return null;
308 }
309
310 /**
311 * Outputs the HTML generated by other functions.
312 * @param $out OutputPage
313 */
314 abstract function outputPage( OutputPage $out = null );
315
316 /**
317 * @param $data array
318 * @return string
319 */
320 static function makeVariablesScript( $data ) {
321 if ( $data ) {
322 return Html::inlineScript(
323 ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) )
324 );
325 } else {
326 return '';
327 }
328 }
329
330 /**
331 * Make a "<script>" tag containing global variables
332 *
333 * @deprecated in 1.19
334 * @param $unused
335 * @return string HTML fragment
336 */
337 public static function makeGlobalVariablesScript( $unused ) {
338 global $wgOut;
339
340 wfDeprecated( __METHOD__, '1.19' );
341
342 return self::makeVariablesScript( $wgOut->getJSVars() );
343 }
344
345 /**
346 * Get the query to generate a dynamic stylesheet
347 *
348 * @return array
349 */
350 public static function getDynamicStylesheetQuery() {
351 global $wgSquidMaxage;
352
353 return array(
354 'action' => 'raw',
355 'maxage' => $wgSquidMaxage,
356 'usemsgcache' => 'yes',
357 'ctype' => 'text/css',
358 'smaxage' => $wgSquidMaxage,
359 );
360 }
361
362 /**
363 * Add skin specific stylesheets
364 * Calling this method with an $out of anything but the same OutputPage
365 * inside ->getOutput() is deprecated. The $out arg is kept
366 * for compatibility purposes with skins.
367 * @param $out OutputPage
368 * @todo delete
369 */
370 abstract function setupSkinUserCss( OutputPage $out );
371
372 /**
373 * TODO: document
374 * @param $title Title
375 * @return String
376 */
377 function getPageClasses( $title ) {
378 $numeric = 'ns-' . $title->getNamespace();
379
380 if ( $title->isSpecialPage() ) {
381 $type = 'ns-special';
382 // bug 23315: provide a class based on the canonical special page name without subpages
383 list( $canonicalName ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
384 if ( $canonicalName ) {
385 $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
386 } else {
387 $type .= ' mw-invalidspecialpage';
388 }
389 } elseif ( $title->isTalkPage() ) {
390 $type = 'ns-talk';
391 } else {
392 $type = 'ns-subject';
393 }
394
395 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
396
397 return "$numeric $type $name";
398 }
399
400 /**
401 * This will be called by OutputPage::headElement when it is creating the
402 * "<body>" tag, skins can override it if they have a need to add in any
403 * body attributes or classes of their own.
404 * @param $out OutputPage
405 * @param $bodyAttrs Array
406 */
407 function addToBodyAttributes( $out, &$bodyAttrs ) {
408 // does nothing by default
409 }
410
411 /**
412 * URL to the logo
413 * @return String
414 */
415 function getLogo() {
416 global $wgLogo;
417 return $wgLogo;
418 }
419
420 /**
421 * @return string
422 */
423 function getCategoryLinks() {
424 global $wgUseCategoryBrowser;
425
426 $out = $this->getOutput();
427 $allCats = $out->getCategoryLinks();
428
429 if ( !count( $allCats ) ) {
430 return '';
431 }
432
433 $embed = "<li>";
434 $pop = "</li>";
435
436 $s = '';
437 $colon = $this->msg( 'colon-separator' )->escaped();
438
439 if ( !empty( $allCats['normal'] ) ) {
440 $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
441
442 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
443 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
444 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
445 Linker::link( Title::newFromText( $linkPage ), $msg )
446 . $colon . '<ul>' . $t . '</ul>' . '</div>';
447 }
448
449 # Hidden categories
450 if ( isset( $allCats['hidden'] ) ) {
451 if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
452 $class = ' mw-hidden-cats-user-shown';
453 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
454 $class = ' mw-hidden-cats-ns-shown';
455 } else {
456 $class = ' mw-hidden-cats-hidden';
457 }
458
459 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
460 $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
461 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
462 '</div>';
463 }
464
465 # optional 'dmoz-like' category browser. Will be shown under the list
466 # of categories an article belong to
467 if ( $wgUseCategoryBrowser ) {
468 $s .= '<br /><hr />';
469
470 # get a big array of the parents tree
471 $parenttree = $this->getTitle()->getParentCategoryTree();
472 # Skin object passed by reference cause it can not be
473 # accessed under the method subfunction drawCategoryBrowser
474 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
475 # Clean out bogus first entry and sort them
476 unset( $tempout[0] );
477 asort( $tempout );
478 # Output one per line
479 $s .= implode( "<br />\n", $tempout );
480 }
481
482 return $s;
483 }
484
485 /**
486 * Render the array as a series of links.
487 * @param array $tree categories tree returned by Title::getParentCategoryTree
488 * @return String separated by &gt;, terminate with "\n"
489 */
490 function drawCategoryBrowser( $tree ) {
491 $return = '';
492
493 foreach ( $tree as $element => $parent ) {
494 if ( empty( $parent ) ) {
495 # element start a new list
496 $return .= "\n";
497 } else {
498 # grab the others elements
499 $return .= $this->drawCategoryBrowser( $parent ) . ' &gt; ';
500 }
501
502 # add our current element to the list
503 $eltitle = Title::newFromText( $element );
504 $return .= Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
505 }
506
507 return $return;
508 }
509
510 /**
511 * @return string
512 */
513 function getCategories() {
514 $out = $this->getOutput();
515
516 $catlinks = $this->getCategoryLinks();
517
518 $classes = 'catlinks';
519
520 // Check what we're showing
521 $allCats = $out->getCategoryLinks();
522 $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
523 $this->getTitle()->getNamespace() == NS_CATEGORY;
524
525 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
526 $classes .= ' catlinks-allhidden';
527 }
528
529 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
530 }
531
532 /**
533 * This runs a hook to allow extensions placing their stuff after content
534 * and article metadata (e.g. categories).
535 * Note: This function has nothing to do with afterContent().
536 *
537 * This hook is placed here in order to allow using the same hook for all
538 * skins, both the SkinTemplate based ones and the older ones, which directly
539 * use this class to get their data.
540 *
541 * The output of this function gets processed in SkinTemplate::outputPage() for
542 * the SkinTemplate based skins, all other skins should directly echo it.
543 *
544 * @return String, empty by default, if not changed by any hook function.
545 */
546 protected function afterContentHook() {
547 $data = '';
548
549 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
550 // adding just some spaces shouldn't toggle the output
551 // of the whole <div/>, so we use trim() here
552 if ( trim( $data ) != '' ) {
553 // Doing this here instead of in the skins to
554 // ensure that the div has the same ID in all
555 // skins
556 $data = "<div id='mw-data-after-content'>\n" .
557 "\t$data\n" .
558 "</div>\n";
559 }
560 } else {
561 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
562 }
563
564 return $data;
565 }
566
567 /**
568 * Generate debug data HTML for displaying at the bottom of the main content
569 * area.
570 * @return String HTML containing debug data, if enabled (otherwise empty).
571 */
572 protected function generateDebugHTML() {
573 return MWDebug::getHTMLDebugLog();
574 }
575
576 /**
577 * This gets called shortly before the "</body>" tag.
578 *
579 * @return String HTML-wrapped JS code to be put before "</body>"
580 */
581 function bottomScripts() {
582 // TODO and the suckage continues. This function is really just a wrapper around
583 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
584 // up at some point
585 $bottomScriptText = $this->getOutput()->getBottomScripts();
586 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
587
588 return $bottomScriptText;
589 }
590
591 /**
592 * Text with the permalink to the source page,
593 * usually shown on the footer of a printed page
594 *
595 * @return string HTML text with an URL
596 */
597 function printSource() {
598 $oldid = $this->getRevisionId();
599 if ( $oldid ) {
600 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
601 } else {
602 // oldid not available for non existing pages
603 $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
604 }
605 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
606 }
607
608 /**
609 * @return String
610 */
611 function getUndeleteLink() {
612 $action = $this->getRequest()->getVal( 'action', 'view' );
613
614 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
615 ( $this->getTitle()->getArticleID() == 0 || $action == 'history' ) ) {
616 $n = $this->getTitle()->isDeleted();
617
618 if ( $n ) {
619 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
620 $msg = 'thisisdeleted';
621 } else {
622 $msg = 'viewdeleted';
623 }
624
625 return $this->msg( $msg )->rawParams(
626 Linker::linkKnown(
627 SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
628 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
629 )->text();
630 }
631 }
632
633 return '';
634 }
635
636 /**
637 * @return string
638 */
639 function subPageSubtitle() {
640 global $wgLang;
641 $out = $this->getOutput();
642 $subpages = '';
643
644 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
645 return $subpages;
646 }
647
648 if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
649 $ptext = $this->getTitle()->getPrefixedText();
650 if ( preg_match( '/\//', $ptext ) ) {
651 $links = explode( '/', $ptext );
652 array_pop( $links );
653 $c = 0;
654 $growinglink = '';
655 $display = '';
656
657 foreach ( $links as $link ) {
658 $growinglink .= $link;
659 $display .= $link;
660 $linkObj = Title::newFromText( $growinglink );
661
662 if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
663 $getlink = Linker::linkKnown(
664 $linkObj,
665 htmlspecialchars( $display )
666 );
667
668 $c++;
669
670 if ( $c > 1 ) {
671 $subpages .= $wgLang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
672 } else {
673 $subpages .= '&lt; ';
674 }
675
676 $subpages .= $getlink;
677 $display = '';
678 } else {
679 $display .= '/';
680 }
681 $growinglink .= '/';
682 }
683 }
684 }
685
686 return $subpages;
687 }
688
689 /**
690 * Returns true if the IP should be shown in the header
691 * @return Bool
692 */
693 function showIPinHeader() {
694 global $wgShowIPinHeader;
695 return $wgShowIPinHeader && session_id() != '';
696 }
697
698 /**
699 * @return String
700 */
701 function getSearchLink() {
702 $searchPage = SpecialPage::getTitleFor( 'Search' );
703 return $searchPage->getLocalURL();
704 }
705
706 /**
707 * @return string
708 */
709 function escapeSearchLink() {
710 return htmlspecialchars( $this->getSearchLink() );
711 }
712
713 /**
714 * @param $type string
715 * @return string
716 */
717 function getCopyright( $type = 'detect' ) {
718 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
719
720 if ( $type == 'detect' ) {
721 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
722 $type = 'history';
723 } else {
724 $type = 'normal';
725 }
726 }
727
728 if ( $type == 'history' ) {
729 $msg = 'history_copyright';
730 } else {
731 $msg = 'copyright';
732 }
733
734 if ( $wgRightsPage ) {
735 $title = Title::newFromText( $wgRightsPage );
736 $link = Linker::linkKnown( $title, $wgRightsText );
737 } elseif ( $wgRightsUrl ) {
738 $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
739 } elseif ( $wgRightsText ) {
740 $link = $wgRightsText;
741 } else {
742 # Give up now
743 return '';
744 }
745
746 // Allow for site and per-namespace customization of copyright notice.
747 $forContent = true;
748
749 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
750
751 $msgObj = $this->msg( $msg )->rawParams( $link );
752 if ( $forContent ) {
753 $msg = $msgObj->inContentLanguage()->text();
754 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
755 $msg = Html::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
756 }
757 return $msg;
758 } else {
759 return $msgObj->text();
760 }
761 }
762
763 /**
764 * @return null|string
765 */
766 function getCopyrightIcon() {
767 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
768
769 $out = '';
770
771 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
772 $out = $wgCopyrightIcon;
773 } elseif ( $wgRightsIcon ) {
774 $icon = htmlspecialchars( $wgRightsIcon );
775
776 if ( $wgRightsUrl ) {
777 $url = htmlspecialchars( $wgRightsUrl );
778 $out .= '<a href="' . $url . '">';
779 }
780
781 $text = htmlspecialchars( $wgRightsText );
782 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
783
784 if ( $wgRightsUrl ) {
785 $out .= '</a>';
786 }
787 }
788
789 return $out;
790 }
791
792 /**
793 * Gets the powered by MediaWiki icon.
794 * @return string
795 */
796 function getPoweredBy() {
797 global $wgStylePath;
798
799 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
800 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
801 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
802 return $text;
803 }
804
805 /**
806 * Get the timestamp of the latest revision, formatted in user language
807 *
808 * @return String
809 */
810 protected function lastModified() {
811 $timestamp = $this->getOutput()->getRevisionTimestamp();
812
813 # No cached timestamp, load it from the database
814 if ( $timestamp === null ) {
815 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
816 }
817
818 if ( $timestamp ) {
819 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
820 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
821 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
822 } else {
823 $s = '';
824 }
825
826 if ( wfGetLB()->getLaggedSlaveMode() ) {
827 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
828 }
829
830 return $s;
831 }
832
833 /**
834 * @param $align string
835 * @return string
836 */
837 function logoText( $align = '' ) {
838 if ( $align != '' ) {
839 $a = " style='float: {$align};'";
840 } else {
841 $a = '';
842 }
843
844 $mp = $this->msg( 'mainpage' )->escaped();
845 $mptitle = Title::newMainPage();
846 $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
847
848 $logourl = $this->getLogo();
849 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
850
851 return $s;
852 }
853
854 /**
855 * Renders a $wgFooterIcons icon according to the method's arguments
856 * @param array $icon The icon to build the html for, see $wgFooterIcons for the format of this array
857 * @param bool|String $withImage Whether to use the icon's image or output a text-only footericon
858 * @return String HTML
859 */
860 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
861 if ( is_string( $icon ) ) {
862 $html = $icon;
863 } else { // Assuming array
864 $url = isset( $icon["url"] ) ? $icon["url"] : null;
865 unset( $icon["url"] );
866 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
867 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
868 } else {
869 $html = htmlspecialchars( $icon["alt"] );
870 }
871 if ( $url ) {
872 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
873 }
874 }
875 return $html;
876 }
877
878 /**
879 * Gets the link to the wiki's main page.
880 * @return string
881 */
882 function mainPageLink() {
883 $s = Linker::linkKnown(
884 Title::newMainPage(),
885 $this->msg( 'mainpage' )->escaped()
886 );
887
888 return $s;
889 }
890
891 /**
892 * @param $desc
893 * @param $page
894 * @return string
895 */
896 public function footerLink( $desc, $page ) {
897 // if the link description has been set to "-" in the default language,
898 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
899 // then it is disabled, for all languages.
900 return '';
901 } else {
902 // Otherwise, we display the link for the user, described in their
903 // language (which may or may not be the same as the default language),
904 // but we make the link target be the one site-wide page.
905 $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
906
907 return Linker::linkKnown(
908 $title,
909 $this->msg( $desc )->escaped()
910 );
911 }
912 }
913
914 /**
915 * Gets the link to the wiki's privacy policy page.
916 * @return String HTML
917 */
918 function privacyLink() {
919 return $this->footerLink( 'privacy', 'privacypage' );
920 }
921
922 /**
923 * Gets the link to the wiki's about page.
924 * @return String HTML
925 */
926 function aboutLink() {
927 return $this->footerLink( 'aboutsite', 'aboutpage' );
928 }
929
930 /**
931 * Gets the link to the wiki's general disclaimers page.
932 * @return String HTML
933 */
934 function disclaimerLink() {
935 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
936 }
937
938 /**
939 * Return URL options for the 'edit page' link.
940 * This may include an 'oldid' specifier, if the current page view is such.
941 *
942 * @return array
943 * @private
944 */
945 function editUrlOptions() {
946 $options = array( 'action' => 'edit' );
947
948 if ( !$this->isRevisionCurrent() ) {
949 $options['oldid'] = intval( $this->getRevisionId() );
950 }
951
952 return $options;
953 }
954
955 /**
956 * @param $id User|int
957 * @return bool
958 */
959 function showEmailUser( $id ) {
960 if ( $id instanceof User ) {
961 $targetUser = $id;
962 } else {
963 $targetUser = User::newFromId( $id );
964 }
965 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
966 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
967 }
968
969 /**
970 * Return a fully resolved style path url to images or styles stored in the common folder.
971 * This method returns a url resolved using the configured skin style path
972 * and includes the style version inside of the url.
973 * @param string $name The name or path of a skin resource file
974 * @return String The fully resolved style path url including styleversion
975 */
976 function getCommonStylePath( $name ) {
977 global $wgStylePath, $wgStyleVersion;
978 return "$wgStylePath/common/$name?$wgStyleVersion";
979 }
980
981 /**
982 * Return a fully resolved style path url to images or styles stored in the current skins's folder.
983 * This method returns a url resolved using the configured skin style path
984 * and includes the style version inside of the url.
985 * @param string $name The name or path of a skin resource file
986 * @return String The fully resolved style path url including styleversion
987 */
988 function getSkinStylePath( $name ) {
989 global $wgStylePath, $wgStyleVersion;
990 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
991 }
992
993 /* these are used extensively in SkinTemplate, but also some other places */
994
995 /**
996 * @param $urlaction string
997 * @return String
998 */
999 static function makeMainPageUrl( $urlaction = '' ) {
1000 $title = Title::newMainPage();
1001 self::checkTitle( $title, '' );
1002
1003 return $title->getLocalURL( $urlaction );
1004 }
1005
1006 /**
1007 * Make a URL for a Special Page using the given query and protocol.
1008 *
1009 * If $proto is set to null, make a local URL. Otherwise, make a full
1010 * URL with the protocol specified.
1011 *
1012 * @param string $name Name of the Special page
1013 * @param string $urlaction Query to append
1014 * @param $proto Protocol to use or null for a local URL
1015 * @return String
1016 */
1017 static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1018 $title = SpecialPage::getSafeTitleFor( $name );
1019 if( is_null( $proto ) ) {
1020 return $title->getLocalURL( $urlaction );
1021 } else {
1022 return $title->getFullURL( $urlaction, false, $proto );
1023 }
1024 }
1025
1026 /**
1027 * @param $name string
1028 * @param $subpage string
1029 * @param $urlaction string
1030 * @return String
1031 */
1032 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1033 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1034 return $title->getLocalURL( $urlaction );
1035 }
1036
1037 /**
1038 * @param $name string
1039 * @param $urlaction string
1040 * @return String
1041 */
1042 static function makeI18nUrl( $name, $urlaction = '' ) {
1043 $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1044 self::checkTitle( $title, $name );
1045 return $title->getLocalURL( $urlaction );
1046 }
1047
1048 /**
1049 * @param $name string
1050 * @param $urlaction string
1051 * @return String
1052 */
1053 static function makeUrl( $name, $urlaction = '' ) {
1054 $title = Title::newFromText( $name );
1055 self::checkTitle( $title, $name );
1056
1057 return $title->getLocalURL( $urlaction );
1058 }
1059
1060 /**
1061 * If url string starts with http, consider as external URL, else
1062 * internal
1063 * @param $name String
1064 * @return String URL
1065 */
1066 static function makeInternalOrExternalUrl( $name ) {
1067 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1068 return $name;
1069 } else {
1070 return self::makeUrl( $name );
1071 }
1072 }
1073
1074 /**
1075 * this can be passed the NS number as defined in Language.php
1076 * @param $name
1077 * @param $urlaction string
1078 * @param $namespace int
1079 * @return String
1080 */
1081 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1082 $title = Title::makeTitleSafe( $namespace, $name );
1083 self::checkTitle( $title, $name );
1084
1085 return $title->getLocalURL( $urlaction );
1086 }
1087
1088 /**
1089 * these return an array with the 'href' and boolean 'exists'
1090 * @param $name
1091 * @param $urlaction string
1092 * @return array
1093 */
1094 static function makeUrlDetails( $name, $urlaction = '' ) {
1095 $title = Title::newFromText( $name );
1096 self::checkTitle( $title, $name );
1097
1098 return array(
1099 'href' => $title->getLocalURL( $urlaction ),
1100 'exists' => $title->getArticleID() != 0,
1101 );
1102 }
1103
1104 /**
1105 * Make URL details where the article exists (or at least it's convenient to think so)
1106 * @param string $name Article name
1107 * @param $urlaction String
1108 * @return Array
1109 */
1110 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1111 $title = Title::newFromText( $name );
1112 self::checkTitle( $title, $name );
1113
1114 return array(
1115 'href' => $title->getLocalURL( $urlaction ),
1116 'exists' => true
1117 );
1118 }
1119
1120 /**
1121 * make sure we have some title to operate on
1122 *
1123 * @param $title Title
1124 * @param $name string
1125 */
1126 static function checkTitle( &$title, $name ) {
1127 if ( !is_object( $title ) ) {
1128 $title = Title::newFromText( $name );
1129 if ( !is_object( $title ) ) {
1130 $title = Title::newFromText( '--error: link target missing--' );
1131 }
1132 }
1133 }
1134
1135 /**
1136 * Build an array that represents the sidebar(s), the navigation bar among them.
1137 *
1138 * BaseTemplate::getSidebar can be used to simplify the format and id generation in new skins.
1139 *
1140 * The format of the returned array is array( heading => content, ... ), where:
1141 * - heading is the heading of a navigation portlet. It is either:
1142 * - magic string to be handled by the skins ('SEARCH' / 'LANGUAGES' / 'TOOLBOX' / ...)
1143 * - a message name (e.g. 'navigation'), the message should be HTML-escaped by the skin
1144 * - plain text, which should be HTML-escaped by the skin
1145 * - content is the contents of the portlet. It is either:
1146 * - HTML text (<ul><li>...</li>...</ul>)
1147 * - array of link data in a format accepted by BaseTemplate::makeListItem()
1148 * - (for a magic string as a key, any value)
1149 *
1150 * Note that extensions can control the sidebar contents using the SkinBuildSidebar hook
1151 * and can technically insert anything in here; skin creators are expected to handle
1152 * values described above.
1153 *
1154 * @return array
1155 */
1156 function buildSidebar() {
1157 global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1158 wfProfileIn( __METHOD__ );
1159
1160 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1161
1162 if ( $wgEnableSidebarCache ) {
1163 $cachedsidebar = $wgMemc->get( $key );
1164 if ( $cachedsidebar ) {
1165 wfProfileOut( __METHOD__ );
1166 return $cachedsidebar;
1167 }
1168 }
1169
1170 $bar = array();
1171 $this->addToSidebar( $bar, 'sidebar' );
1172
1173 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1174 if ( $wgEnableSidebarCache ) {
1175 $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1176 }
1177
1178 wfProfileOut( __METHOD__ );
1179 return $bar;
1180 }
1181 /**
1182 * Add content from a sidebar system message
1183 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1184 *
1185 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1186 *
1187 * @param $bar array
1188 * @param $message String
1189 */
1190 function addToSidebar( &$bar, $message ) {
1191 $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
1192 }
1193
1194 /**
1195 * Add content from plain text
1196 * @since 1.17
1197 * @param $bar array
1198 * @param $text string
1199 * @return Array
1200 */
1201 function addToSidebarPlain( &$bar, $text ) {
1202 $lines = explode( "\n", $text );
1203
1204 $heading = '';
1205
1206 foreach ( $lines as $line ) {
1207 if ( strpos( $line, '*' ) !== 0 ) {
1208 continue;
1209 }
1210 $line = rtrim( $line, "\r" ); // for Windows compat
1211
1212 if ( strpos( $line, '**' ) !== 0 ) {
1213 $heading = trim( $line, '* ' );
1214 if ( !array_key_exists( $heading, $bar ) ) {
1215 $bar[$heading] = array();
1216 }
1217 } else {
1218 $line = trim( $line, '* ' );
1219
1220 if ( strpos( $line, '|' ) !== false ) { // sanity check
1221 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1222 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1223 if ( count( $line ) !== 2 ) {
1224 // Second sanity check, could be hit by people doing
1225 // funky stuff with parserfuncs... (bug 33321)
1226 continue;
1227 }
1228
1229 $extraAttribs = array();
1230
1231 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1232 if ( $msgLink->exists() ) {
1233 $link = $msgLink->text();
1234 if ( $link == '-' ) {
1235 continue;
1236 }
1237 } else {
1238 $link = $line[0];
1239 }
1240 $msgText = $this->msg( $line[1] );
1241 if ( $msgText->exists() ) {
1242 $text = $msgText->text();
1243 } else {
1244 $text = $line[1];
1245 }
1246
1247 if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1248 $href = $link;
1249
1250 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1251 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1252 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1253 $extraAttribs['rel'] = 'nofollow';
1254 }
1255
1256 global $wgExternalLinkTarget;
1257 if ( $wgExternalLinkTarget ) {
1258 $extraAttribs['target'] = $wgExternalLinkTarget;
1259 }
1260 } else {
1261 $title = Title::newFromText( $link );
1262
1263 if ( $title ) {
1264 $title = $title->fixSpecialName();
1265 $href = $title->getLinkURL();
1266 } else {
1267 $href = 'INVALID-TITLE';
1268 }
1269 }
1270
1271 $bar[$heading][] = array_merge( array(
1272 'text' => $text,
1273 'href' => $href,
1274 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1275 'active' => false
1276 ), $extraAttribs );
1277 } else {
1278 continue;
1279 }
1280 }
1281 }
1282
1283 return $bar;
1284 }
1285
1286 /**
1287 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1288 * print stylesheet should override this and return false. (This is an
1289 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1290 *
1291 * @return bool
1292 */
1293 public function commonPrintStylesheet() {
1294 return true;
1295 }
1296
1297 /**
1298 * Gets new talk page messages for the current user.
1299 * @return MediaWiki message or if no new talk page messages, nothing
1300 */
1301 function getNewtalks() {
1302 $out = $this->getOutput();
1303
1304 $newtalks = $this->getUser()->getNewMessageLinks();
1305 $ntl = '';
1306
1307 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1308 $uTalkTitle = $this->getUser()->getTalkPage();
1309
1310 if ( !$uTalkTitle->equals( $out->getTitle() ) ) {
1311 $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
1312 $nofAuthors = 0;
1313 if ( $lastSeenRev !== null ) {
1314 $plural = true; // Default if we have a last seen revision: if unknown, use plural
1315 $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
1316 if ( $latestRev !== null ) {
1317 // Singular if only 1 unseen revision, plural if several unseen revisions.
1318 $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1319 $nofAuthors = $uTalkTitle->countAuthorsBetween(
1320 $lastSeenRev, $latestRev, 10, 'include_new' );
1321 }
1322 } else {
1323 // Singular if no revision -> diff link will show latest change only in any case
1324 $plural = false;
1325 }
1326 $plural = $plural ? 2 : 1;
1327 // 2 signifies "more than one revision". We don't know how many, and even if we did,
1328 // the number of revisions or authors is not necessarily the same as the number of
1329 // "messages".
1330 $newMessagesLink = Linker::linkKnown(
1331 $uTalkTitle,
1332 $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
1333 array(),
1334 array( 'redirect' => 'no' )
1335 );
1336
1337 $newMessagesDiffLink = Linker::linkKnown(
1338 $uTalkTitle,
1339 $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
1340 array(),
1341 $lastSeenRev !== null
1342 ? array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
1343 : array( 'diff' => 'cur' )
1344 );
1345
1346 if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1347 $ntl = $this->msg(
1348 'youhavenewmessagesfromusers',
1349 $newMessagesLink,
1350 $newMessagesDiffLink
1351 )->numParams( $nofAuthors );
1352 } else {
1353 // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1354 $ntl = $this->msg(
1355 $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1356 $newMessagesLink,
1357 $newMessagesDiffLink
1358 );
1359 }
1360 $ntl = $ntl->text();
1361 # Disable Squid cache
1362 $out->setSquidMaxage( 0 );
1363 }
1364 } elseif ( count( $newtalks ) ) {
1365 // _>" " for BC <= 1.16
1366 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1367 $msgs = array();
1368
1369 foreach ( $newtalks as $newtalk ) {
1370 $msgs[] = Xml::element(
1371 'a',
1372 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1373 );
1374 }
1375 $parts = implode( $sep, $msgs );
1376 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1377 $out->setSquidMaxage( 0 );
1378 }
1379
1380 return $ntl;
1381 }
1382
1383 /**
1384 * Get a cached notice
1385 *
1386 * @param string $name message name, or 'default' for $wgSiteNotice
1387 * @return String: HTML fragment
1388 */
1389 private function getCachedNotice( $name ) {
1390 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1391
1392 wfProfileIn( __METHOD__ );
1393
1394 $needParse = false;
1395
1396 if( $name === 'default' ) {
1397 // special case
1398 global $wgSiteNotice;
1399 $notice = $wgSiteNotice;
1400 if( empty( $notice ) ) {
1401 wfProfileOut( __METHOD__ );
1402 return false;
1403 }
1404 } else {
1405 $msg = $this->msg( $name )->inContentLanguage();
1406 if( $msg->isDisabled() ) {
1407 wfProfileOut( __METHOD__ );
1408 return false;
1409 }
1410 $notice = $msg->plain();
1411 }
1412
1413 // Use the extra hash appender to let eg SSL variants separately cache.
1414 $key = wfMemcKey( $name . $wgRenderHashAppend );
1415 $cachedNotice = $parserMemc->get( $key );
1416 if( is_array( $cachedNotice ) ) {
1417 if( md5( $notice ) == $cachedNotice['hash'] ) {
1418 $notice = $cachedNotice['html'];
1419 } else {
1420 $needParse = true;
1421 }
1422 } else {
1423 $needParse = true;
1424 }
1425
1426 if ( $needParse ) {
1427 $parsed = $this->getOutput()->parse( $notice );
1428 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1429 $notice = $parsed;
1430 }
1431
1432 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1433 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
1434 wfProfileOut( __METHOD__ );
1435 return $notice;
1436 }
1437
1438 /**
1439 * Get a notice based on page's namespace
1440 *
1441 * @return String: HTML fragment
1442 */
1443 function getNamespaceNotice() {
1444 wfProfileIn( __METHOD__ );
1445
1446 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1447 $namespaceNotice = $this->getCachedNotice( $key );
1448 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1449 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1450 } else {
1451 $namespaceNotice = '';
1452 }
1453
1454 wfProfileOut( __METHOD__ );
1455 return $namespaceNotice;
1456 }
1457
1458 /**
1459 * Get the site notice
1460 *
1461 * @return String: HTML fragment
1462 */
1463 function getSiteNotice() {
1464 wfProfileIn( __METHOD__ );
1465 $siteNotice = '';
1466
1467 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1468 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1469 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1470 } else {
1471 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1472 if ( !$anonNotice ) {
1473 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1474 } else {
1475 $siteNotice = $anonNotice;
1476 }
1477 }
1478 if ( !$siteNotice ) {
1479 $siteNotice = $this->getCachedNotice( 'default' );
1480 }
1481 }
1482
1483 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1484 wfProfileOut( __METHOD__ );
1485 return $siteNotice;
1486 }
1487
1488 /**
1489 * Create a section edit link. This supersedes editSectionLink() and
1490 * editSectionLinkForOther().
1491 *
1492 * @param $nt Title The title being linked to (may not be the same as
1493 * $wgTitle, if the section is included from a template)
1494 * @param string $section The designation of the section being pointed to,
1495 * to be included in the link, like "&section=$section"
1496 * @param string $tooltip The tooltip to use for the link: will be escaped
1497 * and wrapped in the 'editsectionhint' message
1498 * @param $lang string Language code
1499 * @return string HTML to use for edit link
1500 */
1501 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1502 // HTML generated here should probably have userlangattributes
1503 // added to it for LTR text on RTL pages
1504
1505 $lang = wfGetLangObj( $lang );
1506
1507 $attribs = array();
1508 if ( !is_null( $tooltip ) ) {
1509 # Bug 25462: undo double-escaping.
1510 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1511 $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1512 ->inLanguage( $lang )->text();
1513 }
1514 $link = Linker::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(),
1515 $attribs,
1516 array( 'action' => 'edit', 'section' => $section ),
1517 array( 'noclasses', 'known' )
1518 );
1519
1520 # Run the old hook. This takes up half of the function . . . hopefully
1521 # we can rid of it someday.
1522 $attribs = '';
1523 if ( $tooltip ) {
1524 $attribs = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
1525 ->inLanguage( $lang )->escaped();
1526 $attribs = " title=\"$attribs\"";
1527 }
1528 $result = null;
1529 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1530 if ( !is_null( $result ) ) {
1531 # For reverse compatibility, add the brackets *after* the hook is
1532 # run, and even add them to hook-provided text. (This is the main
1533 # reason that the EditSectionLink hook is deprecated in favor of
1534 # DoEditSectionLink: it can't change the brackets or the span.)
1535 $result = wfMessage( 'editsection-brackets' )->rawParams( $result )
1536 ->inLanguage( $lang )->escaped();
1537 return "<span class=\"editsection\">$result</span>";
1538 }
1539
1540 # Add the brackets and the span, and *then* run the nice new hook, with
1541 # clean and non-redundant arguments.
1542 $result = wfMessage( 'editsection-brackets' )->rawParams( $link )
1543 ->inLanguage( $lang )->escaped();
1544 $result = "<span class=\"editsection\">$result</span>";
1545
1546 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1547 return $result;
1548 }
1549
1550 /**
1551 * Use PHP's magic __call handler to intercept legacy calls to the linker
1552 * for backwards compatibility.
1553 *
1554 * @param string $fname Name of called method
1555 * @param array $args Arguments to the method
1556 * @throws MWException
1557 * @return mixed
1558 */
1559 function __call( $fname, $args ) {
1560 $realFunction = array( 'Linker', $fname );
1561 if ( is_callable( $realFunction ) ) {
1562 wfDeprecated( get_class( $this ) . '::' . $fname, '1.21' );
1563 return call_user_func_array( $realFunction, $args );
1564 } else {
1565 $className = get_class( $this );
1566 throw new MWException( "Call to undefined method $className::$fname" );
1567 }
1568 }
1569
1570 }