Index: trunk/extensions/Contest/api/ApiContestQuery.php |
— | — | @@ -15,15 +15,36 @@ |
16 | 16 | */ |
17 | 17 | abstract class ApiContestQuery extends ApiQueryBase { |
18 | 18 | |
| 19 | + /** |
| 20 | + * Returns the class name of the ContestDBClass deriving class to be used |
| 21 | + * to query for results. |
| 22 | + * |
| 23 | + * @since 0.1 |
| 24 | + * |
| 25 | + * @return string |
| 26 | + */ |
19 | 27 | protected abstract function getClassName(); |
20 | 28 | |
| 29 | + /** |
| 30 | + * Returns an instance of the ContestDBClass deriving class. |
| 31 | + * Once PHP 5.3 becomes an accaptable requirement, we |
| 32 | + * can get rid of this silly hack and simply return the class |
| 33 | + * name (since all methods we need ought to be static in PHP >= 5.3). |
| 34 | + * |
| 35 | + * @since 0.1 |
| 36 | + * |
| 37 | + * @return ContestDBClass |
| 38 | + */ |
21 | 39 | protected function getClass() { |
22 | 40 | $className = $this->getClassName(); |
23 | 41 | return $className::s(); |
24 | 42 | } |
25 | 43 | |
26 | 44 | /** |
27 | | - * Retrieve the special words from the database. |
| 45 | + * Get the parameters, find out what the conditions for the query are, |
| 46 | + * run it, and add the results. |
| 47 | + * |
| 48 | + * @since 0.1 |
28 | 49 | */ |
29 | 50 | public function execute() { |
30 | 51 | $params = $this->getParams(); |
— | — | @@ -31,6 +52,14 @@ |
32 | 53 | $this->addResults( $params, $results ); |
33 | 54 | } |
34 | 55 | |
| 56 | + /** |
| 57 | + * Get the request paramaters, handle the * value for the props param |
| 58 | + * and remove all params set to null (ie those that are not actually provided). |
| 59 | + * |
| 60 | + * @since 0.1 |
| 61 | + * |
| 62 | + * @return array |
| 63 | + */ |
35 | 64 | protected function getParams() { |
36 | 65 | // Get the requests parameters. |
37 | 66 | $params = $this->extractRequestParams(); |
— | — | @@ -45,6 +74,17 @@ |
46 | 75 | return array_filter( $params, create_function( '$p', 'return isset( $p );' ) ); |
47 | 76 | } |
48 | 77 | |
| 78 | + /** |
| 79 | + * Get the conditions for the query. These will be provided as |
| 80 | + * regular parameters, together with limit, props, continue, |
| 81 | + * and possibly others which we need to get rid off. |
| 82 | + * |
| 83 | + * @since 0.1 |
| 84 | + * |
| 85 | + * @param array $params |
| 86 | + * |
| 87 | + * @return array |
| 88 | + */ |
49 | 89 | protected function getConditions( array $params ) { |
50 | 90 | $conditions = array(); |
51 | 91 | |
— | — | @@ -57,6 +97,16 @@ |
58 | 98 | return $conditions; |
59 | 99 | } |
60 | 100 | |
| 101 | + /** |
| 102 | + * Get the actual results. |
| 103 | + * |
| 104 | + * @since 0.1 |
| 105 | + * |
| 106 | + * @param array $params |
| 107 | + * @param array $conditions |
| 108 | + * |
| 109 | + * @return array of ContestDBClass |
| 110 | + */ |
61 | 111 | protected function getResults( array $params, array $conditions ) { |
62 | 112 | return $this->getClass()->select( |
63 | 113 | $params['props'], |
— | — | @@ -68,7 +118,15 @@ |
69 | 119 | ); |
70 | 120 | } |
71 | 121 | |
72 | | - protected function addResults( array $params, array $results ) { |
| 122 | + /** |
| 123 | + * Serialize the results and add them to the result object. |
| 124 | + * |
| 125 | + * @since 0.1 |
| 126 | + * |
| 127 | + * @param array $params |
| 128 | + * @param array $results |
| 129 | + */ |
| 130 | + protected function addResults( array $params, array /* of ContestDBClass */ $results ) { |
73 | 131 | $serializedResults = array(); |
74 | 132 | $count = 0; |
75 | 133 | |
Index: trunk/extensions/Contest/api/ApiQueryContests.php |
— | — | @@ -23,7 +23,8 @@ |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | | - * Retrieve the special words from the database. |
| 27 | + * Handle the API request. |
| 28 | + * Checks for access rights and then let's the parent method do the actual work. |
28 | 29 | */ |
29 | 30 | public function execute() { |
30 | 31 | global $wgUser; |