r91772 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91771‎ | r91772 | r91773 >
Date:01:03, 9 July 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
Inline CSS is bad in itself and bad for RTL support (why was there even a message containing CSS?)
Modified paths:
  • /trunk/extensions/Collection/Collection.hooks.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)
  • /trunk/extensions/Collection/Collection.templates.php (modified) (history)
  • /trunk/extensions/Collection/CollectionCore.i18n.php (modified) (history)
  • /trunk/extensions/Collection/js/bookcreator.css (modified) (history)
  • /trunk/phase3/skins/common/shared.css (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/shared.css
@@ -20,6 +20,8 @@
2121
2222 .mw-float-start { float: left; }
2323 .mw-float-end { float: right; }
 24+.mw-align-start { text-align: left; }
 25+.mw-align-end { text-align: left; }
2426
2527 /* The scripts of these languages are very hard to read with underlines */
2628 [lang="ar"] a, [lang="ckb"] a, [lang="fa"] a, [lang="kk-arab"] a,
Index: trunk/extensions/Collection/Collection.php
@@ -33,7 +33,7 @@
3434 $dir = dirname( __FILE__ ) . '/';
3535
3636 # Extension version
37 -$wgCollectionVersion = "1.4";
 37+$wgCollectionVersion = "1.5";
3838
3939 # ==============================================================================
4040
Index: trunk/extensions/Collection/Collection.hooks.php
@@ -235,7 +235,7 @@
236236 $addRemoveState = $mode;
237237
238238 $html = Xml::element( 'div',
239 - array( 'style' => wfMsg( 'coll-book_creator_box_style' ) ),
 239+ array( 'class' => 'collection-creatorbox' ),
240240 null
241241 );
242242
@@ -245,16 +245,16 @@
246246 'alt' => '',
247247 'width' => '80',
248248 'height' => '45',
249 - 'style' => 'float: left;',
 249+ 'class' => 'mw-float-start collection-creatorbox-book',
250250 ),
251251 '',
252252 true
253253 );
254254
255255 $html .= Xml::tags( 'div',
256 - array( 'style' => 'margin-left: 90px;' ),
 256+ array( 'class' => 'collection-creatorbox-row' ),
257257 Xml::tags( 'div',
258 - array( 'style' => 'float: right' ),
 258+ array( 'class' => 'mw-float-end' ),
259259 $skin->link(
260260 Title::newFromText( wfMsg( 'coll-helppage' ) ),
261261 Xml::element( 'img',
@@ -275,8 +275,8 @@
276276 array( 'known', 'noclasses' )
277277 )
278278 )
279 - . Xml::tags( 'strong',
280 - array( 'style' => 'font-size: 1.2em' ),
 279+ . Xml::tags( 'span',
 280+ array( 'class' => 'collection-creatorbox-title' ),
281281 wfMsgHtml( 'coll-book_creator' )
282282 )
283283 . ' ('
@@ -296,7 +296,7 @@
297297 $html .= Xml::tags( 'div',
298298 array(
299299 'id' => 'coll-book_creator_box',
300 - 'style' => 'margin-left: 90px; margin-bottom: 0;',
 300+ 'class' => 'collection-creatorbox-row',
301301 ),
302302 self::getBookCreatorBoxContent( $skin, $title, $addRemoveState, $oldid )
303303 );
@@ -371,7 +371,6 @@
372372 'alt' => '',
373373 'width' => '16',
374374 'height' => '16',
375 - 'style' => 'vertical-align: text-bottom',
376375 )
377376 )
378377 . ' ' . wfMsgHtml( $captionMsg ),
@@ -392,7 +391,7 @@
393392 if ( $ajaxHint == 'showbook' ) {
394393 return Xml::tags( 'strong',
395394 array(
396 - 'style' => 'margin-left: 10px;',
 395+ 'class' => 'collection-creatorbox-iconlink',
397396 ),
398397 Xml::element( 'img',
399398 array(
@@ -400,7 +399,6 @@
401400 'alt' => '',
402401 'width' => '16',
403402 'height' => '16',
404 - 'style' => 'vertical-align: text-bottom',
405403 )
406404 )
407405 . ' ' . wfMsgHtml( 'coll-show_collection' )
@@ -415,7 +413,6 @@
416414 'alt' => '',
417415 'width' => '16',
418416 'height' => '16',
419 - 'style' => 'vertical-align: text-bottom',
420417 )
421418 )
422419 . ' ' . wfMsgHtml( 'coll-show_collection' )
@@ -423,7 +420,7 @@
424421 array(
425422 'rel' => 'nofollow',
426423 'title' => wfMsg( 'coll-show_collection_tooltip' ),
427 - 'style' => 'margin-left: 10px',
 424+ 'class' => 'collection-creatorbox-iconlink',
428425 ),
429426 array(),
430427 array( 'known', 'noclasses' )
@@ -439,7 +436,7 @@
440437 if ( $ajaxHint == 'suggest' ) {
441438 return Xml::tags( 'strong',
442439 array(
443 - 'style' => 'margin-left: 10px;',
 440+ 'class' => 'collection-creatorbox-iconlink',
444441 ),
445442 Xml::element( 'img',
446443 array(
@@ -468,7 +465,7 @@
469466 array(
470467 'rel' => 'nofollow',
471468 'title' => wfMsg( 'coll-make_suggestions_tooltip' ),
472 - 'style' => 'margin-left: 10px',
 469+ 'class' => 'collection-creatorbox-iconlink',
473470 ),
474471 array( 'bookcmd' => 'suggest', ),
475472 array( 'known', 'noclasses' )
Index: trunk/extensions/Collection/CollectionCore.i18n.php
@@ -32,7 +32,6 @@
3333 'coll-book_creator' => 'Book creator',
3434 'coll-download_as' => 'Download as $1',
3535 'coll-download_as_tooltip' => 'Download a $1 version of this wiki page',
36 - 'coll-book_creator_box_style' => 'text-align: left; margin: 10px 0; padding: 5px 10px; border: 1px solid #aaa; background-color: #f9f9ff;',
3736 'coll-disable' => 'disable',
3837 'coll-book_creator_disable' => 'Disable book creator',
3938 'coll-book_creator_disable_tooltip' => 'Stop using the book creator',
Index: trunk/extensions/Collection/js/bookcreator.css
@@ -8,6 +8,66 @@
99 font-size: 10pt;
1010 }
1111
 12+/*
 13+ * Special page
 14+ */
 15+
 16+.collection-column {
 17+ width: 47%;
 18+}
 19+
 20+.collection-column-left {
 21+ margin-right: 5%;
 22+}
 23+
 24+.collection-column-right-box {
 25+ margin-bottom: 10px;
 26+ padding: 10px;
 27+ border: 1px solid #aaa;
 28+ background-color: #f9f9f9;
 29+}
 30+
 31+/* Input follows user direction */
 32+#mw-collection-title-form input {
 33+ direction: ltr;
 34+}
 35+
 36+.collection-create-chapter-links {
 37+ text-align: center;
 38+ padding: 2px;
 39+ margin-top: 20px;
 40+ margin-bottom: 2px;
 41+ border: 1px solid #aaa;
 42+ background-color: #f9f9f9;
 43+}
 44+
 45+.collection-create-chapter-links a {
 46+ margin: 0 1em;
 47+}
 48+
 49+.collection-create-chapter-list {
 50+ padding: 10px 20px;
 51+ border: 1px solid rgb(170, 170, 170);
 52+}
 53+
 54+.collection-create-chapter-list-text {
 55+ text-align: center;
 56+ margin-bottom: 10px;
 57+}
 58+
 59+.collection-create-chapter-list ul {
 60+ list-style: none;
 61+ margin-left: 0;
 62+}
 63+
 64+.collection-create-chapter-list .chapter {
 65+ margin-top:0.3em;
 66+}
 67+
 68+.collection-create-chapter-list .article .title {
 69+ margin-left: 1em;
 70+}
 71+
1272 .collection-button {
1373 float: left;
1474 padding: 0 10px;
@@ -38,3 +98,42 @@
3999 .collection-button a:hover {
40100 text-decoration: none;
41101 }
 102+
 103+/*
 104+ * Creator box
 105+ */
 106+
 107+.collection-creatorbox {
 108+ text-align: left;
 109+ margin: 10px 0;
 110+ padding: 5px 10px;
 111+ border: 1px solid #aaa;
 112+ background-color: #f9f9ff;
 113+}
 114+
 115+.collection-creatorbox-row {
 116+ margin-left: 90px;
 117+ margin-bottom: 0;
 118+}
 119+
 120+/* Trivial but nicer for the browsers that support it */
 121+.rtl .collection-creatorbox-book {
 122+ --ms-transform: scaleX(-1);
 123+ -moz-transform: scaleX(-1);
 124+ -o-transform: scaleX(-1);
 125+ -webkit-transform: scaleX(-1);
 126+ transform: scaleX(-1);
 127+}
 128+
 129+.collection-creatorbox-title {
 130+ font-weight: bold;
 131+ font-size: 1.2em;
 132+}
 133+
 134+.collection-creatorbox-iconlink {
 135+ margin-left: 10px;
 136+}
 137+
 138+.collection-creatorbox-row img {
 139+ vertical-align: text-bottom;
 140+}
\ No newline at end of file
Index: trunk/extensions/Collection/Collection.templates.php
@@ -15,7 +15,7 @@
1616 $mediapath = $GLOBALS['wgScriptPath'] . '/extensions/Collection/images/';
1717 ?>
1818
19 -<div style="width: 47%; float: left; margin-right: 5%">
 19+<div class="mw-float-start collection-column collection-column-left">
2020
2121 <form action="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book' ) ) ?>" method="post" id="mw-collection-title-form">
2222 <table id="mw-collection-title-table" style="width: 80%; background-color: transparent;" align="center">
@@ -51,16 +51,16 @@
5252
5353 </div>
5454
55 -<div style="width: 47%; float: left">
 55+<div class="mw-float-start collection-column collection-column-right">
5656
57 - <div style="margin-bottom: 10px; padding: 10px; border: 1px solid #aaa; background-color: #f9f9f9;">
 57+ <div class="collection-column-right-box">
5858 <h2><span class="mw-headline"><?php $this->msg( 'coll-book_title' ) ?></span></h2>
5959 <?php
6060 $partnerData = $this->data['podpartners']['pediapress'];
6161 $this->msgWiki( 'coll-book_text' );
6262 ?>
6363 <div>
64 - <div style="float:right">
 64+ <div class="mw-float-end">
6565 <form action="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book' ) ) ?>" method="post">
6666 <input type="hidden" name="bookcmd" value="post_zip" />
6767 <input type="hidden" name="partner" value="pediapress" />
@@ -90,7 +90,7 @@
9191 <?php } ?>
9292 </div>
9393
94 - <div style="margin-bottom: 10px; padding: 10px; border: 1px solid #aaa; background-color: #f9f9f9;">
 94+ <div class="collection-column-right-box">
9595 <h2><span class="mw-headline"><?php $this->msg( 'coll-download_title' ) ?></span></h2>
9696 <?php if ( count( $this->data['formats'] ) == 1 ) {
9797 $writer = array_rand( $this->data['formats'] );
@@ -112,7 +112,7 @@
113113 <?php } ?>
114114 </select>
115115 <?php } ?>
116 - </td><td style="text-align:right; vertical-align:bottom;">
 116+ </td><td class="mw-align-end" style="vertical-align:bottom;">
117117 <input type="hidden" name="bookcmd" value="render" />
118118 <input id="downloadButton" type="submit" value="<?php echo $buttonLabel ?>"<?php if ( count( $this->data['collection']['items'] ) == 0 ) { ?> disabled="disabled"<?php } ?> />
119119 </td></tr></tbody></table>
@@ -129,7 +129,7 @@
130130 }
131131 if ( $GLOBALS['wgEnableWriteAPI'] && ( $canSaveUserPage || $canSaveCommunityPage ) ) {
132132 ?>
133 - <div id="coll-savebox" style="margin-bottom: 10px; padding: 10px; border: 1px solid #aaa; background-color: #f9f9f9;">
 133+ <div class="collection-column-right-box" id="coll-savebox">
134134 <h2><span class="mw-headline"><?php $this->msg( 'coll-save_collection_title' ) ?></span></h2>
135135 <?php
136136 $this->msgWiki( 'coll-save_collection_text' );
@@ -146,7 +146,7 @@
147147 <?php } ?>
148148 <label for="personalCollTitle"><a href="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Prefixindex', 'prefix=' . wfUrlencode( $this->data['user-book-prefix'] ) ) ) ?>"><?php echo htmlspecialchars( $this->data['user-book-prefix'] ) ?></a></label>
149149 </td>
150 - <td style="text-align:right;">
 150+ <td class="mw-align-end">
151151 <input id="personalCollTitle" type="text" name="pcollname" />
152152 </td></tr>
153153 <?php } // if ($canSaveUserPage) ?>
@@ -159,11 +159,11 @@
160160 <?php } ?>
161161 <label for="communityCollTitle"><a href="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Prefixindex', 'prefix=' . wfUrlencode( $this->data['community-book-prefix'] ) ) ) ?>"><?php echo htmlspecialchars( $this->data['community-book-prefix'] ) ?></a></label>
162162 </td>
163 - <td style="text-align:right;">
 163+ <td class="mw-align-end">
