Skip to content

Commit

Permalink
Finish switching to Intuition
Browse files Browse the repository at this point in the history
A follow up from #62.

Bug: T370133
  • Loading branch information
samwilson authored Nov 11, 2024
1 parent 176a415 commit 497e61d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Controller/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use DI\Container;
use Exception;
use GuzzleHttp\Psr7\LazyOpenStream;
use Krinkle\Intuition\Intuition;
use Locale;
use Mediawiki\Api\Guzzle\ClientFactory;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteParser;
use Wikimedia\SimpleI18n\I18nContext;
use Wikisource\IaUpload\ApiClient\CommonsClient;
use Wikisource\IaUpload\ApiClient\IaClient;
use Wikisource\IaUpload\OAuth\MediaWikiOAuth;
Expand All @@ -37,7 +37,7 @@ class UploadController {
protected $routeParser;

/**
* @var I18nContext
* @var Intuition
*/
protected $i18n;

Expand Down Expand Up @@ -215,7 +215,7 @@ public function fill( Request $request, Response $response ) {
'iaId' => $iaId,
'format' => $format,
'commonsName' => $commonsName,
'error' => $this->i18n->message( 'set-all-fields' ),
'error' => $this->i18n->msg( 'set-all-fields' ),
], $response );
}
// Ensure that file name is less than or equal to 240 bytes.
Expand All @@ -224,7 +224,7 @@ public function fill( Request $request, Response $response ) {
'iaId' => $iaId,
'format' => $format,
'commonsName' => $commonsName,
'error' => $this->i18n->message( 'invalid-length', [ $commonsName ] ),
'error' => $this->i18n->msg( 'invalid-length', [ $commonsName ] ),
], $response );
}
// Strip any trailing file extension.
Expand All @@ -235,7 +235,7 @@ public function fill( Request $request, Response $response ) {
'iaId' => $iaId,
'format' => $format,
'commonsName' => $commonsName,
'error' => $this->i18n->message( 'invalid-commons-name', [ $commonsName ] ),
'error' => $this->i18n->msg( 'invalid-commons-name', [ $commonsName ] ),
], $response );
}

Expand All @@ -249,7 +249,7 @@ public function fill( Request $request, Response $response ) {
'iaId' => $iaId,
'format' => $format,
'commonsName' => $commonsName,
'error' => $this->i18n->message( 'no-found-on-ia', [ $link ] ),
'error' => $this->i18n->msg( 'no-found-on-ia', [ $link ] ),
], $response );
}
$iaId = $iaData['metadata']['identifier'][0];
Expand All @@ -264,7 +264,7 @@ public function fill( Request $request, Response $response ) {
'iaId' => $iaId,
'format' => $format,
'commonsName' => $commonsName,
'error' => $this->i18n->message( 'no-usable-files-found' ),
'error' => $this->i18n->msg( 'no-usable-files-found' ),
], $response );
}

Expand All @@ -276,16 +276,16 @@ public function fill( Request $request, Response $response ) {
$sizeInMb = round( $iaData['files'][$jp2Filename]['size'] / ( 1024 * 1024 ) );
if ( $sizeInMb > $maxSizeInMb ) {
$msgParams = [ $sizeInMb, $maxSizeInMb ];
$warning = $this->i18n->message( 'zip-file-too-large', $msgParams )
. ' ' . $this->i18n->message( 'watch-log' );
$warning = $this->i18n->msg( 'zip-file-too-large', $msgParams )
. ' ' . $this->i18n->msg( 'watch-log' );
}
// Make sure there aren't too many pages.
$maxPageCount = 900;
if ( isset( $iaData['metadata']['imagecount'][0] )
&& $iaData['metadata']['imagecount'][0] > $maxPageCount ) {
$msgParams = [ $iaData['metadata']['imagecount'][0], $maxPageCount ];
$warning = $this->i18n->message( 'too-many-pages', $msgParams )
. ' ' . $this->i18n->message( 'watch-log' );
$warning = $this->i18n->msg( 'too-many-pages', $msgParams )
. ' ' . $this->i18n->msg( 'watch-log' );
}
}

