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