Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -22,6 +22,8 @@ |
23 | 23 | 'right-pushadmin' => 'Authorization to modify push targets and push settings.', |
24 | 24 | |
25 | 25 | 'push-err-captacha' => 'Could not push to $1 due to captcha.', |
| 26 | + 'push-err-captcha-page' => 'Could not push page $1 to all targets due to captcha.', |
| 27 | + 'push-err-authentication' => 'Authentication at $1 failed. $2', |
26 | 28 | |
27 | 29 | // Tab |
28 | 30 | 'push-tab-text' => 'Push', |
— | — | @@ -33,7 +35,7 @@ |
34 | 36 | 'push-tab-title' => 'Pushing $1', |
35 | 37 | 'push-targets' => 'Push targets', |
36 | 38 | 'push-add-target' => 'Add target', |
37 | | - 'push-import-revision-message' => 'Import from $1 by $2. $3', |
| 39 | + 'push-import-revision-message' => 'Pushed from $1 by $2. $3', |
38 | 40 | 'push-import-revision-comment' => 'Last comment: $1', |
39 | 41 | 'push-tab-no-targets' => 'There are no targets to push to. Please add some to your LocalSettings.php file.', |
40 | 42 | 'push-tab-push-to' => 'Push to $1', |
— | — | @@ -69,11 +71,13 @@ |
70 | 72 | |
71 | 73 | /** Message documentation (Message documentation) |
72 | 74 | * @author Nike |
| 75 | + * @author Jeroen De Dauw |
73 | 76 | */ |
74 | 77 | $messages['qqq'] = array( |
75 | 78 | 'push-import-revision-message' => '$3 is [[MediaWiki:Push-import-revision-comment]] or empty.', |
76 | 79 | 'push-remote-page-link' => '$1: page name, $2: wiki name', |
77 | 80 | 'push-remote-page-link-full' => '$1: page name, $2: wiki name', |
| 81 | + 'push-err-authentication' => '$1: wiki name, $2: optional detailed error message', |
78 | 82 | ); |
79 | 83 | |
80 | 84 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
Index: trunk/extensions/Push/specials/ext.push.special.js |
— | — | @@ -84,6 +84,9 @@ |
85 | 85 | if ( data.error ) { |
86 | 86 | handleError( listItem, pageName, data.error ); |
87 | 87 | } |
| 88 | + else if ( data.length > 0 && data[0].edit && data[0].edit.captcha ) { |
| 89 | + handleError( listItem, pageName, { info: mediaWiki.msg( 'push-err-captcha-page', pageName ) } ); |
| 90 | + } |
88 | 91 | else { |
89 | 92 | startPush( pageName, targetOffset, listItem ); |
90 | 93 | } |
Index: trunk/extensions/Push/Push.php |
— | — | @@ -78,6 +78,7 @@ |
79 | 79 | 'push-err-captacha', |
80 | 80 | 'push-tab-last-edit', |
81 | 81 | 'push-tab-not-created', |
| 82 | + 'push-err-captcha-page', |
82 | 83 | ); |
83 | 84 | |
84 | 85 | // For backward compatibility with MW < 1.17. |
Index: trunk/extensions/Push/Push_Settings.php |
— | — | @@ -45,6 +45,13 @@ |
46 | 46 | $egPushLoginUser = ''; |
47 | 47 | $egPushLoginPass = ''; |
48 | 48 | |
| 49 | +# Default login data per target. Overrides $egPushLoginUser and $egPushLoginPass when specified. |
| 50 | +# Array keys should be the urls assigned in the $egPushTargets array. |
| 51 | +# When set, the values will always be used when there is |
| 52 | +# no login interface. If there is, they will be filled in as default. |
| 53 | +$egPushLoginUsers = array(); |
| 54 | +$egPushLoginPasswords = array(); |
| 55 | + |
49 | 56 | # The amount of push 'workers' (simultanious push requests) on Special:Push. |
50 | 57 | $egPushBulkWorkers = 3; |
51 | 58 | |
Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | if ( data.error ) { |
122 | 122 | handleError( sender, targetUrl, data.error ); |
123 | 123 | } |
124 | | - else if ( data.edit && data.edit.captcha ) { |
| 124 | + else if ( data.length > 0 && data[0].edit && data[0].edit.captcha ) { |
125 | 125 | handleError( sender, targetUrl, { info: mediaWiki.msg( 'push-err-captacha', targetName ) } ); |
126 | 126 | } |
127 | 127 | else { |
Index: trunk/extensions/Push/api/ApiPush.php |
— | — | @@ -29,6 +29,8 @@ |
30 | 30 | } |
31 | 31 | |
32 | 32 | public function execute() { |
| 33 | + global $egPushLoginUser, $egPushLoginPass, $egPushLoginUsers, $egPushLoginPasswords; |
| 34 | + |
33 | 35 | $params = $this->extractRequestParams(); |
34 | 36 | |
35 | 37 | if ( !isset( $params['page'] ) ) { |
— | — | @@ -40,18 +42,29 @@ |
41 | 43 | } |
42 | 44 | |
43 | 45 | foreach ( $params['targets'] as &$target ) { |
| 46 | + $user = false; |
| 47 | + $pass = false; |
| 48 | + |
| 49 | + if ( array_key_exists( $target, $egPushLoginUsers ) && array_key_exists( $target, $egPushLoginPasswords ) ) { |
| 50 | + $user = $egPushLoginUsers[$target]; |
| 51 | + $pass = $egPushLoginPasswords[$target]; |
| 52 | + } |
| 53 | + else if ( $egPushLoginUser != '' && $egPushLoginPass != '' ) { |
| 54 | + $user = $egPushLoginUser; |
| 55 | + $pass = $egPushLoginPass; |
| 56 | + } |
| 57 | + |
44 | 58 | if ( substr( $target, -1 ) !== '/' ) { |
45 | 59 | $target .= '/'; |
46 | 60 | } |
47 | 61 | |
48 | | - $target .= 'api.php'; |
| 62 | + $target .= 'api.php'; |
| 63 | + |
| 64 | + if ( $user !== false ) { |
| 65 | + $this->doLogin( $user, $pass, $target ); |
| 66 | + } |
49 | 67 | } |
50 | 68 | |
51 | | - global $egPushLoginUser, $egPushLoginPass; |
52 | | - if ( $egPushLoginUser != '' && $egPushLoginPass != '' ) { |
53 | | - $this->doLogin( $egPushLoginUser, $egPushLoginPass, $params['targets'] ); |
54 | | - } |
55 | | - |
56 | 69 | foreach ( $params['page'] as $page ) { |
57 | 70 | $title = Title::newFromText( $page ); |
58 | 71 | |
— | — | @@ -62,46 +75,38 @@ |
63 | 76 | } |
64 | 77 | } |
65 | 78 | |
66 | | - // TODO: this is hardcoded for JSON, make use of API stuff to support all formats. |
67 | 79 | if ( count( $this->editResponses ) == 1 ) { |
68 | | - die( $this->editResponses[0] ); |
69 | | - } |
70 | | - else { |
71 | | - foreach ( $this->editResponses as $rawResponse ) { |
72 | | - $response = FormatJson::decode( $rawResponse ); |
73 | | - |
74 | | - if ( property_exists( $response , 'query' ) |
75 | | - && property_exists( $response->query , 'error' ) ) { |
76 | | - die( $rawResponse ); |
77 | | - } |
78 | | - else if ( property_exists( $response , 'query' ) |
79 | | - && property_exists( $response->query , 'captcha' ) ) { |
80 | | - die( $rawResponse ); |
81 | | - } |
82 | | - } |
83 | | - |
84 | 80 | $this->getResult()->addValue( |
85 | 81 | null, |
86 | | - $this->getModuleName(), |
87 | | - array( |
88 | | - 'result' => 'Success' |
89 | | - ) |
| 82 | + null, |
| 83 | + FormatJson::decode( $this->editResponses[0] ) |
90 | 84 | ); |
91 | 85 | } |
| 86 | + else { |
| 87 | + $success = true; |
| 88 | + |
| 89 | + foreach ( $this->editResponses as $response ) { |
| 90 | + $this->getResult()->addValue( |
| 91 | + null, |
| 92 | + null, |
| 93 | + FormatJson::decode( $response ) |
| 94 | + ); |
| 95 | + } |
| 96 | + } |
92 | 97 | } |
93 | 98 | |
94 | 99 | /** |
95 | | - * Logs in into the target wiki using the provided username and password. |
| 100 | + * Logs in into a target wiki using the provided username and password. |
96 | 101 | * |
97 | 102 | * @since 0.4 |
98 | 103 | * |
99 | 104 | * @param string $user |
100 | 105 | * @param string $password |
101 | | - * @param array $targets |
| 106 | + * @param string $targets |
102 | 107 | * @param string $token |
103 | 108 | * @param CookieJar $cookie |
104 | 109 | */ |
105 | | - protected function doLogin( $user, $password, array $targets, $token = null, $cookieJar = null ) { |
| 110 | + protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null ) { |
106 | 111 | $requestData = array( |
107 | 112 | 'action' => 'login', |
108 | 113 | 'format' => 'json', |
— | — | @@ -113,44 +118,42 @@ |
114 | 119 | $requestData['lgtoken'] = $token; |
115 | 120 | } |
116 | 121 | |
117 | | - foreach ( $targets as $target ) { |
118 | | - $req = MWHttpRequest::factory( $target, |
119 | | - array( |
120 | | - 'postData' => $requestData, |
121 | | - 'method' => 'POST', |
122 | | - 'timeout' => 'default' |
123 | | - ) |
124 | | - ); |
| 122 | + $req = MWHttpRequest::factory( $target, |
| 123 | + array( |
| 124 | + 'postData' => $requestData, |
| 125 | + 'method' => 'POST', |
| 126 | + 'timeout' => 'default' |
| 127 | + ) |
| 128 | + ); |
| 129 | + |
| 130 | + if ( !is_null( $cookieJar ) ) { |
| 131 | + $req->setCookieJar( $cookieJar ); |
| 132 | + } |
| 133 | + |
| 134 | + $status = $req->execute(); |
| 135 | + |
| 136 | + if ( $status->isOK() ) { |
| 137 | + $response = FormatJson::decode( $req->getContent() ); |
125 | 138 | |
126 | | - if ( !is_null( $cookieJar ) ) { |
127 | | - $req->setCookieJar( $cookieJar ); |
128 | | - } |
129 | | - |
130 | | - $status = $req->execute(); |
131 | | - |
132 | | - if ( $status->isOK() ) { |
133 | | - $response = FormatJson::decode( $req->getContent() ); |
134 | | - |
135 | | - if ( property_exists( $response, 'login' ) |
136 | | - && property_exists( $response->login, 'result' ) ) { |
137 | | - |
138 | | - if ( $response->login->result == 'NeedToken' ) { |
139 | | - $this->doLogin( $user, $password, array( $target ), $response->login->token, $req->getCookieJar() ); |
140 | | - } |
141 | | - else if ( $response->login->result == 'Success' ) { |
142 | | - $this->cookieJars[$target] = $req->getCookieJar(); |
143 | | - } |
144 | | - else { |
145 | | - // TODO |
146 | | - } |
| 139 | + if ( property_exists( $response, 'login' ) |
| 140 | + && property_exists( $response->login, 'result' ) ) { |
| 141 | + |
| 142 | + if ( $response->login->result == 'NeedToken' ) { |
| 143 | + $this->doLogin( $user, $password, $target, $response->login->token, $req->getCookieJar() ); |
147 | 144 | } |
| 145 | + else if ( $response->login->result == 'Success' ) { |
| 146 | + $this->cookieJars[$target] = $req->getCookieJar(); |
| 147 | + } |
148 | 148 | else { |
149 | | - // TODO |
150 | | - } |
151 | | - } |
| 149 | + $this->dieUsage( wfMsgExt( 'push-err-authentication', 'parsemag', $target, '' ), 'authentication-failed' ); |
| 150 | + } |
| 151 | + } |
152 | 152 | else { |
153 | | - // TODO |
154 | | - } |
| 153 | + $this->dieUsage( wfMsgExt( 'push-err-authentication', 'parsemag', $target, '' ), 'authentication-failed' ); |
| 154 | + } |
| 155 | + } |
| 156 | + else { |
| 157 | + $this->dieUsage( wfMsgExt( 'push-err-authentication', 'parsemag', $target, '' ), 'authentication-failed' ); |
155 | 158 | } |
156 | 159 | } |
157 | 160 | |