Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

Commit

Permalink
Update Addwiki libraries and fix usages
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson authored Nov 26, 2022
1 parent 20298fe commit c5b0071
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 97 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"sort-packages": true
},
"require": {
"addwiki/mediawiki-api": "^2.0",
"addwiki/mediawiki-api-base": "dev-main",
"addwiki/mediawiki-api": "dev-main",
"addwiki/mediawiki-datamodel": "dev-main",
"krinkle/intuition": "^2.0",
"monolog/monolog": "^2.1",
"symfony/console": "^5.0",
Expand Down
144 changes: 108 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Samwilson\MediaWikiCLI\Command;

use Addwiki\Mediawiki\Api\Client\Action\ActionApi;
use Addwiki\Mediawiki\Api\Client\Auth\AuthMethod;
use Addwiki\Mediawiki\Api\Client\Auth\UserAndPassword;
use Addwiki\Mediawiki\Api\Client\MediaWiki;
use Exception;
use Krinkle\Intuition\Intuition;
use Mediawiki\Api\ApiUser;
use Mediawiki\Api\MediawikiApi;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -108,20 +110,20 @@ protected function saveConfig( InputInterface $input, array $config ): void {
$this->io->success( $this->msg( 'saved-config', [ $configPath ] ) );
}

protected function getApi( array $siteInfo ): MediawikiApi {
protected function getApi( array $siteInfo, ?AuthMethod $authMethod = null ): ActionApi {
// API.
if ( isset( $siteInfo['api_url'] ) ) {
$api = MediawikiApi::newFromApiEndpoint( $siteInfo['api_url'] );
$api = MediaWiki::newFromEndpoint( $siteInfo['api_url'], $authMethod );
} elseif ( isset( $siteInfo['main_page_url'] ) ) {
$api = MediawikiApi::newFromPage( $siteInfo['main_page_url'] );
$api = MediaWiki::newFromPage( $siteInfo['main_page_url'], $authMethod );
} else {
throw new Exception( '$siteInfo does not include a URL.' );
}

// Logger.
$api->setLogger( $this->logger );
$api->action()->setLogger( $this->logger );

return $api;
return $api->action();
}

/**
Expand Down Expand Up @@ -163,9 +165,9 @@ public function setSite( InputInterface $input, string $siteName, array $site )
}

/**
* Log the user in to the given site. If the site doesn't have requisite authentication details, ask for them.
* Get an AuthMethod for the current site. If the site doesn't have requisite authentication details, ask for them.
*/
public function login( InputInterface $input, MediawikiApi $api ) {
public function getAuthMethod( InputInterface $input ): AuthMethod {
$siteName = $input->getOption( 'wiki' );
$site = $this->getSite( $input );
if ( !isset( $site['username'] ) ) {
Expand All @@ -176,9 +178,7 @@ public function login( InputInterface $input, MediawikiApi $api ) {
$site['password'] = $this->io->askHidden( $this->msg( 'ask-login-password' ) );
$this->setSite( $input, $siteName, $site );
}

// Try to log in.
$site = $this->getSite( $input );
return $api->login( new ApiUser( $site['username'], $site['password'] ) );
return new UserAndPassword( $site['username'], $site['password'] );
}
}
Loading

0 comments on commit c5b0071

Please sign in to comment.