Page MenuHomePhabricator

Expose section identifier in HTML output
Open, Needs TriagePublicFeature

Description

The Edit API provides a section parameter to allow API editing of an individual section of a wikipage, rather than the entire page. This is the same identifier used in the section parameter of an action=edit URL in the Mediawiki UI. But these section identifiers are not exposed in a structured way in the HTML output, leading to user scripts and Gadgets (including the reply tool from the Talk pages project) having to extract it from the href with code like:

  $('span.mw-headline').each(function(index, value){
    var editSectionUrl = $(this).parent().find('.mw-editsection a:first').attr('href');
    var sectionReg = /&section=(.*)/;
    var sectionRaw = sectionReg.exec(editSectionUrl);
    if ((sectionRaw !== null) && (sectionRaw[1].indexOf('T') < 0)){
      var section = parseInt(sectionRaw[1]);

These identifiers are known at this point since the URL to edit the section interactively needs it, so it would be nice if the identifier could be added in a mw-section-id data attribute on either the h2 (etc.) itself, the span.mw-headline, or, at least, on the span.mw-editsection. That would be much more intuitive and discoverable (clearly visible in the DOM), and would make code needing the section identifier significantly less grotty.

I'm told Parsoid already does this (mw:Specs/HTML/2.4.0), but we still have years left of dealing with the existing parser and its output.