mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-15 10:59:42 +00:00
Merge "build: Add doxygen, use composer for phpcs, make pass"
This commit is contained in:
commit
a2fd48d342
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
|||
node_modules
|
||||
docs
|
||||
composer.lock
|
||||
vendor
|
||||
doc
|
||||
|
|
|
@ -43,7 +43,9 @@ class ApiFlowThank extends ApiThank {
|
|||
|
||||
$rootPost = $data['root'];
|
||||
$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.
|
||||
$topicTitleText = $this->getLanguage()->truncate( $rawTopicTitleText, 200 );
|
||||
$pageTitle = $this->getPageTitleFromRootPost( $rootPost );
|
||||
|
@ -122,17 +124,17 @@ class ApiFlowThank extends ApiThank {
|
|||
}
|
||||
|
||||
// Create the notification via Echo extension
|
||||
EchoEvent::create( array(
|
||||
EchoEvent::create( [
|
||||
'type' => 'flow-thank',
|
||||
'title' => $pageTitle,
|
||||
'extra' => array(
|
||||
'extra' => [
|
||||
'post-id' => $postId->getAlphadecimal(),
|
||||
'workflow' => $workflowId->getAlphadecimal(),
|
||||
'thanked-user-id' => $recipient->getId(),
|
||||
'topic-title' => $topicTitleText,
|
||||
),
|
||||
],
|
||||
'agent' => $user,
|
||||
) );
|
||||
] );
|
||||
|
||||
// And mark the thank in session for a cheaper check to prevent duplicates (Bug 46690).
|
||||
$user->getRequest()->setSessionData( "flow-thanked-{$postId->getAlphadecimal()}", true );
|
||||
|
@ -142,25 +144,25 @@ class ApiFlowThank extends ApiThank {
|
|||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'postid' => array(
|
||||
return [
|
||||
'postid' => [
|
||||
ApiBase::PARAM_TYPE => 'string',
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
),
|
||||
'token' => array(
|
||||
],
|
||||
'token' => [
|
||||
ApiBase::PARAM_TYPE => 'string',
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ApiBase::getExamplesMessages()
|
||||
*/
|
||||
protected function getExamplesMessages() {
|
||||
return array(
|
||||
return [
|
||||
'action=flowthank&postid=xyz789&token=123ABC'
|
||||
=> 'apihelp-flowthank-example-1',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ class ApiRevThank extends ApiThank {
|
|||
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()}";
|
||||
// Do one last check to make sure we haven't sent Thanks before
|
||||
if ( $this->haveAlreadyThanked( $user, $uniqueId ) ) {
|
||||
|
@ -83,16 +83,16 @@ class ApiRevThank extends ApiThank {
|
|||
|
||||
$title = $this->getTitleFromRevision( $revision );
|
||||
// Create the notification via Echo extension
|
||||
EchoEvent::create( array(
|
||||
EchoEvent::create( [
|
||||
'type' => 'edit-thank',
|
||||
'title' => $title,
|
||||
'extra' => array(
|
||||
'extra' => [
|
||||
'revid' => $revision->getId(),
|
||||
'thanked-user-id' => $recipient->getId(),
|
||||
'source' => $source,
|
||||
),
|
||||
],
|
||||
'agent' => $user,
|
||||
) );
|
||||
] );
|
||||
|
||||
// And mark the thank in session for a cheaper check to prevent duplicates (Bug 46690).
|
||||
$user->getRequest()->setSessionData( "thanks-thanked-{$revision->getId()}", true );
|
||||
|
@ -102,36 +102,36 @@ class ApiRevThank extends ApiThank {
|
|||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'rev' => array(
|
||||
return [
|
||||
'rev' => [
|
||||
ApiBase::PARAM_TYPE => 'integer',
|
||||
ApiBase::PARAM_MIN => 1,
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
),
|
||||
'token' => array(
|
||||
],
|
||||
'token' => [
|
||||
ApiBase::PARAM_TYPE => 'string',
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
),
|
||||
'source' => array(
|
||||
],
|
||||
'source' => [
|
||||
ApiBase::PARAM_TYPE => 'string',
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getHelpUrls() {
|
||||
return array(
|
||||
return [
|
||||
'https://www.mediawiki.org/wiki/Extension:Thanks#API_Documentation',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ApiBase::getExamplesMessages()
|
||||
*/
|
||||
protected function getExamplesMessages() {
|
||||
return array(
|
||||
return [
|
||||
'action=thank&revid=456&source=diff&token=123ABC'
|
||||
=> 'apihelp-thank-example-1',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
22
ApiThank.php
22
ApiThank.php
|
@ -16,9 +16,9 @@ abstract class ApiThank extends ApiBase {
|
|||
if ( $user->isAnon() ) {
|
||||
$this->dieUsage( 'Anonymous users cannot send thanks', 'notloggedin' );
|
||||
} elseif ( $user->pingLimiter( 'thanks-notification' ) ) {
|
||||
$this->dieUsageMsg( array( 'actionthrottledtext' ) );
|
||||
$this->dieUsageMsg( [ 'actionthrottledtext' ] );
|
||||
} elseif ( $user->isBlocked() ) {
|
||||
$this->dieUsageMsg( array( 'blockedtext' ) );
|
||||
$this->dieUsageMsg( [ 'blockedtext' ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,10 @@ abstract class ApiThank extends ApiBase {
|
|||
}
|
||||
|
||||
protected function markResultSuccess( $recipientName ) {
|
||||
$this->getResult()->addValue( null, 'result', array(
|
||||
$this->getResult()->addValue( null, 'result', [
|
||||
'success' => 1,
|
||||
'recipient' => $recipientName,
|
||||
) );
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,16 +49,16 @@ abstract class ApiThank extends ApiBase {
|
|||
protected function haveAlreadyThanked( User $thanker, $uniqueId ) {
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
return (bool)$dbw->selectRow(
|
||||
array( 'log_search', 'logging' ),
|
||||
array( 'ls_value' ),
|
||||
array(
|
||||
[ 'log_search', 'logging' ],
|
||||
[ 'ls_value' ],
|
||||
[
|
||||
'log_user' => $thanker->getId(),
|
||||
'ls_field' => 'thankid',
|
||||
'ls_value' => $uniqueId,
|
||||
),
|
||||
],
|
||||
__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->setPerformer( $user );
|
||||
$logEntry->setRelations( array( 'thankid' => $uniqueId ) );
|
||||
$logEntry->setRelations( [ 'thankid' => $uniqueId ] );
|
||||
$target = $recipient->getUserPage();
|
||||
$logEntry->setTarget( $target );
|
||||
$logId = $logEntry->insert();
|
||||
|
|
34
Doxyfile
Normal file
34
Doxyfile
Normal 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
|
|
@ -13,14 +13,14 @@ class EchoFlowThanksFormatter extends EchoBasicFormatter {
|
|||
$this->setTitleLink(
|
||||
$event,
|
||||
$message,
|
||||
array(
|
||||
[
|
||||
'class' => 'mw-echo-diff',
|
||||
'linkText' => $this->getMessage( 'notification-flow-thanks-post-link' )->text(),
|
||||
'param' => array(
|
||||
'param' => [
|
||||
'workflow' => $event->getExtraParam( 'workflow' ),
|
||||
),
|
||||
],
|
||||
'fragment' => "flow-post-{$event->getExtraParam( 'post-id' )}",
|
||||
)
|
||||
]
|
||||
);
|
||||
} elseif ( $param === 'topictitle' ) {
|
||||
$message->params( $event->getExtraParam( 'topic-title' ) );
|
||||
|
@ -39,7 +39,7 @@ class EchoFlowThanksFormatter extends EchoBasicFormatter {
|
|||
*/
|
||||
protected function getLinkParams( $event, $user, $destination ) {
|
||||
$target = null;
|
||||
$query = array();
|
||||
$query = [];
|
||||
|
||||
if ( $destination === 'post' ) {
|
||||
$target = $event->getTitle();
|
||||
|
@ -47,7 +47,7 @@ class EchoFlowThanksFormatter extends EchoBasicFormatter {
|
|||
$target->setFragment( '#flow-post-' . $event->getExtraParam( 'post-id' ) );
|
||||
$query['workflow'] = $event->getExtraParam( 'workflow' );
|
||||
}
|
||||
return array( $target, $query );
|
||||
return [ $target, $query ];
|
||||
} else {
|
||||
return parent::getLinkParams( $event, $user, $destination );
|
||||
}
|
||||
|
|
|
@ -29,15 +29,15 @@ class EchoFlowThanksPresentationModel extends Flow\FlowPresentationModel {
|
|||
'flow-post-' . $this->event->getExtraParam( 'post-id' )
|
||||
);
|
||||
|
||||
return array(
|
||||
'url' => $title->getFullURL( array(
|
||||
return [
|
||||
'url' => $title->getFullURL( [
|
||||
'workflow' => $this->event->getExtraParam( 'workflow' )
|
||||
) ),
|
||||
] ),
|
||||
'label' => $this->msg( 'notification-link-text-view-post' )->text(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function getSecondaryLinks() {
|
||||
return array( $this->getAgentLink(), $this->getBoardLink() );
|
||||
return [ $this->getAgentLink(), $this->getBoardLink() ];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,15 +57,15 @@ class SpecialThanks extends FormSpecialPage {
|
|||
* @return Array
|
||||
*/
|
||||
protected function getFormFields() {
|
||||
return array(
|
||||
'revid' => array(
|
||||
return [
|
||||
'revid' => [
|
||||
'id' => 'mw-thanks-form-revid',
|
||||
'name' => 'revid',
|
||||
'type' => 'hidden',
|
||||
'label-message' => 'thanks-form-revid',
|
||||
'default' => $this->id,
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,18 +115,18 @@ class SpecialThanks extends FormSpecialPage {
|
|||
}
|
||||
|
||||
if ( $this->type === 'rev' ) {
|
||||
$requestData = array(
|
||||
$requestData = [
|
||||
'action' => 'thank',
|
||||
'rev' => (int)$data['revid'],
|
||||
'source' => 'specialpage',
|
||||
'token' => $this->getUser()->getEditToken(),
|
||||
);
|
||||
];
|
||||
} else {
|
||||
$requestData = array(
|
||||
$requestData = [
|
||||
'action' => 'flowthank',
|
||||
'postid' => $data['revid'],
|
||||
'token' => $this->getUser()->getEditToken(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$request = new DerivativeRequest(
|
||||
|
@ -147,7 +147,7 @@ class SpecialThanks extends FormSpecialPage {
|
|||
}
|
||||
|
||||
if ( defined( 'ApiResult::META_CONTENT' ) ) {
|
||||
$this->result = $api->getResult()->getResultData( array( 'result' ) );
|
||||
$this->result = $api->getResult()->getResultData( [ 'result' ] );
|
||||
} else {
|
||||
$result = $api->getResult()->getData();
|
||||
$this->result = $result['result'];
|
||||
|
|
|
@ -19,15 +19,15 @@ class ThanksHooks {
|
|||
ResourceLoader &$resourceLoader
|
||||
) {
|
||||
if ( class_exists( 'SpecialMobileDiff' ) ) {
|
||||
$testModules['qunit']['tests.ext.thanks.mobilediff'] = array(
|
||||
$testModules['qunit']['tests.ext.thanks.mobilediff'] = [
|
||||
'localBasePath' => __DIR__,
|
||||
'remoteExtPath' => 'Thanks',
|
||||
'dependencies' => array( 'ext.thanks.mobilediff' ),
|
||||
'scripts' => array(
|
||||
'dependencies' => [ 'ext.thanks.mobilediff' ],
|
||||
'scripts' => [
|
||||
'tests/qunit/test_ext.thanks.mobilediff.js',
|
||||
),
|
||||
'targets' => array( 'desktop', 'mobile' ),
|
||||
);
|
||||
],
|
||||
'targets' => [ 'desktop', 'mobile' ],
|
||||
];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ class ThanksHooks {
|
|||
if ( $wgUser->getRequest()->getSessionData( "thanks-thanked-{$rev->getId()}" ) ) {
|
||||
return Html::element(
|
||||
'span',
|
||||
array( 'class' => 'mw-thanks-thanked' ),
|
||||
[ 'class' => 'mw-thanks-thanked' ],
|
||||
wfMessage( 'thanks-thanked', $wgUser, $recipient->getName() )->text()
|
||||
);
|
||||
}
|
||||
|
@ -106,12 +106,12 @@ class ThanksHooks {
|
|||
|
||||
return Html::element(
|
||||
'a',
|
||||
array(
|
||||
[
|
||||
'class' => 'mw-thanks-thank-link',
|
||||
'href' => SpecialPage::getTitleFor( 'Thanks', $rev->getId() )->getFullURL(),
|
||||
'title' => $tooltip,
|
||||
'data-revision-id' => $rev->getId(),
|
||||
),
|
||||
],
|
||||
wfMessage( 'thanks-thank', $wgUser, $recipient->getName() )->text()
|
||||
);
|
||||
}
|
||||
|
@ -119,7 +119,8 @@ class ThanksHooks {
|
|||
/**
|
||||
* Handler for PageHistoryBeforeList hook.
|
||||
* @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
|
||||
* @return bool true in all cases
|
||||
*/
|
||||
|
@ -129,7 +130,7 @@ class ThanksHooks {
|
|||
&& $context->getUser()->isLoggedIn()
|
||||
) {
|
||||
// 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',
|
||||
$wgThanksConfirmationRequired );
|
||||
}
|
||||
|
@ -150,7 +151,7 @@ class ThanksHooks {
|
|||
&& $diff->getUser()->isLoggedIn()
|
||||
) {
|
||||
// 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',
|
||||
$wgThanksConfirmationRequired );
|
||||
}
|
||||
|
@ -165,46 +166,48 @@ class ThanksHooks {
|
|||
* @param $icons array of icon details
|
||||
* @return bool
|
||||
*/
|
||||
public static function onBeforeCreateEchoEvent( &$notifications, &$notificationCategories, &$icons ) {
|
||||
$notificationCategories['edit-thank'] = array(
|
||||
public static function onBeforeCreateEchoEvent(
|
||||
&$notifications, &$notificationCategories, &$icons
|
||||
) {
|
||||
$notificationCategories['edit-thank'] = [
|
||||
'priority' => 3,
|
||||
'tooltip' => 'echo-pref-tooltip-edit-thank',
|
||||
);
|
||||
];
|
||||
|
||||
$notifications['edit-thank'] = array(
|
||||
'primary-link' => array( 'message' => 'notification-link-text-view-edit', 'destination' => 'diff' ),
|
||||
$notifications['edit-thank'] = [
|
||||
'primary-link' => [ 'message' => 'notification-link-text-view-edit', 'destination' => 'diff' ],
|
||||
'category' => 'edit-thank',
|
||||
'group' => 'positive',
|
||||
'presentation-model' => 'EchoThanksPresentationModel',
|
||||
'formatter-class' => 'EchoThanksFormatter',
|
||||
'title-message' => 'notification-thanks',
|
||||
'title-params' => array( 'agent', 'difflink', 'title' ),
|
||||
'payload' => array( 'summary' ),
|
||||
'title-params' => [ 'agent', 'difflink', 'title' ],
|
||||
'payload' => [ 'summary' ],
|
||||
'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-params' => array( 'agent', 'title' ),
|
||||
'email-body-batch-params' => [ 'agent', 'title' ],
|
||||
'icon' => 'thanks',
|
||||
);
|
||||
];
|
||||
|
||||
$notifications['flow-thank'] = array(
|
||||
'primary-link' => array( 'message' => 'notification-link-text-view-post', 'destination' => 'post' ),
|
||||
$notifications['flow-thank'] = [
|
||||
'primary-link' => [ 'message' => 'notification-link-text-view-post', 'destination' => 'post' ],
|
||||
'category' => 'edit-thank',
|
||||
'group' => 'positive',
|
||||
'presentation-model' => 'EchoFlowThanksPresentationModel',
|
||||
'formatter-class' => 'EchoFlowThanksFormatter',
|
||||
'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-params' => array( 'agent', 'user' ),
|
||||
'email-subject-params' => [ 'agent', 'user' ],
|
||||
'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',
|
||||
);
|
||||
];
|
||||
|
||||
$icons['thanks'] = array(
|
||||
$icons['thanks'] = [
|
||||
'path' => 'Thanks/ThankYou.png',
|
||||
);
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -264,7 +267,7 @@ class ThanksHooks {
|
|||
&& self::canReceiveThanks( User::newFromId( $rev->getUser() ) )
|
||||
&& $output->getUser()->isLoggedIn()
|
||||
) {
|
||||
$output->addModules( array( 'ext.thanks.mobilediff' ) );
|
||||
$output->addModules( [ 'ext.thanks.mobilediff' ] );
|
||||
|
||||
if ( $output->getRequest()->getSessionData( 'thanks-thanked-' . $rev->getId() ) ) {
|
||||
// User already sent thanks for this revision
|
||||
|
|
|
@ -18,14 +18,14 @@ class EchoThanksFormatter extends EchoBasicFormatter {
|
|||
$this->setTitleLink(
|
||||
$event,
|
||||
$message,
|
||||
array(
|
||||
[
|
||||
'class' => 'mw-echo-diff',
|
||||
'linkText' => wfMessage( 'notification-thanks-diff-link' )->text(),
|
||||
'param' => array(
|
||||
'param' => [
|
||||
'oldid' => $eventData['revid'],
|
||||
'diff' => 'prev',
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
} else {
|
||||
|
|
|
@ -12,9 +12,9 @@ class ThanksLogFormatter extends LogFormatter {
|
|||
$params[3] = $recipient->getName();
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
public function getPreloadTitles() {
|
||||
// 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() ) ];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,16 +16,16 @@ class EchoThanksPresentationModel extends EchoEventPresentationModel {
|
|||
}
|
||||
|
||||
public function getPrimaryLink() {
|
||||
return array(
|
||||
'url' => $this->event->getTitle()->getLocalURL( array(
|
||||
return [
|
||||
'url' => $this->event->getTitle()->getLocalURL( [
|
||||
'oldid' => 'prev',
|
||||
'diff' => $this->event->getExtraParam( 'revid' )
|
||||
) ),
|
||||
] ),
|
||||
'label' => $this->msg( 'notification-link-text-view-edit' )->text(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function getSecondaryLinks() {
|
||||
return array( $this->getAgentLink() );
|
||||
return [ $this->getAgentLink() ];
|
||||
}
|
||||
}
|
||||
|
|
18
composer.json
Normal file
18
composer.json
Normal 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
8
phpcs.xml
Normal 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>
|
|
@ -21,8 +21,7 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
/**
|
||||
* @var PostRevision
|
||||
*/
|
||||
public
|
||||
$topic,
|
||||
public $topic,
|
||||
$postByOtherUser,
|
||||
$postByMe;
|
||||
|
||||
|
@ -35,14 +34,14 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
|
||||
// mock topic and post
|
||||
$this->topic = $this->generateObject();
|
||||
$this->postByOtherUser = $this->generateObject( array(
|
||||
$this->postByOtherUser = $this->generateObject( [
|
||||
'tree_orig_user_id' => self::$users[ 'uploader' ]->getUser()->getId(),
|
||||
'tree_parent_id' => $this->topic->getPostId()->getBinary(),
|
||||
), array(), 1 );
|
||||
$this->postByMe = $this->generateObject( array(
|
||||
], [], 1 );
|
||||
$this->postByMe = $this->generateObject( [
|
||||
'tree_orig_user_id' => self::$users[ 'sysop' ]->getUser()->getId(),
|
||||
'tree_parent_id' => $this->topic->getPostId()->getBinary(),
|
||||
), array(), 1 );
|
||||
], [], 1 );
|
||||
|
||||
// Set up mock classes in Container.
|
||||
$mockLoader = $this->getMockBuilder( '\Flow\Repository\RootPostLoader' )
|
||||
|
@ -57,19 +56,19 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
function( $postId ) use ( $that ) {
|
||||
switch ( $postId ) {
|
||||
case $that->postByOtherUser->getPostId():
|
||||
return array(
|
||||
return [
|
||||
'post' => $that->postByOtherUser,
|
||||
'root' => $that->topic
|
||||
);
|
||||
];
|
||||
|
||||
case $that->postByMe->getPostId():
|
||||
return array(
|
||||
return [
|
||||
'post' => $that->postByMe,
|
||||
'root' => $that->topic
|
||||
);
|
||||
];
|
||||
|
||||
default:
|
||||
return array( 'post' => null );
|
||||
return [ 'post' => null ];
|
||||
}
|
||||
}
|
||||
) );
|
||||
|
@ -77,7 +76,7 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
$mockWorkflow = $this->getMock( '\Flow\Model\Workflow' );
|
||||
$mockWorkflow->expects( $this->any() )
|
||||
->method( 'getOwnerTitle' )
|
||||
->will( $this->returnValue( new Title() ));
|
||||
->will( $this->returnValue( new Title() ) );
|
||||
|
||||
$mockStorage = $this->getMockBuilder( '\Flow\Data\ManagerGroup' )
|
||||
->disableOriginalConstructor()
|
||||
|
@ -87,7 +86,6 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
->method( 'get' )
|
||||
->will( $this->returnValue( $mockWorkflow ) );
|
||||
|
||||
|
||||
$mockTemplating = $this->getMockBuilder( 'Flow\Templating' )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -106,48 +104,47 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
\DeferredUpdates::clearPendingUpdates();
|
||||
}
|
||||
|
||||
public function testRequestWithoutToken(){
|
||||
public function testRequestWithoutToken() {
|
||||
$this->setExpectedException( 'UsageException', 'The token parameter must be set' );
|
||||
$this->doApiRequest( array(
|
||||
$this->doApiRequest( [
|
||||
'action' => 'flowthank',
|
||||
'postid' => UUID::create( '42' )->getAlphadecimal(),
|
||||
) );
|
||||
] );
|
||||
}
|
||||
|
||||
public function testInvalidRequest(){
|
||||
public function testInvalidRequest() {
|
||||
$this->setExpectedException( 'UsageException', 'The postid parameter must be set' );
|
||||
$this->doApiRequestWithToken( array( 'action' => 'flowthank' ) );
|
||||
$this->doApiRequestWithToken( [ 'action' => 'flowthank' ] );
|
||||
}
|
||||
|
||||
public function testValidRequest(){
|
||||
list( $result,, ) = $this->doApiRequestWithToken( array(
|
||||
public function testValidRequest() {
|
||||
list( $result,, ) = $this->doApiRequestWithToken( [
|
||||
'action' => 'flowthank',
|
||||
'postid' => $this->postByOtherUser->getPostId()->getAlphadecimal(),
|
||||
) );
|
||||
] );
|
||||
$this->assertSuccess( $result );
|
||||
}
|
||||
|
||||
public function testRequestWithInvalidId(){
|
||||
public function testRequestWithInvalidId() {
|
||||
$this->setExpectedException( 'UsageException', 'Post ID is invalid' );
|
||||
list( $result,, ) = $this->doApiRequestWithToken( array(
|
||||
list( $result,, ) = $this->doApiRequestWithToken( [
|
||||
'action' => 'flowthank',
|
||||
'postid' => UUID::create( '42' )->getAlphadecimal(),
|
||||
) );
|
||||
] );
|
||||
}
|
||||
|
||||
public function testRequestWithOwnId(){
|
||||
public function testRequestWithOwnId() {
|
||||
$this->setExpectedException( 'UsageException', 'You cannot thank yourself' );
|
||||
list( $result,, ) = $this->doApiRequestWithToken( array(
|
||||
list( $result,, ) = $this->doApiRequestWithToken( [
|
||||
'action' => 'flowthank',
|
||||
'postid' => $this->postByMe->getPostId()->getAlphadecimal(),
|
||||
) );
|
||||
] );
|
||||
}
|
||||
|
||||
protected function assertSuccess( $result ){
|
||||
protected function assertSuccess( $result ) {
|
||||
$this->assertEquals( 1, $result[ 'result' ][ 'success' ] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @return array
|
||||
*/
|
||||
protected function generateRow( array $row = array() ) {
|
||||
protected function generateRow( array $row = [] ) {
|
||||
$uuidPost = UUID::create();
|
||||
$uuidRevision = UUID::create();
|
||||
|
||||
|
@ -169,7 +166,7 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
$userId = $user->getId();
|
||||
$userIp = null;
|
||||
|
||||
return $row + array(
|
||||
return $row + [
|
||||
// flow_revision
|
||||
'rev_id' => $uuidRevision->getBinary(),
|
||||
'rev_type' => 'post',
|
||||
|
@ -200,7 +197,7 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
'tree_orig_user_ip' => $userIp,
|
||||
'tree_orig_user_wiki' => wfWikiId(),
|
||||
'tree_parent_id' => null,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,7 +214,7 @@ class ApiFlowThankTest extends ApiTestCase {
|
|||
* @param int[optional] $depth Depth of the PostRevision object
|
||||
* @return PostRevision
|
||||
*/
|
||||
protected function generateObject( array $row = array(), $children = array(), $depth = 0 ) {
|
||||
protected function generateObject( array $row = [], $children = [], $depth = 0 ) {
|
||||
$row = $this->generateRow( $row );
|
||||
|
||||
$revision = PostRevision::fromStorageRow( $row );
|
||||
|
|
|
@ -22,38 +22,42 @@ class ApiRevThankTest extends ApiTestCase {
|
|||
$this->newRevId();
|
||||
}
|
||||
|
||||
public function testRequestWithoutToken(){
|
||||
public function testRequestWithoutToken() {
|
||||
$this->setExpectedException( 'UsageException', 'The token parameter must be set' );
|
||||
$this->doApiRequest( array(
|
||||
$this->doApiRequest( [
|
||||
'action' => 'thank',
|
||||
'source' => 'someSource',
|
||||
'rev' => 1,
|
||||
) );
|
||||
] );
|
||||
}
|
||||
|
||||
public function testValidRequest(){
|
||||
list( $result,, ) = $this->doApiRequestWithToken( array(
|
||||
public function testValidRequest() {
|
||||
list( $result,, ) = $this->doApiRequestWithToken( [
|
||||
'action' => 'thank',
|
||||
'rev' => $this->newRevId(),
|
||||
) );
|
||||
] );
|
||||
$this->assertSuccess( $result );
|
||||
}
|
||||
|
||||
public function testValidRequestWithSource(){
|
||||
list( $result,, ) = $this->doApiRequestWithToken( array(
|
||||
public function testValidRequestWithSource() {
|
||||
list( $result,, ) = $this->doApiRequestWithToken( [
|
||||
'action' => 'thank',
|
||||
'source' => 'someSource',
|
||||
'rev' => $this->newRevId(),
|
||||
) );
|
||||
] );
|
||||
$this->assertSuccess( $result );
|
||||
}
|
||||
|
||||
protected function newRevId(){
|
||||
protected function newRevId() {
|
||||
// You can't thank yourself, kind of hacky
|
||||
$this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() );
|
||||
|
||||
/** @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();
|
||||
/** @var Revision $revision */
|
||||
$revision = $result['revision'];
|
||||
|
@ -63,18 +67,18 @@ class ApiRevThankTest extends ApiTestCase {
|
|||
return $revision->getId();
|
||||
}
|
||||
|
||||
protected function assertSuccess( $result ){
|
||||
$this->assertEquals( array(
|
||||
'result' => array(
|
||||
protected function assertSuccess( $result ) {
|
||||
$this->assertEquals( [
|
||||
'result' => [
|
||||
'success' => 1,
|
||||
'recipient' => self::$users['uploader']->username,
|
||||
),
|
||||
), $result );
|
||||
],
|
||||
], $result );
|
||||
}
|
||||
|
||||
public function testInvalidRequest(){
|
||||
public function testInvalidRequest() {
|
||||
$this->setExpectedException( 'UsageException' );
|
||||
$this->doApiRequestWithToken( array( 'action' => 'thank' ) );
|
||||
$this->doApiRequestWithToken( [ 'action' => 'thank' ] );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
class ApiRevThankUnitTest extends MediaWikiTestCase {
|
||||
|
||||
static $moduleName = 'thank';
|
||||
protected static $moduleName = 'thank';
|
||||
|
||||
protected function getModule() {
|
||||
return new ApiRevThank( new ApiMain(), self::$moduleName );
|
||||
|
@ -25,24 +25,24 @@ class ApiRevThankUnitTest extends MediaWikiTestCase {
|
|||
$method = new ReflectionMethod( $module, 'dieOnBadUser' );
|
||||
$method->setAccessible( true );
|
||||
|
||||
if( $expectedError ) {
|
||||
if ( $expectedError ) {
|
||||
$this->setExpectedException( 'UsageException', $expectedError );
|
||||
}
|
||||
|
||||
$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 );
|
||||
}
|
||||
|
||||
public function provideDieOnBadUser() {
|
||||
$testCases = array();
|
||||
$testCases = [];
|
||||
|
||||
$mockUser = $this->getMock( 'User' );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->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->expects( $this->once() )
|
||||
|
@ -52,7 +52,10 @@ class ApiRevThankUnitTest extends MediaWikiTestCase {
|
|||
->method( 'pingLimiter' )
|
||||
->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->expects( $this->once() )
|
||||
|
@ -65,17 +68,17 @@ class ApiRevThankUnitTest extends MediaWikiTestCase {
|
|||
->method( 'isBlocked' )
|
||||
->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;
|
||||
}
|
||||
|
||||
//@todo test userAlreadySentThanksForRevision
|
||||
//@todo test getRevisionFromParams
|
||||
//@todo test getTitleFromRevision
|
||||
//@todo test getSourceFromParams
|
||||
//@todo test getUserIdFromRevision
|
||||
//@todo test markResultSuccess
|
||||
//@todo test sendThanks
|
||||
// @todo test userAlreadySentThanksForRevision
|
||||
// @todo test getRevisionFromParams
|
||||
// @todo test getTitleFromRevision
|
||||
// @todo test getSourceFromParams
|
||||
// @todo test getUserIdFromRevision
|
||||
// @todo test markResultSuccess
|
||||
// @todo test sendThanks
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue