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