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