Skip to content

Commit

Permalink
Update dependencies, and remove one of the CS overrides
Browse files Browse the repository at this point in the history
We were ignoring line length; this changes makes the offending
lines shorter.
  • Loading branch information
samwilson committed Dec 21, 2017
1 parent e5af4fb commit 67d4836
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 66 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"license": "GPL-2.0+",
"homepage": "https://wikitech.wikimedia.org/wiki/Tool:IA_Upload",
"minimum-stability": "stable",
"config": {
"platform": { "php": "5.6" }
},
"require": {
"php": ">=5.5",
"ext-zip": "*",
Expand Down
91 changes: 47 additions & 44 deletions composer.lock

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

3 changes: 0 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<rule ref="MediaWiki.NamingConventions.ValidGlobalName.wgPrefix">
<severity>0</severity>
</rule>
<rule ref="Generic.Files.LineLength.TooLong">
<severity>0</severity>
</rule>
<file>.</file>
<exclude-pattern>vendor/</exclude-pattern>
</ruleset>
2 changes: 1 addition & 1 deletion src/Controller/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct( Application $app, array $config ) {
}

/**
* The first stage of the authentication process, which redirects the user to Commons to authenticate.
* The first stage of the authentication process, which redirects the user to Commons.
* @param Request $request The HTTP request.
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
Expand Down
26 changes: 16 additions & 10 deletions src/Controller/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ public function init( Request $request ) {
$jobInfo->locked = file_exists( dirname( $jobFile ) . '/lock' );
$jobInfo->failed = false;
$logFile = dirname( $jobFile ) . '/log.txt';
$jobInfo->failed = ( file_exists( $logFile ) && filemtime( $logFile ) < ( time() - 24 * 60 * 60 ) );
$jobInfo->hasDjvu = file_exists( dirname( $jobFile ) . '/' . $jobInfo->iaId . '.djvu' );
$aDayAgo = ( time() - 24 * 60 * 60 );
$jobInfo->failed = ( file_exists( $logFile ) && filemtime( $logFile ) < $aDayAgo );
$djvuFilename = dirname( $jobFile ) . '/' . $jobInfo->iaId . '.djvu';
$jobInfo->hasDjvu = file_exists( $djvuFilename );
$jobs[] = $jobInfo;
}
return $this->outputsInitTemplate( [
Expand Down Expand Up @@ -236,9 +238,8 @@ public function fill( Request $request ) {
// See if the file already exists on Commons.
$fullCommonsName = $commonsName . '.djvu';
if ( $this->commonsClient->pageExist( 'File:' . $fullCommonsName ) ) {
$link = '<a href="https://commons.wikimedia.org/wiki/File:' . rawurlencode( $fullCommonsName ) . '">'
. htmlspecialchars( $fullCommonsName )
. '</a>';
$url = 'https://commons.wikimedia.org/wiki/File:' . rawurlencode( $fullCommonsName );
$link = "<a href='$url'>" . htmlspecialchars( $fullCommonsName ) . '</a>';
return $this->outputsInitTemplate( [
'iaId' => $iaId,
'commonsName' => $commonsName,
Expand Down Expand Up @@ -285,9 +286,8 @@ public function save( Request $request ) {

// Check again that the Commons file doesn't exist.
if ( $this->commonsClient->pageExist( 'File:' . $jobInfo['commonsName'] ) ) {
$link = '<a href="http://commons.wikimedia.org/wiki/File:' . rawurlencode( $jobInfo['commonsName'] ) . '">'
. htmlspecialchars( $jobInfo['commonsName'] )
. '</a>';
$url = 'http://commons.wikimedia.org/wiki/File:' . rawurlencode( $jobInfo['commonsName'] );
$link = '<a href="' . $url . '">' . htmlspecialchars( $jobInfo['commonsName'] ) . '</a>';
$jobInfo['error'] = $this->app['i18n']->message( 'already-on-commons', [ $link ] );
return $this->outputsFillTemplate( $jobInfo );
}
Expand Down Expand Up @@ -541,11 +541,17 @@ protected function createPageContent( $data ) {
$content .= '[[Category:Uploaded with IA Upload]]' . "\n";

$isCategorised = false;
if ( isset( $data['metadata']['date'][0] ) && $this->commonsClient->pageExist( 'Category:' . $data['metadata']['date'][0] . ' books' ) ) {
$bookCatExists = $this->commonsClient->pageExist(
'Category:' . $data['metadata']['date'][0] . ' books'
);
if ( isset( $data['metadata']['date'][0] ) && $bookCatExists ) {
$content .= '[[Category:' . $data['metadata']['date'][0] . ' books]]' . "\n";
$isCategorised = true;
}
if ( isset( $data['metadata']['creator'][0] ) && $this->commonsClient->pageExist( 'Category:' . $data['metadata']['creator'][0] ) ) {
$creatorCatExists = $this->commonsClient->pageExist(
'Category:' . $data['metadata']['creator'][0]
);
if ( isset( $data['metadata']['creator'][0] ) && $creatorCatExists ) {
$content .= '[[Category:' . $data['metadata']['creator'][0] . ']]' . "\n";
$isCategorised = true;
}
Expand Down
17 changes: 11 additions & 6 deletions src/OAuth/MediaWikiOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
* @author Thomas Pellissier Tanon
*
* Code inspired from https://github.com/wikimedia/mediawiki-oauthclient-php/blob/master/src/Client.php
* Code inspired from wikimedia/mediawiki-oauthclient-php
* @see https://github.com/wikimedia/mediawiki-oauthclient-php/blob/master/src/Client.php
*/
class MediaWikiOAuth {

Expand All @@ -36,7 +37,8 @@ class MediaWikiOAuth {
protected $userAgent = 'wikisource/ia-upload';

/**
* @param string $baseUri The URI of the index.php file of the wiki like 'https://commons.wikimedia.org/w/index.php'
* @param string $baseUri The URI of the index.php file of the wiki like
* 'https://commons.wikimedia.org/w/index.php'
* @param ConsumerToken $consumerToken The consumer token.
*/
public function __construct( $baseUri, ConsumerToken $consumerToken ) {
Expand All @@ -58,7 +60,9 @@ public function initiate() {
'title' => 'Special:OAuth/initiate',
'oauth_callback' => 'oob'
] );
if ( !array_key_exists( 'oauth_callback_confirmed', $result ) || $result['oauth_callback_confirmed'] !== 'true' ) {
if ( !array_key_exists( 'oauth_callback_confirmed', $result )
|| $result['oauth_callback_confirmed'] !== 'true'
) {
throw new MediaWikiOAuthException( '', 'Callback was not confirmed' );
}
$requestToken = new RequestToken( $result['key'], $result['secret'] );
Expand All @@ -75,11 +79,12 @@ public function initiate() {
/**
* The final leg of the OAuth handshake.
*
* Exchange the request Token from initiate() and the verification code that the user submitted back to you
* for an access token which you'll use for all API calls.
* Exchange the request Token from initiate() and the verification code that the user submitted
* back to you for an access token which you'll use for all API calls.
*
* @param RequestToken $requestToken Request token obtained from initiate
* @param string $verifyCode Authorization code sent to the callback URL (oauth_verifier query parameter)
* @param string $verifyCode Authorization code sent to the callback URL (the oauth_verifier
* query parameter)
*
* @return AccessToken The access token
* @throws MediaWikiOAuthException
Expand Down
Loading

0 comments on commit 67d4836

Please sign in to comment.