From 71c36e9046cd7747ae07cefd3bbbe90391e3bc37 Mon Sep 17 00:00:00 2001 From: John Du Hart Date: Tue, 24 Jan 2012 21:34:26 +0000 Subject: [PATCH] Add HTMLFormFields for namespaces and restriction levels. This is not a 1.19 feature and should be reverted post-branch. --- includes/HTMLForm.php | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index 41a12c1d22..ccdd44afea 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -72,6 +72,8 @@ class HTMLForm extends ContextSource { 'submit' => 'HTMLSubmitField', 'hidden' => 'HTMLHiddenField', 'edittools' => 'HTMLEditTools', + 'namespaces' => 'HTMLNamespacesField', + 'restrictionlevels' => 'HTMLRestrictionLevelsField', // HTMLTextField will output the correct type="" attribute automagically. // There are about four zillion other HTML5 input types, like url, but @@ -2000,3 +2002,99 @@ class HTMLEditTools extends HTMLFormField { . "\n"; } } + +/** + * Dropdown for namespaces + * + * @since 1.20 + */ +class HTMLNamespacesField extends HTMLSelectField { + + /** + * Constructor, adds the namespaces to the options + * + * @param $params + */ + function __construct( $params ) { + global $wgContLang; + parent::__construct( $params ); + + $namespaces = $wgContLang->getFormattedNamespaces(); + + $options = array(); + $options[ wfMessage( 'namespacesall' )->escaped() ] = ''; // TODO: Make an option + + foreach ( $namespaces as $index => $name ) { + // Don't include things like SpecialPages + if ( $index < NS_MAIN ) { + continue; + } + + if ( $index === 0 ) { + $name = wfMessage( 'blanknamespace' )->escaped(); + } + + $options[$name] = $index; + } + + $this->mParams['options'] = $options; + } +} + +/** + * Dropdown for protection levels + * + * @since 1.20 + */ +class HTMLRestrictionLevelsField extends HTMLSelectField { + + /** + * Should this field be displayed? If it hits a condition where it should + * be hidden, set this to false. + * + * @var bool + */ + protected $enabled = true; + + /** + * Constructor, adds the restrictions to the options + * + * @param $params + */ + function __construct( $params ) { + global $wgRestrictionLevels; + parent::__construct( $params ); + + $options = array( wfMsg('restriction-level-all') => 0 ); // Temporary array + + // First pass to load the level names + foreach( $wgRestrictionLevels as $type ) { + if ( $type != '' && $type != '*' ) { + $text = wfMsg("restriction-level-$type"); + $options[$text] = $type; + } + } + + // Is there only one level (aside from "all")? + if( count($options) <= 2 ) { + $this->enabled = false; + return; + } + + $this->mParams['options'] = $options; + } + + /** + * Returns nothing if there are no restrictions to show + * + * @param $value + * @return String + */ + function getTableRow( $value ) { + if ( $this->enabled ) { + return parent::getTableRow( $value ); + } + + return ''; + } +} \ No newline at end of file -- 2.20.1