r104383 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104382‎ | r104383 | r104384 >
Date:00:31, 28 November 2011
Author:johnduhart
Status:reverted (Comments)
Tags:
Comment:
Followup r104353, updating Special:ProtectedTitles
Adds HTML form fields for namespaces and restriction levels
Adds getVal() to HTMLForm
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/Pager.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialProtectedtitles.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -72,6 +72,8 @@
7373 'submit' => 'HTMLSubmitField',
7474 'hidden' => 'HTMLHiddenField',
7575 'edittools' => 'HTMLEditTools',
 76+ 'namespaces' => 'HTMLNamespacesField',
 77+ 'restrictionlevels' => 'HTMLRestrictionLevelsField',
7678
7779 # HTMLTextField will output the correct type="" attribute automagically.
7880 # There are about four zillion other HTML5 input types, like url, but
@@ -854,6 +856,16 @@
855857 public function getFlatFields() {
856858 return $this->mFlatFields;
857859 }
 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+ }
858870 }
859871
860872 /**
@@ -2004,3 +2016,84 @@
20052017 . "</div></td></tr>\n";
20062018 }
20072019 }
 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 @@
2929 */
3030 class SpecialProtectedtitles extends SpecialPage {
3131
32 - protected $IdLevel = 'level';
33 - protected $IdType = 'type';
34 -
3532 public function __construct() {
3633 parent::__construct( 'Protectedtitles' );
3734 }
@@ -44,17 +41,9 @@
4542 Title::purgeExpiredRestrictions();
4643 }
4744
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() );
5447
55 - $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
56 -
57 - $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
58 -
5948 if ( $pager->getNumRows() ) {
6049 $s = $pager->getNavigationBar();
6150 $s .= "<ul>" .
@@ -70,6 +59,7 @@
7160 /**
7261 * Callback function to output a restriction
7362 *
 63+ * @param $row
7464 * @return string
7565 */
7666 function formatRow( $row ) {
@@ -107,89 +97,30 @@
10898
10999 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
110100 }
 101+}
111102
 103+/**
 104+ * @todo document
 105+ * @ingroup Pager
 106+ */
 107+class ProtectedTitlesPager extends AlphabeticPager {
112108 /**
113 - * @param $namespace Integer:
114 - * @param $type string
115 - * @param $level string
116 - * @private
 109+ * @var SpecialProtectedtitles
117110 */
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 ) . "&#160;\n" .
127 - $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
128 - $this->getLevelMenu( $level ) . "&#160;\n" .
129 - "&#160;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
130 - "</fieldset></form>";
131 - }
 111+ public $mForm;
132112
133113 /**
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
139115 */
140 - function getNamespaceMenu( $namespace = null ) {
141 - return Xml::label( wfMsg( 'namespace' ), 'namespace' )
142 - . '&#160;'
143 - . Xml::namespaceSelector( $namespace, '' );
144 - }
 116+ public $mConds;
145117
146118 /**
147 - * @return string Formatted HTML
148 - * @private
 119+ * @param $form SpecialProtectedtitles
 120+ * @param $conds array
149121 */
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 ) . '&#160;' .
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() ) {
189123 $this->mForm = $form;
190124 $this->mConds = $conds;
191 - $this->level = $level;
192 - $this->namespace = $namespace;
193 - $this->size = intval($size);
194125 parent::__construct( $form->getContext() );
195126 }
196127
@@ -225,10 +156,14 @@
226157 function getQueryInfo() {
227158 $conds = $this->mConds;
228159 $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+
233168 return array(
234169 'tables' => 'protected_titles',
235170 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
@@ -239,5 +174,28 @@
240175 function getIndexField() {
241176 return 'pt_timestamp';
242177 }
 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+
243201 }
244202
Index: trunk/phase3/includes/Pager.php
@@ -100,6 +100,13 @@
101101 protected $mLastShown, $mFirstShown, $mPastTheEndIndex, $mDefaultQuery, $mNavigationBar;
102102
103103 /**
 104+ * HTMLForm object
 105+ *
 106+ * @var HTMLForm
 107+ */
 108+ protected $mHTMLForm;
 109+
 110+ /**
104111 * Result object for the query. Warning: seek before use.
105112 *
106113 * @var ResultWrapper
@@ -569,27 +576,25 @@
570577 throw new MWException( __METHOD__ . " was called without any form fields being defined" );
571578 }
572579
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();
580587
581 - return $form->getHTML( '' );
 588+ return $this->mHTMLForm->getHTML( '' );
582589 }
583590
584591 /**
585592 * Adds hidden elements to forms for things that are in the query string.
586593 * This is so that parameters like offset stick through form submissions
587 - *
588 - * @param HTMLForm $form
589594 */
590 - protected function addHiddenFields( HTMLForm $form ) {
 595+ protected function addHiddenFields() {
591596 $query = $this->getRequest()->getQueryValues();
592597 $fieldsBlacklist = array( 'title' );
593 - $fields = $form->getFlatFields();
 598+ $fields = $this->mHTMLForm->getFlatFields();
594599 foreach ( $fields as $name => $field ) {
595600 $fieldsBlacklist[] = $field->getName();
596601 }
@@ -597,7 +602,7 @@
598603 if ( in_array( $name, $fieldsBlacklist ) ) {
599604 continue;
600605 }
601 - $form->addHiddenField( $name, $value );
 606+ $this->mHTMLForm->addHiddenField( $name, $value );
602607 }
603608 }
604609

Follow-up revisions

RevisionCommit summaryAuthorDate
r105338Revert r104353, r104354, r104356, r104358, r104383: changes to pagers break...brion19:32, 6 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r104353This is the rework I was talking about in r104318 for 1.19. Instead of having...johnduhart18:23, 27 November 2011

Comments

#Comment by Nikerabbit (talk | contribs)   08:59, 29 November 2011

Autoloader entries. Are you sure the escaping is correct in both classes?

Status & tagging log