Merge "build: Add doxygen, use composer for phpcs, make pass"

This commit is contained in:
jenkins-bot 2016-04-25 17:08:51 +00:00 committed by Gerrit Code Review
commit a2fd48d342
17 changed files with 240 additions and 168 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
node_modules node_modules
docs docs
composer.lock
vendor
doc

View file

@ -43,7 +43,9 @@ class ApiFlowThank extends ApiThank {
$rootPost = $data['root']; $rootPost = $data['root'];
$workflowId = $rootPost->getPostId(); $workflowId = $rootPost->getPostId();
$rawTopicTitleText = Utils::htmlToPlaintext( Container::get( 'templating' )->getContent( $rootPost, 'topic-title-html' ) ); $rawTopicTitleText = Utils::htmlToPlaintext(
Container::get( 'templating' )->getContent( $rootPost, 'topic-title-html' )
);
// Truncate the title text to prevent issues with database storage. // Truncate the title text to prevent issues with database storage.
$topicTitleText = $this->getLanguage()->truncate( $rawTopicTitleText, 200 ); $topicTitleText = $this->getLanguage()->truncate( $rawTopicTitleText, 200 );
$pageTitle = $this->getPageTitleFromRootPost( $rootPost ); $pageTitle = $this->getPageTitleFromRootPost( $rootPost );
@ -122,17 +124,17 @@ class ApiFlowThank extends ApiThank {
} }
// Create the notification via Echo extension // Create the notification via Echo extension
EchoEvent::create( array( EchoEvent::create( [
'type' => 'flow-thank', 'type' => 'flow-thank',
'title' => $pageTitle, 'title' => $pageTitle,
'extra' => array( 'extra' => [
'post-id' => $postId->getAlphadecimal(), 'post-id' => $postId->getAlphadecimal(),
'workflow' => $workflowId->getAlphadecimal(), 'workflow' => $workflowId->getAlphadecimal(),
'thanked-user-id' => $recipient->getId(), 'thanked-user-id' => $recipient->getId(),
'topic-title' => $topicTitleText, 'topic-title' => $topicTitleText,
), ],
'agent' => $user, 'agent' => $user,
) ); ] );
// And mark the thank in session for a cheaper check to prevent duplicates (Bug 46690). // And mark the thank in session for a cheaper check to prevent duplicates (Bug 46690).
$user->getRequest()->setSessionData( "flow-thanked-{$postId->getAlphadecimal()}", true ); $user->getRequest()->setSessionData( "flow-thanked-{$postId->getAlphadecimal()}", true );
@ -142,25 +144,25 @@ class ApiFlowThank extends ApiThank {
} }
public function getAllowedParams() { public function getAllowedParams() {
return array( return [
'postid' => array( 'postid' => [
ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true, ApiBase::PARAM_REQUIRED => true,
), ],
'token' => array( 'token' => [
ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true, ApiBase::PARAM_REQUIRED => true,
), ],
); ];
} }
/** /**
* @see ApiBase::getExamplesMessages() * @see ApiBase::getExamplesMessages()
*/ */
protected function getExamplesMessages() { protected function getExamplesMessages() {
return array( return [
'action=flowthank&postid=xyz789&token=123ABC' 'action=flowthank&postid=xyz789&token=123ABC'
=> 'apihelp-flowthank-example-1', => 'apihelp-flowthank-example-1',
); ];
} }
} }

View file

