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