API:
authorYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 19 May 2007 20:26:08 +0000 (20:26 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 19 May 2007 20:26:08 +0000 (20:26 +0000)
* breaking change: Converted a map of revisions into a list of revisions to allow easier json processing (no need to know map keys)
* html formatting now properly links urls ending with a '\n' string (jsonfm)
* regression: fixed allpages to return int instead of string for pageid and ns
* Added: info now returns page length, counter, and a new flag

includes/api/ApiFormatBase.php
includes/api/ApiMain.php
includes/api/ApiQueryAllpages.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryRevisions.php
includes/api/ApiResult.php

index 0824338..e420e20 100644 (file)
@@ -149,9 +149,9 @@ for more information.
                $text = ereg_replace('\<([^>]+)\>', '<span style="color:blue;">&lt;\1&gt;</span>', $text);
                // identify URLs
                $protos = "http|https|ftp|gopher";
-               $text = ereg_replace("($protos)://[^ '\"()<\n]+", '<a href="\\0">\\0</a>', $text);
+               $text = ereg_replace("($protos)://[^ \\'\"()<\n]+", '<a href="\\0">\\0</a>', $text);
                // identify requests to api.php
-               $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text);
+               $text = ereg_replace("api\\.php\\?[^ \\()<\n\t]+", '<a href="\\0">\\0</a>', $text);
                // make strings inside * bold
                $text = ereg_replace("\\*[^<>\n]+\\*", '<b>\\0</b>', $text);
                // make strings inside $ italic
index df698fc..234bc52 100644 (file)
@@ -29,7 +29,16 @@ if (!defined('MEDIAWIKI')) {
 }
 
 /**
- * This is the main API class, used for both external and internal processing. 
+ * This is the main API class, used for both external and internal processing.
+ * When executed, it will create the requested formatter object,
+ * instantiate and execute an object associated with the needed action,
+ * and use formatter to print results.
+ * In case of an exception, an error message will be printed using the same formatter.
+ *
+ * To use API from another application, run it using FauxRequest object, in which
+ * case any internal exceptions will not be handled but passed up to the caller.
+ * After successful execution, use getResult() for the resulting data.   
+ *  
  * @addtogroup API
  */
 class ApiMain extends ApiBase {
@@ -43,11 +52,11 @@ class ApiMain extends ApiBase {
         * List of available modules: action name => module class
         */
        private static $Modules = array (
-               'help' => 'ApiHelp',
 //             'login' => 'ApiLogin',          // LOGIN is temporarily disabled until it becomes more secure
                'query' => 'ApiQuery',
                'opensearch' => 'ApiOpenSearch',
-               'feedwatchlist' => 'ApiFeedWatchlist'           
+               'feedwatchlist' => 'ApiFeedWatchlist',
+               'help' => 'ApiHelp',
        );
 
        /**
index 9d52cb1..a6ad4e8 100644 (file)
@@ -92,9 +92,9 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase {
                        if (is_null($resultPageSet)) {
                                $title = Title :: makeTitle($row->page_namespace, $row->page_title);
                                if ($title->userCanRead()) {
-                                       $data[intval($row->page_id)] = array(
-                                               'pageid' => $row->page_id,
-                                               'ns' => $title->getNamespace(),
+                                       $data[] = array(
+                                               'pageid' => intval($row->page_id),
+                                               'ns' => intval($title->getNamespace()),
                                                'title' => $title->getPrefixedText());
                                }
                        } else {
index 3014fec..5ed79fe 100644 (file)
@@ -40,8 +40,11 @@ class ApiQueryInfo extends ApiQueryBase {
        public function requestExtraData() {
                $pageSet = $this->getPageSet();
                $pageSet->requestField('page_is_redirect');
+               $pageSet->requestField('page_is_new');
+               $pageSet->requestField('page_counter');
                $pageSet->requestField('page_touched');
                $pageSet->requestField('page_latest');
+               $pageSet->requestField('page_len');
        }
 
        public function execute() {
@@ -51,18 +54,26 @@ class ApiQueryInfo extends ApiQueryBase {
                $result = $this->getResult();
 
                $pageIsRedir = $pageSet->getCustomField('page_is_redirect');
+               $pageIsNew = $pageSet->getCustomField('page_is_new');
+               $pageCounter = $pageSet->getCustomField('page_counter');
                $pageTouched = $pageSet->getCustomField('page_touched');
                $pageLatest = $pageSet->getCustomField('page_latest');
+               $pageLength = $pageSet->getCustomField('page_len');
 
                foreach ( $titles as $pageid => $unused ) {
                        $pageInfo = array (
                                'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]),
-                               'lastrevid' => intval($pageLatest[$pageid])
+                               'lastrevid' => intval($pageLatest[$pageid]),
+                               'counter' => $pageCounter[$pageid],
+                               'length' => $pageLength[$pageid],
                        );
 
                        if ($pageIsRedir[$pageid])
                                $pageInfo['redirect'] = '';
 
+                       if ($pageIsNew[$pageid])
+                               $pageInfo['new'] = '';
+
                        $result->addValue(array (
                                'query',
                                'pages'
index bf9d6d1..13ae6e5 100644 (file)
@@ -176,11 +176,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                                if ($showContent)
                                        ApiResult :: setContent($vals, Revision :: getRevisionText($row));
 
-                               $this->getResult()->addValue(array (
-                                       'query',
-                                       'pages',
-                                       intval($row->rev_page
-                               ), 'revisions'), intval($row->rev_id), $vals);
+                               $this->getResult()->addValue(
+                                       array (
+                                               'query',
+                                               'pages',
+                                               intval($row->rev_page),
+                                               'revisions'),
+                                       null, $vals);
                        }
                }
                $db->freeResult($res);
index 65f17e8..8eaf87c 100644 (file)
@@ -125,7 +125,8 @@ class ApiResult extends ApiBase {
        /**
         * Add value to the output data at the given path.
         * Path is an indexed array, each element specifing the branch at which to add the new value
-        * Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value  
+        * Setting $path to array('a','b','c') is equivalent to data['a']['b']['c'] = $value
+        * If $name is empty, the $value is added as a next list element data[] = $value  
         */
        public function addValue($path, $name, $value) {
 
@@ -145,7 +146,10 @@ class ApiResult extends ApiBase {
                        }
                }
 
-               ApiResult :: setElement($data, $name, $value);
+               if (empty($name))
+                       $data[] = $value;       // Add list element
+               else
+                       ApiResult :: setElement($data, $name, $value);  // Add named element
        }
 
        public function execute() {