Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -50,6 +50,7 @@ |
51 | 51 | 'push-tab-inc-templates' => 'Include templates', |
52 | 52 | 'push-tab-used-templates' => '(Used {{PLURAL:$2|template|templates}}: $1)', |
53 | 53 | 'push-tab-no-used-templates' => '(No templates are used on this page.)', |
| 54 | + 'push-tab-inc-files' => 'Include files', |
54 | 55 | |
55 | 56 | // Special page |
56 | 57 | 'special-push' => 'Push pages', |
Index: trunk/extensions/Push/Push.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | die( 'Not an entry point.' ); |
24 | 24 | } |
25 | 25 | |
26 | | -define( 'Push_VERSION', '0.4 alpha' ); |
| 26 | +define( 'Push_VERSION', '0.5 alpha' ); |
27 | 27 | |
28 | 28 | $wgExtensionCredits['other'][] = array( |
29 | 29 | 'path' => __FILE__, |
— | — | @@ -45,6 +45,7 @@ |
46 | 46 | |
47 | 47 | $wgAutoloadClasses['PushHooks'] = $egPushIP . '/Push.hooks.php'; |
48 | 48 | $wgAutoloadClasses['ApiPush'] = $egPushIP . '/api/ApiPush.php'; |
| 49 | +$wgAutoloadClasses['ApiPushImages'] = $egPushIP . '/api/ApiPushImages.php'; |
49 | 50 | $wgAutoloadClasses['PushTab'] = $egPushIP . '/includes/Push_Tab.php'; |
50 | 51 | $wgAutoloadClasses['PushFunctions'] = $egPushIP . '/includes/Push_Functions.php'; |
51 | 52 | $wgAutoloadClasses['SpecialPush'] = $egPushIP . '/specials/Push_Body.php'; |
— | — | @@ -53,6 +54,7 @@ |
54 | 55 | $wgSpecialPageGroups['Push'] = 'pagetools'; |
55 | 56 | |
56 | 57 | $wgAPIModules['push'] = 'ApiPush'; |
| 58 | +$wgAPIModules['pushimages'] = 'ApiPushImages'; |
57 | 59 | |
58 | 60 | $wgHooks['UnknownAction'][] = 'PushTab::onUnknownAction'; |
59 | 61 | $wgHooks['SkinTemplateTabs'][] = 'PushTab::displayTab'; |
Index: trunk/extensions/Push/Push_Settings.php |
— | — | @@ -28,6 +28,8 @@ |
29 | 29 | $wgGroupPermissions['autoconfirmed']['bulkpush'] = true; |
30 | 30 | $wgGroupPermissions['sysop']['bulkpush'] = true; |
31 | 31 | $wgGroupPermissions['sysop']['pushadmin'] = true; |
| 32 | +$wgGroupPermissions['autoconfirmed']['filepush'] = true; |
| 33 | +$wgGroupPermissions['sysop']['filepush'] = true; |
32 | 34 | |
33 | 35 | # Show the push action as a tab (if not, it's displayed in the actions dropdown). |
34 | 36 | # This only works for skins with an actions dropdown. For others push will always appear as a tab. |
— | — | @@ -37,6 +39,10 @@ |
38 | 40 | # This is the default choice. |
39 | 41 | $egPushIncTemplates = false; |
40 | 42 | |
| 43 | +# You can choose to push files used in a page. |
| 44 | +# This is the default choice. |
| 45 | +$egPushIncFiles = false; |
| 46 | + |
41 | 47 | # Indicated if login options should be added to the push interface or not. |
42 | 48 | $egPushAllowLogin = true; |
43 | 49 | |
Index: trunk/extensions/Push/RELEASE-NOTES |
— | — | @@ -4,6 +4,11 @@ |
5 | 5 | Latest version of the release notes: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Push/RELEASE-NOTES?view=co |
6 | 6 | |
7 | 7 | |
| 8 | +=== Version 0.5 === |
| 9 | +2010-12-xx |
| 10 | + |
| 11 | +* Added support for image-pushing. |
| 12 | + |
8 | 13 | === Version 0.4 === |
9 | 14 | 2010-12-12 |
10 | 15 | |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -270,10 +270,25 @@ |
271 | 271 | * @since 0.4 |
272 | 272 | */ |
273 | 273 | protected static function displayPushOptions() { |
274 | | - global $wgOut, $wgTitle, $wgLang, $egPushIncTemplates; |
| 274 | + global $wgOut, $wgUser; |
275 | 275 | |
276 | 276 | $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'push-tab-push-options' ) ) . '</h3>' ); |
277 | 277 | |
| 278 | + self::displayIncTemplatesOption(); |
| 279 | + |
| 280 | + if ( $wgUser->isAllowed( 'filepush' ) ) { |
| 281 | + self::displayIncFilesOption(); |
| 282 | + } |
| 283 | + } |
| 284 | + |
| 285 | + /** |
| 286 | + * Outputs the HTML for the "include templates" option. |
| 287 | + * |
| 288 | + * @since 0.4 |
| 289 | + */ |
| 290 | + protected static function displayIncTemplatesOption() { |
| 291 | + global $wgOut, $wgTitle, $wgLang, $egPushIncTemplates; |
| 292 | + |
278 | 293 | $usedTemplates = array_keys( |
279 | 294 | PushFunctions::getTemplates( |
280 | 295 | array( $wgTitle->getFullText() ), |
— | — | @@ -310,7 +325,29 @@ |
311 | 326 | htmlspecialchars( wfMsg( 'push-tab-no-used-templates' ) ) |
312 | 327 | ) |
313 | 328 | ) |
314 | | - ); |
| 329 | + ); |
315 | 330 | } |
316 | 331 | |
| 332 | + /** |
| 333 | + * Outputs the HTML for the "include files" option. |
| 334 | + * |
| 335 | + * @since 0.4 |
| 336 | + */ |
| 337 | + protected static function displayIncFilesOption() { |
| 338 | + global $wgOut, $wgTitle, $egPushIncFiles; |
| 339 | + |
| 340 | + $wgOut->addHTML( |
| 341 | + Html::rawElement( |
| 342 | + 'div', |
| 343 | + array( 'id' => 'divIncFiles' ), |
| 344 | + Xml::check( 'checkIncFiles', $egPushIncFiles, array( 'id' => 'checkIncFiles' ) ) . |
| 345 | + Html::element( |
| 346 | + 'label', |
| 347 | + array( 'id' => 'lblIncFiles', 'for' => 'checkIncFiles' ), |
| 348 | + wfMsg( 'push-tab-inc-files' ) |
| 349 | + ) |
| 350 | + ) |
| 351 | + ); |
| 352 | + } |
| 353 | + |
317 | 354 | } |
\ No newline at end of file |
Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -23,6 +23,11 @@ |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
| 27 | + var pages; |
| 28 | + var imageRequestMade = false; |
| 29 | + var images = false; |
| 30 | + var imagePushRequests = []; |
| 31 | + |
27 | 32 | $.each($(".push-button"), function(i,v) { |
28 | 33 | getRemoteArticleInfo( $(v).attr( 'targetid' ), $(v).attr( 'pushtarget' ) ); |
29 | 34 | }); |
— | — | @@ -31,12 +36,12 @@ |
32 | 37 | this.disabled = true; |
33 | 38 | this.innerHTML = mediaWiki.msg( 'push-button-pushing' ); |
34 | 39 | |
35 | | - if ( $('#checkIncTemplates:checked').attr('checked') ) { |
36 | | - var pages = window.wgPushTemplates; |
| 40 | + if ( $('#checkIncTemplates').attr('checked') ) { |
| 41 | + pages = window.wgPushTemplates; |
37 | 42 | pages.unshift( $('#pageName').attr('value') ); |
38 | 43 | } |
39 | 44 | else { |
40 | | - var pages = [$('#pageName').attr('value')]; |
| 45 | + pages = [$('#pageName').attr('value')]; |
41 | 46 | } |
42 | 47 | |
43 | 48 | initiatePush( |
— | — | @@ -45,6 +50,10 @@ |
46 | 51 | $(this).attr( 'pushtarget' ), |
47 | 52 | $(this).attr( 'targetname' ) |
48 | 53 | ); |
| 54 | + |
| 55 | + if ( $('#checkIncFiles').length != 0 && $('#checkIncFiles').attr('checked') && !imageRequestMade ) { |
| 56 | + getIncludedImages(); |
| 57 | + } |
49 | 58 | }); |
50 | 59 | |
51 | 60 | $('#push-all-button').click(function() { |
— | — | @@ -125,13 +134,13 @@ |
126 | 135 | } |
127 | 136 | else { |
128 | 137 | sender.innerHTML = mediaWiki.msg( 'push-button-completed' ); |
129 | | - setTimeout( function() {reEnableButton( sender );}, 1000 ); |
| 138 | + setTimeout( function() {reEnableButton( sender, targetUrl, targetName );}, 1000 ); |
130 | 139 | } |
131 | 140 | } |
132 | 141 | ); |
133 | 142 | } |
134 | 143 | |
135 | | - function reEnableButton( button ) { |
| 144 | + function reEnableButton( button, targetUrl, targetName ) { |
136 | 145 | button.innerHTML = mediaWiki.msg( 'push-button-text' ); |
137 | 146 | button.disabled = false; |
138 | 147 | |
— | — | @@ -139,7 +148,11 @@ |
140 | 149 | |
141 | 150 | // If there is a "push all" button, make sure to reset it |
142 | 151 | // when all other buttons have been reset. |
143 | | - if ( typeof pushAllButton !== "undefined" ) { |
| 152 | + if ( typeof pushAllButton === "undefined" ) { |
| 153 | + imagePushRequests.push( { 'sender': button, 'targetUrl': targetUrl, 'targetName': targetName } ); |
| 154 | + startImagesPush(); |
| 155 | + } |
| 156 | + else { |
144 | 157 | var hasDisabled = false; |
145 | 158 | |
146 | 159 | $.each($(".push-button"), function(i,v) { |
— | — | @@ -151,10 +164,77 @@ |
152 | 165 | if ( !hasDisabled ) { |
153 | 166 | pushAllButton.attr( "disabled", false ); |
154 | 167 | pushAllButton.text( mediaWiki.msg( 'push-button-all' ) ); |
| 168 | + |
| 169 | + imagePushRequests.push( { 'sender': button, 'targetUrl': targetUrl, 'targetName': targetName } ); |
| 170 | + startImagesPush(); |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + function getIncludedImages() { |
| 176 | + imageRequestMade = true; |
| 177 | + |
| 178 | + $.getJSON( |
| 179 | + wgScriptPath + '/api.php', |
| 180 | + { |
| 181 | + 'action': 'query', |
| 182 | + 'prop': 'images', |
| 183 | + 'format': 'json', |
| 184 | + 'titles': pages.join( '|' ), |
| 185 | + }, |
| 186 | + function( data ) { |
| 187 | + if ( data.query ) { |
| 188 | + images = []; |
| 189 | + |
| 190 | + for ( page in data.query.pages ) { |
| 191 | + for ( var i = data.query.pages[page].images.length - 1; i >= 0; i-- ) { |
| 192 | + if ( $.inArray( data.query.pages[page].images[i].title, images ) == -1 ) { |
| 193 | + images.push( data.query.pages[page].images[i].title ); |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + startImagesPush(); |
| 199 | + } |
| 200 | + else { |
| 201 | + // TODO |
| 202 | + } |
155 | 203 | } |
| 204 | + ); |
| 205 | + } |
| 206 | + |
| 207 | + function startImagesPush() { |
| 208 | + if ( images !== false ) { |
| 209 | + var req; |
| 210 | + while ( req = imagePushRequests.pop() ) { |
| 211 | + initiateImagePush( req.sender, req.targetUrl, req.targetName ); |
| 212 | + } |
156 | 213 | } |
157 | 214 | } |
158 | 215 | |
| 216 | + function initiateImagePush( sender, targetUrl, targetName ) { |
| 217 | + $.getJSON( |
| 218 | + wgScriptPath + '/api.php', |
| 219 | + { |
| 220 | + 'action': 'pushimages', |
| 221 | + 'format': 'json', |
| 222 | + 'images': images.join( '|' ), |
| 223 | + 'targets': targetUrl |
| 224 | + }, |
| 225 | + function( data ) { |
| 226 | + if ( data.upload ) { |
| 227 | + |
| 228 | + } |
| 229 | + else if ( data.error ) { |
| 230 | + // TODO |
| 231 | + } |
| 232 | + else { |
| 233 | + // TODO |
| 234 | + } |
| 235 | + } |
| 236 | + ); |
| 237 | + } |
| 238 | + |
159 | 239 | function handleError( sender, targetUrl, error ) { |
160 | 240 | alert( error.info ); |
161 | 241 | sender.innerHTML = mediaWiki.msg( 'push-button-failed' ); |
Index: trunk/extensions/Push/api/ApiPush.php |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | * |
104 | 104 | * @param string $user |
105 | 105 | * @param string $password |
106 | | - * @param string $targets |
| 106 | + * @param string $target |
107 | 107 | * @param string $token |
108 | 108 | * @param CookieJar $cookie |
109 | 109 | */ |
— | — | @@ -368,14 +368,14 @@ |
369 | 369 | |
370 | 370 | public function getParamDescription() { |
371 | 371 | return array( |
372 | | - 'page' => 'The name of the page to push.', |
373 | | - 'targets' => 'The urls of the wikis to push to.', |
| 372 | + 'page' => 'The names of the page to push. Delimitered by |', |
| 373 | + 'targets' => 'The urls of the wikis to push to. Delimitered by |', |
374 | 374 | ); |
375 | 375 | } |
376 | 376 | |
377 | 377 | public function getDescription() { |
378 | 378 | return array( |
379 | | - 'Pushes page contnet to other wikis.' |
| 379 | + 'Pushes the content of one ore more pages to one or more target wikis.' |
380 | 380 | ); |
381 | 381 | } |
382 | 382 | |
Index: trunk/extensions/Push/api/ApiPushImages.php |
— | — | @@ -0,0 +1,316 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to push images to other MediaWiki wikis. |
| 6 | + * |
| 7 | + * @since 0.5 |
| 8 | + * |
| 9 | + * @file ApiPushImages.php |
| 10 | + * @ingroup Push |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 13 | + */ |
| 14 | +class ApiPushImages extends ApiBase { |
| 15 | + |
| 16 | + /** |
| 17 | + * Associative array containing CookieJar objects (values) to be passed in |
| 18 | + * order to autenticate to the targets (keys). |
| 19 | + * |
| 20 | + * @since 0.5 |
| 21 | + * |
| 22 | + * @var array |
| 23 | + */ |
| 24 | + protected $cookieJars = array(); |
| 25 | + |
| 26 | + public function __construct( $main, $action ) { |
| 27 | + parent::__construct( $main, $action ); |
| 28 | + } |
| 29 | + |
| 30 | + public function execute() { |
| 31 | + global $egPushLoginUser, $egPushLoginPass, $egPushLoginUsers, $egPushLoginPasswords; |
| 32 | + |
| 33 | + $params = $this->extractRequestParams(); |
| 34 | + |
| 35 | + if ( !isset( $params['images'] ) ) { |
| 36 | + $this->dieUsageMsg( array( 'missingparam', 'images' ) ); |
| 37 | + } |
| 38 | + |
| 39 | + if ( !isset( $params['targets'] ) ) { |
| 40 | + $this->dieUsageMsg( array( 'missingparam', 'targets' ) ); |
| 41 | + } |
| 42 | + |
| 43 | + foreach ( $params['targets'] as &$target ) { |
| 44 | + $user = false; |
| 45 | + $pass = false; |
| 46 | + |
| 47 | + if ( array_key_exists( $target, $egPushLoginUsers ) && array_key_exists( $target, $egPushLoginPasswords ) ) { |
| 48 | + $user = $egPushLoginUsers[$target]; |
| 49 | + $pass = $egPushLoginPasswords[$target]; |
| 50 | + } |
| 51 | + else if ( $egPushLoginUser != '' && $egPushLoginPass != '' ) { |
| 52 | + $user = $egPushLoginUser; |
| 53 | + $pass = $egPushLoginPass; |
| 54 | + } |
| 55 | + |
| 56 | + if ( substr( $target, -1 ) !== '/' ) { |
| 57 | + $target .= '/'; |
| 58 | + } |
| 59 | + |
| 60 | + $target .= 'api.php'; |
| 61 | + |
| 62 | + if ( $user !== false ) { |
| 63 | + $this->doLogin( $user, $pass, $target ); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + foreach ( $params['images'] as $image ) { |
| 68 | + $title = Title::newFromText( $image, NS_FILE ); |
| 69 | + if ( !is_null( $title ) && $title->getNamespace() == NS_FILE && $title->exists() ) { |
| 70 | + $this->doPush( $title, $params['targets'] ); |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Logs in into a target wiki using the provided username and password. |
| 77 | + * |
| 78 | + * @since 0.5 |
| 79 | + * |
| 80 | + * @param string $user |
| 81 | + * @param string $password |
| 82 | + * @param string $target |
| 83 | + * @param string $token |
| 84 | + * @param CookieJar $cookie |
| 85 | + */ |
| 86 | + protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null ) { |
| 87 | + $requestData = array( |
| 88 | + 'action' => 'login', |
| 89 | + 'format' => 'json', |
| 90 | + 'lgname' => $user, |
| 91 | + 'lgpassword' => $password |
| 92 | + ); |
| 93 | + |
| 94 | + if ( !is_null( $token ) ) { |
| 95 | + $requestData['lgtoken'] = $token; |
| 96 | + } |
| 97 | + |
| 98 | + $req = MWHttpRequest::factory( $target, |
| 99 | + array( |
| 100 | + 'postData' => $requestData, |
| 101 | + 'method' => 'POST', |
| 102 | + 'timeout' => 'default' |
| 103 | + ) |
| 104 | + ); |
| 105 | + |
| 106 | + if ( !is_null( $cookieJar ) ) { |
| 107 | + $req->setCookieJar( $cookieJar ); |
| 108 | + } |
| 109 | + |
| 110 | + $status = $req->execute(); |
| 111 | + |
| 112 | + if ( $status->isOK() ) { |
| 113 | + $response = FormatJson::decode( $req->getContent() ); |
| 114 | + |
| 115 | + if ( property_exists( $response, 'login' ) |
| 116 | + && property_exists( $response->login, 'result' ) ) { |
| 117 | + |
| 118 | + if ( $response->login->result == 'NeedToken' ) { |
| 119 | + $this->doLogin( $user, $password, $target, $response->login->token, $req->getCookieJar() ); |
| 120 | + } |
| 121 | + else if ( $response->login->result == 'Success' ) { |
| 122 | + $this->cookieJars[$target] = $req->getCookieJar(); |
| 123 | + } |
| 124 | + else { |
| 125 | + $this->dieUsage( wfMsgExt( 'push-err-authentication', 'parsemag', $target, '' ), 'authentication-failed' ); |
| 126 | + } |
| 127 | + } |
| 128 | + else { |
| 129 | + $this->dieUsage( wfMsgExt( 'push-err-authentication', 'parsemag', $target, '' ), 'authentication-failed' ); |
| 130 | + } |
| 131 | + } |
| 132 | + else { |
| 133 | + $this->dieUsage( wfMsgExt( 'push-err-authentication', 'parsemag', $target, '' ), 'authentication-failed' ); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Pushes the page content to the target wikis. |
| 139 | + * |
| 140 | + * @since 0.5 |
| 141 | + * |
| 142 | + * @param Title $title |
| 143 | + * @param array $targets |
| 144 | + */ |
| 145 | + protected function doPush( Title $title, array $targets ) { |
| 146 | + foreach ( $targets as $target ) { |
| 147 | + $token = $this->getEditToken( $title, $target ); |
| 148 | + |
| 149 | + if ( $token !== false ) { |
| 150 | + $this->pushToTarget( $title, $target, $token ); |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Obtains the needed edit token by making an HTTP GET request |
| 157 | + * to the remote wikis API. |
| 158 | + * |
| 159 | + * @since 0.5 |
| 160 | + * |
| 161 | + * @param Title $title |
| 162 | + * @param string $target |
| 163 | + * |
| 164 | + * @return string or false |
| 165 | + */ |
| 166 | + protected function getEditToken( Title $title, $target ) { |
| 167 | + $requestData = array( |
| 168 | + 'action' => 'query', |
| 169 | + 'format' => 'json', |
| 170 | + 'intoken' => 'edit', |
| 171 | + 'prop' => 'info', |
| 172 | + 'titles' => $title->getFullText(), |
| 173 | + ); |
| 174 | + |
| 175 | + $parts = array(); |
| 176 | + |
| 177 | + foreach ( $requestData as $key => $value ) { |
| 178 | + $parts[] = $key . '=' . urlencode( $value ); |
| 179 | + } |
| 180 | + |
| 181 | + $req = MWHttpRequest::factory( $target . '?' . implode( '&', $parts ), |
| 182 | + array( |
| 183 | + 'method' => 'GET', |
| 184 | + 'timeout' => 'default' |
| 185 | + ) |
| 186 | + ); |
| 187 | + |
| 188 | + if ( array_key_exists( $target, $this->cookieJars ) ) { |
| 189 | + $req->setCookieJar( $this->cookieJars[$target] ); |
| 190 | + } |
| 191 | + |
| 192 | + $status = $req->execute(); |
| 193 | + |
| 194 | + $response = $status->isOK() ? FormatJson::decode( $req->getContent() ) : null; |
| 195 | + |
| 196 | + $token = false; |
| 197 | + |
| 198 | + if ( !is_null( $response ) |
| 199 | + && property_exists( $response, 'query' ) |
| 200 | + && property_exists( $response->query, 'pages' ) |
| 201 | + && count( $response->query->pages ) > 0 ) { |
| 202 | + |
| 203 | + foreach ( $response->query->pages as $key => $value ) { |
| 204 | + $first = $key; |
| 205 | + break; |
| 206 | + } |
| 207 | + |
| 208 | + if ( property_exists( $response->query->pages->$first, 'edittoken' ) ) { |
| 209 | + $token = $response->query->pages->$first->edittoken; |
| 210 | + } |
| 211 | + elseif ( !is_null( $response ) && property_exists( $response, 'query' ) && property_exists( $response->query, 'error' ) ) { |
| 212 | + $this->dieUsage( $response->query->error->message, 'token-request-failed' ); |
| 213 | + } |
| 214 | + else { |
| 215 | + $this->dieUsage( wfMsg( 'push-special-err-token-failed' ), 'token-request-failed' ); |
| 216 | + } |
| 217 | + } |
| 218 | + else { |
| 219 | + $this->dieUsage( wfMsg( 'push-special-err-token-failed' ), 'token-request-failed' ); |
| 220 | + } |
| 221 | + |
| 222 | + return $token; |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * Pushes the image to the specified wiki. |
| 227 | + * |
| 228 | + * @since 0.5 |
| 229 | + * |
| 230 | + * @param Title $title |
| 231 | + * @param string $target |
| 232 | + * @param string $token |
| 233 | + */ |
| 234 | + protected function pushToTarget( Title $title, $target, $token ) { |
| 235 | + $imagePage = new ImagePage( $title ); |
| 236 | + |
| 237 | + $requestData = array( |
| 238 | + 'action' => 'upload', |
| 239 | + 'format' => 'json', |
| 240 | + 'token' => $token, |
| 241 | + 'url' => $imagePage->getDisplayedFile()->getFullUrl(), |
| 242 | + 'filename' => $title->getText(), |
| 243 | + 'ignorewarnings' => '1' |
| 244 | + ); |
| 245 | + |
| 246 | + $req = MWHttpRequest::factory( $target, |
| 247 | + array( |
| 248 | + 'method' => 'POST', |
| 249 | + 'timeout' => 'default', |
| 250 | + 'postData' => $requestData, |
| 251 | + ) |
| 252 | + ); |
| 253 | + |
| 254 | + if ( array_key_exists( $target, $this->cookieJars ) ) { |
| 255 | + $req->setCookieJar( $this->cookieJars[$target] ); |
| 256 | + } |
| 257 | + |
| 258 | + $status = $req->execute(); |
| 259 | + |
| 260 | + if ( $status->isOK() ) { |
| 261 | + $this->getResult()->addValue( |
| 262 | + null, |
| 263 | + null, |
| 264 | + FormatJson::decode( $req->getContent() ) |
| 265 | + ); |
| 266 | + } |
| 267 | + else { |
| 268 | + // TODO |
| 269 | + } |
| 270 | + } |
| 271 | + |
| 272 | + public function getAllowedParams() { |
| 273 | + return array( |
| 274 | + 'images' => array( |
| 275 | + ApiBase::PARAM_TYPE => 'string', |
| 276 | + ApiBase::PARAM_ISMULTI => true, |
| 277 | + //ApiBase::PARAM_REQUIRED => true, |
| 278 | + ), |
| 279 | + 'targets' => array( |
| 280 | + ApiBase::PARAM_TYPE => 'string', |
| 281 | + ApiBase::PARAM_ISMULTI => true, |
| 282 | + //ApiBase::PARAM_REQUIRED => true, |
| 283 | + ), |
| 284 | + ); |
| 285 | + } |
| 286 | + |
| 287 | + public function getParamDescription() { |
| 288 | + return array( |
| 289 | + 'images' => 'The names of the images to push. Delimitered by |', |
| 290 | + 'targets' => 'The urls of the wikis to push to. Delimitered by |', |
| 291 | + ); |
| 292 | + } |
| 293 | + |
| 294 | + public function getDescription() { |
| 295 | + return array( |
| 296 | + 'Pushes the content of one ore more pages to one or more target wikis.' |
| 297 | + ); |
| 298 | + } |
| 299 | + |
| 300 | + public function getPossibleErrors() { |
| 301 | + return array_merge( parent::getPossibleErrors(), array( |
| 302 | + array( 'missingparam', 'images' ), |
| 303 | + array( 'missingparam', 'targets' ), |
| 304 | + ) ); |
| 305 | + } |
| 306 | + |
| 307 | + protected function getExamples() { |
| 308 | + return array( |
| 309 | + 'api.php?action=pushimages&images=File:Foo.bar&targets=http://en.wikipedia.org/w', |
| 310 | + ); |
| 311 | + } |
| 312 | + |
| 313 | + public function getVersion() { |
| 314 | + return __CLASS__ . ': $Id$'; |
| 315 | + } |
| 316 | + |
| 317 | +} |
Property changes on: trunk/extensions/Push/api/ApiPushImages.php |
___________________________________________________________________ |
Added: svn:keys |
1 | 318 | + Id |
Added: svn:eol-style |
2 | 319 | + native |
Added: svn:keywords |
3 | 320 | + Id |