@ -72,7 +72,7 @@ class ApiRevThank extends ApiThank {
return User::newFromId( $recipient ); return User::newFromId( $recipient );
} }
private function sendThanks( User $user, Revision $revision, User $recipient, $source ) { private function sendThanks( User $user, Revision $revision, User $recipient, $source ) {
$uniqueId = "rev-{$revision->getId()}"; $uniqueId = "rev-{$revision->getId()}";
// Do one last check to make sure we haven't sent Thanks before // Do one last check to make sure we haven't sent Thanks before
if ( $this->haveAlreadyThanked( $user, $uniqueId ) ) { if ( $this->haveAlreadyThanked( $user, $uniqueId ) ) {
@ -83,16 +83,16 @@ class ApiRevThank extends ApiThank {
$title = $this->getTitleFromRevision( $revision ); $title = $this->getTitleFromRevision( $revision );
// Create the notification via Echo extension // Create the notification via Echo extension
EchoEvent::create( array( EchoEvent::create( [
'type' => 'edit-thank', 'type' => 'edit-thank',
'title' => $title, 'title' => $title,
'extra' => array( 'extra' => [
'revid' => $revision->getId(), 'revid' => $revision->getId(),
'thanked-user-id' => $recipient->getId(), 'thanked-user-id' => $recipient->getId(),
'source' => $source, 'source' => $source,
), ],
'agent' => $user, 'agent' => $user,
) ); ] );
// And mark the thank in session for a cheaper check to prevent duplicates (Bug 46690). // And mark the thank in session for a cheaper check to prevent duplicates (Bug 46690).
$user->getRequest()->setSessionData( "thanks-thanked-{$revision->getId()}", true ); $user->getRequest()->setSessionData( "thanks-thanked-{$revision->getId()}", true );
@ -102,36 +102,36 @@ class ApiRevThank extends ApiThank {
} }
public function getAllowedParams() { public function getAllowedParams() {
return array( return [
'rev' => array( 'rev' => [
ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_REQUIRED => true, ApiBase::PARAM_REQUIRED => true,
), ],
'token' => array( 'token' => [
ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true, ApiBase::PARAM_REQUIRED => true,
), ],
'source' => array( 'source' => [
ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => false, ApiBase::PARAM_REQUIRED => false,
) ]
); ];
} }
public function getHelpUrls() { public function getHelpUrls() {
return array( return [
'https://www.mediawiki.org/wiki/Extension:Thanks#API_Documentation', 'https://www.mediawiki.org/wiki/Extension:Thanks#API_Documentation',
); ];
} }
/** /**
* @see ApiBase::getExamplesMessages() * @see ApiBase::getExamplesMessages()
*/ */
protected function getExamplesMessages() { protected function getExamplesMessages() {
return array( return [
'action=thank&revid=456&source=diff&token=123ABC' 'action=thank&revid=456&source=diff&token=123ABC'
=> 'apihelp-thank-example-1', => 'apihelp-thank-example-1',
); ];
} }
} }

View file

@ -16,9 +16,9 @@ abstract class ApiThank extends ApiBase {
if ( $user->isAnon() ) { if ( $user->isAnon() ) {
$this->dieUsage( 'Anonymous users cannot send thanks', 'notloggedin' ); $this->dieUsage( 'Anonymous users cannot send thanks', 'notloggedin' );
} elseif ( $user->pingLimiter( 'thanks-notification' ) ) { } elseif ( $user->pingLimiter( 'thanks-notification' ) ) {
$this->dieUsageMsg( array( 'actionthrottledtext' ) ); $this->dieUsageMsg( [ 'actionthrottledtext' ] );
} elseif ( $user->isBlocked() ) { } elseif ( $user->isBlocked() ) {
$this->dieUsageMsg( array( 'blockedtext' ) ); $this->dieUsageMsg( [ 'blockedtext' ] );
} }
} }
@ -33,10 +33,10 @@ abstract class ApiThank extends ApiBase {
} }
protected function markResultSuccess( $recipientName ) { protected function markResultSuccess( $recipientName ) {
$this->getResult()->addValue( null, 'result', array( $this->getResult()->addValue( null, 'result', [
'success' => 1, 'success' => 1,
'recipient' => $recipientName, 'recipient' => $recipientName,
) ); ] );
} }
/** /**
@ -49,16 +49,16 @@ abstract class ApiThank extends ApiBase {
protected function haveAlreadyThanked( User $thanker, $uniqueId ) { protected function haveAlreadyThanked( User $thanker, $uniqueId ) {
$dbw = wfGetDB( DB_MASTER ); $dbw = wfGetDB( DB_MASTER );
return (bool)$dbw->selectRow( return (bool)$dbw->selectRow(
array( 'log_search', 'logging' ), [ 'log_search', 'logging' ],
array( 'ls_value' ), [ 'ls_value' ],
array( [
'log_user' => $thanker->getId(), 'log_user' => $thanker->getId(),
'ls_field' => 'thankid', 'ls_field' => 'thankid',
'ls_value' => $uniqueId, 'ls_value' => $uniqueId,
), ],
__METHOD__, __METHOD__,
array(), [],
array( 'logging' => array( 'INNER JOIN', 'ls_log_id=log_id' ) ) [ 'logging' => [ 'INNER JOIN', 'ls_log_id=log_id' ] ]
); );
} }
@ -75,7 +75,7 @@ abstract class ApiThank extends ApiBase {
} }
$logEntry = new ManualLogEntry( 'thanks', 'thank' ); $logEntry = new ManualLogEntry( 'thanks', 'thank' );
$logEntry->setPerformer( $user ); $logEntry->setPerformer( $user );
$logEntry->setRelations( array( 'thankid' => $uniqueId ) ); $logEntry->setRelations( [ 'thankid' => $uniqueId ] );
$target = $recipient->getUserPage(); $target = $recipient->getUserPage();
$logEntry->setTarget( $target ); $logEntry->setTarget( $target );
$logId = $logEntry->insert(); $logId = $logEntry->insert();

34
Doxyfile Normal file
View file

@ -0,0 +1,34 @@
# Configuration file for Doxygen
PROJECT_NAME = Thanks
PROJECT_BRIEF = "MediaWiki Thanks extension"
OUTPUT_DIRECTORY = doc
JAVADOC_AUTOBRIEF = YES
QT_AUTOBRIEF = YES
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = NO
WARN_IF_DOC_ERROR = NO
WARN_NO_PARAMDOC = NO
EXCLUDE = doc docs vendor node_modules
FILE_PATTERNS = *.php
RECURSIVE = YES
HTML_DYNAMIC_SECTIONS = YES
GENERATE_TREEVIEW = YES
TREEVIEW_WIDTH = 250
GENERATE_LATEX = NO
HAVE_DOT = YES
DOT_FONTNAME = Helvetica
DOT_FONTSIZE = 10
TEMPLATE_RELATIONS = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
# Makes dot run faster. Requires graphviz >1.8.10
DOT_MULTI_TARGETS = YES

View file

@ -13,14 +13,14 @@ class EchoFlowThanksFormatter extends EchoBasicFormatter {
$this->setTitleLink( $this->setTitleLink(
$event, $event,
$message, $message,
array( [
'class' => 'mw-echo-diff', 'class' => 'mw-echo-diff',
'linkText' => $this->getMessage( 'notification-flow-thanks-post-link' )->text(), 'linkText' => $this->getMessage( 'notification-flow-thanks-post-link' )->text(),
'param' => array( 'param' => [
'workflow' => $event->getExtraParam( 'workflow' ), 'workflow' => $event->getExtraParam( 'workflow' ),
), ],
'fragment' => "flow-post-{$event->getExtraParam( 'post-id' )}", 'fragment' => "flow-post-{$event->getExtraParam( 'post-id' )}",
) ]
); );
} elseif ( $param === 'topictitle' ) { } elseif ( $param === 'topictitle' ) {
$message->params( $event->getExtraParam( 'topic-title' ) ); $message->params( $event->getExtraParam( 'topic-title' ) );
@ -39,7 +39,7 @@ class EchoFlowThanksFormatter extends EchoBasicFormatter {
*/ */
protected function getLinkParams( $event, $user, $destination ) { protected function getLinkParams( $event, $user, $destination ) {
$target = null; $target = null;
$query = array(); $query = [];
if ( $destination === 'post' ) { if ( $destination === 'post' ) {
$target = $event->getTitle(); $target = $event->getTitle();
@ -47,7 +47,7 @@ class EchoFlowThanksFormatter extends EchoBasicFormatter {
$target->setFragment( '#flow-post-' . $event->getExtraParam( 'post-id' ) ); $target->setFragment( '#flow-post-' . $event->getExtraParam( 'post-id' ) );
$query['workflow'] = $event->getExtraParam( 'workflow' ); $query['workflow'] = $event->getExtraParam( 'workflow' );
} }
return array( $target, $query ); return [ $target, $query ];
} else { } else {
return parent::getLinkParams( $event, $user, $destination ); return parent::getLinkParams( $event, $user, $destination );
} }

View file

@ -29,15 +29,15 @@ class EchoFlowThanksPresentationModel extends Flow\FlowPresentationModel {
'flow-post-' . $this->event->getExtraParam( 'post-id' ) 'flow-post-' . $this->event->getExtraParam( 'post-id' )
); );
return array( return [
'url' => $title->getFullURL( array( 'url' => $title->getFullURL( [
'workflow' => $this->event->getExtraParam( 'workflow' ) 'workflow' => $this->event->getExtraParam( 'workflow' )
) ), ] ),
'label' => $this->msg( 'notification-link-text-view-post' )->text(), 'label' => $this->msg( 'notification-link-text-view-post' )->text(),
); ];
} }
public function getSecondaryLinks() { public function getSecondaryLinks() {
return array( $this->getAgentLink(), $this->getBoardLink() ); return [ $this->getAgentLink(), $this->getBoardLink() ];
} }
} }

