jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/356951 )
Change subject: Add phpcs and make pass
......................................................................
Add phpcs and make pass
Change-Id: I1c55f273826304228f5cfabffbb0a01b3cf26863
---
M Petition.alias.php
M Petition.php
M PetitionHooks.php
M SpecialPetition.php
M SpecialPetitionData.php
M composer.json
A phpcs.xml
7 files changed, 74 insertions(+), 63 deletions(-)
Approvals:
jenkins-bot: Verified
Jforrester: Looks good to me, approved
diff --git a/Petition.alias.php b/Petition.alias.php
index fb33640..f0e8830 100644
--- a/Petition.alias.php
+++ b/Petition.alias.php
@@ -6,11 +6,10 @@
* @ingroup Extensions
*/
-$specialPageAliases = array();
+$specialPageAliases = [];
/** English */
-$specialPageAliases['en'] = array(
- 'Petition' => array( 'Petition' ),
- 'PetitionData' => array( 'PetitionData' )
-);
-
+$specialPageAliases['en'] = [
+ 'Petition' => [ 'Petition' ],
+ 'PetitionData' => [ 'PetitionData' ]
+];
diff --git a/Petition.php b/Petition.php
index 600c331..7f2ff54 100644
--- a/Petition.php
+++ b/Petition.php
@@ -5,10 +5,11 @@
$wgMessagesDirs['Petition'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['PetitionAlias'] = __DIR__ .
'/Petition.alias.php';
/*wfWarn(
- 'Deprecated PHP entry point used for Petition extension. Please
use wfLoadExtension instead, ' .
+ 'Deprecated PHP entry point used for Petition extension. ' .
+ 'Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for
more details.'
);*/
return;
} else {
die( 'This version of the Petition extension requires MediaWiki 1.25+'
);
-}
\ No newline at end of file
+}
diff --git a/PetitionHooks.php b/PetitionHooks.php
index 3510e57..5d998c7 100644
--- a/PetitionHooks.php
+++ b/PetitionHooks.php
@@ -9,4 +9,4 @@
$updater->addExtensionTable( 'petition_data', __DIR__ .
'/table.sql', true );
return true;
}
-}
\ No newline at end of file
+}
diff --git a/SpecialPetition.php b/SpecialPetition.php
index 8a9ddc6..91e1273 100755
--- a/SpecialPetition.php
+++ b/SpecialPetition.php
@@ -30,26 +30,26 @@
$countries = SpecialPetition::getCountryArray(
$this->getLanguage()->getCode() );
$form = SpecialPetition::defineForm( $petitionName, $source,
$countries );
- $form->setSubmitCallback( array( $this, 'petitionSubmit' ) );
+ $form->setSubmitCallback( [ $this, 'petitionSubmit' ] );
$form->prepareForm();
$result = $form->tryAuthorizedSubmit();
if ( $result === true || ( $result instanceof Status &&
$result->isGood() ) ) {
- $htmlOut = '<span class="petition-done">' .
wfMessage('petition-done')->text() . '</span>';
+ $htmlOut = '<span class="petition-done">' . wfMessage(
'petition-done' )->text() . '</span>';
} else {
$htmlOut = '<div class="petition-form">' . "\n";
$numberOfSignatures =
SpecialPetition::getNumberOfSignatures( $petitionName );
$htmlOut .= '<div id="petition-num-signatures">';
- $htmlOut .= wfMessage('petition-num-signatures',
$numberOfSignatures)->escaped();
+ $htmlOut .= wfMessage( 'petition-num-signatures',
$numberOfSignatures )->escaped();
$htmlOut .= '</div>' . "\n";
// Add the form, with any errors if there was an
attempted submission
- $htmlOut .= $form->getHtml($result) . "\n";
+ $htmlOut .= $form->getHtml( $result ) . "\n";
$htmlOut .= '</div>' . "\n";
}
- $out->addHtml($htmlOut);
+ $out->addHtml( $htmlOut );
}
@@ -64,15 +64,15 @@
global $wgPetitionDatabase;
if ( $this->getUser()->pingLimiter( 'edit' ) ) {
- return wfMessage('actionthrottledtext')->text();
+ return wfMessage( 'actionthrottledtext' )->text();
}
- $dbw = wfGetDB( DB_MASTER, array(), $wgPetitionDatabase );
+ $dbw = wfGetDB( DB_MASTER, [], $wgPetitionDatabase );
if ( $dbw->isReadOnly() ) {
throw new ReadOnlyError();
}
- $dbw->insert( 'petition_data', array(
+ $dbw->insert( 'petition_data', [
'pt_petitionname' => $formData['petitionname'],
'pt_source' => $formData['source'],
'pt_name' => $formData['name'],
@@ -81,8 +81,9 @@
'pt_message' =>
$formData['personalmessage'],
'pt_share' => $formData['share'],
'pt_timestamp' => $dbw->timestamp()
- ),
- __METHOD__ );
+ ],
+ __METHOD__
+ );
// Update the cached number of signatures
$cache = ObjectCache::getMainWANInstance();
@@ -93,9 +94,9 @@
$entry = new ManualLogEntry( 'petition', 'sign' );
$entry->setPerformer( $this->getUser() );
$entry->setTarget( SpecialPage::getTitleFor( 'Petition' ) );
- $entry->setParameters( array(
+ $entry->setParameters( [
'4::petitionname' => $formData['petitionname']
- ) );
+ ] );
$entry->insert();
// And if CheckUser is installed, give it a heads up
@@ -126,10 +127,10 @@
$dbr = wfGetDB( DB_SLAVE );
return $dbr->selectField( 'petition_data',
'count(pt_id)',
- array( 'pt_petitionname' =>
$petitionName )
+ [ 'pt_petitionname' => $petitionName ]
);
},
- array( 'checkKeys' => array( $key ), 'lockTSE' => 10 )
+ [ 'checkKeys' => [ $key ], 'lockTSE' => 10 ]
);
}
@@ -141,7 +142,7 @@
* @throws Exception
*/
static function getCountryArray( $language ) {
- if ( is_callable( array( 'CountryNames', 'getNames' ) ) ) {
+ if ( is_callable( [ 'CountryNames', 'getNames' ] ) ) {
// Need to flip as HTMLForm requires display name as
the key
$countries = array_flip( CountryNames::getNames(
$language ) );
ksort( $countries );
@@ -152,47 +153,47 @@
}
static function defineForm( $petitionName, $source, $countries ) {
- $formDescriptor = array(
- 'petitionname' => array(
+ $formDescriptor = [
+ 'petitionname' => [
'type' => 'hidden',
'default' => $petitionName,
- ),
- 'source' => array(
+ ],
+ 'source' => [
'type' => 'hidden',
'default' => $source,
- ),
- 'name' => array(
+ ],
+ 'name' => [
'type' => 'text',
'label-message' => 'petition-form-name',
'required' => true,
- ),
- 'email' => array(
+ ],
+ 'email' => [
'type' => 'text',
'label-message' => 'petition-form-email',
'required' => true,
- ),
- 'country' => array(
+ ],
+ 'country' => [
'type' => 'select',
'label-message' => 'petition-form-country',
'options' => $countries,
- ),
- 'personalmessage' => array(
+ ],
+ 'personalmessage' => [
'type' => 'textarea',
'label-message' => 'petition-form-message',
'rows' => 4,
- ),
- 'share' => array(
+ ],
+ 'share' => [
'type' => 'check',
'hidelabel' => true, // otherwise get an extra
empty <label> element
- 'label-raw' =>
wfMessage('petition-form-share')->parse(),
+ 'label-raw' => wfMessage( 'petition-form-share'
)->parse(),
'cssclass' => 'plainlinks',
- ),
- 'privacy' => array(
+ ],
+ 'privacy' => [
'type' => 'info',
- 'default' =>
wfMessage('petition-form-privacy')->parse(),
+ 'default' => wfMessage( 'petition-form-privacy'
)->parse(),
'raw' => true,
- ),
- );
+ ],
+ ];
$form = HTMLForm::factory( 'vform', $formDescriptor,
RequestContext::getMain(), 'petition' );
$form->setId( 'petition-form' );
diff --git a/SpecialPetitionData.php b/SpecialPetitionData.php
index 62be195..54e6ad7 100644
--- a/SpecialPetitionData.php
+++ b/SpecialPetitionData.php
@@ -5,7 +5,7 @@
parent::__construct( 'PetitionData', 'view-petition-data' );
}
- function execute($par) {
+ function execute( $par ) {
$this->checkPermissions();
@@ -14,7 +14,8 @@
$downloadTitle = $this->getPageTitle( 'csv' );
$downloadText = $this->msg( 'petition-data-download' )->parse();
- $downloadLink = Linker::link( $downloadTitle, $downloadText,
array( 'class' => 'mw-ui-button mw-ui-progressive' ) );
+ $downloadLink = Linker::link( $downloadTitle, $downloadText,
+ [ 'class' => 'mw-ui-button mw-ui-progressive' ] );
$this->getOutput()->addHTML( $downloadLink );
if ( $par == 'csv' ) {
@@ -25,7 +26,7 @@
}
public function getSubpagesForPrefixSearch() {
- return array( 'csv' );
+ return [ 'csv' ];
}
function csvOutput( $res ) {
@@ -45,24 +46,21 @@
$response->header( "Content-type: text/csv; charset=utf-8" );
$fh = fopen( 'php://output', 'w' );
- fputcsv( $fh, array( 'id', 'petitionname', 'source', 'name',
- 'email', 'country', 'message', 'share', 'timestamp' ) );
+ fputcsv( $fh, [ 'id', 'petitionname', 'source', 'name',
+ 'email', 'country', 'message', 'share', 'timestamp' ] );
- foreach( $res as $row ) {
-
- fputcsv( $fh, array(
+ foreach ( $res as $row ) {
+ fputcsv( $fh, [
$row->pt_id,
- preg_replace("/^=/", "'=",
$row->pt_petitionname),
- preg_replace("/^=/", "'=", $row->pt_source),
- preg_replace("/^=/", "'=", $row->pt_name),
- preg_replace("/^=/", "'=", $row->pt_email),
- preg_replace("/^=/", "'=", $row->pt_country),
- preg_replace("/^=/", "'=", $row->pt_message),
+ preg_replace( "/^=/", "'=",
$row->pt_petitionname ),
+ preg_replace( "/^=/", "'=", $row->pt_source ),
+ preg_replace( "/^=/", "'=", $row->pt_name ),
+ preg_replace( "/^=/", "'=", $row->pt_email ),
+ preg_replace( "/^=/", "'=", $row->pt_country ),
+ preg_replace( "/^=/", "'=", $row->pt_message ),
$row->pt_share,
wfTimestamp( TS_MW, $row->pt_timestamp )
- )
- );
-
+ ] );
}
fclose( $fh );
diff --git a/composer.json b/composer.json
index 686b65b..b8f68fb 100644
--- a/composer.json
+++ b/composer.json
@@ -1,11 +1,14 @@
{
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9.2",
- "jakub-onderka/php-console-highlighter": "0.3.2"
+ "jakub-onderka/php-console-highlighter": "0.3.2",
+ "mediawiki/mediawiki-codesniffer": "0.7.2"
},
"scripts": {
+ "fix": "phpcbf",
"test": [
- "parallel-lint . --exclude vendor"
+ "parallel-lint . --exclude vendor",
+ "phpcs -p -s"
]
}
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..4ffde0b
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ruleset>
+ <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+ <file>.</file>
+ <arg name="extensions" value="php,php5,inc"/>
+ <arg name="encoding" value="UTF-8"/>
+ <exclude-pattern>vendor</exclude-pattern>
+ <exclude-pattern>node_modules</exclude-pattern>
+</ruleset>
--
To view, visit https://gerrit.wikimedia.org/r/356951
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1c55f273826304228f5cfabffbb0a01b3cf26863
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Petition
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits