Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies, mainly Addwiki #18

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"require": {
"ext-json": "*",
"ext-simplexml": "*",
"psr/cache": "^1.0",
"psr/log": "^1.0",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3",
"dflydev/dot-access-data": "^3.0",
"addwiki/mediawiki-api": "^0.7",
"addwiki/mediawiki-api": "^3",
"symfony/dom-crawler": "^4.2|^5.0|^6|^7"
},
"require-dev": {
"mediawiki/minus-x": "^1.1",
"php-parallel-lint/php-parallel-lint": "^1.2",
"mediawiki/mediawiki-codesniffer": "^44.0",
"tedivm/stash": "^0.17",
"monolog/monolog": "^1.21|^2.0",
"symfony/var-dumper": "^5.1"
"tedivm/stash": "^1",
"monolog/monolog": "^1|^2|^3",
"symfony/var-dumper": "^5|^6|^7"
},
"scripts": {
"test": [
Expand Down
15 changes: 6 additions & 9 deletions src/Edition.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

namespace Wikisource\Api;

use Addwiki\Mediawiki\Api\Client\Action\Exception\UsageException;
use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest;
use Addwiki\Mediawiki\Api\Service\PageListGetter;
use Dflydev\DotAccessData\Data;
use Mediawiki\Api\FluentRequest;
use Mediawiki\Api\MediawikiFactory;
use Mediawiki\Api\UsageException;
use Psr\Log\LoggerInterface;
use Symfony\Component\DomCrawler\Crawler;

Expand Down Expand Up @@ -129,8 +129,7 @@ protected function fetchPageParse( $title ) {
$this->logger->debug( "Using cached page parse data for $title" );
return $cacheItem;
}
$requestParse = FluentRequest::factory()
->setAction( 'parse' )
$requestParse = ActionRequest::simpleGet( 'parse' )
->setParam( 'page', $title )
->setParam( 'prop', 'text|templates|categories' );
try {
Expand Down Expand Up @@ -162,8 +161,7 @@ public function getWikidataItemNumber() {
return $cacheItem;
}
// Get the Wikidata Item.
$requestProps = FluentRequest::factory()
->setAction( 'query' )
$requestProps = ActionRequest::simpleGet( 'query' )
->setParam( 'titles', $pageTitle )
->setParam( 'prop', 'pageprops' )
->setParam( 'ppprop', 'wikibase_item' );
Expand Down Expand Up @@ -285,8 +283,7 @@ public function getIndexPages() {
$indexPages = [];

// First of all, find all subpages of this Edition.
$f = new MediawikiFactory( $this->getWikisource()->getMediawikiApi() );
$pageListGetter = $f->newPageListGetter();
$pageListGetter = new PageListGetter( $this->getWikisource()->getMediawikiApi() );
$subpages = $pageListGetter->getFromPrefix( $this->getPageTitle() );

// Then, for each of them, find the list of relevant transclusions.
Expand Down
8 changes: 3 additions & 5 deletions src/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Wikisource\Api;

use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest;
use GuzzleHttp\Client;
use Mediawiki\Api\FluentRequest;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\DomCrawler\Crawler;
Expand Down Expand Up @@ -107,8 +107,7 @@ public function loadFromUrl( $url ) {
}

// Query to make sure the page title exists and is an Index page.
$req = new FluentRequest();
$req->setAction( 'query' );
$req = ActionRequest::simpleGet( 'query' );
$req->addParams( [ 'titles' => $title, 'prop' => 'info', 'inprop' => 'url' ] );
$res = $this->wikisource->sendApiRequest( $req, 'query.pages' );
if ( !isset( $res[0] ) ) {
Expand Down Expand Up @@ -188,8 +187,7 @@ public function getPageList( $onlyExisting = false ) {

// Use the API to get a list of all existing pages.
if ( $onlyExisting ) {
$req = new FluentRequest();
$req->setAction( 'query' );
$req = ActionRequest::simpleGet( 'query' );
$indexNsLocalName = $this->wikisource
->getNamespaceLocalName( Wikisource::NS_NAME_INDEX );
$title = substr( $this->getTitle(), strlen( $indexNsLocalName ) + 1 );
Expand Down
19 changes: 9 additions & 10 deletions src/Wikisource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Wikisource\Api;

use Addwiki\Mediawiki\Api\Client\Action\ActionApi;
use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest;
use Dflydev\DotAccessData\Data;
use Mediawiki\Api\FluentRequest;
use Mediawiki\Api\MediawikiApi;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

Expand Down Expand Up @@ -221,8 +221,7 @@ public function getNamespaces() {
$this->logger->debug( "Using cached namespace data for " . $this->getLanguageCode() );
} else {
$this->logger->debug( "Requesting namespace data for " . $this->getLanguageCode() );
$request = FluentRequest::factory()
->setAction( 'query' )
$request = ActionRequest::simpleGet( 'query' )
->setParam( 'meta', 'siteinfo' )
->setParam( 'siprop', 'namespaces' );
$namespaces = $this->sendApiRequest( $request, 'query.namespaces' );
Expand All @@ -233,28 +232,28 @@ public function getNamespaces() {
}

/**
* Get a MediawikiApi object for interacting with this Wikisource.
* @return MediawikiApi
* Get an ActionApi object for interacting with this Wikisource.
* @return ActionApi
*/
public function getMediawikiApi() {
$api = new MediawikiApi( 'https://' . $this->getDomainName() . '/w/api.php' );
$api = new ActionApi( 'https://' . $this->getDomainName() . '/w/api.php' );
return $api;
}

/**
* Run an API query on this Wikisource.
* @param FluentRequest $request The request to send.
* @param ActionRequest $request The request to send.
* @param string $resultKey The dot-delimited array key of the results (e.g. for a pageprop
* query, it's 'query.pages').
* @return array
*/
public function sendApiRequest( FluentRequest $request, $resultKey ) {
public function sendApiRequest( ActionRequest $request, $resultKey ) {
$data = [];
$continue = true;
do {
// Send request and save data for later returning.
$this->logger->debug( "API request: " . json_encode( $request->getParams() ) );
$result = new Data( $this->getMediawikiApi()->getRequest( $request ) );
$result = new Data( $this->getMediawikiApi()->request( $request ) );
if ( !$result->has( $resultKey ) ) {
$continue = false;
continue;
Expand Down
10 changes: 5 additions & 5 deletions src/WikisourceApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace Wikisource\Api;

use Mediawiki\Api\MediawikiApi;
use Mediawiki\Api\SimpleRequest;
use Addwiki\Mediawiki\Api\Client\Action\ActionApi;
use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand Down Expand Up @@ -186,9 +186,9 @@ public function getWikdataEntity( $id ) {
$this->logger->debug( "Using cached data for Wikidata item $id" );
return $cacheItem;
}
$wdApi = new MediawikiApi( 'https://www.wikidata.org/w/api.php' );
$metadataRequest = new SimpleRequest( 'wbgetentities', [ 'ids' => $id ] );
$itemResult = $wdApi->getRequest( $metadataRequest );
$wdApi = new ActionApi( 'https://www.wikidata.org/w/api.php' );
$metadataRequest = ActionRequest::simpleGet( 'wbgetentities', [ 'ids' => $id ] );
$itemResult = $wdApi->request( $metadataRequest );
if ( !isset( $itemResult['success'] ) || !isset( $itemResult['entities'][$id] ) ) {
return false;
}
Expand Down