52 $this->mParser = $parser;
54 $this->mDir = $this->mParser->getTargetLanguage()->getDir();
57 $this->mParser->getOptions()->getUserLangObj();
58 $this->mParser->getOutput()->addModuleStyles( [
59 'ext.inputBox.styles',
61 'mediawiki.ui.checkbox',
67 switch ( $this->mType ) {
70 $this->mParser->getOutput()->addModules(
'ext.inputBox' );
85 [
'class' =>
'error' ],
86 strlen( $this->mType ) > 0
87 ?
wfMessage(
'inputbox-error-bad-type', $this->mType )->text()
88 :
wfMessage(
'inputbox-error-no-type' )->text()
110 'name' =>
'veaction',
124 return strtolower( $this->mBR ) ===
'<br />' ?
'mw-inputbox-input ' :
'';
136 if ( !$this->mButtonLabel ) {
137 $this->mButtonLabel =
wfMessage(
'inputbox-tryexact' )->text();
139 if ( !$this->mSearchButtonLabel ) {
140 $this->mSearchButtonLabel =
wfMessage(
'inputbox-searchfulltext' )->text();
142 if ( $this->mID !==
'' ) {
143 $idArray = [
'id' => Sanitizer::escapeIdForAttribute( $this->mID ) ];
149 $idRandStr = Sanitizer::escapeIdForAttribute(
'-' . $this->mID .
wfRandom() );
154 'class' =>
'mw-inputbox-centered',
160 'name' =>
'searchbox',
161 'class' =>
'searchbox',
169 'type' => $this->mHidden ?
'hidden' :
'text',
170 'value' => $this->mDefaultText,
171 'placeholder' => $this->mPlaceholderText,
172 'size' => $this->mWidth,
173 'dir' => $this->mDir,
177 if ( $this->mPrefix !=
'' ) {
178 $htmlOut .= Html::hidden(
'prefix', $this->mPrefix );
181 if ( $this->mSearchFilter !=
'' ) {
182 $htmlOut .= Html::hidden(
'searchfilter', $this->mSearchFilter );
185 if ( $this->mTour !=
'' ) {
186 $htmlOut .= Html::hidden(
'tour', $this->mTour );
192 $namespacesArray = explode(
',', $this->mNamespaces );
193 if ( $this->mNamespaces ) {
194 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
195 $namespaces = $contLang->getNamespaces();
197 $showNamespaces = [];
200 foreach ( $namespacesArray as $userNS ) {
201 $userNS = trim( $userNS );
204 if ( strpos( $userNS,
'**' ) ) {
205 $userNS = str_replace(
'**',
'', $userNS );
206 $checkedNS[$userNS] =
true;
209 $mainMsg =
wfMessage(
'inputbox-ns-main' )->inContentLanguage()->text();
210 if ( $userNS ==
'Main' || $userNS == $mainMsg ) {
212 } elseif ( array_search( $userNS, $namespaces ) ) {
213 $i = array_search( $userNS, $namespaces );
214 } elseif ( isset( $nsAliases[$userNS] ) ) {
215 $i = $nsAliases[$userNS];
219 $showNamespaces[$i] = $userNS;
220 if ( isset( $checkedNS[$userNS] ) && $checkedNS[$userNS] ) {
221 $checkedNS[$i] =
true;
226 foreach ( $showNamespaces as $i => $name ) {
229 if ( ( isset( $checkedNS[$i] ) && $checkedNS[$i] ) || count( $showNamespaces ) == 1 ) {
230 $checked = [
'checked' =>
'checked' ];
233 if ( count( $showNamespaces ) == 1 ) {
240 'id' =>
'mw-inputbox-ns' . $i . $idRandStr
245 $htmlOut .=
' <div class="mw-inputbox-element mw-ui-checkbox">';
248 'type' =>
'checkbox',
251 'id' =>
'mw-inputbox-ns' . $i . $idRandStr
255 $htmlOut .=
Xml::label( $name,
'mw-inputbox-ns' . $i . $idRandStr );
256 $htmlOut .=
'</div> ';
262 } elseif (
$type ==
'search' ) {
268 'class' =>
'mw-ui-button',
269 'value' => $this->mButtonLabel
272 $htmlOut .=
"\u{00A0}";
279 'name' =>
'fulltext',
280 'class' =>
'mw-ui-button',
281 'value' => $this->mSearchButtonLabel
286 if (
$type ==
'fulltext' ) {
287 $htmlOut .= Html::hidden(
'fulltext',
'Search' );
303 if ( !$this->mButtonLabel ) {
304 $this->mButtonLabel =
wfMessage(
'inputbox-tryexact' )->text();
307 if ( $this->mID !==
'' ) {
315 $id = Sanitizer::escapeIdForAttribute( $unescapedID );
317 if ( isset( $this->mLabelText ) && strlen( trim( $this->mLabelText ) ) ) {
318 $htmlLabel =
Xml::openElement(
'label', [
'for' =>
'bodySearchInput' . $id ] );
319 $htmlLabel .= $this->mParser->recursiveTagParse( $this->mLabelText );
324 'name' =>
'bodySearch' . $id,
325 'id' =>
'bodySearch' . $id,
326 'class' =>
'bodySearch' . ( $this->mInline ?
' mw-inputbox-inline' :
'' ),
332 'class' =>
'bodySearchWrap' . ( $this->mInline ?
' mw-inputbox-inline' :
'' ),
336 $htmlOut .= $htmlLabel;
339 'type' => $this->mHidden ?
'hidden' :
'text',
341 'class' =>
'mw-ui-input mw-ui-input-inline',
342 'size' => $this->mWidth,
343 'id' =>
'bodySearchInput' . $id,
344 'dir' => $this->mDir,
351 'value' => $this->mButtonLabel,
352 'class' =>
'mw-ui-button',
357 if ( !empty( $this->mFullTextButton ) ) {
361 'name' =>
'fulltext',
362 'class' =>
'mw-ui-button',
363 'value' => $this->mSearchButtonLabel
382 if ( $this->mType ==
"comment" ) {
383 if ( !$this->mButtonLabel ) {
384 $this->mButtonLabel =
wfMessage(
'inputbox-postcomment' )->text();
387 if ( !$this->mButtonLabel ) {
388 $this->mButtonLabel =
wfMessage(
'inputbox-createarticle' )->text();
394 'class' =>
'mw-inputbox-centered',
399 'name' =>
'createbox',
400 'class' =>
'createbox',
404 if ( $this->mID !==
'' ) {
405 $createBoxParams[
'id'] = Sanitizer::escapeIdForAttribute( $this->mID );
409 $htmlOut .= Html::hidden( $editArgs[
'name'], $editArgs[
'value'] );
410 if ( $this->mPreload !==
null ) {
411 $htmlOut .= Html::hidden(
'preload', $this->mPreload );
413 if ( is_array( $this->mPreloadparams ) ) {
414 foreach ( $this->mPreloadparams as $preloadparams ) {
415 $htmlOut .= Html::hidden(
'preloadparams[]', $preloadparams );
418 if ( $this->mEditIntro !==
null ) {
419 $htmlOut .= Html::hidden(
'editintro', $this->mEditIntro );
421 if ( $this->mSummary !==
null ) {
422 $htmlOut .= Html::hidden(
'summary', $this->mSummary );
424 if ( $this->mNosummary !==
null ) {
425 $htmlOut .= Html::hidden(
'nosummary', $this->mNosummary );
427 if ( $this->mPrefix !==
'' ) {
428 $htmlOut .= Html::hidden(
'prefix', $this->mPrefix );
430 if ( $this->mMinor !==
null ) {
431 $htmlOut .= Html::hidden(
'minor', $this->mMinor );
433 if ( $this->mType ==
'comment' ) {
434 $htmlOut .= Html::hidden(
'section',
'new' );
438 'type' => $this->mHidden ?
'hidden' :
'text',
441 'mw-ui-input mw-ui-input-inline createboxInput',
442 'value' => $this->mDefaultText,
443 'placeholder' => $this->mPlaceholderText,
444 'size' => $this->mWidth,
445 'dir' => $this->mDir,
453 'class' =>
'mw-ui-button mw-ui-progressive createboxButton',
454 'value' => $this->mButtonLabel
471 if ( !$this->mButtonLabel ) {
472 $this->mButtonLabel =
wfMessage(
'inputbox-movearticle' )->text();
477 'class' =>
'mw-inputbox-centered',
483 'class' =>
'mw-movebox',
487 if ( $this->mID !==
'' ) {
488 $moveBoxParams[
'id'] = Sanitizer::escapeIdForAttribute( $this->mID );
491 $htmlOut .= Html::hidden(
'title',
493 $htmlOut .= Html::hidden(
'wpReason', $this->mSummary );
494 $htmlOut .= Html::hidden(
'prefix', $this->mPrefix );
497 'type' => $this->mHidden ?
'hidden' :
'text',
498 'name' =>
'wpNewTitle',
499 'class' => $this->
getLinebreakClasses() .
'mw-moveboxInput mw-ui-input mw-ui-input-inline',
500 'value' => $this->mDefaultText,
501 'placeholder' => $this->mPlaceholderText,
502 'size' => $this->mWidth,
503 'dir' => $this->mDir,
510 'class' =>
'mw-ui-button mw-ui-progressive',
511 'value' => $this->mButtonLabel
528 if ( !$this->mButtonLabel ) {
529 $this->mButtonLabel =
wfMessage(
'inputbox-postcommenttitle' )->text();
534 'class' =>
'mw-inputbox-centered',
538 $commentFormParams = [
539 'name' =>
'commentbox',
540 'class' =>
'commentbox',
544 if ( $this->mID !==
'' ) {
545 $commentFormParams[
'id'] = Sanitizer::escapeIdForAttribute( $this->mID );
549 $htmlOut .= Html::hidden( $editArgs[
'name'], $editArgs[
'value'] );
550 if ( $this->mPreload !==
null ) {
551 $htmlOut .= Html::hidden(
'preload', $this->mPreload );
553 if ( is_array( $this->mPreloadparams ) ) {
554 foreach ( $this->mPreloadparams as $preloadparams ) {
555 $htmlOut .= Html::hidden(
'preloadparams[]', $preloadparams );
558 if ( $this->mEditIntro !==
null ) {
559 $htmlOut .= Html::hidden(
'editintro', $this->mEditIntro );
563 'type' => $this->mHidden ?
'hidden' :
'text',
564 'name' =>
'preloadtitle',
565 'class' => $this->
getLinebreakClasses() .
'commentboxInput mw-ui-input mw-ui-input-inline',
566 'value' => $this->mDefaultText,
567 'placeholder' => $this->mPlaceholderText,
568 'size' => $this->mWidth,
569 'dir' => $this->mDir,
572 $htmlOut .= Html::hidden(
'section',
'new' );
573 $htmlOut .= Html::hidden(
'title', $this->mPage );
579 'class' =>
'mw-ui-button mw-ui-progressive',
580 'value' => $this->mButtonLabel
598 foreach ( explode(
"\n", $text ) as
$line ) {
599 if ( strpos(
$line,
'=' ) ===
false ) {
602 list( $name, $value ) = explode(
'=',
$line, 2 );
603 $name = strtolower( trim( $name ) );
604 $value = Sanitizer::decodeCharReferences( trim( $value ) );
605 if ( $name ==
'preloadparams[]' ) {
607 $this->mPreloadparams[] = $value;
609 $values[ $name ] = $value;
614 if ( isset( $values[
'dir'] ) && !in_array( $values[
'dir'], [
'ltr',
'rtl' ] ) ) {
615 unset( $values[
'dir'] );
622 'preload' =>
'mPreload',
624 'editintro' =>
'mEditIntro',
626 'summary' =>
'mSummary',
627 'nosummary' =>
'mNosummary',
630 'default' =>
'mDefaultText',
631 'placeholder' =>
'mPlaceholderText',
632 'bgcolor' =>
'mBGColor',
633 'buttonlabel' =>
'mButtonLabel',
634 'searchbuttonlabel' =>
'mSearchButtonLabel',
635 'fulltextbutton' =>
'mFullTextButton',
636 'namespaces' =>
'mNamespaces',
637 'labeltext' =>
'mLabelText',
638 'hidden' =>
'mHidden',
640 'inline' =>
'mInline',
641 'prefix' =>
'mPrefix',
643 'searchfilter' =>
'mSearchFilter',
649 'buttonlabel' =>
true,
650 'searchbuttonlabel' =>
true,
651 'placeholder' =>
true
653 foreach ( $options as $name => $var ) {
654 if ( isset( $values[$name] ) ) {
655 $this->$var = $values[$name];
656 if ( isset( $convertOptions[$name] ) ) {
663 $this->mBR = ( strtolower( $this->mBR ) ==
"no" ) ?
' ' :
'<br />';
666 $this->mWidth = intval( $this->mWidth <= 0 ? 50 : $this->mWidth );
670 $this->mBGColor =
'transparent';
682 [a-zA-Z]* | # color names
683 \# [0-9a-f]{3} | #
short hexadecimal
684 \# [0-9a-f]{6} | #
long hexadecimal
686 \d+ \s* , \s* \d+ \s* , \s* \d+ | # rgb integer
687 [0-9.]+% \s* , \s* [0-9.]+% \s* , \s* [0-9.]+% # rgb percent
691 return (
bool)preg_match( $regex, $color );
695 if ( $this->mBGColor !=
'transparent' ) {
696 return 'background-color: ' . $this->mBGColor .
';';
728 $lang = $this->mParser->getTargetLanguage();
729 if (
$lang->hasVariants() && strpos( $text,
'-{' ) !== false ) {
730 $text =
$lang->convert( $text );