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