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