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