2008-10-27 20:33:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Classes for InputBox extension
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
2021-12-10 18:03:35 +00:00
|
|
|
namespace MediaWiki\Extension\InputBox;
|
|
|
|
|
|
|
|
use ExtensionRegistry;
|
|
|
|
use Html;
|
|
|
|
use Parser;
|
|
|
|
use Sanitizer;
|
|
|
|
use SpecialPage;
|
|
|
|
use Xml;
|
|
|
|
|
2017-10-14 13:45:46 +00:00
|
|
|
/**
|
|
|
|
* InputBox class
|
|
|
|
*/
|
2008-10-27 20:33:18 +00:00
|
|
|
class InputBox {
|
|
|
|
|
|
|
|
/* Fields */
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2022-01-09 08:51:04 +00:00
|
|
|
/** @var Parser */
|
2008-10-27 21:35:00 +00:00
|
|
|
private $mParser;
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mType = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var int */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mWidth = 50;
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mPreload = null;
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?array */
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mPreloadparams = null;
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mEditIntro = null;
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mUseVE = null;
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mSummary = null;
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mNosummary = null;
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mMinor = null;
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mPage = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mBR = 'yes';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mDefaultText = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2011-10-26 20:31:20 +00:00
|
|
|
private $mPlaceholderText = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mBGColor = 'transparent';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mButtonLabel = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mSearchButtonLabel = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mFullTextButton = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mLabelText = '';
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mHidden = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mNamespaces = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mID = '';
|
2022-11-11 06:58:42 +00:00
|
|
|
/** @var ?string */
|
|
|
|
private $mInline = null;
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2008-12-31 03:31:41 +00:00
|
|
|
private $mPrefix = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2012-09-02 13:50:42 +00:00
|
|
|
private $mDir = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2017-06-06 18:45:30 +00:00
|
|
|
private $mSearchFilter = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2017-08-24 19:45:31 +00:00
|
|
|
private $mTour = '';
|
2022-11-10 21:02:32 +00:00
|
|
|
/** @var string */
|
2020-01-22 22:58:00 +00:00
|
|
|
private $mTextBoxAriaLabel = '';
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
/* Functions */
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2017-10-14 13:45:46 +00:00
|
|
|
/**
|
|
|
|
* @param Parser $parser
|
|
|
|
*/
|
2008-10-27 20:33:18 +00:00
|
|
|
public function __construct( $parser ) {
|
2008-10-28 01:56:15 +00:00
|
|
|
$this->mParser = $parser;
|
2012-09-02 13:50:42 +00:00
|
|
|
// Default value for dir taken from the page language (bug 37018)
|
|
|
|
$this->mDir = $this->mParser->getTargetLanguage()->getDir();
|
2012-11-15 22:59:31 +00:00
|
|
|
// Split caches by language, to make sure visitors do not see a cached
|
|
|
|
// version in a random language (since labels are in the user language)
|
|
|
|
$this->mParser->getOptions()->getUserLangObj();
|
2017-05-18 18:09:49 +00:00
|
|
|
$this->mParser->getOutput()->addModuleStyles( [
|
2015-02-23 08:45:05 +00:00
|
|
|
'ext.inputBox.styles',
|
|
|
|
'mediawiki.ui.input',
|
|
|
|
'mediawiki.ui.checkbox',
|
2017-05-18 18:09:49 +00:00
|
|
|
] );
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
public function render() {
|
|
|
|
// Handle various types
|
2014-05-18 09:07:27 +00:00
|
|
|
switch ( $this->mType ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
case 'create':
|
|
|
|
case 'comment':
|
|
|
|
return $this->getCreateForm();
|
2014-04-05 20:43:15 +00:00
|
|
|
case 'move':
|
|
|
|
return $this->getMoveForm();
|
2008-10-28 00:08:08 +00:00
|
|
|
case 'commenttitle':
|
|
|
|
return $this->getCommentForm();
|
2008-10-27 20:33:18 +00:00
|
|
|
case 'search':
|
2017-05-18 18:09:49 +00:00
|
|
|
return $this->getSearchForm( 'search' );
|
2009-01-01 00:55:18 +00:00
|
|
|
case 'fulltext':
|
2017-05-18 18:09:49 +00:00
|
|
|
return $this->getSearchForm( 'fulltext' );
|
2008-10-27 20:33:18 +00:00
|
|
|
case 'search2':
|
|
|
|
return $this->getSearchForm2();
|
|
|
|
default:
|
2021-12-15 11:01:38 +00:00
|
|
|
$key = $this->mType === '' ? 'inputbox-error-no-type' : 'inputbox-error-bad-type';
|
2008-10-27 20:33:18 +00:00
|
|
|
return Xml::tags( 'div', null,
|
|
|
|
Xml::element( 'strong',
|
2017-05-18 18:09:49 +00:00
|
|
|
[ 'class' => 'error' ],
|
2021-12-15 11:01:38 +00:00
|
|
|
wfMessage( $key, $this->mType )->text()
|
2008-10-27 20:33:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-14 13:45:46 +00:00
|
|
|
/**
|
2015-04-25 23:50:40 +00:00
|
|
|
* Returns the action name and value to use in inputboxes which redirects to edit pages.
|
|
|
|
* Decides, if the link should redirect to VE edit page (veaction=edit) or to wikitext editor
|
|
|
|
* (action=edit).
|
|
|
|
*
|
2020-11-04 02:06:20 +00:00
|
|
|
* @return array Array with name and value data
|
2015-04-25 23:50:40 +00:00
|
|
|
*/
|
|
|
|
private function getEditActionArgs() {
|
|
|
|
// default is wikitext editor
|
2017-05-18 18:09:49 +00:00
|
|
|
$args = [
|
2015-04-25 23:50:40 +00:00
|
|
|
'name' => 'action',
|
|
|
|
'value' => 'edit',
|
2017-05-18 18:09:49 +00:00
|
|
|
];
|
2015-04-25 23:50:40 +00:00
|
|
|
// check, if VE is installed and VE editor is requested
|
2016-10-04 20:24:54 +00:00
|
|
|
if ( $this->shouldUseVE() ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
$args = [
|
2015-04-25 23:50:40 +00:00
|
|
|
'name' => 'veaction',
|
|
|
|
'value' => 'edit',
|
2017-05-18 18:09:49 +00:00
|
|
|
];
|
2015-04-25 23:50:40 +00:00
|
|
|
}
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
2015-08-13 19:32:35 +00:00
|
|
|
/**
|
|
|
|
* Get common classes, that could be added and depend on, if
|
|
|
|
* a line break between a button and an input field is added or not.
|
|
|
|
*
|
2020-03-20 15:58:43 +00:00
|
|
|
* @return string
|
2015-08-13 19:32:35 +00:00
|
|
|
*/
|
|
|
|
private function getLinebreakClasses() {
|
|
|
|
return strtolower( $this->mBR ) === '<br />' ? 'mw-inputbox-input ' : '';
|
|
|
|
}
|
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
/**
|
|
|
|
* Generate search form
|
2017-10-14 13:45:46 +00:00
|
|
|
* @param string $type
|
2012-08-30 16:20:32 +00:00
|
|
|
* @return string HTML
|
2008-10-27 20:33:18 +00:00
|
|
|
*/
|
2009-01-01 00:55:18 +00:00
|
|
|
public function getSearchForm( $type ) {
|
2019-09-02 08:54:59 +00:00
|
|
|
global $wgNamespaceAliases;
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Use button label fallbacks
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-tryexact' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mSearchButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mSearchButtonLabel = wfMessage( 'inputbox-searchfulltext' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2014-04-06 19:35:30 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
2017-10-19 02:20:48 +00:00
|
|
|
$idArray = [ 'id' => Sanitizer::escapeIdForAttribute( $this->mID ) ];
|
2014-04-06 19:35:30 +00:00
|
|
|
} else {
|
2017-05-18 18:09:49 +00:00
|
|
|
$idArray = [];
|
2014-04-06 19:35:30 +00:00
|
|
|
}
|
|
|
|
// We need a unqiue id to link <label> to checkboxes, but also
|
|
|
|
// want multiple <inputbox>'s to not be invalid html
|
2017-10-19 02:20:48 +00:00
|
|
|
$idRandStr = Sanitizer::escapeIdForAttribute( '-' . $this->mID . wfRandom() );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Build HTML
|
|
|
|
$htmlOut = Xml::openElement( 'div',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'form',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'searchbox',
|
|
|
|
'class' => 'searchbox',
|
2014-01-04 09:31:54 +00:00
|
|
|
'action' => SpecialPage::getTitleFor( 'Search' )->getLocalUrl(),
|
2017-05-18 18:09:49 +00:00
|
|
|
] + $idArray
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2020-01-22 22:58:00 +00:00
|
|
|
|
|
|
|
$htmlOut .= $this->buildTextBox( [
|
2020-08-14 14:58:48 +00:00
|
|
|
// enable SearchSuggest with mw-searchInput class
|
|
|
|
'class' => $this->getLinebreakClasses() . 'mw-searchInput searchboxInput mw-ui-input mw-ui-input-inline',
|
2020-01-22 22:58:00 +00:00
|
|
|
'name' => 'search',
|
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'value' => $this->mDefaultText,
|
|
|
|
'placeholder' => $this->mPlaceholderText,
|
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir
|
|
|
|
] );
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $this->mPrefix !== '' ) {
|
2015-08-06 07:25:57 +00:00
|
|
|
$htmlOut .= Html::hidden( 'prefix', $this->mPrefix );
|
2008-12-31 03:31:41 +00:00
|
|
|
}
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $this->mSearchFilter !== '' ) {
|
2017-06-06 18:45:30 +00:00
|
|
|
$htmlOut .= Html::hidden( 'searchfilter', $this->mSearchFilter );
|
|
|
|
}
|
|
|
|
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $this->mTour !== '' ) {
|
2017-08-24 19:45:31 +00:00
|
|
|
$htmlOut .= Html::hidden( 'tour', $this->mTour );
|
|
|
|
}
|
|
|
|
|
2008-10-27 21:35:00 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
2008-10-27 20:33:18 +00:00
|
|
|
|
|
|
|
// Determine namespace checkboxes
|
2008-10-27 21:35:00 +00:00
|
|
|
$namespacesArray = explode( ',', $this->mNamespaces );
|
|
|
|
if ( $this->mNamespaces ) {
|
2021-11-02 12:30:19 +00:00
|
|
|
$contLang = $this->mParser->getContentLanguage();
|
2019-09-02 08:54:59 +00:00
|
|
|
$namespaces = $contLang->getNamespaces();
|
|
|
|
$nsAliases = array_merge( $contLang->getNamespaceAliases(), $wgNamespaceAliases );
|
2017-05-18 18:09:49 +00:00
|
|
|
$showNamespaces = [];
|
|
|
|
$checkedNS = [];
|
|
|
|
// Check for valid namespaces
|
2011-07-14 03:51:10 +00:00
|
|
|
foreach ( $namespacesArray as $userNS ) {
|
2022-11-10 21:02:32 +00:00
|
|
|
// no whitespace
|
|
|
|
$userNS = trim( $userNS );
|
2011-07-14 03:51:10 +00:00
|
|
|
|
2017-05-18 18:09:49 +00:00
|
|
|
// Namespace needs to be checked if flagged with "**"
|
2011-08-22 23:47:01 +00:00
|
|
|
if ( strpos( $userNS, '**' ) ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$userNS = str_replace( '**', '', $userNS );
|
|
|
|
$checkedNS[$userNS] = true;
|
|
|
|
}
|
|
|
|
|
2012-08-30 16:20:32 +00:00
|
|
|
$mainMsg = wfMessage( 'inputbox-ns-main' )->inContentLanguage()->text();
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $userNS === 'Main' || $userNS === $mainMsg ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$i = 0;
|
2014-05-18 09:07:27 +00:00
|
|
|
} elseif ( array_search( $userNS, $namespaces ) ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$i = array_search( $userNS, $namespaces );
|
|
|
|
} elseif ( isset( $nsAliases[$userNS] ) ) {
|
|
|
|
$i = $nsAliases[$userNS];
|
|
|
|
} else {
|
2022-11-10 21:02:32 +00:00
|
|
|
// Namespace not recognized, skip
|
|
|
|
continue;
|
2011-07-14 03:51:10 +00:00
|
|
|
}
|
|
|
|
$showNamespaces[$i] = $userNS;
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( isset( $checkedNS[$userNS] ) && $checkedNS[$userNS] ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$checkedNS[$i] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 18:09:49 +00:00
|
|
|
// Show valid namespaces
|
2014-05-18 09:07:27 +00:00
|
|
|
foreach ( $showNamespaces as $i => $name ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
$checked = [];
|
2011-07-14 03:51:10 +00:00
|
|
|
// Namespace flagged with "**" or if it's the only one
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( ( isset( $checkedNS[$i] ) && $checkedNS[$i] ) || count( $showNamespaces ) === 1 ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
$checked = [ 'checked' => 'checked' ];
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( count( $showNamespaces ) === 1 ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
// Checkbox
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2011-07-14 03:51:10 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'ns' . $i,
|
|
|
|
'value' => 1,
|
2014-04-06 19:35:30 +00:00
|
|
|
'id' => 'mw-inputbox-ns' . $i . $idRandStr
|
2017-05-18 18:09:49 +00:00
|
|
|
] + $checked
|
2011-07-14 03:51:10 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Checkbox
|
2015-03-13 10:36:53 +00:00
|
|
|
$htmlOut .= ' <div class="mw-inputbox-element mw-ui-checkbox">';
|
2011-07-14 03:51:10 +00:00
|
|
|
$htmlOut .= Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2011-07-14 03:51:10 +00:00
|
|
|
'type' => 'checkbox',
|
|
|
|
'name' => 'ns' . $i,
|
|
|
|
'value' => 1,
|
2014-04-06 19:35:30 +00:00
|
|
|
'id' => 'mw-inputbox-ns' . $i . $idRandStr
|
2017-05-18 18:09:49 +00:00
|
|
|
] + $checked
|
2011-07-14 03:51:10 +00:00
|
|
|
);
|
|
|
|
// Label
|
2015-02-23 08:45:05 +00:00
|
|
|
$htmlOut .= Xml::label( $name, 'mw-inputbox-ns' . $i . $idRandStr );
|
2011-07-14 03:51:10 +00:00
|
|
|
$htmlOut .= '</div> ';
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
|
|
|
// Line break
|
2008-10-27 21:35:00 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
2021-10-16 20:10:22 +00:00
|
|
|
} elseif ( $type === 'search' ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
// Go button
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 20:33:18 +00:00
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'go',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mButtonLabel
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2019-05-13 15:40:09 +00:00
|
|
|
$htmlOut .= "\u{00A0}";
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Search button
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 20:33:18 +00:00
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'fulltext',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mSearchButtonLabel
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2009-02-26 20:15:49 +00:00
|
|
|
// Hidden fulltext param for IE (bug 17161)
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $type === 'fulltext' ) {
|
2010-10-29 15:32:44 +00:00
|
|
|
$htmlOut .= Html::hidden( 'fulltext', 'Search' );
|
2009-02-26 20:15:49 +00:00
|
|
|
}
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2011-10-26 03:49:06 +00:00
|
|
|
/**
|
2008-10-27 20:33:18 +00:00
|
|
|
* Generate search form version 2
|
2017-10-14 13:45:46 +00:00
|
|
|
* @return string
|
2008-10-27 20:33:18 +00:00
|
|
|
*/
|
|
|
|
public function getSearchForm2() {
|
|
|
|
// Use button label fallbacks
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-tryexact' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2014-04-06 19:35:30 +00:00
|
|
|
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();
|
|
|
|
}
|
2017-10-19 02:20:48 +00:00
|
|
|
$id = Sanitizer::escapeIdForAttribute( $unescapedID );
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlLabel = '';
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( isset( $this->mLabelText ) && strlen( trim( $this->mLabelText ) ) ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
$htmlLabel = Xml::openElement( 'label', [ 'for' => 'bodySearchInput' . $id ] );
|
2018-05-04 20:57:11 +00:00
|
|
|
$htmlLabel .= $this->mParser->recursiveTagParse( $this->mLabelText );
|
2008-11-29 04:07:46 +00:00
|
|
|
$htmlLabel .= Xml::closeElement( 'label' );
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
$htmlOut = Xml::openElement( 'form',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'bodySearch' . $id,
|
|
|
|
'id' => 'bodySearch' . $id,
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'bodySearch' . ( $this->mInline ? ' mw-inputbox-inline' : '' ),
|
2014-01-04 09:31:54 +00:00
|
|
|
'action' => SpecialPage::getTitleFor( 'Search' )->getLocalUrl(),
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
|
|
|
$htmlOut .= Xml::openElement( 'div',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'bodySearchWrap' . ( $this->mInline ? ' mw-inputbox-inline' : '' ),
|
|
|
|
'style' => $this->bgColorStyle(),
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
|
|
|
$htmlOut .= $htmlLabel;
|
2020-01-22 22:58:00 +00:00
|
|
|
|
|
|
|
$htmlOut .= $this->buildTextBox( [
|
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'name' => 'search',
|
2020-08-14 14:58:48 +00:00
|
|
|
// enable SearchSuggest with mw-searchInput class
|
|
|
|
'class' => 'mw-searchInput mw-ui-input mw-ui-input-inline',
|
2020-01-22 22:58:00 +00:00
|
|
|
'size' => $this->mWidth,
|
|
|
|
'id' => 'bodySearchInput' . $id,
|
|
|
|
'dir' => $this->mDir,
|
|
|
|
'placeholder' => $this->mPlaceholderText
|
|
|
|
] );
|
|
|
|
|
2019-05-13 15:40:09 +00:00
|
|
|
$htmlOut .= "\u{00A0}" . Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 20:33:18 +00:00
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'go',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mButtonLabel,
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Better testing needed here!
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !empty( $this->mFullTextButton ) ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 20:33:18 +00:00
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'fulltext',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mSearchButtonLabel
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
|
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate create page form
|
2017-10-14 13:45:46 +00:00
|
|
|
* @return string
|
2008-10-27 20:33:18 +00:00
|
|
|
*/
|
|
|
|
public function getCreateForm() {
|
2008-10-27 20:56:23 +00:00
|
|
|
global $wgScript;
|
2008-10-27 20:33:18 +00:00
|
|
|
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $this->mType === 'comment' ) {
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-22 15:46:10 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-postcomment' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-05 19:40:46 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-createarticle' )->text();
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut = Xml::openElement( 'div',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2017-05-18 18:09:49 +00:00
|
|
|
$createBoxParams = [
|
2009-12-15 11:23:43 +00:00
|
|
|
'name' => 'createbox',
|
|
|
|
'class' => 'createbox',
|
|
|
|
'action' => $wgScript,
|
|
|
|
'method' => 'get'
|
2017-05-18 18:09:49 +00:00
|
|
|
];
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
2017-10-19 02:20:48 +00:00
|
|
|
$createBoxParams['id'] = Sanitizer::escapeIdForAttribute( $this->mID );
|
2009-12-15 11:23:43 +00:00
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'form', $createBoxParams );
|
2015-04-25 23:50:40 +00:00
|
|
|
$editArgs = $this->getEditActionArgs();
|
|
|
|
$htmlOut .= Html::hidden( $editArgs['name'], $editArgs['value'] );
|
2016-10-04 20:24:54 +00:00
|
|
|
if ( $this->mPreload !== null ) {
|
|
|
|
$htmlOut .= Html::hidden( 'preload', $this->mPreload );
|
|
|
|
}
|
|
|
|
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 );
|
2014-09-07 01:23:19 +00:00
|
|
|
}
|
2022-11-10 21:02:32 +00:00
|
|
|
// @phan-suppress-next-line PhanSuspiciousValueComparison False positive
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $this->mType === 'comment' ) {
|
2015-08-06 07:25:57 +00:00
|
|
|
$htmlOut .= Html::hidden( 'section', 'new' );
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2020-01-22 22:58:00 +00:00
|
|
|
|
|
|
|
$htmlOut .= $this->buildTextBox( [
|
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'name' => 'title',
|
|
|
|
'class' => $this->getLinebreakClasses() .
|
2021-05-21 02:03:06 +00:00
|
|
|
'mw-ui-input mw-ui-input-inline mw-inputbox-createbox',
|
2020-01-22 22:58:00 +00:00
|
|
|
'value' => $this->mDefaultText,
|
|
|
|
'placeholder' => $this->mPlaceholderText,
|
2021-05-21 02:03:06 +00:00
|
|
|
// For visible input fields, use required so that the form will not
|
|
|
|
// submit without a value
|
|
|
|
'required' => !$this->mHidden,
|
2020-01-22 22:58:00 +00:00
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir
|
|
|
|
] );
|
|
|
|
|
2008-10-27 21:35:00 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
2008-10-27 20:33:18 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 20:33:18 +00:00
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'create',
|
2021-05-21 02:03:06 +00:00
|
|
|
'class' => 'mw-ui-button mw-ui-progressive',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mButtonLabel
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2014-04-05 20:43:15 +00:00
|
|
|
/**
|
|
|
|
* Generate move page form
|
2017-10-14 13:45:46 +00:00
|
|
|
* @return string
|
2014-04-05 20:43:15 +00:00
|
|
|
*/
|
|
|
|
public function getMoveForm() {
|
|
|
|
global $wgScript;
|
|
|
|
|
|
|
|
if ( !$this->mButtonLabel ) {
|
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-movearticle' )->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
$htmlOut = Xml::openElement( 'div',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2014-04-05 20:43:15 +00:00
|
|
|
);
|
2017-05-18 18:09:49 +00:00
|
|
|
$moveBoxParams = [
|
2014-04-05 20:43:15 +00:00
|
|
|
'name' => 'movebox',
|
|
|
|
'class' => 'mw-movebox',
|
|
|
|
'action' => $wgScript,
|
|
|
|
'method' => 'get'
|
2017-05-18 18:09:49 +00:00
|
|
|
];
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
2017-10-19 02:20:48 +00:00
|
|
|
$moveBoxParams['id'] = Sanitizer::escapeIdForAttribute( $this->mID );
|
2014-04-05 20:43:15 +00:00
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'form', $moveBoxParams );
|
2017-05-18 18:09:49 +00:00
|
|
|
$htmlOut .= Html::hidden( 'title',
|
|
|
|
SpecialPage::getTitleFor( 'Movepage', $this->mPage )->getPrefixedText() );
|
2015-08-06 07:25:57 +00:00
|
|
|
$htmlOut .= Html::hidden( 'wpReason', $this->mSummary );
|
|
|
|
$htmlOut .= Html::hidden( 'prefix', $this->mPrefix );
|
2020-01-22 22:58:00 +00:00
|
|
|
|
|
|
|
$htmlOut .= $this->buildTextBox( [
|
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'name' => 'wpNewTitle',
|
|
|
|
'class' => $this->getLinebreakClasses() . 'mw-moveboxInput mw-ui-input mw-ui-input-inline',
|
|
|
|
'value' => $this->mDefaultText,
|
|
|
|
'placeholder' => $this->mPlaceholderText,
|
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir
|
|
|
|
] );
|
|
|
|
|
2014-04-05 20:43:15 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2014-04-05 20:43:15 +00:00
|
|
|
'type' => 'submit',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button mw-ui-progressive',
|
2014-04-05 20:43:15 +00:00
|
|
|
'value' => $this->mButtonLabel
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2014-04-05 20:43:15 +00:00
|
|
|
);
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
|
|
|
|
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
|
|
|
|
2008-10-28 00:08:08 +00:00
|
|
|
/**
|
|
|
|
* Generate new section form
|
2017-10-14 13:45:46 +00:00
|
|
|
* @return string
|
2008-10-28 00:08:08 +00:00
|
|
|
*/
|
|
|
|
public function getCommentForm() {
|
|
|
|
global $wgScript;
|
|
|
|
|
|
|
|
if ( !$this->mButtonLabel ) {
|
2014-04-22 15:46:10 +00:00
|
|
|
$this->mButtonLabel = wfMessage( 'inputbox-postcommenttitle' )->text();
|
2008-10-28 00:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$htmlOut = Xml::openElement( 'div',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2014-05-18 09:51:07 +00:00
|
|
|
'class' => 'mw-inputbox-centered',
|
|
|
|
'style' => $this->bgColorStyle(),
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-28 00:08:08 +00:00
|
|
|
);
|
2017-05-18 18:09:49 +00:00
|
|
|
$commentFormParams = [
|
2009-12-15 11:23:43 +00:00
|
|
|
'name' => 'commentbox',
|
|
|
|
'class' => 'commentbox',
|
|
|
|
'action' => $wgScript,
|
|
|
|
'method' => 'get'
|
2017-05-18 18:09:49 +00:00
|
|
|
];
|
2014-05-18 09:07:27 +00:00
|
|
|
if ( $this->mID !== '' ) {
|
2017-10-19 02:20:48 +00:00
|
|
|
$commentFormParams['id'] = Sanitizer::escapeIdForAttribute( $this->mID );
|
2009-12-15 11:23:43 +00:00
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'form', $commentFormParams );
|
2015-04-25 23:50:40 +00:00
|
|
|
$editArgs = $this->getEditActionArgs();
|
|
|
|
$htmlOut .= Html::hidden( $editArgs['name'], $editArgs['value'] );
|
2016-10-04 20:24:54 +00:00
|
|
|
if ( $this->mPreload !== null ) {
|
|
|
|
$htmlOut .= Html::hidden( 'preload', $this->mPreload );
|
|
|
|
}
|
|
|
|
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 );
|
2014-09-07 01:23:19 +00:00
|
|
|
}
|
2020-01-22 22:58:00 +00:00
|
|
|
|
|
|
|
$htmlOut .= $this->buildTextBox( [
|
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'name' => 'preloadtitle',
|
|
|
|
'class' => $this->getLinebreakClasses() . 'commentboxInput mw-ui-input mw-ui-input-inline',
|
|
|
|
'value' => $this->mDefaultText,
|
|
|
|
'placeholder' => $this->mPlaceholderText,
|
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir
|
|
|
|
] );
|
|
|
|
|
2015-08-06 07:25:57 +00:00
|
|
|
$htmlOut .= Html::hidden( 'section', 'new' );
|
|
|
|
$htmlOut .= Html::hidden( 'title', $this->mPage );
|
2008-10-28 00:08:08 +00:00
|
|
|
$htmlOut .= $this->mBR;
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-28 00:08:08 +00:00
|
|
|
'type' => 'submit',
|
|
|
|
'name' => 'create',
|
2015-01-07 23:35:10 +00:00
|
|
|
'class' => 'mw-ui-button mw-ui-progressive',
|
2008-10-28 00:08:08 +00:00
|
|
|
'value' => $this->mButtonLabel
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-28 00:08:08 +00:00
|
|
|
);
|
|
|
|
$htmlOut .= Xml::closeElement( 'form' );
|
|
|
|
$htmlOut .= Xml::closeElement( 'div' );
|
|
|
|
|
|
|
|
// Return HTML
|
|
|
|
return $htmlOut;
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract options from a blob of text
|
|
|
|
*
|
|
|
|
* @param string $text Tag contents
|
|
|
|
*/
|
|
|
|
public function extractOptions( $text ) {
|
|
|
|
// Parse all possible options
|
2017-05-18 18:09:49 +00:00
|
|
|
$values = [];
|
2008-10-27 20:56:23 +00:00
|
|
|
foreach ( explode( "\n", $text ) as $line ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
if ( strpos( $line, '=' ) === false ) {
|
2008-10-27 20:33:18 +00:00
|
|
|
continue;
|
2017-05-18 18:09:49 +00:00
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
list( $name, $value ) = explode( '=', $line, 2 );
|
2014-09-07 01:23:19 +00:00
|
|
|
$name = strtolower( trim( $name ) );
|
|
|
|
$value = Sanitizer::decodeCharReferences( trim( $value ) );
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $name === 'preloadparams[]' ) {
|
2014-09-07 01:23:19 +00:00
|
|
|
// We have to special-case this one because it's valid for it to appear more than once.
|
|
|
|
$this->mPreloadparams[] = $value;
|
|
|
|
} else {
|
|
|
|
$values[ $name ] = $value;
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
2008-10-27 20:56:23 +00:00
|
|
|
|
2012-09-02 13:50:42 +00:00
|
|
|
// Validate the dir value.
|
2017-05-18 18:09:49 +00:00
|
|
|
if ( isset( $values['dir'] ) && !in_array( $values['dir'], [ 'ltr', 'rtl' ] ) ) {
|
2012-09-02 13:50:42 +00:00
|
|
|
unset( $values['dir'] );
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:50:13 +00:00
|
|
|
// Build list of options, with local member names
|
2017-05-18 18:09:49 +00:00
|
|
|
$options = [
|
2008-11-13 08:50:13 +00:00
|
|
|
'type' => 'mType',
|
|
|
|
'width' => 'mWidth',
|
|
|
|
'preload' => 'mPreload',
|
|
|
|
'page' => 'mPage',
|
|
|
|
'editintro' => 'mEditIntro',
|
2015-04-25 23:50:40 +00:00
|
|
|
'useve' => 'mUseVE',
|
2009-01-13 02:18:30 +00:00
|
|
|
'summary' => 'mSummary',
|
2010-03-31 12:33:11 +00:00
|
|
|
'nosummary' => 'mNosummary',
|
2009-01-13 02:18:30 +00:00
|
|
|
'minor' => 'mMinor',
|
2008-11-13 08:50:13 +00:00
|
|
|
'break' => 'mBR',
|
|
|
|
'default' => 'mDefaultText',
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => 'mPlaceholderText',
|
2008-11-13 08:50:13 +00:00
|
|
|
'bgcolor' => 'mBGColor',
|
|
|
|
'buttonlabel' => 'mButtonLabel',
|
|
|
|
'searchbuttonlabel' => 'mSearchButtonLabel',
|
|
|
|
'fulltextbutton' => 'mFullTextButton',
|
|
|
|
'namespaces' => 'mNamespaces',
|
|
|
|
'labeltext' => 'mLabelText',
|
|
|
|
'hidden' => 'mHidden',
|
|
|
|
'id' => 'mID',
|
|
|
|
'inline' => 'mInline',
|
2008-12-31 03:31:41 +00:00
|
|
|
'prefix' => 'mPrefix',
|
2012-09-02 13:50:42 +00:00
|
|
|
'dir' => 'mDir',
|
2017-08-24 19:45:31 +00:00
|
|
|
'searchfilter' => 'mSearchFilter',
|
2020-01-22 22:58:00 +00:00
|
|
|
'tour' => 'mTour',
|
|
|
|
'arialabel' => 'mTextBoxAriaLabel'
|
2017-05-18 18:09:49 +00:00
|
|
|
];
|
2017-11-21 04:01:57 +00:00
|
|
|
// Options we should maybe run through lang converter.
|
|
|
|
$convertOptions = [
|
|
|
|
'default' => true,
|
|
|
|
'buttonlabel' => true,
|
|
|
|
'searchbuttonlabel' => true,
|
2020-01-22 22:58:00 +00:00
|
|
|
'placeholder' => true,
|
|
|
|
'arialabel' => true
|
2017-11-21 04:01:57 +00:00
|
|
|
];
|
2008-10-27 20:56:23 +00:00
|
|
|
foreach ( $options as $name => $var ) {
|
|
|
|
if ( isset( $values[$name] ) ) {
|
2008-11-13 08:50:13 +00:00
|
|
|
$this->$var = $values[$name];
|
2017-11-21 04:01:57 +00:00
|
|
|
if ( isset( $convertOptions[$name] ) ) {
|
|
|
|
$this->$var = $this->languageConvert( $this->$var );
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-01 13:29:46 +00:00
|
|
|
|
2008-10-27 20:33:18 +00:00
|
|
|
// Insert a line break if configured to do so
|
2021-10-16 20:10:22 +00:00
|
|
|
$this->mBR = ( strtolower( $this->mBR ) === 'no' ) ? ' ' : '<br />';
|
2008-10-27 20:33:18 +00:00
|
|
|
|
|
|
|
// Validate the width; make sure it's a valid, positive integer
|
2008-10-27 21:35:00 +00:00
|
|
|
$this->mWidth = intval( $this->mWidth <= 0 ? 50 : $this->mWidth );
|
2009-01-01 13:29:46 +00:00
|
|
|
|
2010-03-30 03:59:15 +00:00
|
|
|
// Validate background color
|
|
|
|
if ( !$this->isValidColor( $this->mBGColor ) ) {
|
|
|
|
$this->mBGColor = 'transparent';
|
|
|
|
}
|
2021-12-15 10:50:10 +00:00
|
|
|
|
|
|
|
// T297725: De-obfuscate attempts to trick people into making edits to .js pages
|
|
|
|
$target = $this->mType === 'commenttitle' ? $this->mPage : $this->mDefaultText;
|
|
|
|
if ( $this->mHidden && $this->mPreload && substr( $target, -3 ) === '.js' ) {
|
2022-11-11 06:58:42 +00:00
|
|
|
$this->mHidden = null;
|
2021-12-15 10:50:10 +00:00
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 03:59:15 +00:00
|
|
|
/**
|
|
|
|
* Do a security check on the bgcolor parameter
|
2017-10-14 13:45:46 +00:00
|
|
|
* @param string $color
|
|
|
|
* @return bool
|
2010-03-30 03:59:15 +00:00
|
|
|
*/
|
|
|
|
public function isValidColor( $color ) {
|
|
|
|
$regex = <<<REGEX
|
|
|
|
/^ (
|
|
|
|
[a-zA-Z]* | # color names
|
|
|
|
\# [0-9a-f]{3} | # short hexadecimal
|
|
|
|
\# [0-9a-f]{6} | # long hexadecimal
|
|
|
|
rgb \s* \( \s* (
|
|
|
|
\d+ \s* , \s* \d+ \s* , \s* \d+ | # rgb integer
|
|
|
|
[0-9.]+% \s* , \s* [0-9.]+% \s* , \s* [0-9.]+% # rgb percent
|
|
|
|
) \s* \)
|
|
|
|
) $ /xi
|
|
|
|
REGEX;
|
2017-06-20 07:09:00 +00:00
|
|
|
return (bool)preg_match( $regex, $color );
|
2010-03-30 03:59:15 +00:00
|
|
|
}
|
2014-05-18 09:51:07 +00:00
|
|
|
|
2020-01-22 22:58:00 +00:00
|
|
|
/**
|
|
|
|
* Factory method to help build the textbox widget
|
|
|
|
* @param array $defaultAttr
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function buildTextBox( $defaultAttr ) {
|
|
|
|
if ( $this->mTextBoxAriaLabel ) {
|
|
|
|
$defaultAttr[ 'aria-label' ] = $this->mTextBoxAriaLabel;
|
|
|
|
}
|
|
|
|
|
2021-05-21 02:03:06 +00:00
|
|
|
return Html::openElement( 'input', $defaultAttr );
|
2020-01-22 22:58:00 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 09:51:07 +00:00
|
|
|
private function bgColorStyle() {
|
2021-10-16 20:10:22 +00:00
|
|
|
if ( $this->mBGColor !== 'transparent' ) {
|
2014-05-18 09:51:07 +00:00
|
|
|
return 'background-color: ' . $this->mBGColor . ';';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2016-10-04 20:24:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2017-11-21 04:01:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For compatability with pre T119158 behaviour
|
|
|
|
*
|
|
|
|
* If a field that is going to be used as an attribute
|
|
|
|
* and it contains "-{" in it, run it through language
|
|
|
|
* converter.
|
|
|
|
*
|
|
|
|
* Its not really clear if it would make more sense to
|
|
|
|
* always convert instead of only if -{ is present. This
|
|
|
|
* function just more or less restores the previous
|
|
|
|
* accidental behaviour.
|
|
|
|
*
|
|
|
|
* @see https://phabricator.wikimedia.org/T180485
|
2019-03-15 21:58:39 +00:00
|
|
|
* @param string $text
|
|
|
|
* @return string
|
2017-11-21 04:01:57 +00:00
|
|
|
*/
|
|
|
|
private function languageConvert( $text ) {
|
2021-11-02 12:30:19 +00:00
|
|
|
$langConv = $this->mParser->getTargetLanguageConverter();
|
2021-02-27 14:19:26 +00:00
|
|
|
if ( $langConv->hasVariants() && strpos( $text, '-{' ) !== false ) {
|
|
|
|
$text = $langConv->convert( $text );
|
2017-11-21 04:01:57 +00:00
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|