r99293 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99292‎ | r99293 | r99294 >
Date:01:05, 8 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some work on the api
Modified paths:
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiContestQuery.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryChallenges.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryContestComments.php (added) (history)
  • /trunk/extensions/Contest/api/ApiQueryContestants.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryContests.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestant.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialContestant.php
@@ -53,8 +53,8 @@
5454 $this->displayNavigation();
5555
5656 $this->showGeneralInfo( $contestant );
57 - $this->showRating();
58 - $this->showComments();
 57+ $this->showRating( $contestant );
 58+ $this->showComments( $contestant );
5959 }
6060 }
6161
Index: trunk/extensions/Contest/Contest.php
@@ -53,6 +53,7 @@
5454 $wgAutoloadClasses['ApiDeleteContest'] = dirname( __FILE__ ) . '/api/ApiDeleteContest.php';
5555 $wgAutoloadClasses['ApiQueryChallenges'] = dirname( __FILE__ ) . '/api/ApiQueryChallenges.php';
5656 $wgAutoloadClasses['ApiQueryContestants'] = dirname( __FILE__ ) . '/api/ApiQueryContestants.php';
 57+$wgAutoloadClasses['ApiQueryContestComments'] = dirname( __FILE__ ) . '/api/ApiQueryContestComments.php';
5758 $wgAutoloadClasses['ApiQueryContests'] = dirname( __FILE__ ) . '/api/ApiQueryContests.php';
5859
5960 $wgAutoloadClasses['Contest'] = dirname( __FILE__ ) . '/includes/Contest.class.php';
@@ -93,6 +94,7 @@
9495 $wgAPIModules['deletecontest'] = 'ApiDeleteContest';
9596 $wgAPIListModules['challenges'] = 'ApiQueryChallenges';
9697 $wgAPIListModules['contestants'] = 'ApiQueryContestants';
 98+$wgAPIListModules['contestcomments'] = 'ApiQueryContestComments';
