r99048 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99047‎ | r99048 | r99049 >
Date:20:30, 5 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r99045 - docs++
Modified paths:
  • /trunk/extensions/Contest/api/ApiContestQuery.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryContests.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/api/ApiContestQuery.php
@@ -15,15 +15,36 @@
1616 */
1717 abstract class ApiContestQuery extends ApiQueryBase {
1818
 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+ */
1927 protected abstract function getClassName();
2028
 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+ */
2139 protected function getClass() {
2240 $className = $this->getClassName();
2341 return $className::s();
2442 }
2543
2644 /**
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
2849 */
2950 public function execute() {
3051 $params = $this->getParams();
@@ -31,6 +52,14 @@
3253 $this->addResults( $params, $results );
3354 }
3455
 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+ */
3564 protected function getParams() {
3665 // Get the requests parameters.
3766 $params = $this->extractRequestParams();
@@ -45,6 +74,17 @@
4675 return array_filter( $params, create_function( '$p', 'return isset( $p );' ) );
4776 }
4877
 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+ */
4989 protected function getConditions( array $params ) {
5090 $conditions = array();
5191
@@ -57,6 +97,16 @@
5898 return $conditions;
5999 }
60100
 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+ */
61111 protected function getResults( array $params, array $conditions ) {
62112 return $this->getClass()->select(
63113 $params['props'],
@@ -68,7 +118,15 @@
69119 );
70120 }
71121
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 ) {
73131 $serializedResults = array();
74132 $count = 0;
75133
Index: trunk/extensions/Contest/api/ApiQueryContests.php
@@ -23,7 +23,8 @@
2424 }
2525
2626 /**
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.
2829 */
2930 public function execute() {
3031 global $wgUser;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99045refactored all magic ContestDBClass API behvaiour into a base class, so we ne...jeroendedauw20:20, 5 October 2011

Status & tagging log