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