164164 <input id="communityCollTitle" type="text" name="ccollname" disabled="disabled" />
165165 </td></tr>
166166 <?php } // if ($canSaveCommunityPage) ?>
167 - <tr><td>&#160;</td><td style="text-align:right;">
 167+ <tr><td>&#160;</td><td class="mw-align-end">
168168 <input id="saveButton" type="submit" value="<?php $this->msg( 'coll-save_collection' ) ?>"<?php if ( count( $this->data['collection']['items'] ) == 0 ) { ?> disabled="disabled"<?php } ?> />
169169 </tr></tbody></table>
170170 <input name="token" type="hidden" value="<?php echo htmlspecialchars( $GLOBALS['wgUser']->editToken() ) ?>" />
@@ -196,29 +196,26 @@
197197 $mediapath = $GLOBALS['wgScriptPath'] . '/extensions/Collection/images/';
198198 ?>
199199
200 -<div style="text-align: center; padding: 2px; margin-top: 20px; margin-bottom: 2px; border: 1px solid #aaa; background-color: #f9f9f9;">
201 -<div>
202 -<a class="makeVisible" style="margin-right: 3em;<?php if ( !isset( $this->data['is_ajax'] ) ) { echo ' display:none;'; } ?>" onclick="return coll_create_chapter()" href="javascript:void(0);"><?php $this->msg( 'coll-create_chapter' ) ?></a>
 200+<div class="collection-create-chapter-links">
 201+<a class="makeVisible" style="<?php if ( !isset( $this->data['is_ajax'] ) ) { echo ' display:none;'; } ?>" onclick="return coll_create_chapter()" href="javascript:void(0);"><?php $this->msg( 'coll-create_chapter' ) ?></a>
