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