47use Wikimedia\Assert\Assert;
50use Wikimedia\RemexHtml\Serializer\SerializerNode;
110 $target, $html =
null, $customAttribs = [], $query = [], $options = []
113 wfWarn( __METHOD__ .
': Requires $target to be a LinkTarget object.', 2 );
114 return "<!-- ERROR -->$html";
118 $options = (array)$options;
121 $linkRenderer = $services->getLinkRendererFactory()
122 ->createFromLegacyOptions( $options );
124 $linkRenderer = $services->getLinkRenderer();
127 if ( $html !==
null ) {
133 if ( in_array(
'known', $options,
true ) ) {
134 return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
137 if ( in_array(
'broken', $options,
true ) ) {
138 return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
141 if ( in_array(
'noclasses', $options,
true ) ) {
142 return $linkRenderer->makePreloadedLink( $target, $text,
'', $customAttribs, $query );
145 return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
168 $target, $html =
null, $customAttribs = [],
169 $query = [], $options = [
'known' ]
171 return self::link( $target, $html, $customAttribs, $query, $options );
191 public static function makeSelfLinkObj( $nt, $html =
'', $query =
'', $trail =
'', $prefix =
'', $hash =
'' ) {
192 $nt = Title::newFromLinkTarget( $nt );
195 $attrs[
'class'] =
'mw-selflink-fragment';
196 $attrs[
'href'] =
'#' . $hash;
199 $attrs[
'class'] =
'mw-selflink selflink';
201 $ret = Html::rawElement(
'a', $attrs, $prefix . $html ) . $trail;
203 if ( !$hookRunner->onSelfLinkBegin( $nt, $html, $trail, $prefix, $ret ) ) {
208 $html = htmlspecialchars( $nt->getPrefixedText() );
211 return Html::rawElement(
'a', $attrs, $prefix . $html . $inside ) . $trail;
228 $name = $context->
msg(
'blanknamespace' )->text();
231 getFormattedNsText( $namespace );
233 return $context->
msg(
'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
236 return $context->
msg(
'invalidtitle-unknownnamespace', $namespace, $title )->text();
247 private static function fnamePart(
$url ) {
248 $basename = strrchr(
$url,
'/' );
249 if ( $basename ===
false ) {
252 $basename = substr( $basename, 1 );
269 $alt = self::fnamePart(
$url );
273 ->onLinkerMakeExternalImage(
$url, $alt, $img );
275 wfDebug(
"Hook LinkerMakeExternalImage changed the output of external image "
276 .
"with url {$url} and alt text {$alt} to {$img}" );
326 $file, $frameParams = [], $handlerParams = [], $time =
false,
327 $query =
'', $widthOption =
null
329 $title = Title::newFromLinkTarget( $title );
332 if ( !$hookRunner->onImageBeforeProduceHTML(
null, $title,
334 $file, $frameParams, $handlerParams, $time, $res,
336 $parser, $query, $widthOption )
341 if ( $file && !$file->allowInlineDisplay() ) {
342 wfDebug( __METHOD__ .
': ' . $title->getPrefixedDBkey() .
' does not allow inline display' );
347 $page = $handlerParams[
'page'] ??
false;
348 if ( !isset( $frameParams[
'align'] ) ) {
349 $frameParams[
'align'] =
'';
351 if ( !isset( $frameParams[
'title'] ) ) {
352 $frameParams[
'title'] =
'';
354 if ( !isset( $frameParams[
'class'] ) ) {
355 $frameParams[
'class'] =
'';
359 $config = $services->getMainConfig();
364 !isset( $handlerParams[
'width'] ) &&
365 !isset( $frameParams[
'manualthumb'] ) &&
366 !isset( $frameParams[
'framed'] )
368 $classes[] =
'mw-default-size';
371 $prefix = $postfix =
'';
373 if ( $enableLegacyMediaDOM ) {
374 if ( $frameParams[
'align'] ==
'center' ) {
375 $prefix =
'<div class="center">';
377 $frameParams[
'align'] =
'none';
381 if ( $file && !isset( $handlerParams[
'width'] ) ) {
382 if ( isset( $handlerParams[
'height'] ) && $file->isVectorized() ) {
386 $handlerParams[
'width'] = $svgMaxSize;
388 $handlerParams[
'width'] = $file->getWidth( $page );
391 if ( isset( $frameParams[
'thumbnail'] )
392 || isset( $frameParams[
'manualthumb'] )
393 || isset( $frameParams[
'framed'] )
394 || isset( $frameParams[
'frameless'] )
395 || !$handlerParams[
'width']
399 if ( $widthOption ===
null || !isset( $thumbLimits[$widthOption] ) ) {
400 $userOptionsLookup = $services->getUserOptionsLookup();
405 if ( isset( $frameParams[
'upright'] ) && $frameParams[
'upright'] == 0 ) {
406 $frameParams[
'upright'] = $thumbUpright;
412 $prefWidth = isset( $frameParams[
'upright'] ) ?
413 round( $thumbLimits[$widthOption] * $frameParams[
'upright'], -1 ) :
414 $thumbLimits[$widthOption];
418 if ( !isset( $handlerParams[
'height'] ) && ( $handlerParams[
'width'] <= 0 ||
419 $prefWidth < $handlerParams[
'width'] || $file->isVectorized() ) ) {
420 $handlerParams[
'width'] = $prefWidth;
426 $hasVisibleCaption = isset( $frameParams[
'thumbnail'] ) ||
427 isset( $frameParams[
'manualthumb'] ) ||
428 isset( $frameParams[
'framed'] );
430 if ( $hasVisibleCaption ) {
431 if ( $enableLegacyMediaDOM ) {
436 # Create a thumbnail. Alignment depends on the writing direction of
437 # the page content language (right-aligned for LTR languages,
438 # left-aligned for RTL languages)
439 # If a thumbnail width has not been provided, it is set
440 # to the default user option as specified in Language*.php
441 if ( $frameParams[
'align'] ==
'' ) {
446 $title, $file, $frameParams, $handlerParams, $time, $query,
451 $rdfaType =
'mw:File';
453 if ( isset( $frameParams[
'frameless'] ) ) {
454 $rdfaType .=
'/Frameless';
456 $srcWidth = $file->getWidth( $page );
457 # For "frameless" option: do not present an image bigger than the
458 # source (for bitmap-style images). This is the same behavior as the
459 # "thumb" option does it already.
460 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
461 $handlerParams[
'width'] = $srcWidth;
466 if ( $file && isset( $handlerParams[
'width'] ) ) {
467 # Create a resized image, without the additional thumbnail features
468 $thumb = $file->transform( $handlerParams );
473 $isBadFile = $file && $thumb &&
476 if ( !$thumb || ( !$enableLegacyMediaDOM && $thumb->isError() ) || $isBadFile ) {
477 $rdfaType =
'mw:Error ' . $rdfaType;
478 $currentExists = $file && $file->exists();
479 if ( $enableLegacyMediaDOM ) {
480 $label = $frameParams[
'title'];
482 if ( $currentExists && !$thumb ) {
483 $label =
wfMessage(
'thumbnail_error',
'' )->text();
484 } elseif ( $thumb && $thumb->isError() ) {
487 'Unknown MediaTransformOutput: ' . get_class( $thumb )
489 $label = $thumb->toText();
491 $label = $frameParams[
'alt'] ??
'';
495 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams, $currentExists
503 if ( isset( $frameParams[
'alt'] ) ) {
504 $params[
'alt'] = $frameParams[
'alt'];
506 $params[
'title'] = $frameParams[
'title'];
507 if ( $enableLegacyMediaDOM ) {
509 'valign' => $frameParams[
'valign'] ??
false,
510 'img-class' => $frameParams[
'class'],
512 if ( isset( $frameParams[
'border'] ) ) {
513 $params[
'img-class'] .= ( $params[
'img-class'] !==
'' ?
' ' :
'' ) .
'thumbborder';
517 'img-class' =>
'mw-file-element',
521 $s = $thumb->toHtml( $params );
524 if ( $enableLegacyMediaDOM ) {
525 if ( $frameParams[
'align'] !=
'' ) {
526 $s = Html::rawElement(
528 [
'class' =>
'float' . $frameParams[
'align'] ],
532 return str_replace(
"\n",
' ', $prefix . $s . $postfix );
538 if ( $frameParams[
'align'] !=
'' ) {
541 $classes[] =
"mw-halign-{$frameParams['align']}";
542 $caption = Html::rawElement(
543 'figcaption', [], $frameParams[
'caption'] ??
''
545 } elseif ( isset( $frameParams[
'valign'] ) ) {
549 $classes[] =
"mw-valign-{$frameParams['valign']}";
552 if ( isset( $frameParams[
'border'] ) ) {
553 $classes[] =
'mw-image-border';
556 if ( isset( $frameParams[
'class'] ) ) {
557 $classes[] = $frameParams[
'class'];
562 'typeof' => $rdfaType,
565 $s = Html::rawElement( $wrapper, $attribs, $s . $caption );
567 return str_replace(
"\n",
' ', $s );
580 if ( isset( $frameParams[
'link-url'] ) && $frameParams[
'link-url'] !==
'' ) {
581 $mtoParams[
'custom-url-link'] = $frameParams[
'link-url'];
582 if ( isset( $frameParams[
'link-target'] ) ) {
583 $mtoParams[
'custom-target-link'] = $frameParams[
'link-target'];
586 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams[
'link-url'] );
587 foreach ( $extLinkAttrs as $name => $val ) {
589 $mtoParams[
'parser-extlink-' . $name] = $val;
592 } elseif ( isset( $frameParams[
'link-title'] ) && $frameParams[
'link-title'] !==
'' ) {
594 $mtoParams[
'custom-title-link'] = Title::newFromLinkTarget(
595 $linkRenderer->normalizeTarget( $frameParams[
'link-title'] )
597 if ( isset( $frameParams[
'link-title-query'] ) ) {
598 $mtoParams[
'custom-title-link-query'] = $frameParams[
'link-title-query'];
600 } elseif ( !empty( $frameParams[
'no-link'] ) ) {
603 $mtoParams[
'desc-link'] =
true;
604 $mtoParams[
'desc-query'] = $query;
622 LinkTarget $title, $file, $label =
'', $alt =
'', $align =
null,
623 $params = [], $framed =
false, $manualthumb =
''
631 if ( $manualthumb ) {
632 $frameParams[
'manualthumb'] = $manualthumb;
633 } elseif ( $framed ) {
634 $frameParams[
'framed'] =
true;
635 } elseif ( !isset( $params[
'width'] ) ) {
636 $classes[] =
'mw-default-size';
639 $title, $file, $frameParams, $params,
false,
'', $classes
655 LinkTarget $title, $file, $frameParams = [], $handlerParams = [],
656 $time =
false, $query =
'', array $classes = [], ?
Parser $parser =
null
658 $exists = $file && $file->exists();
663 $page = $handlerParams[
'page'] ??
false;
664 $lang = $handlerParams[
'lang'] ??
false;
666 if ( !isset( $frameParams[
'align'] ) ) {
667 $frameParams[
'align'] =
'';
668 if ( $enableLegacyMediaDOM ) {
669 $frameParams[
'align'] =
'right';
672 if ( !isset( $frameParams[
'caption'] ) ) {
673 $frameParams[
'caption'] =
'';
676 if ( empty( $handlerParams[
'width'] ) ) {
678 $handlerParams[
'width'] = isset( $frameParams[
'upright'] ) ? 130 : 180;
683 $manualthumb =
false;
685 $rdfaType =
'mw:File/Thumb';
689 if ( !isset( $frameParams[
'manualthumb'] ) && isset( $frameParams[
'framed'] ) ) {
690 $rdfaType =
'mw:File/Frame';
692 $outerWidth = $handlerParams[
'width'] + 2;
694 if ( isset( $frameParams[
'manualthumb'] ) ) {
695 # Use manually specified thumbnail
696 $manual_title = Title::makeTitleSafe(
NS_FILE, $frameParams[
'manualthumb'] );
697 if ( $manual_title ) {
698 $manual_img = $services->getRepoGroup()
699 ->findFile( $manual_title );
701 $thumb = $manual_img->getUnscaledThumb( $handlerParams );
706 $srcWidth = $file->getWidth( $page );
707 if ( isset( $frameParams[
'framed'] ) ) {
708 $rdfaType =
'mw:File/Frame';
709 if ( !$file->isVectorized() ) {
715 $handlerParams[
'width'] = $srcWidth;
721 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
722 $handlerParams[
'width'] = $srcWidth;
726 ? $file->getUnscaledThumb( $handlerParams )
727 : $file->transform( $handlerParams );
731 $outerWidth = $thumb->getWidth() + 2;
733 $outerWidth = $handlerParams[
'width'] + 2;
737 if ( !$enableLegacyMediaDOM && $parser && $rdfaType ===
'mw:File/Thumb' ) {
738 $parser->getOutput()->addModules( [
'mediawiki.page.media' ] );
741 $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
742 $linkTitleQuery = [];
743 if ( $page || $lang ) {
745 $linkTitleQuery[
'page'] = $page;
748 $linkTitleQuery[
'lang'] = $lang;
750 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
751 # So we don't need to pass it here in $query. However, the URL for the
752 # zoom icon still needs it, so we make a unique query for it. See T16771
757 && !isset( $frameParams[
'link-title'] )
758 && !isset( $frameParams[
'link-url'] )
759 && !isset( $frameParams[
'no-link'] ) ) {
760 $frameParams[
'link-title'] = $title;
761 $frameParams[
'link-title-query'] = $linkTitleQuery;
764 if ( $frameParams[
'align'] !=
'' ) {
766 $classes[] =
"mw-halign-{$frameParams['align']}";
769 if ( isset( $frameParams[
'class'] ) ) {
770 $classes[] = $frameParams[
'class'];
775 if ( $enableLegacyMediaDOM ) {
776 $s .=
"<div class=\"thumb t{$frameParams['align']}\">"
777 .
"<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
780 $isBadFile = $exists && $thumb && $parser &&
781 $parser->getBadFileLookup()->isBadFile(
782 $manualthumb ? $manual_title : $title->
getDBkey(),
787 $rdfaType =
'mw:Error ' . $rdfaType;
789 if ( !$enableLegacyMediaDOM ) {
790 $label = $frameParams[
'alt'] ??
'';
793 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
false
796 } elseif ( !$thumb || ( !$enableLegacyMediaDOM && $thumb->isError() ) || $isBadFile ) {
797 $rdfaType =
'mw:Error ' . $rdfaType;
798 if ( $enableLegacyMediaDOM ) {
800 $s .=
wfMessage(
'thumbnail_error',
'' )->escaped();
803 $title,
'',
'',
'',
'', (
bool)$time, $handlerParams,
true
807 if ( $thumb && $thumb->isError() ) {
810 'Unknown MediaTransformOutput: ' . get_class( $thumb )
812 $label = $thumb->toText();
813 } elseif ( !$thumb ) {
814 $label =
wfMessage(
'thumbnail_error',
'' )->text();
819 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
true
824 if ( !$noscale && !$manualthumb ) {
831 if ( isset( $frameParams[
'alt'] ) ) {
832 $params[
'alt'] = $frameParams[
'alt'];
834 if ( $enableLegacyMediaDOM ) {
836 'img-class' => ( isset( $frameParams[
'class'] ) && $frameParams[
'class'] !==
''
837 ? $frameParams[
'class'] .
' '
838 :
'' ) .
'thumbimage'
842 'img-class' =>
'mw-file-element',
845 if ( $rdfaType ===
'mw:File/Thumb' ) {
846 $params[
'magnify-resource'] =
$url;
850 $s .= $thumb->toHtml( $params );
851 if ( isset( $frameParams[
'framed'] ) ) {
854 $zoomIcon = Html::rawElement(
'div', [
'class' =>
'magnify' ],
855 Html::rawElement(
'a', [
857 'class' =>
'internal',
858 'title' =>
wfMessage(
'thumbnail-more' )->text(),
864 if ( $enableLegacyMediaDOM ) {
865 $s .=
' <div class="thumbcaption">' . $zoomIcon . $frameParams[
'caption'] .
'</div></div></div>';
866 return str_replace(
"\n",
' ', $s );
869 $s .= Html::rawElement(
870 'figcaption', [], $frameParams[
'caption'] ??
''
875 'typeof' => $rdfaType,
878 $s = Html::rawElement(
'figure', $attribs, $s );
880 return str_replace(
"\n",
' ', $s );
893 if ( $responsiveImages && $thumb && !$thumb->isError() ) {
895 $hp15[
'width'] = round( $hp[
'width'] * 1.5 );
897 $hp20[
'width'] = $hp[
'width'] * 2;
898 if ( isset( $hp[
'height'] ) ) {
899 $hp15[
'height'] = round( $hp[
'height'] * 1.5 );
900 $hp20[
'height'] = $hp[
'height'] * 2;
903 $thumb15 = $file->transform( $hp15 );
904 $thumb20 = $file->transform( $hp20 );
905 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
906 $thumb->responsiveUrls[
'1.5'] = $thumb15->getUrl();
908 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
909 $thumb->responsiveUrls[
'2'] = $thumb20->getUrl();
929 $title, $label =
'', $query =
'', $unused1 =
'', $unused2 =
'',
930 $time =
false, array $handlerParams = [],
bool $currentExists =
false
933 wfWarn( __METHOD__ .
': Requires $title to be a LinkTarget object.' );
934 return "<!-- ERROR -->" . htmlspecialchars( $label );
937 $title = Title::newFromLinkTarget( $title );
939 $mainConfig = $services->getMainConfig();
943 if ( $label ==
'' ) {
944 $label = $title->getPrefixedText();
948 'class' =>
'mw-file-element mw-broken-media',
950 'data-width' => $handlerParams[
'width'] ??
null,
951 'data-height' => $handlerParams[
'height'] ??
null,
955 $html = htmlspecialchars( $label, ENT_COMPAT );
958 $repoGroup = $services->getRepoGroup();
959 $currentExists = $currentExists ||
960 ( $time && $repoGroup->findFile( $title ) !== false );
962 if ( ( $uploadMissingFileUrl || $uploadNavigationUrl || $enableUploads )
966 $title->inNamespace(
NS_FILE ) &&
967 $repoGroup->getLocalRepo()->checkRedirect( $title )
973 [
'class' =>
'mw-redirect' ],
975 [
'known',
'noclasses' ]
978 return Html::rawElement(
'a', [
979 'href' => self::getUploadUrl( $title, $query ),
981 'title' => $title->getPrefixedText()
989 [
'known',
'noclasses' ]
1005 $q =
'wpDestFile=' . Title::newFromLinkTarget( $destFile )->getPartialURL();
1006 if ( $query !=
'' ) {
1010 if ( $uploadMissingFileUrl ) {
1014 if ( $uploadNavigationUrl ) {
1020 return $upload->getLocalURL( $q );
1034 $title, [
'time' => $time ]
1052 if ( $file && $file->exists() ) {
1053 $url = $file->getUrl();
1054 $class =
'internal';
1061 if ( $html ==
'' ) {
1073 Title::newFromLinkTarget( $title ), $file, $html, $attribs, $ret )
1075 wfDebug(
"Hook LinkerMakeMediaLinkFile changed the output of link "
1076 .
"with url {$url} and text {$html} to {$ret}" );
1080 return Html::rawElement(
'a', $attribs, $html );
1094 $queryPos = strpos( $name,
'?' );
1095 if ( $queryPos !==
false ) {
1096 $getParams =
wfCgiToArray( substr( $name, $queryPos + 1 ) );
1097 $name = substr( $name, 0, $queryPos );
1102 $slashPos = strpos( $name,
'/' );
1103 if ( $slashPos !==
false ) {
1104 $subpage = substr( $name, $slashPos + 1 );
1105 $name = substr( $name, 0, $slashPos );
1111 $key = strtolower( $name );
1143 $linktype =
'', $attribs = [], $title =
null
1148 return $linkRenderer->makeExternalLink(
1150 $escape ? $text :
new HtmlArmor( $text ),
1174 $altUserName =
false,
1177 if ( $userName ===
'' || $userName ===
false || $userName ===
null ) {
1178 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1179 'that need to be fixed?' );
1180 return wfMessage(
'empty-username' )->parse();
1186 RequestContext::getMain(),
1187 $altUserName ===
false ?
null : (string)$altUserName,
1211 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null
1215 $talkable = !( $disableAnonTalk && $userId == 0 );
1217 $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
1219 if ( $userId == 0 && ExternalUserNames::isExternal( $userText ) ) {
1231 $attribs[
'class'] =
'mw-usertoollinks-contribs';
1232 if ( $redContribsWhenNoEdits ) {
1233 if ( $edits ===
null ) {
1234 $user = UserIdentityValue::newRegistered( $userId, $userText );
1235 $edits = $services->getUserEditTracker()->getUserEditCount( $user );
1237 if ( $edits === 0 ) {
1240 $attribs[
'class'] .=
' mw-usertoollinks-contribs-no-edits';
1247 $userCanBlock = RequestContext::getMain()->getAuthority()->isAllowed(
'block' );
1248 if ( $blockable && $userCanBlock ) {
1255 ->newEmailUser( RequestContext::getMain()->
getAuthority() )
1262 (
new HookRunner( $services->getHookContainer() ) )->onUserToolLinksEdit( $userId, $userText, $items );
1281 if ( $useParentheses ) {
1282 return wfMessage(
'word-separator' )->escaped()
1283 .
'<span class="mw-usertoollinks">'
1284 .
wfMessage(
'parentheses' )->rawParams(
$wgLang->pipeList( $items ) )->escaped()
1289 foreach ( $items as $tool ) {
1290 $tools[] = Html::rawElement(
'span', [], $tool );
1292 return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1293 implode(
' ', $tools ) .
'</span>';
1311 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null,
1312 $useParentheses =
true
1314 if ( $userText ===
'' ) {
1315 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1316 'that need to be fixed?' );
1317 return ' ' .
wfMessage(
'empty-username' )->parse();
1320 $items = self::userToolLinkArray( $userId, $userText, $redContribsWhenNoEdits, $flags, $edits );
1321 return self::renderUserToolLinksArray( $items, $useParentheses );
1334 $userId, $userText, $edits =
null, $useParentheses =
true
1336 return self::userToolLinks( $userId, $userText,
true, 0, $edits, $useParentheses );
1346 if ( $userText ===
'' ) {
1347 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1348 'that need to be fixed?' );
1349 return wfMessage(
'empty-username' )->parse();
1352 $userTalkPage = TitleValue::tryNew(
NS_USER_TALK, strtr( $userText,
' ',
'_' ) );
1353 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-talk' ];
1354 $linkText =
wfMessage(
'talkpagelinktext' )->escaped();
1356 return $userTalkPage
1357 ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1358 : Html::rawElement(
'span', $moreLinkAttribs, $linkText );
1368 if ( $userText ===
'' ) {
1369 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1370 'that need to be fixed?' );
1371 return wfMessage(
'empty-username' )->parse();
1374 $blockPage = SpecialPage::getTitleFor(
'Block', $userText );
1375 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-block' ];
1377 return self::link( $blockPage,
1389 if ( $userText ===
'' ) {
1390 wfLogWarning( __METHOD__ .
' received an empty username. Are there database errors ' .
1391 'that need to be fixed?' );
1392 return wfMessage(
'empty-username' )->parse();
1395 $emailPage = SpecialPage::getTitleFor(
'Emailuser', $userText );
1396 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-mail' ];
1397 return self::link( $emailPage,
1416 $authority = RequestContext::getMain()->getAuthority();
1418 $revUser = $revRecord->
getUser(
1419 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1423 $link = self::userLink( $revUser->getId(), $revUser->getName() );
1426 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1429 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1430 $class = self::getRevisionDeletedClass( $revRecord );
1431 return '<span class="' . $class .
'">' . $link .
'</span>';
1443 $class =
'history-deleted';
1444 if ( $revisionRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
1445 $class .=
' mw-history-suppressed';
1465 $useParentheses =
true
1468 $authority = RequestContext::getMain()->getAuthority();
1470 $revUser = $revRecord->
getUser(
1471 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1475 $link = self::userLink(
1477 $revUser->getName(),
1479 [
'data-mw-revid' => $revRecord->
getId() ]
1480 ) . self::userToolLinks(
1482 $revUser->getName(),
1490 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1493 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1494 $class = self::getRevisionDeletedClass( $revRecord );
1495 return ' <span class="' . $class .
' mw-userlink">' . $link .
'</span>';
1511 return HtmlHelper::modifyElements(
1513 static function ( SerializerNode $node ):
bool {
1514 return $node->name ===
'a' && isset( $node->attrs[
'href'] );
1516 static function ( SerializerNode $node ): SerializerNode {
1517 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
1518 $node->attrs[
'href'] =
1519 $urlUtils->expand( $node->attrs[
'href'],
PROTO_RELATIVE ) ??
false;
1534 # :Foobar -- override special treatment of prefix (images, language links)
1535 # /Foobar -- convert to CurrentPage/Foobar
1536 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1537 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1538 # ../Foobar -- convert to CurrentPage/Foobar,
1539 # (from CurrentPage/CurrentSubPage)
1540 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1541 # (from CurrentPage/CurrentSubPage)
1543 $ret = $target; #
default return value is no change
1545 # Some namespaces don't allow subpages,
1546 # so only perform processing if subpages are allowed
1548 $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1549 hasSubpages( $contextTitle->getNamespace() )
1551 $hash = strpos( $target,
'#' );
1552 if ( $hash !==
false ) {
1553 $suffix = substr( $target, $hash );
1554 $target = substr( $target, 0, $hash );
1559 $target = trim( $target );
1560 $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1561 getPrefixedText( $contextTitle );
1562 # Look at the first character
1563 if ( $target !=
'' && $target[0] ===
'/' ) {
1564 # / at end means we don't want the slash to be shown
1566 $trailingSlashes = preg_match_all(
'%(/+)$%', $target, $m );
1567 if ( $trailingSlashes ) {
1568 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1570 $noslash = substr( $target, 1 );
1573 $ret = $contextPrefixedText .
'/' . trim( $noslash ) . $suffix;
1574 if ( $text ===
'' ) {
1575 $text = $target . $suffix;
1576 } #
this might be changed
for ugliness reasons
1578 # check for .. subpage backlinks
1580 $nodotdot = $target;
1581 while ( str_starts_with( $nodotdot,
'../' ) ) {
1583 $nodotdot = substr( $nodotdot, 3 );
1585 if ( $dotdotcount > 0 ) {
1586 $exploded = explode(
'/', $contextPrefixedText );
1587 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1588 $ret = implode(
'/', array_slice( $exploded, 0, -$dotdotcount ) );
1589 # / at the end means don't show full path
1590 if ( substr( $nodotdot, -1, 1 ) ===
'/' ) {
1591 $nodotdot = rtrim( $nodotdot,
'/' );
1592 if ( $text ===
'' ) {
1593 $text = $nodotdot . $suffix;
1596 $nodotdot = trim( $nodotdot );
1597 if ( $nodotdot !=
'' ) {
1598 $ret .=
'/' . $nodotdot;
1616 $stxt =
wfMessage(
'historyempty' )->escaped();
1618 $stxt =
wfMessage(
'nbytes' )->numParams( $size )->escaped();
1620 return "<span class=\"history-size mw-diff-bytes\" data-mw-bytes=\"$size\">$stxt</span>";
1630 $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1632 if ( $trail !==
'' && preg_match( $regex, $trail, $m ) ) {
1633 [ , $inside, $trail ] = $m;
1635 return [ $inside, $trail ];
1673 $context ??= RequestContext::getMain();
1675 $editCount = self::getRollbackEditCount( $revRecord );
1676 if ( $editCount ===
false ) {
1680 $inner = self::buildRollbackLink( $revRecord, $context, $editCount );
1682 $services = MediaWikiServices::getInstance();
1685 if ( !(
new HookRunner( $services->getHookContainer() ) )->onLinkerGenerateRollbackLink(
1686 $revRecord, $context, $options, $inner ) ) {
1690 if ( !in_array(
'noBrackets', $options,
true ) ) {
1691 $inner = $context->msg(
'brackets' )->rawParams( $inner )->escaped();
1694 if ( $services->getUserOptionsLookup()
1695 ->getBoolOption( $context->getUser(),
'showrollbackconfirmation' )
1697 $services->getStatsFactory()
1698 ->getCounter(
'rollbackconfirmation_event_load_total' )
1699 ->copyToStatsdAt(
'rollbackconfirmation.event.load' )
1701 $context->getOutput()->addModules(
'mediawiki.misc-authed-curate' );
1704 return '<span class="mw-rollback-link">' . $inner .
'</span>';
1726 if ( func_num_args() > 1 ) {
1727 wfDeprecated( __METHOD__ .
' with $verify parameter',
'1.40' );
1729 $showRollbackEditCount = MediaWikiServices::getInstance()->getMainConfig()
1730 ->get( MainConfigNames::ShowRollbackEditCount );
1732 if ( !is_int( $showRollbackEditCount ) || !$showRollbackEditCount > 0 ) {
1737 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
1740 $queryBuilder = MediaWikiServices::getInstance()->getRevisionStore()->newSelectQueryBuilder( $dbr );
1741 $res = $queryBuilder->where( [
'rev_page' => $revRecord->
getPageId() ] )
1742 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
1743 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC )
1744 ->limit( $showRollbackEditCount + 1 )
1745 ->caller( __METHOD__ )->fetchResultSet();
1747 $revUser = $revRecord->
getUser( RevisionRecord::RAW );
1748 $revUserText = $revUser ? $revUser->getName() :
'';
1752 foreach ( $res as $row ) {
1753 if ( $row->rev_user_text != $revUserText ) {
1754 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1755 || $row->rev_deleted & RevisionRecord::DELETED_USER
1768 if ( $editCount <= $showRollbackEditCount && !$moreRevs ) {
1796 $config = MediaWikiServices::getInstance()->getMainConfig();
1797 $showRollbackEditCount = $config->get( MainConfigNames::ShowRollbackEditCount );
1798 $miserMode = $config->get( MainConfigNames::MiserMode );
1800 $disableRollbackEditCountSpecialPage = [
'Recentchanges',
'Watchlist' ];
1802 $context ??= RequestContext::getMain();
1805 $revUser = $revRecord->
getUser();
1806 $revUserText = $revUser ? $revUser->getName() :
'';
1809 'action' =>
'rollback',
1810 'from' => $revUserText,
1811 'token' => $context->getUser()->getEditToken(
'rollback' ),
1815 'data-mw' =>
'interface',
1816 'title' => $context->msg(
'tooltip-rollback' )->text()
1819 $options = [
'known',
'noclasses' ];
1821 if ( $context->getRequest()->getBool(
'bot' ) ) {
1823 $query[
'hidediff'] =
'1';
1824 $query[
'bot'] =
'1';
1828 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1829 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1830 $showRollbackEditCount =
false;
1837 $msg = [
'rollbacklink' ];
1838 if ( is_int( $showRollbackEditCount ) && $showRollbackEditCount > 0 ) {
1839 if ( !is_numeric( $editCount ) ) {
1840 $editCount = self::getRollbackEditCount( $revRecord );
1843 if ( $editCount > $showRollbackEditCount ) {
1844 $msg = [
'rollbacklinkcount-morethan', Message::numParam( $showRollbackEditCount ) ];
1845 } elseif ( $editCount ) {
1846 $msg = [
'rollbacklinkcount', Message::numParam( $editCount ) ];
1850 $html = $context->msg( ...$msg )->parse();
1851 return self::link( $title, $html, $attrs, $query, $options );
1864 if ( count( $hiddencats ) > 0 ) {
1865 # Construct the HTML
1866 $outText =
'<div class="mw-hiddenCategoriesExplanation">';
1867 $outText .=
wfMessage(
'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1868 $outText .=
"</div><ul>\n";
1870 foreach ( $hiddencats as $titleObj ) {
1871 # If it's hidden, it must exist - no need to check with a LinkBatch
1873 . self::link( $titleObj,
null, [], [],
'known' )
1876 $outText .=
'</ul>';
1884 private static function getContextFromMain() {
1885 $context = RequestContext::getMain();
1907 public static function titleAttrib( $name, $options =
null, array $msgParams = [], $localizer =
null ) {
1908 if ( !$localizer ) {
1909 $localizer = self::getContextFromMain();
1911 $message = $localizer->msg(
"tooltip-$name", $msgParams );
1914 if ( !$message->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1915 $message = $localizer->msg(
'tooltip-ca-nstab' );
1918 if ( $message->isDisabled() ) {
1921 $tooltip = $message->text();
1922 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1923 $tooltip = preg_replace(
"/ ?\[alt-.\]$/",
'', $tooltip );
1926 $options = (array)$options;
1928 if ( in_array(
'nonexisting', $options ) ) {
1929 $tooltip = $localizer->msg(
'red-link-title', $tooltip ?:
'' )->text();
1931 if ( in_array(
'withaccess', $options ) ) {
1932 $accesskey = self::accesskey( $name, $localizer );
1933 if ( $accesskey !==
false ) {
1935 if ( $tooltip ===
false || $tooltip ===
'' ) {
1936 $tooltip = $localizer->msg(
'brackets', $accesskey )->text();
1938 $tooltip .= $localizer->msg(
'word-separator' )->text();
1939 $tooltip .= $localizer->msg(
'brackets', $accesskey )->text();
1962 public static function accesskey( $name, $localizer =
null ) {
1963 if ( !isset( self::$accesskeycache[$name] ) ) {
1964 if ( !$localizer ) {
1965 $localizer = self::getContextFromMain();
1967 $msg = $localizer->msg(
"accesskey-$name" );
1970 if ( !$msg->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1971 $msg = $localizer->msg(
'accesskey-ca-nstab' );
1973 self::$accesskeycache[$name] = $msg->isDisabled() ? false : $msg->plain();
1975 return self::$accesskeycache[$name];
1997 $canHide = $performer->
isAllowed(
'deleterevision' );
1998 $canHideHistory = $performer->
isAllowed(
'deletedhistory' );
1999 if ( !$canHide && !( $revRecord->
getVisibility() && $canHideHistory ) ) {
2003 if ( !$revRecord->
userCan( RevisionRecord::DELETED_RESTRICTED, $performer ) ) {
2004 return self::revDeleteLinkDisabled( $canHide );
2006 $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
2007 getPrefixedDBkey( $title );
2008 if ( $revRecord->
getId() ) {
2012 'type' =>
'revision',
2013 'target' => $prefixedDbKey,
2014 'ids' => $revRecord->
getId()
2020 'type' =>
'archive',
2021 'target' => $prefixedDbKey,
2025 return self::revDeleteLink(
2027 $revRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ),
2044 public static function revDeleteLink( $query = [], $restricted =
false, $delete =
true ) {
2045 $sp = SpecialPage::getTitleFor(
'Revisiondelete' );
2046 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
2047 $html =
wfMessage( $msgKey )->escaped();
2048 $tag = $restricted ?
'strong' :
'span';
2049 $link = self::link( $sp, $html, [], $query, [
'known',
'noclasses' ] );
2050 return Html::rawElement(
2052 [
'class' =>
'mw-revdelundel-link' ],
2053 wfMessage(
'parentheses' )->rawParams( $link )->escaped()
2069 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
2070 $html =
wfMessage( $msgKey )->escaped();
2071 $htmlParentheses =
wfMessage(
'parentheses' )->rawParams( $html )->escaped();
2072 return Html::rawElement(
'span', [
'class' =>
'mw-revdelundel-link' ], $htmlParentheses );
2090 array $msgParams = [],
2094 $options = (array)$options;
2095 $options[] =
'withaccess';
2098 if ( !$localizer ) {
2099 $localizer = self::getContextFromMain();
2103 'title' => self::titleAttrib( $name, $options, $msgParams, $localizer ),
2104 'accesskey' => self::accesskey( $name, $localizer )
2106 if ( $attribs[
'title'] ===
false ) {
2107 unset( $attribs[
'title'] );
2109 if ( $attribs[
'accesskey'] ===
false ) {
2110 unset( $attribs[
'accesskey'] );
2122 public static function tooltip( $name, $options =
null ) {
2123 $tooltip = self::titleAttrib( $name, $options );
2124 if ( $tooltip ===
false ) {
2127 return Html::expandAttributes( [
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgTitle
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
An IContextSource implementation which will inherit context from another source but allow individual ...
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
const UploadNavigationUrl
Name constant for the UploadNavigationUrl setting, for use with Config::get()
const ThumbUpright
Name constant for the ThumbUpright setting, for use with Config::get()
const EnableUploads
Name constant for the EnableUploads setting, for use with Config::get()
const SVGMaxSize
Name constant for the SVGMaxSize setting, for use with Config::get()
const ResponsiveImages
Name constant for the ResponsiveImages setting, for use with Config::get()
const DisableAnonTalk
Name constant for the DisableAnonTalk setting, for use with Config::get()
const ParserEnableLegacyMediaDOM
Name constant for the ParserEnableLegacyMediaDOM setting, for use with Config::get()
const ThumbLimits
Name constant for the ThumbLimits setting, for use with Config::get()
const UploadMissingFileUrl
Name constant for the UploadMissingFileUrl setting, for use with Config::get()
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.
msg( $key,... $params)
This is the method for getting translated interface messages.