mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-11 16:16:51 +00:00
Fix parsing links in Parsoid documents without short URLs
Move the code so that we check for "?title=" query parameter first, because we don't handle this right in the other code path. Use parse_url() instead of wfParseUrl() because the latter doesn't accept relative URLs, and we don't care about the other differences. Bug: T261711 Depends-On: I4da952876e1c3d1a41d06b51f7e26015ff5e34d7 Change-Id: I70fac2b41befd782b0a47a4f726ae748dc0f775d
This commit is contained in:
parent
37e6f64503
commit
10899af666
|
@ -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 ] );
|
||||
|
|
|
@ -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', '/' ),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue