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