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