Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | // Tab |
22 | 22 | 'push-tab-text' => 'Push', |
23 | 23 | '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.', |
25 | 25 | 'push-button-pushing' => 'Pushing', |
26 | 26 | 'push-button-completed' => 'Push completed', |
27 | 27 | 'push-button-failed' => 'Push failed', |
— | — | @@ -29,6 +29,12 @@ |
30 | 30 | 'push-add-target' => 'Add target', |
31 | 31 | 'push-import-revision-message' => 'Import from $1 by $2.$3', // $3 is 'push-import-revision-comment' or empty. 1360! |
32 | 32 | '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', |
33 | 39 | |
34 | 40 | // Special page |
35 | 41 | 'special-push' => 'Push pages', |
Index: trunk/extensions/Push/Push.php |
— | — | @@ -64,6 +64,8 @@ |
65 | 65 | 'push-button-failed', |
66 | 66 | 'push-import-revision-message', |
67 | 67 | 'push-import-revision-comment', |
| 68 | + 'push-button-text', |
| 69 | + 'push-button-all', |
68 | 70 | ); |
69 | 71 | |
70 | 72 | // For backward compatibility with MW < 1.17. |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -104,25 +104,35 @@ |
105 | 105 | * @since 0.1 |
106 | 106 | */ |
107 | 107 | public static function displayPushPage( Article $article ) { |
108 | | - global $wgOut, $wgUser, $wgTitle, $wgSitename; |
| 108 | + global $wgOut, $wgUser, $wgTitle, $wgSitename, $egPushTargets; |
109 | 109 | |
| 110 | + $wgOut->setPageTitle( wfMsgExt( 'push-tab-title', 'parsemag', $article->getTitle()->getText() ) ); |
| 111 | + |
110 | 112 | if ( !$wgUser->isAllowed( 'push' ) ) { |
111 | 113 | $wgOut->permissionRequired( 'push' ); |
112 | 114 | return false; |
113 | 115 | } |
114 | 116 | |
115 | | - self::loadJs(); |
| 117 | + $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsg( 'push-tab-desc' ) ) . '</p>' ); |
116 | 118 | |
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 | + } |
118 | 123 | |
119 | | - $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsg( 'push-button-desc' ) ) . '</p>' ); |
| 124 | + self::loadJs(); |
120 | 125 | |
121 | 126 | $wgOut->addHTML( |
122 | 127 | Html::hidden( 'pageName', $wgTitle->getFullText(), array( 'id' => 'pageName' ) ) . |
123 | 128 | Html::hidden( 'siteName', $wgSitename, array( 'id' => 'siteName' ) ) |
124 | 129 | ); |
125 | 130 | |
126 | | - self::displayPushList(); |
| 131 | + if ( count( $egPushTargets ) == 1 ) { |
| 132 | + self::displayLonelyPushItem(); |
| 133 | + } |
| 134 | + else { |
| 135 | + self::displayPushList(); |
| 136 | + } |
127 | 137 | |
128 | 138 | if ( $wgUser->isAllowed( 'pushadmin' ) ) { |
129 | 139 | // TODO |
— | — | @@ -133,40 +143,93 @@ |
134 | 144 | } |
135 | 145 | |
136 | 146 | /** |
| 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> ' ); |
| 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 | + /** |
137 | 172 | * Displays a list with all targets to which can be pushed. |
138 | 173 | * |
139 | 174 | * @since 0.1 |
140 | 175 | */ |
141 | 176 | protected static function displayPushList() { |
142 | | - global $wgOut, $egPushTargets; |
| 177 | + global $wgOut, $egPushTargets, $wgLang; |
143 | 178 | |
144 | | - $wgOut->addHtml( |
145 | | - Html::element( |
146 | | - 'h2', |
| 179 | + $items = array( |
| 180 | + Html::rawElement( |
| 181 | + 'tr', |
147 | 182 | 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 | + ) |
149 | 198 | ) |
150 | 199 | ); |
151 | 200 | |
152 | | - $items = array(); |
153 | | - |
154 | 201 | foreach ( $egPushTargets as $name => $url ) { |
155 | 202 | $items[] = self::getPushItem( $name, $url ); |
156 | 203 | } |
157 | 204 | |
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 | + ); |
163 | 226 | |
164 | 227 | $wgOut->addHtml( |
165 | 228 | Html::rawElement( |
166 | 229 | 'table', |
167 | | - array( 'width' => '100%' ), |
| 230 | + array( 'class' => 'wikitable', 'width' => '50%' ), |
168 | 231 | implode( "\n", $items ) |
169 | 232 | ) |
170 | | - ); |
| 233 | + ); |
171 | 234 | } |
172 | 235 | |
173 | 236 | /** |
— | — | @@ -180,6 +243,8 @@ |
181 | 244 | * @return string |
182 | 245 | */ |
183 | 246 | protected static function getPushItem( $name, $url ) { |
| 247 | + global $wgTitle; |
| 248 | + |
184 | 249 | return Html::rawElement( |
185 | 250 | 'tr', |
186 | 251 | array(), |
— | — | @@ -192,10 +257,20 @@ |
193 | 258 | 'td', |
194 | 259 | array(), |
195 | 260 | 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( |
196 | 270 | 'button', |
197 | 271 | array( |
198 | 272 | 'class' => 'push-button', |
199 | 273 | 'pushtarget' => $url, |
| 274 | + 'style' => 'width: 125px; height: 30px', |
200 | 275 | ), |
201 | 276 | wfMsg( 'push-button-text' ) |
202 | 277 | ) |
Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -27,6 +27,14 @@ |
28 | 28 | ); |
29 | 29 | }); |
30 | 30 | |
| 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 | + |
31 | 39 | function getLocalArtcileAndContinue( sender, targetUrl ) { |
32 | 40 | var pageName = $('#pageName').attr('value'); |
33 | 41 | |
— | — | @@ -158,11 +166,36 @@ |
159 | 167 | } |
160 | 168 | else { |
161 | 169 | sender.innerHTML = mediaWiki.msg( 'push-button-completed' ); |
| 170 | + setTimeout( function() {reEnableButton( sender );}, 2000 ); |
162 | 171 | } |
163 | 172 | } |
164 | | - ); |
| 173 | + ); |
165 | 174 | } |
166 | 175 | |
| 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 | + |
167 | 200 | function handleError( sender, targetUrl, error ) { |
168 | 201 | alert( error.info ); |
169 | 202 | sender.innerHTML = mediaWiki.msg( 'push-button-failed' ); |