33use Wikimedia\Assert\Assert;
36use Wikimedia\RemexHtml\Serializer\SerializerNode;
95 public static function link(
96 $target, $html =
null, $customAttribs = [], $query = [], $options = []
99 wfWarn( __METHOD__ .
': Requires $target to be a LinkTarget object.', 2 );
100 return "<!-- ERROR -->$html";
103 $options = (array)$options;
104 $linkRenderer = self::getLinkRenderer( $options );
106 if ( $html !==
null ) {
112 if ( in_array(
'known', $options,
true ) ) {
113 return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
116 if ( in_array(
'broken', $options,
true ) ) {
117 return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
120 if ( in_array(
'noclasses', $options,
true ) ) {
121 return $linkRenderer->makePreloadedLink( $target, $text,
'', $customAttribs, $query );
124 return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
147 $target, $html =
null, $customAttribs = [],
148 $query = [], $options = [
'known' ]
150 return self::link( $target, $html, $customAttribs, $query, $options );
170 public static function makeSelfLinkObj( $nt, $html =
'', $query =
'', $trail =
'', $prefix =
'', $hash =
'' ) {
171 $nt = Title::newFromLinkTarget( $nt );
174 $attrs[
'class'] =
'mw-selflink-fragment';
175 $attrs[
'href'] =
'#' . $hash;
178 $attrs[
'class'] =
'mw-selflink selflink';
180 $ret = Html::rawElement(
'a', $attrs, $prefix . $html ) . $trail;
182 if ( !$hookRunner->onSelfLinkBegin( $nt, $html, $trail, $prefix, $ret ) ) {
187 $html = htmlspecialchars( $nt->getPrefixedText() );
190 return Html::rawElement(
'a', $attrs, $prefix . $html . $inside ) . $trail;
207 $name = $context->
msg(
'blanknamespace' )->text();
210 getFormattedNsText( $namespace );
212 return $context->
msg(
'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
215 return $context->
msg(
'invalidtitle-unknownnamespace', $namespace, $title )->text();
226 private static function fnamePart(
$url ) {
227 $basename = strrchr(
$url,
'/' );
228 if ( $basename ===
false ) {
231 $basename = substr( $basename, 1 );
248 $alt = self::fnamePart(
$url );
252 ->onLinkerMakeExternalImage(
$url, $alt, $img );
254 wfDebug(
"Hook LinkerMakeExternalImage changed the output of external image "
255 .
"with url {$url} and alt text {$alt} to {$img}" );
305 $file, $frameParams = [], $handlerParams = [], $time =
false,
306 $query =
'', $widthOption =
null
308 $title = Title::newFromLinkTarget( $title );
311 if ( !$hookRunner->onImageBeforeProduceHTML(
null, $title,
313 $file, $frameParams, $handlerParams, $time, $res,
315 $parser, $query, $widthOption )
320 if ( $file && !$file->allowInlineDisplay() ) {
321 wfDebug( __METHOD__ .
': ' . $title->getPrefixedDBkey() .
' does not allow inline display' );
326 $page = $handlerParams[
'page'] ??
false;
327 if ( !isset( $frameParams[
'align'] ) ) {
328 $frameParams[
'align'] =
'';
330 if ( !isset( $frameParams[
'title'] ) ) {
331 $frameParams[
'title'] =
'';
333 if ( !isset( $frameParams[
'class'] ) ) {
334 $frameParams[
'class'] =
'';
338 $config = $services->getMainConfig();
342 !isset( $handlerParams[
'width'] ) &&
343 !isset( $frameParams[
'manualthumb'] ) &&
344 !isset( $frameParams[
'framed'] )
346 $classes[] =
'mw-default-size';
349 $prefix = $postfix =
'';
351 if ( $file && !isset( $handlerParams[
'width'] ) ) {
352 if ( isset( $handlerParams[
'height'] ) && $file->isVectorized() ) {
356 $handlerParams[
'width'] = $svgMaxSize;
358 $handlerParams[
'width'] = $file->getWidth( $page );
361 if ( isset( $frameParams[
'thumbnail'] )
362 || isset( $frameParams[
'manualthumb'] )
363 || isset( $frameParams[
'framed'] )
364 || isset( $frameParams[
'frameless'] )
365 || !$handlerParams[
'width']
369 if ( $widthOption ===
null || !isset( $thumbLimits[$widthOption] ) ) {
370 $userOptionsLookup = $services->getUserOptionsLookup();
375 if ( isset( $frameParams[
'upright'] ) && $frameParams[
'upright'] == 0 ) {
376 $frameParams[
'upright'] = $thumbUpright;
382 $prefWidth = isset( $frameParams[
'upright'] ) ?
383 round( $thumbLimits[$widthOption] * $frameParams[
'upright'], -1 ) :
384 $thumbLimits[$widthOption];
388 if ( !isset( $handlerParams[
'height'] ) && ( $handlerParams[
'width'] <= 0 ||
389 $prefWidth < $handlerParams[
'width'] || $file->isVectorized() ) ) {
390 $handlerParams[
'width'] = $prefWidth;
396 $hasVisibleCaption = isset( $frameParams[
'thumbnail'] ) ||
397 isset( $frameParams[
'manualthumb'] ) ||
398 isset( $frameParams[
'framed'] );
400 if ( $hasVisibleCaption ) {
402 $title, $file, $frameParams, $handlerParams, $time, $query,
407 $rdfaType =
'mw:File';
409 if ( isset( $frameParams[
'frameless'] ) ) {
410 $rdfaType .=
'/Frameless';
412 $srcWidth = $file->getWidth( $page );
413 # For "frameless" option: do not present an image bigger than the
414 # source (for bitmap-style images). This is the same behavior as the
415 # "thumb" option does it already.
416 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
417 $handlerParams[
'width'] = $srcWidth;
422 if ( $file && isset( $handlerParams[
'width'] ) ) {
423 # Create a resized image, without the additional thumbnail features
424 $thumb = $file->transform( $handlerParams );
429 $isBadFile = $file && $thumb &&
432 if ( !$thumb || $thumb->isError() || $isBadFile ) {
433 $rdfaType =
'mw:Error ' . $rdfaType;
434 $currentExists = $file && $file->exists();
435 if ( $currentExists && !$thumb ) {
436 $label =
wfMessage(
'thumbnail_error',
'' )->text();
437 } elseif ( $thumb && $thumb->isError() ) {
440 'Unknown MediaTransformOutput: ' . get_class( $thumb )
442 $label = $thumb->toText();
444 $label = $frameParams[
'alt'] ??
'';
447 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams, $currentExists
455 if ( isset( $frameParams[
'alt'] ) ) {
456 $params[
'alt'] = $frameParams[
'alt'];
458 $params[
'title'] = $frameParams[
'title'];
460 'img-class' =>
'mw-file-element',
463 if ( isset( $frameParams[
'upright'] ) ) {
464 $params[
'img-class'] .=
' mw-file-upright';
465 $params[
'style'] =
'--mw-file-upright: ' . $frameParams[
'upright'];
468 $s = $thumb->toHtml( $params );
474 if ( $frameParams[
'align'] !=
'' ) {
477 $classes[] =
"mw-halign-{$frameParams['align']}";
478 $caption = Html::rawElement(
479 'figcaption', [], $frameParams[
'caption'] ??
''
481 } elseif ( isset( $frameParams[
'valign'] ) ) {
485 $classes[] =
"mw-valign-{$frameParams['valign']}";
488 if ( isset( $frameParams[
'border'] ) ) {
489 $classes[] =
'mw-image-border';
492 if ( isset( $frameParams[
'class'] ) ) {
493 $classes[] = $frameParams[
'class'];
498 'typeof' => $rdfaType,
501 $s = Html::rawElement( $wrapper, $attribs, $s . $caption );
503 return str_replace(
"\n",
' ', $s );
516 if ( isset( $frameParams[
'link-url'] ) && $frameParams[
'link-url'] !==
'' ) {
517 $mtoParams[
'custom-url-link'] = $frameParams[
'link-url'];
518 if ( isset( $frameParams[
'link-target'] ) ) {
519 $mtoParams[
'custom-target-link'] = $frameParams[
'link-target'];
522 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams[
'link-url'] );
523 foreach ( $extLinkAttrs as $name => $val ) {
525 $mtoParams[
'parser-extlink-' . $name] = $val;
528 } elseif ( isset( $frameParams[
'link-title'] ) && $frameParams[
'link-title'] !==
'' ) {
529 $mtoParams[
'custom-title-link'] = Title::newFromLinkTarget(
530 self::getLinkRenderer()->normalizeTarget( $frameParams[
'link-title'] )
532 if ( isset( $frameParams[
'link-title-query'] ) ) {
533 $mtoParams[
'custom-title-link-query'] = $frameParams[
'link-title-query'];
535 } elseif ( !empty( $frameParams[
'no-link'] ) ) {
538 $mtoParams[
'desc-link'] =
true;
539 $mtoParams[
'desc-query'] = $query;
557 LinkTarget $title, $file, $label =
'', $alt =
'', $align =
null,
558 $params = [], $framed =
false, $manualthumb =
''
566 if ( $manualthumb ) {
567 $frameParams[
'manualthumb'] = $manualthumb;
568 } elseif ( $framed ) {
569 $frameParams[
'framed'] =
true;
570 } elseif ( !isset( $params[
'width'] ) ) {
571 $classes[] =
'mw-default-size';
574 $title, $file, $frameParams, $params,
false,
'', $classes
590 LinkTarget $title, $file, $frameParams = [], $handlerParams = [],
591 $time =
false, $query =
'', array $classes = [], ?
Parser $parser =
null
593 $exists = $file && $file->exists();
596 $page = $handlerParams[
'page'] ??
false;
597 $lang = $handlerParams[
'lang'] ??
false;
599 if ( !isset( $frameParams[
'align'] ) ) {
600 $frameParams[
'align'] =
'';
602 if ( !isset( $frameParams[
'caption'] ) ) {
603 $frameParams[
'caption'] =
'';
606 if ( empty( $handlerParams[
'width'] ) ) {
608 $handlerParams[
'width'] = isset( $frameParams[
'upright'] ) ? 130 : 180;
613 $manualthumb =
false;
615 $rdfaType =
'mw:File/Thumb';
619 if ( !isset( $frameParams[
'manualthumb'] ) && isset( $frameParams[
'framed'] ) ) {
620 $rdfaType =
'mw:File/Frame';
622 $outerWidth = $handlerParams[
'width'] + 2;
624 if ( isset( $frameParams[
'manualthumb'] ) ) {
625 # Use manually specified thumbnail
626 $manual_title = Title::makeTitleSafe(
NS_FILE, $frameParams[
'manualthumb'] );
627 if ( $manual_title ) {
628 $manual_img = $services->getRepoGroup()
629 ->findFile( $manual_title );
631 $thumb = $manual_img->getUnscaledThumb( $handlerParams );
636 $srcWidth = $file->getWidth( $page );
637 if ( isset( $frameParams[
'framed'] ) ) {
638 $rdfaType =
'mw:File/Frame';
639 if ( !$file->isVectorized() ) {
645 $handlerParams[
'width'] = $srcWidth;
651 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
652 $handlerParams[
'width'] = $srcWidth;
656 ? $file->getUnscaledThumb( $handlerParams )
657 : $file->transform( $handlerParams );
661 $outerWidth = $thumb->getWidth() + 2;
663 $outerWidth = $handlerParams[
'width'] + 2;
667 if ( $parser && $rdfaType ===
'mw:File/Thumb' ) {
668 $parser->getOutput()->addModules( [
'mediawiki.page.media' ] );
671 $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
672 $linkTitleQuery = [];
673 if ( $page || $lang ) {
675 $linkTitleQuery[
'page'] = $page;
678 $linkTitleQuery[
'lang'] = $lang;
680 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
681 # So we don't need to pass it here in $query. However, the URL for the
682 # zoom icon still needs it, so we make a unique query for it. See T16771
687 && !isset( $frameParams[
'link-title'] )
688 && !isset( $frameParams[
'link-url'] )
689 && !isset( $frameParams[
'no-link'] ) ) {
690 $frameParams[
'link-title'] = $title;
691 $frameParams[
'link-title-query'] = $linkTitleQuery;
694 if ( $frameParams[
'align'] !=
'' ) {
696 $classes[] =
"mw-halign-{$frameParams['align']}";
699 if ( isset( $frameParams[
'class'] ) ) {
700 $classes[] = $frameParams[
'class'];
705 $isBadFile = $exists && $thumb && $parser &&
706 $parser->getBadFileLookup()->isBadFile(
707 $manualthumb ? $manual_title->getDBkey() : $title->
getDBkey(),
712 $rdfaType =
'mw:Error ' . $rdfaType;
713 $label = $frameParams[
'alt'] ??
'';
715 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
false
718 } elseif ( !$thumb || $thumb->isError() || $isBadFile ) {
719 $rdfaType =
'mw:Error ' . $rdfaType;
720 if ( $thumb && $thumb->isError() ) {
723 'Unknown MediaTransformOutput: ' . get_class( $thumb )
725 $label = $thumb->toText();
726 } elseif ( !$thumb ) {
727 $label =
wfMessage(
'thumbnail_error',
'' )->text();
732 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
true
736 if ( !$noscale && !$manualthumb ) {
743 if ( isset( $frameParams[
'alt'] ) ) {
744 $params[
'alt'] = $frameParams[
'alt'];
747 'img-class' =>
'mw-file-element',
749 if ( isset( $frameParams[
'upright'] ) ) {
750 $params[
'img-class'] .=
' mw-file-upright';
751 $params[
'style'] =
'--mw-file-upright: ' . $frameParams[
'upright'];
754 if ( $rdfaType ===
'mw:File/Thumb' ) {
755 $params[
'magnify-resource'] =
$url;
758 $s .= $thumb->toHtml( $params );
759 if ( isset( $frameParams[
'framed'] ) ) {
762 $zoomIcon = Html::rawElement(
'div', [
'class' =>
'magnify' ],
763 Html::rawElement(
'a', [
765 'class' =>
'internal',
766 'title' =>
wfMessage(
'thumbnail-more' )->text(),
772 $s .= Html::rawElement(
773 'figcaption', [], $frameParams[
'caption'] ??
''
778 'typeof' => $rdfaType,
781 $s = Html::rawElement(
'figure', $attribs, $s );
783 return str_replace(
"\n",
' ', $s );
796 if ( $responsiveImages && $thumb && !$thumb->isError() ) {
798 $hp20[
'width'] = $hp[
'width'] * 2;
799 if ( isset( $hp[
'height'] ) ) {
800 $hp20[
'height'] = $hp[
'height'] * 2;
802 $thumb20 = $file->transform( $hp20 );
803 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
804 $thumb->responsiveUrls[
'2'] = $thumb20->getUrl();
824 $title, $label =
'', $query =
'', $unused1 =
'', $unused2 =
'',
825 $time =
false, array $handlerParams = [],
bool $currentExists =
false
828 wfWarn( __METHOD__ .
': Requires $title to be a LinkTarget object.' );
829 return "<!-- ERROR -->" . htmlspecialchars( $label );
832 $title = Title::newFromLinkTarget( $title );
834 $mainConfig = $services->getMainConfig();
838 if ( $label ==
'' ) {
839 $label = $title->getPrefixedText();
843 'class' =>
'mw-file-element mw-broken-media',
845 'data-width' => $handlerParams[
'width'] ??
null,
846 'data-height' => $handlerParams[
'height'] ??
null,
849 $repoGroup = $services->getRepoGroup();
850 $currentExists = $currentExists ||
851 ( $time && $repoGroup->findFile( $title ) !== false );
853 if ( ( $uploadMissingFileUrl || $uploadNavigationUrl || $enableUploads )
857 $title->inNamespace(
NS_FILE ) &&
858 $repoGroup->getLocalRepo()->checkRedirect( $title )
864 [
'class' =>
'mw-redirect' ],
866 [
'known',
'noclasses' ]
869 return Html::rawElement(
'a', [
870 'href' => self::getUploadUrl( $title, $query ),
872 'title' => $title->getPrefixedText()
880 [
'known',
'noclasses' ]
896 $q =
'wpDestFile=' . Title::newFromLinkTarget( $destFile )->getPartialURL();
897 if ( $query !=
'' ) {
901 if ( $uploadMissingFileUrl ) {
905 if ( $uploadNavigationUrl ) {
911 return $upload->getLocalURL( $q );
925 $title, [
'time' => $time ]
943 if ( $file && $file->exists() ) {
944 $url = $file->getUrl();
964 Title::newFromLinkTarget( $title ), $file, $html, $attribs, $ret )
966 wfDebug(
"Hook LinkerMakeMediaLinkFile changed the output of link "
967 .
"with url {$url} and text {$html} to {$ret}" );
971 return Html::rawElement(
'a', $attribs, $html );
985 $queryPos = strpos( $name,
'?' );
986 if ( $queryPos !==
false ) {
987 $getParams =
wfCgiToArray( substr( $name, $queryPos + 1 ) );
988 $name = substr( $name, 0, $queryPos );
993 $slashPos = strpos( $name,
'/' );
994 if ( $slashPos !==
false ) {
995 $subpage = substr( $name, $slashPos + 1 );
996 $name = substr( $name, 0, $slashPos );
1002 $key = strtolower( $name );
1034 $linktype =
'', $attribs = [], $title =
null
1038 return self::getLinkRenderer()->makeExternalLink(
1040 $escape ? $text :
new HtmlArmor( $text ),
1064 $altUserName =
false,
1067 if ( $userName ===
'' || $userName ===
false || $userName ===
null ) {
1068 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1069 'that need to be fixed?' );
1070 return wfMessage(
'empty-username' )->parse();
1073 return self::getLinkRenderer()->makeUserLink(
1075 RequestContext::getMain(),
1076 $altUserName ===
false ?
null : (string)$altUserName,
1100 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null
1104 $talkable = !( $disableAnonTalk && $userId == 0 );
1106 $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
1108 if ( $userId == 0 && ExternalUserNames::isExternal( $userText ) ) {
1121 if ( $userId && !$services->getTempUserConfig()->isTempName( $userText ) ) {
1123 $attribs[
'class'] =
'mw-usertoollinks-contribs';
1126 if ( $redContribsWhenNoEdits ) {
1127 if ( $edits ===
null ) {
1128 $user = UserIdentityValue::newRegistered( $userId, $userText );
1129 $edits = $services->getUserEditTracker()->getUserEditCount( $user );
1131 if ( $edits === 0 ) {
1134 $attribs[
'class'] .=
' mw-usertoollinks-contribs-no-edits';
1141 $userCanBlock = RequestContext::getMain()->getAuthority()->isAllowed(
'block' );
1142 if ( $blockable && $userCanBlock ) {
1149 ->newEmailUser( RequestContext::getMain()->
getAuthority() )
1156 (
new HookRunner( $services->getHookContainer() ) )->onUserToolLinksEdit( $userId, $userText, $items );
1173 if ( $useParentheses ) {
1174 $lang = RequestContext::getMain()->getLanguage();
1175 return wfMessage(
'word-separator' )->escaped()
1176 .
'<span class="mw-usertoollinks">'
1177 .
wfMessage(
'parentheses' )->rawParams( $lang->pipeList( $items ) )->escaped()
1182 foreach ( $items as $tool ) {
1183 $tools[] = Html::rawElement(
'span', [], $tool );
1185 return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1186 implode(
' ', $tools ) .
'</span>';
1204 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null,
1205 $useParentheses =
true
1207 if ( $userText ===
'' ) {
1208 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1209 'that need to be fixed?' );
1210 return ' ' .
wfMessage(
'empty-username' )->parse();
1213 $items = self::userToolLinkArray( $userId, $userText, $redContribsWhenNoEdits, $flags, $edits );
1214 return self::renderUserToolLinksArray( $items, $useParentheses );
1227 $userId, $userText, $edits =
null, $useParentheses =
true
1229 return self::userToolLinks( $userId, $userText,
true, 0, $edits, $useParentheses );
1239 if ( $userText ===
'' ) {
1240 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1241 'that need to be fixed?' );
1242 return wfMessage(
'empty-username' )->parse();
1245 $userTalkPage = TitleValue::tryNew(
NS_USER_TALK, strtr( $userText,
' ',
'_' ) );
1246 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-talk' ];
1247 $linkText =
wfMessage(
'talkpagelinktext' )->escaped();
1249 return $userTalkPage
1250 ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1251 : Html::rawElement(
'span', $moreLinkAttribs, $linkText );
1261 if ( $userText ===
'' ) {
1262 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1263 'that need to be fixed?' );
1264 return wfMessage(
'empty-username' )->parse();
1267 $blockPage = SpecialPage::getTitleFor(
'Block', $userText );
1268 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-block' ];
1270 return self::link( $blockPage,
1282 if ( $userText ===
'' ) {
1283 wfLogWarning( __METHOD__ .
' received an empty username. Are there database errors ' .
1284 'that need to be fixed?' );
1285 return wfMessage(
'empty-username' )->parse();
1288 $emailPage = SpecialPage::getTitleFor(
'Emailuser', $userText );
1289 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-mail' ];
1290 return self::link( $emailPage,
1309 $authority = RequestContext::getMain()->getAuthority();
1311 $revUser = $revRecord->
getUser(
1312 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1316 $link = self::userLink( $revUser->getId(), $revUser->getName() );
1319 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1322 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1323 $class = self::getRevisionDeletedClass( $revRecord );
1324 return '<span class="' . $class .
'">' . $link .
'</span>';
1336 $class =
'history-deleted';
1337 if ( $revisionRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
1338 $class .=
' mw-history-suppressed';
1358 $useParentheses =
true
1361 $authority = RequestContext::getMain()->getAuthority();
1363 $revUser = $revRecord->
getUser(
1364 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1368 $link = self::userLink(
1370 $revUser->getName(),
1372 [
'data-mw-revid' => $revRecord->
getId() ]
1373 ) . self::userToolLinks(
1375 $revUser->getName(),
1383 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1386 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1387 $class = self::getRevisionDeletedClass( $revRecord );
1388 return ' <span class="' . $class .
' mw-userlink">' . $link .
'</span>';
1404 return HtmlHelper::modifyElements(
1406 static function ( SerializerNode $node ):
bool {
1407 return $node->name ===
'a' && isset( $node->attrs[
'href'] );
1409 static function ( SerializerNode $node ): SerializerNode {
1410 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
1411 $href = $urlUtils->expand( $node->attrs[
'href'],
PROTO_RELATIVE );
1412 if ( $href !==
null ) {
1413 $node->attrs[
'href'] = $href;
1429 # :Foobar -- override special treatment of prefix (images, language links)
1430 # /Foobar -- convert to CurrentPage/Foobar
1431 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1432 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1433 # ../Foobar -- convert to CurrentPage/Foobar,
1434 # (from CurrentPage/CurrentSubPage)
1435 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1436 # (from CurrentPage/CurrentSubPage)
1438 $ret = $target; #
default return value is no change
1440 # Some namespaces don't allow subpages,
1441 # so only perform processing if subpages are allowed
1443 $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1444 hasSubpages( $contextTitle->getNamespace() )
1446 $hash = strpos( $target,
'#' );
1447 if ( $hash !==
false ) {
1448 $suffix = substr( $target, $hash );
1449 $target = substr( $target, 0, $hash );
1454 $target = trim( $target );
1455 $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1456 getPrefixedText( $contextTitle );
1457 # Look at the first character
1458 if ( $target !=
'' && $target[0] ===
'/' ) {
1459 # / at end means we don't want the slash to be shown
1461 $trailingSlashes = preg_match_all(
'%(/+)$%', $target, $m );
1462 if ( $trailingSlashes ) {
1463 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1465 $noslash = substr( $target, 1 );
1468 $ret = $contextPrefixedText .
'/' . trim( $noslash ) . $suffix;
1469 if ( $text ===
'' ) {
1470 $text = $target . $suffix;
1471 } #
this might be changed
for ugliness reasons
1473 # check for .. subpage backlinks
1475 $nodotdot = $target;
1476 while ( str_starts_with( $nodotdot,
'../' ) ) {
1478 $nodotdot = substr( $nodotdot, 3 );
1480 if ( $dotdotcount > 0 ) {
1481 $exploded = explode(
'/', $contextPrefixedText );
1482 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1483 $ret = implode(
'/', array_slice( $exploded, 0, -$dotdotcount ) );
1484 # / at the end means don't show full path
1485 if ( substr( $nodotdot, -1, 1 ) ===
'/' ) {
1486 $nodotdot = rtrim( $nodotdot,
'/' );
1487 if ( $text ===
'' ) {
1488 $text = $nodotdot . $suffix;
1491 $nodotdot = trim( $nodotdot );
1492 if ( $nodotdot !=
'' ) {
1493 $ret .=
'/' . $nodotdot;
1511 $stxt =
wfMessage(
'historyempty' )->escaped();
1513 $stxt =
wfMessage(
'nbytes' )->numParams( $size )->escaped();
1515 return "<span class=\"history-size mw-diff-bytes\" data-mw-bytes=\"$size\">$stxt</span>";
1525 $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1527 if ( $trail !==
'' && preg_match( $regex, $trail, $m ) ) {
1528 [ , $inside, $trail ] = $m;
1530 return [ $inside, $trail ];
1568 $context ??= RequestContext::getMain();
1570 $editCount = self::getRollbackEditCount( $revRecord );
1571 if ( $editCount ===
false ) {
1575 $inner = self::buildRollbackLink( $revRecord, $context, $editCount );
1577 $services = MediaWikiServices::getInstance();
1580 if ( !(
new HookRunner( $services->getHookContainer() ) )->onLinkerGenerateRollbackLink(
1581 $revRecord, $context, $options, $inner ) ) {
1585 if ( !in_array(
'noBrackets', $options,
true ) ) {
1586 $inner = $context->msg(
'brackets' )->rawParams( $inner )->escaped();
1589 if ( $services->getUserOptionsLookup()
1590 ->getBoolOption( $context->getUser(),
'showrollbackconfirmation' )
1592 $context->getOutput()->addModules(
'mediawiki.misc-authed-curate' );
1595 return '<span class="mw-rollback-link">' . $inner .
'</span>';
1617 if ( func_num_args() > 1 ) {
1618 wfDeprecated( __METHOD__ .
' with $verify parameter',
'1.40' );
1620 $showRollbackEditCount = MediaWikiServices::getInstance()->getMainConfig()
1621 ->get( MainConfigNames::ShowRollbackEditCount );
1623 if ( !is_int( $showRollbackEditCount ) || !$showRollbackEditCount > 0 ) {
1628 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
1631 $queryBuilder = MediaWikiServices::getInstance()->getRevisionStore()->newSelectQueryBuilder( $dbr );
1632 $res = $queryBuilder->where( [
'rev_page' => $revRecord->
getPageId() ] )
1633 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
1634 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC )
1635 ->limit( $showRollbackEditCount + 1 )
1636 ->caller( __METHOD__ )->fetchResultSet();
1638 $revUser = $revRecord->
getUser( RevisionRecord::RAW );
1639 $revUserText = $revUser ? $revUser->getName() :
'';
1643 foreach ( $res as $row ) {
1644 if ( $row->rev_user_text != $revUserText ) {
1645 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1646 || $row->rev_deleted & RevisionRecord::DELETED_USER
1659 if ( $editCount <= $showRollbackEditCount && !$moreRevs ) {
1687 $config = MediaWikiServices::getInstance()->getMainConfig();
1688 $showRollbackEditCount = $config->get( MainConfigNames::ShowRollbackEditCount );
1689 $miserMode = $config->get( MainConfigNames::MiserMode );
1691 $disableRollbackEditCountSpecialPage = [
'Recentchanges',
'Watchlist' ];
1693 $context ??= RequestContext::getMain();
1696 $revUser = $revRecord->
getUser();
1697 $revUserText = $revUser ? $revUser->getName() :
'';
1700 'action' =>
'rollback',
1701 'from' => $revUserText,
1702 'token' => $context->getUser()->getEditToken(
'rollback' ),
1706 'data-mw-interface' =>
'',
1707 'title' => $context->msg(
'tooltip-rollback' )->text()
1710 $options = [
'known',
'noclasses' ];
1712 if ( $context->getRequest()->getBool(
'bot' ) ) {
1714 $query[
'hidediff'] =
'1';
1715 $query[
'bot'] =
'1';
1719 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1720 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1721 $showRollbackEditCount =
false;
1728 $msg = [
'rollbacklink' ];
1729 if ( is_int( $showRollbackEditCount ) && $showRollbackEditCount > 0 ) {
1730 if ( !is_numeric( $editCount ) ) {
1731 $editCount = self::getRollbackEditCount( $revRecord );
1734 if ( $editCount > $showRollbackEditCount ) {
1735 $msg = [
'rollbacklinkcount-morethan', Message::numParam( $showRollbackEditCount ) ];
1736 } elseif ( $editCount ) {
1737 $msg = [
'rollbacklinkcount', Message::numParam( $editCount ) ];
1741 $html = $context->msg( ...$msg )->parse();
1742 return self::link( $title, $html, $attrs, $query, $options );
1755 if ( count( $hiddencats ) > 0 ) {
1756 # Construct the HTML
1757 $outText =
'<div class="mw-hiddenCategoriesExplanation">';
1758 $outText .=
wfMessage(
'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1759 $outText .=
"</div><ul>\n";
1761 foreach ( $hiddencats as $titleObj ) {
1762 # If it's hidden, it must exist - no need to check with a LinkBatch
1764 . self::link( $titleObj,
null, [], [],
'known' )
1767 $outText .=
'</ul>';
1775 private static function getContextFromMain() {
1776 $context = RequestContext::getMain();
1798 public static function titleAttrib( $name, $options =
null, array $msgParams = [], $localizer =
null ) {
1799 if ( !$localizer ) {
1800 $localizer = self::getContextFromMain();
1802 $message = $localizer->msg(
"tooltip-$name", $msgParams );
1805 if ( !$message->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1806 $message = $localizer->msg(
'tooltip-ca-nstab' );
1809 if ( $message->isDisabled() ) {
1812 $tooltip = $message->text();
1813 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1814 $tooltip = preg_replace(
"/ ?\[alt-.\]$/",
'', $tooltip );
1817 $options = (array)$options;
1819 if ( in_array(
'nonexisting', $options ) ) {
1820 $tooltip = $localizer->msg(
'red-link-title', $tooltip ?:
'' )->text();
1822 if ( in_array(
'withaccess', $options ) ) {
1823 $accesskey = self::accesskey( $name, $localizer );
1824 if ( $accesskey !==
false ) {
1826 if ( $tooltip ===
false || $tooltip ===
'' ) {
1827 $tooltip = $localizer->msg(
'brackets', $accesskey )->text();
1829 $tooltip .= $localizer->msg(
'word-separator' )->text();
1830 $tooltip .= $localizer->msg(
'brackets', $accesskey )->text();
1853 public static function accesskey( $name, $localizer =
null ) {
1854 if ( !isset( self::$accesskeycache[$name] ) ) {
1855 if ( !$localizer ) {
1856 $localizer = self::getContextFromMain();
1858 $msg = $localizer->msg(
"accesskey-$name" );
1861 if ( !$msg->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1862 $msg = $localizer->msg(
'accesskey-ca-nstab' );
1864 self::$accesskeycache[$name] = $msg->isDisabled() ? false : $msg->plain();
1866 return self::$accesskeycache[$name];
1888 $canHide = $performer->
isAllowed(
'deleterevision' );
1889 $canHideHistory = $performer->
isAllowed(
'deletedhistory' );
1890 if ( !$canHide && !( $revRecord->
getVisibility() && $canHideHistory ) ) {
1894 if ( !$revRecord->
userCan( RevisionRecord::DELETED_RESTRICTED, $performer ) ) {
1895 return self::revDeleteLinkDisabled( $canHide );
1897 $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
1898 getPrefixedDBkey( $title );
1899 if ( $revRecord->
getId() ) {
1903 'type' =>
'revision',
1904 'target' => $prefixedDbKey,
1905 'ids' => $revRecord->
getId()
1911 'type' =>
'archive',
1912 'target' => $prefixedDbKey,
1916 return self::revDeleteLink(
1918 $revRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ),
1935 public static function revDeleteLink( $query = [], $restricted =
false, $delete =
true ) {
1936 $sp = SpecialPage::getTitleFor(
'Revisiondelete' );
1937 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1938 $html =
wfMessage( $msgKey )->escaped();
1939 $tag = $restricted ?
'strong' :
'span';
1940 $link = self::link( $sp, $html, [], $query, [
'known',
'noclasses' ] );
1941 return Html::rawElement(
1943 [
'class' =>
'mw-revdelundel-link' ],
1944 wfMessage(
'parentheses' )->rawParams( $link )->escaped()
1960 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1961 $html =
wfMessage( $msgKey )->escaped();
1962 $htmlParentheses =
wfMessage(
'parentheses' )->rawParams( $html )->escaped();
1963 return Html::rawElement(
'span', [
'class' =>
'mw-revdelundel-link' ], $htmlParentheses );
1981 array $msgParams = [],
1985 $options = (array)$options;
1986 $options[] =
'withaccess';
1989 if ( !$localizer ) {
1990 $localizer = self::getContextFromMain();
1994 'title' => self::titleAttrib( $name, $options, $msgParams, $localizer ),
1995 'accesskey' => self::accesskey( $name, $localizer )
1997 if ( $attribs[
'title'] ===
false ) {
1998 unset( $attribs[
'title'] );
2000 if ( $attribs[
'accesskey'] ===
false ) {
2001 unset( $attribs[
'accesskey'] );
2013 public static function tooltip( $name, $options =
null ) {
2014 $tooltip = self::titleAttrib( $name, $options );
2015 if ( $tooltip ===
false ) {
2018 return Html::expandAttributes( [
2027 private static function getLinkRenderer(
2028 array $legacyOptions = []
2032 if ( count( $legacyOptions ) > 0 ) {
2038 return $services->getLinkRenderer();
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(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgTitle
if(!defined('MW_SETUP_CALLBACK'))
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.