r78247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78246‎ | r78247 | r78248 >
Date:15:35, 12 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added support for login per target
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push.php (modified) (history)
  • /trunk/extensions/Push/Push_Settings.php (modified) (history)
  • /trunk/extensions/Push/api/ApiPush.php (modified) (history)
  • /trunk/extensions/Push/includes/ext.push.tab.js (modified) (history)
  • /trunk/extensions/Push/specials/ext.push.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/Push.i18n.php
@@ -22,6 +22,8 @@
2323 'right-pushadmin' => 'Authorization to modify push targets and push settings.',
2424
2525 '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',
2628
2729 // Tab
2830 'push-tab-text' => 'Push',
@@ -33,7 +35,7 @@
3436 'push-tab-title' => 'Pushing $1',
3537 'push-targets' => 'Push targets',
3638 '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',
3840 'push-import-revision-comment' => 'Last comment: $1',
3941 'push-tab-no-targets' => 'There are no targets to push to. Please add some to your LocalSettings.php file.',
4042 'push-tab-push-to' => 'Push to $1',
@@ -69,11 +71,13 @@
7072
7173 /** Message documentation (Message documentation)
7274 * @author Nike
 75+ * @author Jeroen De Dauw
7376 */
7477 $messages['qqq'] = array(
7578 'push-import-revision-message' => '$3 is [[MediaWiki:Push-import-revision-comment]] or empty.',
7679 'push-remote-page-link' => '$1: page name, $2: wiki name',
7780 'push-remote-page-link-full' => '$1: page name, $2: wiki name',
 81+ 'push-err-authentication' => '$1: wiki name, $2: optional detailed error message',
7882 );
7983
8084 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
Index: trunk/extensions/Push/specials/ext.push.special.js
@@ -84,6 +84,9 @@
8585 if ( data.error ) {
8686 handleError( listItem, pageName, data.error );
8787 }
 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+ }
8891 else {
8992 startPush( pageName, targetOffset, listItem );
9093 }
Index: trunk/extensions/Push/Push.php
@@ -78,6 +78,7 @@
7979 'push-err-captacha',
8080 'push-tab-last-edit',
8181 'push-tab-not-created',
 82+ 'push-err-captcha-page',
8283 );
8384
8485 // For backward compatibility with MW < 1.17.
Index: trunk/extensions/Push/Push_Settings.php
@@ -45,6 +45,13 @@
4646 $egPushLoginUser = '';
4747 $egPushLoginPass = '';
4848
 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+
4956 # The amount of push 'workers' (simultanious push requests) on Special:Push.
5057 $egPushBulkWorkers = 3;
5158
Index: trunk/extensions/Push/includes/ext.push.tab.js
@@ -120,7 +120,7 @@
121121 if ( data.error ) {
122122 handleError( sender, targetUrl, data.error );
123123 }
124 - else if ( data.edit && data.edit.captcha ) {
 124+ else if ( data.length > 0 && data[0].edit && data[0].edit.captcha ) {
125125 handleError( sender, targetUrl, { info: mediaWiki.msg( 'push-err-captacha', targetName ) } );
126126 }
127127 else {
Index: trunk/extensions/Push/api/ApiPush.php
@@ -29,6 +29,8 @@
3030 }
3131
3232 public function execute() {
 33+ global $egPushLoginUser, $egPushLoginPass, $egPushLoginUsers, $egPushLoginPasswords;
 34+
3335 $params = $this->extractRequestParams();
3436
3537 if ( !isset( $params['page'] ) ) {
@@ -40,18 +42,29 @@
4143 }
4244
4345 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+
4458 if ( substr( $target, -1 ) !== '/' ) {
4559 $target .= '/';
4660 }
4761
48 - $target .= 'api.php';
 62+ $target .= 'api.php';
 63+
 64+ if ( $user !== false ) {
 65+ $this->doLogin( $user, $pass, $target );
 66+ }
4967 }
5068
51 - global $egPushLoginUser, $egPushLoginPass;
52 - if ( $egPushLoginUser != '' && $egPushLoginPass != '' ) {
53 - $this->doLogin( $egPushLoginUser, $egPushLoginPass, $params['targets'] );
54 - }
55 -
5669 foreach ( $params['page'] as $page ) {
5770 $title = Title::newFromText( $page );
5871
@@ -62,46 +75,38 @@
6376 }
6477 }
6578
66 - // TODO: this is hardcoded for JSON, make use of API stuff to support all formats.
6779 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 -
8480 $this->getResult()->addValue(
8581 null,
86 - $this->getModuleName(),
87 - array(
88 - 'result' => 'Success'
89 - )
 82+ null,
 83+ FormatJson::decode( $this->editResponses[0] )
9084 );
9185 }
 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+ }
9297 }
9398
9499 /**
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.
96101 *
97102 * @since 0.4
98103 *
99104 * @param string $user
100105 * @param string $password
101 - * @param array $targets
 106+ * @param string $targets
102107 * @param string $token
103108 * @param CookieJar $cookie
104109 */
105 - protected function doLogin( $user, $password, array $targets, $token = null, $cookieJar = null ) {
 110+ protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null ) {
106111 $requestData = array(
107112 'action' => 'login',
108113 'format' => 'json',
@@ -113,44 +118,42 @@
114119 $requestData['lgtoken'] = $token;
115120 }
116121
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() );
125138
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() );
147144 }
 145+ else if ( $response->login->result == 'Success' ) {
 146+ $this->cookieJars[$target] = $req->getCookieJar();
 147+ }
148148 else {
149 - // TODO
150 - }
151 - }
 149+ $this->dieUsage( wfMsgExt( 'push-err-authentication', 'parsemag', $target, '' ), 'authentication-failed' );
 150+ }
 151+ }
152152 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' );
155158 }
156159 }
157160

Status & tagging log