r22767 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22766‎ | r22767 | r22768 >
Date:17:03, 5 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Rename ProtectedPagesForm to SpecialProtectedPages and make it inherit SpecialPage
* Scrap the old special page execution method and use the new one
* Clean up a lot of SpecialProtectedPages UI code
* Overhaul the Special:Protectedpages UI
Modified paths:
  • /branches/robchurch/pr_timestamp/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/pr_timestamp/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/pr_timestamp/includes/SpecialProtectedpages.php (modified) (history)
  • /branches/robchurch/pr_timestamp/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: branches/robchurch/pr_timestamp/includes/SpecialProtectedpages.php
@@ -1,18 +1,31 @@
22 <?php
 3+
34 /**
 5+ * Special page listing all protected pages in the wiki
46 *
57 * @addtogroup SpecialPage
68 */
 9+class SpecialProtectedPages extends SpecialPage {
710
8 -/**
9 - * @todo document
10 - * @addtogroup SpecialPage
11 - */
12 -class ProtectedPagesForm {
13 -
1411 protected $IdLevel = 'level';
1512 protected $IdType = 'type';
1613
 14+ /**
 15+ * Constructor
 16+ */
 17+ public function __construct() {
 18+ parent::__construct( 'Protectedpages' );
 19+ }
 20+
 21+ /**
 22+ * Special page execution function
 23+ *
 24+ * @param mixed $par Parameters passed to the page
 25+ */
 26+ public function execute( $par = false ) {
 27+ $this->showList();
 28+ }
 29+
1730 function showList( $msg = '' ) {
1831 global $wgOut, $wgRequest;
1932
@@ -86,106 +99,120 @@
87100 }
88101
89102 /**
90 - * @param $namespace int
91 - * @param $type string
92 - * @param $level string
93 - * @param $minsize int
94 - * @private
 103+ * Build the filtering option panel
 104+ *
 105+ * @param int $namespace Pre-select namespace
 106+ * @param string $type Pre-select type
 107+ * @param string $level Pre-select level
 108+ * @param string $sizetype Pre-select size bound
 109+ * @param string $size Pre-fill size
 110+ * @return string
95111 */
96 - function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
 112+ function showOptions( $namespace, $type = 'edit', $level, $sizetype, $size ) {
97113 global $wgScript;
98 - $action = htmlspecialchars( $wgScript );
99 - $title = SpecialPage::getTitleFor( 'ProtectedPages' );
100 - $special = htmlspecialchars( $title->getPrefixedDBkey() );
101 - return "<form action=\"$action\" method=\"get\">\n" .
102 - '<fieldset>' .
103 - Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
104 - Xml::hidden( 'title', $special ) . "&nbsp\n" .
105 - $this->getNamespaceMenu( $namespace ) . "&nbsp\n" .
106 - $this->getTypeMenu( $type ) . "&nbsp\n" .
107 - $this->getLevelMenu( $level ) . "<br/>\n" .
108 - $this->getSizeLimit( $sizetype, $size ) . "\n" .
109 - "&nbsp" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
110 - "</fieldset></form>";
 114+ $self = SpecialPage::getTitleFor( 'Protectedpages' );
 115+ return
 116+ Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) )
 117+ . Xml::hidden( 'title', $self->getPrefixedUrl() )
 118+ . '<fieldset><legend>' . wfMsgHtml( 'protectedpages-legend' ). '</legend>'
 119+ . '<table>'
 120+ . '<tr>' . $this->getNamespaceMenu( $namespace ) . '</tr>'
 121+ . '<tr>' . $this->getTypeMenu( $type ) . '</tr>'
 122+ . '<tr>' . $this->getLevelMenu( $level ) . '</tr>'
 123+ . '<tr>' . $this->getSizeLimit( $sizetype, $size ) . '</tr>'
 124+ . '<tr><td></td><td>' . Xml::submitButton( wfMsg( 'protectedpages-submit' ) ) . '</td></tr>'
 125+ . '</table></fieldset></form>';
111126 }
112127
113 - function getNamespaceMenu( $namespace=NULL ) {
114 - return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
115 - }
116 -
117128 /**
118 - * @return string Formatted HTML
119 - * @private
 129+ * Build a namespace selector
 130+ *
 131+ * @param int $select Pre-selected namespace
 132+ * @return string
120133 */
121 - function getSizeLimit( $sizetype, $size ) {
122 - $out = Xml::radio( 'sizetype', 'min', ($sizetype=='min'), array('id' => 'wpmin') );
123 - $out .= Xml::label( wfMsg("minimum-size"), 'wpmin' );
124 - $out .= "&nbsp".Xml::radio( 'sizetype', 'max', ($sizetype=='max'), array('id' => 'wpmax') );
125 - $out .= Xml::label( wfMsg("maximum-size"), 'wpmax' );
126 - $out .= "&nbsp".Xml::input('size', 9, $size, array( 'id' => 'wpsize' ) );
127 - $out .= ' '.wfMsgHtml('pagesize');
128 - return $out;
 134+ private function getNamespaceMenu( $select = null ) {
 135+ return
 136+ '<td><label for="namespace">' . wfMsgHtml( 'namespace' ) . '</label></td>'
 137+ . '<td>' . Xml::namespaceSelector( $select, '' ) . '</td>';
129138 }
130 -
 139+
131140 /**
132 - * @return string Formatted HTML
133 - * @private
 141+ * Build a type selection list
 142+ *
 143+ * @param string $select Pre-selected type
 144+ * @return string
134145 */
135 - function getTypeMenu( $pr_type ) {
 146+ private function getTypeMenu( $select ) {
136147 global $wgRestrictionTypes;
137 -
138 - $m = array(); // Temporary array
139148 $options = array();
140 -
141 - // First pass to load the log names
142149 foreach( $wgRestrictionTypes as $type ) {
143 - $text = wfMsg("restriction-$type");
144 - $m[$text] = $type;
 150+ $options[] = Xml::option(
 151+ wfMsg( 'restriction-' . $type ),
 152+ $type,
 153+ $type == $select
 154+ );
145155 }
146 -
147 - // Third pass generates sorted XHTML content
148 - foreach( $m as $text => $type ) {
149 - $selected = ($type == $pr_type );
150 - $options[] = Xml::option( $text, $type, $selected ) . "\n";
151 - }
152 -
153156 return
154 - Xml::label( wfMsg('restriction-type') , $this->IdType ) . '&nbsp;' .
155 - Xml::tags( 'select',
156 - array( 'id' => $this->IdType, 'name' => $this->IdType ),
157 - implode( "\n", $options ) );
 157+ '<td><label for="type">' . wfMsgHtml( 'restriction-type' ) . '</label></td>'
 158+ . '<td>' . Xml::tags( 'select', array( 'id' => 'type', 'name' => 'type' ),
 159+ implode( '', $options ) ) . '</td>';
158160 }
159161
160162 /**
161 - * @return string Formatted HTML
162 - * @private
163 - */
164 - function getLevelMenu( $pr_level ) {
 163+ * Build a level selection menu
 164+ *
 165+ * @param int $select Pre-selected level
 166+ * @return string
 167+ */
 168+ private function getLevelMenu( $select ) {
165169 global $wgRestrictionLevels;
166 -
167 - $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
168170 $options = array();
169 -
170 - // First pass to load the log names
171 - foreach( $wgRestrictionLevels as $type ) {
172 - if ( $type !='' && $type !='*') {
173 - $text = wfMsg("restriction-level-$type");
174 - $m[$text] = $type;
 171+ $options[] = Xml::option(
 172+ wfMsg( 'restriction-level-all' ),
 173+ 0,
 174+ $select == 0
 175+ );
 176+ foreach( $wgRestrictionLevels as $level ) {
 177+ if( $level != '' && $level != '*' ) {
 178+ $options[] = Xml::option(
 179+ wfMsg( 'restriction-level-' . $level ),
 180+ $level,
 181+ $level == $select
 182+ );
175183 }
176184 }
 185+ return
 186+ '<td><label for="level">' . wfMsgHtml( 'restriction-level' ) . '</label></td>'
 187+ . '<td>' . Xml::tags( 'select', array( 'id' => 'level', 'name' => 'level' ),
 188+ implode( '', $options ) );
 189+ }
177190
178 - // Third pass generates sorted XHTML content
179 - foreach( $m as $text => $type ) {
180 - $selected = ($type == $pr_level );
181 - $options[] = Xml::option( $text, $type, $selected );
 191+
 192+ /**
 193+ * Build a size limit box
 194+ *
 195+ * @param int $select Pre-select min or max
 196+ * @param int $size Pre-fill size value
 197+ * @return string
 198+ */
 199+ private function getSizeLimit( $select, $size ) {
 200+ $radios = array();
 201+ foreach( array( 'min', 'max' ) as $bound ) {
 202+ $radios[] = Xml::radioLabel(
 203+ wfMsg( 'protectedpages-size-' . $bound ),
 204+ 'sizetype',
 205+ $bound,
 206+ 'wpSize' . $bound,
 207+ $bound == $select
 208+ );
182209 }
183 -
184210 return
185 - Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&nbsp;' .
186 - Xml::tags( 'select',
187 - array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
188 - implode( "\n", $options ) );
 211+ '<tr><td><label for="wpSize">' . wfMsgHtml( 'protectedpages-size' ) . '</label></td>'
 212+ . '<td>' . Xml::input( 'size', 9, $size, array( 'id' => 'wpSize' ) )
 213+ . ' ' . wfMsgHtml( 'pagesize' ) . '</td></tr><tr><td></td><td>'
 214+ . implode( '&nbsp;', $radios ) . '</td>';
189215 }
 216+
190217 }
191218
192219 /**
@@ -254,16 +281,4 @@
255282 }
256283 }
257284
258 -/**
259 - * Constructor
260 - */
261 -function wfSpecialProtectedpages() {
262 -
263 - list( $limit, $offset ) = wfCheckLimits();
264 -
265 - $ppForm = new ProtectedPagesForm();
266 -
267 - $ppForm->showList();
268 -}
269 -
270285 ?>
Index: branches/robchurch/pr_timestamp/includes/AutoLoader.php
@@ -200,6 +200,8 @@
201201 'UnlistedSpecialPage' => 'includes/SpecialPage.php',
202202 'IncludableSpecialPage' => 'includes/SpecialPage.php',
203203 'PopularPagesPage' => 'includes/SpecialPopularpages.php',
 204+ 'SpecialProtectedPages' => 'includes/SpecialProtectedpages.php',
 205+ 'ProtectedPagesPager' => 'includes/Specialprotectedpages.php',
204206 'PreferencesForm' => 'includes/SpecialPreferences.php',
205207 'SpecialPrefixindex' => 'includes/SpecialPrefixindex.php',
206208 'PasswordResetForm' => 'includes/SpecialResetpass.php',
Index: branches/robchurch/pr_timestamp/includes/SpecialPage.php
@@ -110,7 +110,7 @@
111111 'Newpages' => array( 'IncludableSpecialPage', 'Newpages' ),
112112 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
113113 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
114 - 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
 114+ 'Protectedpages' => 'SpecialProtectedPages',
115115 'Allpages' => array( 'IncludableSpecialPage', 'Allpages' ),
116116 'Prefixindex' => array( 'IncludableSpecialPage', 'Prefixindex' ) ,
117117 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ),
Index: branches/robchurch/pr_timestamp/languages/messages/MessagesEn.php
@@ -1600,6 +1600,11 @@
16011601 'deadendpagestext' => 'The following pages do not link to other pages in this wiki.',
16021602 'protectedpages' => 'Protected pages',
16031603 'protectedpages-summary' => '',
 1604+'protectedpages-legend' => 'List protected pages',
 1605+'protectedpages-size' => 'Size:',
 1606+'protectedpages-size-min' => '(min)',
 1607+'protectedpages-size-max' => '(max)',
 1608+'protectedpages-submit' => 'Go',
16041609 'protectedpagestext' => 'The following pages are protected from moving or editing',
16051610 'protectedpagesempty' => 'No pages are currently protected with these parameters.',
16061611 'listusers' => 'User list',

Status & tagging log