r105078 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105077‎ | r105078 | r105079 >
Date:19:47, 3 December 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
* Show the list of wikis in two columns, to save space
* Add a list of all databases, excluding those that are defined in the wiki set; this makes it more clear on which wikis an opt-out set is enabled, and on which wikis an opt-in set is disabled
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.i18n.php (modified) (history)
  • /trunk/extensions/CentralAuth/specials/SpecialWikiSets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/specials/SpecialWikiSets.php
@@ -152,7 +152,8 @@
153153 }
154154 $form['centralauth-editset-type'] = $this->buildTypeSelector( 'wpType', $type );
155155 $form['centralauth-editset-wikis'] = Xml::textarea( 'wpWikis', $wikis );
156 - $form['centralauth-editset-reason'] = Xml::input( 'wpReason', false, $reason );
 156+ $form['centralauth-editset-restwikis'] = $this->buildRestWikiList( $set->getWikisRaw() );
 157+ $form['centralauth-editset-reason'] = Xml::input( 'wpReason', 50, $reason );
157158
158159 $wgOut->addHTML( Xml::buildForm( $form, 'centralauth-editset-submit' ) );
159160
@@ -164,6 +165,7 @@
165166 $form['centralauth-editset-usage'] = $usage;
166167 $form['centralauth-editset-type'] = wfMsg( "centralauth-editset-{$type}" );
167168 $form['centralauth-editset-wikis'] = $this->buildWikiList( $set->getWikisRaw() );
 169+ $form['centralauth-editset-restwikis'] = $this->buildRestWikiList( $set->getWikisRaw() );
168170
169171 $wgOut->addHTML( Xml::buildForm( $form ) );
170172 }
@@ -183,21 +185,67 @@
184186 }
185187
186188 /**
187 - * @param $list array
 189+ * @param $list array List of wikis defined in the wiki set (either opt-in or opt-out)
188190 * @return string
189191 */
190192 function buildWikiList( $list ) {
191193 sort( $list );
192 - $html = '<ul>';
193 - foreach ( $list as $wiki ) {
 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 ) {
194201 $escWiki = htmlspecialchars( $wiki );
195202 $html .= "<li>{$escWiki}</li>";
196203 }
197 - $html .= '</ul>';
 204+ $html .= '</ul></td><td>&nbsp;</td><td><ul>';
 205+ foreach ( $list2 as $wiki ) {
 206+ $escWiki = htmlspecialchars( $wiki );
 207+ $html .= "<li>{$escWiki}</li>";
 208+ }
 209+ $html .= '</ul></td></tr></tbody></table>';
 210+
198211 return $html;
199212 }
200213
201214 /**
 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 );
 229+ }
 230+ }
 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>&nbsp;</td><td><ul>' .
 242+ '<li>' . implode( '</li><li>', $list2 ) . '</li>' .
 243+ '</ul></td></tr></tbody></table>';
 244+ }
 245+
 246+ return $html;
 247+ }
 248+
 249+ /**
202250 * @param $subpage
203251 * @return mixed
204252 */
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php
@@ -346,6 +346,7 @@
347347 'centralauth-editset-name' => 'Name:',
348348 'centralauth-editset-type' => 'Type:',
349349 'centralauth-editset-wikis' => 'Wikis:',
 350+ 'centralauth-editset-restwikis' => 'Wikis not included above:',
350351 'centralauth-editset-reason' => 'Reason:',
351352 'centralauth-editset-submit' => 'Submit',
352353 'centralauth-editset-submit-delete' => 'Delete',
@@ -522,6 +523,8 @@
523524 'centralauth-editset-subtitle' => 'Do not translate the <code>Special:WikiSets<code> part.',
524525 'centralauth-editset-name' => '{{Identical|Name}}',
525526 'centralauth-editset-type' => '{{Identical|Type}}',
 527+ 'centralauth-editset-wikis' => 'List of wiki databases defined in this wiki set (either opt-in or opt-out)',
 528+ 'centralauth-editset-restwikis' => 'All wiki databases *not* defined in this wiki set (either opt-in or opt-out)',
526529 'centralauth-editset-reason' => '{{identical|Reason}}',
527530 'centralauth-editset-submit' => '{{Identical|Submit}}',
528531 'centralauth-editset-submit-delete' => '{{Identical|Delete}}',

Follow-up revisions

RevisionCommit summaryAuthorDate
r107077Follow-up r105078: per Brion, make a general function to divide a list over s...robin17:16, 22 December 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   21:38, 6 December 2011

I'd recommend combining the two-column logic into a single function, and pass it lists of HTML-escaped items in both cases.

#Comment by SPQRobin (talk | contribs)   22:26, 10 December 2011

Good idea. Should I leave it in CentralAuth or make a function in e.g. core Html.php?

#Comment by SPQRobin (talk | contribs)   17:19, 22 December 2011

Done in r107077. I even made it so that it accepts a number of columns :) It might be moved to core if it's useful enough.

#Comment by SVG (talk | contribs)   20:32, 22 December 2011

Seems being fixed. Marked it as resolved.

#Comment by P858snake (talk | contribs)   06:45, 10 December 2011

Siebrand, Why did you FIXME this? because of Brion's comments?

Status & tagging log