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