203202 <?php if ( count( $this->data['collection']['items'] ) > 0 ) { ?>
204 -<a style="margin-right: 3em" href="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book', array( 'bookcmd' => 'sort_items' ) ) ) ?>"><?php $this->msg( 'coll-sort_alphabetically' ) ?></a>
 203+<a href="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book', array( 'bookcmd' => 'sort_items' ) ) ) ?>"><?php $this->msg( 'coll-sort_alphabetically' ) ?></a>
205204 <a onclick="return coll_clear_collection()" href="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book', array( 'bookcmd' => 'clear_collection' ) ) ) ?>"><?php $this->msg( 'coll-clear_collection' ) ?></a>
206205 <?php } ?>
207206 </div>
208 -</div>
209207
 208+<div class="collection-create-chapter-list">
210209
211 -<div style="padding: 10px 20px; border: 1px solid rgb(170, 170, 170)">
212 -
213210 <?php
214211 if ( count( $this->data['collection']['items'] ) == 0 ) { ?>
215212 <em id="emptyCollection"><?php $this->msg( 'coll-empty_collection' ); ?></em>
216213 <?php } else { ?>
217 -<div style="text-align: center; margin-bottom: 10px">
 214+<div style="collection-create-chapter-list-text">
218215 <em class="makeVisible" style="display:none; font-size: 95%"><?php $this->msg( 'coll-drag_and_drop' ) ?></em>
219216 </div>
220217 <?php } ?>
221218
222 -<ul id="collectionList" style="list-style: none; margin-left: 0;">
 219+<ul id="collectionList">
