mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-09-23 10:29:11 +00:00
build: Updating dependencies
composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 npm: * postcss: 7.0.35 → 7.0.36 * https://npmjs.com/advisories/1693 (CVE-2021-23368) * glob-parent: 5.1.1 → 5.1.2 * https://npmjs.com/advisories/1751 (CVE-2020-28469) * trim-newlines: 3.0.0 → 3.0.1 * https://npmjs.com/advisories/1753 (CVE-2021-33623) Change-Id: I7a71e23da561599da417db3b3077b78d91173bbc
This commit is contained in:
parent
aa19431689
commit
b0884b177c
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"mediawiki/mediawiki-codesniffer": "36.0.0",
|
||||
"mediawiki/mediawiki-codesniffer": "37.0.0",
|
||||
"mediawiki/mediawiki-phan-config": "0.10.6",
|
||||
"mediawiki/minus-x": "1.1.1",
|
||||
"php-parallel-lint/php-console-highlighter": "0.5.0",
|
||||
|
|
|
@ -32,7 +32,7 @@ class CommentFormatter {
|
|||
* @param DOMElement $container
|
||||
* @return CommentParser
|
||||
*/
|
||||
protected static function getParser( DOMElement $container ) : CommentParser {
|
||||
protected static function getParser( DOMElement $container ): CommentParser {
|
||||
return CommentParser::newFromGlobalState( $container );
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class CommentFormatter {
|
|||
*
|
||||
* @param string &$text Parser text output
|
||||
*/
|
||||
public static function addDiscussionTools( string &$text ) : void {
|
||||
public static function addDiscussionTools( string &$text ): void {
|
||||
$start = microtime( true );
|
||||
|
||||
// Never add tools twice.
|
||||
|
@ -80,7 +80,7 @@ class CommentFormatter {
|
|||
* @param string $html HTML
|
||||
* @return string HTML with discussion tools
|
||||
*/
|
||||
protected static function addDiscussionToolsInternal( string $html ) : string {
|
||||
protected static function addDiscussionToolsInternal( string $html ): string {
|
||||
// The output of this method can end up in the HTTP cache (Varnish). Avoid changing it;
|
||||
// and when doing so, ensure that frontend code can handle both the old and new outputs.
|
||||
// See controller#init in JS.
|
||||
|
@ -211,7 +211,7 @@ class CommentFormatter {
|
|||
*/
|
||||
public static function postprocessTopicSubscription(
|
||||
string $text, Language $lang, SubscriptionStore $subscriptionStore, UserIdentity $user
|
||||
) : string {
|
||||
): string {
|
||||
$doc = new DOMDocument();
|
||||
|
||||
$matches = [];
|
||||
|
|
|
@ -37,7 +37,7 @@ class CommentItem extends ThreadItem {
|
|||
/**
|
||||
* @return array JSON-serializable array
|
||||
*/
|
||||
public function jsonSerialize() : array {
|
||||
public function jsonSerialize(): array {
|
||||
return array_merge( parent::jsonSerialize(), [
|
||||
'timestamp' => $this->timestamp,
|
||||
'author' => $this->author,
|
||||
|
@ -51,7 +51,7 @@ class CommentItem extends ThreadItem {
|
|||
* the signature which consists of whitespace and hyphens e.g. ' --'
|
||||
* @return DOMDocumentFragment Cloned fragment of the body content
|
||||
*/
|
||||
private function getBodyFragment( bool $stripTrailingSeparator = false ) : DOMDocumentFragment {
|
||||
private function getBodyFragment( bool $stripTrailingSeparator = false ): DOMDocumentFragment {
|
||||
$fragment = $this->getBodyRange()->cloneContents();
|
||||
CommentModifier::unwrapFragment( $fragment );
|
||||
|
||||
|
@ -82,7 +82,7 @@ class CommentItem extends ThreadItem {
|
|||
* @param bool $stripTrailingSeparator See getBodyFragment
|
||||
* @return string HTML
|
||||
*/
|
||||
public function getBodyHTML( bool $stripTrailingSeparator = false ) : string {
|
||||
public function getBodyHTML( bool $stripTrailingSeparator = false ): string {
|
||||
$fragment = $this->getBodyFragment( $stripTrailingSeparator );
|
||||
$container = $fragment->ownerDocument->createElement( 'div' );
|
||||
$container->appendChild( $fragment );
|
||||
|
@ -95,7 +95,7 @@ class CommentItem extends ThreadItem {
|
|||
* @param bool $stripTrailingSeparator See getBodyFragment
|
||||
* @return string Text
|
||||
*/
|
||||
public function getBodyText( bool $stripTrailingSeparator = false ) : string {
|
||||
public function getBodyText( bool $stripTrailingSeparator = false ): string {
|
||||
$fragment = $this->getBodyFragment( $stripTrailingSeparator );
|
||||
return $fragment->textContent;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ class CommentItem extends ThreadItem {
|
|||
*
|
||||
* @return Title[] Title objects for mentioned user pages
|
||||
*/
|
||||
public function getMentions() : array {
|
||||
public function getMentions(): array {
|
||||
$fragment = $this->getBodyRange()->cloneContents();
|
||||
$xPath = new DOMXPath( $fragment->ownerDocument );
|
||||
$links = $xPath->query( './/a', $fragment );
|
||||
|
@ -123,14 +123,14 @@ class CommentItem extends ThreadItem {
|
|||
/**
|
||||
* @return ImmutableRange[] Comment signature ranges
|
||||
*/
|
||||
public function getSignatureRanges() : array {
|
||||
public function getSignatureRanges(): array {
|
||||
return $this->signatureRanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ImmutableRange Range of the thread item's "body"
|
||||
*/
|
||||
public function getBodyRange() : ImmutableRange {
|
||||
public function getBodyRange(): ImmutableRange {
|
||||
// Exclude last signature from body
|
||||
$signatureRanges = $this->getSignatureRanges();
|
||||
$lastSignature = end( $signatureRanges );
|
||||
|
@ -140,21 +140,21 @@ class CommentItem extends ThreadItem {
|
|||
/**
|
||||
* @return string Comment timestamp
|
||||
*/
|
||||
public function getTimestamp() : string {
|
||||
public function getTimestamp(): string {
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Comment author
|
||||
*/
|
||||
public function getAuthor() : string {
|
||||
public function getAuthor(): string {
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HeadingItem Closest ancestor which is a HeadingItem
|
||||
*/
|
||||
public function getHeading() : HeadingItem {
|
||||
public function getHeading(): HeadingItem {
|
||||
$parent = $this;
|
||||
while ( $parent instanceof CommentItem ) {
|
||||
$parent = $parent->getParent();
|
||||
|
@ -168,28 +168,28 @@ class CommentItem extends ThreadItem {
|
|||
/**
|
||||
* @param ImmutableRange $signatureRange Comment signature range to add
|
||||
*/
|
||||
public function addSignatureRange( ImmutableRange $signatureRange ) : void {
|
||||
public function addSignatureRange( ImmutableRange $signatureRange ): void {
|
||||
$this->signatureRanges[] = $signatureRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImmutableRange[] $signatureRanges Comment signature ranges
|
||||
*/
|
||||
public function setSignatureRanges( array $signatureRanges ) : void {
|
||||
public function setSignatureRanges( array $signatureRanges ): void {
|
||||
$this->signatureRanges = $signatureRanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $timestamp Comment timestamp
|
||||
*/
|
||||
public function setTimestamp( string $timestamp ) : void {
|
||||
public function setTimestamp( string $timestamp ): void {
|
||||
$this->timestamp = $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $author Comment author
|
||||
*/
|
||||
public function setAuthor( string $author ) : void {
|
||||
public function setAuthor( string $author ): void {
|
||||
$this->author = $author;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class CommentModifier {
|
|||
*
|
||||
* @param DOMElement $listItem
|
||||
*/
|
||||
private static function whitespaceParsoidHack( DOMElement $listItem ) : void {
|
||||
private static function whitespaceParsoidHack( DOMElement $listItem ): void {
|
||||
// HACK: Setting data-parsoid removes the whitespace after the list item,
|
||||
// which makes nested lists work.
|
||||
// This is undocumented behaviour and probably very fragile.
|
||||
|
@ -34,7 +34,7 @@ class CommentModifier {
|
|||
* @param string $wikitext
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitizeWikitextLinebreaks( string $wikitext ) : string {
|
||||
public static function sanitizeWikitextLinebreaks( string $wikitext ): string {
|
||||
$wikitext = CommentUtils::htmlTrim( $wikitext );
|
||||
$wikitext = preg_replace( "/\r/", "\n", $wikitext );
|
||||
$wikitext = preg_replace( "/\n+/", "\n", $wikitext );
|
||||
|
@ -48,7 +48,7 @@ class CommentModifier {
|
|||
* @param CommentItem $comment
|
||||
* @param DOMElement $linkNode Reply link
|
||||
*/
|
||||
public static function addReplyLink( CommentItem $comment, DOMElement $linkNode ) : void {
|
||||
public static function addReplyLink( CommentItem $comment, DOMElement $linkNode ): void {
|
||||
$target = $comment->getRange()->endContainer;
|
||||
|
||||
// Insert the link before trailing whitespace.
|
||||
|
@ -78,7 +78,7 @@ class CommentModifier {
|
|||
* @param ThreadItem $comment
|
||||
* @return DOMElement
|
||||
*/
|
||||
public static function addListItem( ThreadItem $comment ) : DOMElement {
|
||||
public static function addListItem( ThreadItem $comment ): DOMElement {
|
||||
$listTypeMap = [
|
||||
'li' => 'ul',
|
||||
'dd' => 'dl'
|
||||
|
@ -281,7 +281,7 @@ class CommentModifier {
|
|||
* @param string $type Element type
|
||||
* @return bool
|
||||
*/
|
||||
private static function allOfType( array $nodes, string $type ) : bool {
|
||||
private static function allOfType( array $nodes, string $type ): bool {
|
||||
$hasElements = false;
|
||||
foreach ( $nodes as $node ) {
|
||||
if ( $node->nodeType === XML_ELEMENT_NODE ) {
|
||||
|
@ -343,7 +343,7 @@ class CommentModifier {
|
|||
* @param DOMnode $list DOM node, will be wrapped if it is a list element (dl/ol/ul)
|
||||
* @param DOMDocumentFragment|null $fragment Containing document fragment if list has no parent
|
||||
*/
|
||||
public static function unwrapList( DOMnode $list, ?DOMDocumentFragment $fragment = null ) : void {
|
||||
public static function unwrapList( DOMnode $list, ?DOMDocumentFragment $fragment = null ): void {
|
||||
$doc = $list->ownerDocument;
|
||||
$container = $fragment ?: $list->parentNode;
|
||||
$referenceNode = $list;
|
||||
|
@ -407,7 +407,7 @@ class CommentModifier {
|
|||
* @param DOMElement $previousItem
|
||||
* @return DOMElement
|
||||
*/
|
||||
public static function addSiblingListItem( DOMElement $previousItem ) : DOMElement {
|
||||
public static function addSiblingListItem( DOMElement $previousItem ): DOMElement {
|
||||
$listItem = $previousItem->ownerDocument->createElement( $previousItem->tagName );
|
||||
self::whitespaceParsoidHack( $listItem );
|
||||
$previousItem->parentNode->insertBefore( $listItem, $previousItem->nextSibling );
|
||||
|
@ -421,7 +421,7 @@ class CommentModifier {
|
|||
* @param string $wikitext
|
||||
* @return DOMElement
|
||||
*/
|
||||
public static function createWikitextNode( DOMDocument $doc, string $wikitext ) : DOMElement {
|
||||
public static function createWikitextNode( DOMDocument $doc, string $wikitext ): DOMElement {
|
||||
$span = $doc->createElement( 'span' );
|
||||
|
||||
$span->setAttribute( 'typeof', 'mw:Transclusion' );
|
||||
|
@ -436,7 +436,7 @@ class CommentModifier {
|
|||
* @param string $wikitext
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWikitextSigned( string $wikitext ) : bool {
|
||||
public static function isWikitextSigned( string $wikitext ): bool {
|
||||
$wikitext = CommentUtils::htmlTrim( $wikitext );
|
||||
// Contains ~~~~ (four tildes), but not ~~~~~ (five tildes), at the end.
|
||||
return (bool)preg_match( '/([^~]|^)~~~~$/', $wikitext );
|
||||
|
@ -448,7 +448,7 @@ class CommentModifier {
|
|||
* @param DOMElement $container
|
||||
* @return bool
|
||||
*/
|
||||
public static function isHtmlSigned( DOMElement $container ) : bool {
|
||||
public static function isHtmlSigned( DOMElement $container ): bool {
|
||||
$xpath = new DOMXPath( $container->ownerDocument );
|
||||
// Good enough?…
|
||||
$matches = $xpath->query( './/span[@typeof="mw:Transclusion"][contains(@data-mw,"~~~~")]', $container );
|
||||
|
@ -480,7 +480,7 @@ class CommentModifier {
|
|||
*
|
||||
* @param DOMElement $container
|
||||
*/
|
||||
public static function appendSignature( DOMElement $container ) : void {
|
||||
public static function appendSignature( DOMElement $container ): void {
|
||||
$doc = $container->ownerDocument;
|
||||
|
||||
$signature = wfMessage( 'discussiontools-signature-prefix' )->inContentLanguage()->text() . '~~~~';
|
||||
|
|
|
@ -76,7 +76,7 @@ class CommentParser {
|
|||
* @param DomElement $rootNode
|
||||
* @return CommentParser
|
||||
*/
|
||||
public static function newFromGlobalState( DOMElement $rootNode ) : CommentParser {
|
||||
public static function newFromGlobalState( DOMElement $rootNode ): CommentParser {
|
||||
return new static(
|
||||
$rootNode,
|
||||
MediaWikiServices::getInstance()->getContentLanguage(),
|
||||
|
@ -112,7 +112,7 @@ class CommentParser {
|
|||
* @param DOMNode $node Node to start searching at. This node's children are ignored.
|
||||
* @return DOMNode
|
||||
*/
|
||||
private function nextInterestingLeafNode( DOMNode $node ) : DOMNode {
|
||||
private function nextInterestingLeafNode( DOMNode $node ): DOMNode {
|
||||
$rootNode = $this->rootNode;
|
||||
$treeWalker = new TreeWalker(
|
||||
$rootNode,
|
||||
|
@ -161,7 +161,7 @@ class CommentParser {
|
|||
* @param string[] $values Values to match
|
||||
* @return string Regular expression
|
||||
*/
|
||||
private static function regexpAlternateGroup( array $values ) : string {
|
||||
private static function regexpAlternateGroup( array $values ): string {
|
||||
return '(' . implode( '|', array_map( static function ( string $x ) {
|
||||
return preg_quote( $x, '/' );
|
||||
}, $values ) ) . ')';
|
||||
|
@ -174,7 +174,7 @@ class CommentParser {
|
|||
* @param string[] $messages Message keys
|
||||
* @return string[] Message values
|
||||
*/
|
||||
private function getMessages( string $contLangVariant, array $messages ) : array {
|
||||
private function getMessages( string $contLangVariant, array $messages ): array {
|
||||
return array_map( function ( string $key ) use ( $contLangVariant ) {
|
||||
return $this->contLangMessages[$contLangVariant][$key];
|
||||
}, $messages );
|
||||
|
@ -197,7 +197,7 @@ class CommentParser {
|
|||
*/
|
||||
private function getTimestampRegexp(
|
||||
string $contLangVariant, string $format, string $digitsRegexp, array $tzAbbrs
|
||||
) : string {
|
||||
): string {
|
||||
$formatLength = strlen( $format );
|
||||
$s = '';
|
||||
// Adapted from Language::sprintfDate()
|
||||
|
@ -318,7 +318,7 @@ class CommentParser {
|
|||
*/
|
||||
private function getTimestampParser(
|
||||
string $contLangVariant, string $format, ?array $digits, string $localTimezone, array $tzAbbrs
|
||||
) : callable {
|
||||
): callable {
|
||||
$untransformDigits = static function ( string $text ) use ( $digits ) {
|
||||
if ( !$digits ) {
|
||||
return $text;
|
||||
|
@ -499,7 +499,7 @@ class CommentParser {
|
|||
*
|
||||
* @return string[] Regular expressions
|
||||
*/
|
||||
public function getLocalTimestampRegexps() : array {
|
||||
public function getLocalTimestampRegexps(): array {
|
||||
$langConv = MediaWikiServices::getInstance()->getLanguageConverterFactory()
|
||||
->getLanguageConverter( $this->language );
|
||||
return array_map( function ( $contLangVariant ) {
|
||||
|
@ -520,7 +520,7 @@ class CommentParser {
|
|||
*
|
||||
* @return callable[] Parser functions
|
||||
*/
|
||||
private function getLocalTimestampParsers() : array {
|
||||
private function getLocalTimestampParsers(): array {
|
||||
$langConv = MediaWikiServices::getInstance()->getLanguageConverterFactory()
|
||||
->getLanguageConverter( $this->language );
|
||||
return array_map( function ( $contLangVariant ) {
|
||||
|
@ -589,7 +589,7 @@ class CommentParser {
|
|||
* @param DOMNode|null $until Node to stop searching at
|
||||
* @return array [ nodes, username ]
|
||||
*/
|
||||
private function findSignature( DOMText $timestampNode, ?DOMNode $until = null ) : array {
|
||||
private function findSignature( DOMText $timestampNode, ?DOMNode $until = null ): array {
|
||||
$sigUsername = null;
|
||||
$length = 0;
|
||||
$lastLinkNode = $timestampNode;
|
||||
|
@ -697,7 +697,7 @@ class CommentParser {
|
|||
* - array 'matchData' Regexp match data, which specifies the location of the match,
|
||||
* and which can be parsed using getLocalTimestampParsers()
|
||||
*/
|
||||
public function findTimestamp( DOMText $node, array $timestampRegexps ) : ?array {
|
||||
public function findTimestamp( DOMText $node, array $timestampRegexps ): ?array {
|
||||
$nodeText = '';
|
||||
$offset = 0;
|
||||
|
||||
|
@ -780,7 +780,7 @@ class CommentParser {
|
|||
*
|
||||
* @return ThreadItem[] Thread items
|
||||
*/
|
||||
public function getThreadItems() : array {
|
||||
public function getThreadItems(): array {
|
||||
if ( !$this->threadItems ) {
|
||||
$this->buildThreads();
|
||||
}
|
||||
|
@ -792,7 +792,7 @@ class CommentParser {
|
|||
*
|
||||
* @return CommentItem[] Comment items
|
||||
*/
|
||||
public function getCommentItems() : array {
|
||||
public function getCommentItems(): array {
|
||||
if ( !$this->commentItems ) {
|
||||
$this->buildThreads();
|
||||
}
|
||||
|
@ -808,7 +808,7 @@ class CommentParser {
|
|||
* @param string $name Name
|
||||
* @return ThreadItem[] Thread items, empty array if not found
|
||||
*/
|
||||
public function findCommentsByName( string $name ) : array {
|
||||
public function findCommentsByName( string $name ): array {
|
||||
if ( !$this->threadItemsByName ) {
|
||||
$this->buildThreads();
|
||||
}
|
||||
|
@ -821,7 +821,7 @@ class CommentParser {
|
|||
* @param string $id ID
|
||||
* @return ThreadItem|null Thread item, null if not found
|
||||
*/
|
||||
public function findCommentById( string $id ) : ?ThreadItem {
|
||||
public function findCommentById( string $id ): ?ThreadItem {
|
||||
if ( !$this->threadItemsById ) {
|
||||
$this->buildThreads();
|
||||
}
|
||||
|
@ -852,7 +852,7 @@ class CommentParser {
|
|||
return $sigRange;
|
||||
}
|
||||
|
||||
private function buildThreadItems() : void {
|
||||
private function buildThreadItems(): void {
|
||||
$timestampRegexps = $this->getLocalTimestampRegexps();
|
||||
$commentItems = [];
|
||||
$threadItems = [];
|
||||
|
@ -1041,7 +1041,7 @@ class CommentParser {
|
|||
*
|
||||
* @return HeadingItem[] Tree structure of comments, top-level items are the headings.
|
||||
*/
|
||||
public function getThreads() : array {
|
||||
public function getThreads(): array {
|
||||
if ( !$this->threads ) {
|
||||
$this->buildThreads();
|
||||
}
|
||||
|
@ -1054,7 +1054,7 @@ class CommentParser {
|
|||
* @param string $text Text
|
||||
* @return string Truncated text
|
||||
*/
|
||||
private function truncateForId( string $text ) : string {
|
||||
private function truncateForId( string $text ): string {
|
||||
return $this->language->truncateForDatabase( $text, 80, '' );
|
||||
}
|
||||
|
||||
|
@ -1064,7 +1064,7 @@ class CommentParser {
|
|||
* @param ThreadItem $threadItem
|
||||
* @return string
|
||||
*/
|
||||
private function computeId( ThreadItem $threadItem ) : string {
|
||||
private function computeId( ThreadItem $threadItem ): string {
|
||||
$id = null;
|
||||
|
||||
if ( $threadItem instanceof HeadingItem && $threadItem->isPlaceholderHeading() ) {
|
||||
|
@ -1123,7 +1123,7 @@ class CommentParser {
|
|||
* @param ThreadItem $threadItem
|
||||
* @return string|null
|
||||
*/
|
||||
private function computeLegacyId( ThreadItem $threadItem ) : ?string {
|
||||
private function computeLegacyId( ThreadItem $threadItem ): ?string {
|
||||
$id = null;
|
||||
|
||||
if ( $threadItem instanceof HeadingItem && $threadItem->isPlaceholderHeading() ) {
|
||||
|
@ -1184,7 +1184,7 @@ class CommentParser {
|
|||
* @param ThreadItem $threadItem
|
||||
* @return string
|
||||
*/
|
||||
private function computeName( ThreadItem $threadItem ) : string {
|
||||
private function computeName( ThreadItem $threadItem ): string {
|
||||
$name = null;
|
||||
|
||||
if ( $threadItem instanceof HeadingItem ) {
|
||||
|
@ -1205,7 +1205,7 @@ class CommentParser {
|
|||
return $name;
|
||||
}
|
||||
|
||||
private function buildThreads() : void {
|
||||
private function buildThreads(): void {
|
||||
if ( !$this->threadItems ) {
|
||||
$this->buildThreadItems();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class CommentUtils {
|
|||
* @param DOMNode $node
|
||||
* @return bool Node is a block element
|
||||
*/
|
||||
public static function isBlockElement( DOMNode $node ) : bool {
|
||||
public static function isBlockElement( DOMNode $node ): bool {
|
||||
return $node instanceof DOMElement &&
|
||||
in_array( strtolower( $node->tagName ), self::$blockElementTypes );
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class CommentUtils {
|
|||
* @param DOMNode $node
|
||||
* @return bool Node is considered a rendering-transparent node in Parsoid
|
||||
*/
|
||||
public static function isRenderingTransparentNode( DOMNode $node ) : bool {
|
||||
public static function isRenderingTransparentNode( DOMNode $node ): bool {
|
||||
return (
|
||||
$node instanceof DOMComment ||
|
||||
$node instanceof DOMElement && (
|
||||
|
@ -87,7 +87,7 @@ class CommentUtils {
|
|||
* @param DOMNode $node
|
||||
* @return bool If true, node can't have element children. If false, it's complicated.
|
||||
*/
|
||||
public static function cantHaveElementChildren( DOMNode $node ) : bool {
|
||||
public static function cantHaveElementChildren( DOMNode $node ): bool {
|
||||
return (
|
||||
$node instanceof DOMComment ||
|
||||
$node instanceof DOMElement &&
|
||||
|
@ -101,7 +101,7 @@ class CommentUtils {
|
|||
* @param DOMNode $child
|
||||
* @return int
|
||||
*/
|
||||
public static function childIndexOf( DOMNode $child ) : int {
|
||||
public static function childIndexOf( DOMNode $child ): int {
|
||||
$i = 0;
|
||||
while ( ( $child = $child->previousSibling ) ) {
|
||||
$i++;
|
||||
|
@ -116,7 +116,7 @@ class CommentUtils {
|
|||
* @param DOMNode $descendant
|
||||
* @return bool
|
||||
*/
|
||||
public static function contains( DOMNode $ancestor, DOMNode $descendant ) : bool {
|
||||
public static function contains( DOMNode $ancestor, DOMNode $descendant ): bool {
|
||||
// TODO can we use DOMNode->compareDocumentPosition() here maybe?
|
||||
$node = $descendant;
|
||||
while ( $node && $node !== $ancestor ) {
|
||||
|
@ -132,7 +132,7 @@ class CommentUtils {
|
|||
* @param string[] $tagNames
|
||||
* @return DOMElement|null
|
||||
*/
|
||||
public static function closestElement( DOMNode $node, array $tagNames ) : ?DOMElement {
|
||||
public static function closestElement( DOMNode $node, array $tagNames ): ?DOMElement {
|
||||
do {
|
||||
if (
|
||||
$node->nodeType === XML_ELEMENT_NODE &&
|
||||
|
@ -155,7 +155,7 @@ class CommentUtils {
|
|||
* @param DOMNode $node
|
||||
* @return DOMElement|null Translcusion node, null if not found
|
||||
*/
|
||||
public static function getTranscludedFromElement( DOMNode $node ) : ?DOMElement {
|
||||
public static function getTranscludedFromElement( DOMNode $node ): ?DOMElement {
|
||||
while ( $node ) {
|
||||
// 1.
|
||||
if (
|
||||
|
@ -196,7 +196,7 @@ class CommentUtils {
|
|||
* @param DOMElement $heading Heading node (`<h1>`-`<h6>`)
|
||||
* @return array Array containing a 'node' (DOMElement) and offset (int)
|
||||
*/
|
||||
public static function getHeadlineNodeAndOffset( DOMElement $heading ) : array {
|
||||
public static function getHeadlineNodeAndOffset( DOMElement $heading ): array {
|
||||
// This code assumes that $wgFragmentMode is [ 'html5', 'legacy' ] or [ 'html5' ]
|
||||
$headline = $heading;
|
||||
$offset = 0;
|
||||
|
@ -239,7 +239,7 @@ class CommentUtils {
|
|||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public static function htmlTrim( string $str ) : string {
|
||||
public static function htmlTrim( string $str ): string {
|
||||
// https://infra.spec.whatwg.org/#ascii-whitespace
|
||||
return trim( $str, "\t\n\f\r " );
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ class CommentUtils {
|
|||
* @param DOMNode $rootNode
|
||||
* @return int
|
||||
*/
|
||||
public static function getIndentLevel( DOMNode $node, DOMNode $rootNode ) : int {
|
||||
public static function getIndentLevel( DOMNode $node, DOMNode $rootNode ): int {
|
||||
$indent = 0;
|
||||
while ( $node ) {
|
||||
if ( $node === $rootNode ) {
|
||||
|
@ -274,7 +274,7 @@ class CommentUtils {
|
|||
* @param ImmutableRange $range
|
||||
* @return DOMElement[]
|
||||
*/
|
||||
public static function getCoveredSiblings( ImmutableRange $range ) : array {
|
||||
public static function getCoveredSiblings( ImmutableRange $range ): array {
|
||||
$ancestor = $range->commonAncestorContainer;
|
||||
|
||||
// Convert to array early because apparently DOMNodeList acts like a linked list
|
||||
|
@ -310,7 +310,7 @@ class CommentUtils {
|
|||
* @param ThreadItem $item
|
||||
* @return DOMElement[]|null
|
||||
*/
|
||||
public static function getFullyCoveredSiblings( ThreadItem $item ) : ?array {
|
||||
public static function getFullyCoveredSiblings( ThreadItem $item ): ?array {
|
||||
$siblings = self::getCoveredSiblings( $item->getRange() );
|
||||
$startContainer = $item->getRange()->startContainer;
|
||||
$endContainer = $item->getRange()->endContainer;
|
||||
|
@ -403,7 +403,7 @@ class CommentUtils {
|
|||
*/
|
||||
public static function unwrapParsoidSections(
|
||||
DOMElement $element, string $keepSection = null
|
||||
) : void {
|
||||
): void {
|
||||
$xpath = new DOMXPath( $element->ownerDocument );
|
||||
$sections = $xpath->query( '//section[@data-mw-section-id]', $element );
|
||||
foreach ( $sections as $section ) {
|
||||
|
@ -429,7 +429,7 @@ class CommentUtils {
|
|||
* @param string $url
|
||||
* @return Title|null
|
||||
*/
|
||||
public static function getTitleFromUrl( string $url ) : ?Title {
|
||||
public static function getTitleFromUrl( string $url ): ?Title {
|
||||
$bits = parse_url( $url );
|
||||
$query = wfCgiToArray( $bits['query'] ?? '' );
|
||||
if ( isset( $query['title'] ) ) {
|
||||
|
|
|
@ -33,7 +33,7 @@ class Data {
|
|||
*/
|
||||
public static function getLocalData(
|
||||
?ResourceLoaderContext $context, Config $config, $lang = null
|
||||
) : array {
|
||||
): array {
|
||||
if ( !$lang ) {
|
||||
$lang = MediaWikiServices::getInstance()->getContentLanguage();
|
||||
} elseif ( !( $lang instanceof Language ) ) {
|
||||
|
@ -146,7 +146,7 @@ class Data {
|
|||
string $format,
|
||||
ILanguageConverter $langConv,
|
||||
string $variant
|
||||
) : string {
|
||||
): string {
|
||||
$formatLength = strlen( $format );
|
||||
$s = '';
|
||||
// The supported codes must match CommentParser::getTimestampRegexp()
|
||||
|
@ -226,7 +226,7 @@ class Data {
|
|||
*/
|
||||
public static function getContentLanguageMessages(
|
||||
ResourceLoaderContext $context, Config $config, array $messagesKeys = []
|
||||
) : array {
|
||||
): array {
|
||||
return array_combine(
|
||||
$messagesKeys,
|
||||
array_map( static function ( $key ) {
|
||||
|
@ -241,7 +241,7 @@ class Data {
|
|||
* @param array $info
|
||||
* @return ResourceLoaderModule
|
||||
*/
|
||||
public static function addOptionalDependencies( array $info ) : ResourceLoaderModule {
|
||||
public static function addOptionalDependencies( array $info ): ResourceLoaderModule {
|
||||
$extensionRegistry = ExtensionRegistry::getInstance();
|
||||
|
||||
foreach ( $info['optionalDependencies'] as $ext => $deps ) {
|
||||
|
|
|
@ -22,7 +22,7 @@ class HeadingItem extends ThreadItem {
|
|||
/**
|
||||
* @return array JSON-serializable array
|
||||
*/
|
||||
public function jsonSerialize() : array {
|
||||
public function jsonSerialize(): array {
|
||||
return array_merge( parent::jsonSerialize(), [
|
||||
'headingLevel' => $this->headingLevel,
|
||||
'placeholderHeading' => $this->placeholderHeading,
|
||||
|
@ -34,7 +34,7 @@ class HeadingItem extends ThreadItem {
|
|||
*
|
||||
* @return string Title
|
||||
*/
|
||||
public function getLinkableTitle() : string {
|
||||
public function getLinkableTitle(): string {
|
||||
$title = '';
|
||||
// If this comment is in 0th section, there's no section title for the edit summary
|
||||
if ( !$this->isPlaceholderHeading() ) {
|
||||
|
@ -55,28 +55,28 @@ class HeadingItem extends ThreadItem {
|
|||
/**
|
||||
* @return int Heading level (1-6)
|
||||
*/
|
||||
public function getHeadingLevel() : int {
|
||||
public function getHeadingLevel(): int {
|
||||
return $this->headingLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $headingLevel Heading level (1-6)
|
||||
*/
|
||||
public function setHeadingLevel( int $headingLevel ) : void {
|
||||
public function setHeadingLevel( int $headingLevel ): void {
|
||||
$this->headingLevel = $headingLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPlaceholderHeading() : bool {
|
||||
public function isPlaceholderHeading(): bool {
|
||||
return $this->placeholderHeading;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $placeholderHeading
|
||||
*/
|
||||
public function setPlaceholderHeading( bool $placeholderHeading ) : void {
|
||||
public function setPlaceholderHeading( bool $placeholderHeading ): void {
|
||||
$this->placeholderHeading = $placeholderHeading;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ class EchoHooks {
|
|||
* @param string &$bundleString
|
||||
* @return bool
|
||||
*/
|
||||
public static function onEchoGetBundleRules( EchoEvent $event, string &$bundleString ) : bool {
|
||||
public static function onEchoGetBundleRules( EchoEvent $event, string &$bundleString ): bool {
|
||||
switch ( $event->getType() ) {
|
||||
case 'dt-subscribed-new-comment':
|
||||
$bundleString = $event->getType() . '-' . $event->getExtraParam( 'subscribed-comment-name' );
|
||||
|
|
|
@ -44,7 +44,7 @@ class HookUtils {
|
|||
* Null will check for any DT feature.
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureAvailableToUser( User $user, ?string $feature = null ) : bool {
|
||||
public static function isFeatureAvailableToUser( User $user, ?string $feature = null ): bool {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
|
||||
|
||||
|
@ -103,7 +103,7 @@ class HookUtils {
|
|||
* Null will check for any DT feature.
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureEnabledForUser( User $user, ?string $feature = null ) : bool {
|
||||
public static function isFeatureEnabledForUser( User $user, ?string $feature = null ): bool {
|
||||
if ( !static::isFeatureAvailableToUser( $user, $feature ) ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ class HookUtils {
|
|||
* @return string 'test' if in the test group, 'control' if in the control group, or '' if they've
|
||||
* never been in the test
|
||||
*/
|
||||
private static function determineUserABTestBucket( $user, $feature = null ) : string {
|
||||
private static function determineUserABTestBucket( $user, $feature = null ): string {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$optionsManager = $services->getUserOptionsManager();
|
||||
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
|
||||
|
@ -169,7 +169,7 @@ class HookUtils {
|
|||
* @param Title $title
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAvailableForTitle( Title $title ) : bool {
|
||||
public static function isAvailableForTitle( Title $title ): bool {
|
||||
// Only wikitext pages (e.g. not Flow boards, special pages)
|
||||
if ( $title->getContentModel() !== CONTENT_MODEL_WIKITEXT ) {
|
||||
return false;
|
||||
|
@ -201,7 +201,7 @@ class HookUtils {
|
|||
* Null will check for any DT feature.
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureEnabledForOutput( OutputPage $output, ?string $feature = null ) : bool {
|
||||
public static function isFeatureEnabledForOutput( OutputPage $output, ?string $feature = null ): bool {
|
||||
// Don't show on edit pages, history, etc.
|
||||
if ( Action::getActionName( $output->getContext() ) !== 'view' ) {
|
||||
return false;
|
||||
|
|
|
@ -41,7 +41,7 @@ class PageHooks implements
|
|||
* @param Skin $skin
|
||||
* @return void This hook must not abort, it must return no value
|
||||
*/
|
||||
public function onBeforePageDisplay( $output, $skin ) : void {
|
||||
public function onBeforePageDisplay( $output, $skin ): void {
|
||||
$user = $output->getUser();
|
||||
// Load style modules if the tools can be available for the title
|
||||
// as this means the DOM may have been modified in the parser cache.
|
||||
|
|
|
@ -33,7 +33,7 @@ class ParserHooks implements
|
|||
* @param string &$text
|
||||
* @param StripState $stripState
|
||||
*/
|
||||
public function onParserAfterParse( $parser, &$text, $stripState ) : void {
|
||||
public function onParserAfterParse( $parser, &$text, $stripState ): void {
|
||||
$title = $parser->getTitle();
|
||||
|
||||
// This condition must be unreliant on current enablement config or user preference.
|
||||
|
|
|
@ -78,7 +78,7 @@ class PreferenceHooks implements
|
|||
* @param User $user
|
||||
* @param array &$preferences
|
||||
*/
|
||||
public static function onGetBetaFeaturePreferences( User $user, array &$preferences ) : void {
|
||||
public static function onGetBetaFeaturePreferences( User $user, array &$preferences ): void {
|
||||
$coreConfig = RequestContext::getMain()->getConfig();
|
||||
$iconpath = $coreConfig->get( 'ExtensionAssetsPath' ) . '/DiscussionTools/images';
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
|||
use ConfigException;
|
||||
|
||||
class RegistrationHooks {
|
||||
public static function onRegistration() : void {
|
||||
public static function onRegistration(): void {
|
||||
// Use globals instead of Config. Accessing it so early blows up unrelated extensions (T255704).
|
||||
global $wgLocaltimezone, $wgFragmentMode;
|
||||
// HACK: Do not run these tests on CI as the globals are not configured.
|
||||
|
|
|
@ -24,7 +24,7 @@ class ResourceLoaderHooks implements
|
|||
* @param string $skin Current skin name to restrict config variables to a certain skin
|
||||
* @param Config $config
|
||||
*/
|
||||
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ) : void {
|
||||
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
|
||||
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()
|
||||
->makeConfig( 'discussiontools' );
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class ImmutableRange {
|
|||
* @param DOMNode $b
|
||||
* @return DOMNode Common ancestor container
|
||||
*/
|
||||
private static function findCommonAncestorContainer( DOMNode $a, DOMNode $b ) : DOMNode {
|
||||
private static function findCommonAncestorContainer( DOMNode $a, DOMNode $b ): DOMNode {
|
||||
$ancestorsA = [];
|
||||
$ancestorsB = [];
|
||||
|
||||
|
@ -64,7 +64,7 @@ class ImmutableRange {
|
|||
* @param DOMNode $node
|
||||
* @return DOMNode
|
||||
*/
|
||||
private static function getRootNode( DOMNode $node ) : DOMNode {
|
||||
private static function getRootNode( DOMNode $node ): DOMNode {
|
||||
while ( $node->parentNode ) {
|
||||
$node = $node->parentNode;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ class ImmutableRange {
|
|||
* @param int $startOffset
|
||||
* @return self
|
||||
*/
|
||||
public function setStart( DOMNode $startNode, int $startOffset ) : self {
|
||||
public function setStart( DOMNode $startNode, int $startOffset ): self {
|
||||
return new self(
|
||||
$startNode, $startOffset, $this->mEndContainer, $this->mEndOffset
|
||||
);
|
||||
|
@ -135,7 +135,7 @@ class ImmutableRange {
|
|||
* @param int $endOffset
|
||||
* @return self
|
||||
*/
|
||||
public function setEnd( DOMNode $endNode, int $endOffset ) : self {
|
||||
public function setEnd( DOMNode $endNode, int $endOffset ): self {
|
||||
return new self(
|
||||
$this->mStartContainer, $this->mStartOffset, $endNode, $endOffset
|
||||
);
|
||||
|
@ -150,7 +150,7 @@ class ImmutableRange {
|
|||
* @param DOMNode $node The Node to check against.
|
||||
* @return bool
|
||||
*/
|
||||
private function isPartiallyContainedNode( DOMNode $node ) : bool {
|
||||
private function isPartiallyContainedNode( DOMNode $node ): bool {
|
||||
$isAncestorOfStart = CommentUtils::contains( $node, $this->mStartContainer );
|
||||
$isAncestorOfEnd = CommentUtils::contains( $node, $this->mEndContainer );
|
||||
|
||||
|
@ -167,7 +167,7 @@ class ImmutableRange {
|
|||
* @param DOMNode $node The Node to check against.
|
||||
* @return bool
|
||||
*/
|
||||
private function isFullyContainedNode( DOMNode $node ) : bool {
|
||||
private function isFullyContainedNode( DOMNode $node ): bool {
|
||||
$startBP = [ $this->mStartContainer, $this->mStartOffset ];
|
||||
$endBP = [ $this->mEndContainer, $this->mEndOffset ];
|
||||
$root = self::getRootNode( $this->mStartContainer );
|
||||
|
@ -186,7 +186,7 @@ class ImmutableRange {
|
|||
*
|
||||
* @return DOMDocumentFragment
|
||||
*/
|
||||
public function cloneContents() : DOMDocumentFragment {
|
||||
public function cloneContents(): DOMDocumentFragment {
|
||||
$ownerDocument = $this->mStartContainer->ownerDocument;
|
||||
$fragment = $ownerDocument->createDocumentFragment();
|
||||
|
||||
|
@ -347,7 +347,7 @@ class ImmutableRange {
|
|||
* @param DOMNode $node The Node to be inserted.
|
||||
* @return void
|
||||
*/
|
||||
public function insertNode( DOMNode $node ) : void {
|
||||
public function insertNode( DOMNode $node ): void {
|
||||
if ( ( $this->mStartContainer instanceof DOMProcessingInstruction
|
||||
|| $this->mStartContainer instanceof DOMComment )
|
||||
|| ( $this->mStartContainer instanceof DOMText
|
||||
|
@ -414,7 +414,7 @@ class ImmutableRange {
|
|||
private function computePosition(
|
||||
array $boundaryPointA,
|
||||
array $boundaryPointB
|
||||
) : string {
|
||||
): string {
|
||||
if ( $boundaryPointA[0] === $boundaryPointB[0] ) {
|
||||
if ( $boundaryPointA[1] === $boundaryPointB[1] ) {
|
||||
return 'equal';
|
||||
|
|
|
@ -30,7 +30,7 @@ class EventDispatcher {
|
|||
* @param RevisionRecord $revRecord
|
||||
* @return CommentParser
|
||||
*/
|
||||
private static function getParsedRevision( RevisionRecord $revRecord ) : CommentParser {
|
||||
private static function getParsedRevision( RevisionRecord $revRecord ): CommentParser {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
|
||||
$pageRecord = $services->getPageStore()->getPageByReference( $revRecord->getPage() );
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace MediaWiki\Extension\DiscussionTools;
|
|||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
return [
|
||||
'DiscussionTools.SubscriptionStore' => static function ( MediaWikiServices $services ) : SubscriptionStore {
|
||||
'DiscussionTools.SubscriptionStore' => static function ( MediaWikiServices $services ): SubscriptionStore {
|
||||
return new SubscriptionStore(
|
||||
$services->getDBLoadBalancerFactory(),
|
||||
$services->getReadOnlyMode(),
|
||||
|
|
|
@ -44,21 +44,21 @@ class SubscriptionItem {
|
|||
/**
|
||||
* @return UserIdentity
|
||||
*/
|
||||
public function getUserIdentity() : UserIdentity {
|
||||
public function getUserIdentity(): UserIdentity {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getItemName() : string {
|
||||
public function getItemName(): string {
|
||||
return $this->itemName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LinkTarget
|
||||
*/
|
||||
public function getLinkTarget() : LinkTarget {
|
||||
public function getLinkTarget(): LinkTarget {
|
||||
return $this->linkTarget;
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class SubscriptionItem {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMuted() : bool {
|
||||
public function isMuted(): bool {
|
||||
return $this->state === 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ class SubscriptionStore {
|
|||
*
|
||||
* @return IDatabase
|
||||
*/
|
||||
private function getConnectionRef( $dbIndex ) : IDatabase {
|
||||
private function getConnectionRef( $dbIndex ): IDatabase {
|
||||
return $this->loadBalancer->getConnectionRef( $dbIndex, [ 'watchlist' ] );
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ class SubscriptionStore {
|
|||
?array $itemNames = null,
|
||||
?int $state = null,
|
||||
array $options = []
|
||||
) : array {
|
||||
): array {
|
||||
// Only a registered user can be subscribed
|
||||
if ( !$user->isRegistered() ) {
|
||||
return [];
|
||||
|
@ -156,7 +156,7 @@ class SubscriptionStore {
|
|||
string $itemName,
|
||||
?int $state = null,
|
||||
array $options = []
|
||||
) : array {
|
||||
): array {
|
||||
$options += [ 'forWrite' => false ];
|
||||
$db = $this->getConnectionRef( $options['forWrite'] ? DB_PRIMARY : DB_REPLICA );
|
||||
|
||||
|
@ -191,7 +191,7 @@ class SubscriptionStore {
|
|||
UserIdentity $user,
|
||||
LinkTarget $target,
|
||||
stdClass $row
|
||||
) : SubscriptionItem {
|
||||
): SubscriptionItem {
|
||||
return new SubscriptionItem(
|
||||
$user,
|
||||
$row->sub_item,
|
||||
|
@ -206,7 +206,7 @@ class SubscriptionStore {
|
|||
* @param UserIdentity $user
|
||||
* @return bool
|
||||
*/
|
||||
private function userExceedsSubscriptionLimit( UserIdentity $user ) : bool {
|
||||
private function userExceedsSubscriptionLimit( UserIdentity $user ): bool {
|
||||
$logger = LoggerFactory::getInstance( 'DiscussionTools' );
|
||||
// This is always queried before updating
|
||||
$db = $this->getConnectionRef( DB_PRIMARY );
|
||||
|
@ -242,7 +242,7 @@ class SubscriptionStore {
|
|||
UserIdentity $user,
|
||||
LinkTarget $target,
|
||||
string $itemName
|
||||
) : bool {
|
||||
): bool {
|
||||
if ( $this->readOnlyMode->isReadOnly() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ class SubscriptionStore {
|
|||
public function removeSubscriptionForUser(
|
||||
UserIdentity $user,
|
||||
string $itemName
|
||||
) : bool {
|
||||
): bool {
|
||||
if ( $this->readOnlyMode->isReadOnly() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ class SubscriptionStore {
|
|||
string $field,
|
||||
?UserIdentity $user,
|
||||
string $itemName
|
||||
) : bool {
|
||||
): bool {
|
||||
if ( $this->readOnlyMode->isReadOnly() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ class SubscriptionStore {
|
|||
public function updateSubscriptionNotifiedTimestamp(
|
||||
?UserIdentity $user,
|
||||
string $itemName
|
||||
) : bool {
|
||||
): bool {
|
||||
return $this->updateSubscriptionTimestamp(
|
||||
'sub_notified',
|
||||
$user,
|
||||
|
|
|
@ -39,7 +39,7 @@ abstract class ThreadItem implements JsonSerializable {
|
|||
/**
|
||||
* @return array JSON-serializable array
|
||||
*/
|
||||
public function jsonSerialize() : array {
|
||||
public function jsonSerialize(): array {
|
||||
// The output of this method can end up in the HTTP cache (Varnish). Avoid changing it;
|
||||
// and when doing so, ensure that frontend code can handle both the old and new outputs.
|
||||
// See ThreadItem.static.newFromJSON in JS.
|
||||
|
@ -61,7 +61,7 @@ abstract class ThreadItem implements JsonSerializable {
|
|||
*
|
||||
* @return string[] Author usernames
|
||||
*/
|
||||
public function getAuthorsBelow() : array {
|
||||
public function getAuthorsBelow(): array {
|
||||
$authors = [];
|
||||
$getAuthorSet = static function ( ThreadItem $comment ) use ( &$authors, &$getAuthorSet ) {
|
||||
if ( $comment instanceof CommentItem ) {
|
||||
|
@ -139,7 +139,7 @@ abstract class ThreadItem implements JsonSerializable {
|
|||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function getHTML() : string {
|
||||
public function getHTML(): string {
|
||||
$fragment = $this->getRange()->cloneContents();
|
||||
CommentModifier::unwrapFragment( $fragment );
|
||||
$container = $fragment->ownerDocument->createElement( 'div' );
|
||||
|
@ -152,7 +152,7 @@ abstract class ThreadItem implements JsonSerializable {
|
|||
*
|
||||
* @return string Text
|
||||
*/
|
||||
public function getText() : string {
|
||||
public function getText(): string {
|
||||
$fragment = $this->getRange()->cloneContents();
|
||||
return $fragment->textContent;
|
||||
}
|
||||
|
@ -160,77 +160,77 @@ abstract class ThreadItem implements JsonSerializable {
|
|||
/**
|
||||
* @return string Thread item type
|
||||
*/
|
||||
public function getType() : string {
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int Indentation level
|
||||
*/
|
||||
public function getLevel() : int {
|
||||
public function getLevel(): int {
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ThreadItem|null Parent thread item
|
||||
*/
|
||||
public function getParent() : ?ThreadItem {
|
||||
public function getParent(): ?ThreadItem {
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ImmutableRange Range of the entire thread item
|
||||
*/
|
||||
public function getRange() : ImmutableRange {
|
||||
public function getRange(): ImmutableRange {
|
||||
return $this->range;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DOMNode Root node (level is relative to this node)
|
||||
*/
|
||||
public function getRootNode() : DOMNode {
|
||||
public function getRootNode(): DOMNode {
|
||||
return $this->rootNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Thread item name
|
||||
*/
|
||||
public function getName() : string {
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Thread ID
|
||||
*/
|
||||
public function getId() : string {
|
||||
public function getId(): string {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null Thread ID, according to an older algorithm
|
||||
*/
|
||||
public function getLegacyId() : ?string {
|
||||
public function getLegacyId(): ?string {
|
||||
return $this->legacyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ThreadItem[] Replies to this thread item
|
||||
*/
|
||||
public function getReplies() : array {
|
||||
public function getReplies(): array {
|
||||
return $this->replies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] Warnings
|
||||
*/
|
||||
public function getWarnings() : array {
|
||||
public function getWarnings(): array {
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level Indentation level
|
||||
*/
|
||||
public function setLevel( int $level ) : void {
|
||||
public function setLevel( int $level ): void {
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
|
@ -244,56 +244,56 @@ abstract class ThreadItem implements JsonSerializable {
|
|||
/**
|
||||
* @param ImmutableRange $range Thread item range
|
||||
*/
|
||||
public function setRange( ImmutableRange $range ) : void {
|
||||
public function setRange( ImmutableRange $range ): void {
|
||||
$this->range = $range;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DOMNode $rootNode Root node (level is relative to this node)
|
||||
*/
|
||||
public function setRootNode( DOMNode $rootNode ) : void {
|
||||
public function setRootNode( DOMNode $rootNode ): void {
|
||||
$this->rootNode = $rootNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $name Thread item name
|
||||
*/
|
||||
public function setName( ?string $name ) : void {
|
||||
public function setName( ?string $name ): void {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id Thread ID
|
||||
*/
|
||||
public function setId( ?string $id ) : void {
|
||||
public function setId( ?string $id ): void {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id Thread ID
|
||||
*/
|
||||
public function setLegacyId( ?string $id ) : void {
|
||||
public function setLegacyId( ?string $id ): void {
|
||||
$this->legacyId = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $warning
|
||||
*/
|
||||
public function addWarning( string $warning ) : void {
|
||||
public function addWarning( string $warning ): void {
|
||||
$this->warnings[] = $warning;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $warnings
|
||||
*/
|
||||
public function addWarnings( array $warnings ) : void {
|
||||
public function addWarnings( array $warnings ): void {
|
||||
$this->warnings = array_merge( $this->warnings, $warnings );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ThreadItem $reply Reply comment
|
||||
*/
|
||||
public function addReply( ThreadItem $reply ) : void {
|
||||
public function addReply( ThreadItem $reply ): void {
|
||||
$this->replies[] = $reply;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class TreeWalker {
|
|||
*
|
||||
* @return DOMNode|null The current node
|
||||
*/
|
||||
public function nextNode() : ?DOMNode {
|
||||
public function nextNode(): ?DOMNode {
|
||||
$node = $this->currentNode;
|
||||
$result = NodeFilter::FILTER_ACCEPT;
|
||||
|
||||
|
|
18
package-lock.json
generated
18
package-lock.json
generated
|
@ -1786,9 +1786,9 @@
|
|||
}
|
||||
},
|
||||
"glob-parent": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
|
||||
"integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
||||
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-glob": "^4.0.1"
|
||||
|
@ -3010,9 +3010,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"postcss": {
|
||||
"version": "7.0.35",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.35.tgz",
|
||||
"integrity": "sha512-3QT8bBJeX/S5zKTTjTCIjRF3If4avAT6kqxcASlTWEtAFCb9NH0OUxNDfgZSWdP5fJnBYCMEWkIFfWeugjzYMg==",
|
||||
"version": "7.0.36",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.36.tgz",
|
||||
"integrity": "sha512-BebJSIUMwJHRH0HAQoxN4u1CN86glsrwsW0q7T+/m44eXOUAxSNdHRkNZPYz5vVUbg17hFgOQDE7fZk7li3pZw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "^2.4.2",
|
||||
|
@ -4023,9 +4023,9 @@
|
|||
}
|
||||
},
|
||||
"trim-newlines": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.0.tgz",
|
||||
"integrity": "sha512-C4+gOpvmxaSMKuEf9Qc134F1ZuOHVXKRbtEflf4NTtuuJDEIJ9p5PXsalL8SkeRw+qit1Mo+yuvMPAKwWg/1hA==",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz",
|
||||
"integrity": "sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==",
|
||||
"dev": true
|
||||
},
|
||||
"trough": {
|
||||
|
|
|
@ -16,7 +16,7 @@ class CommentFormatterTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testAddDiscussionToolsInternal(
|
||||
string $name, string $dom, string $expected, string $config, string $data
|
||||
) : void {
|
||||
): void {
|
||||
$dom = self::getHtml( $dom );
|
||||
$expectedPath = $expected;
|
||||
$expected = self::getText( $expected );
|
||||
|
@ -49,7 +49,7 @@ class CommentFormatterTest extends IntegrationTestCase {
|
|||
self::assertEquals( $expected, $actual, $name );
|
||||
}
|
||||
|
||||
public function provideAddDiscussionToolsInternal() : array {
|
||||
public function provideAddDiscussionToolsInternal(): array {
|
||||
return self::getJson( '../cases/formattedreply.json' );
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testAddListItem(
|
||||
string $name, string $dom, string $expected, string $config, string $data
|
||||
) : void {
|
||||
): void {
|
||||
$origPath = $dom;
|
||||
$dom = self::getHtml( $dom );
|
||||
$expectedPath = $expected;
|
||||
|
@ -55,7 +55,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
// removeAddedListItem is not implemented on the server
|
||||
}
|
||||
|
||||
public function provideAddListItem() : array {
|
||||
public function provideAddListItem(): array {
|
||||
return self::getJson( '../cases/modified.json' );
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testAddReplyLink(
|
||||
string $name, string $dom, string $expected, string $config, string $data
|
||||
) : void {
|
||||
): void {
|
||||
$origPath = $dom;
|
||||
$dom = self::getHtml( $dom );
|
||||
$expectedPath = $expected;
|
||||
|
@ -99,7 +99,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name );
|
||||
}
|
||||
|
||||
public function provideAddReplyLink() : array {
|
||||
public function provideAddReplyLink(): array {
|
||||
return self::getJson( '../cases/reply.json' );
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
* @dataProvider provideUnwrapList
|
||||
* @covers ::unwrapList
|
||||
*/
|
||||
public function testUnwrapList( string $name, string $html, int $index, string $expected ) : void {
|
||||
public function testUnwrapList( string $name, string $html, int $index, string $expected ): void {
|
||||
$doc = self::createDocument( '' );
|
||||
$container = $doc->createElement( 'div' );
|
||||
|
||||
|
@ -117,7 +117,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
self::assertEquals( $expected, DOMCompat::getInnerHTML( $container ) );
|
||||
}
|
||||
|
||||
public function provideUnwrapList() : array {
|
||||
public function provideUnwrapList(): array {
|
||||
return self::getJson( '../cases/unwrap.json' );
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testIsWikitextSigned(
|
||||
string $msg, string $wikitext, bool $expected
|
||||
) : void {
|
||||
): void {
|
||||
self::assertEquals(
|
||||
$expected,
|
||||
CommentModifier::isWikitextSigned( $wikitext ),
|
||||
|
@ -135,7 +135,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function provideIsWikitextSigned() : array {
|
||||
public function provideIsWikitextSigned(): array {
|
||||
return self::getJson( '../cases/isWikitextSigned.json' );
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testIsHtmlSigned(
|
||||
string $msg, string $html, bool $expected
|
||||
) : void {
|
||||
): void {
|
||||
$doc = self::createDocument( '' );
|
||||
$container = $doc->createElement( 'div' );
|
||||
DOMCompat::setInnerHTML( $container, $html );
|
||||
|
@ -157,7 +157,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function provideIsHtmlSigned() : array {
|
||||
public function provideIsHtmlSigned(): array {
|
||||
return self::getJson( '../cases/isHtmlSigned.json' );
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testAppendSignature(
|
||||
string $msg, string $html, string $expected
|
||||
) : void {
|
||||
): void {
|
||||
$doc = self::createDocument( '' );
|
||||
$container = $doc->createElement( 'div' );
|
||||
DOMCompat::setInnerHTML( $container, $html );
|
||||
|
@ -181,7 +181,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function provideAppendSignature() : array {
|
||||
public function provideAppendSignature(): array {
|
||||
return self::getJson( '../cases/appendSignature.json' );
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
* @dataProvider provideSanitizeWikitextLinebreaks
|
||||
* @covers ::sanitizeWikitextLinebreaks
|
||||
*/
|
||||
public function testSanitizeWikitextLinebreaks( string $msg, string $wikitext, string $expected ) : void {
|
||||
public function testSanitizeWikitextLinebreaks( string $msg, string $wikitext, string $expected ): void {
|
||||
self::assertEquals(
|
||||
$expected,
|
||||
CommentModifier::sanitizeWikitextLinebreaks( $wikitext ),
|
||||
|
@ -197,7 +197,7 @@ class CommentModifierTest extends IntegrationTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function provideSanitizeWikitextLinebreaks() : array {
|
||||
public function provideSanitizeWikitextLinebreaks(): array {
|
||||
return self::getJson( '../cases/sanitize-wikitext-linebreaks.json' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
*/
|
||||
private static function getOffsetPath(
|
||||
DOMElement $ancestor, DOMNode $node, int $nodeOffset
|
||||
) : string {
|
||||
): string {
|
||||
if ( $node->nodeType === XML_TEXT_NODE ) {
|
||||
$str = substr( $node->nodeValue, 0, $nodeOffset );
|
||||
// Count characters that require two code units to encode in UTF-16
|
||||
|
@ -51,7 +51,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
return implode( '/', $path );
|
||||
}
|
||||
|
||||
private static function serializeComments( ThreadItem &$threadItem, DOMElement $root ) : stdClass {
|
||||
private static function serializeComments( ThreadItem &$threadItem, DOMElement $root ): stdClass {
|
||||
$serialized = new stdClass();
|
||||
|
||||
if ( $threadItem instanceof HeadingItem ) {
|
||||
|
@ -107,7 +107,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testGetTimestampRegexp(
|
||||
string $format, string $expected, string $message
|
||||
) : void {
|
||||
): void {
|
||||
$parser = TestingAccessWrapper::newFromObject(
|
||||
CommentParser::newFromGlobalState( new DOMElement( 'div' ) )
|
||||
);
|
||||
|
@ -122,7 +122,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
self::assertSame( $expected, $result, $message );
|
||||
}
|
||||
|
||||
public function provideTimestampRegexps() : array {
|
||||
public function provideTimestampRegexps(): array {
|
||||
return self::getJson( '../cases/timestamp-regex.json' );
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testGetTimestampParser(
|
||||
string $format, array $data, string $expected, string $message
|
||||
) : void {
|
||||
): void {
|
||||
$parser = TestingAccessWrapper::newFromObject(
|
||||
CommentParser::newFromGlobalState( new DOMElement( 'div' ) )
|
||||
);
|
||||
|
@ -143,7 +143,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
self::assertEquals( $expected, $tsParser( $data ), $message );
|
||||
}
|
||||
|
||||
public function provideTimestampParser() : array {
|
||||
public function provideTimestampParser(): array {
|
||||
return self::getJson( '../cases/timestamp-parser.json' );
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
public function testGetTimestampParserDST(
|
||||
string $sample, string $expected, string $expectedUtc, string $format,
|
||||
string $timezone, array $timezoneAbbrs, string $message
|
||||
) : void {
|
||||
): void {
|
||||
$parser = TestingAccessWrapper::newFromObject(
|
||||
CommentParser::newFromGlobalState( new DOMElement( 'div' ) )
|
||||
);
|
||||
|
@ -172,7 +172,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
self::assertEquals( $expectedUtc, $date, $message );
|
||||
}
|
||||
|
||||
public function provideTimestampParserDST() : array {
|
||||
public function provideTimestampParserDST(): array {
|
||||
return self::getJson( '../cases/timestamp-parser-dst.json' );
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testGetThreads(
|
||||
string $name, string $dom, string $expected, string $config, string $data
|
||||
) : void {
|
||||
): void {
|
||||
$dom = self::getHtml( $dom );
|
||||
$expectedPath = $expected;
|
||||
$expected = self::getJson( $expected );
|
||||
|
@ -214,7 +214,7 @@ class CommentParserTest extends IntegrationTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function provideComments() : array {
|
||||
public function provideComments(): array {
|
||||
return self::getJson( '../cases/comments.json' );
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class DataTest extends IntegrationTestCase {
|
|||
* @dataProvider provideLocalData
|
||||
* @covers ::getLocalData
|
||||
*/
|
||||
public function testGetLocalData( string $langCode, array $config, string $expectedPath ) : void {
|
||||
public function testGetLocalData( string $langCode, array $config, string $expectedPath ): void {
|
||||
$conf = new HashConfig( $config + [
|
||||
'ContentLanguage' => $langCode,
|
||||
'TranslateNumerals' => true,
|
||||
|
@ -32,7 +32,7 @@ class DataTest extends IntegrationTestCase {
|
|||
self::assertEquals( $expectedData, $data );
|
||||
}
|
||||
|
||||
public function provideLocalData() : array {
|
||||
public function provideLocalData(): array {
|
||||
return [
|
||||
// Boring
|
||||
[ 'en', [], '../cases/datatest-en.json' ],
|
||||
|
|
|
@ -14,7 +14,7 @@ abstract class IntegrationTestCase extends MediaWikiTestCase {
|
|||
* @param array $config
|
||||
* @param array $data
|
||||
*/
|
||||
protected function setupEnv( array $config, array $data ) : void {
|
||||
protected function setupEnv( array $config, array $data ): void {
|
||||
$this->setMwGlobals( $config );
|
||||
$this->setMwGlobals( [
|
||||
'wgArticlePath' => $config['wgArticlePath'],
|
||||
|
|
|
@ -14,7 +14,7 @@ class MockCommentFormatter extends CommentFormatter {
|
|||
* @param DOMElement $container
|
||||
* @return CommentParser
|
||||
*/
|
||||
protected static function getParser( DOMElement $container ) : CommentParser {
|
||||
protected static function getParser( DOMElement $container ): CommentParser {
|
||||
return TestUtils::createParser( $container, static::$data );
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class MockSubscriptionStore extends SubscriptionStore {
|
|||
?array $itemNames = null,
|
||||
?int $state = null,
|
||||
array $options = []
|
||||
) : array {
|
||||
): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ trait TestUtils {
|
|||
* @param string $html
|
||||
* @return DOMDocument
|
||||
*/
|
||||
protected static function createDocument( string $html ) : DOMDocument {
|
||||
protected static function createDocument( string $html ): DOMDocument {
|
||||
$doc = DOMUtils::parseHTML( $html );
|
||||
$doc->preserveWhiteSpace = false;
|
||||
return $doc;
|
||||
|
@ -29,7 +29,7 @@ trait TestUtils {
|
|||
* @param string $relativePath
|
||||
* @return string
|
||||
*/
|
||||
protected static function getText( string $relativePath ) : string {
|
||||
protected static function getText( string $relativePath ): string {
|
||||
return file_get_contents( __DIR__ . '/../' . $relativePath );
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ trait TestUtils {
|
|||
* @param string $relativePath
|
||||
* @param string $text
|
||||
*/
|
||||
protected static function overwriteTextFile( string $relativePath, string $text ) : void {
|
||||
protected static function overwriteTextFile( string $relativePath, string $text ): void {
|
||||
file_put_contents( __DIR__ . '/../' . $relativePath, $text );
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ trait TestUtils {
|
|||
* @param bool $assoc See json_decode()
|
||||
* @return array
|
||||
*/
|
||||
protected static function getJson( string $relativePath, bool $assoc = true ) : array {
|
||||
protected static function getJson( string $relativePath, bool $assoc = true ): array {
|
||||
$json = json_decode(
|
||||
file_get_contents( __DIR__ . '/' . $relativePath ),
|
||||
$assoc
|
||||
|
@ -64,7 +64,7 @@ trait TestUtils {
|
|||
* @param string $relativePath
|
||||
* @param array $data
|
||||
*/
|
||||
protected static function overwriteJsonFile( string $relativePath, array $data ) : void {
|
||||
protected static function overwriteJsonFile( string $relativePath, array $data ): void {
|
||||
$json = json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
|
||||
// Tabs instead of 4 spaces
|
||||
$json = preg_replace( '/(?:\G|^) {4}/m', "\t", $json );
|
||||
|
@ -77,7 +77,7 @@ trait TestUtils {
|
|||
* @param string $relativePath
|
||||
* @return string
|
||||
*/
|
||||
protected static function getHtml( string $relativePath ) : string {
|
||||
protected static function getHtml( string $relativePath ): string {
|
||||
$html = file_get_contents( __DIR__ . '/../' . $relativePath );
|
||||
|
||||
// Remove all but the body tags from full Parsoid docs
|
||||
|
@ -96,7 +96,7 @@ trait TestUtils {
|
|||
* @param DOMDocument $doc
|
||||
* @param string $origRelPath
|
||||
*/
|
||||
protected static function overwriteHtmlFile( string $relPath, DOMDocument $doc, string $origRelPath ) : void {
|
||||
protected static function overwriteHtmlFile( string $relPath, DOMDocument $doc, string $origRelPath ): void {
|
||||
// Do not use $doc->saveHtml(), it outputs an awful soup of HTML entities for documents with
|
||||
// non-ASCII characters
|
||||
$html = file_get_contents( __DIR__ . '/../' . $origRelPath );
|
||||
|
@ -124,7 +124,7 @@ trait TestUtils {
|
|||
* @param array $data
|
||||
* @return CommentParser
|
||||
*/
|
||||
public static function createParser( DOMElement $rootNode, array $data ) : CommentParser {
|
||||
public static function createParser( DOMElement $rootNode, array $data ): CommentParser {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
return new CommentParser(
|
||||
$rootNode,
|
||||
|
|
|
@ -18,12 +18,12 @@ class ThreadItemTest extends IntegrationTestCase {
|
|||
* @dataProvider provideAuthors
|
||||
* @covers ::getAuthorsBelow
|
||||
*/
|
||||
public function testGetAuthorsBelow( array $thread, array $expected ) : void {
|
||||
public function testGetAuthorsBelow( array $thread, array $expected ): void {
|
||||
$doc = $this->createDocument( '' );
|
||||
$node = $doc->createElement( 'div' );
|
||||
$range = new ImmutableRange( $node, 0, $node, 0 );
|
||||
|
||||
$makeThreadItem = static function ( array $arr ) use ( &$makeThreadItem, $range ) : ThreadItem {
|
||||
$makeThreadItem = static function ( array $arr ) use ( &$makeThreadItem, $range ): ThreadItem {
|
||||
if ( $arr['type'] === 'comment' ) {
|
||||
$item = new CommentItem( 1, $range, [], 'TIMESTAMP', $arr['author'] );
|
||||
} else {
|
||||
|
@ -40,7 +40,7 @@ class ThreadItemTest extends IntegrationTestCase {
|
|||
self::assertEquals( $expected, $threadItem->getAuthorsBelow() );
|
||||
}
|
||||
|
||||
public function provideAuthors() : array {
|
||||
public function provideAuthors(): array {
|
||||
return self::getJson( '../cases/authors.json' );
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ class ThreadItemTest extends IntegrationTestCase {
|
|||
*/
|
||||
public function testGetTranscludedFrom(
|
||||
string $name, string $dom, string $expected, string $config, string $data
|
||||
) : void {
|
||||
): void {
|
||||
$dom = self::getHtml( $dom );
|
||||
$expectedPath = $expected;
|
||||
$expected = self::getJson( $expected );
|
||||
|
@ -85,7 +85,7 @@ class ThreadItemTest extends IntegrationTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function provideTranscludedFrom() : array {
|
||||
public function provideTranscludedFrom(): array {
|
||||
return self::getJson( '../cases/transcluded.json' );
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class CommentUtilsTest extends MediaWikiUnitTestCase {
|
|||
self::assertEquals( $expectedBackwards, $actualBackwards, $name . ' (backwards)' );
|
||||
}
|
||||
|
||||
public function provideLinearWalk() : array {
|
||||
public function provideLinearWalk(): array {
|
||||
return self::getJson( '../cases/linearWalk.json' );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue