Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Linker often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Linker, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
34 | class Linker { |
||
35 | /** |
||
36 | * Flags for userToolLinks() |
||
37 | */ |
||
38 | const TOOL_LINKS_NOBLOCK = 1; |
||
39 | const TOOL_LINKS_EMAIL = 2; |
||
40 | |||
41 | /** |
||
42 | * Get the appropriate HTML attributes to add to the "a" element of an interwiki link. |
||
43 | * |
||
44 | * @since 1.16.3 |
||
45 | * @deprecated since 1.25 |
||
46 | * |
||
47 | * @param string $title The title text for the link, URL-encoded (???) but |
||
48 | * not HTML-escaped |
||
49 | * @param string $unused Unused |
||
50 | * @param string $class The contents of the class attribute; if an empty |
||
51 | * string is passed, which is the default value, defaults to 'external'. |
||
52 | * @return string |
||
53 | */ |
||
54 | static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) { |
||
67 | |||
68 | /** |
||
69 | * Get the appropriate HTML attributes to add to the "a" element of an internal link. |
||
70 | * |
||
71 | * @since 1.16.3 |
||
72 | * @deprecated since 1.25 |
||
73 | * |
||
74 | * @param string $title The title text for the link, URL-encoded (???) but |
||
75 | * not HTML-escaped |
||
76 | * @param string $unused Unused |
||
77 | * @param string $class The contents of the class attribute, default none |
||
78 | * @return string |
||
79 | */ |
||
80 | static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) { |
||
87 | |||
88 | /** |
||
89 | * Get the appropriate HTML attributes to add to the "a" element of an internal |
||
90 | * link, given the Title object for the page we want to link to. |
||
91 | * |
||
92 | * @since 1.16.3 |
||
93 | * @deprecated since 1.25 |
||
94 | * |
||
95 | * @param Title $nt |
||
96 | * @param string $unused Unused |
||
97 | * @param string $class The contents of the class attribute, default none |
||
98 | * @param string|bool $title Optional (unescaped) string to use in the title |
||
99 | * attribute; if false, default to the name of the page we're linking to |
||
100 | * @return string |
||
101 | */ |
||
102 | static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) { |
||
110 | |||
111 | /** |
||
112 | * Common code for getLinkAttributesX functions |
||
113 | * |
||
114 | * @since 1.16.3 |
||
115 | * @deprecated since 1.25 |
||
116 | * |
||
117 | * @param string $title |
||
118 | * @param string $class |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | private static function getLinkAttributesInternal( $title, $class ) { |
||
136 | |||
137 | /** |
||
138 | * Return the CSS colour of a known link |
||
139 | * |
||
140 | * @deprecated since 1.28, use LinkRenderer::getLinkClasses() instead |
||
141 | * |
||
142 | * @since 1.16.3 |
||
143 | * @param LinkTarget $t |
||
144 | * @param int $threshold User defined threshold |
||
145 | * @return string CSS class |
||
146 | */ |
||
147 | public static function getLinkColour( LinkTarget $t, $threshold ) { |
||
159 | |||
160 | /** |
||
161 | * This function returns an HTML link to the given target. It serves a few |
||
162 | * purposes: |
||
163 | * 1) If $target is a Title, the correct URL to link to will be figured |
||
164 | * out automatically. |
||
165 | * 2) It automatically adds the usual classes for various types of link |
||
166 | * targets: "new" for red links, "stub" for short articles, etc. |
||
167 | * 3) It escapes all attribute values safely so there's no risk of XSS. |
||
168 | * 4) It provides a default tooltip if the target is a Title (the page |
||
169 | * name of the target). |
||
170 | * link() replaces the old functions in the makeLink() family. |
||
171 | * |
||
172 | * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18. |
||
173 | * @deprecated since 1.28, use MediaWiki\Linker\LinkRenderer instead |
||
174 | * |
||
175 | * @param Title $target Can currently only be a Title, but this may |
||
176 | * change to support Images, literal URLs, etc. |
||
177 | * @param string $html The HTML contents of the <a> element, i.e., |
||
178 | * the link text. This is raw HTML and will not be escaped. If null, |
||
179 | * defaults to the prefixed text of the Title; or if the Title is just a |
||
180 | * fragment, the contents of the fragment. |
||
181 | * @param array $customAttribs A key => value array of extra HTML attributes, |
||
182 | * such as title and class. (href is ignored.) Classes will be |
||
183 | * merged with the default classes, while other attributes will replace |
||
184 | * default attributes. All passed attribute values will be HTML-escaped. |
||
185 | * A false attribute value means to suppress that attribute. |
||
186 | * @param array $query The query string to append to the URL |
||
187 | * you're linking to, in key => value array form. Query keys and values |
||
188 | * will be URL-encoded. |
||
189 | * @param string|array $options String or array of strings: |
||
190 | * 'known': Page is known to exist, so don't check if it does. |
||
191 | * 'broken': Page is known not to exist, so don't check if it does. |
||
192 | * 'noclasses': Don't add any classes automatically (includes "new", |
||
193 | * "stub", "mw-redirect", "extiw"). Only use the class attribute |
||
194 | * provided, if any, so you get a simple blue link with no funny i- |
||
195 | * cons. |
||
196 | * 'forcearticlepath': Use the article path always, even with a querystring. |
||
197 | * Has compatibility issues on some setups, so avoid wherever possible. |
||
198 | * 'http': Force a full URL with http:// as the scheme. |
||
199 | * 'https': Force a full URL with https:// as the scheme. |
||
200 | * 'stubThreshold' => (int): Stub threshold to use when determining link classes. |
||
201 | * @return string HTML <a> attribute |
||
202 | */ |
||
203 | public static function link( |
||
246 | |||
247 | /** |
||
248 | * Identical to link(), except $options defaults to 'known'. |
||
249 | * |
||
250 | * @since 1.16.3 |
||
251 | * @deprecated since 1.28, use MediaWiki\Linker\LinkRenderer instead |
||
252 | * @see Linker::link |
||
253 | * @return string |
||
254 | */ |
||
255 | public static function linkKnown( |
||
261 | |||
262 | /** |
||
263 | * Make appropriate markup for a link to the current article. This is |
||
264 | * currently rendered as the bold link text. The calling sequence is the |
||
265 | * same as the other make*LinkObj static functions, despite $query not |
||
266 | * being used. |
||
267 | * |
||
268 | * @since 1.16.3 |
||
269 | * @param Title $nt |
||
270 | * @param string $html [optional] |
||
271 | * @param string $query [optional] |
||
272 | * @param string $trail [optional] |
||
273 | * @param string $prefix [optional] |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) { |
||
289 | |||
290 | /** |
||
291 | * Get a message saying that an invalid title was encountered. |
||
292 | * This should be called after a method like Title::makeTitleSafe() returned |
||
293 | * a value indicating that the title object is invalid. |
||
294 | * |
||
295 | * @param IContextSource $context Context to use to get the messages |
||
296 | * @param int $namespace Namespace number |
||
297 | * @param string $title Text of the title, without the namespace part |
||
298 | * @return string |
||
299 | */ |
||
300 | public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) { |
||
315 | |||
316 | /** |
||
317 | * @since 1.16.3 |
||
318 | * @param LinkTarget $target |
||
319 | * @return LinkTarget |
||
320 | */ |
||
321 | public static function normaliseSpecialPage( LinkTarget $target ) { |
||
322 | if ( $target->getNamespace() == NS_SPECIAL && !$target->isExternal() ) { |
||
323 | list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $target->getDBkey() ); |
||
324 | if ( !$name ) { |
||
325 | return $target; |
||
326 | } |
||
327 | $ret = SpecialPage::getTitleValueFor( $name, $subpage, $target->getFragment() ); |
||
328 | return $ret; |
||
329 | } else { |
||
330 | return $target; |
||
331 | } |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * Returns the filename part of an url. |
||
336 | * Used as alternative text for external images. |
||
337 | * |
||
338 | * @param string $url |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | private static function fnamePart( $url ) { |
||
351 | |||
352 | /** |
||
353 | * Return the code for images which were added via external links, |
||
354 | * via Parser::maybeMakeExternalImage(). |
||
355 | * |
||
356 | * @since 1.16.3 |
||
357 | * @param string $url |
||
358 | * @param string $alt |
||
359 | * |
||
360 | * @return string |
||
361 | */ |
||
362 | public static function makeExternalImage( $url, $alt = '' ) { |
||
378 | |||
379 | /** |
||
380 | * Given parameters derived from [[Image:Foo|options...]], generate the |
||
381 | * HTML that that syntax inserts in the page. |
||
382 | * |
||
383 | * @param Parser $parser |
||
384 | * @param Title $title Title object of the file (not the currently viewed page) |
||
385 | * @param File $file File object, or false if it doesn't exist |
||
386 | * @param array $frameParams Associative array of parameters external to the media handler. |
||
387 | * Boolean parameters are indicated by presence or absence, the value is arbitrary and |
||
388 | * will often be false. |
||
389 | * thumbnail If present, downscale and frame |
||
390 | * manualthumb Image name to use as a thumbnail, instead of automatic scaling |
||
391 | * framed Shows image in original size in a frame |
||
392 | * frameless Downscale but don't frame |
||
393 | * upright If present, tweak default sizes for portrait orientation |
||
394 | * upright_factor Fudge factor for "upright" tweak (default 0.75) |
||
395 | * border If present, show a border around the image |
||
396 | * align Horizontal alignment (left, right, center, none) |
||
397 | * valign Vertical alignment (baseline, sub, super, top, text-top, middle, |
||
398 | * bottom, text-bottom) |
||
399 | * alt Alternate text for image (i.e. alt attribute). Plain text. |
||
400 | * class HTML for image classes. Plain text. |
||
401 | * caption HTML for image caption. |
||
402 | * link-url URL to link to |
||
403 | * link-title Title object to link to |
||
404 | * link-target Value for the target attribute, only with link-url |
||
405 | * no-link Boolean, suppress description link |
||
406 | * |
||
407 | * @param array $handlerParams Associative array of media handler parameters, to be passed |
||
408 | * to transform(). Typical keys are "width" and "page". |
||
409 | * @param string|bool $time Timestamp of the file, set as false for current |
||
410 | * @param string $query Query params for desc url |
||
411 | * @param int|null $widthOption Used by the parser to remember the user preference thumbnailsize |
||
412 | * @since 1.20 |
||
413 | * @return string HTML for an image, with links, wrappers, etc. |
||
414 | */ |
||
415 | public static function makeImageLink( Parser $parser, Title $title, |
||
416 | $file, $frameParams = [], $handlerParams = [], $time = false, |
||
417 | $query = "", $widthOption = null |
||
418 | ) { |
||
419 | $res = null; |
||
420 | $dummy = new DummyLinker; |
||
421 | if ( !Hooks::run( 'ImageBeforeProduceHTML', [ &$dummy, &$title, |
||
422 | &$file, &$frameParams, &$handlerParams, &$time, &$res ] ) ) { |
||
423 | return $res; |
||
424 | } |
||
425 | |||
426 | if ( $file && !$file->allowInlineDisplay() ) { |
||
427 | wfDebug( __METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" ); |
||
428 | return self::link( $title ); |
||
429 | } |
||
430 | |||
431 | // Clean up parameters |
||
432 | $page = isset( $handlerParams['page'] ) ? $handlerParams['page'] : false; |
||
433 | if ( !isset( $frameParams['align'] ) ) { |
||
434 | $frameParams['align'] = ''; |
||
435 | } |
||
436 | if ( !isset( $frameParams['alt'] ) ) { |
||
437 | $frameParams['alt'] = ''; |
||
438 | } |
||
439 | if ( !isset( $frameParams['title'] ) ) { |
||
440 | $frameParams['title'] = ''; |
||
441 | } |
||
442 | if ( !isset( $frameParams['class'] ) ) { |
||
443 | $frameParams['class'] = ''; |
||
444 | } |
||
445 | |||
446 | $prefix = $postfix = ''; |
||
447 | |||
448 | if ( 'center' == $frameParams['align'] ) { |
||
449 | $prefix = '<div class="center">'; |
||
450 | $postfix = '</div>'; |
||
451 | $frameParams['align'] = 'none'; |
||
452 | } |
||
453 | if ( $file && !isset( $handlerParams['width'] ) ) { |
||
454 | if ( isset( $handlerParams['height'] ) && $file->isVectorized() ) { |
||
455 | // If its a vector image, and user only specifies height |
||
456 | // we don't want it to be limited by its "normal" width. |
||
457 | global $wgSVGMaxSize; |
||
458 | $handlerParams['width'] = $wgSVGMaxSize; |
||
459 | } else { |
||
460 | $handlerParams['width'] = $file->getWidth( $page ); |
||
461 | } |
||
462 | |||
463 | if ( isset( $frameParams['thumbnail'] ) |
||
464 | || isset( $frameParams['manualthumb'] ) |
||
465 | || isset( $frameParams['framed'] ) |
||
466 | || isset( $frameParams['frameless'] ) |
||
467 | || !$handlerParams['width'] |
||
468 | ) { |
||
469 | global $wgThumbLimits, $wgThumbUpright; |
||
470 | |||
471 | if ( $widthOption === null || !isset( $wgThumbLimits[$widthOption] ) ) { |
||
472 | $widthOption = User::getDefaultOption( 'thumbsize' ); |
||
473 | } |
||
474 | |||
475 | // Reduce width for upright images when parameter 'upright' is used |
||
476 | if ( isset( $frameParams['upright'] ) && $frameParams['upright'] == 0 ) { |
||
477 | $frameParams['upright'] = $wgThumbUpright; |
||
478 | } |
||
479 | |||
480 | // For caching health: If width scaled down due to upright |
||
481 | // parameter, round to full __0 pixel to avoid the creation of a |
||
482 | // lot of odd thumbs. |
||
483 | $prefWidth = isset( $frameParams['upright'] ) ? |
||
484 | round( $wgThumbLimits[$widthOption] * $frameParams['upright'], -1 ) : |
||
485 | $wgThumbLimits[$widthOption]; |
||
486 | |||
487 | // Use width which is smaller: real image width or user preference width |
||
488 | // Unless image is scalable vector. |
||
489 | if ( !isset( $handlerParams['height'] ) && ( $handlerParams['width'] <= 0 || |
||
490 | $prefWidth < $handlerParams['width'] || $file->isVectorized() ) ) { |
||
491 | $handlerParams['width'] = $prefWidth; |
||
492 | } |
||
493 | } |
||
494 | } |
||
495 | |||
496 | if ( isset( $frameParams['thumbnail'] ) || isset( $frameParams['manualthumb'] ) |
||
497 | || isset( $frameParams['framed'] ) |
||
498 | ) { |
||
499 | # Create a thumbnail. Alignment depends on the writing direction of |
||
500 | # the page content language (right-aligned for LTR languages, |
||
501 | # left-aligned for RTL languages) |
||
502 | # If a thumbnail width has not been provided, it is set |
||
503 | # to the default user option as specified in Language*.php |
||
504 | if ( $frameParams['align'] == '' ) { |
||
505 | $frameParams['align'] = $parser->getTargetLanguage()->alignEnd(); |
||
506 | } |
||
507 | return $prefix . |
||
508 | self::makeThumbLink2( $title, $file, $frameParams, $handlerParams, $time, $query ) . |
||
509 | $postfix; |
||
510 | } |
||
511 | |||
512 | if ( $file && isset( $frameParams['frameless'] ) ) { |
||
513 | $srcWidth = $file->getWidth( $page ); |
||
514 | # For "frameless" option: do not present an image bigger than the |
||
515 | # source (for bitmap-style images). This is the same behavior as the |
||
516 | # "thumb" option does it already. |
||
517 | View Code Duplication | if ( $srcWidth && !$file->mustRender() && $handlerParams['width'] > $srcWidth ) { |
|
518 | $handlerParams['width'] = $srcWidth; |
||
519 | } |
||
520 | } |
||
521 | |||
522 | if ( $file && isset( $handlerParams['width'] ) ) { |
||
523 | # Create a resized image, without the additional thumbnail features |
||
524 | $thumb = $file->transform( $handlerParams ); |
||
525 | } else { |
||
526 | $thumb = false; |
||
527 | } |
||
528 | |||
529 | if ( !$thumb ) { |
||
530 | $s = self::makeBrokenImageLinkObj( $title, $frameParams['title'], '', '', '', $time == true ); |
||
531 | } else { |
||
532 | self::processResponsiveImages( $file, $thumb, $handlerParams ); |
||
533 | $params = [ |
||
534 | 'alt' => $frameParams['alt'], |
||
535 | 'title' => $frameParams['title'], |
||
536 | 'valign' => isset( $frameParams['valign'] ) ? $frameParams['valign'] : false, |
||
537 | 'img-class' => $frameParams['class'] ]; |
||
538 | if ( isset( $frameParams['border'] ) ) { |
||
539 | $params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder'; |
||
540 | } |
||
541 | $params = self::getImageLinkMTOParams( $frameParams, $query, $parser ) + $params; |
||
542 | |||
543 | $s = $thumb->toHtml( $params ); |
||
544 | } |
||
545 | if ( $frameParams['align'] != '' ) { |
||
546 | $s = "<div class=\"float{$frameParams['align']}\">{$s}</div>"; |
||
547 | } |
||
548 | return str_replace( "\n", ' ', $prefix . $s . $postfix ); |
||
549 | } |
||
550 | |||
551 | /** |
||
552 | * Get the link parameters for MediaTransformOutput::toHtml() from given |
||
553 | * frame parameters supplied by the Parser. |
||
554 | * @param array $frameParams The frame parameters |
||
555 | * @param string $query An optional query string to add to description page links |
||
556 | * @param Parser|null $parser |
||
557 | * @return array |
||
558 | */ |
||
559 | private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) { |
||
560 | $mtoParams = []; |
||
561 | if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) { |
||
562 | $mtoParams['custom-url-link'] = $frameParams['link-url']; |
||
563 | if ( isset( $frameParams['link-target'] ) ) { |
||
564 | $mtoParams['custom-target-link'] = $frameParams['link-target']; |
||
565 | } |
||
566 | if ( $parser ) { |
||
567 | $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] ); |
||
568 | foreach ( $extLinkAttrs as $name => $val ) { |
||
569 | // Currently could include 'rel' and 'target' |
||
570 | $mtoParams['parser-extlink-' . $name] = $val; |
||
571 | } |
||
572 | } |
||
573 | } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) { |
||
574 | $mtoParams['custom-title-link'] = Title::newFromLinkTarget( |
||
575 | self::normaliseSpecialPage( $frameParams['link-title'] ) |
||
576 | ); |
||
577 | } elseif ( !empty( $frameParams['no-link'] ) ) { |
||
578 | // No link |
||
579 | } else { |
||
580 | $mtoParams['desc-link'] = true; |
||
581 | $mtoParams['desc-query'] = $query; |
||
582 | } |
||
583 | return $mtoParams; |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * Make HTML for a thumbnail including image, border and caption |
||
588 | * @param Title $title |
||
589 | * @param File|bool $file File object or false if it doesn't exist |
||
590 | * @param string $label |
||
591 | * @param string $alt |
||
592 | * @param string $align |
||
593 | * @param array $params |
||
594 | * @param bool $framed |
||
595 | * @param string $manualthumb |
||
596 | * @return string |
||
597 | */ |
||
598 | public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt, |
||
614 | |||
615 | /** |
||
616 | * @param Title $title |
||
617 | * @param File $file |
||
618 | * @param array $frameParams |
||
619 | * @param array $handlerParams |
||
620 | * @param bool $time |
||
621 | * @param string $query |
||
622 | * @return string |
||
623 | */ |
||
624 | public static function makeThumbLink2( Title $title, $file, $frameParams = [], |
||
625 | $handlerParams = [], $time = false, $query = "" |
||
626 | ) { |
||
627 | $exists = $file && $file->exists(); |
||
628 | |||
629 | $page = isset( $handlerParams['page'] ) ? $handlerParams['page'] : false; |
||
630 | if ( !isset( $frameParams['align'] ) ) { |
||
631 | $frameParams['align'] = 'right'; |
||
632 | } |
||
633 | if ( !isset( $frameParams['alt'] ) ) { |
||
634 | $frameParams['alt'] = ''; |
||
635 | } |
||
636 | if ( !isset( $frameParams['title'] ) ) { |
||
637 | $frameParams['title'] = ''; |
||
638 | } |
||
639 | if ( !isset( $frameParams['caption'] ) ) { |
||
640 | $frameParams['caption'] = ''; |
||
641 | } |
||
642 | |||
643 | if ( empty( $handlerParams['width'] ) ) { |
||
644 | // Reduce width for upright images when parameter 'upright' is used |
||
645 | $handlerParams['width'] = isset( $frameParams['upright'] ) ? 130 : 180; |
||
646 | } |
||
647 | $thumb = false; |
||
648 | $noscale = false; |
||
649 | $manualthumb = false; |
||
650 | |||
651 | if ( !$exists ) { |
||
652 | $outerWidth = $handlerParams['width'] + 2; |
||
653 | } else { |
||
654 | if ( isset( $frameParams['manualthumb'] ) ) { |
||
655 | # Use manually specified thumbnail |
||
656 | $manual_title = Title::makeTitleSafe( NS_FILE, $frameParams['manualthumb'] ); |
||
657 | if ( $manual_title ) { |
||
658 | $manual_img = wfFindFile( $manual_title ); |
||
659 | if ( $manual_img ) { |
||
660 | $thumb = $manual_img->getUnscaledThumb( $handlerParams ); |
||
661 | $manualthumb = true; |
||
662 | } else { |
||
663 | $exists = false; |
||
664 | } |
||
665 | } |
||
666 | } elseif ( isset( $frameParams['framed'] ) ) { |
||
667 | // Use image dimensions, don't scale |
||
668 | $thumb = $file->getUnscaledThumb( $handlerParams ); |
||
669 | $noscale = true; |
||
670 | } else { |
||
671 | # Do not present an image bigger than the source, for bitmap-style images |
||
672 | # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior |
||
673 | $srcWidth = $file->getWidth( $page ); |
||
674 | View Code Duplication | if ( $srcWidth && !$file->mustRender() && $handlerParams['width'] > $srcWidth ) { |
|
675 | $handlerParams['width'] = $srcWidth; |
||
676 | } |
||
677 | $thumb = $file->transform( $handlerParams ); |
||
678 | } |
||
679 | |||
680 | if ( $thumb ) { |
||
681 | $outerWidth = $thumb->getWidth() + 2; |
||
682 | } else { |
||
683 | $outerWidth = $handlerParams['width'] + 2; |
||
684 | } |
||
685 | } |
||
686 | |||
687 | # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs |
||
688 | # So we don't need to pass it here in $query. However, the URL for the |
||
689 | # zoom icon still needs it, so we make a unique query for it. See bug 14771 |
||
690 | $url = $title->getLocalURL( $query ); |
||
691 | if ( $page ) { |
||
692 | $url = wfAppendQuery( $url, [ 'page' => $page ] ); |
||
693 | } |
||
694 | if ( $manualthumb |
||
695 | && !isset( $frameParams['link-title'] ) |
||
696 | && !isset( $frameParams['link-url'] ) |
||
697 | && !isset( $frameParams['no-link'] ) ) { |
||
698 | $frameParams['link-url'] = $url; |
||
699 | } |
||
700 | |||
701 | $s = "<div class=\"thumb t{$frameParams['align']}\">" |
||
702 | . "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">"; |
||
703 | |||
704 | if ( !$exists ) { |
||
705 | $s .= self::makeBrokenImageLinkObj( $title, $frameParams['title'], '', '', '', $time == true ); |
||
706 | $zoomIcon = ''; |
||
707 | } elseif ( !$thumb ) { |
||
708 | $s .= wfMessage( 'thumbnail_error', '' )->escaped(); |
||
709 | $zoomIcon = ''; |
||
710 | } else { |
||
711 | if ( !$noscale && !$manualthumb ) { |
||
712 | self::processResponsiveImages( $file, $thumb, $handlerParams ); |
||
713 | } |
||
714 | $params = [ |
||
715 | 'alt' => $frameParams['alt'], |
||
716 | 'title' => $frameParams['title'], |
||
717 | 'img-class' => ( isset( $frameParams['class'] ) && $frameParams['class'] !== '' |
||
718 | ? $frameParams['class'] . ' ' |
||
719 | : '' ) . 'thumbimage' |
||
720 | ]; |
||
721 | $params = self::getImageLinkMTOParams( $frameParams, $query ) + $params; |
||
722 | $s .= $thumb->toHtml( $params ); |
||
723 | if ( isset( $frameParams['framed'] ) ) { |
||
724 | $zoomIcon = ""; |
||
725 | } else { |
||
726 | $zoomIcon = Html::rawElement( 'div', [ 'class' => 'magnify' ], |
||
727 | Html::rawElement( 'a', [ |
||
728 | 'href' => $url, |
||
729 | 'class' => 'internal', |
||
730 | 'title' => wfMessage( 'thumbnail-more' )->text() ], |
||
731 | "" ) ); |
||
732 | } |
||
733 | } |
||
734 | $s .= ' <div class="thumbcaption">' . $zoomIcon . $frameParams['caption'] . "</div></div></div>"; |
||
735 | return str_replace( "\n", ' ', $s ); |
||
736 | } |
||
737 | |||
738 | /** |
||
739 | * Process responsive images: add 1.5x and 2x subimages to the thumbnail, where |
||
740 | * applicable. |
||
741 | * |
||
742 | * @param File $file |
||
743 | * @param MediaTransformOutput $thumb |
||
744 | * @param array $hp Image parameters |
||
745 | */ |
||
746 | public static function processResponsiveImages( $file, $thumb, $hp ) { |
||
768 | |||
769 | /** |
||
770 | * Make a "broken" link to an image |
||
771 | * |
||
772 | * @since 1.16.3 |
||
773 | * @param Title $title |
||
774 | * @param string $label Link label (plain text) |
||
775 | * @param string $query Query string |
||
776 | * @param string $unused1 Unused parameter kept for b/c |
||
777 | * @param string $unused2 Unused parameter kept for b/c |
||
778 | * @param bool $time A file of a certain timestamp was requested |
||
779 | * @return string |
||
780 | */ |
||
781 | public static function makeBrokenImageLinkObj( $title, $label = '', |
||
822 | |||
823 | /** |
||
824 | * Get the URL to upload a certain file |
||
825 | * |
||
826 | * @since 1.16.3 |
||
827 | * @param Title $destFile Title object of the file to upload |
||
828 | * @param string $query Urlencoded query string to prepend |
||
829 | * @return string Urlencoded URL |
||
830 | */ |
||
831 | protected static function getUploadUrl( $destFile, $query = '' ) { |
||
847 | |||
848 | /** |
||
849 | * Create a direct link to a given uploaded file. |
||
850 | * |
||
851 | * @since 1.16.3 |
||
852 | * @param Title $title |
||
853 | * @param string $html Pre-sanitized HTML |
||
854 | * @param string $time MW timestamp of file creation time |
||
855 | * @return string HTML |
||
856 | */ |
||
857 | public static function makeMediaLinkObj( $title, $html = '', $time = false ) { |
||
861 | |||
862 | /** |
||
863 | * Create a direct link to a given uploaded file. |
||
864 | * This will make a broken link if $file is false. |
||
865 | * |
||
866 | * @since 1.16.3 |
||
867 | * @param Title $title |
||
868 | * @param File|bool $file File object or false |
||
869 | * @param string $html Pre-sanitized HTML |
||
870 | * @return string HTML |
||
871 | * |
||
872 | * @todo Handle invalid or missing images better. |
||
873 | */ |
||
874 | public static function makeMediaLinkFile( Title $title, $file, $html = '' ) { |
||
904 | |||
905 | /** |
||
906 | * Make a link to a special page given its name and, optionally, |
||
907 | * a message key from the link text. |
||
908 | * Usage example: Linker::specialLink( 'Recentchanges' ) |
||
909 | * |
||
910 | * @since 1.16.3 |
||
911 | * @param string $name |
||
912 | * @param string $key |
||
913 | * @return string |
||
914 | */ |
||
915 | public static function specialLink( $name, $key = '' ) { |
||
922 | |||
923 | /** |
||
924 | * Make an external link |
||
925 | * @since 1.16.3. $title added in 1.21 |
||
926 | * @param string $url URL to link to |
||
927 | * @param string $text Text of link |
||
928 | * @param bool $escape Do we escape the link text? |
||
929 | * @param string $linktype Type of external link. Gets added to the classes |
||
930 | * @param array $attribs Array of extra attributes to <a> |
||
931 | * @param Title|null $title Title object used for title specific link attributes |
||
932 | * @return string |
||
933 | */ |
||
934 | public static function makeExternalLink( $url, $text, $escape = true, |
||
975 | |||
976 | /** |
||
977 | * Make user link (or user contributions for unregistered users) |
||
978 | * @param int $userId User id in database. |
||
979 | * @param string $userName User name in database. |
||
980 | * @param string $altUserName Text to display instead of the user name (optional) |
||
981 | * @return string HTML fragment |
||
982 | * @since 1.16.3. $altUserName was added in 1.19. |
||
983 | */ |
||
984 | public static function userLink( $userId, $userName, $altUserName = false ) { |
||
985 | $classes = 'mw-userlink'; |
||
986 | if ( $userId == 0 ) { |
||
987 | $page = SpecialPage::getTitleFor( 'Contributions', $userName ); |
||
988 | if ( $altUserName === false ) { |
||
989 | $altUserName = IP::prettifyIP( $userName ); |
||
990 | } |
||
991 | $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179) |
||
992 | } else { |
||
993 | $page = Title::makeTitle( NS_USER, $userName ); |
||
994 | } |
||
995 | |||
996 | // Wrap the output with <bdi> tags for directionality isolation |
||
997 | return self::link( |
||
998 | $page, |
||
999 | '<bdi>' . htmlspecialchars( $altUserName !== false ? $altUserName : $userName ) . '</bdi>', |
||
1000 | [ 'class' => $classes ] |
||
1001 | ); |
||
1002 | } |
||
1003 | |||
1004 | /** |
||
1005 | * Generate standard user tool links (talk, contributions, block link, etc.) |
||
1006 | * |
||
1007 | * @since 1.16.3 |
||
1008 | * @param int $userId User identifier |
||
1009 | * @param string $userText User name or IP address |
||
1010 | * @param bool $redContribsWhenNoEdits Should the contributions link be |
||
1011 | * red if the user has no edits? |
||
1012 | * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK |
||
1013 | * and Linker::TOOL_LINKS_EMAIL). |
||
1014 | * @param int $edits User edit count (optional, for performance) |
||
1015 | * @return string HTML fragment |
||
1016 | */ |
||
1017 | public static function userToolLinks( |
||
1064 | |||
1065 | /** |
||
1066 | * Alias for userToolLinks( $userId, $userText, true ); |
||
1067 | * @since 1.16.3 |
||
1068 | * @param int $userId User identifier |
||
1069 | * @param string $userText User name or IP address |
||
1070 | * @param int $edits User edit count (optional, for performance) |
||
1071 | * @return string |
||
1072 | */ |
||
1073 | public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) { |
||
1076 | |||
1077 | /** |
||
1078 | * @since 1.16.3 |
||
1079 | * @param int $userId User id in database. |
||
1080 | * @param string $userText User name in database. |
||
1081 | * @return string HTML fragment with user talk link |
||
1082 | */ |
||
1083 | public static function userTalkLink( $userId, $userText ) { |
||
1088 | |||
1089 | /** |
||
1090 | * @since 1.16.3 |
||
1091 | * @param int $userId Userid |
||
1092 | * @param string $userText User name in database. |
||
1093 | * @return string HTML fragment with block link |
||
1094 | */ |
||
1095 | public static function blockLink( $userId, $userText ) { |
||
1100 | |||
1101 | /** |
||
1102 | * @param int $userId Userid |
||
1103 | * @param string $userText User name in database. |
||
1104 | * @return string HTML fragment with e-mail user link |
||
1105 | */ |
||
1106 | public static function emailLink( $userId, $userText ) { |
||
1111 | |||
1112 | /** |
||
1113 | * Generate a user link if the current user is allowed to view it |
||
1114 | * @since 1.16.3 |
||
1115 | * @param Revision $rev |
||
1116 | * @param bool $isPublic Show only if all users can see it |
||
1117 | * @return string HTML fragment |
||
1118 | */ |
||
1119 | public static function revUserLink( $rev, $isPublic = false ) { |
||
1133 | |||
1134 | /** |
||
1135 | * Generate a user tool link cluster if the current user is allowed to view it |
||
1136 | * @since 1.16.3 |
||
1137 | * @param Revision $rev |
||
1138 | * @param bool $isPublic Show only if all users can see it |
||
1139 | * @return string HTML |
||
1140 | */ |
||
1141 | public static function revUserTools( $rev, $isPublic = false ) { |
||
1157 | |||
1158 | /** |
||
1159 | * This function is called by all recent changes variants, by the page history, |
||
1160 | * and by the user contributions list. It is responsible for formatting edit |
||
1161 | * summaries. It escapes any HTML in the summary, but adds some CSS to format |
||
1162 | * auto-generated comments (from section editing) and formats [[wikilinks]]. |
||
1163 | * |
||
1164 | * @author Erik Moeller <[email protected]> |
||
1165 | * @since 1.16.3. $wikiId added in 1.26 |
||
1166 | * |
||
1167 | * Note: there's not always a title to pass to this function. |
||
1168 | * Since you can't set a default parameter for a reference, I've turned it |
||
1169 | * temporarily to a value pass. Should be adjusted further. --brion |
||
1170 | * |
||
1171 | * @param string $comment |
||
1172 | * @param Title|null $title Title object (to generate link to the section in autocomment) |
||
1173 | * or null |
||
1174 | * @param bool $local Whether section links should refer to local page |
||
1175 | * @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to. |
||
1176 | * For use with external changes. |
||
1177 | * |
||
1178 | * @return mixed|string |
||
1179 | */ |
||
1180 | public static function formatComment( |
||
1194 | |||
1195 | /** |
||
1196 | * Converts autogenerated comments in edit summaries into section links. |
||
1197 | * |
||
1198 | * The pattern for autogen comments is / * foo * /, which makes for |
||
1199 | * some nasty regex. |
||
1200 | * We look for all comments, match any text before and after the comment, |
||
1201 | * add a separator where needed and format the comment itself with CSS |
||
1202 | * Called by Linker::formatComment. |
||
1203 | * |
||
1204 | * @param string $comment Comment text |
||
1205 | * @param Title|null $title An optional title object used to links to sections |
||
1206 | * @param bool $local Whether section links should refer to local page |
||
1207 | * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), |
||
1208 | * as used by WikiMap. |
||
1209 | * |
||
1210 | * @return string Formatted comment (wikitext) |
||
1211 | */ |
||
1212 | private static function formatAutocomments( |
||
1286 | |||
1287 | /** |
||
1288 | * Formats wiki links and media links in text; all other wiki formatting |
||
1289 | * is ignored |
||
1290 | * |
||
1291 | * @since 1.16.3. $wikiId added in 1.26 |
||
1292 | * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser |
||
1293 | * |
||
1294 | * @param string $comment Text to format links in. WARNING! Since the output of this |
||
1295 | * function is html, $comment must be sanitized for use as html. You probably want |
||
1296 | * to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling |
||
1297 | * this function. |
||
1298 | * @param Title|null $title An optional title object used to links to sections |
||
1299 | * @param bool $local Whether section links should refer to local page |
||
1300 | * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), |
||
1301 | * as used by WikiMap. |
||
1302 | * |
||
1303 | * @return string |
||
1304 | */ |
||
1305 | public static function formatLinksInComment( |
||
1399 | |||
1400 | /** |
||
1401 | * Generates a link to the given Title |
||
1402 | * |
||
1403 | * @note This is only public for technical reasons. It's not intended for use outside Linker. |
||
1404 | * |
||
1405 | * @param Title $title |
||
1406 | * @param string $text |
||
1407 | * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), |
||
1408 | * as used by WikiMap. |
||
1409 | * @param string|string[] $options See the $options parameter in Linker::link. |
||
1410 | * |
||
1411 | * @return string HTML link |
||
1412 | */ |
||
1413 | public static function makeCommentLink( |
||
1432 | |||
1433 | /** |
||
1434 | * @param Title $contextTitle |
||
1435 | * @param string $target |
||
1436 | * @param string $text |
||
1437 | * @return string |
||
1438 | */ |
||
1439 | public static function normalizeSubpageLink( $contextTitle, $target, &$text ) { |
||
1511 | |||
1512 | /** |
||
1513 | * Wrap a comment in standard punctuation and formatting if |
||
1514 | * it's non-empty, otherwise return empty string. |
||
1515 | * |
||
1516 | * @since 1.16.3. $wikiId added in 1.26 |
||
1517 | * @param string $comment |
||
1518 | * @param Title|null $title Title object (to generate link to section in autocomment) or null |
||
1519 | * @param bool $local Whether section links should refer to local page |
||
1520 | * @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to. |
||
1521 | * For use with external changes. |
||
1522 | * |
||
1523 | * @return string |
||
1524 | */ |
||
1525 | public static function commentBlock( |
||
1539 | |||
1540 | /** |
||
1541 | * Wrap and format the given revision's comment block, if the current |
||
1542 | * user is allowed to view it. |
||
1543 | * |
||
1544 | * @since 1.16.3 |
||
1545 | * @param Revision $rev |
||
1546 | * @param bool $local Whether section links should refer to local page |
||
1547 | * @param bool $isPublic Show only if all users can see it |
||
1548 | * @return string HTML fragment |
||
1549 | */ |
||
1550 | public static function revComment( Revision $rev, $local = false, $isPublic = false ) { |
||
1567 | |||
1568 | /** |
||
1569 | * @since 1.16.3 |
||
1570 | * @param int $size |
||
1571 | * @return string |
||
1572 | */ |
||
1573 | public static function formatRevisionSize( $size ) { |
||
1582 | |||
1583 | /** |
||
1584 | * Add another level to the Table of Contents |
||
1585 | * |
||
1586 | * @since 1.16.3 |
||
1587 | * @return string |
||
1588 | */ |
||
1589 | public static function tocIndent() { |
||
1592 | |||
1593 | /** |
||
1594 | * Finish one or more sublevels on the Table of Contents |
||
1595 | * |
||
1596 | * @since 1.16.3 |
||
1597 | * @param int $level |
||
1598 | * @return string |
||
1599 | */ |
||
1600 | public static function tocUnindent( $level ) { |
||
1603 | |||
1604 | /** |
||
1605 | * parameter level defines if we are on an indentation level |
||
1606 | * |
||
1607 | * @since 1.16.3 |
||
1608 | * @param string $anchor |
||
1609 | * @param string $tocline |
||
1610 | * @param string $tocnumber |
||
1611 | * @param string $level |
||
1612 | * @param string|bool $sectionIndex |
||
1613 | * @return string |
||
1614 | */ |
||
1615 | public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) { |
||
1625 | |||
1626 | /** |
||
1627 | * End a Table Of Contents line. |
||
1628 | * tocUnindent() will be used instead if we're ending a line below |
||
1629 | * the new level. |
||
1630 | * @since 1.16.3 |
||
1631 | * @return string |
||
1632 | */ |
||
1633 | public static function tocLineEnd() { |
||
1636 | |||
1637 | /** |
||
1638 | * Wraps the TOC in a table and provides the hide/collapse javascript. |
||
1639 | * |
||
1640 | * @since 1.16.3 |
||
1641 | * @param string $toc Html of the Table Of Contents |
||
1642 | * @param string|Language|bool $lang Language for the toc title, defaults to user language |
||
1643 | * @return string Full html of the TOC |
||
1644 | */ |
||
1645 | public static function tocList( $toc, $lang = false ) { |
||
1654 | |||
1655 | /** |
||
1656 | * Generate a table of contents from a section tree. |
||
1657 | * |
||
1658 | * @since 1.16.3. $lang added in 1.17 |
||
1659 | * @param array $tree Return value of ParserOutput::getSections() |
||
1660 | * @param string|Language|bool $lang Language for the toc title, defaults to user language |
||
1661 | * @return string HTML fragment |
||
1662 | */ |
||
1663 | public static function generateTOC( $tree, $lang = false ) { |
||
1684 | |||
1685 | /** |
||
1686 | * Create a headline for content |
||
1687 | * |
||
1688 | * @since 1.16.3 |
||
1689 | * @param int $level The level of the headline (1-6) |
||
1690 | * @param string $attribs Any attributes for the headline, starting with |
||
1691 | * a space and ending with '>' |
||
1692 | * This *must* be at least '>' for no attribs |
||
1693 | * @param string $anchor The anchor to give the headline (the bit after the #) |
||
1694 | * @param string $html Html for the text of the header |
||
1695 | * @param string $link HTML to add for the section edit link |
||
1696 | * @param bool|string $legacyAnchor A second, optional anchor to give for |
||
1697 | * backward compatibility (false to omit) |
||
1698 | * |
||
1699 | * @return string HTML headline |
||
1700 | */ |
||
1701 | public static function makeHeadline( $level, $attribs, $anchor, $html, |
||
1713 | |||
1714 | /** |
||
1715 | * Split a link trail, return the "inside" portion and the remainder of the trail |
||
1716 | * as a two-element array |
||
1717 | * @param string $trail |
||
1718 | * @return array |
||
1719 | */ |
||
1720 | static function splitTrail( $trail ) { |
||
1733 | |||
1734 | /** |
||
1735 | * Generate a rollback link for a given revision. Currently it's the |
||
1736 | * caller's responsibility to ensure that the revision is the top one. If |
||
1737 | * it's not, of course, the user will get an error message. |
||
1738 | * |
||
1739 | * If the calling page is called with the parameter &bot=1, all rollback |
||
1740 | * links also get that parameter. It causes the edit itself and the rollback |
||
1741 | * to be marked as "bot" edits. Bot edits are hidden by default from recent |
||
1742 | * changes, so this allows sysops to combat a busy vandal without bothering |
||
1743 | * other users. |
||
1744 | * |
||
1745 | * If the option verify is set this function will return the link only in case the |
||
1746 | * revision can be reverted. Please note that due to performance limitations |
||
1747 | * it might be assumed that a user isn't the only contributor of a page while |
||
1748 | * (s)he is, which will lead to useless rollback links. Furthermore this wont |
||
1749 | * work if $wgShowRollbackEditCount is disabled, so this can only function |
||
1750 | * as an additional check. |
||
1751 | * |
||
1752 | * If the option noBrackets is set the rollback link wont be enclosed in "[]". |
||
1753 | * |
||
1754 | * @since 1.16.3. $context added in 1.20. $options added in 1.21 |
||
1755 | * |
||
1756 | * @param Revision $rev |
||
1757 | * @param IContextSource $context Context to use or null for the main context. |
||
1758 | * @param array $options |
||
1759 | * @return string |
||
1760 | */ |
||
1761 | public static function generateRollback( $rev, IContextSource $context = null, |
||
1784 | |||
1785 | /** |
||
1786 | * This function will return the number of revisions which a rollback |
||
1787 | * would revert and, if $verify is set it will verify that a revision |
||
1788 | * can be reverted (that the user isn't the only contributor and the |
||
1789 | * revision we might rollback to isn't deleted). These checks can only |
||
1790 | * function as an additional check as this function only checks against |
||
1791 | * the last $wgShowRollbackEditCount edits. |
||
1792 | * |
||
1793 | * Returns null if $wgShowRollbackEditCount is disabled or false if $verify |
||
1794 | * is set and the user is the only contributor of the page. |
||
1795 | * |
||
1796 | * @param Revision $rev |
||
1797 | * @param bool $verify Try to verify that this revision can really be rolled back |
||
1798 | * @return int|bool|null |
||
1799 | */ |
||
1800 | public static function getRollbackEditCount( $rev, $verify ) { |
||
1850 | |||
1851 | /** |
||
1852 | * Build a raw rollback link, useful for collections of "tool" links |
||
1853 | * |
||
1854 | * @since 1.16.3. $context added in 1.20. $editCount added in 1.21 |
||
1855 | * @param Revision $rev |
||
1856 | * @param IContextSource|null $context Context to use or null for the main context. |
||
1857 | * @param int $editCount Number of edits that would be reverted |
||
1858 | * @return string HTML fragment |
||
1859 | */ |
||
1860 | public static function buildRollbackLink( $rev, IContextSource $context = null, |
||
1920 | |||
1921 | /** |
||
1922 | * @deprecated since 1.28, use TemplatesOnThisPageFormatter directly |
||
1923 | * |
||
1924 | * Returns HTML for the "templates used on this page" list. |
||
1925 | * |
||
1926 | * Make an HTML list of templates, and then add a "More..." link at |
||
1927 | * the bottom. If $more is null, do not add a "More..." link. If $more |
||
1928 | * is a Title, make a link to that title and use it. If $more is a string, |
||
1929 | * directly paste it in as the link (escaping needs to be done manually). |
||
1930 | * Finally, if $more is a Message, call toString(). |
||
1931 | * |
||
1932 | * @since 1.16.3. $more added in 1.21 |
||
1933 | * @param Title[] $templates Array of templates |
||
1934 | * @param bool $preview Whether this is for a preview |
||
1935 | * @param bool $section Whether this is for a section edit |
||
1936 | * @param Title|Message|string|null $more An escaped link for "More..." of the templates |
||
1937 | * @return string HTML output |
||
1938 | */ |
||
1939 | public static function formatTemplates( $templates, $preview = false, |
||
1961 | |||
1962 | /** |
||
1963 | * Returns HTML for the "hidden categories on this page" list. |
||
1964 | * |
||
1965 | * @since 1.16.3 |
||
1966 | * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories |
||
1967 | * or similar |
||
1968 | * @return string HTML output |
||
1969 | */ |
||
1970 | public static function formatHiddenCategories( $hiddencats ) { |
||
1989 | |||
1990 | /** |
||
1991 | * @deprecated since 1.28, use Language::formatSize() directly |
||
1992 | * |
||
1993 | * Format a size in bytes for output, using an appropriate |
||
1994 | * unit (B, KB, MB or GB) according to the magnitude in question |
||
1995 | * |
||
1996 | * @since 1.16.3 |
||
1997 | * @param int $size Size to format |
||
1998 | * @return string |
||
1999 | */ |
||
2000 | public static function formatSize( $size ) { |
||
2006 | |||
2007 | /** |
||
2008 | * Given the id of an interface element, constructs the appropriate title |
||
2009 | * attribute from the system messages. (Note, this is usually the id but |
||
2010 | * isn't always, because sometimes the accesskey needs to go on a different |
||
2011 | * element than the id, for reverse-compatibility, etc.) |
||
2012 | * |
||
2013 | * @since 1.16.3 $msgParams added in 1.27 |
||
2014 | * @param string $name Id of the element, minus prefixes. |
||
2015 | * @param string|null $options Null or the string 'withaccess' to add an access- |
||
2016 | * key hint |
||
2017 | * @param array $msgParams Parameters to pass to the message |
||
2018 | * |
||
2019 | * @return string Contents of the title attribute (which you must HTML- |
||
2020 | * escape), or false for no title attribute |
||
2021 | */ |
||
2022 | public static function titleAttrib( $name, $options = null, array $msgParams = [] ) { |
||
2051 | |||
2052 | public static $accesskeycache; |
||
2053 | |||
2054 | /** |
||
2055 | * Given the id of an interface element, constructs the appropriate |
||
2056 | * accesskey attribute from the system messages. (Note, this is usually |
||
2057 | * the id but isn't always, because sometimes the accesskey needs to go on |
||
2058 | * a different element than the id, for reverse-compatibility, etc.) |
||
2059 | * |
||
2060 | * @since 1.16.3 |
||
2061 | * @param string $name Id of the element, minus prefixes. |
||
2062 | * @return string Contents of the accesskey attribute (which you must HTML- |
||
2063 | * escape), or false for no accesskey attribute |
||
2064 | */ |
||
2065 | public static function accesskey( $name ) { |
||
2087 | |||
2088 | /** |
||
2089 | * Get a revision-deletion link, or disabled link, or nothing, depending |
||
2090 | * on user permissions & the settings on the revision. |
||
2091 | * |
||
2092 | * Will use forward-compatible revision ID in the Special:RevDelete link |
||
2093 | * if possible, otherwise the timestamp-based ID which may break after |
||
2094 | * undeletion. |
||
2095 | * |
||
2096 | * @param User $user |
||
2097 | * @param Revision $rev |
||
2098 | * @param Title $title |
||
2099 | * @return string HTML fragment |
||
2100 | */ |
||
2101 | public static function getRevDeleteLink( User $user, Revision $rev, Title $title ) { |
||
2131 | |||
2132 | /** |
||
2133 | * Creates a (show/hide) link for deleting revisions/log entries |
||
2134 | * |
||
2135 | * @param array $query Query parameters to be passed to link() |
||
2136 | * @param bool $restricted Set to true to use a "<strong>" instead of a "<span>" |
||
2137 | * @param bool $delete Set to true to use (show/hide) rather than (show) |
||
2138 | * |
||
2139 | * @return string HTML "<a>" link to Special:Revisiondelete, wrapped in a |
||
2140 | * span to allow for customization of appearance with CSS |
||
2141 | */ |
||
2142 | public static function revDeleteLink( $query = [], $restricted = false, $delete = true ) { |
||
2154 | |||
2155 | /** |
||
2156 | * Creates a dead (show/hide) link for deleting revisions/log entries |
||
2157 | * |
||
2158 | * @since 1.16.3 |
||
2159 | * @param bool $delete Set to true to use (show/hide) rather than (show) |
||
2160 | * |
||
2161 | * @return string HTML text wrapped in a span to allow for customization |
||
2162 | * of appearance with CSS |
||
2163 | */ |
||
2164 | public static function revDeleteLinkDisabled( $delete = true ) { |
||
2170 | |||
2171 | /* Deprecated methods */ |
||
2172 | |||
2173 | /** |
||
2174 | * Returns the attributes for the tooltip and access key. |
||
2175 | * |
||
2176 | * @since 1.16.3. $msgParams introduced in 1.27 |
||
2177 | * @param string $name |
||
2178 | * @param array $msgParams Params for constructing the message |
||
2179 | * |
||
2180 | * @return array |
||
2181 | */ |
||
2182 | public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = [] ) { |
||
2198 | |||
2199 | /** |
||
2200 | * Returns raw bits of HTML, use titleAttrib() |
||
2201 | * @since 1.16.3 |
||
2202 | * @param string $name |
||
2203 | * @param array|null $options |
||
2204 | * @return null|string |
||
2205 | */ |
||
2206 | public static function tooltip( $name, $options = null ) { |
||
2218 | |||
2219 | } |
||
2220 | |||
2221 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.