Add HTMLFormFields for namespaces and restriction levels. This is not a 1.19 feature...
authorJohn Du Hart <johnduhart@users.mediawiki.org>
Tue, 24 Jan 2012 21:34:26 +0000 (21:34 +0000)
committerJohn Du Hart <johnduhart@users.mediawiki.org>
Tue, 24 Jan 2012 21:34:26 +0000 (21:34 +0000)
includes/HTMLForm.php

index 41a12c1..ccdd44a 100644 (file)
@@ -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 {
                        . "</div></td></tr>\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