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