fix(core): let makeSections xpath query cope with multiple classes (#733)

* 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>
This commit is contained in:
David Lynch 2023-11-15 14:15:25 -06:00 committed by GitHub
parent e718afa4ab
commit 6f5b761fe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -132,7 +132,10 @@ final class BodyContent extends Partial {
*/
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 ) {