API: Avoid duplicate IDs in API documentation
authorFomafix <fomafix@googlemail.com>
Mon, 2 May 2016 14:09:06 +0000 (14:09 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Mon, 2 May 2016 14:09:06 +0000 (14:09 +0000)
With $wgExperimentalHtmlIds = true Sanitizer::escapeId( 'main/credits' )
is equal to 'main/credits'. This generate a duplicate ID.

This change generates the additional <span> only with
$wgExperimentalHtmlIds = false.

Bug: T134155
Change-Id: Ie5d692b7b166030b2bc5c426b44608d981274cd0

includes/api/ApiMain.php

index 07642c4..280565e 100644 (file)
@@ -1630,9 +1630,14 @@ class ApiMain extends ApiBase {
                        $tocnumber = &$options['tocnumber'];
 
                        $header = $this->msg( 'api-help-datatypes-header' )->parse();
+
+                       // Add an additional span with sanitized ID
+                       if ( !$this->getConfig()->get( 'ExperimentalHtmlIds' ) ) {
+                               $header = Html::element( 'span', [ 'id' => Sanitizer::escapeId( 'main/datatypes' ) ] ) .
+                                       $header;
+                       }
                        $help['datatypes'] .= Html::rawElement( 'h' . min( 6, $level ),
                                [ 'id' => 'main/datatypes', 'class' => 'apihelp-header' ],
-                               Html::element( 'span', [ 'id' => Sanitizer::escapeId( 'main/datatypes' ) ] ) .
                                $header
                        );
                        $help['datatypes'] .= $this->msg( 'api-help-datatypes' )->parseAsBlock();
@@ -1648,10 +1653,14 @@ class ApiMain extends ApiBase {
                                ];
                        }
 
+                       // Add an additional span with sanitized ID
+                       if ( !$this->getConfig()->get( 'ExperimentalHtmlIds' ) ) {
+                               $header = Html::element( 'span', [ 'id' => Sanitizer::escapeId( 'main/credits' ) ] ) .
+                                       $header;
+                       }
                        $header = $this->msg( 'api-credits-header' )->parse();
                        $help['credits'] .= Html::rawElement( 'h' . min( 6, $level ),
                                [ 'id' => 'main/credits', 'class' => 'apihelp-header' ],
-                               Html::element( 'span', [ 'id' => Sanitizer::escapeId( 'main/credits' ) ] ) .
                                $header
                        );
                        $help['credits'] .= $this->msg( 'api-credits' )->useDatabase( false )->parseAsBlock();