diff --git a/includes/Data.php b/includes/Data.php index c9fbb3a7d..e5f526ab7 100644 --- a/includes/Data.php +++ b/includes/Data.php @@ -71,6 +71,8 @@ class Data { $data['specialContributionsName'] = MediaWikiServices::getInstance() ->getSpecialPageFactory()->getLocalNameFor( 'Contributions' ); + $data['specialNewSectionName'] = MediaWikiServices::getInstance() + ->getSpecialPageFactory()->getLocalNameFor( 'NewSection' ); $localTimezone = $config->get( 'Localtimezone' ); // Return all timezone abbreviations for the local timezone (there will often be two, for diff --git a/modules/ReplyLinksController.js b/modules/ReplyLinksController.js index cfc0fc8bc..2172007fd 100644 --- a/modules/ReplyLinksController.js +++ b/modules/ReplyLinksController.js @@ -1,4 +1,6 @@ var + // Data::getLocalData() + parserData = require( './parser/data.json' ), utils = require( './utils.js' ); function ReplyLinksController( $pageContainer ) { @@ -77,13 +79,38 @@ ReplyLinksController.prototype.onAnyLinkClick = function ( e ) { // T106244: URL encoded values using fallback 8-bit encoding (invalid UTF-8) cause mediawiki.Uri to crash return; } - if ( ( uri.query.action !== 'edit' && uri.query.veaction !== 'editsource' ) || uri.query.section !== 'new' ) { + + var title = utils.getTitleFromUrl( href ); + if ( !title ) { + return; + } + + // Recognize links to add a new topic: + if ( + // Special:NewSection/... + title.getNamespaceId() === mw.config.get( 'wgNamespaceIds' ).special && + title.getMainText().split( '/' )[ 0 ] === parserData.specialNewSectionName + ) { + // Get the real title from the subpage parameter + var param = title.getMainText().slice( parserData.specialNewSectionName.length + 1 ); + title = mw.Title.newFromText( param ); + if ( !title ) { + return; + } + + } else if ( + // ?title=...&action=edit§ion=new + // ?title=...&veaction=editsource§ion=new + ( uri.query.action === 'edit' || uri.query.veaction === 'editsource' ) && uri.query.section === 'new' + ) { + // Do nothing + + } else { // Not a link to add a new topic return; } - var title = utils.getTitleFromUrl( href ); - if ( !title || title.getPrefixedDb() !== mw.config.get( 'wgRelevantPageName' ) ) { + if ( title.getPrefixedDb() !== mw.config.get( 'wgRelevantPageName' ) ) { // Link to add a section on another page, not supported yet (T282205) return; } diff --git a/tests/cases/datatest-ckb.json b/tests/cases/datatest-ckb.json index c0a353c47..bc573ca78 100644 --- a/tests/cases/datatest-ckb.json +++ b/tests/cases/datatest-ckb.json @@ -18,6 +18,7 @@ }, "localTimezone": "UTC", "specialContributionsName": "Contributions", + "specialNewSectionName": "NewSection", "timezones": { "ckb": { "UTC": "UTC" diff --git a/tests/cases/datatest-en.json b/tests/cases/datatest-en.json index a04c64e62..8a78da1bf 100644 --- a/tests/cases/datatest-en.json +++ b/tests/cases/datatest-en.json @@ -18,6 +18,7 @@ }, "localTimezone": "UTC", "specialContributionsName": "Contributions", + "specialNewSectionName": "NewSection", "timezones": { "en": { "UTC": "UTC" diff --git a/tests/cases/datatest-sr.json b/tests/cases/datatest-sr.json index d500faff9..d5c2cc6dc 100644 --- a/tests/cases/datatest-sr.json +++ b/tests/cases/datatest-sr.json @@ -44,6 +44,7 @@ }, "localTimezone": "UTC", "specialContributionsName": "Contributions", + "specialNewSectionName": "NewSection", "timezones": { "sr": { "UTC": "UTC" diff --git a/tests/cases/datatest-th.json b/tests/cases/datatest-th.json index f595dd18d..7c548a61b 100644 --- a/tests/cases/datatest-th.json +++ b/tests/cases/datatest-th.json @@ -18,6 +18,7 @@ }, "localTimezone": "Asia/Bangkok", "specialContributionsName": "Contributions", + "specialNewSectionName": "NewSection", "timezones": { "th": { "LMT": "LMT",