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