Index: trunk/extensions/ee/ee.pl |
— | — | @@ -70,11 +70,11 @@ |
71 | 71 | vdie (_("nocontrolfile")); |
72 | 72 | } |
73 | 73 | |
74 | | -# Initialize the browser as Firefox 1.0 with new cookie jar |
| 74 | +# Initialize the browser with new cookie jar |
75 | 75 | $browser=LWP::UserAgent->new(); |
76 | 76 | $browser->cookie_jar( {} ); |
77 | 77 | @ns_headers = ( |
78 | | - 'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20041107 Firefox/1.0', |
| 78 | + 'User-Agent' => 'Mediawiki external editor helper. (http://www.mediawiki.org/wiki/Manual:External_editors)', |
79 | 79 | 'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, |
80 | 80 | image/pjpeg, image/png, */*', |
81 | 81 | 'Accept-Charset' => 'iso-8859-1,*,utf-8', |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | $filename =~ s/[\[\]\{\}\(\)~!#\$\^\&\*;'"<>\?]/__/g; |
114 | 114 | |
115 | 115 | $filename=$filename.".wiki"; |
116 | | - $edit_url=$script."?title=$pagetitle&action=submit"; |
| 116 | + $edit_url=$script."?title=$pagetitle&action=submit&assert=user"; |
117 | 117 | $view_url=$script."?title=$pagetitle"; |
118 | 118 | } elsif($type eq "Diff text") { |
119 | 119 | $secondurl=$input->val("File 2","URL"); |
— | — | @@ -169,13 +169,21 @@ |
170 | 170 | $auth_username => $auth_password |
171 | 171 | ); |
172 | 172 | } |
| 173 | +$loginPage=$browser->get($login_url,@ns_headers); |
| 174 | +$loginpageresponse=$loginPage->content; |
| 175 | +$loginpageresponse=~m|<input type="hidden" name="wpLoginToken" value="(.*?)" />|i; |
| 176 | +$logintoken=$1; |
173 | 177 | $response=$browser->post($login_url,@ns_headers, |
174 | | -Content=>[wpName=>$username,wpPassword=>$password,wpRemember=>"1",wpLoginAttempt=>"Log in"]); |
| 178 | + Content=>[wpName=>$username, |
| 179 | + wpPassword=>$password, |
| 180 | + wpRemember=>"1", |
| 181 | + wpLoginAttempt=>"Log in", |
| 182 | + wpLoginToken=>$logintoken]); |
175 | 183 | |
176 | | -# We expect a redirect after successful login |
177 | | -if($response->code!=302 && !$ignore_login_error) { |
178 | | - vdie (_("loginfailed",$login_url,$username,$password)); |
179 | | -} |
| 184 | +# This check doesn't work with central auth. Checks edit token later to see if logged in. |
| 185 | +#if( ($response->code!=302 || $response->code!=200) && !$ignore_login_error) { |
| 186 | +# vdie (_("loginfailed",$login_url,$username,$password)); |
| 187 | +#} |
180 | 188 | |
181 | 189 | $response=$browser->get($fileurl,@ns_headers); |
182 | 190 | if($type eq "Edit file") { |
— | — | @@ -199,12 +207,20 @@ |
200 | 208 | # we want to edit in one go. |
201 | 209 | $ct=$response->header('Content-Type'); |
202 | 210 | $editpage=$response->content; |
203 | | - $editpage=~m|<input type='hidden' value="(.*?)" name="wpEditToken" />|i; |
| 211 | + $editpage=~m|<input type=["']hidden["'] value="(.*?)" name="wpEditToken" />|i; |
204 | 212 | $token=$1; |
| 213 | + |
| 214 | + # do a quick check to see if logged in. |
| 215 | + if ( $token eq "+\\" ) { |
| 216 | + vdie (_("loginfailed",$login_url,$username,$password)); |
| 217 | + } |
| 218 | + |
205 | 219 | $editpage=~m|<textarea.*?name="wpTextbox1".*?>(.*?)</textarea>|is; |
206 | 220 | $text=$1; |
207 | 221 | $editpage=~m|<input type='hidden' value="(.*?)" name="wpEdittime" />|i; |
208 | 222 | $time=$1; |
| 223 | + $editpage=~m|<input type='hidden' value="(.*?)" name="wpStarttime" />|i; |
| 224 | + $starttime=$1; |
209 | 225 | |
210 | 226 | # Do we need to convert ..? |
211 | 227 | if($ct=~m/charset=utf-8/i) { |
— | — | @@ -410,6 +426,7 @@ |
411 | 427 | wpTextbox1=>$text, |
412 | 428 | wpSummary=>$summary, |
413 | 429 | wpEdittime=>$time, |
| 430 | + wpStarttime=>$starttime, |
414 | 431 | wpEditToken=>$token] |
415 | 432 | ); |
416 | 433 | $watchvar && push @{$content[1]}, (wpWatchthis=>"1"); |