Expand All @@ -297,15 +297,15 @@ public function fill( Request $request, Response $response ) {
'iaId' => $iaId,
'format' => $format,
'commonsName' => $commonsName,
'error' => $this->i18n->message( 'already-on-commons', [ $link ] ),
'error' => $this->i18n->msg( 'already-on-commons', [ $link ] ),
], $response );
}

// See if a page for the IA item exists on Commons under a different name.
$existingPage = $this->commonsClient->pageForIAItem( $iaId );
if ( $existingPage ) {
$linkExisting = $this->commonsClient->getHtmlLink( $existingPage );
$warning = $this->i18n->message( 'ia-identifier-exists', [ $iaId, $linkExisting ] );
$warning = $this->i18n->msg( 'ia-identifier-exists', [ $iaId, $linkExisting ] );
}

// Output the page.
Expand Down Expand Up @@ -356,7 +356,7 @@ public function save( Request $request, Response $response ) {
// Check again that the Commons file doesn't exist.
if ( $this->commonsClient->pageExist( 'File:' . $jobInfo['fullCommonsName'] ) ) {
$link = $this->commonsClient->getHtmlLink( 'File:' . $jobInfo['fullCommonsName'] );
$jobInfo['error'] = $this->i18n->message( 'already-on-commons', [ $link ] );
$jobInfo['error'] = $this->i18n->msg( 'already-on-commons', [ $link ] );
return $this->outputsFillTemplate( $jobInfo, $response );
}

Expand All @@ -366,7 +366,7 @@ public function save( Request $request, Response $response ) {
$link = '<a href="http://archive.org/details/' . rawurlencode( $jobInfo['iaId'] ) . '">'
. htmlspecialchars( $jobInfo['iaId'] )
. '</a>';
$jobInfo['error'] = $this->i18n->message( 'no-found-on-ia', [ $link ] );
$jobInfo['error'] = $this->i18n->msg( 'no-found-on-ia', [ $link ] );
return $this->outputsFillTemplate( $jobInfo, $response );
}
$jobInfo['iaId'] = $iaData['metadata']['identifier'][0];
Expand Down Expand Up @@ -408,7 +408,7 @@ public function save( Request $request, Response $response ) {
if ( isset( $result['upload']['warnings']['duplicate'][0] ) ) {
$dupeFile = $result['upload']['warnings']['duplicate'][0];
$dupeLink = $this->commonsClient->getHtmlLink( 'File:' . $dupeFile );
$jobInfo['error'] = $this->i18n->message( 'duplicate-on-commons', [ $dupeLink ] );
$jobInfo['error'] = $this->i18n->msg( 'duplicate-on-commons', [ $dupeLink ] );
return $this->outputsFillTemplate( $jobInfo, $response );
}
} catch ( Exception $e ) {
Expand All @@ -428,7 +428,7 @@ public function save( Request $request, Response $response ) {
rmdir( $jobDirectory );
$fileLink = $this->commonsClient->getHtmlLink( 'File:' . $jobInfo['fullCommonsName'] );
return $this->outputsInitTemplate( [
'success' => $this->i18n->message( 'successfully-uploaded', [ $fileLink ] ),
'success' => $this->i18n->msg( 'successfully-uploaded', [ $fileLink ] ),
], $response );
}
}
Expand Down Expand Up @@ -715,7 +715,7 @@ protected function parseAuthorParam( $data, &$notes ) {
if ( $this->commonsClient->pageExist( "Creator:$creator" ) ) {
return "{{Creator:$creator}}";
} else {
$notes[] = $this->i18n->message( 'creator-template-missing', [ $creator ] );
$notes[] = $this->i18n->msg( 'creator-template-missing', [ $creator ] );
return $creator;
}
}
Expand Down

0 comments on commit 497e61d

Please sign in to comment.