View file

@ -57,15 +57,15 @@ class SpecialThanks extends FormSpecialPage {
* @return Array * @return Array
*/ */
protected function getFormFields() { protected function getFormFields() {
return array( return [
'revid' => array( 'revid' => [
'id' => 'mw-thanks-form-revid', 'id' => 'mw-thanks-form-revid',
'name' => 'revid', 'name' => 'revid',
'type' => 'hidden', 'type' => 'hidden',
'label-message' => 'thanks-form-revid', 'label-message' => 'thanks-form-revid',
'default' => $this->id, 'default' => $this->id,
) ]
); ];
} }
/** /**
@ -115,18 +115,18 @@ class SpecialThanks extends FormSpecialPage {
} }
if ( $this->type === 'rev' ) { if ( $this->type === 'rev' ) {
$requestData = array( $requestData = [
'action' => 'thank', 'action' => 'thank',
'rev' => (int)$data['revid'], 'rev' => (int)$data['revid'],
'source' => 'specialpage', 'source' => 'specialpage',
'token' => $this->getUser()->getEditToken(), 'token' => $this->getUser()->getEditToken(),
); ];
} else { } else {
$requestData = array( $requestData = [
'action' => 'flowthank', 'action' => 'flowthank',
'postid' => $data['revid'], 'postid' => $data['revid'],
'token' => $this->getUser()->getEditToken(), 'token' => $this->getUser()->getEditToken(),
); ];
} }
$request = new DerivativeRequest( $request = new DerivativeRequest(
@ -147,7 +147,7 @@ class SpecialThanks extends FormSpecialPage {
} }
if ( defined( 'ApiResult::META_CONTENT' ) ) { if ( defined( 'ApiResult::META_CONTENT' ) ) {
$this->result = $api->getResult()->getResultData( array( 'result' ) ); $this->result = $api->getResult()->getResultData( [ 'result' ] );
} else { } else {
$result = $api->getResult()->getData(); $result = $api->getResult()->getData();
$this->result = $result['result']; $this->result = $result['result'];

View file

@ -19,15 +19,15 @@ class ThanksHooks {
ResourceLoader &$resourceLoader ResourceLoader &$resourceLoader
) { ) {
if ( class_exists( 'SpecialMobileDiff' ) ) { if ( class_exists( 'SpecialMobileDiff' ) ) {
$testModules['qunit']['tests.ext.thanks.mobilediff'] = array( $testModules['qunit']['tests.ext.thanks.mobilediff'] = [
'localBasePath' => __DIR__, 'localBasePath' => __DIR__,
'remoteExtPath' => 'Thanks', 'remoteExtPath' => 'Thanks',
'dependencies' => array( 'ext.thanks.mobilediff' ), 'dependencies' => [ 'ext.thanks.mobilediff' ],
'scripts' => array( 'scripts' => [
'tests/qunit/test_ext.thanks.mobilediff.js', 'tests/qunit/test_ext.thanks.mobilediff.js',
), ],
'targets' => array( 'desktop', 'mobile' ), 'targets' => [ 'desktop', 'mobile' ],
); ];
} }
return true; return true;
} }
@ -94,7 +94,7 @@ class ThanksHooks {
if ( $wgUser->getRequest()->getSessionData( "thanks-thanked-{$rev->getId()}" ) ) { if ( $wgUser->getRequest()->getSessionData( "thanks-thanked-{$rev->getId()}" ) ) {
return Html::element( return Html::element(
'span', 'span',
array( 'class' => 'mw-thanks-thanked' ), [ 'class' => 'mw-thanks-thanked' ],
wfMessage( 'thanks-thanked', $wgUser, $recipient->getName() )->text() wfMessage( 'thanks-thanked', $wgUser, $recipient->getName() )->text()
); );
} }
@ -106,12 +106,12 @@ class ThanksHooks {
return Html::element( return Html::element(
'a', 'a',
array( [
'class' => 'mw-thanks-thank-link', 'class' => 'mw-thanks-thank-link',
'href' => SpecialPage::getTitleFor( 'Thanks', $rev->getId() )->getFullURL(), 'href' => SpecialPage::getTitleFor( 'Thanks', $rev->getId() )->getFullURL(),
'title' => $tooltip, 'title' => $tooltip,
'data-revision-id' => $rev->getId(), 'data-revision-id' => $rev->getId(),
), ],
wfMessage( 'thanks-thank', $wgUser, $recipient->getName() )->text() wfMessage( 'thanks-thank', $wgUser, $recipient->getName() )->text()
); );
} }
@ -119,7 +119,8 @@ class ThanksHooks {
/** /**
* Handler for PageHistoryBeforeList hook. * Handler for PageHistoryBeforeList hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/PageHistoryBeforeList * @see http://www.mediawiki.org/wiki/Manual:Hooks/PageHistoryBeforeList
* @param &$page WikiPage|Article|ImagePage|CategoryPage|Page The page that the history is loading for. * @param &$page WikiPage|Article|ImagePage|CategoryPage|Page The page for which the history
* is loading.
* @param $context RequestContext object * @param $context RequestContext object
* @return bool true in all cases * @return bool true in all cases
*/ */
@ -129,7 +130,7 @@ class ThanksHooks {
&& $context->getUser()->isLoggedIn() && $context->getUser()->isLoggedIn()
) { ) {
// Load the module for the thank links // Load the module for the thank links
$context->getOutput()->addModules( array( 'ext.thanks.revthank' ) ); $context->getOutput()->addModules( [ 'ext.thanks.revthank' ] );
$context->getOutput()->addJsConfigVars( 'thanks-confirmation-required', $context->getOutput()->addJsConfigVars( 'thanks-confirmation-required',
$wgThanksConfirmationRequired ); $wgThanksConfirmationRequired );
} }
@ -150,7 +151,7 @@ class ThanksHooks {
&& $diff->getUser()->isLoggedIn() && $diff->getUser()->isLoggedIn()
) { ) {
// Load the module for the thank link // Load the module for the thank link
$diff->getOutput()->addModules( array( 'ext.thanks.revthank' ) ); $diff->getOutput()->addModules( [ 'ext.thanks.revthank' ] );
$diff->getOutput()->addJsConfigVars( 'thanks-confirmation-required', $diff->getOutput()->addJsConfigVars( 'thanks-confirmation-required',
$wgThanksConfirmationRequired ); $wgThanksConfirmationRequired );
} }
@ -165,46 +166,48 @@ class ThanksHooks {
* @param $icons array of icon details * @param $icons array of icon details
* @return bool * @return bool
*/ */
public static function onBeforeCreateEchoEvent( &$notifications, &$notificationCategories, &$icons ) { public static function onBeforeCreateEchoEvent(
$notificationCategories['edit-thank'] = array( &$notifications, &$notificationCategories, &$icons
) {
$notificationCategories['edit-thank'] = [
'priority' => 3, 'priority' => 3,
'tooltip' => 'echo-pref-tooltip-edit-thank', 'tooltip' => 'echo-pref-tooltip-edit-thank',
); ];
$notifications['edit-thank'] = array( $notifications['edit-thank'] = [
'primary-link' => array( 'message' => 'notification-link-text-view-edit', 'destination' => 'diff' ), 'primary-link' => [ 'message' => 'notification-link-text-view-edit', 'destination' => 'diff' ],
'category' => 'edit-thank', 'category' => 'edit-thank',
'group' => 'positive', 'group' => 'positive',
'presentation-model' => 'EchoThanksPresentationModel', 'presentation-model' => 'EchoThanksPresentationModel',
'formatter-class' => 'EchoThanksFormatter', 'formatter-class' => 'EchoThanksFormatter',
'title-message' => 'notification-thanks', 'title-message' => 'notification-thanks',
'title-params' => array( 'agent', 'difflink', 'title' ), 'title-params' => [ 'agent', 'difflink', 'title' ],
'payload' => array( 'summary' ), 'payload' => [ 'summary' ],
'email-subject-message' => 'notification-thanks-email-subject', 'email-subject-message' => 'notification-thanks-email-subject',
'email-subject-params' => array( 'agent' ), 'email-subject-params' => [ 'agent' ],
'email-body-batch-message' => 'notification-thanks-email-batch-body', 'email-body-batch-message' => 'notification-thanks-email-batch-body',
'email-body-batch-params' => array( 'agent', 'title' ), 'email-body-batch-params' => [ 'agent', 'title' ],
'icon' => 'thanks', 'icon' => 'thanks',
); ];
$notifications['flow-thank'] = array( $notifications['flow-thank'] = [
'primary-link' => array( 'message' => 'notification-link-text-view-post', 'destination' => 'post' ), 'primary-link' => [ 'message' => 'notification-link-text-view-post', 'destination' => 'post' ],
'category' => 'edit-thank', 'category' => 'edit-thank',
'group' => 'positive', 'group' => 'positive',
'presentation-model' => 'EchoFlowThanksPresentationModel', 'presentation-model' => 'EchoFlowThanksPresentationModel',
'formatter-class' => 'EchoFlowThanksFormatter', 'formatter-class' => 'EchoFlowThanksFormatter',
'title-message' => 'notification-flow-thanks', 'title-message' => 'notification-flow-thanks',
'title-params' => array( 'agent', 'postlink', 'topictitle', 'title', 'user' ), 'title-params' => [ 'agent', 'postlink', 'topictitle', 'title', 'user' ],
'email-subject-message' => 'notification-flow-thanks-email-subject', 'email-subject-message' => 'notification-flow-thanks-email-subject',
'email-subject-params' => array( 'agent', 'user' ), 'email-subject-params' => [ 'agent', 'user' ],
'email-body-batch-message' => 'notification-flow-thanks-email-batch-body', 'email-body-batch-message' => 'notification-flow-thanks-email-batch-body',
'email-body-batch-params' => array( 'agent', 'topictitle', 'title', 'user' ), 'email-body-batch-params' => [ 'agent', 'topictitle', 'title', 'user' ],
'icon' => 'thanks', 'icon' => 'thanks',
); ];
$icons['thanks'] = array( $icons['thanks'] = [
'path' => 'Thanks/ThankYou.png', 'path' => 'Thanks/ThankYou.png',
); ];
return true; return true;
} }
@ -264,7 +267,7 @@ class ThanksHooks {
&& self::canReceiveThanks( User::newFromId( $rev->getUser() ) ) && self::canReceiveThanks( User::newFromId( $rev->getUser() ) )
&& $output->getUser()->isLoggedIn() && $output->getUser()->isLoggedIn()
) { ) {
$output->addModules( array( 'ext.thanks.mobilediff' ) ); $output->addModules( [ 'ext.thanks.mobilediff' ] );
if ( $output->getRequest()->getSessionData( 'thanks-thanked-' . $rev->getId() ) ) { if ( $output->getRequest()->getSessionData( 'thanks-thanked-' . $rev->getId() ) ) {
// User already sent thanks for this revision // User already sent thanks for this revision

View file

@ -18,14 +18,14 @@ class EchoThanksFormatter extends EchoBasicFormatter {
$this->setTitleLink( $this->setTitleLink(
$event, $event,
$message, $message,
array( [
'class' => 'mw-echo-diff', 'class' => 'mw-echo-diff',
'linkText' => wfMessage( 'notification-thanks-diff-link' )->text(), 'linkText' => wfMessage( 'notification-thanks-diff-link' )->text(),
'param' => array( 'param' => [
'oldid' => $eventData['revid'], 'oldid' => $eventData['revid'],
'diff' => 'prev', 'diff' => 'prev',
) ]
) ]
); );
} else { } else {

View file

@ -12,9 +12,9 @@ class ThanksLogFormatter extends LogFormatter {
$params[3] = $recipient->getName(); $params[3] = $recipient->getName();
return $params; return $params;
} }
public function getPreloadTitles() { public function getPreloadTitles() {
// Add the recipient's user talk page to LinkBatch // Add the recipient's user talk page to LinkBatch
return array( Title::makeTitle( NS_USER_TALK, $this->entry->getTarget()->getText() ) ); return [ Title::makeTitle( NS_USER_TALK, $this->entry->getTarget()->getText() ) ];
} }
} }

View file

@ -16,16 +16,16 @@ class EchoThanksPresentationModel extends EchoEventPresentationModel {
} }
public function getPrimaryLink() { public function getPrimaryLink() {
return array( return [
'url' => $this->event->getTitle()->getLocalURL( array( 'url' => $this->event->getTitle()->getLocalURL( [
'oldid' => 'prev', 'oldid' => 'prev',
'diff' => $this->event->getExtraParam( 'revid' ) 'diff' => $this->event->getExtraParam( 'revid' )
) ), ] ),
'label' => $this->msg( 'notification-link-text-view-edit' )->text(), 'label' => $this->msg( 'notification-link-text-view-edit' )->text(),
); ];
} }
public function getSecondaryLinks() { public function getSecondaryLinks() {
return array( $this->getAgentLink() ); return [ $this->getAgentLink() ];
} }
} }

