Removed useless $out variable from Skin::getCopyright()
[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' ) && !$this->getUser()->isBlocked() &&
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 if ( !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
732 $type = 'history';
733 } else {
734 $type = 'normal';
735 }
736 }
737
738 if ( $type == 'history' ) {
739 $msg = 'history_copyright';
740 } else {
741 $msg = 'copyright';
742 }
743
744 if ( $wgRightsPage ) {
745 $title = Title::newFromText( $wgRightsPage );
746 $link = Linker::linkKnown( $title, $wgRightsText );
747 } elseif ( $wgRightsUrl ) {
748 $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
749 } elseif ( $wgRightsText ) {
750 $link = $wgRightsText;
751 } else {
752 # Give up now
753 return '';
754 }
755
756 // Allow for site and per-namespace customization of copyright notice.
757 $forContent = true;
758
759 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
760
761 if ( $forContent ) {
762 return wfMsgForContent( $msg, $link );
763 } else {
764 return wfMsg( $msg, $link );
765 }
766 }
767
768 function getCopyrightIcon() {
769 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
770
771 $out = '';
772
773 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
774 $out = $wgCopyrightIcon;
775 } elseif ( $wgRightsIcon ) {
776 $icon = htmlspecialchars( $wgRightsIcon );
777
778 if ( $wgRightsUrl ) {
779 $url = htmlspecialchars( $wgRightsUrl );
780 $out .= '<a href="' . $url . '">';
781 }
782
783 $text = htmlspecialchars( $wgRightsText );
784 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
785
786 if ( $wgRightsUrl ) {
787 $out .= '</a>';
788 }
789 }
790
791 return $out;
792 }
793
794 /**
795 * Gets the powered by MediaWiki icon.
796 * @return string
797 */
798 function getPoweredBy() {
799 global $wgStylePath;
800
801 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
802 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
803 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
804 return $text;
805 }
806
807 /**
808 * Get the timestamp of the latest revision, formatted in user language
809 *
810 * @param $article Article object. Used if we're working with the current revision
811 * @return String
812 */
813 protected function lastModified( $article ) {
814 if ( !$this->isRevisionCurrent() ) {
815 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
816 } else {
817 $timestamp = $article->getTimestamp();
818 }
819
820 if ( $timestamp ) {
821 $d = $this->getLang()->date( $timestamp, true );
822 $t = $this->getLang()->time( $timestamp, true );
823 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
824 } else {
825 $s = '';
826 }
827
828 if ( wfGetLB()->getLaggedSlaveMode() ) {
829 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
830 }
831
832 return $s;
833 }
834
835 function logoText( $align = '' ) {
836 if ( $align != '' ) {
837 $a = " align='{$align}'";
838 } else {
839 $a = '';
840 }
841
842 $mp = wfMsgHtml( 'mainpage' );
843 $mptitle = Title::newMainPage();
844 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
845
846 $logourl = $this->getLogo();
847 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
848
849 return $s;
850 }
851
852 /**
853 * Renders a $wgFooterIcons icon acording to the method's arguments
854 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
855 * @param $withImage Bool|String: Whether to use the icon's image or output a text-only footericon
856 * @return String HTML
857 */
858 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
859 if ( is_string( $icon ) ) {
860 $html = $icon;
861 } else { // Assuming array
862 $url = isset($icon["url"]) ? $icon["url"] : null;
863 unset( $icon["url"] );
864 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
865 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
866 } else {
867 $html = htmlspecialchars( $icon["alt"] );
868 }
869 if ( $url ) {
870 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
871 }
872 }
873 return $html;
874 }
875
876 /**
877 * Gets the link to the wiki's main page.
878 * @return string
879 */
880 function mainPageLink() {
881 $s = Linker::linkKnown(
882 Title::newMainPage(),
883 wfMsgHtml( 'mainpage' )
884 );
885
886 return $s;
887 }
888
889 public function footerLink( $desc, $page ) {
890 // if the link description has been set to "-" in the default language,
891 if ( wfMsgForContent( $desc ) == '-' ) {
892 // then it is disabled, for all languages.
893 return '';
894 } else {
895 // Otherwise, we display the link for the user, described in their
896 // language (which may or may not be the same as the default language),
897 // but we make the link target be the one site-wide page.
898 $title = Title::newFromText( wfMsgForContent( $page ) );
899
900 return Linker::linkKnown(
901 $title,
902 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
903 );
904 }
905 }
906
907 /**
908 * Gets the link to the wiki's privacy policy page.
909 * @return String HTML
910 */
911 function privacyLink() {
912 return $this->footerLink( 'privacy', 'privacypage' );
913 }
914
915 /**
916 * Gets the link to the wiki's about page.
917 * @return String HTML
918 */
919 function aboutLink() {
920 return $this->footerLink( 'aboutsite', 'aboutpage' );
921 }
922
923 /**
924 * Gets the link to the wiki's general disclaimers page.
925 * @return String HTML
926 */
927 function disclaimerLink() {
928 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
929 }
930
931 /**
932 * Return URL options for the 'edit page' link.
933 * This may include an 'oldid' specifier, if the current page view is such.
934 *
935 * @return array
936 * @private
937 */
938 function editUrlOptions() {
939 $options = array( 'action' => 'edit' );
940
941 if ( !$this->isRevisionCurrent() ) {
942 $options['oldid'] = intval( $this->getRevisionId() );
943 }
944
945 return $options;
946 }
947
948 function showEmailUser( $id ) {
949 $targetUser = User::newFromId( $id );
950 return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
951 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
952 }
953
954 /**
955 * Return a fully resolved style path url to images or styles stored in the common folder.
956 * This method returns a url resolved using the configured skin style path
957 * and includes the style version inside of the url.
958 * @param $name String: The name or path of a skin resource file
959 * @return String The fully resolved style path url including styleversion
960 */
961 function getCommonStylePath( $name ) {
962 global $wgStylePath, $wgStyleVersion;
963 return "$wgStylePath/common/$name?$wgStyleVersion";
964 }
965
966 /**
967 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
968 * This method returns a url resolved using the configured skin style path
969 * and includes the style version inside of the url.
970 * @param $name String: The name or path of a skin resource file
971 * @return String The fully resolved style path url including styleversion
972 */
973 function getSkinStylePath( $name ) {
974 global $wgStylePath, $wgStyleVersion;
975 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
976 }
977
978 /* these are used extensively in SkinTemplate, but also some other places */
979 static function makeMainPageUrl( $urlaction = '' ) {
980 $title = Title::newMainPage();
981 self::checkTitle( $title, '' );
982
983 return $title->getLocalURL( $urlaction );
984 }
985
986 static function makeSpecialUrl( $name, $urlaction = '' ) {
987 $title = SpecialPage::getSafeTitleFor( $name );
988 return $title->getLocalURL( $urlaction );
989 }
990
991 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
992 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
993 return $title->getLocalURL( $urlaction );
994 }
995
996 static function makeI18nUrl( $name, $urlaction = '' ) {
997 $title = Title::newFromText( wfMsgForContent( $name ) );
998 self::checkTitle( $title, $name );
999 return $title->getLocalURL( $urlaction );
1000 }
1001
1002 static function makeUrl( $name, $urlaction = '' ) {
1003 $title = Title::newFromText( $name );
1004 self::checkTitle( $title, $name );
1005
1006 return $title->getLocalURL( $urlaction );
1007 }
1008
1009 /**
1010 * If url string starts with http, consider as external URL, else
1011 * internal
1012 * @param $name String
1013 * @return String URL
1014 */
1015 static function makeInternalOrExternalUrl( $name ) {
1016 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1017 return $name;
1018 } else {
1019 return self::makeUrl( $name );
1020 }
1021 }
1022
1023 # this can be passed the NS number as defined in Language.php
1024 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1025 $title = Title::makeTitleSafe( $namespace, $name );
1026 self::checkTitle( $title, $name );
1027
1028 return $title->getLocalURL( $urlaction );
1029 }
1030
1031 /* these return an array with the 'href' and boolean 'exists' */
1032 static function makeUrlDetails( $name, $urlaction = '' ) {
1033 $title = Title::newFromText( $name );
1034 self::checkTitle( $title, $name );
1035
1036 return array(
1037 'href' => $title->getLocalURL( $urlaction ),
1038 'exists' => $title->getArticleID() != 0,
1039 );
1040 }
1041
1042 /**
1043 * Make URL details where the article exists (or at least it's convenient to think so)
1044 * @param $name String Article name
1045 * @param $urlaction String
1046 * @return Array
1047 */
1048 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1049 $title = Title::newFromText( $name );
1050 self::checkTitle( $title, $name );
1051
1052 return array(
1053 'href' => $title->getLocalURL( $urlaction ),
1054 'exists' => true
1055 );
1056 }
1057
1058 # make sure we have some title to operate on
1059 static function checkTitle( &$title, $name ) {
1060 if ( !is_object( $title ) ) {
1061 $title = Title::newFromText( $name );
1062 if ( !is_object( $title ) ) {
1063 $title = Title::newFromText( '--error: link target missing--' );
1064 }
1065 }
1066 }
1067
1068 /**
1069 * Build an array that represents the sidebar(s), the navigation bar among them
1070 *
1071 * @return array
1072 */
1073 function buildSidebar() {
1074 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1075 wfProfileIn( __METHOD__ );
1076
1077 $key = wfMemcKey( 'sidebar', $this->getLang()->getCode() );
1078
1079 if ( $wgEnableSidebarCache ) {
1080 $cachedsidebar = $parserMemc->get( $key );
1081 if ( $cachedsidebar ) {
1082 wfProfileOut( __METHOD__ );
1083 return $cachedsidebar;
1084 }
1085 }
1086
1087 $bar = array();
1088 $this->addToSidebar( $bar, 'sidebar' );
1089
1090 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1091 if ( $wgEnableSidebarCache ) {
1092 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1093 }
1094
1095 wfProfileOut( __METHOD__ );
1096 return $bar;
1097 }
1098 /**
1099 * Add content from a sidebar system message
1100 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1101 *
1102 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1103 *
1104 * @param &$bar array
1105 * @param $message String
1106 */
1107 function addToSidebar( &$bar, $message ) {
1108 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1109 }
1110
1111 /**
1112 * Add content from plain text
1113 * @since 1.17
1114 * @param &$bar array
1115 * @param $text string
1116 * @return Array
1117 */
1118 function addToSidebarPlain( &$bar, $text ) {
1119 $lines = explode( "\n", $text );
1120 $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.
1121
1122 $heading = '';
1123
1124 foreach ( $lines as $line ) {
1125 if ( strpos( $line, '*' ) !== 0 ) {
1126 continue;
1127 }
1128
1129 if ( strpos( $line, '**' ) !== 0 ) {
1130 $heading = trim( $line, '* ' );
1131 if ( !array_key_exists( $heading, $bar ) ) {
1132 $bar[$heading] = array();
1133 }
1134 } else {
1135 $line = trim( $line, '* ' );
1136
1137 if ( strpos( $line, '|' ) !== false ) { // sanity check
1138 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
1139 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1140 $extraAttribs = array();
1141
1142 $msgLink = wfMessage( $line[0] )->inContentLanguage();
1143 if ( $msgLink->exists() ) {
1144 $link = $msgLink->text();
1145 if ( $link == '-' ) {
1146 continue;
1147 }
1148 } else {
1149 $link = $line[0];
1150 }
1151
1152 $msgText = wfMessage( $line[1] );
1153 if ( $msgText->exists() ) {
1154 $text = $msgText->text();
1155 } else {
1156 $text = $line[1];
1157 }
1158
1159 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1160 $href = $link;
1161 //Parser::getExternalLinkAttribs won't work here because of the Namespace things
1162 global $wgNoFollowLinks;
1163 if ( $wgNoFollowLinks ) {
1164 $extraAttribs['rel'] = 'nofollow';
1165
1166 global $wgNoFollowDomainExceptions;
1167 if ( $wgNoFollowDomainExceptions ) {
1168 $bits = wfParseUrl( $url );
1169 if ( is_array( $bits ) && isset( $bits['host'] ) ) {
1170 foreach ( $wgNoFollowDomainExceptions as $domain ) {
1171 if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) {
1172 unset( $extraAttribs['rel'] );
1173 break;
1174 }
1175 }
1176 }
1177 }
1178 }
1179 global $wgExternalLinkTarget;
1180 if ( $wgExternalLinkTarget) {
1181 $extraAttribs['target'] = $wgExternalLinkTarget;
1182 }
1183 } else {
1184 $title = Title::newFromText( $link );
1185
1186 if ( $title ) {
1187 $title = $title->fixSpecialName();
1188 $href = $title->getLocalURL();
1189 } else {
1190 $href = 'INVALID-TITLE';
1191 }
1192 }
1193
1194 $bar[$heading][] = array_merge( array(
1195 'text' => $text,
1196 'href' => $href,
1197 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
1198 'active' => false
1199 ), $extraAttribs );
1200 } elseif ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1201 global $wgParser;
1202
1203 $line = substr( $line, 2, strlen( $line ) - 4 );
1204
1205 $options = new ParserOptions();
1206 $options->setEditSection( false );
1207 $options->setInterfaceMessage( true );
1208 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
1209 } else {
1210 continue;
1211 }
1212 }
1213 }
1214
1215 if ( count( $wikiBar ) > 0 ) {
1216 $bar = array_merge( $bar, $wikiBar );
1217 }
1218
1219 return $bar;
1220 }
1221
1222 /**
1223 * Should we include common/wikiprintable.css? Skins that have their own
1224 * print stylesheet should override this and return false. (This is an
1225 * ugly hack to get Monobook to play nicely with
1226 * OutputPage::headElement().)
1227 *
1228 * @return bool
1229 */
1230 public function commonPrintStylesheet() {
1231 return true;
1232 }
1233
1234 /**
1235 * Gets new talk page messages for the current user.
1236 * @return MediaWiki message or if no new talk page messages, nothing
1237 */
1238 function getNewtalks() {
1239 $out = $this->getOutput();
1240
1241 $newtalks = $this->getUser()->getNewMessageLinks();
1242 $ntl = '';
1243
1244 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1245 $userTitle = $this->getUser()->getUserPage();
1246 $userTalkTitle = $userTitle->getTalkPage();
1247
1248 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1249 $newMessagesLink = Linker::linkKnown(
1250 $userTalkTitle,
1251 wfMsgHtml( 'newmessageslink' ),
1252 array(),
1253 array( 'redirect' => 'no' )
1254 );
1255
1256 $newMessagesDiffLink = Linker::linkKnown(
1257 $userTalkTitle,
1258 wfMsgHtml( 'newmessagesdifflink' ),
1259 array(),
1260 array( 'diff' => 'cur' )
1261 );
1262
1263 $ntl = wfMsg(
1264 'youhavenewmessages',
1265 $newMessagesLink,
1266 $newMessagesDiffLink
1267 );
1268 # Disable Squid cache
1269 $out->setSquidMaxage( 0 );
1270 }
1271 } elseif ( count( $newtalks ) ) {
1272 // _>" " for BC <= 1.16
1273 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1274 $msgs = array();
1275
1276 foreach ( $newtalks as $newtalk ) {
1277 $msgs[] = Xml::element(
1278 'a',
1279 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1280 );
1281 }
1282 $parts = implode( $sep, $msgs );
1283 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1284 $out->setSquidMaxage( 0 );
1285 }
1286
1287 return $ntl;
1288 }
1289
1290 /**
1291 * Get a cached notice
1292 *
1293 * @param $name String: message name, or 'default' for $wgSiteNotice
1294 * @return String: HTML fragment
1295 */
1296 private function getCachedNotice( $name ) {
1297 global $wgRenderHashAppend, $parserMemc, $wgContLang;
1298
1299 wfProfileIn( __METHOD__ );
1300
1301 $needParse = false;
1302
1303 if( $name === 'default' ) {
1304 // special case
1305 global $wgSiteNotice;
1306 $notice = $wgSiteNotice;
1307 if( empty( $notice ) ) {
1308 wfProfileOut( __METHOD__ );
1309 return false;
1310 }
1311 } else {
1312 $msg = wfMessage( $name )->inContentLanguage();
1313 if( $msg->isDisabled() ) {
1314 wfProfileOut( __METHOD__ );
1315 return false;
1316 }
1317 $notice = $msg->plain();
1318 }
1319
1320 // Use the extra hash appender to let eg SSL variants separately cache.
1321 $key = wfMemcKey( $name . $wgRenderHashAppend );
1322 $cachedNotice = $parserMemc->get( $key );
1323 if( is_array( $cachedNotice ) ) {
1324 if( md5( $notice ) == $cachedNotice['hash'] ) {
1325 $notice = $cachedNotice['html'];
1326 } else {
1327 $needParse = true;
1328 }
1329 } else {
1330 $needParse = true;
1331 }
1332
1333 if ( $needParse ) {
1334 $parsed = $this->getOutput()->parse( $notice );
1335 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1336 $notice = $parsed;
1337 }
1338
1339 $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
1340 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $notice );
1341 wfProfileOut( __METHOD__ );
1342 return $notice;
1343 }
1344
1345 /**
1346 * Get a notice based on page's namespace
1347 *
1348 * @return String: HTML fragment
1349 */
1350 function getNamespaceNotice() {
1351 wfProfileIn( __METHOD__ );
1352
1353 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1354 $namespaceNotice = $this->getCachedNotice( $key );
1355 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
1356 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1357 } else {
1358 $namespaceNotice = '';
1359 }
1360
1361 wfProfileOut( __METHOD__ );
1362 return $namespaceNotice;
1363 }
1364
1365 /**
1366 * Get the site notice
1367 *
1368 * @return String: HTML fragment
1369 */
1370 function getSiteNotice() {
1371 wfProfileIn( __METHOD__ );
1372 $siteNotice = '';
1373
1374 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1375 if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1376 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1377 } else {
1378 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1379 if ( !$anonNotice ) {
1380 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1381 } else {
1382 $siteNotice = $anonNotice;
1383 }
1384 }
1385 if ( !$siteNotice ) {
1386 $siteNotice = $this->getCachedNotice( 'default' );
1387 }
1388 }
1389
1390 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1391 wfProfileOut( __METHOD__ );
1392 return $siteNotice;
1393 }
1394
1395 /**
1396 * Create a section edit link. This supersedes editSectionLink() and
1397 * editSectionLinkForOther().
1398 *
1399 * @param $nt Title The title being linked to (may not be the same as
1400 * $wgTitle, if the section is included from a template)
1401 * @param $section string The designation of the section being pointed to,
1402 * to be included in the link, like "&section=$section"
1403 * @param $tooltip string The tooltip to use for the link: will be escaped
1404 * and wrapped in the 'editsectionhint' message
1405 * @param $lang string Language code
1406 * @return string HTML to use for edit link
1407 */
1408 public function doEditSectionLink( Title $nt, $section, $tooltip = null, $lang = false ) {
1409 // HTML generated here should probably have userlangattributes
1410 // added to it for LTR text on RTL pages
1411 $attribs = array();
1412 if ( !is_null( $tooltip ) ) {
1413 # Bug 25462: undo double-escaping.
1414 $tooltip = Sanitizer::decodeCharReferences( $tooltip );
1415 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1416 }
1417 $link = Linker::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1418 $attribs,
1419 array( 'action' => 'edit', 'section' => $section ),
1420 array( 'noclasses', 'known' )
1421 );
1422
1423 # Run the old hook. This takes up half of the function . . . hopefully
1424 # we can rid of it someday.
1425 $attribs = '';
1426 if ( $tooltip ) {
1427 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1428 $attribs = " title=\"$attribs\"";
1429 }
1430 $result = null;
1431 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1432 if ( !is_null( $result ) ) {
1433 # For reverse compatibility, add the brackets *after* the hook is
1434 # run, and even add them to hook-provided text. (This is the main
1435 # reason that the EditSectionLink hook is deprecated in favor of
1436 # DoEditSectionLink: it can't change the brackets or the span.)
1437 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1438 return "<span class=\"editsection\">$result</span>";
1439 }
1440
1441 # Add the brackets and the span, and *then* run the nice new hook, with
1442 # clean and non-redundant arguments.
1443 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1444 $result = "<span class=\"editsection\">$result</span>";
1445
1446 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1447 return $result;
1448 }
1449
1450 /**
1451 * Use PHP's magic __call handler to intercept legacy calls to the linker
1452 * for backwards compatibility.
1453 *
1454 * @param $fname String Name of called method
1455 * @param $args Array Arguments to the method
1456 */
1457 function __call( $fname, $args ) {
1458 $realFunction = array( 'Linker', $fname );
1459 if ( is_callable( $realFunction ) ) {
1460 return call_user_func_array( $realFunction, $args );
1461 } else {
1462 $className = get_class( $this );
1463 throw new MWException( "Call to undefined method $className::$fname" );
1464 }
1465 }
1466
1467 }