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