Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/195029
Change subject: Add "composer test" command to run phplint and phpcs
......................................................................
Add "composer test" command to run phplint and phpcs
And fix all the code to pass phpcs!
Change-Id: Ibe33b412aee3580655cddac93df50089ae9d8fd4
---
M .gitignore
M MassMessage.hooks.php
M MassMessage.i18n.magic.php
M MassMessage.php
A composer.json
M includes/ApiEditMassMessageList.php
M includes/ApiMassMessage.php
M includes/MassMessageTargets.php
M includes/content/MassMessageListDiffEngine.php
M includes/job/MassMessageJob.php
M maintenance/sendMessages.php
M tests/MassMessageTargetsTest.php
M tests/MassMessageTest.php
M tests/content/MassMessageContentHandlerTest.php
M tests/job/MassMessageJobTest.php
M tests/job/MassMessageSubmitJobTest.php
16 files changed, 108 insertions(+), 76 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage
refs/changes/29/195029/1
diff --git a/.gitignore b/.gitignore
index 98b092a..f7fe6c8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
*~
*.kate-swp
.*.swp
+composer.lock
+vendor
diff --git a/MassMessage.hooks.php b/MassMessage.hooks.php
index e54c16a..cd0475d 100644
--- a/MassMessage.hooks.php
+++ b/MassMessage.hooks.php
@@ -60,7 +60,7 @@
if ( !$current ) {
$output->setProperty( 'massmessage-targets', serialize(
array( $data ) ) );
} else {
- $output->setProperty( 'massmessage-targets' , serialize(
+ $output->setProperty( 'massmessage-targets', serialize(
array_merge( unserialize( $current ), array(
$data ) ) ) );
}
return '';
@@ -87,7 +87,7 @@
public static function onRenameUserPreRename( $uid, $oldName, $newName
) {
global $wgMassMessageAccountUsername;
if ( $oldName == $wgMassMessageAccountUsername ) {
- return wfMessage( 'massmessage-cannot-rename' )->text()
;
+ return wfMessage( 'massmessage-cannot-rename' )->text();
}
return true;
}
diff --git a/MassMessage.i18n.magic.php b/MassMessage.i18n.magic.php
index 967b59a..9579fb6 100644
--- a/MassMessage.i18n.magic.php
+++ b/MassMessage.i18n.magic.php
@@ -78,4 +78,4 @@
/** Simplified Chinese (中文(简体)) */
$magicWords['zh-hans'] = array(
'target' => array( 0, '目标' ),
-);
\ No newline at end of file
+);
diff --git a/MassMessage.php b/MassMessage.php
index 4923d41..4aba69b 100644
--- a/MassMessage.php
+++ b/MassMessage.php
@@ -72,17 +72,26 @@
$wgAutoloadClasses['MassMessage'] = __DIR__ . '/includes/MassMessage.php';
$wgAutoloadClasses['MassMessageTargets'] = __DIR__ .
'/includes/MassMessageTargets.php';
$wgAutoloadClasses['SpecialMassMessage'] = __DIR__ .
'/includes/SpecialMassMessage.php';
-$wgAutoloadClasses['SpecialCreateMassMessageList'] = __DIR__ .
'/includes/SpecialCreateMassMessageList.php';
-$wgAutoloadClasses['SpecialEditMassMessageList'] = __DIR__ .
'/includes/SpecialEditMassMessageList.php';
+$wgAutoloadClasses['SpecialCreateMassMessageList']
+ = __DIR__ . '/includes/SpecialCreateMassMessageList.php';
+$wgAutoloadClasses['SpecialEditMassMessageList']
+ = __DIR__ . '/includes/SpecialEditMassMessageList.php';
$wgAutoloadClasses['MassMessageJob'] = __DIR__ .
'/includes/job/MassMessageJob.php';
-$wgAutoloadClasses['MassMessageServerSideJob'] = __DIR__ .
'/includes/job/MassMessageServerSideJob.php';
+$wgAutoloadClasses['MassMessageServerSideJob']
+ = __DIR__ . '/includes/job/MassMessageServerSideJob.php';
$wgAutoloadClasses['MassMessageSubmitJob'] = __DIR__ .
'/includes/job/MassMessageSubmitJob.php';
-$wgAutoloadClasses['MassMessageFailureLogFormatter'] = __DIR__ .
'/includes/logging/MassMessageFailureLogFormatter.php';
-$wgAutoloadClasses['MassMessageSendLogFormatter'] = __DIR__ .
'/includes/logging/MassMessageSendLogFormatter.php';
-$wgAutoloadClasses['MassMessageSkipLogFormatter'] = __DIR__ .
'/includes/logging/MassMessageSkipLogFormatter.php';
-$wgAutoloadClasses['MassMessageListContent'] = __DIR__ .
'/includes/content/MassMessageListContent.php';
-$wgAutoloadClasses['MassMessageListContentHandler'] = __DIR__ .
'/includes/content/MassMessageListContentHandler.php';
-$wgAutoloadClasses['MassMessageListDiffEngine'] = __DIR__ .
'/includes/content/MassMessageListDiffEngine.php';
+$wgAutoloadClasses['MassMessageFailureLogFormatter']
+ = __DIR__ . '/includes/logging/MassMessageFailureLogFormatter.php';
+$wgAutoloadClasses['MassMessageSendLogFormatter']
+ = __DIR__ . '/includes/logging/MassMessageSendLogFormatter.php';
+$wgAutoloadClasses['MassMessageSkipLogFormatter']
+ = __DIR__ . '/includes/logging/MassMessageSkipLogFormatter.php';
+$wgAutoloadClasses['MassMessageListContent']
+ = __DIR__ . '/includes/content/MassMessageListContent.php';
+$wgAutoloadClasses['MassMessageListContentHandler']
+ = __DIR__ . '/includes/content/MassMessageListContentHandler.php';
+$wgAutoloadClasses['MassMessageListDiffEngine']
+ = __DIR__ . '/includes/content/MassMessageListDiffEngine.php';
$wgAutoloadClasses['MassMessageTestCase'] = __DIR__ .
'/tests/MassMessageTestCase.php';
$wgAutoloadClasses['MassMessageApiTestCase'] = __DIR__ .
'/tests/MassMessageApiTestCase.php';
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..d3201eb
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+ "require-dev": {
+ "jakub-onderka/php-parallel-lint": "0.8.*",
+ "mediawiki/mediawiki-codesniffer": "0.1.0"
+ },
+ "scripts": {
+ "test": [
+ "parallel-lint . --exclude vendor",
+ "phpcs
--standard=vendor/mediawiki/mediawiki-codesniffer/MediaWiki
--extensions=php,php5,inc --ignore=vendor -p ."
+ ]
+ }
+}
diff --git a/includes/ApiEditMassMessageList.php
b/includes/ApiEditMassMessageList.php
index 3663159..6e4e45e 100644
--- a/includes/ApiEditMassMessageList.php
+++ b/includes/ApiEditMassMessageList.php
@@ -33,7 +33,7 @@
$target =
MassMessageListContentHandler::extractTarget( $page );
if ( isset( $target['errors'] ) ) {
$item = array( '*' => $page );
- foreach( $target['errors'] as $error ) {
+ foreach ( $target['errors'] as $error )
{
$item[$error] = '';
}
$invalidAdd[] = $item;
@@ -254,21 +254,12 @@
}
/**
- * @deprecated since MediaWiki core 1.25
- */
- public function getExamples() {
- return array(
-
'api.php?action=editmassmessagelist&spamlist=Example&add=User%20talk%3AFoo%7CTalk%3ABar&remove=Talk%3ABaz&token=TOKEN'
- => 'Add [[User talk:Foo]] and [[Talk:Bar]] to the
delivery list [[Example]] and remove [[Talk:Baz]] from it'
- );
- }
-
- /**
* @see ApiBase::getExamplesMessages()
*/
protected function getExamplesMessages() {
return array(
-
'action=editmassmessagelist&spamlist=Example&add=User%20talk%3AFoo%7CTalk%3ABar&remove=Talk%3ABaz&token=TOKEN'
+
'action=editmassmessagelist&spamlist=Example&add=User%20talk%3AFoo%7CTalk%3ABar'
.
+ '&remove=Talk%3ABaz&token=TOKEN'
=> 'apihelp-editmassmessagelist-example-1',
);
}
diff --git a/includes/ApiMassMessage.php b/includes/ApiMassMessage.php
index e9e3c2b..fba028d 100644
--- a/includes/ApiMassMessage.php
+++ b/includes/ApiMassMessage.php
@@ -30,13 +30,6 @@
);
}
- /**
- * @deprecated since MediaWiki core 1.25
- */
- public function getDescription() {
- return 'Send a message to a list of pages';
- }
-
public function getAllowedParams() {
return array(
'spamlist' => array(
@@ -52,18 +45,6 @@
ApiBase::PARAM_REQUIRED => true
),
'token' => null,
- );
- }
-
- /**
- * @deprecated since MediaWiki core 1.25
- */
- public function getParamDescription() {
- return array(
- 'spamlist' => 'Page containing list of pages to leave a
message on',
- 'subject' => 'Subject line of the message',
- 'message' => 'Message body text',
- 'token' => 'An edit token from action=tokens'
);
}
@@ -92,21 +73,12 @@
}
/**
- * @deprecated since MediaWiki core 1.25
- */
- public function getExamples() {
- return array(
-
'api.php?action=massmessage&spamlist=Signpost%20Spamlist&subject=New%20Signpost&message=Please%20read%20it&token=TOKEN'
- => 'Send a message to the list at [[Signpost Spamlist]]
with the subject "New Signpost", and message body of "Please read it"'
- );
- }
-
- /**
* @see ApiBase::getExamplesMessages()
*/
protected function getExamplesMessages() {
return array(
-
'action=massmessage&spamlist=Signpost%20Spamlist&subject=New%20Signpost&message=Please%20read%20it&token=TOKEN'
+
'action=massmessage&spamlist=Signpost%20Spamlist&subject=New%20Signpost' .
+ '&message=Please%20read%20it&token=TOKEN'
=> 'apihelp-massmessage-example-1',
);
}
diff --git a/includes/MassMessageTargets.php b/includes/MassMessageTargets.php
index 42b341f..2c5036e 100644
--- a/includes/MassMessageTargets.php
+++ b/includes/MassMessageTargets.php
@@ -18,10 +18,10 @@
* preview and save in SpecialMassMessage.
*
* @param Title $spamlist
- * @param $normalize Whether to normalize and deduplicate the targets
+ * @param bool $normalize Whether to normalize and deduplicate the
targets
* @return array|null
*/
- public static function getTargets( Title $spamlist, $normalize = true
) {
+ public static function getTargets( Title $spamlist, $normalize = true )
{
global $wgMemc;
if ( !$spamlist->exists() && !$spamlist->inNamespace(
NS_CATEGORY ) ) {
@@ -150,7 +150,11 @@
$parserOptions = $page->makeParserOptions( 'canonical' );
$parser = new Parser();
$parser->firstCallInit(); // So our initial parser function is
added
- $parser->setFunctionHook( 'target',
'MassMessageHooks::storeDataParserFunction' ); // Now overwrite it
+ // Now overwrite it
+ $parser->setFunctionHook(
+ 'target',
+ 'MassMessageHooks::storeDataParserFunction'
+ );
// Parse
$output = $parser->parse( $text, $spamlist, $parserOptions );
diff --git a/includes/content/MassMessageListDiffEngine.php
b/includes/content/MassMessageListDiffEngine.php
index 9499171..d5428a6 100644
--- a/includes/content/MassMessageListDiffEngine.php
+++ b/includes/content/MassMessageListDiffEngine.php
@@ -14,8 +14,8 @@
* @return bool|string
*/
public function generateContentDiffBody( Content $old, Content $new ) {
- if ( !( $old instanceOf MassMessageListContent )
- || !( $new instanceOf MassMessageListContent )
+ if ( !( $old instanceof MassMessageListContent )
+ || !( $new instanceof MassMessageListContent )
) {
throw new Exception( 'Cannot diff content types other
than MassMessageListContent' );
}
diff --git a/includes/job/MassMessageJob.php b/includes/job/MassMessageJob.php
index dded081..4d30493 100644
--- a/includes/job/MassMessageJob.php
+++ b/includes/job/MassMessageJob.php
@@ -49,7 +49,10 @@
public function isOptedOut( Title $title) {
$wikipage = WikiPage::factory( $title );
$categories = $wikipage->getCategories();
- $category = Title::makeTitle( NS_CATEGORY, wfMessage(
'massmessage-optout-category')->inContentLanguage()->text() );
+ $category = Title::makeTitle(
+ NS_CATEGORY,
+ wfMessage(
'massmessage-optout-category')->inContentLanguage()->text()
+ );
foreach ( $categories as $cat ) {
if ( $category->equals( $cat ) ) {
return true;
@@ -150,7 +153,8 @@
}
// If the page is using a different discussion system, handle
it specially
- if ( class_exists( 'LqtDispatch' ) && LqtDispatch::isLqtPage(
$title ) ) { // This is the same check that LQT uses internally
+ if ( class_exists( 'LqtDispatch' ) && LqtDispatch::isLqtPage(
$title ) ) {
+ // This is the same check that LQT uses internally
$this->addLQTThread();
} elseif ( $title->hasContentModel( 'flow-board' )
// But it can't be a Topic: page, see bug 71196
@@ -223,7 +227,8 @@
) {
$text = substr( $text, 0, -4 );
}
- $text .= "\n" . wfMessage( 'massmessage-hidden-comment'
)->params( $this->params['comment'] )->text();
+ $text .= "\n" . wfMessage( 'massmessage-hidden-comment' )
+ ->params( $this->params['comment'] )->text();
return $text;
}
diff --git a/maintenance/sendMessages.php b/maintenance/sendMessages.php
index 672b057..096843b 100644
--- a/maintenance/sendMessages.php
+++ b/maintenance/sendMessages.php
@@ -4,7 +4,7 @@
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}
-require_once( "$IP/maintenance/Maintenance.php" );
+require_once "$IP/maintenance/Maintenance.php";
/**
* Script to send MassMessages server-side
@@ -47,7 +47,7 @@
$pages = array();
$this->output( "Reading from \"$list\".");
- while( $line = trim( fgets( $file ) ) ) {
+ while ( $line = trim( fgets( $file ) ) ) {
$exp = explode( '\t', $line );
$pages[] = array(
'title' => $exp[0],
diff --git a/tests/MassMessageTargetsTest.php b/tests/MassMessageTargetsTest.php
index 19489b7..b0d3311 100644
--- a/tests/MassMessageTargetsTest.php
+++ b/tests/MassMessageTargetsTest.php
@@ -28,9 +28,23 @@
array( '{{#target:User:<><}}', array(), ),
array( '{{#target:Project:!!!<><><><>', array(), ),
// project page and site
- array( '{{#target:Project:Testing|en.wikipedia.org}}',
array( 'title' => 'Project:Testing', 'site' => 'en.wikipedia.org', 'wiki' =>
'enwiki' ), ),
+ array(
+ '{{#target:Project:Testing|en.wikipedia.org}}',
+ array(
+ 'title' => 'Project:Testing',
+ 'site' => 'en.wikipedia.org',
+ 'wiki' => 'enwiki'
+ ),
+ ),
// user page and site
- array( '{{#target:User talk:Test|fr.wikipedia.org}}',
array( 'title' => 'User talk:Test', 'site' => 'fr.wikipedia.org', 'wiki' =>
'frwiki' ), ),
+ array(
+ '{{#target:User talk:Test|fr.wikipedia.org}}',
+ array(
+ 'title' => 'User talk:Test',
+ 'site' => 'fr.wikipedia.org',
+ 'wiki' => 'frwiki'
+ ),
+ ),
);
}
diff --git a/tests/MassMessageTest.php b/tests/MassMessageTest.php
index 9972755..d65154d 100644
--- a/tests/MassMessageTest.php
+++ b/tests/MassMessageTest.php
@@ -69,7 +69,7 @@
$this->setMwGlobals( 'wgMassMessageAccountUsername', $name );
$user = MassMessage::getMessengerUser();
$this->assertEquals( $name, $user->getName() );
- $this->assertTrue( in_array( 'bot' , $user->getGroups() ) );
+ $this->assertTrue( in_array( 'bot', $user->getGroups() ) );
$this->assertInstanceOf( 'InvalidPassword',
$user->getPassword() );
}
@@ -82,7 +82,13 @@
$title2 = Title::newfromtext( 'R2' );
self::updatePage( $title2, 'foo' );
- $this->assertEquals( $title2->getFullText(),
MassMessage::followRedirect( $title )->getFullText() );
- $this->assertEquals( $title2->getFullText(),
MassMessage::followRedirect( $title2 )->getFullText() );
+ $this->assertEquals(
+ $title2->getFullText(),
+ MassMessage::followRedirect( $title )->getFullText()
+ );
+ $this->assertEquals(
+ $title2->getFullText(),
+ MassMessage::followRedirect( $title2 )->getFullText()
+ );
}
}
diff --git a/tests/content/MassMessageContentHandlerTest.php
b/tests/content/MassMessageContentHandlerTest.php
index 630e517..d1f6865 100644
--- a/tests/content/MassMessageContentHandlerTest.php
+++ b/tests/content/MassMessageContentHandlerTest.php
@@ -13,7 +13,9 @@
public function setUp() {
parent::setUp();
- $this->mergeMwGlobalArrayValue( 'wgGroupPermissions', array(
'*' => array( 'editcontentmodel' => true ) ) );
+ $this->mergeMwGlobalArrayValue(
+ 'wgGroupPermissions', array( '*' => array(
'editcontentmodel' => true ) )
+ );
}
/**
diff --git a/tests/job/MassMessageJobTest.php b/tests/job/MassMessageJobTest.php
index f36b02f..7135791 100644
--- a/tests/job/MassMessageJobTest.php
+++ b/tests/job/MassMessageJobTest.php
@@ -7,8 +7,16 @@
*/
private function simulateJob( $title ) {
$subject = md5( MWCryptRand::generateHex( 15 ) );
- $params = array( 'subject' => $subject, 'message' => 'This is a
message.', 'title' => $title->getFullText() );
- $params['comment'] = array( User::newFromName('Admin'),
'metawiki', 'http://meta.wikimedia.org/w/index.php?title=Spamlist&oldid=5' );
+ $params = array(
+ 'subject' => $subject,
+ 'message' => 'This is a message.',
+ 'title' => $title->getFullText()
+ );
+ $params['comment'] = array(
+ User::newFromName('Admin'),
+ 'metawiki',
+
'http://meta.wikimedia.org/w/index.php?title=Spamlist&oldid=5'
+ );
$job = new MassMessageJob( $title, $params );
$job->run();
return $subject;
@@ -30,7 +38,8 @@
//$this->assertTrue( $target->exists() ); // Message was created
$text = WikiPage::factory( $target )->getContent( Revision::RAW
)->getNativeData();
$this->assertEquals(
- "== $subj ==\n\nThis is a message.\n<!-- Message sent
by User:Admin@metawiki using the list at
http://meta.wikimedia.org/w/index.php?title=Spamlist&oldid=5 -->",
+ "== $subj ==\n\nThis is a message.\n<!-- Message sent
by User:Admin@metawiki' .
+ ' using the list at
http://meta.wikimedia.org/w/index.php?title=Spamlist&oldid=5 -->",
$text
);
}
@@ -60,10 +69,13 @@
$target = Title::newFromText( 'Project:Opt out test page' );
self::updatePage( $target, '[[Category:Opted-out of message
delivery]]');
$this->assertTrue( $fakejob->isOptedOut( $target ) );
- $this->assertFalse( $fakejob->isOptedOut( Title::newFromText(
'Project:Some random page' ) ) );
+ $this->assertFalse( $fakejob->isOptedOut(
+ Title::newFromText( 'Project:Some random page' )
+ ) );
$this->simulateJob( $target ); // Try posting a message to this
page
$text = WikiPage::factory( $target )->getContent( Revision::RAW
)->getNativeData();
- $this->assertEquals( '[[Category:Opted-out of message
delivery]]', $text ); // Nothing should be updated
+ // Nothing should be updated.
+ $this->assertEquals( '[[Category:Opted-out of message
delivery]]', $text );
}
}
diff --git a/tests/job/MassMessageSubmitJobTest.php
b/tests/job/MassMessageSubmitJobTest.php
index a09766d..859f971 100644
--- a/tests/job/MassMessageSubmitJobTest.php
+++ b/tests/job/MassMessageSubmitJobTest.php
@@ -55,7 +55,10 @@
return array(
array( $data, $pages ),
array( $data, $pages + array( array( 'wiki' =>
'dewiki', 'title' => 'Baz foo' ) ) ),
- array( $data + array( 'message' => 'rar' ), $pages +
array( array( 'wiki' => 'zzwiki', 'title' => 'Title!' ) ) ),
+ array(
+ $data + array( 'message' => 'rar' ),
+ $pages + array( array( 'wiki' => 'zzwiki',
'title' => 'Title!' ) )
+ ),
);
}
}
--
To view, visit https://gerrit.wikimedia.org/r/195029
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe33b412aee3580655cddac93df50089ae9d8fd4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits