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