Skip to content

Commit

Permalink
Fix logging in to MW api (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
supertassu authored Feb 15, 2021
1 parent 27e9184 commit b31e6e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/Jobs/Scheduled/UpdateWikiAppealListJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public function handle()
$text = $this->createContents($appeals);

// get page information
$services = MediaWikiRepository::getApiForTarget($this->wiki)->getAddWikiServices();
$api = MediaWikiRepository::getApiForTarget($this->wiki);
$api->login();

$services = $api->getAddWikiServices();
$page = $services->newPageGetter()->getFromTitle($page);

// prepare edit
Expand Down
2 changes: 2 additions & 0 deletions app/Services/MediaWiki/Api/MediaWikiApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public function getAddWikiMediaWikiApi(): AddwikiMediaWikiApi;
public function getAddWikiServices(): MediawikiFactory;

public function getMediaWikiExtras(): MediaWikiExtras;

public function login(): void;
}
8 changes: 6 additions & 2 deletions app/Services/MediaWiki/Implementation/RealMediaWikiApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public function __construct(string $identifier, string $url)

/** @var CookieJar $jar */
$jar = $this->guzzleClient->getConfig('cookies');
if ($jar->getCookieByName('mediawiki_session')) {

// session names are unreliable, just assume there is at least some session if it's not empty
// checking the logged-in status when logging in isn't that expensive and this is significantly
// simpler than trying to guess the correct session cookie name which can change at any point anyways
if ($jar->count() > 0) {
$this->hasExistingSession = true;
}
}
Expand Down Expand Up @@ -69,7 +73,7 @@ public function getMediaWikiExtras(): MediaWikiExtras
return new RealMediaWikiExtras($this);
}

public function login()
public function login(): void
{
if ($this->loggedIn) {
return;
Expand Down
5 changes: 5 additions & 0 deletions tests/Fakes/MediaWiki/FakeMediaWikiApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public function getWikiName(): string
{
return $this->wiki;
}

public function login(): void
{
// no-op
}
}

0 comments on commit b31e6e0

Please sign in to comment.