Recognize links to add a new topic that use Special:NewSection

Bug: T277371
Change-Id: I40a13d8bf87bcd3ecea1427b444b6b7b621213c4
This commit is contained in:
Bartosz Dziewoński 2021-07-22 22:20:16 +02:00
parent aa19431689
commit 4ebf05d802
6 changed files with 36 additions and 3 deletions

View file

@ -71,6 +71,8 @@ class Data {
$data['specialContributionsName'] = MediaWikiServices::getInstance() $data['specialContributionsName'] = MediaWikiServices::getInstance()
->getSpecialPageFactory()->getLocalNameFor( 'Contributions' ); ->getSpecialPageFactory()->getLocalNameFor( 'Contributions' );
$data['specialNewSectionName'] = MediaWikiServices::getInstance()
->getSpecialPageFactory()->getLocalNameFor( 'NewSection' );
$localTimezone = $config->get( 'Localtimezone' ); $localTimezone = $config->get( 'Localtimezone' );
// Return all timezone abbreviations for the local timezone (there will often be two, for // Return all timezone abbreviations for the local timezone (there will often be two, for

View file

@ -1,4 +1,6 @@
var var
// Data::getLocalData()
parserData = require( './parser/data.json' ),
utils = require( './utils.js' ); utils = require( './utils.js' );
function ReplyLinksController( $pageContainer ) { 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 // T106244: URL encoded values using fallback 8-bit encoding (invalid UTF-8) cause mediawiki.Uri to crash
return; 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&section=new
// ?title=...&veaction=editsource&section=new
( uri.query.action === 'edit' || uri.query.veaction === 'editsource' ) && uri.query.section === 'new'
) {
// Do nothing
} else {
// Not a link to add a new topic // Not a link to add a new topic
return; return;
} }
var title = utils.getTitleFromUrl( href ); if ( title.getPrefixedDb() !== mw.config.get( 'wgRelevantPageName' ) ) {
if ( !title || title.getPrefixedDb() !== mw.config.get( 'wgRelevantPageName' ) ) {
// Link to add a section on another page, not supported yet (T282205) // Link to add a section on another page, not supported yet (T282205)
return; return;
} }

View file

@ -18,6 +18,7 @@
}, },
"localTimezone": "UTC", "localTimezone": "UTC",
"specialContributionsName": "Contributions", "specialContributionsName": "Contributions",
"specialNewSectionName": "NewSection",
"timezones": { "timezones": {
"ckb": { "ckb": {
"UTC": "UTC" "UTC": "UTC"

View file

@ -18,6 +18,7 @@
}, },
"localTimezone": "UTC", "localTimezone": "UTC",
"specialContributionsName": "Contributions", "specialContributionsName": "Contributions",
"specialNewSectionName": "NewSection",
"timezones": { "timezones": {
"en": { "en": {
"UTC": "UTC" "UTC": "UTC"

View file

@ -44,6 +44,7 @@
}, },
"localTimezone": "UTC", "localTimezone": "UTC",
"specialContributionsName": "Contributions", "specialContributionsName": "Contributions",
"specialNewSectionName": "NewSection",
"timezones": { "timezones": {
"sr": { "sr": {
"UTC": "UTC" "UTC": "UTC"

View file

@ -18,6 +18,7 @@
}, },
"localTimezone": "Asia/Bangkok", "localTimezone": "Asia/Bangkok",
"specialContributionsName": "Contributions", "specialContributionsName": "Contributions",
"specialNewSectionName": "NewSection",
"timezones": { "timezones": {
"th": { "th": {
"LMT": "LMT", "LMT": "LMT",