Index: trunk/extensions/CentralAuth/specials/SpecialWikiSets.php |
— | — | @@ -106,7 +106,7 @@ |
107 | 107 | * @param $reason |
108 | 108 | */ |
109 | 109 | function buildSetView( $subpage, $error = false, $name = null, $type = null, $wikis = null, $reason = null ) { |
110 | | - global $wgOut, $wgUser; |
| 110 | + global $wgOut, $wgUser, $wgLocalDatabases; |
111 | 111 | |
112 | 112 | $wgOut->setSubtitle( wfMsgExt( 'centralauth-editset-subtitle', 'parseinline' ) ); |
113 | 113 | |
— | — | @@ -139,6 +139,19 @@ |
140 | 140 | $usage = ''; |
141 | 141 | } |
142 | 142 | |
| 143 | + $sortedWikis = $set->getWikisRaw(); |
| 144 | + sort( $sortedWikis ); |
| 145 | + |
| 146 | + # Make an array of the opposite list of wikis |
| 147 | + # (all databases *excluding* the defined ones) |
| 148 | + $restWikis = array(); |
| 149 | + foreach( $wgLocalDatabases as $wiki ) { |
| 150 | + if( !in_array( $wiki, $sortedWikis ) ) { |
| 151 | + $restWikis[] = $wiki; |
| 152 | + } |
| 153 | + } |
| 154 | + sort( $restWikis ); |
| 155 | + |
143 | 156 | if ( $this->mCanEdit ) { |
144 | 157 | if ( $error ) { |
145 | 158 | $wgOut->addHTML( "<strong class='error'>{$error}</strong>" ); |
— | — | @@ -152,7 +165,8 @@ |
153 | 166 | } |
154 | 167 | $form['centralauth-editset-type'] = $this->buildTypeSelector( 'wpType', $type ); |
155 | 168 | $form['centralauth-editset-wikis'] = Xml::textarea( 'wpWikis', $wikis ); |
156 | | - $form['centralauth-editset-restwikis'] = $this->buildRestWikiList( $set->getWikisRaw() ); |
| 169 | + $form['centralauth-editset-restwikis'] = Xml::textarea( 'wpRestWikis', |
| 170 | + implode( "\n", $restWikis ), 40, 5, array( 'readonly' => true ) ); |
157 | 171 | $form['centralauth-editset-reason'] = Xml::input( 'wpReason', 50, $reason ); |
158 | 172 | |
159 | 173 | $wgOut->addHTML( Xml::buildForm( $form, 'centralauth-editset-submit' ) ); |
— | — | @@ -164,8 +178,8 @@ |
165 | 179 | $form['centralauth-editset-name'] = htmlspecialchars( $name ); |
166 | 180 | $form['centralauth-editset-usage'] = $usage; |
167 | 181 | $form['centralauth-editset-type'] = wfMsg( "centralauth-editset-{$type}" ); |
168 | | - $form['centralauth-editset-wikis'] = $this->buildWikiList( $set->getWikisRaw() ); |
169 | | - $form['centralauth-editset-restwikis'] = $this->buildRestWikiList( $set->getWikisRaw() ); |
| 182 | + $form['centralauth-editset-wikis'] = self::buildTableByList( $sortedWikis, 3, array( 'width' => '100%' ) ); |
| 183 | + $form['centralauth-editset-restwikis'] = self::buildTableByList( $restWikis, 3, array( 'width' => '100%' ) ); |
170 | 184 | |
171 | 185 | $wgOut->addHTML( Xml::buildForm( $form ) ); |
172 | 186 | } |
— | — | @@ -185,64 +199,43 @@ |
186 | 200 | } |
187 | 201 | |
188 | 202 | /** |
189 | | - * @param $list array List of wikis defined in the wiki set (either opt-in or opt-out) |
190 | | - * @return string |
| 203 | + * Builds a table of several columns, and divides the items of |
| 204 | + * $list equally among each column. All items are escaped. |
| 205 | + * |
| 206 | + * Could in the future be replaced by CSS column-count. |
| 207 | + * |
| 208 | + * @param $list array |
| 209 | + * @param $columns int: number of columns |
| 210 | + * @param $tableAttribs array: <table> attributes |
| 211 | + * @return string Table |
191 | 212 | */ |
192 | | - function buildWikiList( $list ) { |
193 | | - sort( $list ); |
194 | | - |
195 | | - $firstCol = round( count( $list ) / 2 ); |
196 | | - $list1 = array_slice( $list, 0, $firstCol ); |
197 | | - $list2 = array_slice( $list, $firstCol ); |
198 | | - |
199 | | - $html = '<table><tbody><tr style="vertical-align:top;"><td><ul>'; |
200 | | - foreach ( $list1 as $wiki ) { |
201 | | - $escWiki = htmlspecialchars( $wiki ); |
202 | | - $html .= "<li>{$escWiki}</li>"; |
| 213 | + function buildTableByList( $list, $columns = 2, $tableAttribs = array() ) { |
| 214 | + if( !is_array( $list ) ) { |
| 215 | + return ''; |
203 | 216 | } |
204 | | - $html .= '</ul></td><td> </td><td><ul>'; |
205 | | - foreach ( $list2 as $wiki ) { |
206 | | - $escWiki = htmlspecialchars( $wiki ); |
207 | | - $html .= "<li>{$escWiki}</li>"; |
| 217 | + $count = count( $list ); |
| 218 | + # If there are less items than columns, limit the number of columns |
| 219 | + $columns = $count < $columns ? $count : $columns; |
| 220 | + $itemsPerCol = round( $count / $columns ); |
| 221 | + $i = 0; |
| 222 | + $splitLists = array(); |
| 223 | + while( $i < $columns ) { |
| 224 | + $splitLists[$i] = array_slice( $list, $itemsPerCol*$i, $itemsPerCol ); |
| 225 | + $i++; |
208 | 226 | } |
209 | | - $html .= '</ul></td></tr></tbody></table>'; |
210 | | - |
211 | | - return $html; |
212 | | - } |
213 | | - |
214 | | - /** |
215 | | - * This list shows all databases *excluding* the defined ones |
216 | | - * So for opt-out, it shows the databases on which the wiki set is enabled |
217 | | - * And for opt-in, it shows the databases on which the wiki set is disabled |
218 | | - * |
219 | | - * @param $list array List of wikis defined in the wiki set (either opt-in or opt-out) |
220 | | - * @return string |
221 | | - */ |
222 | | - function buildRestWikiList( $list ) { |
223 | | - global $wgLocalDatabases; |
224 | | - |
225 | | - sort( $wgLocalDatabases ); |
226 | | - foreach( $wgLocalDatabases as $wiki ) { |
227 | | - if( !in_array( $wiki, $list ) ) { |
228 | | - $restWikis[] = htmlspecialchars( $wiki ); |
| 227 | + $body = ''; |
| 228 | + foreach( $splitLists as $column => $splitList ) { |
| 229 | + $body .= '<td width="' . round( 100 / $columns ) . '%"><ul>'; |
| 230 | + foreach( $splitList as $listitem ) { |
| 231 | + $body .= Html::element( 'li', array(), $listitem ); |
229 | 232 | } |
| 233 | + $body .= '</ul></td>'; |
230 | 234 | } |
231 | | - |
232 | | - if( $this->mCanEdit ) { |
233 | | - $html = Xml::textarea( 'wpWikis', implode( "\n", $restWikis ), 40, 5, array( 'readonly' => true ) ); |
234 | | - } else { |
235 | | - $firstCol = round( count( $restWikis ) / 2 ); |
236 | | - $list1 = array_slice( $restWikis, 0, $firstCol ); |
237 | | - $list2 = array_slice( $restWikis, $firstCol ); |
238 | | - |
239 | | - $html = '<table><tbody><tr style="vertical-align:top;"><td><ul>' . |
240 | | - '<li>' . implode( '</li><li>', $list2 ) . '</li>' . |
241 | | - '</ul></td><td> </td><td><ul>' . |
242 | | - '<li>' . implode( '</li><li>', $list2 ) . '</li>' . |
243 | | - '</ul></td></tr></tbody></table>'; |
244 | | - } |
245 | | - |
246 | | - return $html; |
| 235 | + return Html::rawElement( 'table', $tableAttribs, |
| 236 | + '<tbody>' . |
| 237 | + Html::rawElement( 'tr', array( 'style' => 'vertical-align:top;' ), $body ) . |
| 238 | + '</tbody>' |
| 239 | + ); |
247 | 240 | } |
248 | 241 | |
249 | 242 | /** |