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