Section

Section

Class representing a section.

Constructor

new Section(parser, heading, targets, subscriptions)

Source:

Create a section object.

Parameters:
Name Type Description
parser Parser
heading object

Heading object returned by Parser#findHeadings.

targets Array.<object>

Sorted target objects returned by Parser#findSignatures + Parser#findHeadings.

subscriptions Subscriptions
Throws:

Extends

Members

$actions :external:jQuery

Source:

Actions element under the 2-level section heading or to the right of headings of other levels.

Type:

$addSubsectionButtonContainer :external:jQuery|undefined

Source:

"Add subsection" button container.

Type:

$authorCountWrapper :external:jQuery|undefined

Source:

Author count wrapper element in the metadata element.

Type:

$bar :external:jQuery|undefined

Source:

Bar element under a 2-level section heading.

Type:

$heading :external:jQuery

Source:

Heading element as a jQuery element.

Type:

$headline :external:jQuery

Source:

Headline element as a jQuery object.

Type:

$latestCommentWrapper :external:jQuery|undefined

Source:

Latest comment date wrapper element in the metadata element.

Type:

$metadata :external:jQuery|undefined

Source:

Metadata element in the bar element.

Type:

$replyButtonContainer :external:jQuery|undefined

Source:

Reply button container and part-time reply comment form container, a list element. It is wrapped around the reply button wrapper, but it is created by the script only when there is no suitable element that already exists. If there is, it can contain other elements (and comments) too.

Type:

$replyButtonWrapper :external:jQuery|undefined

Source:

Reply button wrapper and part-time reply comment form wrapper, an item element.

Type:

actions :object

Source:

Section actions object. It contains widgets (buttons, menus) triggering the actions of the section.

Type:
  • object

addSubsectionButton :Button|undefined

Source:

"Add subsection" button at the end of the section.

Type:

addSubsectionForm :CommentForm|undefined

Source:

"Add subsection" form related to the section.

Type:

authorsPopup :external:OO.ui.PopupWidget|undefined

Source:

Popup with the list of users who have posted in the section.

Type:

code :string|undefined

Source:

Section code. Filled upon running Section#loadCode.

Type:
  • string | undefined

comments :Array.<Comment>

Source:
Overrides:

Comments contained in the section.

Type:

commentsInFirstChunk :Array.<Comment>

Source:
Overrides:

Comments contained in the first chunk of the section, i.e. all elements up to the first subheading if it is present, or all elements if it is not.

Type:

editUrl :string

Source:
Overrides:

URL to edit the section.

Type:
  • string

headingElement :Element|external:Element

Source:
Overrides:

Heading element (.mw-heading or <h1> - <h6>).

Type:

headline :string

Source:
Overrides:

Section headline as it appears on the page.

Foreign elements can get there, add the classes of these elements to module:defaultConfig.excludeFromHeadlineClasses to filter them out.

Type:
  • string

headlineElement :Element|external:Element

Source:
Overrides:

Headline element.

Type:

hElement :Element|external:Element

Source:
Overrides:

