r72770 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72769‎ | r72770 | r72771 >
Date:01:44, 11 September 2010
Author:bawolff
Status:deferred (Comments)
Tags:
Comment:
Fix Bug 23765 (ee.pl can't login after crsf fix). Basically fix up the broken screen-scrapping

This is more of a quick fix, as this really really really should use the api, but for the moment my only
goal was to make it work again.
Modified paths:
  • /trunk/extensions/ee/ee.pl (modified) (history)

Diff [purge]

Index: trunk/extensions/ee/ee.pl
@@ -70,11 +70,11 @@
7171 vdie (_("nocontrolfile"));
7272 }
7373
74 -# Initialize the browser as Firefox 1.0 with new cookie jar
 74+# Initialize the browser with new cookie jar
7575 $browser=LWP::UserAgent->new();
7676 $browser->cookie_jar( {} );
7777 @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)',
7979 'Accept' => 'image/gif, image/x-xbitmap, image/jpeg,
8080 image/pjpeg, image/png, */*',
8181 'Accept-Charset' => 'iso-8859-1,*,utf-8',
@@ -112,7 +112,7 @@
113113 $filename =~ s/[\[\]\{\}\(\)~!#\$\^\&\*;'"<>\?]/__/g;
114114
115115 $filename=$filename.".wiki";
116 - $edit_url=$script."?title=$pagetitle&action=submit";
 116+ $edit_url=$script."?title=$pagetitle&action=submit&assert=user";
117117 $view_url=$script."?title=$pagetitle";
118118 } elsif($type eq "Diff text") {
119119 $secondurl=$input->val("File 2","URL");
@@ -169,13 +169,21 @@
170170 $auth_username => $auth_password
171171 );
172172 }
 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;
173177 $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]);
175183
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+#}
180188
181189 $response=$browser->get($fileurl,@ns_headers);
182190 if($type eq "Edit file") {
@@ -199,12 +207,20 @@
200208 # we want to edit in one go.
201209 $ct=$response->header('Content-Type');
202210 $editpage=$response->content;
203 - $editpage=~m|<input type='hidden' value="(.*?)" name="wpEditToken" />|i;
 211+ $editpage=~m|<input type=["']hidden["'] value="(.*?)" name="wpEditToken" />|i;
204212 $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+
205219 $editpage=~m|<textarea.*?name="wpTextbox1".*?>(.*?)</textarea>|is;
206220 $text=$1;
207221 $editpage=~m|<input type='hidden' value="(.*?)" name="wpEdittime" />|i;
208222 $time=$1;
 223+ $editpage=~m|<input type='hidden' value="(.*?)" name="wpStarttime" />|i;
 224+ $starttime=$1;
209225
210226 # Do we need to convert ..?
211227 if($ct=~m/charset=utf-8/i) {
@@ -410,6 +426,7 @@
411427 wpTextbox1=>$text,
412428 wpSummary=>$summary,
413429 wpEdittime=>$time,
 430+ wpStarttime=>$starttime,
414431 wpEditToken=>$token]
415432 );
416433 $watchvar && push @{$content[1]}, (wpWatchthis=>"1");

Comments

#Comment by Bawolff (talk | contribs)   01:48, 11 September 2010

I forgot to mention in commit summary that I made it stop pretending to be firefox because that seems wrong.

Status & tagging log