r77965 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77964‎ | r77965 | r77966 >
Date:09:41, 7 December 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Made interface more awesome
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push.php (modified) (history)
  • /trunk/extensions/Push/includes/Push_Tab.php (modified) (history)
  • /trunk/extensions/Push/includes/ext.push.tab.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/Push.i18n.php
@@ -20,7 +20,7 @@
2121 // Tab
2222 'push-tab-text' => 'Push',
2323 'push-button-text' => 'Push',
24 - 'push-button-desc' => 'This tab allows you to push the current revision of this page to one or more other wikis.',
 24+ 'push-tab-desc' => 'This tab allows you to push the current revision of this page to one or more other wikis.',
2525 'push-button-pushing' => 'Pushing',
2626 'push-button-completed' => 'Push completed',
2727 'push-button-failed' => 'Push failed',
@@ -29,6 +29,12 @@
3030 'push-add-target' => 'Add target',
3131 'push-import-revision-message' => 'Import from $1 by $2.$3', // $3 is 'push-import-revision-comment' or empty. 1360!
3232 'push-import-revision-comment' => ' Last comment: $1',
 33+ 'push-tab-no-targets' => 'There are no targets to push to. Please add some to your LocalSettings.php file.',
 34+ 'push-tab-push-to' => 'Push to $1',
 35+ 'push-remote-pages' => 'Remote pages',
 36+ 'push-remote-page-link' => '$1 on $2',
 37+ 'push-targets-total' => 'There are $1 targets in total.', // $1 will always be plural
 38+ 'push-button-all' => 'Push all',
3339
3440 // Special page
3541 'special-push' => 'Push pages',
Index: trunk/extensions/Push/Push.php
@@ -64,6 +64,8 @@
6565 'push-button-failed',
6666 'push-import-revision-message',
6767 'push-import-revision-comment',
 68+ 'push-button-text',
 69+ 'push-button-all',
6870 );
6971
7072 // For backward compatibility with MW < 1.17.
Index: trunk/extensions/Push/includes/Push_Tab.php
@@ -104,25 +104,35 @@
105105 * @since 0.1
106106 */
107107 public static function displayPushPage( Article $article ) {
108 - global $wgOut, $wgUser, $wgTitle, $wgSitename;
 108+ global $wgOut, $wgUser, $wgTitle, $wgSitename, $egPushTargets;
109109
 110+ $wgOut->setPageTitle( wfMsgExt( 'push-tab-title', 'parsemag', $article->getTitle()->getText() ) );
 111+
110112 if ( !$wgUser->isAllowed( 'push' ) ) {
111113 $wgOut->permissionRequired( 'push' );
112114 return false;
113115 }
114116
115 - self::loadJs();
 117+ $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsg( 'push-tab-desc' ) ) . '</p>' );
116118
117 - $wgOut->setPageTitle( wfMsgExt( 'push-tab-title', 'parsemag', $article->getTitle()->getText() ) );
 119+ if ( count( $egPushTargets ) == 0 ) {
 120+ $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsg( 'push-tab-no-targets' ) ) . '</p>' );
 121+ return false;
 122+ }
118123
119 - $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsg( 'push-button-desc' ) ) . '</p>' );
 124+ self::loadJs();
120125
121126 $wgOut->addHTML(
122127 Html::hidden( 'pageName', $wgTitle->getFullText(), array( 'id' => 'pageName' ) ) .
123128 Html::hidden( 'siteName', $wgSitename, array( 'id' => 'siteName' ) )
124129 );
125130
126 - self::displayPushList();
 131+ if ( count( $egPushTargets ) == 1 ) {
 132+ self::displayLonelyPushItem();
 133+ }
 134+ else {
 135+ self::displayPushList();
 136+ }
