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 |
— | — | @@ -854,6 +856,16 @@ |
855 | 857 | public function getFlatFields() { |
856 | 858 | return $this->mFlatFields; |
857 | 859 | } |
| 860 | + |
| 861 | + /** |
| 862 | + * Returns a value of a field |
| 863 | + * |
| 864 | + * @param $field string Field name |
| 865 | + * @return mixed |
| 866 | + */ |
| 867 | + public function getVal( $field ) { |
| 868 | + return $this->mFieldData[$field]; |
| 869 | + } |
858 | 870 | } |
859 | 871 | |
860 | 872 | /** |
— | — | @@ -2004,3 +2016,84 @@ |
2005 | 2017 | . "</div></td></tr>\n"; |
2006 | 2018 | } |
2007 | 2019 | } |
| 2020 | + |
| 2021 | +/** |
| 2022 | + * Dropdown for namespaces |
| 2023 | + */ |
| 2024 | +class HTMLNamespacesField extends HTMLSelectField { |
| 2025 | + function __construct( $params ) { |
| 2026 | + global $wgContLang; |
| 2027 | + parent::__construct( $params ); |
| 2028 | + |
| 2029 | + $namespaces = $wgContLang->getFormattedNamespaces(); |
| 2030 | + |
| 2031 | + $options = array(); |
| 2032 | + $options[ wfMessage( 'namespacesall' )->escaped() ] = ''; // TODO: Make an option |
| 2033 | + |
| 2034 | + foreach ( $namespaces as $index => $name ) { |
| 2035 | + // Don't include things like SpecialPages |
| 2036 | + if ( $index < NS_MAIN ) { |
| 2037 | + continue; |
| 2038 | + } |
| 2039 | + |
| 2040 | + if ( $index === 0 ) { |
| 2041 | + $name = wfMessage( 'blanknamespace' )->escaped(); |
| 2042 | + } |
| 2043 | + |
| 2044 | + $options[$name] = $index; |
| 2045 | + } |
| 2046 | + |
| 2047 | + $this->mParams['options'] = $options; |
| 2048 | + } |
| 2049 | +} |
| 2050 | + |
| 2051 | +/** |
| 2052 | + * Dropdown for protection levels |
| 2053 | + */ |
| 2054 | +class HTMLRestrictionLevelsField extends HTMLSelectField { |
| 2055 | + |
| 2056 | + /** |
| 2057 | + * Should this field be displayed? If it hits a condition where it should |
| 2058 | + * be hidden, set this to false. |
| 2059 | + * |
| 2060 | + * @var bool |
| 2061 | + */ |
| 2062 | + protected $enabled = true; |
| 2063 | + |
| 2064 | + function __construct( $params ) { |
| 2065 | + global $wgRestrictionLevels; |
| 2066 | + parent::__construct( $params ); |
| 2067 | + |
| 2068 | + $options = array( wfMsg('restriction-level-all') => 0 ); // Temporary array |
| 2069 | + |
| 2070 | + // First pass to load the level names |
| 2071 | + foreach( $wgRestrictionLevels as $type ) { |
| 2072 | + if ( $type != '' && $type != '*' ) { |
| 2073 | + $text = wfMsg("restriction-level-$type"); |
| 2074 | + $options[$text] = $type; |
| 2075 | + } |
| 2076 | + } |
| 2077 | + |
| 2078 | + // Is there only one level (aside from "all")? |
| 2079 | + if( count($options) <= 2 ) { |
| 2080 | + $this->enabled = false; |
| 2081 | + return; |
| 2082 | + } |
| 2083 | + |
| 2084 | + $this->mParams['options'] = $options; |
| 2085 | + } |
| 2086 | + |
| 2087 | + /** |
| 2088 | + * Returns false where |
| 2089 | + * |
| 2090 | + * @param $value |
| 2091 | + * @return String |
| 2092 | + */ |
| 2093 | + function getTableRow( $value ) { |
| 2094 | + if ( $this->enabled ) { |
| 2095 | + return parent::getTableRow( $value ); |
| 2096 | + } |
| 2097 | + |
| 2098 | + return ''; |
| 2099 | + } |
| 2100 | +} |
\ No newline at end of file |
Index: trunk/phase3/includes/specials/SpecialProtectedtitles.php |
— | — | @@ -28,9 +28,6 @@ |
29 | 29 | */ |
30 | 30 | class SpecialProtectedtitles extends SpecialPage { |
31 | 31 | |
32 | | - protected $IdLevel = 'level'; |
33 | | - protected $IdType = 'type'; |
34 | | - |
35 | 32 | public function __construct() { |
36 | 33 | parent::__construct( 'Protectedtitles' ); |
37 | 34 | } |
— | — | @@ -44,17 +41,9 @@ |
45 | 42 | Title::purgeExpiredRestrictions(); |
46 | 43 | } |
47 | 44 | |
48 | | - $request = $this->getRequest(); |
49 | | - $type = $request->getVal( $this->IdType ); |
50 | | - $level = $request->getVal( $this->IdLevel ); |
51 | | - $sizetype = $request->getVal( 'sizetype' ); |
52 | | - $size = $request->getIntOrNull( 'size' ); |
53 | | - $NS = $request->getIntOrNull( 'namespace' ); |
| 45 | + $pager = new ProtectedTitlesPager( $this ); |
| 46 | + $this->getOutput()->addHTML( $pager->buildHTMLForm() ); |
54 | 47 | |
55 | | - $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size ); |
56 | | - |
57 | | - $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) ); |
58 | | - |
59 | 48 | if ( $pager->getNumRows() ) { |
60 | 49 | $s = $pager->getNavigationBar(); |
61 | 50 | $s .= "<ul>" . |
— | — | @@ -70,6 +59,7 @@ |
71 | 60 | /** |
72 | 61 | * Callback function to output a restriction |
73 | 62 | * |
| 63 | + * @param $row |
74 | 64 | * @return string |
75 | 65 | */ |
76 | 66 | function formatRow( $row ) { |
— | — | @@ -107,89 +97,30 @@ |
108 | 98 | |
109 | 99 | return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n"; |
110 | 100 | } |
| 101 | +} |
111 | 102 | |
| 103 | +/** |
| 104 | + * @todo document |
| 105 | + * @ingroup Pager |
| 106 | + */ |
| 107 | +class ProtectedTitlesPager extends AlphabeticPager { |
112 | 108 | /** |
113 | | - * @param $namespace Integer: |
114 | | - * @param $type string |
115 | | - * @param $level string |
116 | | - * @private |
| 109 | + * @var SpecialProtectedtitles |
117 | 110 | */ |
118 | | - function showOptions( $namespace, $type='edit', $level ) { |
119 | | - global $wgScript; |
120 | | - $action = htmlspecialchars( $wgScript ); |
121 | | - $title = $this->getTitle(); |
122 | | - $special = htmlspecialchars( $title->getPrefixedDBkey() ); |
123 | | - return "<form action=\"$action\" method=\"get\">\n" . |
124 | | - '<fieldset>' . |
125 | | - Xml::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) . |
126 | | - Html::hidden( 'title', $special ) . " \n" . |
127 | | - $this->getNamespaceMenu( $namespace ) . " \n" . |
128 | | - $this->getLevelMenu( $level ) . " \n" . |
129 | | - " " . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" . |
130 | | - "</fieldset></form>"; |
131 | | - } |
| 111 | + public $mForm; |
132 | 112 | |
133 | 113 | /** |
134 | | - * Prepare the namespace filter drop-down; standard namespace |
135 | | - * selector, sans the MediaWiki namespace |
136 | | - * |
137 | | - * @param $namespace Mixed: pre-select namespace |
138 | | - * @return string |
| 114 | + * @var array |
139 | 115 | */ |
140 | | - function getNamespaceMenu( $namespace = null ) { |
141 | | - return Xml::label( wfMsg( 'namespace' ), 'namespace' ) |
142 | | - . ' ' |
143 | | - . Xml::namespaceSelector( $namespace, '' ); |
144 | | - } |
| 116 | + public $mConds; |
145 | 117 | |
146 | 118 | /** |
147 | | - * @return string Formatted HTML |
148 | | - * @private |
| 119 | + * @param $form SpecialProtectedtitles |
| 120 | + * @param $conds array |
149 | 121 | */ |
150 | | - function getLevelMenu( $pr_level ) { |
151 | | - global $wgRestrictionLevels; |
152 | | - |
153 | | - $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array |
154 | | - $options = array(); |
155 | | - |
156 | | - // First pass to load the log names |
157 | | - foreach( $wgRestrictionLevels as $type ) { |
158 | | - if ( $type !='' && $type !='*') { |
159 | | - $text = wfMsg("restriction-level-$type"); |
160 | | - $m[$text] = $type; |
161 | | - } |
162 | | - } |
163 | | - // Is there only one level (aside from "all")? |
164 | | - if( count($m) <= 2 ) { |
165 | | - return ''; |
166 | | - } |
167 | | - // Third pass generates sorted XHTML content |
168 | | - foreach( $m as $text => $type ) { |
169 | | - $selected = ($type == $pr_level ); |
170 | | - $options[] = Xml::option( $text, $type, $selected ); |
171 | | - } |
172 | | - |
173 | | - return |
174 | | - Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . ' ' . |
175 | | - Xml::tags( 'select', |
176 | | - array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ), |
177 | | - implode( "\n", $options ) ); |
178 | | - } |
179 | | -} |
180 | | - |
181 | | -/** |
182 | | - * @todo document |
183 | | - * @ingroup Pager |
184 | | - */ |
185 | | -class ProtectedTitlesPager extends AlphabeticPager { |
186 | | - public $mForm, $mConds; |
187 | | - |
188 | | - function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) { |
| 122 | + function __construct( $form, $conds = array() ) { |
189 | 123 | $this->mForm = $form; |
190 | 124 | $this->mConds = $conds; |
191 | | - $this->level = $level; |
192 | | - $this->namespace = $namespace; |
193 | | - $this->size = intval($size); |
194 | 125 | parent::__construct( $form->getContext() ); |
195 | 126 | } |
196 | 127 | |
— | — | @@ -225,10 +156,14 @@ |
226 | 157 | function getQueryInfo() { |
227 | 158 | $conds = $this->mConds; |
228 | 159 | $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ); |
229 | | - if( $this->level ) |
230 | | - $conds['pt_create_perm'] = $this->level; |
231 | | - if( !is_null($this->namespace) ) |
232 | | - $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace ); |
| 160 | + |
| 161 | + if ( $this->mHTMLForm->getVal( 'Level' ) ) { |
| 162 | + $conds['pt_create_perm'] = $this->mHTMLForm->getVal( 'Level' ); |
| 163 | + } |
| 164 | + if ( $this->mHTMLForm->getVal( 'Namespace' ) !== '' ) { |
| 165 | + $conds['pt_namespace'] = $this->mHTMLForm->getVal( 'Namespace' ); |
| 166 | + } |
| 167 | + |
233 | 168 | return array( |
234 | 169 | 'tables' => 'protected_titles', |
235 | 170 | 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp', |
— | — | @@ -239,5 +174,28 @@ |
240 | 175 | function getIndexField() { |
241 | 176 | return 'pt_timestamp'; |
242 | 177 | } |
| 178 | + |
| 179 | + protected function getHTMLFormFields() { |
| 180 | + return array( |
| 181 | + 'Namespace' => array( |
| 182 | + 'type' => 'namespaces', |
| 183 | + 'label-message' => 'namespace', |
| 184 | + ), |
| 185 | + 'Level' => array( |
| 186 | + 'type' => 'restrictionlevels', |
| 187 | + 'label-message' => 'restriction-level', |
| 188 | + ), |
| 189 | + ); |
| 190 | + } |
| 191 | + |
| 192 | + protected function getHTMLFormSubmit() { |
| 193 | + return 'allpagessubmit'; |
| 194 | + } |
| 195 | + |
| 196 | + protected function getHTMLFormLegend() { |
| 197 | + return 'protectedtitles'; |
| 198 | + } |
| 199 | + |
| 200 | + |
243 | 201 | } |
244 | 202 | |
Index: trunk/phase3/includes/Pager.php |
— | — | @@ -100,6 +100,13 @@ |
101 | 101 | protected $mLastShown, $mFirstShown, $mPastTheEndIndex, $mDefaultQuery, $mNavigationBar; |
102 | 102 | |
103 | 103 | /** |
| 104 | + * HTMLForm object |
| 105 | + * |
| 106 | + * @var HTMLForm |
| 107 | + */ |
| 108 | + protected $mHTMLForm; |
| 109 | + |
| 110 | + /** |
104 | 111 | * Result object for the query. Warning: seek before use. |
105 | 112 | * |
106 | 113 | * @var ResultWrapper |
— | — | @@ -569,27 +576,25 @@ |
570 | 577 | throw new MWException( __METHOD__ . " was called without any form fields being defined" ); |
571 | 578 | } |
572 | 579 | |
573 | | - $form = new HTMLForm( $this->getHTMLFormFields(), $this->getContext() ); |
574 | | - $form->setMethod( 'get' ); |
575 | | - $form->setWrapperLegendMsg( $this->getHTMLFormLegend() ); |
576 | | - $form->setSubmitTextMsg( $this->getHTMLFormSubmit() ); |
577 | | - $this->addHiddenFields( $form ); |
578 | | - $this->modifyHTMLForm( $form ); |
579 | | - $form->prepareForm(); |
| 580 | + $this->mHTMLForm = new HTMLForm( $this->getHTMLFormFields(), $this->getContext() ); |
| 581 | + $this->mHTMLForm->setMethod( 'get' ); |
| 582 | + $this->mHTMLForm->setWrapperLegendMsg( $this->getHTMLFormLegend() ); |
| 583 | + $this->mHTMLForm->setSubmitTextMsg( $this->getHTMLFormSubmit() ); |
| 584 | + $this->addHiddenFields(); |
| 585 | + $this->modifyHTMLForm( $this->mHTMLForm ); |
| 586 | + $this->mHTMLForm->prepareForm(); |
580 | 587 | |
581 | | - return $form->getHTML( '' ); |
| 588 | + return $this->mHTMLForm->getHTML( '' ); |
582 | 589 | } |
583 | 590 | |
584 | 591 | /** |
585 | 592 | * Adds hidden elements to forms for things that are in the query string. |
586 | 593 | * This is so that parameters like offset stick through form submissions |
587 | | - * |
588 | | - * @param HTMLForm $form |
589 | 594 | */ |
590 | | - protected function addHiddenFields( HTMLForm $form ) { |
| 595 | + protected function addHiddenFields() { |
591 | 596 | $query = $this->getRequest()->getQueryValues(); |
592 | 597 | $fieldsBlacklist = array( 'title' ); |
593 | | - $fields = $form->getFlatFields(); |
| 598 | + $fields = $this->mHTMLForm->getFlatFields(); |
594 | 599 | foreach ( $fields as $name => $field ) { |
595 | 600 | $fieldsBlacklist[] = $field->getName(); |
596 | 601 | } |
— | — | @@ -597,7 +602,7 @@ |
598 | 603 | if ( in_array( $name, $fieldsBlacklist ) ) { |
599 | 604 | continue; |
600 | 605 | } |
601 | | - $form->addHiddenField( $name, $value ); |
| 606 | + $this->mHTMLForm->addHiddenField( $name, $value ); |
602 | 607 | } |
603 | 608 | } |
604 | 609 | |