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