`H1...6' element.

Type:

id :string

Source:
Overrides:

Section id.

Type:
  • string

index :number

Source:
Overrides:

Section index. Same as the index in the array returned by module:sectionRegistry.getAll.

Type:
  • number

isActionable :boolean

Source:

Is the section actionable. (If it is in a closed discussion or on an old version page, then no).

Type:
  • boolean

isHidden :boolean

Source:

Is the section visible (visibility: visible as opposed to visibility: hidden). Can be true when the improvePerformance setting is enabled.

Type:
  • boolean

isLastSection :boolean

Source:

Is the section the last section on the page.

Type:
  • boolean

isTranscludedFromTemplate :boolean

Source:

Is the section transcluded from a template (usually, that template in turn transludes content, like here: https://ru.wikipedia.org/wiki/Project:Выборы_арбитров/Лето_2021/Вопросы/Кандидатские_заявления.)

Type:
  • boolean

lastElement :Element|external:Element

Source:
Overrides:

Last element in the section.

Type:

lastElementInFirstChunk :Element|external:Element

Source:
Overrides:

Last element in the first chunk of the section, i.e. all elements up to the first subheading if it is present or just all elements if it is not.

Type:

(nullable) latestComment :Comment|undefined

Source:

Latest comment in a 2-level section.

Type:

level :number

Source:
Overrides:

Section level. A level is a number representing the number of = characters in the section heading's code.

Type:
  • number

(nullable) liveSectionNumber :number

Source:

Automatically updated sequental number of the section.

Type:
  • number

liveSectionNumberRevisionId :number

Source:

Revision ID of Section#liveSectionNumber.

Type:
  • number

newComments :Array.<Comment>

Source:

List of new comments in the section. ("New" actually means "unseen at the moment of load".)

Type:

oldestComment :CommentSkeleton

Source:
Overrides:

Oldest comment in the section.

Type:

queryTimestamp :string|undefined

Source:

Time when Section#code was queried (as the server reports it). Filled upon running Section#loadCode.

Type:
  • string | undefined

replyButton :Button|undefined

Source:

Reply button at the bottom of the first chunk of the section.

Type:

replyForm :CommentForm|undefined

Source:

Reply form related to the section.

Type:

revisionId :number|undefined

Source:

ID of the revision that has Section#code. Filled upon running Section#loadCode.

Type:
  • number | undefined

(nullable) sectionNumber :number

Source:
Overrides:

Sequental number of the section at the time of the page load.

Type:
  • number

(nullable) source :SectionSource|undefined

Source:

Section's source code object.

Type:

sourcePage :module:pageRegistry.Page

Source:

Wiki page that has the source code of the section (may be different from the current page if the section is transcluded from another page). This property may be wrong on old version pages where there are no edit section links.

Type:

subscribeId :string|undefined

Source:

The section subscribe ID, either in the DiscussionTools format or just a headline if legacy subscriptions are used.

Type:
  • string | undefined

(nullable) subscriptionState :boolean

Source:

Subscription state of the section. Currently, true stands for "subscribed", false for "unsubscribed", null for n/a.

Type:
  • boolean

Methods

(static) initPrototypes()

Source:

For internal use. Create element and widget prototypes to reuse them instead of creating new elements from scratch (which is more expensive).

addCommentFormToPage(mode, commentForm)

Source:

Add a comment form targeted at this section to the page.

Parameters:
Name Type Description
mode string
commentForm CommentForm

addMetadataAndActions()

Source:

Add the metadata and actions elements below or to the right of the section heading.

addNewCommentCountMetadata()

Source:

Add the new comment count to the metadata element. ("New" actually means "unseen at the moment of load".)

addSubscribeButton()

Source:

For internal use. Add a "Subscribe" / "Unsubscribe" button to the actions element.

Fires:

addSubsection(initialStateopt, commentFormopt)

Source:

Create an add subsection form form or focus an existing one.

Parameters:
Name Type Attributes Description
initialState object <optional>
commentForm CommentForm <optional>
Throws:

canBeMoved() → {boolean}

Source:

Check whether the user should get the affordance to move the section to another page.

Returns:
Type
boolean

canBeReplied() → {boolean}

Source:

Check whether the user should get the affordance to add a reply to the section.

Returns:
Type
boolean

canBeSubsectioned() → {boolean}

Source:

Check whether the user should get the affordance to add a subsection to the section.

Returns:
Type
boolean

canFirstCommentBeEdited() → {boolean}

Source:

Check whether the user should get the affordance to edit the first comment from the section menu.

Returns:
Type
boolean
Source:

Copy a link to the section or open a copy link dialog.

Parameters:
Name Type Description
e Event

ensureSubscribeIdPresent(editTimestamp)

Source:

Generate a DT subscribe ID from the oldest timestamp in the section and the current user's name if there is no.

Parameters:
Name Type Description
editTimestamp string

Timestamp of the edit just made.

extractSubscribeId()

Source:

Extract the section's subscribe ID.

findNewSelf() → (nullable) {Section}

Source:

After the page is reloaded and this instance doesn't relate to a rendered section on the page, get the instance of this section that does.

Returns:
Type
Section

findRealLastElement(additionalConditionopt) → {Element}

Source:

Find the last element of the section including

Parameters:
Name Type Attributes Description
additionalCondition function <optional>
Returns:
Type
Element

getAncestors() → {Array.<SectionSkeleton>}

Source:
Overrides:

Get the chain of ancestors of the section as an array, starting with the parent section.

The returned value is cached, so don't change the array in-place. (That's ugly, need to check if running .slice() on the array slows anything down. To be clear – this method is run very frequently.)

Returns:
Type
Array.<SectionSkeleton>

getBase(force2Levelopt) → (nullable) {Section}

Source:

Get the base section, i.e. a section of level 2 that is an ancestor of the section, or the section itself if it is of level 2 (even if there is a level 1 section) or if there is no higher level section (the current section may be of level 3 or 1, for example).

Parameters:
Name Type Attributes Default Description
force2Level boolean <optional>
false

Guarantee a 2-level section is returned.

Returns:
Type
Section

getChildren(indirectopt) → {Array.<Section>}

Source:

Get the collection of the section's subsections.

Parameters:
Name Type Attributes Default Description
indirect boolean <optional>
false

Whether to include subsections of subsections and so on (return descendants, in a word).

Returns:
Type
Array.<Section>

getClosestSectionSubscribedTo(includeCurrentopt) → (nullable) {Section}

Source:

Get the first upper level section relative to the current section that is subscribed to.

Parameters:
Name Type Attributes Default Description
includeCurrent boolean <optional>
false

Check the current section too.

Returns:
Type
Section

getCommentAboveReply(commentForm) → {Comment}

Source:

If this section is replied to, get the comment that will end up directly above the reply.

Parameters:
Name Type Description
commentForm CommentForm
Returns:
Type
Comment

getCommentFormMethodName(mode) → {string}

Source:

Get the name of the section's method creating a comment form with the specified mode.

Parameters:
Name Type Description
mode string
Returns:
Type
string

getIdentifyingData() → {object}

Source:

Get the data identifying the section when restoring a comment form. (Used for polymorphism with Comment#getRelevantComment and Page#getIdentifyingData.)

Returns:
Type
object

getLastElement(followingHeadingElement, treeWalker) → {Element|external:Element}

Source:
Overrides:

Get the last element in the section based on a following (directly or not) section's heading element.

Sometimes sections are nested trickily in some kind of container elements, so a following structure may take place:

== Heading 1 ==
<p>Paragraph 1.</p>
<div>
  <p>Paragraph 2.</p>
  == Heading 2 ==
  <p>Paragraph 3.</p>
</div>
<p>Paragraph 4.</p>
== Heading 3 ==

In this case, section 1 has paragraphs 1 and 2 as the first and last, and section 2 has paragraphs 3 and 4 as such. Our code must capture that.

Parameters:
Name Type Description
followingHeadingElement Element | external:Element | undefined
treeWalker TreeWalker
Returns:
Type
Element | external:Element

getParent(ignoreFirstLevelopt) → (nullable) {SectionSkeleton}

Source:
Overrides:

Get the parent section of the section.

Parameters:
Name Type Attributes Default Description
ignoreFirstLevel boolean <optional>
true

Don't consider sections of the first level parent sections; stop at second level sections.

Returns:
Type
SectionSkeleton

getRelevantComment() → (nullable) {Section}

Source:

Get a comment relevant to this section, which means the first comment if it is opening the section. (Used for polymorphism with Comment#getRelevantComment and Page#getRelevantComment.)

Returns:
Type
Section

getRelevantSection() → {Section}

Source:

Get a section relevant to this section, which means the section itself. (Used for polymorphism with Comment#getRelevantSection and Page#getRelevantSection.)

Returns:
Type
Section

getSectionSubscribedTo() → (nullable) {Section}

Source:

Get the section used to subscribe to if available.

Returns:
Type
Section

getSourcePage() → {module:pageRegistry.Page}

Source:

Get the wiki page that has the source code of the section (may be different from the current page if the section is transcluded from another page).

Returns:
Type
module:pageRegistry.Page

getTocItem() → (nullable) {module:toc~TocItem}

Source:

Get the TOC item for the section if present.

Returns:
Type
module:toc~TocItem

getUrl(permanent) → {string}

Source:

Get a link to the section with Unicode sequences decoded.

Parameters:
Name Type Description
permanent boolean

Get a permanent URL.

Returns:
Type
string

getWikilinkFragment() → {string}

Source:

Get the fragment for use in a section wikilink.

Returns:
Type
string

(async) loadCode(commentFormopt)

Source:

Load the section wikitext. See also Section#requestCode.

Parameters:
Name Type Attributes Description
commentForm CommentForm <optional>

Comment form, if it is submitted or code changes are viewed.

Throws:
CdError | Error

locateInCode(useSectionCode)

Source:

Locate the section in the source code and set the result to the Section#source property.

It is expected that the section or page code is loaded (using Page#loadCode) before this method is called. Otherwise, the method will throw an error.

Parameters:
Name Type Description
useSectionCode boolean

Is the section code available to locate the section in instead of the page code.

Throws:

maybeAddAddSubsectionButton()

Source:

For internal use. Add an "Add subsection" button that appears when hovering over a "Reply in section" button.

maybeAddReplyButton()

Source:

For internal use. Add a "Reply in section" button to the end of the first chunk of the section.

move()

Source:

Show a move section dialog.

parseHeadline()

Source:
Overrides:

For internal use. Parse the headline of the section and fill the headline property that contains no HTML tags.

removeCommentFormFromPage(mode)

Source:

Remove a comment form targeted at this section from the page.

Parameters:
Name Type Description
mode string

reply(initialStateopt, commentFormopt)

Source:

Create an add reply form.

Parameters:
Name Type Attributes Description
initialState object <optional>
commentForm CommentForm <optional>

(async) requestCode()

Source:

Request the wikitext of the section by its number using the API and set some properties of the section (and also the page). Section#loadCode is a more general method.

Throws:

resubscribeIfRenamed(currentCommentData, oldCommentData)

Source:

Resubscribe to a renamed section if legacy topic subscriptions are used.

Parameters:
Name Type Description
currentCommentData object
oldCommentData object

showAddSubsectionButtonOnReplyButtonHover(baseSection)

Source:

For internal use. Make it so that when the user hovers over a reply button at the end of the section for a second, an "Add subsection" button shows up under it.

Parameters:
Name Type Description
baseSection Section

subscribe(modeopt, renamedFromopt)

Source:

Add the section to the subscription list.

Parameters:
Name Type Attributes Description
mode 'quiet' | 'silent' <optional>
  • No value: a notification will be shown.
  • 'quiet': don't show a notification.
  • 'silent': don't even change any UI, including the subscribe button appearance. If there is an error, it will be displayed though.
renamedFrom string <optional>

If DiscussionTools' topic subscriptions API is not used and the section was renamed, the previous section headline. It is unwatched together with watching the current headline if there are no other coinciding headlines on the page.

unsubscribe(modeopt)

Source:

Remove the section from the subscription list.

Parameters:
Name Type Attributes Description
mode 'quiet' | 'silent' <optional>
  • No value: a notification will be shown.
  • 'quiet': don't show a notification.
  • 'silent': don't even change any UI, including the subscribe button appearance. If there is an error, it will be displayed though.

update($html)

Source:

For internal use. When the section's headline is live-updated in Comment#update, also update some aspects of the section.

Parameters:
Name Type Description
$html external:jQuery

updateNewCommentsData()

Source:

For internal use. Update the new comments data for the section and render the updates.

Source:

Add/remove the section's TOC link according to its subscription state and update the title attribute.

updateVisibility(show)

Source:

For internal use. Set the visibility CSS value to the section.

Parameters:
Name Type Description
show boolean

Show or hide.