r84376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84375‎ | r84376 | r84377 >
Date:12:50, 20 March 2011
Author:reedy
Status:ok
Tags:
Comment:
Fix r84359 with partial revert

Didn't add empty() back in, used !count

LQT seems to have crappy error handling, no?

Also trim trailing whitespace
Modified paths:
  • /trunk/extensions/LiquidThreads/api/ApiThreadAction.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/api/ApiThreadAction.php
@@ -12,6 +12,9 @@
1313 return;
1414 }
1515
 16+ if ( !count( $params['threadaction'] ) ) {
 17+ $this->dieUsageMsg( array( 'missingparam', 'action' ) );
 18+ }
1619
1720 $allowedAllActions = array( 'markread' );
1821 $action = $params['threadaction'];
@@ -280,7 +283,7 @@
281284 'minor' => 0,
282285 'format' => 'json',
283286 );
284 -
 287+
285288 if ( $wgUser->isAllowed('bot') ) {
286289 $requestData['bot'] = true;
287290 }
@@ -328,7 +331,7 @@
329332
330333 $this->getResult()->addValue( null, $this->getModuleName(), $result );
331334 }
332 -
 335+
333336 public function actionEdit( $threads, $params ) {
334337 if ( count( $threads ) > 1 ) {
335338 $this->dieUsage( 'You may only edit one thread at a time',
@@ -337,10 +340,10 @@
338341 $this->dieUsage( 'You must specify a thread to edit',
339342 'no-specified-threads' );
340343 }
341 -
 344+
342345 $thread = array_pop( $threads );
343346 $talkpage = $thread->article();
344 -
 347+
345348 $bump = isset( $params['bump'] ) ? $params['bump'] : null;
346349
347350 // Validate subject
@@ -358,21 +361,21 @@
359362 $this->dieUsage( 'The subject you specified is not valid',
360363 'invalid-subject' );
361364 }
362 -
 365+
363366 // Check for text
364367 if ( empty( $params['text'] ) ) {
365368 $this->dieUsage( 'You must include text in your post', 'no-text' );
366369 }
367370 $text = $params['text'];
368 -
 371+
369372 $summary = '';
370373 if ( !empty( $params['reason'] ) ) {
371374 $summary = $params['reason'];
372375 }
373 -
 376+
374377 $article = $thread->root();
375378 $title = $article->getTitle();
376 -
 379+
377380 $signature = null;
378381 if ( isset( $params['signature'] ) ) {
379382 $signature = $params['signature'];
@@ -386,7 +389,7 @@
387390 LqtHooks::$editAppliesTo = null;
388391
389392 $token = $params['token'];
390 -
 393+
391394 // All seems in order. Construct an API edit request
392395 $requestData = array(
393396 'action' => 'edit',
@@ -398,7 +401,7 @@
399402 'basetimestamp' => wfTimestampNow(),
400403 'format' => 'json',
401404 );
402 -
 405+
403406 global $wgUser;
404407
405408 if ( $wgUser->isAllowed('bot') ) {
@@ -417,7 +420,7 @@
418421 $this->getResult()->addValue( null, $this->getModuleName(), $result );
419422 return;
420423 }
421 -
 424+
422425 $thread = LqtView::editMetadataUpdates(
423426 array(
424427 'root' => $article,
@@ -444,7 +447,7 @@
445448
446449 $this->getResult()->addValue( null, $this->getModuleName(), $result );
447450 }
448 -
 451+
449452 public function actionReply( $threads, $params ) {
450453 global $wgUser;
451454
@@ -517,7 +520,7 @@
518521 'minor' => 0,
519522 'format' => 'json',
520523 );
521 -
 524+
522525 if ( $wgUser->isAllowed('bot') ) {
523526 $requestData['bot'] = true;
524527 }
@@ -689,111 +692,111 @@
690693
691694 $this->getResult()->addValue( null, $this->getModuleName(), $result );
692695 }
693 -
 696+
694697 public function actionAddReaction( $threads, $params ) {
695698 global $wgUser;
696 -
 699+
697700 if ( !count( $threads ) ) {
698701 $this->dieUsage( 'You must specify a thread to add a reaction for',
699702 'no-specified-threads' );
700703 }
701 -
 704+
702705 if ( ! $wgUser->isAllowed( 'lqt-react' ) ) {
703706 $this->dieUsage( 'You are not allowed to react to threads.', 'permission-denied' );
704707 }
705708
706709 $required = array( 'type', 'value' );
707 -
 710+
708711 if ( count( array_diff( $required, array_keys($params) ) ) ) {
709712 $this->dieUsage( 'You must specify both a type and a value for the reaction',
710713 'missing-parameter' );
711714 }
712 -
 715+
713716 $result = array();
714 -
 717+
715718 foreach( $threads as $thread ) {
716719 $thread->addReaction( $wgUser, $params['type'], $params['value'] );
717 -
 720+
718721 $result[] = array(
719722 'result' => 'Success',
720723 'action' => 'addreaction',
721724 'id' => $thread->id(),
722725 );
723726 }
724 -
 727+
725728 $this->getResult()->setIndexedTagName( $result, 'thread' );
726729 $this->getResult()->addValue( null, 'threadaction', $result );
727730 }
728 -
 731+
729732 public function actionDeleteReaction( $threads, $params ) {
730733 global $wgUser;
731 -
 734+
732735 if ( !count( $threads ) ) {
733736 $this->dieUsage( 'You must specify a thread to delete a reaction for',
734737 'no-specified-threads' );
735738 }
736 -
 739+
737740 if ( ! $wgUser->isAllowed( 'lqt-react' ) ) {
738741 $this->dieUsage( 'You are not allowed to react to threads.', 'permission-denied' );
739742 }
740743
741744 $required = array( 'type', 'value' );
742 -
 745+
743746 if ( count( array_diff( $required, array_keys($params) ) ) ) {
744747 $this->dieUsage( 'You must specify both a type for the reaction',
745748 'missing-parameter' );
746749 }
747 -
 750+
748751 $result = array();
749 -
 752+
750753 foreach( $threads as $thread ) {
751754 $thread->deleteReaction( $wgUser, $params['type'] );
752 -
 755+
753756 $result[] = array(
754757 'result' => 'Success',
755758 'action' => 'deletereaction',
756759 'id' => $thread->id(),
757760 );
758761 }
759 -
 762+
760763 $this->getResult()->setIndexedTagName( $result, 'thread' );
761764 $this->getResult()->addValue( null, 'threadaction', $result );
762765 }
763 -
 766+
764767 public function actionInlineEditForm( $threads, $params ) {
765768 $method = $talkpage = $operand = null;
766 -
 769+
767770 if ( isset($params['method']) ) {
768771 $method = $params['method'];
769772 }
770 -
 773+
771774 if ( isset( $params['talkpage'] ) ) {
772775 $talkpage = $params['talkpage'];
773776 }
774 -
 777+
775778 if ( $talkpage ) {
776779 $talkpage = new Article( Title::newFromText( $talkpage ), 0 );
777780 } else {
778781 $talkpage = null;
779782 }
780 -
 783+
781784 if ( count($threads) ) {
782785 $operand = $threads[0];
783786 $operand = $operand->id();
784787 }
785 -
 788+
786789 $output = LqtView::getInlineEditForm( $talkpage, $method, $operand );
787 -
 790+
788791 $result = array( 'inlineeditform' => array( 'html' => $output ) );
789792
790793 /* FIXME
791794 $result['resources'] = LqtView::getJSandCSS();
792795 $result['resources']['messages'] = LqtView::exportJSLocalisation();
793796 */
794 -
 797+
795798 $this->getResult()->addValue( null, 'threadaction', $result );
796799 }
797 -
 800+
798801 public function getDescription() {
799802 return 'Allows actions to be taken on threads and posts in threaded discussions.';
800803 }
@@ -844,9 +847,10 @@
845848 'gettoken' => 'Gets a thread token',
846849 );
847850 }
848 -
 851+
849852 public function getPossibleErrors() {
850853 return array_merge( parent::getPossibleErrors(), array(
 854+ array( 'missingparam', 'action' ),
851855 array( 'missingparam', 'talkpage' ),
852856 array( 'missingparam', 'subject' ),
853857 array( 'code' => 'too-many-threads', 'info' => 'You may only split one thread at a time' ),
@@ -879,7 +883,7 @@
880884 public function needsToken() {
881885 return true;
882886 }
883 -
 887+
884888 public function getTokenSalt() {
885889 return '';
886890 }
@@ -892,7 +896,6 @@
893897 'talkpage' => null,
894898 'threadaction' => array(
895899 ApiBase::PARAM_TYPE => array_keys( $this->getActions() ),
896 - ApiBase::PARAM_REQUIRED => true,
897900 ),
898901 'token' => null,
899902 'subject' => null,

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84359set threadaction to be PARAM_REQUIRED, don't do it explicitally, using empty ...reedy23:53, 19 March 2011

Status & tagging log