18
composer.json Normal file
View file

@ -0,0 +1,18 @@
{
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9.2",
"mediawiki/mediawiki-codesniffer": "0.6.0"
},
"scripts": {
"test": [
"parallel-lint . --exclude vendor",
"phpcs -p -s"
],
"fix": [
"phpcbf"
],
"doc": [
"doxygen"
]
}
}

8
phpcs.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
<file>.</file>
<arg name="extensions" value="php,php5,inc"/>
<arg name="encoding" value="utf8"/>
<exclude-pattern>vendor</exclude-pattern>
</ruleset>

View file

@ -21,8 +21,7 @@ class ApiFlowThankTest extends ApiTestCase {
/** /**
* @var PostRevision * @var PostRevision
*/ */
public public $topic,
$topic,
$postByOtherUser, $postByOtherUser,
$postByMe; $postByMe;
@ -35,14 +34,14 @@ class ApiFlowThankTest extends ApiTestCase {
// mock topic and post // mock topic and post
$this->topic = $this->generateObject(); $this->topic = $this->generateObject();
$this->postByOtherUser = $this->generateObject( array( $this->postByOtherUser = $this->generateObject( [
'tree_orig_user_id' => self::$users[ 'uploader' ]->getUser()->getId(), 'tree_orig_user_id' => self::$users[ 'uploader' ]->getUser()->getId(),
'tree_parent_id' => $this->topic->getPostId()->getBinary(), 'tree_parent_id' => $this->topic->getPostId()->getBinary(),
), array(), 1 ); ], [], 1 );
$this->postByMe = $this->generateObject( array( $this->postByMe = $this->generateObject( [
'tree_orig_user_id' => self::$users[ 'sysop' ]->getUser()->getId(), 'tree_orig_user_id' => self::$users[ 'sysop' ]->getUser()->getId(),
'tree_parent_id' => $this->topic->getPostId()->getBinary(), 'tree_parent_id' => $this->topic->getPostId()->getBinary(),
), array(), 1 ); ], [], 1 );
// Set up mock classes in Container. // Set up mock classes in Container.
$mockLoader = $this->getMockBuilder( '\Flow\Repository\RootPostLoader' ) $mockLoader = $this->getMockBuilder( '\Flow\Repository\RootPostLoader' )
@ -57,19 +56,19 @@ class ApiFlowThankTest extends ApiTestCase {
function( $postId ) use ( $that ) { function( $postId ) use ( $that ) {
switch ( $postId ) { switch ( $postId ) {
case $that->postByOtherUser->getPostId(): case $that->postByOtherUser->getPostId():
return array( return [
'post' => $that->postByOtherUser, 'post' => $that->postByOtherUser,
'root' => $that->topic 'root' => $that->topic
); ];
case $that->postByMe->getPostId(): case $that->postByMe->getPostId():
return array( return [
'post' => $that->postByMe, 'post' => $that->postByMe,
'root' => $that->topic 'root' => $that->topic
); ];
default: default:
return array( 'post' => null ); return [ 'post' => null ];
} }
} }
) ); ) );
@ -77,7 +76,7 @@ class ApiFlowThankTest extends ApiTestCase {
$mockWorkflow = $this->getMock( '\Flow\Model\Workflow' ); $mockWorkflow = $this->getMock( '\Flow\Model\Workflow' );
$mockWorkflow->expects( $this->any() ) $mockWorkflow->expects( $this->any() )
->method( 'getOwnerTitle' ) ->method( 'getOwnerTitle' )
->will( $this->returnValue( new Title() )); ->will( $this->returnValue( new Title() ) );
$mockStorage = $this->getMockBuilder( '\Flow\Data\ManagerGroup' ) $mockStorage = $this->getMockBuilder( '\Flow\Data\ManagerGroup' )
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -87,7 +86,6 @@ class ApiFlowThankTest extends ApiTestCase {
->method( 'get' ) ->method( 'get' )
->will( $this->returnValue( $mockWorkflow ) ); ->will( $this->returnValue( $mockWorkflow ) );
$mockTemplating = $this->getMockBuilder( 'Flow\Templating' ) $mockTemplating = $this->getMockBuilder( 'Flow\Templating' )
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -106,48 +104,47 @@ class ApiFlowThankTest extends ApiTestCase {
\DeferredUpdates::clearPendingUpdates(); \DeferredUpdates::clearPendingUpdates();
} }
public function testRequestWithoutToken(){ public function testRequestWithoutToken() {
$this->setExpectedException( 'UsageException', 'The token parameter must be set' ); $this->setExpectedException( 'UsageException', 'The token parameter must be set' );
$this->doApiRequest( array( $this->doApiRequest( [
'action' => 'flowthank', 'action' => 'flowthank',
'postid' => UUID::create( '42' )->getAlphadecimal(), 'postid' => UUID::create( '42' )->getAlphadecimal(),
) ); ] );
} }
public function testInvalidRequest(){ public function testInvalidRequest() {
$this->setExpectedException( 'UsageException', 'The postid parameter must be set' ); $this->setExpectedException( 'UsageException', 'The postid parameter must be set' );
$this->doApiRequestWithToken( array( 'action' => 'flowthank' ) ); $this->doApiRequestWithToken( [ 'action' => 'flowthank' ] );
} }
public function testValidRequest(){ public function testValidRequest() {
list( $result,, ) = $this->doApiRequestWithToken( array( list( $result,, ) = $this->doApiRequestWithToken( [
'action' => 'flowthank', 'action' => 'flowthank',
'postid' => $this->postByOtherUser->getPostId()->getAlphadecimal(), 'postid' => $this->postByOtherUser->getPostId()->getAlphadecimal(),
) ); ] );
$this->assertSuccess( $result ); $this->assertSuccess( $result );
} }
public function testRequestWithInvalidId(){ public function testRequestWithInvalidId() {
$this->setExpectedException( 'UsageException', 'Post ID is invalid' ); $this->setExpectedException( 'UsageException', 'Post ID is invalid' );
list( $result,, ) = $this->doApiRequestWithToken( array( list( $result,, ) = $this->doApiRequestWithToken( [
'action' => 'flowthank', 'action' => 'flowthank',
'postid' => UUID::create( '42' )->getAlphadecimal(), 'postid' => UUID::create( '42' )->getAlphadecimal(),
) ); ] );
} }
public function testRequestWithOwnId(){ public function testRequestWithOwnId() {
$this->setExpectedException( 'UsageException', 'You cannot thank yourself' ); $this->setExpectedException( 'UsageException', 'You cannot thank yourself' );
list( $result,, ) = $this->doApiRequestWithToken( array( list( $result,, ) = $this->doApiRequestWithToken( [
'action' => 'flowthank', 'action' => 'flowthank',
'postid' => $this->postByMe->getPostId()->getAlphadecimal(), 'postid' => $this->postByMe->getPostId()->getAlphadecimal(),
) ); ] );
} }
protected function assertSuccess( $result ){ protected function assertSuccess( $result ) {
$this->assertEquals( 1, $result[ 'result' ][ 'success' ] ); $this->assertEquals( 1, $result[ 'result' ][ 'success' ] );
} }
/** /**
* This method is obtained from Flow/tests/PostRevisionTestCase.php * This method is obtained from Flow/tests/PostRevisionTestCase.php
* *
@ -161,7 +158,7 @@ class ApiFlowThankTest extends ApiTestCase {
* @param array[optional] $row DB row data (only specify override columns) * @param array[optional] $row DB row data (only specify override columns)
* @return array * @return array
*/ */
protected function generateRow( array $row = array() ) { protected function generateRow( array $row = [] ) {
$uuidPost = UUID::create(); $uuidPost = UUID::create();
$uuidRevision = UUID::create(); $uuidRevision = UUID::create();
@ -169,7 +166,7 @@ class ApiFlowThankTest extends ApiTestCase {
$userId = $user->getId(); $userId = $user->getId();
$userIp = null; $userIp = null;
return $row + array( return $row + [
// flow_revision // flow_revision
'rev_id' => $uuidRevision->getBinary(), 'rev_id' => $uuidRevision->getBinary(),
'rev_type' => 'post', 'rev_type' => 'post',
@ -200,7 +197,7 @@ class ApiFlowThankTest extends ApiTestCase {
'tree_orig_user_ip' => $userIp, 'tree_orig_user_ip' => $userIp,
'tree_orig_user_wiki' => wfWikiId(), 'tree_orig_user_wiki' => wfWikiId(),
'tree_parent_id' => null, 'tree_parent_id' => null,
); ];
} }
/** /**
@ -217,7 +214,7 @@ class ApiFlowThankTest extends ApiTestCase {
* @param int[optional] $depth Depth of the PostRevision object * @param int[optional] $depth Depth of the PostRevision object
* @return PostRevision * @return PostRevision
*/ */
protected function generateObject( array $row = array(), $children = array(), $depth = 0 ) { protected function generateObject( array $row = [], $children = [], $depth = 0 ) {
$row = $this->generateRow( $row ); $row = $this->generateRow( $row );
$revision = PostRevision::fromStorageRow( $row ); $revision = PostRevision::fromStorageRow( $row );

View file

@ -22,38 +22,42 @@ class ApiRevThankTest extends ApiTestCase {
$this->newRevId(); $this->newRevId();
} }
public function testRequestWithoutToken(){ public function testRequestWithoutToken() {
$this->setExpectedException( 'UsageException', 'The token parameter must be set' ); $this->setExpectedException( 'UsageException', 'The token parameter must be set' );
$this->doApiRequest( array( $this->doApiRequest( [
'action' => 'thank', 'action' => 'thank',
'source' => 'someSource', 'source' => 'someSource',
'rev' => 1, 'rev' => 1,
) ); ] );
} }
public function testValidRequest(){ public function testValidRequest() {
list( $result,, ) = $this->doApiRequestWithToken( array( list( $result,, ) = $this->doApiRequestWithToken( [
'action' => 'thank', 'action' => 'thank',
'rev' => $this->newRevId(), 'rev' => $this->newRevId(),
) ); ] );
$this->assertSuccess( $result ); $this->assertSuccess( $result );
} }
public function testValidRequestWithSource(){ public function testValidRequestWithSource() {
list( $result,, ) = $this->doApiRequestWithToken( array( list( $result,, ) = $this->doApiRequestWithToken( [
'action' => 'thank', 'action' => 'thank',
'source' => 'someSource', 'source' => 'someSource',
'rev' => $this->newRevId(), 'rev' => $this->newRevId(),
) ); ] );
$this->assertSuccess( $result ); $this->assertSuccess( $result );
} }
protected function newRevId(){ protected function newRevId() {
// You can't thank yourself, kind of hacky // You can't thank yourself, kind of hacky
$this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() ); $this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() );
/** @var Status $result */ /** @var Status $result */
$result = $this->editPage( 'thanks' . rand( 0, 100 ), 'thanks' . rand( 0, 100 ), 'thanksSummary' ); $result = $this->editPage(
'thanks' . rand( 0, 100 ),
'thanks' . rand( 0, 100 ),
'thanksSummary'
);
$result = $result->getValue(); $result = $result->getValue();
/** @var Revision $revision */ /** @var Revision $revision */
$revision = $result['revision']; $revision = $result['revision'];
@ -63,18 +67,18 @@ class ApiRevThankTest extends ApiTestCase {
return $revision->getId(); return $revision->getId();
} }
protected function assertSuccess( $result ){ protected function assertSuccess( $result ) {
$this->assertEquals( array( $this->assertEquals( [
'result' => array( 'result' => [
'success' => 1, 'success' => 1,
'recipient' => self::$users['uploader']->username, 'recipient' => self::$users['uploader']->username,
), ],
), $result ); ], $result );
} }
public function testInvalidRequest(){ public function testInvalidRequest() {
$this->setExpectedException( 'UsageException' ); $this->setExpectedException( 'UsageException' );
$this->doApiRequestWithToken( array( 'action' => 'thank' ) ); $this->doApiRequestWithToken( [ 'action' => 'thank' ] );
} }
} }

View file

@ -10,7 +10,7 @@
*/ */
class ApiRevThankUnitTest extends MediaWikiTestCase { class ApiRevThankUnitTest extends MediaWikiTestCase {
static $moduleName = 'thank'; protected static $moduleName = 'thank';
protected function getModule() { protected function getModule() {
return new ApiRevThank( new ApiMain(), self::$moduleName ); return new ApiRevThank( new ApiMain(), self::$moduleName );
@ -25,24 +25,24 @@ class ApiRevThankUnitTest extends MediaWikiTestCase {
$method = new ReflectionMethod( $module, 'dieOnBadUser' ); $method = new ReflectionMethod( $module, 'dieOnBadUser' );
$method->setAccessible( true ); $method->setAccessible( true );
if( $expectedError ) { if ( $expectedError ) {
$this->setExpectedException( 'UsageException', $expectedError ); $this->setExpectedException( 'UsageException', $expectedError );
} }
$method->invoke( $module, $user ); $method->invoke( $module, $user );
//perhaps the method should return true.. For now we must do this // perhaps the method should return true.. For now we must do this
$this->assertTrue( true ); $this->assertTrue( true );
} }
public function provideDieOnBadUser() { public function provideDieOnBadUser() {
$testCases = array(); $testCases = [];
$mockUser = $this->getMock( 'User' ); $mockUser = $this->getMock( 'User' );
$mockUser->expects( $this->once() ) $mockUser->expects( $this->once() )
->method( 'isAnon' ) ->method( 'isAnon' )
->will( $this->returnValue( true ) ); ->will( $this->returnValue( true ) );
$testCases[ 'anon' ] = array( $mockUser, 'Anonymous users cannot send thanks' ); $testCases[ 'anon' ] = [ $mockUser, 'Anonymous users cannot send thanks' ];
$mockUser = $this->getMock( 'User' ); $mockUser = $this->getMock( 'User' );
$mockUser->expects( $this->once() ) $mockUser->expects( $this->once() )
@ -52,7 +52,10 @@ class ApiRevThankUnitTest extends MediaWikiTestCase {
->method( 'pingLimiter' ) ->method( 'pingLimiter' )
->will( $this->returnValue( true ) ); ->will( $this->returnValue( true ) );
$testCases[ 'ping' ] = array( $mockUser, "You've exceeded your rate limit. Please wait some time and try again" ); $testCases[ 'ping' ] = [
$mockUser,
"You've exceeded your rate limit. Please wait some time and try again"
];
$mockUser = $this->getMock( 'User' ); $mockUser = $this->getMock( 'User' );
$mockUser->expects( $this->once() ) $mockUser->expects( $this->once() )
@ -65,17 +68,17 @@ class ApiRevThankUnitTest extends MediaWikiTestCase {
->method( 'isBlocked' ) ->method( 'isBlocked' )
->will( $this->returnValue( true ) ); ->will( $this->returnValue( true ) );
$testCases[ 'blocked' ] = array( $mockUser, 'You have been blocked from editing' ); $testCases[ 'blocked' ] = [ $mockUser, 'You have been blocked from editing' ];
return $testCases; return $testCases;
} }
//@todo test userAlreadySentThanksForRevision // @todo test userAlreadySentThanksForRevision
//@todo test getRevisionFromParams // @todo test getRevisionFromParams
//@todo test getTitleFromRevision // @todo test getTitleFromRevision
//@todo test getSourceFromParams // @todo test getSourceFromParams
//@todo test getUserIdFromRevision // @todo test getUserIdFromRevision
//@todo test markResultSuccess // @todo test markResultSuccess
//@todo test sendThanks // @todo test sendThanks
} }