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