r29637 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29636‎ | r29637 | r29638 >
Date:07:08, 12 January 2008
Author:amidaniel
Status:old
Tags:
Comment:
API: Various docu and clean-up.
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiChangeRights.php (modified) (history)
  • /trunk/phase3/includes/api/ApiDelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiExpandTemplates.php (modified) (history)
  • /trunk/phase3/includes/api/ApiLogout.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiChangeRights.php
@@ -27,7 +27,10 @@
2828 require_once ("ApiBase.php");
2929 }
3030
31 -/**
 31+/**
 32+ * API module that facilitates the changing of user rights. The API eqivalent of
 33+ * Special:Userrights. Requires API write mode to be enabled.
 34+ *
3235 * @addtogroup API
3336 */
3437 class ApiChangeRights extends ApiBase {
Index: trunk/phase3/includes/api/ApiLogout.php
@@ -28,6 +28,12 @@
2929 require_once ('ApiBase.php');
3030 }
3131
 32+/**
 33+ * API module to allow users to log out of the wiki. API equivalent of
 34+ * Special:Userlogout.
 35+ *
 36+ * @addtogroup API
 37+ */
3238 class ApiLogout extends ApiBase {
3339
3440 public function __construct($main, $action) {
@@ -62,4 +68,4 @@
6369 public function getVersion() {
6470 return __CLASS__ . ': $Id$';
6571 }
66 -}
\ No newline at end of file
 72+}
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -28,14 +28,26 @@
2929 }
3030
3131 /**
 32+* API module that facilitates the blocking of users. Requires API write mode
 33+* to be enabled.
 34+*
3235 * @addtogroup API
3336 */
3437 class ApiBlock extends ApiBase {
3538
 39+ /**
 40+ * Std ctor.
 41+ */
3642 public function __construct($main, $action) {
3743 parent :: __construct($main, $action);
3844 }
3945
 46+ /**
 47+ * Blocks the user specified in the parameters for the given expiry, with the
 48+ * given reason, and with all other settings provided in the params. If the block
 49+ * succeeds, produces a result containing the details of the block and notice
 50+ * of success. If it fails, the result will specify the nature of the error.
 51+ */
4052 public function execute() {
4153 global $wgUser;
4254 $this->getMain()->requestWriteMode();
@@ -141,7 +153,7 @@
142154 'nocreate' => 'Prevent account creation',
143155 'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from',
144156 'noemail' => 'Prevent user from sending e-mail through the wiki',
145 - 'hidename' => 'Hide the username from the block log.'
 157+ 'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)'
146158 );
147159 }
148160
Index: trunk/phase3/includes/api/ApiExpandTemplates.php
@@ -29,6 +29,10 @@
3030 }
3131
3232 /**
 33+ * API module that functions as a shortcut to the wikitext preprocessor. Expands
 34+ * any templates in a provided string, and returns the result of this expansion
 35+ * to the caller.
 36+ *
3337 * @addtogroup API
3438 */
3539 class ApiExpandTemplates extends ApiBase {
Index: trunk/phase3/includes/api/ApiDelete.php
@@ -29,6 +29,9 @@
3030
3131
3232 /**
 33+ * API module that facilitates deleting pages. The API eqivalent of action=delete.
 34+ * Requires API write mode to be enabled.
 35+ *
3336 * @addtogroup API
3437 */
3538 class ApiDelete extends ApiBase {
@@ -37,51 +40,21 @@
3841 parent :: __construct($main, $action);
3942 }
4043
 44+ /* Return values for the delete function. */
 45+ const DELETE_SUCCESS = 0;
 46+ const DELETE_PERM = 1;
 47+ const DELETE_BLOCKED = 2;
 48+ const DELETE_READONLY = 3;
 49+ const DELETE_BADTOKEN = 4;
 50+ const DELETE_BADARTICLE = 5;
 51+
4152 /**
42 - * We have our own delete() function, since Article.php's implementation is split in two phases
43 - * @param Article $article - Article object to work on
44 - * @param string $token - Delete token (same as edit token)
45 - * @param string $reason - Reason for the deletion. Autogenerated if NULL
46 - * @return DELETE_SUCCESS on success, DELETE_* on failure
 53+ * Extracts the title, token, and reason from the request parameters and invokes
 54+ * the local delete() function with these as arguments. It does not make use of
 55+ * the delete function specified by Article.php. If the deletion succeeds, the
 56+ * details of the article deleted and the reason for deletion are added to the
 57+ * result object.
4758 */
48 -
49 - const DELETE_SUCCESS = 0;
50 - const DELETE_PERM = 1;
51 - const DELETE_BLOCKED = 2;
52 - const DELETE_READONLY = 3;
53 - const DELETE_BADTOKEN = 4;
54 - const DELETE_BADARTICLE = 5;
55 -
56 - public static function delete(&$article, $token, &$reason = NULL)
57 - {
58 - global $wgUser;
59 -
60 - // Check permissions first
61 - if(!$article->mTitle->userCan('delete'))
62 - return self::DELETE_PERM;
63 - if($wgUser->isBlocked())
64 - return self::DELETE_BLOCKED;
65 - if(wfReadOnly())
66 - return self::DELETE_READONLY;
67 -
68 - // Check token
69 - if(!$wgUser->matchEditToken($token))
70 - return self::DELETE_BADTOKEN;
71 -
72 - // Auto-generate a summary, if necessary
73 - if(is_null($reason))
74 - {
75 - $reason = $article->generateReason($hasHistory);
76 - if($reason === false)
77 - return self::DELETE_BADARTICLE;
78 - }
79 -
80 - // Luckily, Article.php provides a reusable delete function that does the hard work for us
81 - if($article->doDeleteArticle($reason))
82 - return self::DELETE_SUCCESS;
83 - return self::DELETE_BADARTICLE;
84 - }
85 -
8659 public function execute() {
8760 global $wgUser;
8861 $this->getMain()->requestWriteMode();
@@ -136,6 +109,44 @@
137110 $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason);
138111 $this->getResult()->addValue(null, $this->getModuleName(), $r);
139112 }
 113+
 114+ /**
 115+ * We have our own delete() function, since Article.php's implementation is split in two phases
 116+ *
 117+ * @param Article $article - Article object to work on
 118+ * @param string $token - Delete token (same as edit token)
 119+ * @param string $reason - Reason for the deletion. Autogenerated if NULL
 120+ * @return DELETE_SUCCESS on success, DELETE_* on failure
 121+ */
 122+ public static function delete(&$article, $token, &$reason = NULL)
 123+ {
 124+ global $wgUser;
 125+
 126+ // Check permissions first
 127+ if(!$article->mTitle->userCan('delete'))
 128+ return self::DELETE_PERM;
 129+ if($wgUser->isBlocked())
 130+ return self::DELETE_BLOCKED;
 131+ if(wfReadOnly())
 132+ return self::DELETE_READONLY;
 133+
 134+ // Check token
 135+ if(!$wgUser->matchEditToken($token))
 136+ return self::DELETE_BADTOKEN;
 137+
 138+ // Auto-generate a summary, if necessary
 139+ if(is_null($reason))
 140+ {
 141+ $reason = $article->generateReason($hasHistory);
 142+ if($reason === false)
 143+ return self::DELETE_BADARTICLE;
 144+ }
 145+
 146+ // Luckily, Article.php provides a reusable delete function that does the hard work for us
 147+ if($article->doDeleteArticle($reason))
 148+ return self::DELETE_SUCCESS;
 149+ return self::DELETE_BADARTICLE;
 150+ }
