Viewing File: /home/omtekel/www/wp-content/upgrade/backup/fields.tar
HTMLSizeFilterField.php 0000666 00000004432 15133477043 0011004 0 ustar 00 <?php
use MediaWiki\Request\WebRequest;
/**
* A size filter field for use on query-type special pages. It looks a bit like:
*
* (o) Min size ( ) Max size: [ ] bytes
*
* Minimum size limits are represented using a positive integer, while maximum
* size limits are represented using a negative integer.
*
* @stable to extend
*
*/
class HTMLSizeFilterField extends HTMLIntField {
protected bool $mSelectMin = true;
public function getSize() {
return $this->mParams['size'] ?? 9;
}
public function getInputHTML( $value ) {
$attribs = [];
if ( !empty( $this->mParams['disabled'] ) ) {
$attribs['disabled'] = 'disabled';
}
$html = Xml::radioLabel(
$this->msg( 'minimum-size' )->text(),
$this->mName . '-mode',
'min',
$this->mID . '-mode-min',
$this->mSelectMin,
$attribs
);
$html .= "\u{00A0}" . Xml::radioLabel(
$this->msg( 'maximum-size' )->text(),
$this->mName . '-mode',
'max',
$this->mID . '-mode-max',
!$this->mSelectMin,
$attribs
);
$html .= "\u{00A0}" . parent::getInputHTML( $value ? abs( $value ) : '' );
$html .= "\u{00A0}" . $this->msg( 'pagesize' )->parse();
return $html;
}
/**
* @inheritDoc
* @stable to override
*/
protected function getInputWidget( $params ) {
$this->mParent->getOutput()->addModuleStyles( 'mediawiki.widgets.SizeFilterWidget.styles' );
// negative numbers represent "max", positive numbers represent "min"
$value = $params['value'];
$params['value'] = $value ? abs( $value ) : '';
return new MediaWiki\Widget\SizeFilterWidget( [
'selectMin' => $this->mSelectMin,
'textinput' => $params,
'radioselectinput' => [
'name' => $this->mName . '-mode',
'disabled' => !empty( $this->mParams['disabled'] ),
],
] );
}
protected function getOOUIModules() {
return [ 'mediawiki.widgets.SizeFilterWidget' ];
}
/**
* @param WebRequest $request
*
* @return int
*/
public function loadDataFromRequest( $request ) {
$size = abs( $request->getInt( $this->mName, $this->getDefault() ) );
// negative numbers represent "max", positive numbers represent "min"
if ( $request->getVal( $this->mName . '-mode' ) === 'max' ) {
$this->mSelectMin = false;
return -$size;
} else {
return $size;
}
}
protected function needsLabel() {
return false;
}
}
HTMLTagFilter.php 0000666 00000002512 15133477043 0007636 0 ustar 00 <?php
/**
* Wrapper for ChangeTags::buildTagFilterSelector to use in HTMLForm
*
* @stable to extend
*/
class HTMLTagFilter extends HTMLFormField {
protected $tagFilter;
public function getTableRow( $value ) {
$this->tagFilter = ChangeTags::buildTagFilterSelector(
$value, false, $this->mParent->getContext() );
if ( $this->tagFilter ) {
return parent::getTableRow( $value );
}
return '';
}
public function getDiv( $value ) {
$this->tagFilter = ChangeTags::buildTagFilterSelector(
$value, false, $this->mParent->getContext() );
if ( $this->tagFilter ) {
return parent::getDiv( $value );
}
return '';
}
public function getOOUI( $value ) {
$this->tagFilter = ChangeTags::buildTagFilterSelector(
$value, true, $this->mParent->getContext() );
if ( $this->tagFilter ) {
return parent::getOOUI( $value );
}
return new OOUI\FieldLayout( new OOUI\Widget() );
}
public function getInputHTML( $value ) {
if ( $this->tagFilter ) {
// we only need the select field, HTMLForm should handle the label
return $this->tagFilter[1];
}
return '';
}
public function getInputOOUI( $value ) {
if ( $this->tagFilter ) {
// we only need the select field, HTMLForm should handle the label
return $this->tagFilter[1];
}
return '';
}
protected function shouldInfuseOOUI() {
return true;
}
}
HTMLTagMultiselectField.php 0000666 00000007306 15133477043 0011655 0 ustar 00 <?php
use MediaWiki\Widget\TagMultiselectWidget;
/**
* Implements a tag multiselect input field for arbitrary values.
*
* Besides the parameters recognized by HTMLTextField, additional recognized
* parameters are:
* allowArbitrary - (optional) Bool to allow arbitrary inputs
* allowedValues - (optional) Array of allowed values
*
* The result is the array of tags
*
* @stable to extend
* @note This widget is not likely to remain functional in non-OOUI forms.
*/
class HTMLTagMultiselectField extends HTMLTextField {
public function loadDataFromRequest( $request ) {
$value = $request->getText( $this->mName, $this->getDefault() ?? '' );
$tagsArray = explode( "\n", $value );
// Remove empty lines
$tagsArray = array_values( array_filter( $tagsArray, static function ( $tag ) {
return trim( $tag ) !== '';
} ) );
// Remove any duplicate tags
$uniqueTags = array_unique( $tagsArray );
// This function is expected to return a string
return implode( "\n", $uniqueTags );
}
public function validate( $value, $alldata ) {
if ( $value === null ) {
return false;
}
// $value is a string, because HTMLForm fields store their values as strings
$tagsArray = explode( "\n", $value );
if ( isset( $this->mParams['max'] ) && ( count( $tagsArray ) > $this->mParams['max'] ) ) {
return $this->msg( 'htmlform-multiselect-toomany', $this->mParams['max'] );
}
foreach ( $tagsArray as $tag ) {
$result = parent::validate( $tag, $alldata );
if ( $result !== true ) {
return $result;
}
if ( empty( $this->mParams['allowArbitrary'] ) && $tag ) {
$allowedValues = $this->mParams['allowedValues'] ?? [];
if ( !in_array( $tag, $allowedValues ) ) {
return $this->msg( 'htmlform-tag-not-allowed', $tag )->escaped();
}
}
}
return true;
}
public function getInputHTML( $value ) {
$this->mParent->getOutput()->enableOOUI();
return $this->getInputOOUI( $value );
}
public function getInputOOUI( $value ) {
$this->mParent->getOutput()->addModuleStyles( 'mediawiki.widgets.TagMultiselectWidget.styles' );
$params = [ 'name' => $this->mName ];
if ( isset( $this->mParams['id'] ) ) {
$params['id'] = $this->mParams['id'];
}
if ( isset( $this->mParams['disabled'] ) ) {
$params['disabled'] = $this->mParams['disabled'];
}
if ( isset( $this->mParams['default'] ) ) {
$params['default'] = $this->mParams['default'];
}
$params['placeholder'] = $this->mParams['placeholder'] ??
$this->msg( 'mw-widgets-tagmultiselect-placeholder' )->plain();
if ( isset( $this->mParams['max'] ) ) {
$params['tagLimit'] = $this->mParams['max'];
}
if ( isset( $this->mParams['allowArbitrary'] ) ) {
$params['allowArbitrary'] = $this->mParams['allowArbitrary'];
}
if ( isset( $this->mParams['allowedValues'] ) ) {
$params['allowedValues'] = $this->mParams['allowedValues'];
}
if ( isset( $this->mParams['input'] ) ) {
$params['input'] = $this->mParams['input'];
}
if ( $value !== null ) {
// $value is a string, but the widget expects an array
$params['default'] = $value === '' ? [] : explode( "\n", $value );
}
// Make the field auto-infusable when it's used inside a legacy HTMLForm rather than OOUIHTMLForm
$params['infusable'] = true;
$params['classes'] = [ 'mw-htmlform-autoinfuse' ];
return $this->getInputWidget( $params );
}
/**
* @inheritDoc
*/
protected function getInputWidget( $params ) {
$widget = new TagMultiselectWidget( $params );
$widget->setAttributes( [ 'data-mw-modules' => implode( ',', $this->getOOUIModules() ) ] );
return $widget;
}
protected function shouldInfuseOOUI() {
return true;
}
protected function getOOUIModules() {
return [ 'mediawiki.widgets.TagMultiselectWidget' ];
}
}
Back to Directory
File Manager