~ubuntu-branches/ubuntu/maverick/mediawiki/maverick

« back to all changes in this revision

Viewing changes to includes/api/ApiMain.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-06-19 01:38:50 UTC
  • mfrom: (16.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090619013850-dsn4lrxvs90ab4rx
Tags: 1:1.15.0-1
* New upstream release. 
* Upstream added support for OASIS documents.
Closes: #530328
* Refreshed quilt patches
* Bumped standards versions to 3.8.2
* Bumped compat to 7
* Pointed to GPL-2 in debian/copyright
* Added php5-sqlite to possible DB backend dependencies.
Closes: #501569
* Proofread README.Debian, upgrade is documented there.
Closes: #520121

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
                'feedwatchlist' => 'ApiFeedWatchlist',
66
66
                'help' => 'ApiHelp',
67
67
                'paraminfo' => 'ApiParamInfo',
 
68
 
 
69
                // Write modules
68
70
                'purge' => 'ApiPurge',
69
 
        );
70
 
 
71
 
        private static $WriteModules = array (
72
71
                'rollback' => 'ApiRollback',
73
72
                'delete' => 'ApiDelete',
74
73
                'undelete' => 'ApiUndelete',
80
79
                'emailuser' => 'ApiEmailUser',
81
80
                'watch' => 'ApiWatch',
82
81
                'patrol' => 'ApiPatrol',
 
82
                'import' => 'ApiImport',
83
83
        );
84
84
 
85
85
        /**
149
149
                                wfDebug( "API: stripping user credentials for JSON callback\n" );
150
150
                                $wgUser = new User();
151
151
                        }
152
 
 
153
 
                        if (!$wgUser->isAllowed('read')) {
154
 
                                self::$Modules = array(
155
 
                                        'login'  => self::$Modules['login'],
156
 
                                        'logout' => self::$Modules['logout'],
157
 
                                        'help'   => self::$Modules['help'],
158
 
                                        );
159
 
                        }
160
152
                }
161
153
 
162
 
                global $wgAPIModules, $wgEnableWriteAPI; // extension modules
 
154
                global $wgAPIModules; // extension modules
163
155
                $this->mModules = $wgAPIModules + self :: $Modules;
164
 
                if($wgEnableWriteAPI)
165
 
                        $this->mModules += self::$WriteModules;
166
156
 
167
157
                $this->mModuleNames = array_keys($this->mModules);
168
158
                $this->mFormats = self :: $Formats;
200
190
        }
201
191
 
202
192
        /**
203
 
         * This method will simply cause an error if the write mode was disabled
204
 
         * or if the current user doesn't have the right to use it
 
193
         * Only kept for backwards compatibility
 
194
         * @deprecated Use isWriteMode() instead
205
195
         */
206
 
        public function requestWriteMode() {
207
 
                global $wgUser;
208
 
                if (!$this->mEnableWrite)
209
 
                        $this->dieUsage('Editing of this wiki through the API' .
210
 
                        ' is disabled. Make sure the $wgEnableWriteAPI=true; ' .
211
 
                        'statement is included in the wiki\'s ' .
212
 
                        'LocalSettings.php file', 'noapiwrite');
213
 
                if (!$wgUser->isAllowed('writeapi'))
214
 
                        $this->dieUsage('You\'re not allowed to edit this ' .
215
 
                        'wiki through the API', 'writeapidenied');
216
 
                if (wfReadOnly())
217
 
                        $this->dieUsageMsg(array('readonlytext'));
218
 
        }
 
196
        public function requestWriteMode() {}
219
197
 
220
198
        /**
221
199
         * Set how long the response should be cached.
360
338
                        }
361
339
 
362
340
                        $this->getResult()->reset();
 
341
                        $this->getResult()->disableSizeCheck();
363
342
                        // Re-add the id
364
 
                        if($this->mRequest->getCheck('requestid'))
365
 
                                $this->getResult()->addValue(null, 'requestid', $this->mRequest->getVal('requestid'));
 
343
                        $requestid = $this->getParameter('requestid');
 
344
                        if(!is_null($requestid))
 
345
                                $this->getResult()->addValue(null, 'requestid', $requestid);
366
346
                        $this->getResult()->addValue(null, 'error', $errMessage);
367
347
 
368
348
                return $errMessage['code'];
373
353
         */
374
354
        protected function executeAction() {
375
355
                // First add the id to the top element
376
 
                if($this->mRequest->getCheck('requestid'))
377
 
                        $this->getResult()->addValue(null, 'requestid', $this->mRequest->getVal('requestid'));
 
356
                $requestid = $this->getParameter('requestid');
 
357
                if(!is_null($requestid))
 
358
                        $this->getResult()->addValue(null, 'requestid', $requestid);
378
359
 
379
360
                $params = $this->extractRequestParams();
380
361
 
398
379
                                header( 'X-Database-Lag: ' . intval( $lag ) );
399
380
                                // XXX: should we return a 503 HTTP error code like wfMaxlagError() does?
400
381
                                if( $wgShowHostnames ) {
401
 
                                        ApiBase :: dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
 
382
                                        $this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
402
383
                                } else {
403
 
                                        ApiBase :: dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
 
384
                                        $this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
404
385
                                }
405
386
                                return;
406
387
                        }
407
388
                }
408
389
 
 
390
                global $wgUser;
 
391
                if ($module->isReadMode() && !$wgUser->isAllowed('read'))
 
392
                        $this->dieUsageMsg(array('readrequired'));
 
393
                if ($module->isWriteMode()) {
 
394
                        if (!$this->mEnableWrite)
 
395
                                $this->dieUsageMsg(array('writedisabled'));
 
396
                        if (!$wgUser->isAllowed('writeapi'))
 
397
                                $this->dieUsageMsg(array('writerequired'));
 
398
                        if (wfReadOnly())
 
399
                                $this->dieUsageMsg(array('readonlytext'));
 
400
                }
 
401
 
409
402
                if (!$this->mInternalMode) {
410
403
                        // Ignore mustBePosted() for internal calls
411
404
                        if($module->mustBePosted() && !$this->mRequest->wasPosted())
438
431
         * Print results using the current printer
439
432
         */
440
433
        protected function printResult($isError) {
441
 
                $this->getResult()->cleanupUTF8();
 
434
                $this->getResult()->cleanUpUTF8();
442
435
                $printer = $this->mPrinter;
443
436
                $printer->profileIn();
444
437
 
454
447
                $printer->closePrinter();
455
448
                $printer->profileOut();
456
449
        }
 
450
        
 
451
        public function isReadMode() {
 
452
                return false;
 
453
        }
457
454
 
458
455
        /**
459
456
         * See ApiBase for description.
657
654
        public function getVersion() {
658
655
                $vers = array ();
659
656
                $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n    http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
660
 
                $vers[] = __CLASS__ . ': $Id: ApiMain.php 45752 2009-01-14 21:36:57Z catrope $';
 
657
                $vers[] = __CLASS__ . ': $Id: ApiMain.php 50834 2009-05-20 20:10:47Z catrope $';
661
658
                $vers[] = ApiBase :: getBaseVersion();
662
659
                $vers[] = ApiFormatBase :: getBaseVersion();
663
660
                $vers[] = ApiQueryBase :: getBaseVersion();