API * version param now links to the SVN
authorYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 4 Nov 2006 05:24:59 +0000 (05:24 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 4 Nov 2006 05:24:59 +0000 (05:24 +0000)
* debug case fixes
* renamed ApiQueryContributions to ApiQueryUserContributions (a bit clearer)

includes/AutoLoader.php
includes/api/ApiBase.php
includes/api/ApiPageSet.php
includes/api/ApiQueryBacklinks.php
includes/api/ApiQueryContributions.php [deleted file]
includes/api/ApiQueryUserContributions.php [new file with mode: 0644]

index 3232a0b..15fe3e7 100644 (file)
@@ -256,7 +256,7 @@ function __autoload($className) {
                'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php',
                'ApiQueryBase' => 'includes/api/ApiQueryBase.php',
                'ApiQueryBacklinks' => 'includes/api/ApiQueryBacklinks.php',
-               'ApiQueryContributions' => 'includes/api/ApiQueryContributions.php',
+               'ApiQueryContributions' => 'includes/api/ApiQueryUserContributions.php',
                'ApiQueryInfo' => 'includes/api/ApiQueryInfo.php',
                'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php',
                'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php',
index 569845f..e12a256 100644 (file)
@@ -150,8 +150,18 @@ abstract class ApiBase {
 
                        if ($this->getMain()->getShowVersions()) {
                                $versions = $this->getVersion();
-                               if (is_array($versions))
+                               $pattern = '(\$.*) ([0-9a-z_]+\.php) (.*\$)';
+                               $replacement = '\\0' . "\n    " . 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/api/\\2';
+                               
+                               if (is_array($versions)) {
+                                       $ver2 = array();
+                                       foreach ($versions as &$v)
+                                               $v = eregi_replace($pattern, $replacement, $v);
                                        $versions = implode("\n  ", $versions);
+                               }
+                               else
+                                       $versions = eregi_replace($pattern, $replacement, $versions);
+
                                $msg .= "Version:\n  $versions\n";
                        }
                }
index ef05465..b5424bb 100644 (file)
@@ -358,7 +358,7 @@ class ApiPageSet extends ApiQueryBase {
         */
        private function initFromQueryResult($db, $res, &$remaining = null, $processTitles = null) {
                if (!is_null($remaining) && is_null($processTitles))
-                       ApiBase :: dieDebug('Missing $processTitles parameter when $remaining is provided');
+                       ApiBase :: dieDebug(__METHOD__, 'Missing $processTitles parameter when $remaining is provided');
                        
                while ($row = $db->fetchObject($res)) {
 
@@ -431,7 +431,7 @@ class ApiPageSet extends ApiQueryBase {
 
                // Populate all the page information
                if($this->mResolveRedirects)
-                       $this->dieDebug('revids may not be used with redirect resolution');
+                       ApiBase :: dieDebug(__METHOD__, 'revids may not be used with redirect resolution');
                $this->initFromPageIds(array_keys($pageids));
        }
 
@@ -527,7 +527,7 @@ class ApiPageSet extends ApiQueryBase {
 
                // All IDs must exist in the page table
                if (!empty($this->mPendingRedirectIDs[$plfrom]))
-                       $this->dieDebug('Invalid redirect IDs were found');
+                       ApiBase :: dieDebug(__METHOD__, 'Invalid redirect IDs were found');
 
                return $linkBatch;
        }
index 30228d4..2c171f8 100644 (file)
@@ -95,7 +95,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                extract($this->extractRequestParams());
 
                if ($redirect)
-                       $this->dieDebug('Redirect is not yet been implemented', 'notimplemented');
+                       ApiBase :: dieDebug(__METHOD__, 'Redirect is not yet been implemented', 'notimplemented');
 
                $this->processContinue($continue, $redirect);
 
diff --git a/includes/api/ApiQueryContributions.php b/includes/api/ApiQueryContributions.php
deleted file mode 100644 (file)
index 5bb880a..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-<?php
-
-
-/*
- * Created on Oct 16, 2006
- *
- * API for MediaWiki 1.8+
- *
- * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * http://www.gnu.org/copyleft/gpl.html
- */
-
-if (!defined('MEDIAWIKI')) {
-       // Eclipse helper - will be ignored in production
-       require_once ('ApiQueryBase.php');
-}
-
-class ApiQueryContributions extends ApiQueryBase {
-
-       public function __construct($query, $moduleName) {
-               parent :: __construct($query, $moduleName, 'uc');
-       }
-
-       public function execute() {
-
-               //Blank all our variables
-               $limit = $user = $start = $end = $dir = null;
-
-               //Get our parameters out
-               extract($this->extractRequestParams());
-
-               //Get a database instance
-               $db = & $this->getDB();
-
-               if (is_null($user))
-                       $this->dieUsage("User parameter may not be empty", 'param_user');
-               $userid = $db->selectField('user', 'user_id', array (
-                       'user_name' => $user
-               ));
-               if (!$userid)
-                       $this->dieUsage("User name $user not found", 'param_user');
-
-               //Extract the table names, in case we have a prefix
-               extract($db->tableNames( 'page', 'revision'), EXTR_PREFIX_ALL, 'tbl');
-
-               //We're after the revision table, and the corresponding page row for
-               //anything we retrieve.
-               $this->addTables("$tbl_revision LEFT OUTER JOIN $tbl_page ON " .
-                       "page_id=rev_page");
-
-               //We want to know the namespace, title, new-ness, and ID of a page,
-               // and the id, text-id, timestamp, minor-status, summary and page
-               // of a revision.
-               $this->addFields(array('page_namespace', 'page_title', 'page_is_new',
-                       'rev_id', 'rev_text_id', 'rev_timestamp', 'rev_minor_edit',
-                               'rev_comment', 'rev_page'));
-
-               // We only want pages by the specified user.
-               $this->addWhereFld('rev_user_text', $user);
-               // ... and in the specified timeframe.
-               $this->addWhereRange('rev_timestamp', $dir, $start, $end );
-
-               $this->addOption('LIMIT', $limit + 1);
-
-               //Initialise some variables
-               $data = array ();
-               $count = 0;
-
-               //Do the actual query.
-               $res = $this->select( __METHOD__ );
-
-               //Fetch each row
-               while ( $row = $db->fetchObject( $res ) ) {
-                       if (++ $count > $limit) {
-                               // We've reached the one extra which shows that there are additional pages to be had. Stop here...
-                               $this->setContinueEnumParameter('start', $row->rev_timestamp);
-                               break;
-                       }
-
-                       //There's a fancy function in ApiQueryBase that does
-                       // most of the work for us. Use that for the page
-                       // and revision.
-                       $revvals = $this->addRowInfo('rev', $row);
-                       $pagevals = $this->addRowInfo('page', $row);
-
-                       //If we got data on the revision only, use only
-                       // that data.
-                       if($revvals && !$pagevals)
-                               $data[] = $revvals;
-                       //If we got data on the page only, use only
-                       // that data.
-                       else if($pagevals && !$revvals)
-                               $data[] = $pagevals;
-                       //... and if we got data on both the revision and
-                       // the page, merge the data and send it out.
-                       else if($pagevals && $revvals)
-                               $data[] = array_merge($revvals, $pagevals);
-               }
-
-               //Free the database record so the connection can get on with other stuff
-               $db->freeResult($res);
-
-               //And send the whole shebang out as output.
-               $this->getResult()->setIndexedTagName($data, 'item');
-               $this->getResult()->addValue('query', $this->getModuleName(), $data);
-       }
-
-       protected function getAllowedParams() {
-               return array (
-                       'limit' => array (
-                               ApiBase :: PARAM_DFLT => 10,
-                               ApiBase :: PARAM_TYPE => 'limit',
-                               ApiBase :: PARAM_MIN => 1,
-                               ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
-                               ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
-                       ),
-                       'start' => array (
-                               ApiBase :: PARAM_TYPE => 'timestamp'
-                       ),
-                       'end' => array (
-                               ApiBase :: PARAM_TYPE => 'timestamp'
-                       ),
-                       'user' => null,
-                       'dir' => array (
-                               ApiBase :: PARAM_DFLT => 'older',
-                               ApiBase :: PARAM_TYPE => array (
-                                       'newer',
-                                       'older'
-                               )
-                       )
-               );
-       }
-
-       protected function getParamDescription() {
-               return array (
-                       'limit' => 'The maximum number of contributions to return.',
-                       'start' => 'The start timestamp to return from.',
-                       'end' => 'The end timestamp to return to.',
-                       'user' => 'The user to retrieve contributions for.',
-                       'dir' => 'The direction to search (older or newer).'
-               );
-       }
-
-       protected function getDescription() {
-               return 'Get edits by a user..';
-       }
-
-       protected function getExamples() {
-               return array (
-                       'api.php?action=query&list=usercontribs&ucuser=YurikBot'
-               );
-       }
-
-       public function getVersion() {
-               return __CLASS__ . ': $Id: ApiQueryContributions.php 17335 2006-11-01 09:36:00Z Werdna $';
-       }
-}
-?>
diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php
new file mode 100644 (file)
index 0000000..1d8ae69
--- /dev/null
@@ -0,0 +1,172 @@
+<?php
+
+
+/*
+ * Created on Oct 16, 2006
+ *
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+if (!defined('MEDIAWIKI')) {
+       // Eclipse helper - will be ignored in production
+       require_once ('ApiQueryBase.php');
+}
+
+class ApiQueryContributions extends ApiQueryBase {
+
+       public function __construct($query, $moduleName) {
+               parent :: __construct($query, $moduleName, 'uc');
+       }
+
+       public function execute() {
+
+               //Blank all our variables
+               $limit = $user = $start = $end = $dir = null;
+
+               //Get our parameters out
+               extract($this->extractRequestParams());
+
+               //Get a database instance
+               $db = & $this->getDB();
+
+               if (is_null($user))
+                       $this->dieUsage("User parameter may not be empty", 'param_user');
+               $userid = $db->selectField('user', 'user_id', array (
+                       'user_name' => $user
+               ));
+               if (!$userid)
+                       $this->dieUsage("User name $user not found", 'param_user');
+
+               //Extract the table names, in case we have a prefix
+               extract($db->tableNames( 'page', 'revision'), EXTR_PREFIX_ALL, 'tbl');
+
+               //We're after the revision table, and the corresponding page row for
+               //anything we retrieve.
+               $this->addTables("$tbl_revision LEFT OUTER JOIN $tbl_page ON " .
+                       "page_id=rev_page");
+
+               //We want to know the namespace, title, new-ness, and ID of a page,
+               // and the id, text-id, timestamp, minor-status, summary and page
+               // of a revision.
+               $this->addFields(array('page_namespace', 'page_title', 'page_is_new',
+                       'rev_id', 'rev_text_id', 'rev_timestamp', 'rev_minor_edit',
+                               'rev_comment', 'rev_page'));
+
+               // We only want pages by the specified user.
+               $this->addWhereFld('rev_user_text', $user);
+               // ... and in the specified timeframe.
+               $this->addWhereRange('rev_timestamp', $dir, $start, $end );
+
+               $this->addOption('LIMIT', $limit + 1);
+
+               //Initialise some variables
+               $data = array ();
+               $count = 0;
+
+               //Do the actual query.
+               $res = $this->select( __METHOD__ );
+
+               //Fetch each row
+               while ( $row = $db->fetchObject( $res ) ) {
+                       if (++ $count > $limit) {
+                               // We've reached the one extra which shows that there are additional pages to be had. Stop here...
+                               $this->setContinueEnumParameter('start', $row->rev_timestamp);
+                               break;
+                       }
+
+                       //There's a fancy function in ApiQueryBase that does
+                       // most of the work for us. Use that for the page
+                       // and revision.
+                       $revvals = $this->addRowInfo('rev', $row);
+                       $pagevals = $this->addRowInfo('page', $row);
+
+                       //If we got data on the revision only, use only
+                       // that data.
+                       if($revvals && !$pagevals)
+                               $data[] = $revvals;
+                       //If we got data on the page only, use only
+                       // that data.
+                       else if($pagevals && !$revvals)
+                               $data[] = $pagevals;
+                       //... and if we got data on both the revision and
+                       // the page, merge the data and send it out.
+                       else if($pagevals && $revvals)
+                               $data[] = array_merge($revvals, $pagevals);
+               }
+
+               //Free the database record so the connection can get on with other stuff
+               $db->freeResult($res);
+
+               //And send the whole shebang out as output.
+               $this->getResult()->setIndexedTagName($data, 'item');
+               $this->getResult()->addValue('query', $this->getModuleName(), $data);
+       }
+
+       protected function getAllowedParams() {
+               return array (
+                       'limit' => array (
+                               ApiBase :: PARAM_DFLT => 10,
+                               ApiBase :: PARAM_TYPE => 'limit',
+                               ApiBase :: PARAM_MIN => 1,
+                               ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
+                               ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+                       ),
+                       'start' => array (
+                               ApiBase :: PARAM_TYPE => 'timestamp'
+                       ),
+                       'end' => array (
+                               ApiBase :: PARAM_TYPE => 'timestamp'
+                       ),
+                       'user' => null,
+                       'dir' => array (
+                               ApiBase :: PARAM_DFLT => 'older',
+                               ApiBase :: PARAM_TYPE => array (
+                                       'newer',
+                                       'older'
+                               )
+                       )
+               );
+       }
+
+       protected function getParamDescription() {
+               return array (
+                       'limit' => 'The maximum number of contributions to return.',
+                       'start' => 'The start timestamp to return from.',
+                       'end' => 'The end timestamp to return to.',
+                       'user' => 'The user to retrieve contributions for.',
+                       'dir' => 'The direction to search (older or newer).'
+               );
+       }
+
+       protected function getDescription() {
+               return 'Get edits by a user..';
+       }
+
+       protected function getExamples() {
+               return array (
+                       'api.php?action=query&list=usercontribs&ucuser=YurikBot'
+               );
+       }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
+}
+?>