223220
224221 <?php
225222 foreach ( $this->data['collection']['items'] as $index => $item ) {
@@ -244,7 +241,7 @@
245242 }
246243 ?>
247244 <a href="<?php echo htmlspecialchars( $url ) ?>" title="<?php $this->msg( 'coll-show' ) ?>"><img src="<?php echo htmlspecialchars( $mediapath . "show.png" ) ?>" width="10" height="10" alt="<?php $this->msg( 'coll-show' ) ?>" /></a>
248 - <span class="title sortableitem" style="margin-left: 1em;">
 245+ <span class="title sortableitem">
249246 <?php if ( isset( $item['displaytitle'] ) && $item['displaytitle'] != '' ) {
250247 echo htmlspecialchars( $item['displaytitle'] );
251248 } else {
@@ -253,7 +250,7 @@
254251 </span>
255252 </li>
256253 <?php } elseif ( $item['type'] == 'chapter' ) { ?>
257 - <li id="item-<?php echo intval( $index ) ?>" class="chapter" style="margin-top:0.3em;">
 254+ <li id="item-<?php echo intval( $index ) ?>" class="chapter">
258255 <a onclick="return coll_remove_item(<?php echo intval( $index ) ?>)" href="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book', array( 'bookcmd' => 'remove_item', 'index=' => $index ) ) ) ?>" title="<?php $this->msg( 'coll-remove' ) ?>"><img src="<?php echo htmlspecialchars( $mediapath . "remove.png" ) ?>" width="10" height="10" alt="<?php $this->msg( 'coll-remove' ) ?>" /></a>
259256 <noscript>
260257 <?php if ( $index == 0 ) { ?>
@@ -421,7 +418,7 @@
422419 (<a href="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book', array( 'bookcmd' => 'suggest', 'resetbans' => '1' ) ) ) ?>" title="<?php $this->msg( 'coll-suggest_reset_bans_tooltip' ) ?>"><?php $this->msg( 'coll-suggest_reset_bans' ) ?></a>)
423420 <?php if ( count( $this->data['proposals'] ) > 0 ) { ?>
424421 <noscript>
425 - <div style="float: right;">
 422+ <div class="mw-float-end">
426423 <input type="submit" value="<?php $this->msg( 'coll-suggest_add_selected' ) ?>" name="addselected" />
427424 </div>
428425 </noscript>

Follow-up revisions

RevisionCommit summaryAuthorDate
r91791Followup r91772 for Translatewikiraymond16:54, 9 July 2011
r92010Fix r91772: left should be right (copy-paste error)robin21:15, 12 July 2011
r95337Followup r91772: update requiredVersion in collection.js so Collection extens...brion21:35, 23 August 2011
r96406Per Krinke on r91772, do not use general float/align classes. I removed them ...robin05:23, 7 September 2011

Comments

#Comment by 😂 (talk | contribs)   20:34, 12 July 2011

Is the shared.css change in core intended?

#Comment by SPQRobin (talk | contribs)   21:13, 12 July 2011

Yes, they are general classes that can be used anywhere (like the float classes), but it appears that I did a stupid copy-paste error, I'll have to change the second 'left' to 'right'.

#Comment by 😂 (talk | contribs)   21:33, 12 July 2011

My point is that I don't see them referenced anywhere else in the commit (which seems to have been about Collection), so I'm not sure why it was included here.

#Comment by SPQRobin (talk | contribs)   21:37, 12 July 2011

I made use of mw-align-end in Collection in this commit. I should have perhaps mentioned it in the summary.

#Comment by Brion VIBBER (talk | contribs)   21:31, 23 August 2011

This updates $wgCollectionVersion without updating requiredVersion in collection.js, so all the JavaScript front-end code aborts...

#Comment by Brion VIBBER (talk | contribs)   21:36, 23 August 2011

Updated on trunk in r95337. Resetting this rev from fixme to new.

#Comment by Krinkle (talk | contribs)   23:04, 5 September 2011

I didn't understand the mw-align-start/end and mw-float-start/end at first, but SPQRobin explained it to me. Repeating here in my own words for later reference.

mw-float-start/end allows to float an element to the side where either the text starts, or to the opposite side.

For example, if a diagram should be floated to the right of the page in an LTR context, then it should float to the left of the page in an RTL context. On such element you could use mw-float-end.

That's all nice. But from a front-end perspective it's not very semantic in my opinion and it doesn't solve anything.

Consider the following example:

--- CSS
.mw-float-left {
  float: left; /* flipped by ResourceLoader */
}
.mw-float-end {
  float: right; /* flipped by ResourceLoader */
}

.infobox {
  border: 1px solid grey;
  ...
}

--- HTML
<div class="infobox mw-float-end">
...
</div>

I would rather have us do the following, and therewith separate presentation from content.

-- CSS
.infobox {
  float: right; /* flipped by ResourceLoader as needed */
  border: 1px solid grey;
  ...
}

--- HTML
...
</pe> To use an extreme example: Suppose there's a class for "error" that is declared like .error { color: red; } and another called "love": .love { color: red; }, we wouldn't go and use a class "red-text" and use <div class="red-text"> for both.... That's the opposite of what CSS is meant to be used for. Marking fixme. Use meaningful classes for elements that need special presentation (ie. "mw-collection-label-download").
#Comment by SPQRobin (talk | contribs)   05:24, 7 September 2011

Should be OK in r96406.

Status & tagging log