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