Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -72,6 +72,8 @@ |
73 | 73 | 'submit' => 'HTMLSubmitField', |
74 | 74 | 'hidden' => 'HTMLHiddenField', |
75 | 75 | 'edittools' => 'HTMLEditTools', |
| 76 | + 'namespaces' => 'HTMLNamespacesField', |
| 77 | + 'restrictionlevels' => 'HTMLRestrictionLevelsField', |
76 | 78 | |
77 | 79 | // HTMLTextField will output the correct type="" attribute automagically. |
78 | 80 | // There are about four zillion other HTML5 input types, like url, but |
— | — | @@ -2000,3 +2002,99 @@ |
2001 | 2003 | . "</div></td></tr>\n"; |
2002 | 2004 | } |
2003 | 2005 | } |
| 2006 | + |
| 2007 | +/** |
| 2008 | + * Dropdown for namespaces |
| 2009 | + * |
| 2010 | + * @since 1.20 |
| 2011 | + */ |
| 2012 | +class HTMLNamespacesField extends HTMLSelectField { |
| 2013 | + |
| 2014 | + /** |
| 2015 | + * Constructor, adds the namespaces to the options |
| 2016 | + * |
| 2017 | + * @param $params |
| 2018 | + */ |
| 2019 | + function __construct( $params ) { |
| 2020 | + global $wgContLang; |
| 2021 | + parent::__construct( $params ); |
| 2022 | + |
| 2023 | + $namespaces = $wgContLang->getFormattedNamespaces(); |
| 2024 | + |
| 2025 | + $options = array(); |
| 2026 | + $options[ wfMessage( 'namespacesall' )->escaped() ] = ''; // TODO: Make an option |
| 2027 | + |
| 2028 | + foreach ( $namespaces as $index => $name ) { |
| 2029 | + // Don't include things like SpecialPages |
| 2030 | + if ( $index < NS_MAIN ) { |
| 2031 | + continue; |
| 2032 | + } |
| 2033 | + |
| 2034 | + if ( $index === 0 ) { |
| 2035 | + $name = wfMessage( 'blanknamespace' )->escaped(); |
| 2036 | + } |
| 2037 | + |
| 2038 | + $options[$name] = $index; |
| 2039 | + } |
| 2040 | + |
| 2041 | + $this->mParams['options'] = $options; |
| 2042 | + } |
| 2043 | +} |
| 2044 | + |
| 2045 | +/** |
| 2046 | + * Dropdown for protection levels |
| 2047 | + * |
| 2048 | + * @since 1.20 |
| 2049 | + */ |
| 2050 | +class HTMLRestrictionLevelsField extends HTMLSelectField { |
| 2051 | + |
| 2052 | + /** |
| 2053 | + * Should this field be displayed? If it hits a condition where it should |
| 2054 | + * be hidden, set this to false. |
| 2055 | + * |
| 2056 | + * @var bool |
| 2057 | + */ |
| 2058 | + protected $enabled = true; |
| 2059 | + |
| 2060 | + /** |
| 2061 | + * Constructor, adds the restrictions to the options |
| 2062 | + * |
| 2063 | + * @param $params |
| 2064 | + */ |
| 2065 | + function __construct( $params ) { |
| 2066 | + global $wgRestrictionLevels; |
| 2067 | + parent::__construct( $params ); |
| 2068 | + |
| 2069 | + $options = array( wfMsg('restriction-level-all') => 0 ); // Temporary array |
| 2070 | + |
| 2071 | + // First pass to load the level names |
| 2072 | + foreach( $wgRestrictionLevels as $type ) { |
| 2073 | + if ( $type != '' && $type != '*' ) { |
| 2074 | + $text = wfMsg("restriction-level-$type"); |
| 2075 | + $options[$text] = $type; |
| 2076 | + } |
| 2077 | + } |
| 2078 | + |
| 2079 | + // Is there only one level (aside from "all")? |
| 2080 | + if( count($options) <= 2 ) { |
| 2081 | + $this->enabled = false; |
| 2082 | + return; |
| 2083 | + } |
| 2084 | + |
| 2085 | + $this->mParams['options'] = $options; |
| 2086 | + } |
| 2087 | + |
| 2088 | + /** |
| 2089 | + * Returns nothing if there are no restrictions to show |
| 2090 | + * |
| 2091 | + * @param $value |
| 2092 | + * @return String |
| 2093 | + */ |
| 2094 | + function getTableRow( $value ) { |
| 2095 | + if ( $this->enabled ) { |
| 2096 | + return parent::getTableRow( $value ); |
| 2097 | + } |
| 2098 | + |
| 2099 | + return ''; |
| 2100 | + } |
| 2101 | +} |
\ No newline at end of file |