Файловый менеджер - Редактировать - /var/www/html/CommentFormatter.zip
Ðазад
PK ! Ļ�~�/ �/ CommentFormatter.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use MediaWiki\Linker\Linker; use MediaWiki\Linker\LinkTarget; use MediaWiki\Permissions\Authority; use MediaWiki\Revision\RevisionRecord; use Traversable; /** * This is the main service interface for converting single-line comments from * various DB comment fields into HTML. * * @since 1.38 */ class CommentFormatter { /** @var CommentParserFactory */ protected $parserFactory; /** * @internal Use MediaWikiServices::getCommentFormatter() * * @param CommentParserFactory $parserFactory */ public function __construct( CommentParserFactory $parserFactory ) { $this->parserFactory = $parserFactory; } /** * Format comments using a fluent interface. * * @return CommentBatch */ public function createBatch() { return new CommentBatch( $this ); } /** * Format a single comment. Similar to the old Linker::formatComment(). * * @param string $comment * @param LinkTarget|null $selfLinkTarget The title used for fragment-only * and section links, formerly $title. * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @param string|false|null $wikiId ID of the wiki to link to (if not the local * wiki), as used by WikiMap. * @return string */ public function format( string $comment, ?LinkTarget $selfLinkTarget = null, $samePage = false, $wikiId = false ) { return $this->formatInternal( $comment, true, false, false, $selfLinkTarget, $samePage, $wikiId ); } /** * Wrap a comment in standard punctuation and formatting if * it's non-empty, otherwise return an empty string. * * @param string $comment * @param LinkTarget|null $selfLinkTarget The title used for fragment-only * and section links, formerly $title. * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @param string|false|null $wikiId ID of the wiki to link to (if not the local * wiki), as used by WikiMap. * @param bool $useParentheses * @return string */ public function formatBlock( string $comment, ?LinkTarget $selfLinkTarget = null, $samePage = false, $wikiId = false, $useParentheses = true ) { return $this->formatInternal( $comment, true, true, $useParentheses, $selfLinkTarget, $samePage, $wikiId ); } /** * Format a comment, passing through HTML in the input to the output. * This is unsafe and exists only for backwards compatibility with * Linker::formatLinksInComment(). * * In new code, use formatLinks() or createBatch()->disableSectionLinks(). * * @internal * * @param string $comment * @param LinkTarget|null $selfLinkTarget The title used for fragment-only * and section links, formerly $title. * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @param string|false|null $wikiId ID of the wiki to link to (if not the local * wiki), as used by WikiMap. * @return string */ public function formatLinksUnsafe( string $comment, ?LinkTarget $selfLinkTarget = null, $samePage = false, $wikiId = false ) { $parser = $this->parserFactory->create(); $preprocessed = $parser->preprocessUnsafe( $comment, $selfLinkTarget, $samePage, $wikiId, false ); return $parser->finalize( $preprocessed ); } /** * Format links in a comment, ignoring section links in C-style comments. * * @param string $comment * @param LinkTarget|null $selfLinkTarget The title used for fragment-only * and section links, formerly $title. * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @param string|false|null $wikiId ID of the wiki to link to (if not the local * wiki), as used by WikiMap. * @return string */ public function formatLinks( string $comment, ?LinkTarget $selfLinkTarget = null, $samePage = false, $wikiId = false ) { return $this->formatInternal( $comment, false, false, false, $selfLinkTarget, $samePage, $wikiId ); } /** * Format a single comment with many ugly boolean parameters. * * @param string $comment * @param bool $enableSectionLinks * @param bool $useBlock * @param bool $useParentheses * @param LinkTarget|null $selfLinkTarget The title used for fragment-only * and section links, formerly $title. * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @param string|false|null $wikiId ID of the wiki to link to (if not the local * wiki), as used by WikiMap. * @return string|string[] */ private function formatInternal( $comment, $enableSectionLinks, $useBlock, $useParentheses, $selfLinkTarget = null, $samePage = false, $wikiId = false ) { $parser = $this->parserFactory->create(); $preprocessed = $parser->preprocess( $comment, $selfLinkTarget, $samePage, $wikiId, $enableSectionLinks ); $output = $parser->finalize( $preprocessed ); if ( $useBlock ) { $output = $this->wrapCommentWithBlock( $output, $useParentheses ); } return $output; } /** * Format comments which are provided as strings and all have the same * self-link target and other options. * * If you need a different title for each comment, use createBatch(). * * @param string[] $strings * @param LinkTarget|null $selfLinkTarget The title used for fragment-only * and section links, formerly $title. * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @param string|false|null $wikiId ID of the wiki to link to (if not the local * wiki), as used by WikiMap. * @return string[] */ public function formatStrings( $strings, ?LinkTarget $selfLinkTarget = null, $samePage = false, $wikiId = false ) { $parser = $this->parserFactory->create(); $outputs = []; foreach ( $strings as $i => $comment ) { $outputs[$i] = $parser->preprocess( $comment, $selfLinkTarget, $samePage, $wikiId ); } return $parser->finalize( $outputs ); } /** * Wrap and format the given revision's comment block, if the specified * user is allowed to view it. * * This method produces HTML that requires CSS styles in mediawiki.interface.helpers.styles. * * NOTE: revision comments are special. This is not the same as getting a * revision comment as a string and then formatting it with format(). * * @param RevisionRecord $revision The revision to extract the comment and * title from. The title should always be populated, to avoid an additional * DB query. * @param Authority $authority The user viewing the comment * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @param bool $isPublic Show only if all users can see it * @param bool $useParentheses Whether the comment is wrapped in parentheses * @return string */ public function formatRevision( RevisionRecord $revision, Authority $authority, $samePage = false, $isPublic = false, $useParentheses = true ) { $parser = $this->parserFactory->create(); return $parser->finalize( $this->preprocessRevComment( $parser, $authority, $revision, $samePage, $isPublic, $useParentheses ) ); } /** * Format multiple revision comments. * * @see CommentFormatter::formatRevision() * * @param iterable<RevisionRecord> $revisions * @param Authority $authority * @param bool $samePage * @param bool $isPublic * @param bool $useParentheses * @param bool $indexById * @return string|string[] */ public function formatRevisions( $revisions, Authority $authority, $samePage = false, $isPublic = false, $useParentheses = true, $indexById = false ) { $parser = $this->parserFactory->create(); $outputs = []; foreach ( $revisions as $i => $rev ) { if ( $indexById ) { $key = $rev->getId(); } else { $key = $i; } // @phan-suppress-next-line PhanTypeMismatchDimAssignment getId does not return null here $outputs[$key] = $this->preprocessRevComment( $parser, $authority, $rev, $samePage, $isPublic, $useParentheses ); } return $parser->finalize( $outputs ); } /** * Format a batch of revision comments using a fluent interface. * * @return RevisionCommentBatch */ public function createRevisionBatch() { return new RevisionCommentBatch( $this ); } /** * Format an iterator over CommentItem objects * * A shortcut for createBatch()->comments()->execute() for when you * need to pass no other options. * * @param iterable<CommentItem>|Traversable $items * @return string[] */ public function formatItems( $items ) { return $this->formatItemsInternal( $items ); } /** * @internal For use by CommentBatch * * Format comments with nullable batch options. * * @param iterable<CommentItem> $items * @param LinkTarget|null $selfLinkTarget * @param bool|null $samePage * @param string|false|null $wikiId * @param bool|null $enableSectionLinks * @param bool|null $useBlock * @param bool|null $useParentheses * @return string[] */ public function formatItemsInternal( $items, $selfLinkTarget = null, $samePage = null, $wikiId = null, $enableSectionLinks = null, $useBlock = null, $useParentheses = null ) { $outputs = []; $parser = $this->parserFactory->create(); foreach ( $items as $index => $item ) { $preprocessed = $parser->preprocess( $item->comment, $item->selfLinkTarget ?? $selfLinkTarget, $item->samePage ?? $samePage ?? false, $item->wikiId ?? $wikiId ?? false, $enableSectionLinks ?? true ); if ( $useBlock ?? false ) { $preprocessed = $this->wrapCommentWithBlock( $preprocessed, $useParentheses ?? true ); } $outputs[$index] = $preprocessed; } return $parser->finalize( $outputs ); } /** * Wrap a comment in standard punctuation and formatting if * it's non-empty, otherwise return empty string. * * @param string $formatted * @param bool $useParentheses Whether the comment is wrapped in parentheses * * @return string */ protected function wrapCommentWithBlock( $formatted, $useParentheses ) { // '*' used to be the comment inserted by the software way back // in antiquity in case none was provided, here for backwards // compatibility, acc. to [brooke] -ævar if ( $formatted == '' || $formatted == '*' ) { return ''; } if ( $useParentheses ) { $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped(); $classNames = 'comment'; } else { $classNames = 'comment comment--without-parentheses'; } return " <span class=\"$classNames\">$formatted</span>"; } /** * Preprocess and wrap a revision comment. * * @param CommentParser $parser * @param Authority $authority * @param RevisionRecord $revRecord * @param bool $samePage Whether section links should refer to local page * @param bool $isPublic Show only if all users can see it * @param bool $useParentheses (optional) Wrap comments in parentheses where needed * @return string HTML fragment with link markers */ private function preprocessRevComment( CommentParser $parser, Authority $authority, RevisionRecord $revRecord, $samePage = false, $isPublic = false, $useParentheses = true ) { if ( $revRecord->getComment( RevisionRecord::RAW ) === null ) { return ""; } if ( $revRecord->audienceCan( RevisionRecord::DELETED_COMMENT, $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER, $authority ) ) { $comment = $revRecord->getComment( RevisionRecord::FOR_THIS_USER, $authority ); $block = $parser->preprocess( $comment ? $comment->text : '', $revRecord->getPageAsLinkTarget(), $samePage, null, true ); $block = $this->wrapCommentWithBlock( $block, $useParentheses ); } else { $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>"; } if ( $revRecord->isDeleted( RevisionRecord::DELETED_COMMENT ) ) { $class = Linker::getRevisionDeletedClass( $revRecord ); return " <span class=\"$class comment\">$block</span>"; } return $block; } } PK ! a�|8 CommentParserFactory.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use MediaWiki\Cache\LinkBatchFactory; use MediaWiki\Cache\LinkCache; use MediaWiki\HookContainer\HookContainer; use MediaWiki\Language\Language; use MediaWiki\Linker\LinkRenderer; use MediaWiki\Title\NamespaceInfo; use MediaWiki\Title\TitleParser; use RepoGroup; /** * @internal */ class CommentParserFactory { /** @var LinkRenderer */ private $linkRenderer; /** @var LinkBatchFactory */ private $linkBatchFactory; /** @var LinkCache */ private $linkCache; /** @var RepoGroup */ private $repoGroup; /** @var Language */ private $userLang; /** @var Language */ private $contLang; /** @var TitleParser */ private $titleParser; /** @var NamespaceInfo */ private $namespaceInfo; /** @var HookContainer */ private $hookContainer; /** * @param LinkRenderer $linkRenderer * @param LinkBatchFactory $linkBatchFactory * @param LinkCache $linkCache * @param RepoGroup $repoGroup * @param Language $userLang * @param Language $contLang * @param TitleParser $titleParser * @param NamespaceInfo $namespaceInfo * @param HookContainer $hookContainer */ public function __construct( LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory, LinkCache $linkCache, RepoGroup $repoGroup, Language $userLang, Language $contLang, TitleParser $titleParser, NamespaceInfo $namespaceInfo, HookContainer $hookContainer ) { $this->linkRenderer = $linkRenderer; $this->linkBatchFactory = $linkBatchFactory; $this->linkCache = $linkCache; $this->repoGroup = $repoGroup; $this->userLang = $userLang; $this->contLang = $contLang; $this->titleParser = $titleParser; $this->namespaceInfo = $namespaceInfo; $this->hookContainer = $hookContainer; } /** * @return CommentParser */ public function create() { return new CommentParser( $this->linkRenderer, $this->linkBatchFactory, $this->linkCache, $this->repoGroup, $this->userLang, $this->contLang, $this->titleParser, $this->namespaceInfo, $this->hookContainer ); } } PK ! Y���& & RowCommentFormatter.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use MediaWiki\CommentStore\CommentStore; use Traversable; use Wikimedia\Rdbms\IResultWrapper; /** * This is basically a CommentFormatter with a CommentStore dependency, allowing * it to retrieve comment texts directly from database result wrappers. * * @since 1.38 */ class RowCommentFormatter extends CommentFormatter { /** @var CommentStore */ private $commentStore; /** * @internal Use MediaWikiServices::getRowCommentFormatter() * * @param CommentParserFactory $commentParserFactory * @param CommentStore $commentStore */ public function __construct( CommentParserFactory $commentParserFactory, CommentStore $commentStore ) { parent::__construct( $commentParserFactory ); $this->commentStore = $commentStore; } /** * Format DB rows using a fluent interface. Pass the return value of this * function to CommentBatch::comments(). * * Example: * $comments = $rowCommentFormatter->createBatch() * ->comments( * $rowCommentFormatter->rows( $rows ) * ->commentField( 'img_comment' ) * ) * ->useBlock( true ) * ->execute(); * * @param Traversable|array $rows * @return RowCommentIterator */ public function rows( $rows ) { return new RowCommentIterator( $this->commentStore, $rows ); } /** * Format DB rows using a parametric interface. * * @param iterable<\stdClass>|IResultWrapper $rows * @param string $commentKey The comment key to pass through to CommentStore, * typically a legacy field name. * @param string|null $namespaceField The namespace field for the self-link * target, or null to have no self-link target. * @param string|null $titleField The title field for the self-link target, * or null to have no self-link target. * @param string|null $indexField The field to use for array keys in the * result, or null to use the same keys as in the input $rows * @param bool $useBlock Wrap the output in standard punctuation and * formatting if it's non-empty. * @param bool $useParentheses Wrap the output with parentheses. Has no * effect if $useBlock is false. * @return string[] The formatted comment. The key will be the value of the * index field if an index field was specified, or the key from the * corresponding element of $rows if no index field was specified. */ public function formatRows( $rows, $commentKey, $namespaceField = null, $titleField = null, $indexField = null, $useBlock = false, $useParentheses = true ) { return $this->createBatch() ->comments( $this->rows( $rows ) ->commentKey( $commentKey ) ->namespaceField( $namespaceField ) ->titleField( $titleField ) ->indexField( $indexField ) ) ->useBlock( $useBlock ) ->useParentheses( $useParentheses ) ->execute(); } } PK ! Y��17 7 RowCommentIterator.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use ArrayIterator; use IteratorIterator; use MediaWiki\CommentStore\CommentStore; use MediaWiki\Title\TitleValue; use Traversable; /** * An adaptor which converts a row iterator into a CommentItem iterator for * batch formatting. * * Fluent-style mutators are provided to configure how comment text is extracted * from rows. * * Using an iterator for this configuration, instead of putting the * options in CommentBatch, allows CommentBatch to be a simple single * class without a CommentStore dependency. * * @since 1.38 */ class RowCommentIterator extends IteratorIterator { /** @var CommentStore */ private $commentStore; /** @var string|null */ private $commentKey; /** @var string|null */ private $namespaceField; /** @var string|null */ private $titleField; /** @var string|null */ private $indexField; /** * @internal Use RowCommentFormatter::rows() * @param CommentStore $commentStore * @param Traversable|array $rows */ public function __construct( CommentStore $commentStore, $rows ) { if ( is_array( $rows ) ) { parent::__construct( new ArrayIterator( $rows ) ); } else { parent::__construct( $rows ); } $this->commentStore = $commentStore; } /** * Set what CommentStore calls the key -- typically a legacy field name * which once held a comment. This must be called before attempting * iteration. * * @param string $key * @return $this */ public function commentKey( $key ) { $this->commentKey = $key; return $this; } /** * Set the namespace field. If this is not called, the item will not have * a self-link target, although it may be provided by the batch. * * @param string $field * @return $this */ public function namespaceField( $field ) { $this->namespaceField = $field; return $this; } /** * Set the title field. If this is not called, the item will not have * a self-link target, although it may be provided by the batch. * * @param string $field * @return $this */ public function titleField( $field ) { $this->titleField = $field; return $this; } /** * Set the index field. Values from this field will appear as array keys * in the final formatted comment array. If unset, the array will be * numerically indexed. * * @param string $field * @return $this */ public function indexField( $field ) { $this->indexField = $field; return $this; } public function key(): string { if ( $this->indexField ) { return parent::current()->{$this->indexField}; } else { return parent::key(); } } public function current(): CommentItem { if ( $this->commentKey === null ) { throw new \RuntimeException( __METHOD__ . ': commentKey must be specified' ); } $row = parent::current(); $comment = $this->commentStore->getComment( $this->commentKey, $row ); $item = new CommentItem( (string)$comment->text ); if ( $this->namespaceField && $this->titleField ) { $item->selfLinkTarget( new TitleValue( (int)$row->{$this->namespaceField}, (string)$row->{$this->titleField} ) ); } return $item; } } PK ! ���� � StringCommentIterator.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use ArrayIterator; /** * An adaptor which converts an array of strings to an iterator of CommentItem * objects. * * @since 1.38 */ class StringCommentIterator extends ArrayIterator { /** * @internal Use CommentBatch::strings() * @param string[] $strings */ public function __construct( $strings ) { parent::__construct( $strings ); } public function current(): CommentItem { return new CommentItem( parent::current() ); } } PK ! б-�sB sB CommentParser.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use File; use HtmlArmor; use MediaWiki\Cache\LinkBatch; use MediaWiki\Cache\LinkBatchFactory; use MediaWiki\Cache\LinkCache; use MediaWiki\HookContainer\HookContainer; use MediaWiki\HookContainer\HookRunner; use MediaWiki\Html\Html; use MediaWiki\Language\Language; use MediaWiki\Linker\Linker; use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkTarget; use MediaWiki\Parser\Parser; use MediaWiki\Parser\Sanitizer; use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Title\MalformedTitleException; use MediaWiki\Title\NamespaceInfo; use MediaWiki\Title\Title; use MediaWiki\Title\TitleParser; use MediaWiki\Title\TitleValue; use MediaWiki\WikiMap\WikiMap; use RepoGroup; use StringUtils; /** * The text processing backend for CommentFormatter. * * CommentParser objects should be discarded after the comment batch is * complete, in order to reduce memory usage. * * @internal */ class CommentParser { /** @var LinkRenderer */ private $linkRenderer; /** @var LinkBatchFactory */ private $linkBatchFactory; /** @var RepoGroup */ private $repoGroup; /** @var Language */ private $userLang; /** @var Language */ private $contLang; /** @var TitleParser */ private $titleParser; /** @var NamespaceInfo */ private $namespaceInfo; /** @var HookRunner */ private $hookRunner; /** @var LinkCache */ private $linkCache; /** @var callable[] */ private $links = []; /** @var LinkBatch|null */ private $linkBatch; /** @var array Input to RepoGroup::findFiles() */ private $fileBatch; /** @var File[] Resolved File objects indexed by DB key */ private $files = []; /** @var int The maximum number of digits in a marker ID */ private const MAX_ID_SIZE = 7; /** @var string Prefix for marker. ' and " included to break attributes (T355538) */ private const MARKER_PREFIX = "\x1B\"'"; /** * @param LinkRenderer $linkRenderer * @param LinkBatchFactory $linkBatchFactory * @param LinkCache $linkCache * @param RepoGroup $repoGroup * @param Language $userLang * @param Language $contLang * @param TitleParser $titleParser * @param NamespaceInfo $namespaceInfo * @param HookContainer $hookContainer */ public function __construct( LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory, LinkCache $linkCache, RepoGroup $repoGroup, Language $userLang, Language $contLang, TitleParser $titleParser, NamespaceInfo $namespaceInfo, HookContainer $hookContainer ) { $this->linkRenderer = $linkRenderer; $this->linkBatchFactory = $linkBatchFactory; $this->linkCache = $linkCache; $this->repoGroup = $repoGroup; $this->userLang = $userLang; $this->contLang = $contLang; $this->titleParser = $titleParser; $this->namespaceInfo = $namespaceInfo; $this->hookRunner = new HookRunner( $hookContainer ); } /** * Convert a comment to HTML, but replace links with markers which are * resolved later. * * @param string $comment * @param LinkTarget|null $selfLinkTarget * @param bool $samePage * @param string|false|null $wikiId * @param bool $enableSectionLinks * @return string */ public function preprocess( string $comment, ?LinkTarget $selfLinkTarget = null, $samePage = false, $wikiId = false, $enableSectionLinks = true ) { return $this->preprocessInternal( $comment, false, $selfLinkTarget, $samePage, $wikiId, $enableSectionLinks ); } /** * Convert a comment in pseudo-HTML format to HTML, replacing links with markers. * * @param string $comment * @param LinkTarget|null $selfLinkTarget * @param bool $samePage * @param string|false|null $wikiId * @param bool $enableSectionLinks * @return string */ public function preprocessUnsafe( $comment, ?LinkTarget $selfLinkTarget = null, $samePage = false, $wikiId = false, $enableSectionLinks = true ) { return $this->preprocessInternal( $comment, true, $selfLinkTarget, $samePage, $wikiId, $enableSectionLinks ); } /** * Execute pending batch queries and replace markers in the specified * string(s) with actual links. * * @param string|string[] $comments * @return string|string[] */ public function finalize( $comments ) { $this->flushLinkBatches(); return preg_replace_callback( '/' . self::MARKER_PREFIX . '([0-9]{' . self::MAX_ID_SIZE . '})/', function ( $m ) { $callback = $this->links[(int)$m[1]] ?? null; if ( $callback ) { return $callback(); } else { return '<!-- MISSING -->'; } }, $comments ); } /** * @param string $comment * @param bool $unsafe * @param LinkTarget|null $selfLinkTarget * @param bool $samePage * @param string|false|null $wikiId * @param bool $enableSectionLinks * @return string */ private function preprocessInternal( $comment, $unsafe, $selfLinkTarget, $samePage, $wikiId, $enableSectionLinks ) { // Sanitize text a bit // \x1b needs to be stripped because it is used for link markers $comment = strtr( $comment, "\n\x1b", " " ); // Allow HTML entities (for T15815) if ( !$unsafe ) { $comment = Sanitizer::escapeHtmlAllowEntities( $comment ); } if ( $enableSectionLinks ) { $comment = $this->doSectionLinks( $comment, $selfLinkTarget, $samePage, $wikiId ); } return $this->doWikiLinks( $comment, $selfLinkTarget, $samePage, $wikiId ); } /** * Converts C-style comments in edit summaries into section links. * * Too many things are called "comments", so these are mostly now called * section links rather than autocomments. * * We look for all comments, match any text before and after the comment, * add a separator where needed and format the comment itself with CSS. * * @param string $comment Comment text * @param LinkTarget|null $selfLinkTarget An optional LinkTarget object used to links to sections * @param bool $samePage Whether section links should refer to local page * @param string|false|null $wikiId Id of the wiki to link to (if not the local wiki), * as used by WikiMap. * @return string Preprocessed comment */ private function doSectionLinks( $comment, $selfLinkTarget = null, $samePage = false, $wikiId = false ) { $comment = preg_replace_callback( // To detect the presence of content before or after the // auto-comment, we use capturing groups inside optional zero-width // assertions. But older versions of PCRE can't directly make // zero-width assertions optional, so wrap them in a non-capturing // group. '!(?:(?<=(.)))?/\*\s*(.*?)\s*\*/(?:(?=(.)))?!', function ( $match ) use ( $selfLinkTarget, $samePage, $wikiId ) { // Ensure all match positions are defined $match += [ '', '', '', '' ]; $pre = $match[1] !== ''; $auto = $match[2]; $post = $match[3] !== ''; $comment = null; $this->hookRunner->onFormatAutocomments( $comment, $pre, $auto, $post, Title::castFromLinkTarget( $selfLinkTarget ), $samePage, $wikiId ); if ( $comment !== null ) { return $comment; } if ( $selfLinkTarget ) { $section = $auto; # Remove links that a user may have manually put in the autosummary # This could be improved by copying as much of Parser::stripSectionName as desired. $section = str_replace( [ '[[:', '[[', ']]' ], '', $section ); // We don't want any links in the auto text to be linked, but we still // want to show any [[ ]] $sectionText = str_replace( '[[', '[[', $auto ); $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 ); if ( $section !== '' ) { if ( $samePage ) { $sectionTitle = new TitleValue( NS_MAIN, '', $section ); } else { $sectionTitle = $selfLinkTarget->createFragmentTarget( $section ); } $auto = $this->makeSectionLink( $sectionTitle, $this->userLang->getArrow() . Html::rawElement( 'bdi', [ 'dir' => $this->userLang->getDir() ], $sectionText ), $wikiId, $selfLinkTarget ); } } if ( $pre ) { # written summary $presep autocomment (summary /* section */) $pre = wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped(); } if ( $post ) { # autocomment $postsep written summary (/* section */ summary) $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped(); } if ( $auto ) { $auto = Html::rawElement( 'span', [ 'class' => 'autocomment' ], $auto ); } return $pre . $auto; }, $comment ); return $comment; } /** * Make a section link. These don't need to go into the LinkBatch, since * the link class does not depend on whether the link is known. * * @param LinkTarget $target * @param string $text * @param string|false|null $wikiId Id of the wiki to link to (if not the local wiki), * as used by WikiMap. * @param LinkTarget $contextTitle * * @return string HTML link */ private function makeSectionLink( LinkTarget $target, $text, $wikiId, LinkTarget $contextTitle ) { if ( $wikiId !== null && $wikiId !== false && !$target->isExternal() ) { return $this->linkRenderer->makeExternalLink( WikiMap::getForeignURL( $wikiId, $target->getNamespace() === 0 ? $target->getDBkey() : $this->namespaceInfo->getCanonicalName( $target->getNamespace() ) . ':' . $target->getDBkey(), $target->getFragment() ), new HtmlArmor( $text ), // Already escaped $contextTitle ); } return $this->linkRenderer->makePreloadedLink( $target, new HtmlArmor( $text ), '' ); } /** * Formats wiki links and media links in text; all other wiki formatting * is ignored * * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser * * @param string $comment Text to format links in. WARNING! Since the output of this * function is html, $comment must be sanitized for use as html. You probably want * to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling * this function. * as used by WikiMap. * @param LinkTarget|null $selfLinkTarget An optional LinkTarget object used to links to sections * @param bool $samePage Whether section links should refer to local page * @param string|false|null $wikiId Id of the wiki to link to (if not the local wiki), * as used by WikiMap. * * @return string HTML */ private function doWikiLinks( $comment, $selfLinkTarget = null, $samePage = false, $wikiId = false ) { return preg_replace_callback( '/ \[\[ \s*+ # ignore leading whitespace, the *+ quantifier disallows backtracking :? # ignore optional leading colon ([^[\]|]+) # 1. link target; page names cannot include [, ] or | (?:\| # 2. link text # Stop matching at ]] without relying on backtracking. ((?:]?[^\]])*+) )? \]\] ([^[]*) # 3. link trail (the text up until the next link) /x', function ( $match ) use ( $selfLinkTarget, $samePage, $wikiId ) { $medians = '(?:'; $medians .= preg_quote( $this->namespaceInfo->getCanonicalName( NS_MEDIA ), '/' ); $medians .= '|'; $medians .= preg_quote( $this->contLang->getNsText( NS_MEDIA ), '/' ) . '):'; $comment = $match[0]; // Fix up urlencoded title texts (copied from Parser::replaceInternalLinks) if ( strpos( $match[1], '%' ) !== false ) { $match[1] = strtr( rawurldecode( $match[1] ), [ '<' => '<', '>' => '>' ] ); } // Handle link renaming [[foo|text]] will show link as "text" if ( $match[2] != "" ) { $text = $match[2]; } else { $text = $match[1]; } $submatch = []; $linkMarker = null; if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) { // Media link; trail not supported. $linkRegexp = '/\[\[(.*?)\]\]/'; $linkTarget = $this->titleParser->makeTitleValueSafe( NS_FILE, $submatch[1] ); if ( $linkTarget ) { $linkMarker = $this->addFileLink( $linkTarget, $text ); } } else { // Other kind of link // Make sure its target is non-empty if ( isset( $match[1][0] ) && $match[1][0] == ':' ) { $match[1] = substr( $match[1], 1 ); } // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive if ( $match[1] !== false && $match[1] !== null && $match[1] !== '' ) { if ( preg_match( $this->contLang->linkTrail(), $match[3], $submatch ) ) { $trail = $submatch[1]; } else { $trail = ""; } $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; [ $inside, $trail ] = Linker::splitTrail( $trail ); $linkText = $text; $linkTarget = Linker::normalizeSubpageLink( $selfLinkTarget, $match[1], $linkText ); try { $target = $this->titleParser->parseTitle( $linkTarget ); if ( $target->getText() == '' && !$target->isExternal() && !$samePage && $selfLinkTarget ) { $target = $selfLinkTarget->createFragmentTarget( $target->getFragment() ); } // We should deprecate `null` as a valid value for // $selfLinkTarget to ensure that we can use it as // the title context for the external link. // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgTitle global $wgTitle; $linkMarker = $this->addPageLink( $target, $linkText . $inside, $wikiId, $selfLinkTarget ?? $wgTitle ?? SpecialPage::getTitleFor( 'Badtitle' ) ); $linkMarker .= $trail; } catch ( MalformedTitleException $e ) { // Fall through } } } if ( $linkMarker ) { // If the link is still valid, go ahead and replace it in! $comment = preg_replace( // @phan-suppress-next-next-line PhanPossiblyUndeclaredVariable linkRegexp set when used // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal linkRegexp set when used $linkRegexp, StringUtils::escapeRegexReplacement( $linkMarker ), $comment, 1 ); } return $comment; }, $comment ); } /** * Add a deferred link to the list and return its marker. * * @param callable $callback * @return string */ private function addLinkMarker( $callback ) { $nextId = count( $this->links ); if ( strlen( (string)$nextId ) > self::MAX_ID_SIZE ) { throw new \RuntimeException( 'Too many links in comment batch' ); } $this->links[] = $callback; return sprintf( self::MARKER_PREFIX . "%0" . self::MAX_ID_SIZE . 'd', $nextId ); } /** * Link to a LinkTarget. Return either HTML or a marker depending on whether * existence checks are deferred. * * @param LinkTarget $target * @param string $text * @param string|false|null $wikiId * @param LinkTarget $contextTitle * @return string */ private function addPageLink( LinkTarget $target, $text, $wikiId, LinkTarget $contextTitle ) { if ( $wikiId !== null && $wikiId !== false && !$target->isExternal() ) { // Handle links from a foreign wiki ID return $this->linkRenderer->makeExternalLink( WikiMap::getForeignURL( $wikiId, $target->getNamespace() === 0 ? $target->getDBkey() : $this->namespaceInfo->getCanonicalName( $target->getNamespace() ) . ':' . $target->getDBkey(), $target->getFragment() ), new HtmlArmor( $text ), // Already escaped $contextTitle ); } elseif ( $this->linkCache->getGoodLinkID( $target ) || Title::newFromLinkTarget( $target )->isAlwaysKnown() ) { // Already known return $this->linkRenderer->makeKnownLink( $target, new HtmlArmor( $text ) ); } elseif ( $this->linkCache->isBadLink( $target ) ) { // Already cached as unknown return $this->linkRenderer->makeBrokenLink( $target, new HtmlArmor( $text ) ); } // Defer page link if ( !$this->linkBatch ) { $this->linkBatch = $this->linkBatchFactory->newLinkBatch(); $this->linkBatch->setCaller( __METHOD__ ); } $this->linkBatch->addObj( $target ); return $this->addLinkMarker( function () use ( $target, $text ) { return $this->linkRenderer->makeLink( $target, new HtmlArmor( $text ) ); } ); } /** * Link to a file, returning a marker. * * @param LinkTarget $target The name of the file. * @param string $html The inner HTML of the link * @return string */ private function addFileLink( LinkTarget $target, $html ) { $this->fileBatch[] = [ 'title' => $target ]; return $this->addLinkMarker( function () use ( $target, $html ) { return Linker::makeMediaLinkFile( $target, $this->files[$target->getDBkey()] ?? false, $html ); } ); } /** * Execute any pending link batch or file batch */ private function flushLinkBatches() { if ( $this->linkBatch ) { $this->linkBatch->execute(); $this->linkBatch = null; } if ( $this->fileBatch ) { $this->files += $this->repoGroup->findFiles( $this->fileBatch ); $this->fileBatch = []; } } } PK ! �>Pky y RevisionCommentBatch.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use MediaWiki\Permissions\Authority; use MediaWiki\Revision\RevisionRecord; /** * Fluent interface for revision comment batch inputs. * * @since 1.38 */ class RevisionCommentBatch { /** @var CommentFormatter */ private $formatter; /** @var Authority|null */ private $authority; /** @var iterable<RevisionRecord> */ private $revisions; /** @var bool */ private $samePage = false; /** @var bool */ private $isPublic = false; /** @var bool */ private $useParentheses = false; /** @var bool */ private $indexById = false; /** * @param CommentFormatter $formatter */ public function __construct( CommentFormatter $formatter ) { $this->formatter = $formatter; } /** * Set the authority to use for permission checks. This must be called * prior to execute(). * * @param Authority $authority * @return $this */ public function authority( Authority $authority ) { $this->authority = $authority; return $this; } /** * Set the revisions to extract comments from. * * @param iterable<RevisionRecord> $revisions * @return $this */ public function revisions( $revisions ) { $this->revisions = $revisions; return $this; } /** * Set the same-page option. If this is true, section links and fragment- * only wikilinks are rendered with an href that is a fragment-only URL. * If it is false (the default), such links go to the self link title. * * This is equivalent to $local in the old Linker methods. * * @param bool $samePage * @return $this */ public function samePage( $samePage = true ) { $this->samePage = $samePage; return $this; } /** * Wrap the comment with parentheses. This has no effect if the useBlock * option is not enabled. * * Unlike the legacy Linker::commentBlock(), this option defaults to false * if this method is not called, since that better preserves the fluent * style. * * @param bool $useParentheses * @return $this */ public function useParentheses( $useParentheses = true ) { $this->useParentheses = $useParentheses; return $this; } /** * If this is true, show the comment only if all users can see it. * * We'll call it hideIfDeleted() since public is a keyword and isPublic() * has an inappropriate verb. * * @param bool $isPublic * @return $this */ public function hideIfDeleted( $isPublic = true ) { $this->isPublic = $isPublic; return $this; } /** * If this is true, the array keys in the return value will be the revision * IDs instead of the keys from the input array. * * @param bool $indexById * @return $this */ public function indexById( $indexById = true ) { $this->indexById = $indexById; return $this; } /** * Format the comments. * * @return string[] Formatted comments. The array key is either the field * value specified by indexField(), or if that was not called, it is the * key from the array passed to revisions(). */ public function execute() { return $this->formatter->formatRevisions( $this->revisions, $this->authority, $this->samePage, $this->isPublic, $this->useParentheses, $this->indexById ); } } PK ! �E�A A CommentItem.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use MediaWiki\Linker\LinkTarget; /** * An object to represent one of the inputs to a batch formatting operation. * * @since 1.38 * @newable */ class CommentItem { /** * @var string * @internal */ public $comment; /** * @var LinkTarget|null * @internal */ public $selfLinkTarget; /** * @var bool|null * @internal */ public $samePage; /** * @var string|false|null * @internal */ public $wikiId; /** * @param string $comment The comment to format */ public function __construct( string $comment ) { $this->comment = $comment; } /** * Set the self-link target. * * @param LinkTarget $selfLinkTarget The title used for fragment-only * and section links, formerly $title. * @return $this */ public function selfLinkTarget( LinkTarget $selfLinkTarget ) { $this->selfLinkTarget = $selfLinkTarget; return $this; } /** * Set the same-page flag. * * @param bool $samePage If true, self links are rendered with a fragment- * only URL. Formerly $local. * @return $this */ public function samePage( $samePage = true ) { $this->samePage = $samePage; return $this; } /** * ID of the wiki to link to (if not the local wiki), as used by WikiMap. * This is used to render comments which are loaded from a foreign wiki. * This only affects links which are syntactically internal -- it has no * effect on interwiki links. * * @param string|false|null $wikiId * @return $this */ public function wikiId( $wikiId ) { $this->wikiId = $wikiId; return $this; } } PK ! 2�� I I CommentBatch.phpnu �Iw�� <?php namespace MediaWiki\CommentFormatter; use MediaWiki\Linker\LinkTarget; use Traversable; /** * This class provides a fluent interface for formatting a batch of comments. * * @since 1.38 */ class CommentBatch { /** @var CommentFormatter */ private $formatter; /** @var iterable<CommentItem>|Traversable */ private $comments; /** @var bool|null */ private $useBlock; /** @var bool|null */ private $useParentheses; /** @var LinkTarget|null */ private $selfLinkTarget; /** @var bool|null */ private $samePage; /** @var string|false|null */ private $wikiId; /** @var bool|null */ private $enableSectionLinks; /** * @internal Use CommentFormatter::createBatch() * * @param CommentFormatter $formatter */ public function __construct( CommentFormatter $formatter ) { $this->formatter = $formatter; } /** * Set the comments to be formatted. This can be an array of CommentItem * objects, or it can be an iterator which generates CommentItem objects. * * Theoretically iterable should imply Traversable, but PHPStorm gives an * error when RowCommentIterator is passed as iterable<CommentItem>. * * @param iterable<CommentItem>|Traversable $comments * @return $this */ public function comments( $comments ) { $this->comments = $comments; return $this; } /** * Specify the comments to be formatted as an array of strings. This is a * simplified wrapper for comments() which does not allow you to set options * on a per-comment basis. * * $strings must be an array -- use comments() if you want to use an iterator. * * @param string[] $strings * @return $this */ public function strings( array $strings ) { $this->comments = new StringCommentIterator( $strings ); return $this; } /** * Wrap each comment in standard punctuation and formatting if it's * non-empty. Empty comments remain empty. This causes the batch to work * like the old Linker::commentBlock(). * * If this function is not called, the option is false. * * @param bool $useBlock * @return $this */ public function useBlock( $useBlock = true ) { $this->useBlock = $useBlock; return $this; } /** * Wrap each comment with parentheses. This has no effect if the useBlock * option is not enabled. * * Unlike the legacy Linker::commentBlock(), this option defaults to false * if this method is not called, since that better preserves the fluent * style. * * @param bool $useParentheses * @return $this */ public function useParentheses( $useParentheses = true ) { $this->useParentheses = $useParentheses; return $this; } /** * Set the title to be used for self links in the comments. If there is no * title specified either here or in the item, fragment links are not * expanded. * * @param LinkTarget $selfLinkTarget * @return $this */ public function selfLinkTarget( LinkTarget $selfLinkTarget ) { $this->selfLinkTarget = $selfLinkTarget; return $this; } /** * Set the option to enable/disable section links formatted as C-style * comments, as used in revision comments to indicate the section which * was edited. * * If the method is not called, the option is true. Setting this to false * approximately emulates Linker::formatLinksInComment() except that HTML * in the input is escaped. * * @param bool $enable * @return $this */ public function enableSectionLinks( $enable ) { $this->enableSectionLinks = $enable; return $this; } /** * Disable section links formatted as C-style comments, as used in revision * comments to indicate the section which was edited. Calling this * approximately emulates Linker::formatLinksInComment() except that HTML * in the input is escaped. * * @return $this */ public function disableSectionLinks() { $this->enableSectionLinks = false; return $this; } /** * Set the same-page option. If this is true, section links and fragment- * only wikilinks are rendered with an href that is a fragment-only URL. * If it is false (the default), such links go to the self link title. * * This can also be set per-item using CommentItem::samePage(). * * This is equivalent to $local in the old Linker methods. * * @param bool $samePage * @return $this */ public function samePage( $samePage = true ) { $this->samePage = $samePage; return $this; } /** * ID of the wiki to link to (if not the local wiki), as used by WikiMap. * This is used to render comments which are loaded from a foreign wiki. * This only affects links which are syntactically internal -- it has no * effect on interwiki links. * * This can also be set per-item using CommentItem::wikiId(). * * @param string|false|null $wikiId * @return $this */ public function wikiId( $wikiId ) { $this->wikiId = $wikiId; return $this; } /** * Format the comments and produce an array of HTML fragments. * * @return string[] */ public function execute() { return $this->formatter->formatItemsInternal( $this->comments, $this->selfLinkTarget, $this->samePage, $this->wikiId, $this->enableSectionLinks, $this->useBlock, $this->useParentheses ); } } PK ! Ļ�~�/ �/ CommentFormatter.phpnu �Iw�� PK ! a�|8 �/ CommentParserFactory.phpnu �Iw�� PK ! Y���& & 68 RowCommentFormatter.phpnu �Iw�� PK ! Y��17 7 �C RowCommentIterator.phpnu �Iw�� PK ! ���� � P StringCommentIterator.phpnu �Iw�� PK ! б-�sB sB UR CommentParser.phpnu �Iw�� PK ! �>Pky y � RevisionCommentBatch.phpnu �Iw�� PK ! �E�A A ʡ CommentItem.phpnu �Iw�� PK ! 2�� I I J� CommentBatch.phpnu �Iw�� PK � Ӽ
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка