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