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();
363 !isset( $handlerParams[
'width'] ) &&
364 !isset( $frameParams[
'manualthumb'] ) &&
365 !isset( $frameParams[
'framed'] )
367 $classes[] =
'mw-default-size';
370 $prefix = $postfix =
'';
372 if ( $file && !isset( $handlerParams[
'width'] ) ) {
373 if ( isset( $handlerParams[
'height'] ) && $file->isVectorized() ) {
377 $handlerParams[
'width'] = $svgMaxSize;
379 $handlerParams[
'width'] = $file->getWidth( $page );
382 if ( isset( $frameParams[
'thumbnail'] )
383 || isset( $frameParams[
'manualthumb'] )
384 || isset( $frameParams[
'framed'] )
385 || isset( $frameParams[
'frameless'] )
386 || !$handlerParams[
'width']
390 if ( $widthOption ===
null || !isset( $thumbLimits[$widthOption] ) ) {
391 $userOptionsLookup = $services->getUserOptionsLookup();
396 if ( isset( $frameParams[
'upright'] ) && $frameParams[
'upright'] == 0 ) {
397 $frameParams[
'upright'] = $thumbUpright;
403 $prefWidth = isset( $frameParams[
'upright'] ) ?
404 round( $thumbLimits[$widthOption] * $frameParams[
'upright'], -1 ) :
405 $thumbLimits[$widthOption];
409 if ( !isset( $handlerParams[
'height'] ) && ( $handlerParams[
'width'] <= 0 ||
410 $prefWidth < $handlerParams[
'width'] || $file->isVectorized() ) ) {
411 $handlerParams[
'width'] = $prefWidth;
417 $hasVisibleCaption = isset( $frameParams[
'thumbnail'] ) ||
418 isset( $frameParams[
'manualthumb'] ) ||
419 isset( $frameParams[
'framed'] );
421 if ( $hasVisibleCaption ) {
423 $title, $file, $frameParams, $handlerParams, $time, $query,
428 $rdfaType =
'mw:File';
430 if ( isset( $frameParams[
'frameless'] ) ) {
431 $rdfaType .=
'/Frameless';
433 $srcWidth = $file->getWidth( $page );
434 # For "frameless" option: do not present an image bigger than the
435 # source (for bitmap-style images). This is the same behavior as the
436 # "thumb" option does it already.
437 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
438 $handlerParams[
'width'] = $srcWidth;
443 if ( $file && isset( $handlerParams[
'width'] ) ) {
444 # Create a resized image, without the additional thumbnail features
445 $thumb = $file->transform( $handlerParams );
450 $isBadFile = $file && $thumb &&
453 if ( !$thumb || $thumb->isError() || $isBadFile ) {
454 $rdfaType =
'mw:Error ' . $rdfaType;
455 $currentExists = $file && $file->exists();
456 if ( $currentExists && !$thumb ) {
457 $label =
wfMessage(
'thumbnail_error',
'' )->text();
458 } elseif ( $thumb && $thumb->isError() ) {
461 'Unknown MediaTransformOutput: ' . get_class( $thumb )
463 $label = $thumb->toText();
465 $label = $frameParams[
'alt'] ??
'';
468 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams, $currentExists
476 if ( isset( $frameParams[
'alt'] ) ) {
477 $params[
'alt'] = $frameParams[
'alt'];
479 $params[
'title'] = $frameParams[
'title'];
481 'img-class' =>
'mw-file-element',
484 $s = $thumb->toHtml( $params );
490 if ( $frameParams[
'align'] !=
'' ) {
493 $classes[] =
"mw-halign-{$frameParams['align']}";
494 $caption = Html::rawElement(
495 'figcaption', [], $frameParams[
'caption'] ??
''
497 } elseif ( isset( $frameParams[
'valign'] ) ) {
501 $classes[] =
"mw-valign-{$frameParams['valign']}";
504 if ( isset( $frameParams[
'border'] ) ) {
505 $classes[] =
'mw-image-border';
508 if ( isset( $frameParams[
'class'] ) ) {
509 $classes[] = $frameParams[
'class'];
514 'typeof' => $rdfaType,
517 $s = Html::rawElement( $wrapper, $attribs, $s . $caption );
519 return str_replace(
"\n",
' ', $s );
532 if ( isset( $frameParams[
'link-url'] ) && $frameParams[
'link-url'] !==
'' ) {
533 $mtoParams[
'custom-url-link'] = $frameParams[
'link-url'];
534 if ( isset( $frameParams[
'link-target'] ) ) {
535 $mtoParams[
'custom-target-link'] = $frameParams[
'link-target'];
538 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams[
'link-url'] );
539 foreach ( $extLinkAttrs as $name => $val ) {
541 $mtoParams[
'parser-extlink-' . $name] = $val;
544 } elseif ( isset( $frameParams[
'link-title'] ) && $frameParams[
'link-title'] !==
'' ) {
546 $mtoParams[
'custom-title-link'] = Title::newFromLinkTarget(
547 $linkRenderer->normalizeTarget( $frameParams[
'link-title'] )
549 if ( isset( $frameParams[
'link-title-query'] ) ) {
550 $mtoParams[
'custom-title-link-query'] = $frameParams[
'link-title-query'];
552 } elseif ( !empty( $frameParams[
'no-link'] ) ) {
555 $mtoParams[
'desc-link'] =
true;
556 $mtoParams[
'desc-query'] = $query;
574 LinkTarget $title, $file, $label =
'', $alt =
'', $align =
null,
575 $params = [], $framed =
false, $manualthumb =
''
583 if ( $manualthumb ) {
584 $frameParams[
'manualthumb'] = $manualthumb;
585 } elseif ( $framed ) {
586 $frameParams[
'framed'] =
true;
587 } elseif ( !isset( $params[
'width'] ) ) {
588 $classes[] =
'mw-default-size';
591 $title, $file, $frameParams, $params,
false,
'', $classes
607 LinkTarget $title, $file, $frameParams = [], $handlerParams = [],
608 $time =
false, $query =
'', array $classes = [], ?
Parser $parser =
null
610 $exists = $file && $file->exists();
613 $page = $handlerParams[
'page'] ??
false;
614 $lang = $handlerParams[
'lang'] ??
false;
616 if ( !isset( $frameParams[
'align'] ) ) {
617 $frameParams[
'align'] =
'';
619 if ( !isset( $frameParams[
'caption'] ) ) {
620 $frameParams[
'caption'] =
'';
623 if ( empty( $handlerParams[
'width'] ) ) {
625 $handlerParams[
'width'] = isset( $frameParams[
'upright'] ) ? 130 : 180;
630 $manualthumb =
false;
632 $rdfaType =
'mw:File/Thumb';
636 if ( !isset( $frameParams[
'manualthumb'] ) && isset( $frameParams[
'framed'] ) ) {
637 $rdfaType =
'mw:File/Frame';
639 $outerWidth = $handlerParams[
'width'] + 2;
641 if ( isset( $frameParams[
'manualthumb'] ) ) {
642 # Use manually specified thumbnail
643 $manual_title = Title::makeTitleSafe(
NS_FILE, $frameParams[
'manualthumb'] );
644 if ( $manual_title ) {
645 $manual_img = $services->getRepoGroup()
646 ->findFile( $manual_title );
648 $thumb = $manual_img->getUnscaledThumb( $handlerParams );
653 $srcWidth = $file->getWidth( $page );
654 if ( isset( $frameParams[
'framed'] ) ) {
655 $rdfaType =
'mw:File/Frame';
656 if ( !$file->isVectorized() ) {
662 $handlerParams[
'width'] = $srcWidth;
668 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
669 $handlerParams[
'width'] = $srcWidth;
673 ? $file->getUnscaledThumb( $handlerParams )
674 : $file->transform( $handlerParams );
678 $outerWidth = $thumb->getWidth() + 2;
680 $outerWidth = $handlerParams[
'width'] + 2;
684 if ( $parser && $rdfaType ===
'mw:File/Thumb' ) {
685 $parser->getOutput()->addModules( [
'mediawiki.page.media' ] );
688 $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
689 $linkTitleQuery = [];
690 if ( $page || $lang ) {
692 $linkTitleQuery[
'page'] = $page;
695 $linkTitleQuery[
'lang'] = $lang;
697 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
698 # So we don't need to pass it here in $query. However, the URL for the
699 # zoom icon still needs it, so we make a unique query for it. See T16771
704 && !isset( $frameParams[
'link-title'] )
705 && !isset( $frameParams[
'link-url'] )
706 && !isset( $frameParams[
'no-link'] ) ) {
707 $frameParams[
'link-title'] = $title;
708 $frameParams[
'link-title-query'] = $linkTitleQuery;
711 if ( $frameParams[
'align'] !=
'' ) {
713 $classes[] =
"mw-halign-{$frameParams['align']}";
716 if ( isset( $frameParams[
'class'] ) ) {
717 $classes[] = $frameParams[
'class'];
722 $isBadFile = $exists && $thumb && $parser &&
723 $parser->getBadFileLookup()->isBadFile(
724 $manualthumb ? $manual_title : $title->
getDBkey(),
729 $rdfaType =
'mw:Error ' . $rdfaType;
730 $label = $frameParams[
'alt'] ??
'';
732 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
false
735 } elseif ( !$thumb || $thumb->isError() || $isBadFile ) {
736 $rdfaType =
'mw:Error ' . $rdfaType;
737 if ( $thumb && $thumb->isError() ) {
740 'Unknown MediaTransformOutput: ' . get_class( $thumb )
742 $label = $thumb->toText();
743 } elseif ( !$thumb ) {
744 $label =
wfMessage(
'thumbnail_error',
'' )->text();
749 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
true
753 if ( !$noscale && !$manualthumb ) {
760 if ( isset( $frameParams[
'alt'] ) ) {
761 $params[
'alt'] = $frameParams[
'alt'];
764 'img-class' =>
'mw-file-element',
767 if ( $rdfaType ===
'mw:File/Thumb' ) {
768 $params[
'magnify-resource'] =
$url;
771 $s .= $thumb->toHtml( $params );
772 if ( isset( $frameParams[
'framed'] ) ) {
775 $zoomIcon = Html::rawElement(
'div', [
'class' =>
'magnify' ],
776 Html::rawElement(
'a', [
778 'class' =>
'internal',
779 'title' =>
wfMessage(
'thumbnail-more' )->text(),
785 $s .= Html::rawElement(
786 'figcaption', [], $frameParams[
'caption'] ??
''
791 'typeof' => $rdfaType,
794 $s = Html::rawElement(
'figure', $attribs, $s );
796 return str_replace(
"\n",
' ', $s );
809 if ( $responsiveImages && $thumb && !$thumb->isError() ) {
811 $hp15[
'width'] = round( $hp[
'width'] * 1.5 );
813 $hp20[
'width'] = $hp[
'width'] * 2;
814 if ( isset( $hp[
'height'] ) ) {
815 $hp15[
'height'] = round( $hp[
'height'] * 1.5 );
816 $hp20[
'height'] = $hp[
'height'] * 2;
819 $thumb15 = $file->transform( $hp15 );
820 $thumb20 = $file->transform( $hp20 );
821 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
822 $thumb->responsiveUrls[
'1.5'] = $thumb15->getUrl();
824 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
825 $thumb->responsiveUrls[
'2'] = $thumb20->getUrl();
845 $title, $label =
'', $query =
'', $unused1 =
'', $unused2 =
'',
846 $time =
false, array $handlerParams = [],
bool $currentExists =
false
849 wfWarn( __METHOD__ .
': Requires $title to be a LinkTarget object.' );
850 return "<!-- ERROR -->" . htmlspecialchars( $label );
853 $title = Title::newFromLinkTarget( $title );
855 $mainConfig = $services->getMainConfig();
859 if ( $label ==
'' ) {
860 $label = $title->getPrefixedText();
864 'class' =>
'mw-file-element mw-broken-media',
866 'data-width' => $handlerParams[
'width'] ??
null,
867 'data-height' => $handlerParams[
'height'] ??
null,
870 $repoGroup = $services->getRepoGroup();
871 $currentExists = $currentExists ||
872 ( $time && $repoGroup->findFile( $title ) !== false );
874 if ( ( $uploadMissingFileUrl || $uploadNavigationUrl || $enableUploads )
878 $title->inNamespace(
NS_FILE ) &&
879 $repoGroup->getLocalRepo()->checkRedirect( $title )
885 [
'class' =>
'mw-redirect' ],
887 [
'known',
'noclasses' ]
890 return Html::rawElement(
'a', [
891 'href' => self::getUploadUrl( $title, $query ),
893 'title' => $title->getPrefixedText()
901 [
'known',
'noclasses' ]
917 $q =
'wpDestFile=' . Title::newFromLinkTarget( $destFile )->getPartialURL();
918 if ( $query !=
'' ) {
922 if ( $uploadMissingFileUrl ) {
926 if ( $uploadNavigationUrl ) {
932 return $upload->getLocalURL( $q );
946 $title, [
'time' => $time ]
964 if ( $file && $file->exists() ) {
965 $url = $file->getUrl();
985 Title::newFromLinkTarget( $title ), $file, $html, $attribs, $ret )
987 wfDebug(
"Hook LinkerMakeMediaLinkFile changed the output of link "
988 .
"with url {$url} and text {$html} to {$ret}" );
992 return Html::rawElement(
'a', $attribs, $html );
1006 $queryPos = strpos( $name,
'?' );
1007 if ( $queryPos !==
false ) {
1008 $getParams =
wfCgiToArray( substr( $name, $queryPos + 1 ) );
1009 $name = substr( $name, 0, $queryPos );
1014 $slashPos = strpos( $name,
'/' );
1015 if ( $slashPos !==
false ) {
1016 $subpage = substr( $name, $slashPos + 1 );
1017 $name = substr( $name, 0, $slashPos );
1023 $key = strtolower( $name );
1055 $linktype =
'', $attribs = [], $title =
null
1060 return $linkRenderer->makeExternalLink(
1062 $escape ? $text :
new HtmlArmor( $text ),
1086 $altUserName =
false,
1089 if ( $userName ===
'' || $userName ===
false || $userName ===
null ) {
1090 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1091 'that need to be fixed?' );
1092 return wfMessage(
'empty-username' )->parse();
1098 RequestContext::getMain(),
1099 $altUserName ===
false ?
null : (string)$altUserName,
1123 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null
1127 $talkable = !( $disableAnonTalk && $userId == 0 );
1129 $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
1131 if ( $userId == 0 && ExternalUserNames::isExternal( $userText ) ) {
1143 $attribs[
'class'] =
'mw-usertoollinks-contribs';
1144 if ( $redContribsWhenNoEdits ) {
1145 if ( $edits ===
null ) {
1146 $user = UserIdentityValue::newRegistered( $userId, $userText );
1147 $edits = $services->getUserEditTracker()->getUserEditCount( $user );
1149 if ( $edits === 0 ) {
1152 $attribs[
'class'] .=
' mw-usertoollinks-contribs-no-edits';
1159 $userCanBlock = RequestContext::getMain()->getAuthority()->isAllowed(
'block' );
1160 if ( $blockable && $userCanBlock ) {
1167 ->newEmailUser( RequestContext::getMain()->
getAuthority() )
1174 (
new HookRunner( $services->getHookContainer() ) )->onUserToolLinksEdit( $userId, $userText, $items );
1193 if ( $useParentheses ) {
1194 return wfMessage(
'word-separator' )->escaped()
1195 .
'<span class="mw-usertoollinks">'
1196 .
wfMessage(
'parentheses' )->rawParams(
$wgLang->pipeList( $items ) )->escaped()
1201 foreach ( $items as $tool ) {
1202 $tools[] = Html::rawElement(
'span', [], $tool );
1204 return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1205 implode(
' ', $tools ) .
'</span>';
1223 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null,
1224 $useParentheses =
true
1226 if ( $userText ===
'' ) {
1227 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1228 'that need to be fixed?' );
1229 return ' ' .
wfMessage(
'empty-username' )->parse();
1232 $items = self::userToolLinkArray( $userId, $userText, $redContribsWhenNoEdits, $flags, $edits );
1233 return self::renderUserToolLinksArray( $items, $useParentheses );
1246 $userId, $userText, $edits =
null, $useParentheses =
true
1248 return self::userToolLinks( $userId, $userText,
true, 0, $edits, $useParentheses );
1258 if ( $userText ===
'' ) {
1259 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1260 'that need to be fixed?' );
1261 return wfMessage(
'empty-username' )->parse();
1264 $userTalkPage = TitleValue::tryNew(
NS_USER_TALK, strtr( $userText,
' ',
'_' ) );
1265 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-talk' ];
1266 $linkText =
wfMessage(
'talkpagelinktext' )->escaped();
1268 return $userTalkPage
1269 ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1270 : Html::rawElement(
'span', $moreLinkAttribs, $linkText );
1280 if ( $userText ===
'' ) {
1281 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1282 'that need to be fixed?' );
1283 return wfMessage(
'empty-username' )->parse();
1286 $blockPage = SpecialPage::getTitleFor(
'Block', $userText );
1287 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-block' ];
1289 return self::link( $blockPage,
1301 if ( $userText ===
'' ) {
1302 wfLogWarning( __METHOD__ .
' received an empty username. Are there database errors ' .
1303 'that need to be fixed?' );
1304 return wfMessage(
'empty-username' )->parse();
1307 $emailPage = SpecialPage::getTitleFor(
'Emailuser', $userText );
1308 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-mail' ];
1309 return self::link( $emailPage,
1328 $authority = RequestContext::getMain()->getAuthority();
1330 $revUser = $revRecord->
getUser(
1331 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1335 $link = self::userLink( $revUser->getId(), $revUser->getName() );
1338 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1341 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1342 $class = self::getRevisionDeletedClass( $revRecord );
1343 return '<span class="' . $class .
'">' . $link .
'</span>';
1355 $class =
'history-deleted';
1356 if ( $revisionRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
1357 $class .=
' mw-history-suppressed';
1377 $useParentheses =
true
1380 $authority = RequestContext::getMain()->getAuthority();
1382 $revUser = $revRecord->
getUser(
1383 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1387 $link = self::userLink(
1389 $revUser->getName(),
1391 [
'data-mw-revid' => $revRecord->
getId() ]
1392 ) . self::userToolLinks(
1394 $revUser->getName(),
1402 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1405 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1406 $class = self::getRevisionDeletedClass( $revRecord );
1407 return ' <span class="' . $class .
' mw-userlink">' . $link .
'</span>';
1423 return HtmlHelper::modifyElements(
1425 static function ( SerializerNode $node ):
bool {
1426 return $node->name ===
'a' && isset( $node->attrs[
'href'] );
1428 static function ( SerializerNode $node ): SerializerNode {
1429 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
1430 $node->attrs[
'href'] =
1431 $urlUtils->expand( $node->attrs[
'href'],
PROTO_RELATIVE ) ??
false;
1446 # :Foobar -- override special treatment of prefix (images, language links)
1447 # /Foobar -- convert to CurrentPage/Foobar
1448 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1449 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1450 # ../Foobar -- convert to CurrentPage/Foobar,
1451 # (from CurrentPage/CurrentSubPage)
1452 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1453 # (from CurrentPage/CurrentSubPage)
1455 $ret = $target; #
default return value is no change
1457 # Some namespaces don't allow subpages,
1458 # so only perform processing if subpages are allowed
1460 $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1461 hasSubpages( $contextTitle->getNamespace() )
1463 $hash = strpos( $target,
'#' );
1464 if ( $hash !==
false ) {
1465 $suffix = substr( $target, $hash );
1466 $target = substr( $target, 0, $hash );
1471 $target = trim( $target );
1472 $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1473 getPrefixedText( $contextTitle );
1474 # Look at the first character
1475 if ( $target !=
'' && $target[0] ===
'/' ) {
1476 # / at end means we don't want the slash to be shown
1478 $trailingSlashes = preg_match_all(
'%(/+)$%', $target, $m );
1479 if ( $trailingSlashes ) {
1480 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1482 $noslash = substr( $target, 1 );
1485 $ret = $contextPrefixedText .
'/' . trim( $noslash ) . $suffix;
1486 if ( $text ===
'' ) {
1487 $text = $target . $suffix;
1488 } #
this might be changed
for ugliness reasons
1490 # check for .. subpage backlinks
1492 $nodotdot = $target;
1493 while ( str_starts_with( $nodotdot,
'../' ) ) {
1495 $nodotdot = substr( $nodotdot, 3 );
1497 if ( $dotdotcount > 0 ) {
1498 $exploded = explode(
'/', $contextPrefixedText );
1499 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1500 $ret = implode(
'/', array_slice( $exploded, 0, -$dotdotcount ) );
1501 # / at the end means don't show full path
1502 if ( substr( $nodotdot, -1, 1 ) ===
'/' ) {
1503 $nodotdot = rtrim( $nodotdot,
'/' );
1504 if ( $text ===
'' ) {
1505 $text = $nodotdot . $suffix;
1508 $nodotdot = trim( $nodotdot );
1509 if ( $nodotdot !=
'' ) {
1510 $ret .=
'/' . $nodotdot;
1528 $stxt =
wfMessage(
'historyempty' )->escaped();
1530 $stxt =
wfMessage(
'nbytes' )->numParams( $size )->escaped();
1532 return "<span class=\"history-size mw-diff-bytes\" data-mw-bytes=\"$size\">$stxt</span>";
1542 $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1544 if ( $trail !==
'' && preg_match( $regex, $trail, $m ) ) {
1545 [ , $inside, $trail ] = $m;
1547 return [ $inside, $trail ];
1585 $context ??= RequestContext::getMain();
1587 $editCount = self::getRollbackEditCount( $revRecord );
1588 if ( $editCount ===
false ) {
1592 $inner = self::buildRollbackLink( $revRecord, $context, $editCount );
1594 $services = MediaWikiServices::getInstance();
1597 if ( !(
new HookRunner( $services->getHookContainer() ) )->onLinkerGenerateRollbackLink(
1598 $revRecord, $context, $options, $inner ) ) {
1602 if ( !in_array(
'noBrackets', $options,
true ) ) {
1603 $inner = $context->msg(
'brackets' )->rawParams( $inner )->escaped();
1606 if ( $services->getUserOptionsLookup()
1607 ->getBoolOption( $context->getUser(),
'showrollbackconfirmation' )
1609 $services->getStatsFactory()
1610 ->getCounter(
'rollbackconfirmation_event_load_total' )
1611 ->copyToStatsdAt(
'rollbackconfirmation.event.load' )
1613 $context->getOutput()->addModules(
'mediawiki.misc-authed-curate' );
1616 return '<span class="mw-rollback-link">' . $inner .
'</span>';
1638 if ( func_num_args() > 1 ) {
1639 wfDeprecated( __METHOD__ .
' with $verify parameter',
'1.40' );
1641 $showRollbackEditCount = MediaWikiServices::getInstance()->getMainConfig()
1642 ->get( MainConfigNames::ShowRollbackEditCount );
1644 if ( !is_int( $showRollbackEditCount ) || !$showRollbackEditCount > 0 ) {
1649 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
1652 $queryBuilder = MediaWikiServices::getInstance()->getRevisionStore()->newSelectQueryBuilder( $dbr );
1653 $res = $queryBuilder->where( [
'rev_page' => $revRecord->
getPageId() ] )
1654 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
1655 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC )
1656 ->limit( $showRollbackEditCount + 1 )
1657 ->caller( __METHOD__ )->fetchResultSet();
1659 $revUser = $revRecord->
getUser( RevisionRecord::RAW );
1660 $revUserText = $revUser ? $revUser->getName() :
'';
1664 foreach ( $res as $row ) {
1665 if ( $row->rev_user_text != $revUserText ) {
1666 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1667 || $row->rev_deleted & RevisionRecord::DELETED_USER
1680 if ( $editCount <= $showRollbackEditCount && !$moreRevs ) {
1708 $config = MediaWikiServices::getInstance()->getMainConfig();
1709 $showRollbackEditCount = $config->get( MainConfigNames::ShowRollbackEditCount );
1710 $miserMode = $config->get( MainConfigNames::MiserMode );
1712 $disableRollbackEditCountSpecialPage = [
'Recentchanges',
'Watchlist' ];
1714 $context ??= RequestContext::getMain();
1717 $revUser = $revRecord->
getUser();
1718 $revUserText = $revUser ? $revUser->getName() :
'';
1721 'action' =>
'rollback',
1722 'from' => $revUserText,
1723 'token' => $context->getUser()->getEditToken(
'rollback' ),
1727 'data-mw' =>
'interface',
1728 'title' => $context->msg(
'tooltip-rollback' )->text()
1731 $options = [
'known',
'noclasses' ];
1733 if ( $context->getRequest()->getBool(
'bot' ) ) {
1735 $query[
'hidediff'] =
'1';
1736 $query[
'bot'] =
'1';
1740 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1741 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1742 $showRollbackEditCount =
false;
1749 $msg = [
'rollbacklink' ];
1750 if ( is_int( $showRollbackEditCount ) && $showRollbackEditCount > 0 ) {
1751 if ( !is_numeric( $editCount ) ) {
1752 $editCount = self::getRollbackEditCount( $revRecord );
1755 if ( $editCount > $showRollbackEditCount ) {
1756 $msg = [
'rollbacklinkcount-morethan', Message::numParam( $showRollbackEditCount ) ];
1757 } elseif ( $editCount ) {
1758 $msg = [
'rollbacklinkcount', Message::numParam( $editCount ) ];
1762 $html = $context->msg( ...$msg )->parse();
1763 return self::link( $title, $html, $attrs, $query, $options );
1776 if ( count( $hiddencats ) > 0 ) {
1777 # Construct the HTML
1778 $outText =
'<div class="mw-hiddenCategoriesExplanation">';
1779 $outText .=
wfMessage(
'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1780 $outText .=
"</div><ul>\n";
1782 foreach ( $hiddencats as $titleObj ) {
1783 # If it's hidden, it must exist - no need to check with a LinkBatch
1785 . self::link( $titleObj,
null, [], [],
'known' )
1788 $outText .=
'</ul>';
1796 private static function getContextFromMain() {
1797 $context = RequestContext::getMain();
1819 public static function titleAttrib( $name, $options =
null, array $msgParams = [], $localizer =
null ) {
1820 if ( !$localizer ) {
1821 $localizer = self::getContextFromMain();
1823 $message = $localizer->msg(
"tooltip-$name", $msgParams );
1826 if ( !$message->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1827 $message = $localizer->msg(
'tooltip-ca-nstab' );
1830 if ( $message->isDisabled() ) {
1833 $tooltip = $message->text();
1834 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1835 $tooltip = preg_replace(
"/ ?\[alt-.\]$/",
'', $tooltip );
1838 $options = (array)$options;
1840 if ( in_array(
'nonexisting', $options ) ) {
1841 $tooltip = $localizer->msg(
'red-link-title', $tooltip ?:
'' )->text();
1843 if ( in_array(
'withaccess', $options ) ) {
1844 $accesskey = self::accesskey( $name, $localizer );
1845 if ( $accesskey !==
false ) {
1847 if ( $tooltip ===
false || $tooltip ===
'' ) {
1848 $tooltip = $localizer->msg(
'brackets', $accesskey )->text();
1850 $tooltip .= $localizer->msg(
'word-separator' )->text();
1851 $tooltip .= $localizer->msg(
'brackets', $accesskey )->text();
1874 public static function accesskey( $name, $localizer =
null ) {
1875 if ( !isset( self::$accesskeycache[$name] ) ) {
1876 if ( !$localizer ) {
1877 $localizer = self::getContextFromMain();
1879 $msg = $localizer->msg(
"accesskey-$name" );
1882 if ( !$msg->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1883 $msg = $localizer->msg(
'accesskey-ca-nstab' );
1885 self::$accesskeycache[$name] = $msg->isDisabled() ? false : $msg->plain();
1887 return self::$accesskeycache[$name];
1909 $canHide = $performer->
isAllowed(
'deleterevision' );
1910 $canHideHistory = $performer->
isAllowed(
'deletedhistory' );
1911 if ( !$canHide && !( $revRecord->
getVisibility() && $canHideHistory ) ) {
1915 if ( !$revRecord->
userCan( RevisionRecord::DELETED_RESTRICTED, $performer ) ) {
1916 return self::revDeleteLinkDisabled( $canHide );
1918 $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
1919 getPrefixedDBkey( $title );
1920 if ( $revRecord->
getId() ) {
1924 'type' =>
'revision',
1925 'target' => $prefixedDbKey,
1926 'ids' => $revRecord->
getId()
1932 'type' =>
'archive',
1933 'target' => $prefixedDbKey,
1937 return self::revDeleteLink(
1939 $revRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ),
1956 public static function revDeleteLink( $query = [], $restricted =
false, $delete =
true ) {
1957 $sp = SpecialPage::getTitleFor(
'Revisiondelete' );
1958 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1959 $html =
wfMessage( $msgKey )->escaped();
1960 $tag = $restricted ?
'strong' :
'span';
1961 $link = self::link( $sp, $html, [], $query, [
'known',
'noclasses' ] );
1962 return Html::rawElement(
1964 [
'class' =>
'mw-revdelundel-link' ],
1965 wfMessage(
'parentheses' )->rawParams( $link )->escaped()
1981 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1982 $html =
wfMessage( $msgKey )->escaped();
1983 $htmlParentheses =
wfMessage(
'parentheses' )->rawParams( $html )->escaped();
1984 return Html::rawElement(
'span', [
'class' =>
'mw-revdelundel-link' ], $htmlParentheses );
2002 array $msgParams = [],
2006 $options = (array)$options;
2007 $options[] =
'withaccess';
2010 if ( !$localizer ) {
2011 $localizer = self::getContextFromMain();
2015 'title' => self::titleAttrib( $name, $options, $msgParams, $localizer ),
2016 'accesskey' => self::accesskey( $name, $localizer )
2018 if ( $attribs[
'title'] ===
false ) {
2019 unset( $attribs[
'title'] );
2021 if ( $attribs[
'accesskey'] ===
false ) {
2022 unset( $attribs[
'accesskey'] );
2034 public static function tooltip( $name, $options =
null ) {
2035 $tooltip = self::titleAttrib( $name, $options );
2036 if ( $tooltip ===
false ) {
2039 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 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.