mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 16:34:21 +00:00
Merge "Move ID->title logic into HeadingItem"
This commit is contained in:
commit
579cc20120
|
@ -158,25 +158,9 @@ class ApiDiscussionToolsEdit extends ApiBase {
|
|||
if ( isset( $params['summary'] ) ) {
|
||||
$summary = $params['summary'];
|
||||
} else {
|
||||
$heading = $comment->getHeading();
|
||||
if ( $heading->isPlaceholderHeading() ) {
|
||||
// This comment is in 0th section, there's no section title for the edit summary
|
||||
$summary = '';
|
||||
} else {
|
||||
$headingNode =
|
||||
CommentUtils::getHeadlineNodeAndOffset( $heading->getRange()->startContainer )['node'];
|
||||
$id = $headingNode->getAttribute( 'id' );
|
||||
if ( $id ) {
|
||||
// Replace underscores with spaces to undo Sanitizer::escapeIdInternal().
|
||||
// This assumes that $wgFragmentMode is [ 'html5', 'legacy' ] or [ 'html5' ],
|
||||
// otherwise the escaped IDs are super garbled and can't be unescaped reliably.
|
||||
$summary = '/* ' . str_replace( '_', ' ', $id ) . ' */ ';
|
||||
} else {
|
||||
// Not a real section, probably just HTML markup in wikitext, bleh
|
||||
$summary = '';
|
||||
}
|
||||
}
|
||||
$summary .= $this->msg( 'discussiontools-defaultsummary-reply' )->inContentLanguage()->text();
|
||||
$title = $comment->getHeading()->getLinkableTitle();
|
||||
$summary = ( $title ? '/* ' . $title . ' */ ' : '' ) .
|
||||
$this->msg( 'discussiontools-defaultsummary-reply' )->inContentLanguage()->text();
|
||||
}
|
||||
|
||||
$api = new ApiMain(
|
||||
|
|
|
@ -29,6 +29,29 @@ class HeadingItem extends ThreadItem {
|
|||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a title based on the hash ID, such that it can be linked to
|
||||
*
|
||||
* @return string Title
|
||||
*/
|
||||
public function getLinkableTitle() : string {
|
||||
$title = '';
|
||||
// If this comment is in 0th section, there's no section title for the edit summary
|
||||
if ( !$this->isPlaceholderHeading() ) {
|
||||
$headingNode =
|
||||
CommentUtils::getHeadlineNodeAndOffset( $this->getRange()->startContainer )['node'];
|
||||
$id = $headingNode->getAttribute( 'id' );
|
||||
if ( $id ) {
|
||||
// Replace underscores with spaces to undo Sanitizer::escapeIdInternal().
|
||||
// This assumes that $wgFragmentMode is [ 'html5', 'legacy' ] or [ 'html5' ],
|
||||
// otherwise the escaped IDs are super garbled and can't be unescaped reliably.
|
||||
$title = str_replace( '_', ' ', $id );
|
||||
}
|
||||
// else: Not a real section, probably just HTML markup in wikitext
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int Heading level (1-6)
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var ThreadItem = require( './ThreadItem.js' );
|
||||
var ThreadItem = require( './ThreadItem.js' ),
|
||||
utils = require( './utils.js' );
|
||||
|
||||
/**
|
||||
* A heading item
|
||||
|
@ -20,4 +21,22 @@ function HeadingItem( range, headingLevel, placeholderHeading ) {
|
|||
|
||||
OO.inheritClass( HeadingItem, ThreadItem );
|
||||
|
||||
HeadingItem.prototype.getLinkableTitle = function () {
|
||||
var headingNode, id,
|
||||
title = '';
|
||||
// If this comment is in 0th section, there's no section title for the edit summary
|
||||
if ( !this.placeholderHeading ) {
|
||||
headingNode = utils.getHeadlineNodeAndOffset( this.range.startContainer ).node;
|
||||
id = headingNode.getAttribute( 'id' );
|
||||
if ( id ) {
|
||||
// Replace underscores with spaces to undo Sanitizer::escapeIdInternal().
|
||||
// This assumes that $wgFragmentMode is [ 'html5', 'legacy' ] or [ 'html5' ],
|
||||
// otherwise the escaped IDs are super garbled and can't be unescaped reliably.
|
||||
title = id.replace( /_/g, ' ' );
|
||||
}
|
||||
// else: Not a real section, probably just HTML markup in wikitext
|
||||
}
|
||||
return title;
|
||||
};
|
||||
|
||||
module.exports = HeadingItem;
|
||||
|
|
|
@ -376,7 +376,7 @@ ReplyWidget.prototype.onModeTabSelectChoose = function ( option ) {
|
|||
* @return {ReplyWidget}
|
||||
*/
|
||||
ReplyWidget.prototype.setup = function ( data ) {
|
||||
var heading, headingNode, id, summary;
|
||||
var title, summary;
|
||||
|
||||
data = data || {};
|
||||
|
||||
|
@ -389,24 +389,9 @@ ReplyWidget.prototype.setup = function ( data ) {
|
|||
summary = this.storage.get( this.storagePrefix + '/summary' ) || data.editSummary;
|
||||
|
||||
if ( !summary ) {
|
||||
heading = this.comment.getHeading();
|
||||
if ( heading.placeholderHeading ) {
|
||||
// This comment is in 0th section, there's no section title for the edit summary
|
||||
summary = '';
|
||||
} else {
|
||||
headingNode = utils.getHeadlineNodeAndOffset( heading.range.startContainer ).node;
|
||||
id = headingNode.getAttribute( 'id' );
|
||||
if ( id ) {
|
||||
// Replace underscores with spaces to undo Sanitizer::escapeIdInternal().
|
||||
// This assumes that $wgFragmentMode is [ 'html5', 'legacy' ] or [ 'html5' ],
|
||||
// otherwise the escaped IDs are super garbled and can't be unescaped reliably.
|
||||
summary = '/* ' + id.replace( /_/g, ' ' ) + ' */ ';
|
||||
} else {
|
||||
// Not a real section, probably just HTML markup in wikitext, bleh
|
||||
summary = '';
|
||||
}
|
||||
}
|
||||
summary += mw.msg( 'discussiontools-defaultsummary-reply' );
|
||||
title = this.comment.getHeading().getLinkableTitle();
|
||||
summary = ( title ? '/* ' + title + ' */ ' : '' ) +
|
||||
mw.msg( 'discussiontools-defaultsummary-reply' );
|
||||
}
|
||||
|
||||
this.toggleAdvanced(
|
||||
|
|
Loading…
Reference in a new issue