Index: trunk/extensions/LiquidThreads/api/ApiThreadAction.php |
— | — | @@ -12,6 +12,9 @@ |
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
| 16 | + if ( !count( $params['threadaction'] ) ) { |
| 17 | + $this->dieUsageMsg( array( 'missingparam', 'action' ) ); |
| 18 | + } |
16 | 19 | |
17 | 20 | $allowedAllActions = array( 'markread' ); |
18 | 21 | $action = $params['threadaction']; |
— | — | @@ -280,7 +283,7 @@ |
281 | 284 | 'minor' => 0, |
282 | 285 | 'format' => 'json', |
283 | 286 | ); |
284 | | - |
| 287 | + |
285 | 288 | if ( $wgUser->isAllowed('bot') ) { |
286 | 289 | $requestData['bot'] = true; |
287 | 290 | } |
— | — | @@ -328,7 +331,7 @@ |
329 | 332 | |
330 | 333 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
331 | 334 | } |
332 | | - |
| 335 | + |
333 | 336 | public function actionEdit( $threads, $params ) { |
334 | 337 | if ( count( $threads ) > 1 ) { |
335 | 338 | $this->dieUsage( 'You may only edit one thread at a time', |
— | — | @@ -337,10 +340,10 @@ |
338 | 341 | $this->dieUsage( 'You must specify a thread to edit', |
339 | 342 | 'no-specified-threads' ); |
340 | 343 | } |
341 | | - |
| 344 | + |
342 | 345 | $thread = array_pop( $threads ); |
343 | 346 | $talkpage = $thread->article(); |
344 | | - |
| 347 | + |
345 | 348 | $bump = isset( $params['bump'] ) ? $params['bump'] : null; |
346 | 349 | |
347 | 350 | // Validate subject |
— | — | @@ -358,21 +361,21 @@ |
359 | 362 | $this->dieUsage( 'The subject you specified is not valid', |
360 | 363 | 'invalid-subject' ); |
361 | 364 | } |
362 | | - |
| 365 | + |
363 | 366 | // Check for text |
364 | 367 | if ( empty( $params['text'] ) ) { |
365 | 368 | $this->dieUsage( 'You must include text in your post', 'no-text' ); |
366 | 369 | } |
367 | 370 | $text = $params['text']; |
368 | | - |
| 371 | + |
369 | 372 | $summary = ''; |
370 | 373 | if ( !empty( $params['reason'] ) ) { |
371 | 374 | $summary = $params['reason']; |
372 | 375 | } |
373 | | - |
| 376 | + |
374 | 377 | $article = $thread->root(); |
375 | 378 | $title = $article->getTitle(); |
376 | | - |
| 379 | + |
377 | 380 | $signature = null; |
378 | 381 | if ( isset( $params['signature'] ) ) { |
379 | 382 | $signature = $params['signature']; |
— | — | @@ -386,7 +389,7 @@ |
387 | 390 | LqtHooks::$editAppliesTo = null; |
388 | 391 | |
389 | 392 | $token = $params['token']; |
390 | | - |
| 393 | + |
391 | 394 | // All seems in order. Construct an API edit request |
392 | 395 | $requestData = array( |
393 | 396 | 'action' => 'edit', |
— | — | @@ -398,7 +401,7 @@ |
399 | 402 | 'basetimestamp' => wfTimestampNow(), |
400 | 403 | 'format' => 'json', |
401 | 404 | ); |
402 | | - |
| 405 | + |
403 | 406 | global $wgUser; |
404 | 407 | |
405 | 408 | if ( $wgUser->isAllowed('bot') ) { |
— | — | @@ -417,7 +420,7 @@ |
418 | 421 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
419 | 422 | return; |
420 | 423 | } |
421 | | - |
| 424 | + |
422 | 425 | $thread = LqtView::editMetadataUpdates( |
423 | 426 | array( |
424 | 427 | 'root' => $article, |
— | — | @@ -444,7 +447,7 @@ |
445 | 448 | |
446 | 449 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
447 | 450 | } |
448 | | - |
| 451 | + |
449 | 452 | public function actionReply( $threads, $params ) { |
450 | 453 | global $wgUser; |
451 | 454 | |
— | — | @@ -517,7 +520,7 @@ |
518 | 521 | 'minor' => 0, |
519 | 522 | 'format' => 'json', |
520 | 523 | ); |
521 | | - |
| 524 | + |
522 | 525 | if ( $wgUser->isAllowed('bot') ) { |
523 | 526 | $requestData['bot'] = true; |
524 | 527 | } |
— | — | @@ -689,111 +692,111 @@ |
690 | 693 | |
691 | 694 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
692 | 695 | } |
693 | | - |
| 696 | + |
694 | 697 | public function actionAddReaction( $threads, $params ) { |
695 | 698 | global $wgUser; |
696 | | - |
| 699 | + |
697 | 700 | if ( !count( $threads ) ) { |
698 | 701 | $this->dieUsage( 'You must specify a thread to add a reaction for', |
699 | 702 | 'no-specified-threads' ); |
700 | 703 | } |
701 | | - |
| 704 | + |
702 | 705 | if ( ! $wgUser->isAllowed( 'lqt-react' ) ) { |
703 | 706 | $this->dieUsage( 'You are not allowed to react to threads.', 'permission-denied' ); |
704 | 707 | } |
705 | 708 | |
706 | 709 | $required = array( 'type', 'value' ); |
707 | | - |
| 710 | + |
708 | 711 | if ( count( array_diff( $required, array_keys($params) ) ) ) { |
709 | 712 | $this->dieUsage( 'You must specify both a type and a value for the reaction', |
710 | 713 | 'missing-parameter' ); |
711 | 714 | } |
712 | | - |
| 715 | + |
713 | 716 | $result = array(); |
714 | | - |
| 717 | + |
715 | 718 | foreach( $threads as $thread ) { |
716 | 719 | $thread->addReaction( $wgUser, $params['type'], $params['value'] ); |
717 | | - |
| 720 | + |
718 | 721 | $result[] = array( |
719 | 722 | 'result' => 'Success', |
720 | 723 | 'action' => 'addreaction', |
721 | 724 | 'id' => $thread->id(), |
722 | 725 | ); |
723 | 726 | } |
724 | | - |
| 727 | + |
725 | 728 | $this->getResult()->setIndexedTagName( $result, 'thread' ); |
726 | 729 | $this->getResult()->addValue( null, 'threadaction', $result ); |
727 | 730 | } |
728 | | - |
| 731 | + |
729 | 732 | public function actionDeleteReaction( $threads, $params ) { |
730 | 733 | global $wgUser; |
731 | | - |
| 734 | + |
732 | 735 | if ( !count( $threads ) ) { |
733 | 736 | $this->dieUsage( 'You must specify a thread to delete a reaction for', |
734 | 737 | 'no-specified-threads' ); |
735 | 738 | } |
736 | | - |
| 739 | + |
737 | 740 | if ( ! $wgUser->isAllowed( 'lqt-react' ) ) { |
738 | 741 | $this->dieUsage( 'You are not allowed to react to threads.', 'permission-denied' ); |
739 | 742 | } |
740 | 743 | |
741 | 744 | $required = array( 'type', 'value' ); |
742 | | - |
| 745 | + |
743 | 746 | if ( count( array_diff( $required, array_keys($params) ) ) ) { |
744 | 747 | $this->dieUsage( 'You must specify both a type for the reaction', |
745 | 748 | 'missing-parameter' ); |
746 | 749 | } |
747 | | - |
| 750 | + |
748 | 751 | $result = array(); |
749 | | - |
| 752 | + |
750 | 753 | foreach( $threads as $thread ) { |
751 | 754 | $thread->deleteReaction( $wgUser, $params['type'] ); |
752 | | - |
| 755 | + |
753 | 756 | $result[] = array( |
754 | 757 | 'result' => 'Success', |
755 | 758 | 'action' => 'deletereaction', |
756 | 759 | 'id' => $thread->id(), |
757 | 760 | ); |
758 | 761 | } |
759 | | - |
| 762 | + |
760 | 763 | $this->getResult()->setIndexedTagName( $result, 'thread' ); |
761 | 764 | $this->getResult()->addValue( null, 'threadaction', $result ); |
762 | 765 | } |
763 | | - |
| 766 | + |
764 | 767 | public function actionInlineEditForm( $threads, $params ) { |
765 | 768 | $method = $talkpage = $operand = null; |
766 | | - |
| 769 | + |
767 | 770 | if ( isset($params['method']) ) { |
768 | 771 | $method = $params['method']; |
769 | 772 | } |
770 | | - |
| 773 | + |
771 | 774 | if ( isset( $params['talkpage'] ) ) { |
772 | 775 | $talkpage = $params['talkpage']; |
773 | 776 | } |
774 | | - |
| 777 | + |
775 | 778 | if ( $talkpage ) { |
776 | 779 | $talkpage = new Article( Title::newFromText( $talkpage ), 0 ); |
777 | 780 | } else { |
778 | 781 | $talkpage = null; |
779 | 782 | } |
780 | | - |
| 783 | + |
781 | 784 | if ( count($threads) ) { |
782 | 785 | $operand = $threads[0]; |
783 | 786 | $operand = $operand->id(); |
784 | 787 | } |
785 | | - |
| 788 | + |
786 | 789 | $output = LqtView::getInlineEditForm( $talkpage, $method, $operand ); |
787 | | - |
| 790 | + |
788 | 791 | $result = array( 'inlineeditform' => array( 'html' => $output ) ); |
789 | 792 | |
790 | 793 | /* FIXME |
791 | 794 | $result['resources'] = LqtView::getJSandCSS(); |
792 | 795 | $result['resources']['messages'] = LqtView::exportJSLocalisation(); |
793 | 796 | */ |
794 | | - |
| 797 | + |
795 | 798 | $this->getResult()->addValue( null, 'threadaction', $result ); |
796 | 799 | } |
797 | | - |
| 800 | + |
798 | 801 | public function getDescription() { |
799 | 802 | return 'Allows actions to be taken on threads and posts in threaded discussions.'; |
800 | 803 | } |
— | — | @@ -844,9 +847,10 @@ |
845 | 848 | 'gettoken' => 'Gets a thread token', |
846 | 849 | ); |
847 | 850 | } |
848 | | - |
| 851 | + |
849 | 852 | public function getPossibleErrors() { |
850 | 853 | return array_merge( parent::getPossibleErrors(), array( |
| 854 | + array( 'missingparam', 'action' ), |
851 | 855 | array( 'missingparam', 'talkpage' ), |
852 | 856 | array( 'missingparam', 'subject' ), |
853 | 857 | array( 'code' => 'too-many-threads', 'info' => 'You may only split one thread at a time' ), |
— | — | @@ -879,7 +883,7 @@ |
880 | 884 | public function needsToken() { |
881 | 885 | return true; |
882 | 886 | } |
883 | | - |
| 887 | + |
884 | 888 | public function getTokenSalt() { |
885 | 889 | return ''; |
886 | 890 | } |
— | — | @@ -892,7 +896,6 @@ |
893 | 897 | 'talkpage' => null, |
894 | 898 | 'threadaction' => array( |
895 | 899 | ApiBase::PARAM_TYPE => array_keys( $this->getActions() ), |
896 | | - ApiBase::PARAM_REQUIRED => true, |
897 | 900 | ), |
898 | 901 | 'token' => null, |
899 | 902 | 'subject' => null, |