140151
141152 protected function getAllowedParams() {
142153 return array (
Index: trunk/phase3/includes/api/ApiBase.php
@@ -63,12 +63,36 @@
6464 $this->mModulePrefix = $modulePrefix;
6565 }
6666
 67+ /*****************************************************************************
 68+ * ABSTRACT METHODS *
 69+ *****************************************************************************/
 70+
6771 /**
68 - * Executes this module
 72+ * Evaluates the parameters, performs the requested query, and sets up the
 73+ * result. Concrete implementations of ApiBase must override this method to
 74+ * provide whatever functionality their module offers. Implementations must
 75+ * not produce any output on their own and are not expected to handle any
 76+ * errors.
 77+ *
 78+ * The execute method will be invoked directly by ApiMain immediately before
 79+ * the result of the module is output. Aside from the constructor, implementations
 80+ * should assume that no other methods will be called externally on the module
 81+ * before the result is processed.
 82+ *
 83+ * The result data should be stored in the result object referred to by
 84+ * "getResult()". Refer to ApiResult.php for details on populating a result
 85+ * object.
6986 */
7087 public abstract function execute();
7188
7289 /**
 90+ * Returns a String that identifies the version of the extending class. Typically
 91+ * includes the class name, the svn revision, timestamp, and last author. May
 92+ * be severely incorrect in many implementations!
 93+ */
 94+ public abstract function getVersion();
 95+
 96+ /**
7397 * Get the name of the module being executed by this instance
7498 */
7599 public function getModuleName() {
@@ -100,14 +124,16 @@
101125 }
102126
103127 /**
104 - * If this module's $this is the same as $this->mMainModule, its the root, otherwise no
 128+ * Returns true if this module is the main module ($this === $this->mMainModule),
 129+ * false otherwise.
105130 */
106131 public function isMain() {
107132 return $this === $this->mMainModule;
108133 }
109134
110135 /**
111 - * Get result object
 136+ * Get the result object. Please refer to the documentation in ApiResult.php
 137+ * for details on populating and accessing data in a result object.
112138 */
113139 public function getResult() {
114140 // Main module has getResult() method overriden
@@ -125,7 +151,8 @@
126152 }
127153
128154 /**
129 - * Set warning section for this module. Users should monitor this section to notice any changes in API.
 155+ * Set warning section for this module. Users should monitor this section to
 156+ * notice any changes in API.
130157 */
131158 public function setWarning($warning) {
132159 $msg = array();
@@ -196,6 +223,10 @@
197224 return $msg;
198225 }
199226
 227+ /**
 228+ * Generates the parameter descriptions for this module, to be displayed in the
 229+ * module's help.
 230+ */
200231 public function makeHelpMsgParameters() {
201232 $params = $this->getAllowedParams();
202233 if ($params !== false) {
@@ -208,7 +239,7 @@
209240 if (is_array($desc))
210241 $desc = implode($paramPrefix, $desc);
211242
212 - @ $type = $paramSettings[self :: PARAM_TYPE];
 243+ $type = $paramSettings[self :: PARAM_TYPE];
213244 if (isset ($type)) {
214245 if (isset ($paramSettings[self :: PARAM_ISMULTI]))
215246 $prompt = 'Values (separate with \'|\'): ';
@@ -325,6 +356,10 @@
326357 return $this->getParameterFromSettings($paramName, $paramSettings);
327358 }
328359
 360+ /**
 361+ * Returns an array of the namespaces (by integer id) that exist on the
 362+ * wiki. Used primarily in help documentation.
 363+ */
329364 public static function getValidNamespaces() {
330365 static $mValidNamespaces = null;
331366 if (is_null($mValidNamespaces)) {
@@ -341,6 +376,7 @@
342377
343378 /**
344379 * Using the settings determine the value for the given parameter
 380+ *
345381 * @param $paramName String: parameter name
346382 * @param $paramSettings Mixed: default value or an array of settings using PARAM_* constants.
347383 * @param $parseMaxLimit Boolean: parse limit when max is given?
@@ -637,8 +673,10 @@
638674 print "\n</pre>\n";
639675 }
640676
641 - public abstract function getVersion();
642677
 678+ /**
 679+ * Returns a String that identifies the version of this class.
 680+ */
643681 public static function getBaseVersion() {
644682 return __CLASS__ . ': $Id$';
645683 }
Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -28,6 +28,9 @@
2929 }
3030
3131 /**
 32+ * API module that facilitates the unblocking of users. Requires API write mode
 33+ * to be enabled.
 34+ *
3235 * @addtogroup API
3336 */
3437 class ApiUnblock extends ApiBase {
@@ -36,6 +39,9 @@
3740 parent :: __construct($main, $action);
3841 }
3942
 43+ /**
 44+ * Unblocks the specified user or provides the reason the unblock failed.
 45+ */
4046 public function execute() {
4147 global $wgUser;
4248 $this->getMain()->requestWriteMode();

Status & tagging log