jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/314070 )
Change subject: Don't add url parameters to an input box, if the parameter is empty ...................................................................... Don't add url parameters to an input box, if the parameter is empty If a parameter isn't set, it shouldn't be added to the form. Bug: T147048 Change-Id: I7e5aa21528fbc98e9e4d52baca93870f213d4c15 --- M InputBox.classes.php M tests/inputBoxParserTests.txt 2 files changed, 279 insertions(+), 23 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/InputBox.classes.php b/InputBox.classes.php index 0536747..ffa21dd 100644 --- a/InputBox.classes.php +++ b/InputBox.classes.php @@ -14,13 +14,13 @@ private $mParser; private $mType = ''; private $mWidth = 50; - private $mPreload = ''; - private $mPreloadparams = []; - private $mEditIntro = ''; - private $mUseVE = ''; - private $mSummary = ''; - private $mNosummary = ''; - private $mMinor = ''; + private $mPreload = null; + private $mPreloadparams = null; + private $mEditIntro = null; + private $mUseVE = null; + private $mSummary = null; + private $mNosummary = null; + private $mMinor = null; private $mPage = ''; private $mBR = 'yes'; private $mDefaultText = ''; @@ -97,7 +97,7 @@ 'value' => 'edit', ]; // check, if VE is installed and VE editor is requested - if ( ExtensionRegistry::getInstance()->isLoaded( 'VisualEditor' ) && $this->mUseVE ) { + if ( $this->shouldUseVE() ) { $args = [ 'name' => 'veaction', 'value' => 'edit', @@ -393,15 +393,29 @@ $htmlOut .= Xml::openElement( 'form', $createBoxParams ); $editArgs = $this->getEditActionArgs(); $htmlOut .= Html::hidden( $editArgs['name'], $editArgs['value'] ); - $htmlOut .= Html::hidden( 'preload', $this->mPreload ); - foreach ( $this->mPreloadparams as $preloadparams ) { - $htmlOut .= Html::hidden( 'preloadparams[]', $preloadparams ); + if ( $this->mPreload !== null ) { + $htmlOut .= Html::hidden( 'preload', $this->mPreload ); } - $htmlOut .= Html::hidden( 'editintro', $this->mEditIntro ); - $htmlOut .= Html::hidden( 'summary', $this->mSummary ); - $htmlOut .= Html::hidden( 'nosummary', $this->mNosummary ); - $htmlOut .= Html::hidden( 'prefix', $this->mPrefix ); - $htmlOut .= Html::hidden( 'minor', $this->mMinor ); + if ( is_array( $this->mPreloadparams ) ) { + foreach ( $this->mPreloadparams as $preloadparams ) { + $htmlOut .= Html::hidden( 'preloadparams[]', $preloadparams ); + } + } + if ( $this->mEditIntro !== null ) { + $htmlOut .= Html::hidden( 'editintro', $this->mEditIntro ); + } + if ( $this->mSummary !== null ) { + $htmlOut .= Html::hidden( 'summary', $this->mSummary ); + } + if ( $this->mNosummary !== null ) { + $htmlOut .= Html::hidden( 'nosummary', $this->mNosummary ); + } + if ( $this->mPrefix !== '' ) { + $htmlOut .= Html::hidden( 'prefix', $this->mPrefix ); + } + if ( $this->mMinor !== null ) { + $htmlOut .= Html::hidden( 'minor', $this->mMinor ); + } if ( $this->mType == 'comment' ) { $htmlOut .= Html::hidden( 'section', 'new' ); } @@ -517,11 +531,17 @@ $htmlOut .= Xml::openElement( 'form', $commentFormParams ); $editArgs = $this->getEditActionArgs(); $htmlOut .= Html::hidden( $editArgs['name'], $editArgs['value'] ); - $htmlOut .= Html::hidden( 'preload', $this->mPreload ); - foreach ( $this->mPreloadparams as $preloadparams ) { - $htmlOut .= Html::hidden( 'preloadparams[]', $preloadparams ); + if ( $this->mPreload !== null ) { + $htmlOut .= Html::hidden( 'preload', $this->mPreload ); } - $htmlOut .= Html::hidden( 'editintro', $this->mEditIntro ); + if ( is_array( $this->mPreloadparams ) ) { + foreach ( $this->mPreloadparams as $preloadparams ) { + $htmlOut .= Html::hidden( 'preloadparams[]', $preloadparams ); + } + } + if ( $this->mEditIntro !== null ) { + $htmlOut .= Html::hidden( 'editintro', $this->mEditIntro ); + } $htmlOut .= Xml::openElement( 'input', [ 'type' => $this->mHidden ? 'hidden' : 'text', @@ -648,4 +668,14 @@ } return ''; } + + /** + * Returns true, if the VisualEditor is requested from the inputbox wikitext definition and + * if the VisualEditor extension is actually installed or not, false otherwise. + * + * @return bool + */ + private function shouldUseVE() { + return ExtensionRegistry::getInstance()->isLoaded( 'VisualEditor' ) && $this->mUseVE !== null; + } } diff --git a/tests/inputBoxParserTests.txt b/tests/inputBoxParserTests.txt index 9d9749c..d71fdf6 100644 --- a/tests/inputBoxParserTests.txt +++ b/tests/inputBoxParserTests.txt @@ -22,7 +22,233 @@ !! html+tidy <div class="mw-inputbox-centered" style=""> <form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> -<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="preload" /><input type="hidden" name="editintro" /><input type="hidden" name="summary" /><input type="hidden" name="nosummary" /><input type="hidden" name="prefix" /><input type="hidden" name="minor" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<p><input type="hidden" value="edit" name="action" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with minor +!! wikitext +<inputbox> +type=create +minor=1 +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="1" name="minor" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with minor=0 +!! wikitext +<inputbox> +type=create +minor=0 +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="0" name="minor" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with preloadparams +!! wikitext +<inputbox> +type=create +preloadparams[]=param1 +preloadparams[]=param2 +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="param1" name="preloadparams[]" /><input type="hidden" value="param2" name="preloadparams[]" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with empty preloadparams +!! wikitext +<inputbox> +type=create +preloadparams[]= +preloadparams[]= +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="preloadparams[]" /><input type="hidden" name="preloadparams[]" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with editintro +!! wikitext +<inputbox> +type=create +editintro=MediaWiki:Test +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="MediaWiki:Test" name="editintro" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with empty editintro +!! wikitext +<inputbox> +type=create +editintro= +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="editintro" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with summary +!! wikitext +<inputbox> +type=create +summary=Summary test +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="Summary test" name="summary" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with empty summary +!! wikitext +<inputbox> +type=create +summary= +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="summary" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with nosummary +!! wikitext +<inputbox> +type=create +nosummary=true +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="true" name="nosummary" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with empty nosummary +!! wikitext +<inputbox> +type=create +nosummary= +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="nosummary" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with prefix +!! wikitext +<inputbox> +type=create +prefix=Test/ +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="Test/" name="prefix" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with empty prefix +!! wikitext +<inputbox> +type=create +prefix= +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with preload +!! wikitext +<inputbox> +type=create +preload=test +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="test" name="preload" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> +</form> +</div> +!! end + +!! test +InputBox type=create with empty preload +!! wikitext +<inputbox> +type=create +preload= +</inputbox> +!! html+tidy +<div class="mw-inputbox-centered" style=""> +<form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="preload" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> <input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="Create page" /></p> </form> </div> @@ -37,7 +263,7 @@ !! html+tidy <div class="mw-inputbox-centered" style=""> <form name="createbox" class="createbox" action="/index.php" method="get" id="createbox"> -<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="preload" /><input type="hidden" name="editintro" /><input type="hidden" name="summary" /><input type="hidden" name="nosummary" /><input type="hidden" name="prefix" /><input type="hidden" name="minor" /><input type="hidden" value="new" name="section" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> +<p><input type="hidden" value="edit" name="action" /><input type="hidden" value="new" name="section" /><input type="text" name="title" class="mw-inputbox-input mw-ui-input mw-ui-input-inline createboxInput" value="" placeholder="" size="50" dir="ltr" /><br /> <input type="submit" name="create" class="mw-ui-button mw-ui-progressive createboxButton" value="New section" /></p> </form> </div> @@ -52,7 +278,7 @@ !! html+tidy <div class="mw-inputbox-centered" style=""> <form name="commentbox" class="commentbox" action="/index.php" method="get" id="commentbox"> -<p><input type="hidden" value="edit" name="action" /><input type="hidden" name="preload" /><input type="hidden" name="editintro" /><input type="text" name="preloadtitle" class="mw-inputbox-input commentboxInput mw-ui-input mw-ui-input-inline" value="" placeholder="" size="50" dir="ltr" /><input type="hidden" value="new" name="section" /><input type="hidden" name="title" /><br /> +<p><input type="hidden" value="edit" name="action" /><input type="text" name="preloadtitle" class="mw-inputbox-input commentboxInput mw-ui-input mw-ui-input-inline" value="" placeholder="" size="50" dir="ltr" /><input type="hidden" value="new" name="section" /><input type="hidden" name="title" /><br /> <input type="submit" name="create" class="mw-ui-button mw-ui-progressive" value="New section" /></p> </form> </div> -- To view, visit https://gerrit.wikimedia.org/r/314070 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7e5aa21528fbc98e9e4d52baca93870f213d4c15 Gerrit-PatchSet: 12 Gerrit-Project: mediawiki/extensions/InputBox Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> Gerrit-Reviewer: Alex Monk <kren...@gmail.com> Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Sophivorus <scheno...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits