diff --git a/includes/ApiDiscussionToolsEdit.php b/includes/ApiDiscussionToolsEdit.php index cfff0f740..e638c0fa4 100644 --- a/includes/ApiDiscussionToolsEdit.php +++ b/includes/ApiDiscussionToolsEdit.php @@ -82,6 +82,7 @@ class ApiDiscussionToolsEdit extends ApiBase { } $parser = CommentParser::newFromGlobalState( $container ); + $comment = $parser->findCommentById( $commentId ); if ( !$comment ) { $this->dieWithError( [ 'apierror-discussiontools-commentid-notfound', $commentId ] ); diff --git a/includes/CommentUtils.php b/includes/CommentUtils.php index 61b1a1d6c..1d4828c6e 100644 --- a/includes/CommentUtils.php +++ b/includes/CommentUtils.php @@ -302,6 +302,12 @@ class CommentUtils { * @return Title|null */ public static function getTitleFromUrl( string $url ) : ?Title { + $bits = parse_url( $url ); + $query = wfCgiToArray( $bits['query'] ?? '' ); + if ( isset( $query['title'] ) ) { + return Title::newFromText( $query['title'] ); + } + $config = MediaWikiServices::getInstance()->getMainConfig(); // TODO: Set the correct base in the document? if ( strpos( $url, './' ) === 0 ) { @@ -309,11 +315,6 @@ class CommentUtils { } elseif ( strpos( $url, '://' ) === false ) { $url = 'https://local' . $url; } - $bits = wfParseUrl( $url ); - $query = wfCgiToArray( $bits['query'] ?? '' ); - if ( isset( $query['title'] ) ) { - return Title::newFromText( $query['title'] ); - } $articlePathRegexp = '/' . str_replace( preg_quote( '$1', '/' ), diff --git a/modules/Parser.js b/modules/Parser.js index 781027d53..b6c024482 100644 --- a/modules/Parser.js +++ b/modules/Parser.js @@ -480,17 +480,18 @@ function getTitleFromUrl( url ) { // T106244: URL encoded values using fallback 8-bit encoding (invalid UTF-8) cause mediawiki.Uri to crash return null; } + if ( url.query.title ) { + return mw.Title.newFromText( url.query.title ); + } + articlePathRegexp = new RegExp( mw.util.escapeRegExp( mw.config.get( 'wgArticlePath' ) ) .replace( mw.util.escapeRegExp( '$1' ), '(.*)' ) ); - if ( ( match = url.path.match( articlePathRegexp ) ) ) { return mw.Title.newFromText( decodeURIComponent( match[ 1 ] ) ); } - if ( url.query.title ) { - return mw.Title.newFromText( url.query.title ); - } + return null; }