OOUIHTMLForm: Implement HTMLSelectNamespace
* Extracted some common code between this and Html::namespaceSelector into a new method Html::namespaceSelectorOptions(). Change-Id: I5e97e5c661582f726153533ad00695b450caed46
This commit is contained in:
parent
b524a4333f
commit
53b012ce2a
2 changed files with 68 additions and 28 deletions
|
|
@ -822,6 +822,47 @@ class Html {
|
|||
return self::element( 'textarea', self::getTextInputAttributes( $attribs ), $spacedValue );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for Html::namespaceSelector().
|
||||
* @param array $params See Html::namespaceSelector()
|
||||
* @return array
|
||||
*/
|
||||
public static function namespaceSelectorOptions( array $params = array() ) {
|
||||
global $wgContLang;
|
||||
|
||||
$options = array();
|
||||
|
||||
if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
|
||||
$params['exclude'] = array();
|
||||
}
|
||||
|
||||
if ( isset( $params['all'] ) ) {
|
||||
// add an option that would let the user select all namespaces.
|
||||
// Value is provided by user, the name shown is localized for the user.
|
||||
$options[$params['all']] = wfMessage( 'namespacesall' )->text();
|
||||
}
|
||||
// Add all namespaces as options (in the content language)
|
||||
$options += $wgContLang->getFormattedNamespaces();
|
||||
|
||||
$optionsOut = array();
|
||||
// Filter out namespaces below 0 and massage labels
|
||||
foreach ( $options as $nsId => $nsName ) {
|
||||
if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( $nsId === NS_MAIN ) {
|
||||
// For other namespaces use the namespace prefix as label, but for
|
||||
// main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
|
||||
$nsName = wfMessage( 'blanknamespace' )->text();
|
||||
} elseif ( is_int( $nsId ) ) {
|
||||
$nsName = $wgContLang->convertNamespace( $nsId );
|
||||
}
|
||||
$optionsOut[ $nsId ] = $nsName;
|
||||
}
|
||||
|
||||
return $optionsOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a drop-down box for selecting a namespace
|
||||
*
|
||||
|
|
@ -841,8 +882,6 @@ class Html {
|
|||
public static function namespaceSelector( array $params = array(),
|
||||
array $selectAttribs = array()
|
||||
) {
|
||||
global $wgContLang;
|
||||
|
||||
ksort( $selectAttribs );
|
||||
|
||||
// Is a namespace selected?
|
||||
|
|
@ -859,37 +898,16 @@ class Html {
|
|||
$params['selected'] = '';
|
||||
}
|
||||
|
||||
if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
|
||||
$params['exclude'] = array();
|
||||
}
|
||||
if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
|
||||
$params['disable'] = array();
|
||||
}
|
||||
|
||||
// Associative array between option-values and option-labels
|
||||
$options = array();
|
||||
$options = self::namespaceSelectorOptions( $params );
|
||||
|
||||
if ( isset( $params['all'] ) ) {
|
||||
// add an option that would let the user select all namespaces.
|
||||
// Value is provided by user, the name shown is localized for the user.
|
||||
$options[$params['all']] = wfMessage( 'namespacesall' )->text();
|
||||
}
|
||||
// Add all namespaces as options (in the content language)
|
||||
$options += $wgContLang->getFormattedNamespaces();
|
||||
|
||||
// Convert $options to HTML and filter out namespaces below 0
|
||||
// Convert $options to HTML
|
||||
$optionsHtml = array();
|
||||
foreach ( $options as $nsId => $nsName ) {
|
||||
if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( $nsId === NS_MAIN ) {
|
||||
// For other namespaces use the namespace prefix as label, but for
|
||||
// main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
|
||||
$nsName = wfMessage( 'blanknamespace' )->text();
|
||||
} elseif ( is_int( $nsId ) ) {
|
||||
$nsName = $wgContLang->convertNamespace( $nsId );
|
||||
}
|
||||
$optionsHtml[] = self::element(
|
||||
'option', array(
|
||||
'disabled' => in_array( $nsId, $params['disable'] ),
|
||||
|
|
|
|||
|
|
@ -3,13 +3,16 @@
|
|||
* Wrapper for Html::namespaceSelector to use in HTMLForm
|
||||
*/
|
||||
class HTMLSelectNamespace extends HTMLFormField {
|
||||
function getInputHTML( $value ) {
|
||||
$allValue = ( isset( $this->mParams['all'] ) ? $this->mParams['all'] : 'all' );
|
||||
public function __construct( $params ) {
|
||||
parent::__construct( $params );
|
||||
$this->mAllValue = isset( $this->mParams['all'] ) ? $this->mParams['all'] : 'all';
|
||||
}
|
||||
|
||||
function getInputHTML( $value ) {
|
||||
return Html::namespaceSelector(
|
||||
array(
|
||||
'selected' => $value,
|
||||
'all' => $allValue
|
||||
'all' => $this->mAllValue
|
||||
), array(
|
||||
'name' => $this->mName,
|
||||
'id' => $this->mID,
|
||||
|
|
@ -17,4 +20,23 @@ class HTMLSelectNamespace extends HTMLFormField {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getInputOOUI( $value ) {
|
||||
$namespaceOptions = Html::namespaceSelectorOptions( array( 'all' => $this->mAllValue ) );
|
||||
|
||||
$options = array();
|
||||
foreach( $namespaceOptions as $id => $name ) {
|
||||
$options[] = array(
|
||||
'data' => (string)$id,
|
||||
'label' => $name,
|
||||
);
|
||||
};
|
||||
|
||||
return new OOUI\DropdownInputWidget( array(
|
||||
'options' => $options,
|
||||
'value' => $value,
|
||||
'name' => $this->mName,
|
||||
'id' => $this->mID,
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue