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