mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-24 18:58:42 +00:00
Merge "Allow 'T-' prefixed sections, and redirect if section link title isn't current page"
This commit is contained in:
commit
e91f8f913e
|
@ -103,8 +103,8 @@
|
|||
|
||||
function parseSection( section ) {
|
||||
var parsedSection = section;
|
||||
// Section must be 'new' or a number
|
||||
if ( section !== 'new' ) {
|
||||
// Section must be a number, 'new' or 'T-' prefixed
|
||||
if ( section !== 'new' && section.indexOf( 'T-' ) !== 0 ) {
|
||||
parsedSection = +section;
|
||||
if ( isNaN( parsedSection ) ) {
|
||||
parsedSection = null;
|
||||
|
@ -681,10 +681,17 @@
|
|||
* @param {number|string} [section] Override edit section, taken from link URL if not specified
|
||||
*/
|
||||
onEditSectionLinkClick: function ( mode, e, section ) {
|
||||
var targetPromise;
|
||||
var targetPromise,
|
||||
uri = new mw.Uri( e.target.href ),
|
||||
title = mw.Title.newFromText( uri.query.title || '' );
|
||||
|
||||
if ( !init.isUnmodifiedLeftClick( e ) ) {
|
||||
return;
|
||||
}
|
||||
if ( title && title.getPrefixedText() !== new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getPrefixedText() ) {
|
||||
// title param doesn't match current page, let default event happen (navigate to other page)
|
||||
return true;
|
||||
}
|
||||
e.preventDefault();
|
||||
if ( isLoading ) {
|
||||
return;
|
||||
|
@ -711,7 +718,7 @@
|
|||
} else {
|
||||
// Use section from URL
|
||||
if ( section === undefined ) {
|
||||
section = parseSection( new mw.Uri( e.target.href ).query.section );
|
||||
section = parseSection( uri.query.section );
|
||||
}
|
||||
targetPromise = getTarget( mode, section );
|
||||
}
|
||||
|
|
|
@ -1939,15 +1939,18 @@ ve.init.mw.ArticleTarget.prototype.getSaveDialogOpeningData = function () {
|
|||
*/
|
||||
ve.init.mw.ArticleTarget.prototype.restoreEditSection = function () {
|
||||
var headingText,
|
||||
section,
|
||||
surface = this.getSurface(),
|
||||
mode = surface.getMode(),
|
||||
surfaceView, $documentNode, $section, headingNode;
|
||||
|
||||
if ( this.section !== null && this.section !== 'new' && this.section !== 0 ) {
|
||||
if ( this.section !== null && this.section !== 'new' && this.section !== 0 && this.section !== 'T-0' ) {
|
||||
if ( mode === 'visual' ) {
|
||||
// Get numerical part of section (strip 'T-'' if present)
|
||||
section = this.section.toString().indexOf( 'T-' ) === 0 ? +this.section.slice( 2 ) : this.section;
|
||||
surfaceView = surface.getView();
|
||||
$documentNode = surfaceView.getDocument().getDocumentNode().$element;
|
||||
$section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( this.section - 1 );
|
||||
$section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( section - 1 );
|
||||
headingNode = $section.data( 'view' );
|
||||
|
||||
if ( $section.length && new mw.Uri().query.summary === undefined ) {
|
||||
|
|
Loading…
Reference in a new issue