Revert r104659 and its followup r104665: break the unit tests with a fatal error...
[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
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 if ( $wgShowDebug ) {
535 $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext );
536 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
537 $listInternals . "</ul>\n";
538 }
539
540 return '';
541 }
542
543 /**
544 * @param $debugText
545 * @return string
546 */
547 private function formatDebugHTML( $debugText ) {
548 global $wgDebugTimestamps;
549
550 $lines = explode( "\n", $debugText );
551 $curIdent = 0;
552 $ret = '<li>';
553
554 foreach ( $lines as $line ) {
555 $pre = '';
556 if ( $wgDebugTimestamps ) {
557 $matches = array();
558 if ( preg_match( '/^(\d+\.\d+ {1,3}\d+.\dM\s{2})/', $line, $matches ) ) {
559 $pre = $matches[1];
560 $line = substr( $line, strlen( $pre ) );
561 }
562 }
563 $display = ltrim( $line );
564 $ident = strlen( $line ) - strlen( $display );
565 $diff = $ident - $curIdent;
566
567 $display = $pre . $display;
568 if ( $display == '' ) {
569 $display = "\xc2\xa0";
570 }
571
572 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
573 $ident = $curIdent;
574 $diff = 0;
575 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
576 } else {
577 $display = htmlspecialchars( $display );
578 }
579
580 if ( $diff < 0 ) {
581 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
582 } elseif ( $diff == 0 ) {
583 $ret .= "</li><li>\n";
584 } else {
585 $ret .= str_repeat( "<ul><li>\n", $diff );
586 }
587 $ret .= "<tt>$display</tt>\n";
588
589 $curIdent = $ident;
590 }
591
592 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
593
594 return $ret;
595 }
596
597 /**
598 * This gets called shortly before the </body> tag.
599 *
600 * @return String HTML-wrapped JS code to be put before </body>
601 */
602 function bottomScripts() {
603 // TODO and the suckage continues. This function is really just a wrapper around
604 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
605 // up at some point
606 $bottomScriptText = $this->getOutput()->getBottomScripts();
607 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
608
609 return $bottomScriptText;
610 }
611
612 /**
613 * Text with the permalink to the source page,
614 * usually shown on the footer of a printed page
615 *
616 * @return string HTML text with an URL
617 */
618 function printSource() {
619 $oldid = $this->getRevisionId();
620 if ( $oldid ) {
621 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
622 } else {
623 // oldid not available for non existing pages
624 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
625 }
626 return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
627 }
628
629 /**
630 * @return String
631 */
632 function getUndeleteLink() {
633 $action = $this->getRequest()->getVal( 'action', 'view' );
634
635 if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
636 ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) {
637 $n = $this->getTitle()->isDeleted();
638
639
640 if ( $n ) {
641 if ( $this->getUser()->isAllowed( 'undelete' ) ) {
642 $msg = 'thisisdeleted';
643 } else {
644 $msg = 'viewdeleted';
645 }
646
647 return $this->msg( $msg )->rawParams(
648 Linker::linkKnown(
649 SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
650 $this->msg( 'restorelink' )->numParams( $n )->escaped() )
651 )->text();
652 }
653 }
654
655 return '';
656 }
657
658 /**
659 * @return string
660 */
661 function subPageSubtitle() {
662 $out = $this->getOutput();
663 $subpages = '';
664
665 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
666 return $subpages;
667 }
668
669 if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
670 $ptext = $this->getTitle()->getPrefixedText();
671 if ( preg_match( '/\//', $ptext ) ) {
672 $links = explode( '/', $ptext );
673 array_pop( $links );
674 $c = 0;
675 $growinglink = '';
676 $display = '';
677
678 foreach ( $links as $link ) {
679 $growinglink .= $link;
680 $display .= $link;
681 $linkObj = Title::newFromText( $growinglink );
682
683 if ( is_object( $linkObj ) && $linkObj->exists() ) {
684 $getlink = Linker::linkKnown(
685 $linkObj,
686 htmlspecialchars( $display )
687 );
688
689 $c++;
690
691 if ( $c > 1 ) {
692 $subpages .= $this->msg( 'pipe-separator' )->escaped();
693 } else {
694 $subpages .= '&lt; ';
695 }
696
697 $subpages .= $getlink;
698 $display = '';
699 } else {
700 $display .= '/';
701 }
702 $growinglink .= '/';
703 }
704 }
705 }
706
707 return $subpages;
708 }
709
710 /**
711 * Returns true if the IP should be shown in the header
712 * @return Bool
713 */
714 function showIPinHeader() {
715 global $wgShowIPinHeader;
716 return $wgShowIPinHeader && session_id() != '';
717 }
718
719 /**
720 * @return String
721 */
722 function getSearchLink() {
723 $searchPage = SpecialPage::getTitleFor( 'Search' );
724 return $searchPage->getLocalURL();
725 }
726
727 /**
728 * @return string
729 */
730 function escapeSearchLink() {
731 return htmlspecialchars( $this->getSearchLink() );
732 }
733
734 /**
735 * @param string $type
736 * @return string
737 */
738 function getCopyright( $type = 'detect' ) {
739 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
740
741 if ( $type == 'detect' ) {
742 if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
743 $type = 'history';
744 } else {
745 $type = 'normal';
746 }
747 }
748
749 if ( $type == 'history' ) {
750 $msg = 'history_copyright';
751 } else {
752 $msg = 'copyright';
753 }
754
755 if ( $wgRightsPage ) {
756 $title = Title::newFromText( $wgRightsPage );
757 $link = Linker::linkKnown( $title, $wgRightsText );
758 } elseif ( $wgRightsUrl ) {
759 $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
760 } elseif ( $wgRightsText ) {
761 $link = $wgRightsText;
762 } else {
763 # Give up now
764 return '';
765 }
766
767 // Allow for site and per-namespace customization of copyright notice.
768 $forContent = true;
769
770 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
771
772 $msgObj = $this->msg( $msg )->rawParams( $link );
773 if ( $forContent ) {
774 $msg = $msgObj->inContentLanguage()->text();
775 if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
776 $msg = Html::rawElement( 'span', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $msg );
777 }
778 return $msg;
779 } else {
780 return $msgObj->text();
781 }
782 }
783
784 /**
785 * @return null|string
786 */
787 function getCopyrightIcon() {
788 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
789
790 $out = '';
791
792 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
793 $out = $wgCopyrightIcon;
794 } elseif ( $wgRightsIcon ) {
795 $icon = htmlspecialchars( $wgRightsIcon );
796
797 if ( $wgRightsUrl ) {
798 $url = htmlspecialchars( $wgRightsUrl );
799 $out .= '<a href="' . $url . '">';
800 }
801
802 $text = htmlspecialchars( $wgRightsText );
803 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
804
805 if ( $wgRightsUrl ) {
806 $out .= '</a>';
807 }
808 }
809
810 return $out;
811 }
812
813 /**
814 * Gets the powered by MediaWiki icon.
815 * @return string
816 */
817 function getPoweredBy() {
818 global $wgStylePath;
819
820 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
821 $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
822 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
823 return $text;
824 }
825
826 /**
827 * Get the timestamp of the latest revision, formatted in user language
828 *
829 * @param $page WikiPage object. Used if we're working with the current revision
830 * @return String
831 */
832 protected function lastModified( $page ) {
833 if ( !$this->isRevisionCurrent() ) {
834 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
835 } else {
836 $timestamp = $page->getTimestamp();
837 }
838
839 if ( $timestamp ) {
840 $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
841 $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
842 $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
843 } else {
844 $s = '';
845 }
846
847 if ( wfGetLB()->getLaggedSlaveMode() ) {
848 $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
849 }
850
851 return $s;
852 }
853
854 /**
855 * @param $align string
856 * @return string
857 */
858 function logoText( $align = '' ) {
859 if ( $align != '' ) {
860 $a = " align='{$align}'";
861 } else {
862 $a = '';
863 }
864
865 $mp = $this->msg( 'mainpage' )->escaped();
866 $mptitle = Title::newMainPage();
867 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
868
869 $logourl = $this->getLogo();
870 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
871
872 return $s;
873 }
874
875 /**
876 * Renders a $wgFooterIcons icon acording to the method's arguments
877 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
878 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
879 * @return String HTML
880 */
881 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
882 if ( is_string( $icon ) ) {
883 $html = $icon;
884 } else { // Assuming array
885 $url = isset($icon["url"]) ? $icon["url"] : null;
886 unset( $icon["url"] );
887 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
888 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
889 } else {
890 $html = htmlspecialchars( $icon["alt"] );
891 }
892 if ( $url ) {
893 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
894 }
895 }
896 return $html;
897 }
898
899 /**
900 * Gets the link to the wiki's main page.
901 * @return string
902 */
903 function mainPageLink() {
904 $s = Linker::linkKnown(
905 Title::newMainPage(),
906 $this->msg( 'mainpage' )->escaped()
907 );
908
909 return $s;
910 }
911
912 /**
913 * @param $desc
914 * @param $page
915 * @return string
916 */
917 public function footerLink( $desc, $page ) {
918 // if the link description has been set to "-" in the default language,
919 if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
920 // then it is disabled, for all languages.
921 return '';
922 } else {
923 // Otherwise, we display the link for the user, described in their
924 // language (which may or may not be the same as the default language),
925 // but we make the link target be the one site-wide page.
926 $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
927
928 return Linker::linkKnown(
929 $title,
930 $this->msg( $desc )->escaped()
931 );
932 }
933 }
934
935 /**
936 * Gets the link to the wiki's privacy policy page.
937 * @return String HTML
938 */
939 function privacyLink() {
940 return $this->footerLink( 'privacy', 'privacypage' );
941 }
942
943 /**
944 * Gets the link to the wiki's about page.
945 * @return String HTML
946 */
947 function aboutLink() {
948 return $this->footerLink( 'aboutsite', 'aboutpage' );
949 }
950
951 /**
952 * Gets the link to the wiki's general disclaimers page.
953 * @return String HTML
954 */
955 function disclaimerLink() {
956 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
957 }
958
959 /**
960 * Return URL options for the 'edit page' link.
961 * This may include an 'oldid' specifier, if the current page view is such.
962 *
963 * @return array
964 * @private
965 */
966 function editUrlOptions() {
967 $options = array( 'action' => 'edit' );
968
969 if ( !$this->isRevisionCurrent() ) {
970 $options['oldid'] = intval( $this->getRevisionId() );
971 }
972
973 return $options;
974 }
975
976 /**
977 * @param $id
978 * @return bool
979 */
980 function showEmailUser( $id ) {
981 if ( $id instanceof User ) {
982 $targetUser = $id;
983 } else {
984 $targetUser = User::newFromId( $id );
985 }
986 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
987 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
988 }
989
990 /**
991 * Return a fully resolved style path url to images or styles stored in the common folder.
992 * This method returns a url resolved using the configured skin style path
993 * and includes the style version inside of the url.
994 * @param $name String: The name or path of a skin resource file
995 * @return String The fully resolved style path url including styleversion
996 */
997 function getCommonStylePath( $name ) {
998 global $wgStylePath, $wgStyleVersion;
999 return "$wgStylePath/common/$name?$wgStyleVersion";
1000 }
1001
1002 /**
1003 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1004 * This method returns a url resolved using the configured skin style path
1005 * and includes the style version inside of the url.
1006 * @param $name String: The name or path of a skin resource file
1007 * @return String The fully resolved style path url including styleversion
1008 */
1009 function getSkinStylePath( $name ) {
1010 global $wgStylePath, $wgStyleVersion;
1011 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1012 }
1013
1014 /* these are used extensively in SkinTemplate, but also some other places */
1015
1016 /**
1017 * @param $urlaction string
1018 * @return String
1019 */
1020 static function makeMainPageUrl( $urlaction = '' ) {
1021 $title = Title::newMainPage();
1022 self::checkTitle( $title, '' );
1023
1024 return $title->getLocalURL( $urlaction );
1025 }
1026
1027 /**
1028 * @param $name
1029 * @param $urlaction string
1030 * @return String
1031 */
1032 static function makeSpecialUrl( $name, $urlaction = '' ) {
1033 $title = SpecialPage::getSafeTitleFor( $name );
1034 return $title->getLocalURL( $urlaction );
1035 }
1036
1037 /**
1038 * @param $name
1039 * @param $subpage
1040 * @param $urlaction string
1041 * @return String
1042 */
1043 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1044 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1045 return $title->getLocalURL( $urlaction );
1046 }
1047
1048 /**
1049 * @param $name
1050 * @param $urlaction string
1051 * @return String
1052 */
1053 static function makeI18nUrl( $name, $urlaction = '' ) {
1054 $title = Title::newFromText( wfMsgForContent( $name ) );
1055 self::checkTitle( $title, $name );
1056 return $title->getLocalURL( $urlaction );
1057 }
1058
1059 /**
1060 * @param $name
1061 * @param $urlaction string
1062 * @return String
1063 */
1064 static function makeUrl( $name, $urlaction = '' ) {
1065 $title = Title::newFromText( $name );
1066 self::checkTitle( $title, $name );
1067
1068 return $title->getLocalURL( $urlaction );
1069 }
1070
1071 /**
1072 * If url string starts with http, consider as external URL, else
1073 * internal
1074 * @param $name String
1075 * @return String URL
1076 */
1077 static function makeInternalOrExternalUrl( $name ) {
1078 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1079 return $name;
1080 } else {
1081 return self::makeUrl( $name );
1082 }
1083 }
1084
1085 /**
1086 * this can be passed the NS number as defined in Language.php
1087 * @param $name
1088 * @param $urlaction string
1089 * @param $namespace int
1090 * @return String
1091 */
1092 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1093 $title = Title::makeTitleSafe( $namespace, $name );
1094 self::checkTitle( $title, $name );
1095
1096 return $title->getLocalURL( $urlaction );
1097 }
1098
1099 /**
1100 * these return an array with the 'href' and boolean 'exists'
1101 * @param $name
1102 * @param $urlaction string
1103 * @return array
1104 */
1105 static function makeUrlDetails( $name, $urlaction = '' ) {
1106 $title = Title::newFromText( $name );
1107 self::checkTitle( $title, $name );
1108
1109 return array(
1110 'href' => $title->getLocalURL( $urlaction ),
1111 'exists' => $title->getArticleID() != 0,
1112 );
1113 }
1114
1115 /**
1116 * Make URL details where the article exists (or at least it's convenient to think so)
1117 * @param $name String Article name
1118 * @param $urlaction String
1119 * @return Array
1120 */
1121 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1122 $title = Title::newFromText( $name );
1123 self::checkTitle( $title, $name );
1124
1125 return array(
1126 'href' => $title->getLocalURL( $urlaction ),
1127 'exists' => true
1128 );
1129 }
1130
1131 /**
1132 * make sure we have some title to operate on
1133 *
1134 * @param $title Title
1135 * @param $name
1136 */
1137 static function checkTitle( &$title, $name ) {
1138 if ( !is_object( $title ) ) {
1139 $title = Title::newFromText( $name );
1140 if ( !is_object( $title ) ) {
1141 $title = Title::newFromText( '--error: link target missing--' );
1142 }
1143 }
1144 }
1145
1146 /**
1147 * Build an array that represents the sidebar(s), the navigation bar among them
1148 *
1149 * @return array
1150 */
1151 function buildSidebar() {
1152 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1153 wfProfileIn( __METHOD__ );
1154
1155 $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
1156
1157 if ( $wgEnableSidebarCache ) {
1158 $cachedsidebar = $parserMemc->get( $key );
1159 if ( $cachedsidebar ) {
1160 wfProfileOut( __METHOD__ );
1161 return $cachedsidebar;
1162 }
1163 }
1164
1165 $bar = array();
1166 $this->addToSidebar( $bar, 'sidebar' );
1167
1168 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1169 if ( $wgEnableSidebarCache ) {
1170 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1171 }
1172
1173 wfProfileOut( __METHOD__ );
1174 return $bar;
1175 }
1176 /**
1177 * Add content from a sidebar system message
1178 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1179 *
1180 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1181 *
1182 * @param $bar array
1183 * @param $message String
1184 */
1185 function addToSidebar( &$bar, $message ) {
1186 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1187 }
1188
1189 /**
1190 * Add content from plain text
1191 * @since 1.17
1192 * @param $bar array
1193 * @param $text string
1194 * @return Array
1195 */
1196 function addToSidebarPlain( &$bar, $text ) {
1197 $lines = explode( "\n", $text );
1198
1199 $heading = '';
1200
1201 foreach ( $lines as $line ) {
1202 if ( strpos( $line, '*' ) !== 0 ) {
1203 continue;
1204 }
1205 $line = rtrim( $line, "\r" ); // for Windows compat
1206
1207 if ( strpos( $line, '**' ) !== 0 ) {
1208 $heading = trim( $line, '* ' );
1209 if ( !array_key_exists( $heading, $bar ) ) {
1210 $bar[$heading] = array();
1211 }
1212 } else {
1213 $line = trim( $line, '* ' );
1214
1215 if ( strpos( $line, '|' ) !== false ) { // sanity check
1216 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1217 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1218 $extraAttribs = array();
1219
1220 $msgLink = $this->msg( $line[0] )->inContentLanguage();
1221 if ( $msgLink->exists() ) {
1222 $link = $msgLink->text();
1223 if ( $link == '-' ) {
1224 continue;
1225 }
1226 } else {
1227 $link = $line[0];
1228 }
1229
1230 $msgText = $this->msg( $line[1] );
1231 if ( $msgText->exists() ) {
1232 $text = $msgText->text();
1233 } else {
1234 $text = $line[1];
1235 }
1236
1237 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1238 $href = $link;
1239
1240 // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1241 global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
1242 if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
1243 $extraAttribs['rel'] = 'nofollow';
1244 }
1245
1246 global $wgExternalLinkTarget;
1247 if ( $wgExternalLinkTarget) {
1248 $extraAttribs['target'] = $wgExternalLinkTarget;
1249 }
1250 } else {
1251 $title = Title::newFromText( $link );
1252
1253 if ( $title ) {
1254 $title = $title->fixSpecialName();
1255 $href = $title->getLinkURL();
1256 } else {
1257 $href = 'INVALID-TITLE';
1258 }
1259 }
1260
1261 $bar[$heading][] = array_merge( array(
1262 'text' => $text,
1263 'href' => $href,
1264 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1265 'active' => false
1266 ), $extraAttribs );
1267 } else {
1268 continue;
1269 }
1270 }
1271 }
1272
1273 return $bar;
1274 }
1275
1276 /**
1277 * Should we load mediawiki.legacy.wikiprintable? Skins that have their own
1278 * print stylesheet should override this and return false. (This is an
1279 * ugly hack to get Monobook to play nicely with OutputPage::headElement().)
1280 *
1281 * @return bool
1282 */
1283 public function commonPrintStylesheet() {
1284 return true;
1285 }
1286
1287 /**
1288 * Gets new talk page messages for the current user.
1289 * @return MediaWiki message or if no new talk page messages, nothing
1290 */
1291 function getNewtalks() {
1292 $out = $this->getOutput();
1293
1294 $newtalks = $this->getUser()->getNewMessageLinks();
1295 $ntl = '';
1296
1297 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1298 $userTitle = $this->getUser()->getUserPage();
1299 $userTalkTitle = $userTitle->getTalkPage();
1300
1301 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1302 $newMessagesLink = Linker::linkKnown(
1303 $userTalkTitle,
1304 $this->msg( 'newmessageslink' )->escaped(),
1305 array(),
1306 array( 'redirect' => 'no' )
1307 );
1308
1309 $newMessagesDiffLink = Linker::linkKnown(
1310 $userTalkTitle,
1311 $this->msg( 'newmessagesdifflink' )->escaped(),
1312 array(),
1313 array( 'diff' => 'cur' )
1314 );
1315
1316 $ntl = $this->msg(
1317 'youhavenewmessages',
1318 $newMessagesLink,
1319 $newMessagesDiffLink
1320 )->text();
1321 # Disable Squid cache
1322 $out->setSquidMaxage( 0 );
1323 }
1324 } elseif ( count( $newtalks ) ) {
1325 // _>" " for BC <= 1.16
1326 $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
1327 $msgs = array();
1328
1329 foreach ( $newtalks as $newtalk ) {
1330 $msgs[] = Xml::element(
1331 'a',
1332 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1333 );
1334 }
1335 $parts = implode( $sep, $msgs );
1336 $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1337 $out->setSquidMaxage( 0 );
1338 }
1339
1340 return $ntl;
1341 }
1342
1343 /**
1344 * Get a cached notice
1345 *
1346 * @param $name String: message name, or 'default' for $wgSiteNotice
1347 * @return String: HTML fragment
1348 */
1349 private function getCachedNotice( $name ) {
1350 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1351
1352 wfProfileIn( __METHOD__ );
1353
1354 $needParse = false;
1355
1356 if( $name === 'default' ) {
1357 // special case
1358 global $wgSiteNotice;
1359 $notice = $wgSiteNotice;
1360 if( empty( $notice ) ) {
1361 wfProfileOut( __METHOD__ );
1362 return false;
1363 }
1364 } else {
1365 $msg = $this->msg( $name )->inContentLanguage();
1366 if( $msg->isDisabled() ) {
1367 wfProfileOut( __METHOD__ );
1368 return false;
1369 }
1370 $notice = $msg->plain();
1371 }
1372
1373 // Use the extra hash appender to let eg SSL variants separately cache.
1374 $key = wfMemcKey( $name . $wgRenderHashAppend );
1375 $cachedNotice = $parserMemc->get( $key );
1376 if( is_array( $cachedNotice ) ) {
1377 if( md5( $notice ) == $cachedNotice['hash'] ) {
1378 $notice = $cachedNotice['html'];
1379 } else {
1380 $needParse = true;
1381 }
1382 } else {
1383 $needParse = true;
1384 }
1385
1386 if ( $needParse ) {
1387 $parsed = $this->getOutput()->parse( $notice );
1388 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1389 $notice = $parsed;
1390 }
1391
1392 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1393 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $notice );
1394 wfProfileOut( __METHOD__ );
1395 return $notice;
1396 }
1397
1398 /**
1399 * Get a notice based on page's namespace
1400 *
1401 * @return String: HTML fragment
1402 */
1403 function getNamespaceNotice() {
1404 wfProfileIn( __METHOD__ );
1405
1406 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1407 $namespaceNotice = $this->getCachedNotice( $key );
1408 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1409 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1410 } else {
1411 $namespaceNotice = '';
1412 }
1413
1414 wfProfileOut( __METHOD__ );
1415 return $namespaceNotice;
1416 }
1417
1418 /**
1419 * Get the site notice
1420 *
1421 * @return String: HTML fragment
1422 */
1423 function getSiteNotice() {
1424 wfProfileIn( __METHOD__ );
1425 $siteNotice = '';
1426
1427 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1428 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1429 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1430 } else {
1431 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1432 if ( !$anonNotice ) {
1433 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1434 } else {
1435 $siteNotice = $anonNotice;
1436 }
1437 }
1438 if ( !$siteNotice ) {
1439 $siteNotice = $this->getCachedNotice( 'default' );
1440 }
1441 }
1442
1443 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1444 wfProfileOut( __METHOD__ );
1445 return $siteNotice;
1446 }
1447
1448 /**
1449 * Create a section edit link. This supersedes editSectionLink() and
1450 * editSectionLinkForOther().
1451 *
1452 * @param $nt Title The title being linked to (may not be the same as
1453 * $wgTitle, if the section is included from a template)
1454 * @param $section string The designation of the section being pointed to,
1455 * to be included in the link, like "&section=$section"
1456 * @param $tooltip string The tooltip to use for the link: will be escaped
1457 * and wrapped in the 'editsectionhint' message
1458 * @param $lang string Language code
1459 * @return string HTML to use for edit link
1460 */
1461 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1462 // HTML generated here should probably have userlangattributes
1463 // added to it for LTR text on RTL pages
1464 $attribs = array();
1465 if ( !is_null( $tooltip ) ) {
1466 # Bug 25462: undo double-escaping.
1467 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1468 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1469 }
1470 $link = Linker::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1471 $attribs,
1472 array( 'action' => 'edit', 'section' => $section ),
1473 array( 'noclasses', 'known' )
1474 );
1475
1476 # Run the old hook. This takes up half of the function . . . hopefully
1477 # we can rid of it someday.
1478 $attribs = '';
1479 if ( $tooltip ) {
1480 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1481 $attribs = " title=\"$attribs\"";
1482 }
1483 $result = null;
1484 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1485 if ( !is_null( $result ) ) {
1486 # For reverse compatibility, add the brackets *after* the hook is
1487 # run, and even add them to hook-provided text. (This is the main
1488 # reason that the EditSectionLink hook is deprecated in favor of
1489 # DoEditSectionLink: it can't change the brackets or the span.)
1490 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1491 return "<span class=\"editsection\">$result</span>";
1492 }
1493
1494 # Add the brackets and the span, and *then* run the nice new hook, with
1495 # clean and non-redundant arguments.
1496 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1497 $result = "<span class=\"editsection\">$result</span>";
1498
1499 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1500 return $result;
1501 }
1502
1503 /**
1504 * Use PHP's magic __call handler to intercept legacy calls to the linker
1505 * for backwards compatibility.
1506 *
1507 * @param $fname String Name of called method
1508 * @param $args Array Arguments to the method
1509 */
1510 function __call( $fname, $args ) {
1511 $realFunction = array( 'Linker', $fname );
1512 if ( is_callable( $realFunction ) ) {
1513 return call_user_func_array( $realFunction, $args );
1514 } else {
1515 $className = get_class( $this );
1516 throw new MWException( "Call to undefined method $className::$fname" );
1517 }
1518 }
1519
1520 }