2008-10-27 20:33:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Classes for InputBox extension
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2008-10-27 21:35:00 +00:00
|
|
|
private $mParser;
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mType = '';
|
|
|
|
private $mWidth = 50;
|
2016-10-04 20:24:54 +00:00
|
|
|
private $mPreload = null;
|
|
|
|
private $mPreloadparams = null;
|
|
|
|
private $mEditIntro = null;
|
|
|
|
private $mUseVE = null;
|
|
|
|
private $mSummary = null;
|
|
|
|
private $mNosummary = null;
|
|
|
|
private $mMinor = null;
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mPage = '';
|
|
|
|
private $mBR = 'yes';
|
|
|
|
private $mDefaultText = '';
|
2011-10-26 20:31:20 +00:00
|
|
|
private $mPlaceholderText = '';
|
2008-11-13 08:50:13 +00:00
|
|
|
private $mBGColor = 'transparent';
|
|
|
|
private $mButtonLabel = '';
|
|
|
|
private $mSearchButtonLabel = '';
|
|
|
|
private $mFullTextButton = '';
|
|
|
|
private $mLabelText = '';
|
|
|
|
private $mHidden = '';
|
|
|
|
private $mNamespaces = '';
|
|
|
|
private $mID = '';
|
|
|
|
private $mInline = false;
|
2008-12-31 03:31:41 +00:00
|
|
|
private $mPrefix = '';
|
2012-09-02 13:50:42 +00:00
|
|
|
private $mDir = '';
|
2017-06-06 18:45:30 +00:00
|
|
|
private $mSearchFilter = '';
|
2017-08-24 19:45:31 +00:00
|
|
|
private $mTour = '';
|
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':
|
2014-03-24 06:08:56 +00:00
|
|
|
$this->mParser->getOutput()->addModules( 'ext.inputBox' );
|
2008-10-27 20:33:18 +00:00
|
|
|
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:
|
|
|
|
return Xml::tags( 'div', null,
|
|
|
|
Xml::element( 'strong',
|
2017-05-18 18:09:49 +00:00
|
|
|
[ 'class' => 'error' ],
|
2008-10-28 01:56:15 +00:00
|
|
|
strlen( $this->mType ) > 0
|
2017-05-18 18:09:49 +00:00
|
|
|
? wfMessage( 'inputbox-error-bad-type', $this->mType )->text()
|
|
|
|
: wfMessage( 'inputbox-error-no-type' )->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).
|
|
|
|
*
|
|
|
|
* @return Array Array with name and value data
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
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 ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
global $wgContLang, $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
|
|
|
);
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2015-08-13 19:32:35 +00:00
|
|
|
'class' => $this->getLinebreakClasses() . 'searchboxInput mw-ui-input mw-ui-input-inline',
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'search',
|
2008-10-27 21:35:00 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'value' => $this->mDefaultText,
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => $this->mPlaceholderText,
|
2008-10-27 21:35:00 +00:00
|
|
|
'size' => $this->mWidth,
|
2012-09-02 13:50:42 +00:00
|
|
|
'dir' => $this->mDir,
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2011-06-17 16:26:31 +00:00
|
|
|
|
2014-05-18 09:07:27 +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
|
|
|
|
2017-06-06 18:45:30 +00:00
|
|
|
if ( $this->mSearchFilter != '' ) {
|
|
|
|
$htmlOut .= Html::hidden( 'searchfilter', $this->mSearchFilter );
|
|
|
|
}
|
|
|
|
|
2017-08-24 19:45:31 +00:00
|
|
|
if ( $this->mTour != '' ) {
|
|
|
|
$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 ) {
|
2011-07-14 03:51:10 +00:00
|
|
|
$namespaces = $wgContLang->getNamespaces();
|
|
|
|
$nsAliases = array_merge( $wgContLang->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 ) {
|
2017-05-18 18:09:49 +00:00
|
|
|
$userNS = trim( $userNS ); // no whitespace
|
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();
|
2014-05-18 09:07:27 +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 {
|
2017-05-18 18:09:49 +00:00
|
|
|
continue; // Namespace not recognized, skip
|
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
|
|
|
|
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
|
|
|
|
2011-07-14 03:51:10 +00:00
|
|
|
if ( count( $showNamespaces ) == 1 ) {
|
|
|
|
// 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;
|
2014-05-18 09:07:27 +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
|
|
|
);
|
2010-05-30 17:33:59 +00:00
|
|
|
$htmlOut .= ' ';
|
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)
|
2014-05-18 09:07:27 +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;
|
|
|
|
$htmlOut .= Xml::element( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 21:35:00 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'search',
|
2015-02-23 08:45:05 +00:00
|
|
|
'class' => 'mw-ui-input mw-ui-input-inline',
|
2008-10-27 21:35:00 +00:00
|
|
|
'size' => $this->mWidth,
|
2012-09-02 13:50:42 +00:00
|
|
|
'id' => 'bodySearchInput' . $id,
|
|
|
|
'dir' => $this->mDir,
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
2015-02-23 08:45:05 +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' => '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
|
|
|
|
2008-10-27 21:35:00 +00:00
|
|
|
if ( $this->mType == "comment" ) {
|
|
|
|
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
|
|
|
}
|
2008-10-27 21:35:00 +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
|
|
|
}
|
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-10-27 21:35:00 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
2008-10-27 20:33:18 +00:00
|
|
|
'name' => 'title',
|
2015-08-13 19:32:35 +00:00
|
|
|
'class' => $this->getLinebreakClasses() .
|
2015-04-25 23:40:14 +00:00
|
|
|
'mw-ui-input mw-ui-input-inline createboxInput',
|
2008-10-27 21:35:00 +00:00
|
|
|
'value' => $this->mDefaultText,
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => $this->mPlaceholderText,
|
2012-09-02 13:50:42 +00:00
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir,
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-27 20:33:18 +00:00
|
|
|
);
|
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',
|
2015-03-13 10:36:53 +00:00
|
|
|
'class' => 'mw-ui-button mw-ui-progressive createboxButton',
|
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 );
|
2014-04-05 20:43:15 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2014-04-05 20:43:15 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
|
|
|
'name' => 'wpNewTitle',
|
2015-08-13 19:32:35 +00:00
|
|
|
'class' => $this->getLinebreakClasses() . 'mw-moveboxInput mw-ui-input mw-ui-input-inline',
|
2014-04-05 20:43:15 +00:00
|
|
|
'value' => $this->mDefaultText,
|
|
|
|
'placeholder' => $this->mPlaceholderText,
|
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir,
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
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
|
|
|
}
|
2008-10-28 00:08:08 +00:00
|
|
|
$htmlOut .= Xml::openElement( 'input',
|
2017-05-18 18:09:49 +00:00
|
|
|
[
|
2008-11-17 21:54:38 +00:00
|
|
|
'type' => $this->mHidden ? 'hidden' : 'text',
|
2008-10-28 00:08:08 +00:00
|
|
|
'name' => 'preloadtitle',
|
2015-08-13 19:32:35 +00:00
|
|
|
'class' => $this->getLinebreakClasses() . 'commentboxInput mw-ui-input mw-ui-input-inline',
|
2008-10-28 00:08:08 +00:00
|
|
|
'value' => $this->mDefaultText,
|
2011-10-26 20:31:20 +00:00
|
|
|
'placeholder' => $this->mPlaceholderText,
|
2012-09-02 13:50:42 +00:00
|
|
|
'size' => $this->mWidth,
|
|
|
|
'dir' => $this->mDir,
|
2017-05-18 18:09:49 +00:00
|
|
|
]
|
2008-10-28 00:08:08 +00:00
|
|
|
);
|
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 ) );
|
|
|
|
if ( $name == 'preloadparams[]' ) {
|
|
|
|
// 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',
|
|
|
|
'tour' => 'mTour'
|
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,
|
|
|
|
'placeholder' => true
|
|
|
|
];
|
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
|
2009-01-01 13:29:46 +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';
|
|
|
|
}
|
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
|
|
|
|
|
|
|
private function bgColorStyle() {
|
|
|
|
if ( $this->mBGColor != 'transparent' ) {
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
private function languageConvert( $text ) {
|
|
|
|
$lang = $this->mParser->getConverterLanguage();
|
|
|
|
if ( $lang->hasVariants() && strpos( $text, '-{' ) !== false ) {
|
|
|
|
$text = $lang->convert( $text );
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
2008-10-27 20:33:18 +00:00
|
|
|
}
|