Skip to content

Commit

Permalink
Merge pull request #32 from ProfessionalWiki/clean
Browse files Browse the repository at this point in the history
Prep 1.6 release
  • Loading branch information
JeroenDeDauw authored Mar 24, 2020
2 parents 1288d75 + 0267dcf commit e7eece0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 77 deletions.
3 changes: 2 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "SimpleBatchUpload",
"version": "1.5.1-alpha",
"version": "1.6.0-alpha",
"author": [
"[https://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]",
"[https://professional.wiki/ Professional.Wiki]",
"..."
],
"url": "https://www.mediawiki.org/wiki/Extension:SimpleBatchUpload",
Expand Down
6 changes: 2 additions & 4 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
## Release Notes

### SimpleBatchUpload 1.5.1
### SimpleBatchUpload 1.6.0

Released on tbd

Changes:
- Support for system message translations via [translatewiki.net](https://translatewiki.net).
- System message translations by translatewiki.net translators
* Added translations (via [translatewiki.net](https://translatewiki.net)).

### SimpleBatchUpload 1.5.0

Expand Down
45 changes: 8 additions & 37 deletions src/ParameterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,13 @@ class ParameterProvider {
private $parameters = null;

/**
* ParameterProvider constructor.
* @param string|null $templateName
*/
public function __construct( $templateName ) {
$this->templateName = $templateName ? $templateName : '';
}

/**
* @return string
*/
public function getEscapedUploadPageText() {
public function getEscapedUploadPageText(): string {

if ( $this->templateName === '' ) {
return '';
Expand All @@ -61,43 +57,27 @@ public function getEscapedUploadPageText() {
return '{{' . $this->getEscapedParameter( self::IDX_TEMPLATENAME ) . $this->getEscapedParameter( self::IDX_TEMPLATEPARAMETERS ) . '}}';
}

/**
* @param int $key
* @return string
*/
private function getEscapedParameter( $key ) {
private function getEscapedParameter( int $key ): string {
return $this->escape( $this->getParameter( $key ) );
}

/**
* @param string $text
* @return string
*/
private function escape( $text ) {
private function escape( string $text ): string {
return htmlspecialchars( $text, ENT_QUOTES, 'UTF-8', false );
}

/**
* @param int $key
* @return string
*/
private function getParameter( $key ) {
private function getParameter( int $key ): string {
if ( $this->parameters === null ) {
$this->populateParameters();
}
return $this->parameters[ $key ];
}

private function populateParameters() {

if ( $this->templateName === '' || $this->populateParametersFromKey() === false ) {
$this->populateParametersFromDefaults();
}

}

/**
*/
private function populateParametersFromKey() {
$paramMsg = Message::newFromKey( 'simplebatchupload-parameters' );

Expand Down Expand Up @@ -134,24 +114,15 @@ private function setParameters( $templateName, $templateParameters, $uploadComme
];
}

/**
* @return string
*/
public function getEscapedUploadComment() {
public function getEscapedUploadComment(): string {
return $this->getEscapedParameter( self::IDX_COMMENT );
}

/**
* @return string
*/
public function getSpecialPageTitle() {
public function getSpecialPageTitle(): string {
return $this->getParameter( self::IDX_SPECIALPAGETITLE );
}

/**
* @param string $parameter
*/
public function addTemplateParameter( $parameter ) {
public function addTemplateParameter( string $parameter ) {

if ( $this->parameters === null ) {
$this->populateParameters();
Expand All @@ -164,7 +135,7 @@ public function addTemplateParameter( $parameter ) {
* @param string $paramLine
* @return string[]
*/
private function parseParamLine( $paramLine ) {
private function parseParamLine( string $paramLine ): array {
return array_replace( [ '', '', '' ], array_map( 'trim', explode( '|', $paramLine, 3 ) ) );
}

Expand Down
29 changes: 3 additions & 26 deletions src/SimpleBatchUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,11 @@ public static function initCallback() {
$simpleBatchUpload->registerEarlyConfiguration( $GLOBALS );
}


/**
* @param $targetConfiguration
*/
public function registerEarlyConfiguration( &$targetConfiguration ){
$sourceConfiguration = $this->getEarlyConfiguration();
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration );
}

/**
* @param $targetConfiguration
*/
public function registerLateConfiguration( &$targetConfiguration ){
$sourceConfiguration = $this->getLateConfiguration();
$this->mergeConfiguration( $sourceConfiguration, $targetConfiguration );
Expand All @@ -68,9 +61,6 @@ protected function mergeConfiguration( $sourceConfiguration, &$targetConfigurati
}
}

/**
* @return array
*/
protected function getEarlyConfiguration(): array {

$configuration = [];
Expand All @@ -87,10 +77,6 @@ protected function getEarlyConfiguration(): array {
return $configuration;
}


/**
* @return array
*/
protected function getLateConfiguration(): array {

$configuration = [];
Expand All @@ -110,12 +96,7 @@ public function registerParserFunction( &$parser ) {
return true;
}


/**
* @return array
*/
protected function getUploadSupportModuleDefinition() {

protected function getUploadSupportModuleDefinition(): array {
return [ 'ext.SimpleBatchUpload.jquery-file-upload' =>

$this->getBasePathsForNonComposerModules() +
Expand All @@ -127,13 +108,9 @@ protected function getUploadSupportModuleDefinition() {
'dependencies' => [ 'jquery.ui.widget' ],
],
];

}

/**
* @return array
*/
protected function getUploadModuleDefinition() {
protected function getUploadModuleDefinition(): array {

$dependencies = [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.jqueryMsg' ];

Expand All @@ -160,7 +137,7 @@ protected function getUploadModuleDefinition() {
/**
* @return string[]
*/
protected function getBasePathsForNonComposerModules() {
protected function getBasePathsForNonComposerModules(): array {
return [
'localBasePath' => dirname( __DIR__ ),
'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload',
Expand Down
12 changes: 3 additions & 9 deletions src/UploadButtonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,26 @@ class UploadButtonRenderer {
* @param $args
* @return array
*/
public function renderParserFunction( Parser $parser, PPFrame $frame, $args ) {

public function renderParserFunction( Parser $parser, PPFrame $frame, $args ): array {
$args = array_map( [ $frame, 'expand' ], $args );
$output = $parser->getOutput();

$html = $this->renderUploadButton( $args, $output );

return [ $html, 'isHTML' => true, 'noparse' => true, 'nowiki' => false ];

}


/**
* @param SpecialBatchUpload $specialPage
* @param string $templateName
*/
public function renderSpecialPage( SpecialBatchUpload $specialPage, $templateName ) {

$args = [ $templateName ];
$output = $specialPage->getOutput();

$html = $this->renderUploadButton( $args, $output );

$output->addHTML( $html );

}

/**
Expand All @@ -72,7 +67,6 @@ public function renderSpecialPage( SpecialBatchUpload $specialPage, $templateNam
* @return string
*/
protected function renderUploadButton( $args, $output ) {

$paramProvider = $this->prepareParameterProvider( $args );

$this->addModulesToOutput( $output );
Expand Down Expand Up @@ -121,7 +115,7 @@ protected function addModulesToOutput( $output ) {
* @param string[] $args
* @return ParameterProvider
*/
protected function prepareParameterProvider( $args ) {
protected function prepareParameterProvider( $args ): ParameterProvider {

$templateName = $args[ 0 ];

Expand All @@ -136,4 +130,4 @@ protected function prepareParameterProvider( $args ) {
return $paramProvider;
}

}
}

0 comments on commit e7eece0

Please sign in to comment.