Skip to content

Commit

Permalink
fix(core): let makeSections xpath query cope with multiple classes (#733
Browse files Browse the repository at this point in the history
)

* Let makeSections xpath query cope with multiple classes

As-of https://gerrit.wikimedia.org/r/c/mediawiki/core/+/939783 in mediawiki-core, this class attribute is going to contain multiple classes. This would break the section-creation. This change to the query is backwards-compatible, so this should just inoculate the skin against future updates.

* Shorten line for mediawiki-lint compatibility

* fix: update html selector for parser output

Related: T350627

---------

Co-authored-by: alistair3149 <alistair3149@users.noreply.github.com>
  • Loading branch information
kemayo and alistair3149 committed Nov 15, 2023
1 parent e718afa commit 6f5b761
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion includes/Partials/BodyContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ private function getHeadingName( $node ) {
*/
private function makeSections( DOMDocument $doc, array $headingWrappers ) {
$xpath = new DOMXpath( $doc );
$containers = $xpath->query( '//div[@class="mw-parser-output"][1]' );
$containers = $xpath->query(
// Equivalent of CSS attribute `~=` to support multiple classes
'//div[contains(concat(" ",normalize-space(@class)," ")," mw-parser-output ")][1]'
);

// Return if no parser output is found
if ( !$containers->length || $containers->item( 0 ) === null ) {
Expand Down

0 comments on commit 6f5b761

Please sign in to comment.