Merge "Avoid duplicate ids"

This commit is contained in:
jenkins-bot 2014-05-18 16:54:47 +00:00 committed by Gerrit Code Review
commit 8160f5815d

View file

@ -91,6 +91,14 @@ class InputBox {
if ( !$this->mSearchButtonLabel ) { if ( !$this->mSearchButtonLabel ) {
$this->mSearchButtonLabel = wfMessage( 'inputbox-searchfulltext' )->text(); $this->mSearchButtonLabel = wfMessage( 'inputbox-searchfulltext' )->text();
} }
if ( $this->mID !== '' ) {
$idArray = array( 'id' => Sanitizer::escapeId( $this->mID ) );
} else {
$idArray = array();
}
// We need a unqiue id to link <label> to checkboxes, but also
// want multiple <inputbox>'s to not be invalid html
$idRandStr = Sanitizer::escapeId( '-' . $this->mID . wfRandom(), 'noninitial' );
// Build HTML // Build HTML
$htmlOut = Xml::openElement( 'div', $htmlOut = Xml::openElement( 'div',
@ -101,10 +109,9 @@ class InputBox {
$htmlOut .= Xml::openElement( 'form', $htmlOut .= Xml::openElement( 'form',
array( array(
'name' => 'searchbox', 'name' => 'searchbox',
'id' => 'searchbox',
'class' => 'searchbox', 'class' => 'searchbox',
'action' => SpecialPage::getTitleFor( 'Search' )->getLocalUrl(), 'action' => SpecialPage::getTitleFor( 'Search' )->getLocalUrl(),
) ) + $idArray
); );
$htmlOut .= Xml::element( 'input', $htmlOut .= Xml::element( 'input',
array( array(
@ -178,7 +185,7 @@ class InputBox {
'type' => 'hidden', 'type' => 'hidden',
'name' => 'ns' . $i, 'name' => 'ns' . $i,
'value' => 1, 'value' => 1,
'id' => 'mw-inputbox-ns' . $i 'id' => 'mw-inputbox-ns' . $i . $idRandStr
) + $checked ) + $checked
); );
} else { } else {
@ -189,11 +196,11 @@ class InputBox {
'type' => 'checkbox', 'type' => 'checkbox',
'name' => 'ns' . $i, 'name' => 'ns' . $i,
'value' => 1, 'value' => 1,
'id' => 'mw-inputbox-ns' . $i 'id' => 'mw-inputbox-ns' . $i . $idRandStr
) + $checked ) + $checked
); );
// Label // Label
$htmlOut .= '&#160;' . Xml::label( $name, 'mw-inputbox-ns' . $i ); $htmlOut .= '&#160;' . Xml::label( $name, 'mw-inputbox-ns' . $i . $idRandStr );
$htmlOut .= '</div> '; $htmlOut .= '</div> ';
} }
} }
@ -244,7 +251,15 @@ class InputBox {
$this->mButtonLabel = wfMessage( 'inputbox-tryexact' )->text(); $this->mButtonLabel = wfMessage( 'inputbox-tryexact' )->text();
} }
$id = Sanitizer::escapeId( $this->mID, 'noninitial' ); if ( $this->mID !== '' ) {
$unescapedID = $this->mID;
} else {
// The label element needs a unique id, use
// random number to avoid multiple input boxes
// having conflicts.
$unescapedID = wfRandom();
}
$id = Sanitizer::escapeId( $unescapedID, 'noninitial' );
$htmlLabel = ''; $htmlLabel = '';
if ( isset( $this->mLabelText ) && strlen( trim( $this->mLabelText ) ) ) { if ( isset( $this->mLabelText ) && strlen( trim( $this->mLabelText ) ) ) {
$this->mLabelText = $this->mParser->recursiveTagParse( $this->mLabelText ); $this->mLabelText = $this->mParser->recursiveTagParse( $this->mLabelText );