Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -68,7 +68,11 @@ |
69 | 69 | 'push-special-push-done' => 'Push completed', |
70 | 70 | 'push-special-err-token-failed' => 'Could not obtain an edit token on the target wiki.', |
71 | 71 | 'push-special-err-pageget-failed' => 'Could not obtain local page content.', |
72 | | - 'push-special-err-push-failed' => 'Target wiki refused the pushed page.' |
| 72 | + 'push-special-err-push-failed' => 'Target wiki refused the pushed page.', |
| 73 | + 'push-special-inc-files' => 'Include files', |
| 74 | + 'push-special-err-imginfo-failed' => 'Could not determine if any files needed to be pushed.', |
| 75 | + 'push-special-obtaining-fileinfo' => '$1: Obtaining file information.', |
| 76 | + 'push-special-pushing-file' => '$1: Pushing file $2.', |
73 | 77 | ); |
74 | 78 | |
75 | 79 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Push/specials/Push_Body.php |
— | — | @@ -177,7 +177,8 @@ |
178 | 178 | 'var wgPushPages = ' . json_encode( $pages ) . ';' . |
179 | 179 | 'var wgPushTargets = ' . json_encode( $targets ) . ';' . |
180 | 180 | 'var wgPushWorkerCount = ' . $egPushBulkWorkers . ';' . |
181 | | - 'var wgPushBatchSize = ' . $egPushBatchSize . ';' |
| 181 | + 'var wgPushBatchSize = ' . $egPushBatchSize . ';' . |
| 182 | + 'var wgPushIncFiles = ' . ( $wgRequest->getCheck( 'files' ) ? 'true' : 'false' ) . ';' |
182 | 183 | ); |
183 | 184 | |
184 | 185 | $this->loadJs(); |
— | — | @@ -187,7 +188,7 @@ |
188 | 189 | * @since 0.2 |
189 | 190 | */ |
190 | 191 | protected function displayPushInterface( $arg, $pages ) { |
191 | | - global $wgOut, $wgUser, $wgRequest, $egPushTargets; |
| 192 | + global $wgOut, $wgUser, $wgRequest, $egPushTargets, $egPushIncTemplates, $egPushIncFiles; |
192 | 193 | |
193 | 194 | $wgOut->addWikiMsg( 'push-special-description' ); |
194 | 195 | |
— | — | @@ -205,10 +206,19 @@ |
206 | 207 | $form .= Xml::checkLabel( |
207 | 208 | wfMsg( 'export-templates' ), |
208 | 209 | 'templates', |
209 | | - 'wpExportTemplates', |
210 | | - $wgRequest->wasPosted() ? $wgRequest->getCheck( 'templates' ) : false |
| 210 | + 'wpPushTemplates', |
| 211 | + $wgRequest->wasPosted() ? $wgRequest->getCheck( 'templates' ) : $egPushIncTemplates |
211 | 212 | ) . '<br />'; |
212 | 213 | |
| 214 | + if ( $wgUser->isAllowed( 'filepush' ) ) { |
| 215 | + $form .= Xml::checkLabel( |
| 216 | + wfMsg( 'push-special-inc-files' ), |
| 217 | + 'files', |
| 218 | + 'wpPushFiles', |
| 219 | + $wgRequest->wasPosted() ? $wgRequest->getCheck( 'files' ) : $egPushIncFiles |
| 220 | + ) . '<br />'; |
| 221 | + } |
| 222 | + |
213 | 223 | if ( count( $egPushTargets ) == 1 ) { |
214 | 224 | $names = array_keys( $egPushTargets ); |
215 | 225 | $form .= '<b>' . htmlspecialchars( wfMsgExt( 'push-special-target-is', 'parsemag', $names[0] ) ) . '</b><br />'; |
Index: trunk/extensions/Push/specials/ext.push.special.js |
— | — | @@ -33,6 +33,8 @@ |
34 | 34 | var requestAmount = Math.min( pages.length, window.wgPushWorkerCount ); |
35 | 35 | var batchSize = Math.min( targets.length, window.wgPushBatchSize ); |
36 | 36 | |
| 37 | + var pushedFiles = []; |
| 38 | + |
37 | 39 | for ( i = requestAmount; i > 0; i-- ) { |
38 | 40 | initiateNextPush(); |
39 | 41 | } |
— | — | @@ -86,7 +88,7 @@ |
87 | 89 | } |
88 | 90 | else if ( data.length > 0 && data[0].edit && data[0].edit.captcha ) { |
89 | 91 | handleError( listItem, pageName, { info: mediaWiki.msg( 'push-err-captcha-page', pageName ) } ); |
90 | | - } |
| 92 | + } |
91 | 93 | else { |
92 | 94 | startPush( pageName, targetOffset, listItem ); |
93 | 95 | } |
— | — | @@ -94,20 +96,125 @@ |
95 | 97 | ); |
96 | 98 | } |
97 | 99 | else { |
98 | | - listItem.text( mediaWiki.msg( 'push-special-item-completed', pageName ) ); |
99 | | - listItem.css( 'color', 'darkgray' ); |
100 | | - initiateNextPush(); |
| 100 | + if ( window.wgPushIncFiles ) { |
| 101 | + getIncludedImagesAndInitPush( pageName, listItem ); |
| 102 | + } |
| 103 | + else { |
| 104 | + completeItem( pageName, listItem ); |
| 105 | + } |
101 | 106 | } |
102 | 107 | } |
103 | 108 | |
104 | | - function showCompletion() { |
105 | | - resultList.append( $( '<li />' ).append( $( '<b />' ).text( mediaWiki.msg( 'push-special-push-done' ) ) ) ); |
| 109 | + function getIncludedImagesAndInitPush( pageName, listItem ) { |
| 110 | + listItem.text( mediaWiki.msg( 'push-special-obtaining-fileinfo', pageName ) ); |
| 111 | + |
| 112 | + $.getJSON( |
| 113 | + wgScriptPath + '/api.php', |
| 114 | + { |
| 115 | + 'action': 'query', |
| 116 | + 'prop': 'images', |
| 117 | + 'format': 'json', |
| 118 | + 'titles': pageName, |
| 119 | + }, |
| 120 | + function( data ) { |
| 121 | + if ( data.query ) { |
| 122 | + var images = []; |
| 123 | + |
| 124 | + for ( page in data.query.pages ) { |
| 125 | + for ( var i = data.query.pages[page].images.length - 1; i >= 0; i-- ) { |
| 126 | + if ( $.inArray( data.query.pages[page].images[i].title, pushedFiles ) == -1 ) { |
| 127 | + pushedFiles.push( data.query.pages[page].images[i].title ); |
| 128 | + images.push( data.query.pages[page].images[i].title ); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + if ( images.length > 0 ) { |
| 134 | + var currentFile = images.pop(); |
| 135 | + startFilePush( pageName, images, 0, listItem, currentFile ); |
| 136 | + } |
| 137 | + else { |
| 138 | + completeItem( pageName, listItem ); |
| 139 | + } |
| 140 | + } |
| 141 | + else { |
| 142 | + handleError( pageName, { info: mediaWiki.msg( 'push-special-err-imginfo-failed' ) } ); |
| 143 | + } |
| 144 | + } |
| 145 | + ); |
106 | 146 | } |
107 | 147 | |
| 148 | + function startFilePush( pageName, images, targetOffset, listItem, fileName ) { |
| 149 | + if ( targetOffset == 0 ) { |
| 150 | + listItem.text( mediaWiki.msg( 'push-special-pushing-file', pageName, fileName ) ); |
| 151 | + } |
| 152 | + else { |
| 153 | + listItem.text( listItem.text() + '...' ); |
| 154 | + } |
| 155 | + |
| 156 | + var currentBatchLimit = Math.min( targetOffset + batchSize, targets.length ); |
| 157 | + var currentBatchStart = targetOffset; |
| 158 | + |
| 159 | + if ( targetOffset < targets.length ) { |
| 160 | + listItem.text( listItem.text() + '...' ); |
| 161 | + |
| 162 | + targetOffset = currentBatchLimit; |
| 163 | + |
| 164 | + $.getJSON( |
| 165 | + wgScriptPath + '/api.php', |
| 166 | + { |
| 167 | + 'action': 'pushimages', |
| 168 | + 'format': 'json', |
| 169 | + 'images': fileName, |
| 170 | + 'targets': targets.slice( currentBatchStart, currentBatchLimit ).join( '|' ) |
| 171 | + }, |
| 172 | + function( data ) { |
| 173 | + var fail = false; |
| 174 | + |
| 175 | + for ( i in data.upload ) { |
| 176 | + if ( data.error ) { |
| 177 | + handleError( pageName, data.error ); |
| 178 | + fail = true; |
| 179 | + break; |
| 180 | + } |
| 181 | + else if ( !data.upload ) { |
| 182 | + handleError( pageName, { info: 'Unknown error' } ); // TODO |
| 183 | + fail = true; |
| 184 | + break; |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + if ( !fail ) { |
| 189 | + startFilePush( pageName, images, targetOffset, listItem, fileName ); |
| 190 | + } |
| 191 | + } |
| 192 | + ); |
| 193 | + } |
| 194 | + else { |
| 195 | + if ( images.length > 0 ) { |
| 196 | + var currentFile = images.pop(); |
| 197 | + startFilePush( pageName, images, 0, listItem, currentFile ); |
| 198 | + } |
| 199 | + else { |
| 200 | + completeItem( pageName, listItem ); |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + function completeItem( pageName, listItem ) { |
| 206 | + listItem.text( mediaWiki.msg( 'push-special-item-completed', pageName ) ); |
| 207 | + listItem.css( 'color', 'darkgray' ); |
| 208 | + initiateNextPush(); |
| 209 | + } |
| 210 | + |
108 | 211 | function handleError( listItem, pageName, error ) { |
109 | 212 | listItem.text( mediaWiki.msg( 'push-special-item-failed', pageName, error.info ) ); |
110 | 213 | listItem.css( 'color', 'darkred' ); |
111 | 214 | initiateNextPush(); |
| 215 | + } |
| 216 | + |
| 217 | + function showCompletion() { |
| 218 | + resultList.append( $( '<li />' ).append( $( '<b />' ).text( mediaWiki.msg( 'push-special-push-done' ) ) ) ); |
112 | 219 | } |
113 | 220 | |
114 | 221 | } ); })(jQuery); |
\ No newline at end of file |
Index: trunk/extensions/Push/Push.php |
— | — | @@ -82,6 +82,9 @@ |
83 | 83 | 'push-tab-not-created', |
84 | 84 | 'push-err-captcha-page', |
85 | 85 | 'push-button-pushing-files', |
| 86 | + 'push-special-err-imginfo-failed', |
| 87 | + 'push-special-obtaining-fileinfo', |
| 88 | + 'push-special-pushing-file', |
86 | 89 | ); |
87 | 90 | |
88 | 91 | // For backward compatibility with MW < 1.17. |
Index: trunk/extensions/Push/RELEASE-NOTES |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | === Version 0.5 === |
9 | 9 | 2010-12-xx |
10 | 10 | |
11 | | -* Added support for image-pushing. |
| 11 | +* Added support for file-pushing. |
12 | 12 | |
13 | 13 | === Version 0.4 === |
14 | 14 | 2010-12-12 |