Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -41,51 +41,55 @@ |
42 | 42 | 'descriptionmsg' => 'survey-desc' |
43 | 43 | ); |
44 | 44 | |
45 | | -$wgExtensionMessagesFiles['Survey'] = dirname( __FILE__ ) . '/Survey.i18n.php'; |
46 | | -$wgExtensionMessagesFiles['SurveyAlias'] = dirname( __FILE__ ) . '/Survey.alias.php'; |
| 45 | +$wgExtensionMessagesFiles['Survey'] = dirname( __FILE__ ) . '/Survey.i18n.php'; |
| 46 | +$wgExtensionMessagesFiles['SurveyAlias'] = dirname( __FILE__ ) . '/Survey.alias.php'; |
47 | 47 | |
48 | | -$wgAutoloadClasses['SurveyHooks'] = dirname( __FILE__ ) . '/Survey.hooks.php'; |
49 | | -$wgAutoloadClasses['SurveySettings'] = dirname( __FILE__ ) . '/Survey.settings.php'; |
| 48 | +$wgAutoloadClasses['SurveyHooks'] = dirname( __FILE__ ) . '/Survey.hooks.php'; |
| 49 | +$wgAutoloadClasses['SurveySettings'] = dirname( __FILE__ ) . '/Survey.settings.php'; |
50 | 50 | |
51 | | -$wgAutoloadClasses['ApiAddSurvey'] = dirname( __FILE__ ) . '/api/ApiAddSurvey.php'; |
52 | | -$wgAutoloadClasses['ApiDeleteSurvey'] = dirname( __FILE__ ) . '/api/ApiDeleteSurvey.php'; |
53 | | -$wgAutoloadClasses['ApiEditSurvey'] = dirname( __FILE__ ) . '/api/ApiEditSurvey.php'; |
54 | | -$wgAutoloadClasses['ApiQuerySurveys'] = dirname( __FILE__ ) . '/api/ApiQuerySurveys.php'; |
55 | | -$wgAutoloadClasses['ApiSubmitSurvey'] = dirname( __FILE__ ) . '/api/ApiSubmitSurvey.php'; |
| 51 | +$wgAutoloadClasses['ApiAddSurvey'] = dirname( __FILE__ ) . '/api/ApiAddSurvey.php'; |
| 52 | +$wgAutoloadClasses['ApiDeleteSurvey'] = dirname( __FILE__ ) . '/api/ApiDeleteSurvey.php'; |
| 53 | +$wgAutoloadClasses['ApiEditSurvey'] = dirname( __FILE__ ) . '/api/ApiEditSurvey.php'; |
| 54 | +$wgAutoloadClasses['ApiQuerySurveyAnswers'] = dirname( __FILE__ ) . '/api/ApiQuerySurveyAnswers.php'; |
| 55 | +$wgAutoloadClasses['ApiQuerySurveys'] = dirname( __FILE__ ) . '/api/ApiQuerySurveys.php'; |
| 56 | +$wgAutoloadClasses['ApiQuerySurveySubmissions'] = dirname( __FILE__ ) . '/api/ApiQuerySurveySubmissions.php'; |
| 57 | +$wgAutoloadClasses['ApiSubmitSurvey'] = dirname( __FILE__ ) . '/api/ApiSubmitSurvey.php'; |
56 | 58 | |
57 | | -$wgAutoloadClasses['Survey'] = dirname( __FILE__ ) . '/includes/Survey.class.php'; |
58 | | -$wgAutoloadClasses['SurveyAnswer'] = dirname( __FILE__ ) . '/includes/SurveyAnswer.php'; |
59 | | -$wgAutoloadClasses['SurveyCompat'] = dirname( __FILE__ ) . '/includes/SurveyCompat.php'; |
60 | | -$wgAutoloadClasses['SurveyDBClass'] = dirname( __FILE__ ) . '/includes/SurveyDBClass.php'; |
61 | | -$wgAutoloadClasses['SurveyQuestion'] = dirname( __FILE__ ) . '/includes/SurveyQuestion.php'; |
62 | | -$wgAutoloadClasses['SurveySubmission'] = dirname( __FILE__ ) . '/includes/SurveySubmission.php'; |
63 | | -$wgAutoloadClasses['SurveyTag'] = dirname( __FILE__ ) . '/includes/SurveyTag.php'; |
| 59 | +$wgAutoloadClasses['Survey'] = dirname( __FILE__ ) . '/includes/Survey.class.php'; |
| 60 | +$wgAutoloadClasses['SurveyAnswer'] = dirname( __FILE__ ) . '/includes/SurveyAnswer.php'; |
| 61 | +$wgAutoloadClasses['SurveyCompat'] = dirname( __FILE__ ) . '/includes/SurveyCompat.php'; |
| 62 | +$wgAutoloadClasses['SurveyDBClass'] = dirname( __FILE__ ) . '/includes/SurveyDBClass.php'; |
| 63 | +$wgAutoloadClasses['SurveyQuestion'] = dirname( __FILE__ ) . '/includes/SurveyQuestion.php'; |
| 64 | +$wgAutoloadClasses['SurveySubmission'] = dirname( __FILE__ ) . '/includes/SurveySubmission.php'; |
| 65 | +$wgAutoloadClasses['SurveyTag'] = dirname( __FILE__ ) . '/includes/SurveyTag.php'; |
64 | 66 | |
65 | | -$wgAutoloadClasses['SpecialSurvey'] = dirname( __FILE__ ) . '/specials/SpecialSurvey.php'; |
66 | | -$wgAutoloadClasses['SpecialSurveyPage'] = dirname( __FILE__ ) . '/specials/SpecialSurveyPage.php'; |
67 | | -$wgAutoloadClasses['SpecialSurveys'] = dirname( __FILE__ ) . '/specials/SpecialSurveys.php'; |
68 | | -$wgAutoloadClasses['SpecialSurveyStats'] = dirname( __FILE__ ) . '/specials/SpecialSurveyStats.php'; |
69 | | -$wgAutoloadClasses['SpecialTakeSurvey'] = dirname( __FILE__ ) . '/specials/SpecialTakeSurvey.php'; |
| 67 | +$wgAutoloadClasses['SpecialSurvey'] = dirname( __FILE__ ) . '/specials/SpecialSurvey.php'; |
| 68 | +$wgAutoloadClasses['SpecialSurveyPage'] = dirname( __FILE__ ) . '/specials/SpecialSurveyPage.php'; |
| 69 | +$wgAutoloadClasses['SpecialSurveys'] = dirname( __FILE__ ) . '/specials/SpecialSurveys.php'; |
| 70 | +$wgAutoloadClasses['SpecialSurveyStats'] = dirname( __FILE__ ) . '/specials/SpecialSurveyStats.php'; |
| 71 | +$wgAutoloadClasses['SpecialTakeSurvey'] = dirname( __FILE__ ) . '/specials/SpecialTakeSurvey.php'; |
70 | 72 | |
71 | | -$wgSpecialPages['Survey'] = 'SpecialSurvey'; |
72 | | -$wgSpecialPages['Surveys'] = 'SpecialSurveys'; |
73 | | -$wgSpecialPages['SurveyStats'] = 'SpecialSurveyStats'; |
74 | | -$wgSpecialPages['TakeSurvey'] = 'SpecialTakeSurvey'; |
| 73 | +$wgSpecialPages['Survey'] = 'SpecialSurvey'; |
| 74 | +$wgSpecialPages['Surveys'] = 'SpecialSurveys'; |
| 75 | +$wgSpecialPages['SurveyStats'] = 'SpecialSurveyStats'; |
| 76 | +$wgSpecialPages['TakeSurvey'] = 'SpecialTakeSurvey'; |
75 | 77 | |
76 | | -$wgSpecialPageGroups['Survey'] = 'other'; |
77 | | -$wgSpecialPageGroups['Surveys'] = 'other'; |
78 | | -$wgSpecialPageGroups['SurveyStats'] = 'other'; |
79 | | -$wgSpecialPageGroups['TakeSurvey'] = 'other'; |
| 78 | +$wgSpecialPageGroups['Survey'] = 'other'; |
| 79 | +$wgSpecialPageGroups['Surveys'] = 'other'; |
| 80 | +$wgSpecialPageGroups['SurveyStats'] = 'other'; |
| 81 | +$wgSpecialPageGroups['TakeSurvey'] = 'other'; |
80 | 82 | |
81 | | -$wgAPIModules['addsurvey'] = 'ApiAddSurvey'; |
82 | | -$wgAPIModules['deletesurvey'] = 'ApiDeleteSurvey'; |
83 | | -$wgAPIModules['editsurvey'] = 'ApiEditSurvey'; |
84 | | -$wgAPIModules['submitsurvey'] = 'ApiSubmitSurvey'; |
85 | | -$wgAPIListModules['surveys'] = 'ApiQuerySurveys'; |
| 83 | +$wgAPIModules['addsurvey'] = 'ApiAddSurvey'; |
| 84 | +$wgAPIModules['deletesurvey'] = 'ApiDeleteSurvey'; |
| 85 | +$wgAPIModules['editsurvey'] = 'ApiEditSurvey'; |
| 86 | +$wgAPIModules['submitsurvey'] = 'ApiSubmitSurvey'; |
| 87 | +$wgAPIListModules['surveys'] = 'ApiQuerySurveys'; |
| 88 | +$wgAPIListModules['surveyanswers'] = 'ApiQuerySurveyAnswers'; |
| 89 | +$wgAPIListModules['surveysubmissions'] = 'ApiQuerySurveySubmissions'; |
86 | 90 | |
87 | | -$wgHooks['LoadExtensionSchemaUpdates'][] = 'SurveyHooks::onSchemaUpdate'; |
88 | | -$wgHooks['UnitTestsList'][] = 'SurveyHooks::registerUnitTests'; |
89 | | -$wgHooks['ParserFirstCallInit'][] = 'SurveyHooks::onParserFirstCallInit'; |
| 91 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'SurveyHooks::onSchemaUpdate'; |
| 92 | +$wgHooks['UnitTestsList'][] = 'SurveyHooks::registerUnitTests'; |
| 93 | +$wgHooks['ParserFirstCallInit'][] = 'SurveyHooks::onParserFirstCallInit'; |
90 | 94 | |
91 | 95 | $wgAvailableRights[] = 'surveyadmin'; |
92 | 96 | $wgAvailableRights[] = 'surveysubmit'; |
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php |
— | — | @@ -217,6 +217,15 @@ |
218 | 218 | $out->addHTML( '</tr>' ); |
219 | 219 | } |
220 | 220 | |
| 221 | + /** |
| 222 | + * Get a list of most provided answers for the question. |
| 223 | + * |
| 224 | + * @since 0.1 |
| 225 | + * |
| 226 | + * @param SurveyQuestion $question |
| 227 | + * |
| 228 | + * @return string |
| 229 | + */ |
221 | 230 | protected function getAnswerList( SurveyQuestion $question ) { |
222 | 231 | if ( $question->isRestrictiveType() ) { |
223 | 232 | $list = '<ul>'; |
Index: trunk/extensions/Survey/includes/SurveyDBClass.php |
— | — | @@ -66,6 +66,19 @@ |
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
| 70 | + * Returns an array with the fields and their descriptions. |
| 71 | + * |
| 72 | + * field name => field description |
| 73 | + * |
| 74 | + * @since 0.1 |
| 75 | + * |
| 76 | + * @return array |
| 77 | + */ |
| 78 | + public static function getFieldDescriptions() { |
| 79 | + return array(); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
70 | 83 | * Returns the name of the database table objects of this type are stored in. |
71 | 84 | * |
72 | 85 | * @since 0.1 |
— | — | @@ -561,6 +574,19 @@ |
562 | 575 | } |
563 | 576 | |
564 | 577 | /** |
| 578 | + * Takes in a field and returns an it's prefixed version, ready for db usage. |
| 579 | + * |
| 580 | + * @since 0.1 |
| 581 | + * |
| 582 | + * @param string $field |
| 583 | + * |
| 584 | + * @return string |
| 585 | + */ |
| 586 | + public static function getPrefixedField( $field ) { |
| 587 | + return static::getFieldPrefix() . $field; |
| 588 | + } |
| 589 | + |
| 590 | + /** |
565 | 591 | * Takes in an associative array with field names as keys and |
566 | 592 | * their values as value. The field names are prefixed with the |
567 | 593 | * db field prefix. |
— | — | @@ -628,11 +654,22 @@ |
629 | 655 | return array(); |
630 | 656 | } |
631 | 657 | |
632 | | - public static function getAPIParams() { |
| 658 | + /** |
| 659 | + * Get API parameters for the fields supported by this object. |
| 660 | + * |
| 661 | + * @since 0.1 |
| 662 | + * |
| 663 | + * @param boolean $requireParams |
| 664 | + * |
| 665 | + * @return array |
| 666 | + */ |
| 667 | + public static function getAPIParams( $requireParams = true ) { |
633 | 668 | $typeMap = array( |
| 669 | + 'id' => 'integer', |
634 | 670 | 'int' => 'integer', |
635 | 671 | 'str' => 'string', |
636 | | - 'bool' => 'integer' |
| 672 | + 'bool' => 'integer', |
| 673 | + 'array' => 'string' |
637 | 674 | ); |
638 | 675 | |
639 | 676 | $params = array(); |
— | — | @@ -647,11 +684,16 @@ |
648 | 685 | |
649 | 686 | $params[$field] = array( |
650 | 687 | ApiBase::PARAM_TYPE => $typeMap[$type], |
651 | | - ApiBase::PARAM_REQUIRED => !$hasDefault |
| 688 | + ApiBase::PARAM_REQUIRED => $requireParams && !$hasDefault |
652 | 689 | ); |
653 | 690 | |
| 691 | + if ( $type == 'array' ) { |
| 692 | + $params[$field][ApiBase::PARAM_ISMULTI] = true; |
| 693 | + } |
| 694 | + |
654 | 695 | if ( $hasDefault ) { |
655 | | - $params[$field][ApiBase::PARAM_DFLT] = $defaults[$field]; |
| 696 | + $default = is_array( $defaults[$field] ) ? implode( '|', $defaults[$field] ) : $defaults[$field]; |
| 697 | + $params[$field][ApiBase::PARAM_DFLT] = $default; |
656 | 698 | } |
657 | 699 | } |
658 | 700 | |
— | — | @@ -659,22 +701,24 @@ |
660 | 702 | } |
661 | 703 | |
662 | 704 | /** |
663 | | - * Create a new instance from API parameters. |
| 705 | + * Takes an array of field name => field value and |
| 706 | + * filters it on valid field names. |
664 | 707 | * |
665 | 708 | * @since 0.1 |
666 | 709 | * |
667 | | - * @param array $params |
| 710 | + * @param array $conditions |
| 711 | + * @param false|integer $id |
668 | 712 | * |
669 | | - * @return SurveyDBClass |
| 713 | + * @return array |
670 | 714 | */ |
671 | | - public static function newFromAPIParams( array $params, $id = false ) { |
672 | | - $validParams = array(); |
| 715 | + public static function getValidFields( array $conditions, $id = false ) { |
| 716 | + $validFields = array(); |
673 | 717 | |
674 | 718 | $fields = static::getFieldTypes(); |
675 | 719 | |
676 | | - foreach ( $params as $name => $value ) { |
| 720 | + foreach ( $conditions as $name => $value ) { |
677 | 721 | if ( array_key_exists( $name, $fields ) ) { |
678 | | - $validParams[$name] = $value; |
| 722 | + $validFields[$name] = $value; |
679 | 723 | } |
680 | 724 | } |
681 | 725 | |
— | — | @@ -682,7 +726,7 @@ |
683 | 727 | $validParams[static::getIDField()] = $id; |
684 | 728 | } |
685 | 729 | |
686 | | - return new static( $validParams ); |
| 730 | + return $validFields; |
687 | 731 | } |
688 | 732 | |
689 | 733 | } |
Index: trunk/extensions/Survey/api/ApiQuerySurveySubmissions.php |
— | — | @@ -0,0 +1,154 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to get a list of survey submissions. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiQuerySurveySubmissions.php |
| 10 | + * @ingroup Surveys |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiQuerySurveySubmissions extends ApiQueryBase { |
| 17 | + |
| 18 | + public function __construct( $main, $action ) { |
| 19 | + parent::__construct( $main, $action, 'qs' ); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Retrieve the special words from the database. |
| 24 | + */ |
| 25 | + public function execute() { |
| 26 | + global $wgUser; |
| 27 | + |
| 28 | + if ( $wgUser->isBlocked() ) { |
| 29 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 30 | + } |
| 31 | + |
| 32 | + // Get the requests parameters. |
| 33 | + $params = $this->extractRequestParams(); |
| 34 | + |
| 35 | + $starPropPosition = array_search( '*', $params['props'] ); |
| 36 | + |
| 37 | + if ( $starPropPosition !== false ) { |
| 38 | + unset( $params['props'][$starPropPosition] ); |
| 39 | + $params['props'] = array_merge( $params['props'], SurveySubmission::getFieldNames() ); |
| 40 | + } |
| 41 | + |
| 42 | + $params = array_filter( $params, function( $param ) { return !is_null( $param ); } ); |
| 43 | + |
| 44 | + $results = SurveySubmission::select( |
| 45 | + $params['props'], |
| 46 | + SurveySubmission::getValidFields( $params ), |
| 47 | + array( |
| 48 | + 'LIMIT' => $params['limit'] + 1, |
| 49 | + 'ORDER BY' => SurveySubmission::getPrefixedField( 'id' ) . ' ASC' |
| 50 | + ) |
| 51 | + ); |
| 52 | + |
| 53 | + $serializedResults = array(); |
| 54 | + $count = 0; |
| 55 | + |
| 56 | + foreach ( $results as $result ) { |
| 57 | + if ( ++$count > $params['limit'] ) { |
| 58 | + // We've reached the one extra which shows that |
| 59 | + // there are additional pages to be had. Stop here... |
| 60 | + $this->setContinueEnumParameter( 'continue', $result->getId() ); |
| 61 | + break; |
| 62 | + } |
| 63 | + |
| 64 | + $serializedResults[] = $result->toArray(); |
| 65 | + } |
| 66 | + |
| 67 | + $this->getResult()->setIndexedTagName( $serializedResults, 'submission' ); |
| 68 | + |
| 69 | + $this->getResult()->addValue( |
| 70 | + null, |
| 71 | + 'submissions', |
| 72 | + $serializedResults |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + public function needsToken() { |
| 77 | + return true; |
| 78 | + } |
| 79 | + |
| 80 | + public function getTokenSalt() { |
| 81 | + return 'querysurveysubmissions'; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * (non-PHPdoc) |
| 86 | + * @see includes/api/ApiBase#getAllowedParams() |
| 87 | + */ |
| 88 | + public function getAllowedParams() { |
| 89 | + $params = array ( |
| 90 | + 'props' => array( |
| 91 | + ApiBase::PARAM_TYPE => array_merge( SurveySubmission::getFieldNames(), array( '*' ) ), |
| 92 | + ApiBase::PARAM_ISMULTI => true, |
| 93 | + ApiBase::PARAM_DFLT => '*' |
| 94 | + ), |
| 95 | + 'limit' => array( |
| 96 | + ApiBase::PARAM_DFLT => 20, |
| 97 | + ApiBase::PARAM_TYPE => 'limit', |
| 98 | + ApiBase::PARAM_MIN => 1, |
| 99 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 100 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 101 | + ), |
| 102 | + 'continue' => null, |
| 103 | + 'token' => null, |
| 104 | + ); |
| 105 | + |
| 106 | + return array_merge( SurveySubmission::getAPIParams( false ), $params ); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * (non-PHPdoc) |
| 111 | + * @see includes/api/ApiBase#getParamDescription() |
| 112 | + */ |
| 113 | + public function getParamDescription() { |
| 114 | + $descs = array ( |
| 115 | + 'props' => 'Survey data to query', |
| 116 | + 'continue' => 'Offset number from where to continue the query', |
| 117 | + 'limit' => 'Max amount of words to return', |
| 118 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 119 | + ); |
| 120 | + |
| 121 | + return array_merge( SurveySubmission::getFieldDescriptions(), $descs ); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * (non-PHPdoc) |
| 126 | + * @see includes/api/ApiBase#getDescription() |
| 127 | + */ |
| 128 | + public function getDescription() { |
| 129 | + return 'API module for obatining survey submissions'; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * (non-PHPdoc) |
| 134 | + * @see includes/api/ApiBase#getPossibleErrors() |
| 135 | + */ |
| 136 | + public function getPossibleErrors() { |
| 137 | + return array_merge( parent::getPossibleErrors(), array( |
| 138 | + ) ); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * (non-PHPdoc) |
| 143 | + * @see includes/api/ApiBase#getExamples() |
| 144 | + */ |
| 145 | + protected function getExamples() { |
| 146 | + return array ( |
| 147 | + 'api.php?action=query&list=surveysubmissions&', |
| 148 | + ); |
| 149 | + } |
| 150 | + |
| 151 | + public function getVersion() { |
| 152 | + return __CLASS__ . ': $Id$'; |
| 153 | + } |
| 154 | + |
| 155 | +} |
Property changes on: trunk/extensions/Survey/api/ApiQuerySurveySubmissions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 156 | + native |
Added: svn:keywords |
2 | 157 | + Id |
Index: trunk/extensions/Survey/api/ApiEditSurvey.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | $question = SurveyQuestion::newFromUrlData( $question ); |
33 | 33 | } |
34 | 34 | |
35 | | - $survey = Survey::newFromAPIParams( $params, $params['id'] ); |
| 35 | + $survey = new Survey( Survey::getValidFields( $params, $params['id'] ) ); |
36 | 36 | |
37 | 37 | $this->getResult()->addValue( |
38 | 38 | null, |
Index: trunk/extensions/Survey/api/ApiAddSurvey.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | } |
34 | 34 | |
35 | 35 | try { |
36 | | - $survey = Survey::newFromAPIParams( $params ); |
| 36 | + $survey = new Survey( Survey::getValidFields( $params ) ); |
37 | 37 | $success = $survey->writeToDB(); |
38 | 38 | } |
39 | 39 | catch ( DBQueryError $ex ) { |
Index: trunk/extensions/Survey/api/ApiQuerySurveyAnswers.php |
— | — | @@ -0,0 +1,154 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to get a list of survey answers. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiQuerySurveyAnswers.php |
| 10 | + * @ingroup Surveys |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiQuerySurveyAnswers extends ApiQueryBase { |
| 17 | + |
| 18 | + public function __construct( $main, $action ) { |
| 19 | + parent::__construct( $main, $action, 'qa' ); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Retrieve the special words from the database. |
| 24 | + */ |
| 25 | + public function execute() { |
| 26 | + global $wgUser; |
| 27 | + |
| 28 | + if ( $wgUser->isBlocked() ) { |
| 29 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 30 | + } |
| 31 | + |
| 32 | + // Get the requests parameters. |
| 33 | + $params = $this->extractRequestParams(); |
| 34 | + |
| 35 | + $starPropPosition = array_search( '*', $params['props'] ); |
| 36 | + |
| 37 | + if ( $starPropPosition !== false ) { |
| 38 | + unset( $params['props'][$starPropPosition] ); |
| 39 | + $params['props'] = array_merge( $params['props'], SurveyAnswer::getFieldNames() ); |
| 40 | + } |
| 41 | + |
| 42 | + $params = array_filter( $params, function( $param ) { return !is_null( $param ); } ); |
| 43 | + |
| 44 | + $answers = SurveyAnswer::select( |
| 45 | + $params['props'], |
| 46 | + SurveyAnswer::getValidFields( $params ), |
| 47 | + array( |
| 48 | + 'LIMIT' => $params['limit'] + 1, |
| 49 | + 'ORDER BY' => SurveyAnswer::getPrefixedField( 'id' ) . ' ASC' |
| 50 | + ) |
| 51 | + ); |
| 52 | + |
| 53 | + $serializedAnswers = array(); |
| 54 | + $count = 0; |
| 55 | + |
| 56 | + foreach ( $answers as $answer ) { |
| 57 | + if ( ++$count > $params['limit'] ) { |
| 58 | + // We've reached the one extra which shows that |
| 59 | + // there are additional pages to be had. Stop here... |
| 60 | + $this->setContinueEnumParameter( 'continue', $answer->getId() ); |
| 61 | + break; |
| 62 | + } |
| 63 | + |
| 64 | + $serializedAnswers[] = $answer->toArray(); |
| 65 | + } |
| 66 | + |
| 67 | + $this->getResult()->setIndexedTagName( $serializedAnswers, 'answer' ); |
| 68 | + |
| 69 | + $this->getResult()->addValue( |
| 70 | + null, |
| 71 | + 'answers', |
| 72 | + $serializedAnswers |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + public function needsToken() { |
| 77 | + return true; |
| 78 | + } |
| 79 | + |
| 80 | + public function getTokenSalt() { |
| 81 | + return 'querysurveyanswers'; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * (non-PHPdoc) |
| 86 | + * @see includes/api/ApiBase#getAllowedParams() |
| 87 | + */ |
| 88 | + public function getAllowedParams() { |
| 89 | + $params = array ( |
| 90 | + 'props' => array( |
| 91 | + ApiBase::PARAM_TYPE => array_merge( SurveyAnswer::getFieldNames(), array( '*' ) ), |
| 92 | + ApiBase::PARAM_ISMULTI => true, |
| 93 | + ApiBase::PARAM_DFLT => '*' |
| 94 | + ), |
| 95 | + 'limit' => array( |
| 96 | + ApiBase::PARAM_DFLT => 20, |
| 97 | + ApiBase::PARAM_TYPE => 'limit', |
| 98 | + ApiBase::PARAM_MIN => 1, |
| 99 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 100 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 101 | + ), |
| 102 | + 'continue' => null, |
| 103 | + 'token' => null, |
| 104 | + ); |
| 105 | + |
| 106 | + return array_merge( SurveyAnswer::getAPIParams( false ), $params ); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * (non-PHPdoc) |
| 111 | + * @see includes/api/ApiBase#getParamDescription() |
| 112 | + */ |
| 113 | + public function getParamDescription() { |
| 114 | + $descs = array ( |
| 115 | + 'props' => 'Survey data to query', |
| 116 | + 'continue' => 'Offset number from where to continue the query', |
| 117 | + 'limit' => 'Max amount of words to return', |
| 118 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 119 | + ); |
| 120 | + |
| 121 | + return array_merge( SurveyAnswer::getFieldDescriptions(), $descs ); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * (non-PHPdoc) |
| 126 | + * @see includes/api/ApiBase#getDescription() |
| 127 | + */ |
| 128 | + public function getDescription() { |
| 129 | + return 'API module for obatining survey answers'; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * (non-PHPdoc) |
| 134 | + * @see includes/api/ApiBase#getPossibleErrors() |
| 135 | + */ |
| 136 | + public function getPossibleErrors() { |
| 137 | + return array_merge( parent::getPossibleErrors(), array( |
| 138 | + ) ); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * (non-PHPdoc) |
| 143 | + * @see includes/api/ApiBase#getExamples() |
| 144 | + */ |
| 145 | + protected function getExamples() { |
| 146 | + return array ( |
| 147 | + 'api.php?action=query&list=surveyanswers&', |
| 148 | + ); |
| 149 | + } |
| 150 | + |
| 151 | + public function getVersion() { |
| 152 | + return __CLASS__ . ': $Id$'; |
| 153 | + } |
| 154 | + |
| 155 | +} |
Property changes on: trunk/extensions/Survey/api/ApiQuerySurveyAnswers.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 156 | + native |
Added: svn:keywords |
2 | 157 | + Id |
Index: trunk/extensions/Survey/api/ApiQuerySurveys.php |
— | — | @@ -116,6 +116,14 @@ |
117 | 117 | return $survey; |
118 | 118 | } |
119 | 119 | |
| 120 | + public function needsToken() { |
| 121 | + return true; |
| 122 | + } |
| 123 | + |
| 124 | + public function getTokenSalt() { |
| 125 | + return 'querysurveys'; |
| 126 | + } |
| 127 | + |
120 | 128 | /** |
121 | 129 | * (non-PHPdoc) |
122 | 130 | * @see includes/api/ApiBase#getAllowedParams() |