127137
128138 if ( $wgUser->isAllowed( 'pushadmin' ) ) {
129139 // TODO
@@ -133,40 +143,93 @@
134144 }
135145
136146 /**
 147+ * Displays a target to push to for when there is only a single target.
 148+ *
 149+ * @since 0.1
 150+ */
 151+ protected static function displayLonelyPushItem() {
 152+ global $wgOut, $egPushTargets;
 153+
 154+ $targetNames = array_keys( $egPushTargets );
 155+
 156+ $wgOut->addHTML( '<b>' . htmlspecialchars( wfMsgExt( 'push-tab-push-to', 'parsemag', $targetNames[0] ) ) . '</b>&nbsp;&nbsp;' );
 157+
 158+ $wgOut->addHTML(
 159+ Html::element(
 160+ 'button',
 161+ array(
 162+ 'class' => 'push-button',
 163+ 'pushtarget' => $egPushTargets[$targetNames[0]],
 164+ 'style' => 'width: 125px; height: 30px',
 165+ ),
 166+ wfMsg( 'push-button-text' )
 167+ )
 168+ );
 169+ }
 170+
 171+ /**
137172 * Displays a list with all targets to which can be pushed.
138173 *
139174 * @since 0.1
140175 */
141176 protected static function displayPushList() {
142 - global $wgOut, $egPushTargets;
 177+ global $wgOut, $egPushTargets, $wgLang;
143178
144 - $wgOut->addHtml(
145 - Html::element(
146 - 'h2',
 179+ $items = array(
 180+ Html::rawElement(
 181+ 'tr',
147182 array(),
148 - wfMsg( 'push-targets' )
 183+ Html::element(
 184+ 'th',
 185+ array(),
 186+ wfMsg( 'push-targets' )
 187+ ) .
 188+ Html::rawElement(
 189+ 'th',
 190+ array(),
 191+ wfMsg( 'push-remote-pages' )
 192+ ) .
 193+ Html::rawElement(
 194+ 'th',
 195+ array( 'width' => '125px' ),
 196+ ''
 197+ )
149198 )
150199 );
151200
152 - $items = array();
153 -
154201 foreach ( $egPushTargets as $name => $url ) {
155202 $items[] = self::getPushItem( $name, $url );
156203 }
157204
158 - if ( count( $items ) > 1 ) {
159 - $items = array_merge( array(
160 - // TODO: header here
161 - ), $items );
162 - }
 205+ $items[] = Html::rawElement(
 206+ 'tr',
 207+ array(),
 208+ Html::element(
 209+ 'th',
 210+ array( 'colspan' => 2, 'style' => 'text-align: left' ),
 211+ wfMsgExt( 'push-targets-total', 'parsemag', $wgLang->formatNum( count( $egPushTargets ) ) )
 212+ ) .
 213+ Html::rawElement(
 214+ 'th',
 215+ array( 'width' => '125px' ),
 216+ Html::element(
 217+ 'button',
 218+ array(
 219+ 'id' => 'push-all-button',
 220+ 'style' => 'width: 125px; height: 30px',
 221+ ),
 222+ wfMsg( 'push-button-all' )
 223+ )
 224+ )
 225+ );
163226
164227 $wgOut->addHtml(
165228 Html::rawElement(
166229 'table',
167 - array( 'width' => '100%' ),
 230+ array( 'class' => 'wikitable', 'width' => '50%' ),
168231 implode( "\n", $items )
169232 )
170 - );
 233+ );
171234 }
172235
173236 /**
@@ -180,6 +243,8 @@
181244 * @return string
182245 */
183246 protected static function getPushItem( $name, $url ) {
 247+ global $wgTitle;
 248+
184249 return Html::rawElement(
185250 'tr',
186251 array(),
@@ -192,10 +257,20 @@
193258 'td',
194259 array(),
195260 Html::element(
 261+ 'a',
 262+ array( 'href' => $url . '/index.php?title=' . $wgTitle->getFullText(), 'rel' => 'nofollow' ),
 263+ wfMsgExt( 'push-remote-page-link', 'parsemag', $wgTitle->getFullText(), $name )
 264+ )
 265+ ) .
 266+ Html::rawElement(
 267+ 'td',
 268+ array(),
 269+ Html::element(
196270 'button',
197271 array(
198272 'class' => 'push-button',
199273 'pushtarget' => $url,
 274+ 'style' => 'width: 125px; height: 30px',
200275 ),
201276 wfMsg( 'push-button-text' )
202277 )
Index: trunk/extensions/Push/includes/ext.push.tab.js
@@ -27,6 +27,14 @@
2828 );
2929 });
3030
 31+ $('#push-all-button').click(function() {
 32+ this.disabled = true;
 33+ this.innerHTML = mediaWiki.msg( 'push-button-pushing' );
 34+ $.each($(".push-button"), function(i,v) {
 35+ $(v).click();
 36+ });
 37+ });
 38+
3139 function getLocalArtcileAndContinue( sender, targetUrl ) {
3240 var pageName = $('#pageName').attr('value');
3341
@@ -158,11 +166,36 @@
159167 }
160168 else {
161169 sender.innerHTML = mediaWiki.msg( 'push-button-completed' );
 170+ setTimeout( function() {reEnableButton( sender );}, 2000 );
162171 }
163172 }
164 - );
 173+ );
165174 }
166175
 176+ function reEnableButton( button ) {
 177+ button.innerHTML = mediaWiki.msg( 'push-button-text' );
 178+ button.disabled = false;
 179+
 180+ var pushAllButton = $('#push-all-button');
 181+
 182+ // If there is a "push all" button, make sure to reset it
 183+ // when all other buttons have been reset.
 184+ if ( typeof pushAllButton !== "undefined" ) {
 185+ var hasDisabled = false;
 186+
 187+ $.each($(".push-button"), function(i,v) {
 188+ if ( v.disabled ) {
 189+ hasDisabled = true;
 190+ }
 191+ });
 192+
 193+ if ( !hasDisabled ) {
 194+ pushAllButton.attr( "disabled", false );
 195+ pushAllButton.text( mediaWiki.msg( 'push-button-all' ) );
 196+ }
 197+ }
 198+ }
 199+
167200 function handleError( sender, targetUrl, error ) {
168201 alert( error.info );
169202 sender.innerHTML = mediaWiki.msg( 'push-button-failed' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r77966Follow up to r77965jeroendedauw09:51, 7 December 2010
r78035Follow up to r77965jeroendedauw01:02, 8 December 2010

Comments

#Comment by Nikerabbit (talk | contribs)   13:26, 7 December 2010

+ 'push-targets-total' => 'There are $1 targets in total.', // $1 will always be plural We have adopted a practice to use {{PLURAL}} syntax in the source message always, when it is needed in translations.

push-remote-pages is an unescaped message.

Status & tagging log