9799 $wgAPIListModules['contests'] = 'ApiQueryContests';
98100
99101 // Hooks
Index: trunk/extensions/Contest/api/ApiContestQuery.php
@@ -16,14 +16,16 @@
1717 abstract class ApiContestQuery extends ApiQueryBase {
1818
1919 /**
20 - * Returns the class name of the ContestDBClass deriving class to be used
21 - * to query for results.
 20+ * Returns the class specific info.
 21+ * * class: name of the ContestDBClass deriving class (ie Contest)
 22+ * * item: item name (ie contest)
 23+ * * set: item set name (ie contests)
2224 *
2325 * @since 0.1
2426 *
25 - * @return string
 27+ * @return array of string
2628 */
27 - protected abstract function getClassName();
 29+ protected abstract function getClassInfo();
2830
2931 /**
3032 * Returns an instance of the ContestDBClass deriving class.
@@ -36,7 +38,8 @@
3739 * @return ContestDBClass
3840 */
3941 protected function getClass() {
40 - $className = $this->getClassName();
 42+ $className = $this->getClassInfo();
 43+ $className = $className['class'];
4144 return $className::s();
4245 }
4346
@@ -141,11 +144,20 @@
142145 $serializedResults[] = $result->toArray();
143146 }
144147
145 - $this->getResult()->setIndexedTagName( $serializedResults, 'contest' );
146 -
 148+ $this->addIndexedTagNames( $serializedResults );
 149+ $this->addSerializedResults( $serializedResults );
 150+ }
 151+
 152+ protected function addIndexedTagNames( array $serializedResults ) {
 153+ $classInfo = $this->getClassInfo();
 154+ $this->getResult()->setIndexedTagName( $serializedResults, $classInfo['item'] );
 155+ }
 156+
 157+ protected function addSerializedResults( array $serializedResults ) {
 158+ $classInfo = $this->getClassInfo();
147159 $this->getResult()->addValue(
148160 null,
149 - 'contests',
 161+ $classInfo['set'],
150162 $serializedResults
151163 );
152164 }
Index: trunk/extensions/Contest/api/ApiQueryContests.php
@@ -14,8 +14,16 @@
1515 */
1616 class ApiQueryContests extends ApiContestQuery {
1717
18 - protected function getClassName() {
19 - return 'Contest';
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see ApiContestQuery::getClassInfo()
 21+ */
 22+ protected function getClassInfo() {
 23+ return array(
 24+ 'class' => 'Contest',
 25+ 'item' => 'contest',
 26+ 'set' => 'contests',
 27+ );
2028 }
2129
2230 public function __construct( $main, $action ) {
Index: trunk/extensions/Contest/api/ApiQueryChallenges.php
@@ -14,8 +14,16 @@
1515 */
1616 class ApiQueryChallenges extends ApiContestQuery {
1717
18 - protected function getClassName() {
19 - return 'ContestChallenge';
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see ApiContestQuery::getClassInfo()
 21+ */
 22+ protected function getClassInfo() {
 23+ return array(
 24+ 'class' => 'ContestChallenge',
 25+ 'item' => 'challenge',
 26+ 'set' => 'challenges',
 27+ );
2028 }
2129
2230 public function __construct( $main, $action ) {
Index: trunk/extensions/Contest/api/ApiQueryContestComments.php
@@ -0,0 +1,74 @@
 2+<?php
 3+
 4+/**
 5+ * API module to get a list of commets.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file ApiQueryContestComments.php
 10+ * @ingroup Contest
 11+ * @ingroup API
 12+ *
 13+ * @licence GNU GPL v3+
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class ApiQueryContestComments extends ApiContestQuery {
 17+
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see ApiContestQuery::getClassInfo()
 21+ */
 22+ protected function getClassInfo() {
 23+ return array(
 24+ 'class' => 'ContestComment',
 25+ 'item' => 'comment',
 26+ 'set' => 'comments',
 27+ );
 28+ }
 29+
 30+ public function __construct( $main, $action ) {
 31+ parent::__construct( $main, $action, 'coco' );
 32+ }
 33+
 34+ /**
 35+ * Handle the API request.
 36+ * Checks for access rights and then let's the parent method do the actual work.
 37+ */
 38+ public function execute() {
 39+ global $wgUser;
 40+
 41+ if ( !$wgUser->isAllowed( 'contestjudge' ) || $wgUser->isBlocked() ) {
 42+ $this->dieUsageMsg( array( 'badaccess-groups' ) );
 43+ }
 44+
 45+ parent::execute();
 46+ }
 47+
 48+ /**
 49+ * (non-PHPdoc)
 50+ * @see includes/api/ApiBase#getDescription()
 51+ */
 52+ public function getDescription() {
 53+ return 'API module for querying contest comments';
 54+ }
 55+
 56+ /**
 57+ * (non-PHPdoc)
 58+ * @see includes/api/ApiBase#getExamples()
 59+ */
 60+ protected function getExamples() {
 61+ return array (
 62+ 'api.php?action=query&list=contestcomments&cocoprops=id|user_id|contestant_id|text',
 63+ 'api.php?action=query&list=contestcomments&cocoprops=id|text&cocouser_id=42',
 64+ );
 65+ }
 66+
 67+ /**
 68+ * (non-PHPdoc)
 69+ * @see includes/api/ApiBase#getVersion()
 70+ */
 71+ public function getVersion() {
 72+ return __CLASS__ . ': $Id$';
 73+ }
 74+
 75+}
Property changes on: trunk/extensions/Contest/api/ApiQueryContestComments.php
___________________________________________________________________
Added: svn:keywords
176 + Id
Index: trunk/extensions/Contest/api/ApiQueryContestants.php
@@ -14,8 +14,16 @@
1515 */
1616 class ApiQueryContestants extends ApiContestQuery {
1717
18 - protected function getClassName() {
19 - return 'ContestContestant';
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see ApiContestQuery::getClassInfo()
 21+ */
 22+ protected function getClassInfo() {
 23+ return array(
 24+ 'class' => 'ContestContestant',
 25+ 'item' => 'contestant',
 26+ 'set' => 'contestants',
 27+ );
2028 }
2129
2230 public function __construct( $main, $action ) {
@@ -51,7 +59,7 @@
5260 protected function getExamples() {
5361 return array (
5462 'api.php?action=query&list=contestants&ctprops=id|user_id|contest_id|rating',
55 - 'api.php?action=query&list=contestants&ctprops=id|rating&ctcontestid=42',
 63+ 'api.php?action=query&list=contestants&ctprops=id|rating&ctcontest_id=42',
5664 );
5765 }
5866

Status & tagging log