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