r99376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99375‎ | r99376 | r99377 >
Date:20:42, 9 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some fixes to the api stuff
Modified paths:
  • /trunk/extensions/Contest/api/ApiContestQuery.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -187,10 +187,11 @@
188188 * @since 0.1
189189 *
190190 * @param null|array $props
 191+ * @param boolean $incNullId
191192 *
192193 * @return array
193194 */
194 - public function toArray( $fields = null ) {
 195+ public function toArray( $fields = null, $incNullId = false ) {
195196 $data = array();
196197 $setFields = array();
197198
@@ -205,7 +206,9 @@
206207 }
207208
208209 foreach ( $setFields as $field ) {
209 - $data[$field] = $this->getField( $field );
 210+ if ( $incNullId || $field != 'id' || $this->hasIdField() ) {
 211+ $data[$field] = $this->getField( $field );
 212+ }
210213 }
211214
212215 return $data;
Index: trunk/extensions/Contest/api/ApiContestQuery.php
@@ -2,7 +2,7 @@
33
44 /**
55 * Base class for API query modules that return results using a
6 - * ContestDBClass deriving class.
 6+ * ContestDBObject deriving class.
77 *
88 * @since 0.1
99 *
@@ -17,7 +17,7 @@
1818
1919 /**
2020 * Returns the class specific info.
21 - * * class: name of the ContestDBClass deriving class (ie Contest)
 21+ * * class: name of the ContestDBObject deriving class (ie Contest)
2222 * * item: item name (ie contest)
2323 * * set: item set name (ie contests)
2424 *
@@ -28,7 +28,7 @@
2929 protected abstract function getClassInfo();
3030
3131 /**
32 - * Returns an instance of the ContestDBClass deriving class.
 32+ * Returns an instance of the ContestDBObject deriving class.
3333 * Once PHP 5.3 becomes an accaptable requirement, we
3434 * can get rid of this silly hack and simply return the class
3535 * name (since all methods we need ought to be static in PHP >= 5.3).
@@ -129,7 +129,7 @@
130130 * @param array $params
131131 * @param array $results
132132 */
133 - protected function addResults( array $params, array /* of ContestDBClass */ $results ) {
 133+ protected function addResults( array $params, array /* of ContestDBObject */ $results ) {
134134 $serializedResults = array();
135135 $count = 0;
136136
@@ -141,20 +141,35 @@
142142 break;
143143 }
144144
145 - $serializedResults[] = $result->toArray();
 145+ $serializedResults[] = $result->toArray( $params['props'] );
146146 }
147 -
148 - $this->addIndexedTagNames( $serializedResults );
149 - $this->addSerializedResults( $serializedResults );
 147+
 148+ $this->setIndexedTagNames( $serializedResults );
 149+ $this->addSerializedResults( $serializedResults );
150150 }
151151
152 - protected function addIndexedTagNames( array $serializedResults ) {
 152+ /**
 153+ * Set the tag names for formats such as XML.
 154+ *
 155+ * @since 0.1
 156+ *
 157+ * @param array $serializedResults
 158+ */
 159+ protected function setIndexedTagNames( array &$serializedResults ) {
153160 $classInfo = $this->getClassInfo();
154161 $this->getResult()->setIndexedTagName( $serializedResults, $classInfo['item'] );
155162 }
156163
 164+ /**
 165+ * Add the serialized results to the result object.
 166+ *
 167+ * @since 0.1
 168+ *
 169+ * @param array $serializedResults
 170+ */
157171 protected function addSerializedResults( array $serializedResults ) {
158172 $classInfo = $this->getClassInfo();
 173+
159174 $this->getResult()->addValue(
160175 null,
161176 $classInfo['set'],

Status & tagging log