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