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