Merge "escape HTML elements in docblock with double quotes"
[lhc/web/wiklou.git] / includes / api / ApiImport.php
index 3bb3b9a..15eac33 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on Feb 4, 2009
  *
- * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@gmail.com
+ * Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@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
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiBase.php' );
-}
-
 /**
  * API module that imports an XML file like Special:Import does
  *
@@ -41,13 +36,12 @@ class ApiImport extends ApiBase {
        }
 
        public function execute() {
-               global $wgUser;
-
+               $user = $this->getUser();
                $params = $this->extractRequestParams();
 
                $isUpload = false;
                if ( isset( $params['interwikisource'] ) ) {
-                       if ( !$wgUser->isAllowed( 'import' ) ) {
+                       if ( !$user->isAllowed( 'import' ) ) {
                                $this->dieUsageMsg( 'cantimport' );
                        }
                        if ( !isset( $params['interwikipage'] ) ) {
@@ -61,7 +55,7 @@ class ApiImport extends ApiBase {
                        );
                } else {
                        $isUpload = true;
-                       if ( !$wgUser->isAllowed( 'importupload' ) ) {
+                       if ( !$user->isAllowed( 'importupload' ) ) {
                                $this->dieUsageMsg( 'cantimport-upload' );
                        }
                        $source = ImportStreamSource::newFromUpload( 'xml' );
@@ -132,6 +126,17 @@ class ApiImport extends ApiBase {
                );
        }
 
+       public function getResultProperties() {
+               return array(
+                       ApiBase::PROP_LIST => true,
+                       '' => array(
+                               'ns' => 'namespace',
+                               'title' => 'string',
+                               'revisions' => 'integer'
+                       )
+               );
+       }
+
        public function getDescription() {
                return array(
                        'Import a page from another wiki, or an XML file.' ,
@@ -160,13 +165,13 @@ class ApiImport extends ApiBase {
 
        public function getExamples() {
                return array(
-                       'Import [[meta:Help:Parserfunctions]] to namespace 100 with full history:',
-                       '  api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&namespace=100&fullhistory=&token=123ABC',
+                       'api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&namespace=100&fullhistory=&token=123ABC'
+                               => 'Import [[meta:Help:Parserfunctions]] to namespace 100 with full history',
                );
        }
 
        public function getHelpUrls() {
-               return 'http://www.mediawiki.org/wiki/API:Import';
+               return 'https://www.mediawiki.org/wiki/API:Import';
        }
 
        public function getVersion() {
@@ -192,8 +197,16 @@ class ApiImportReporter extends ImportReporter {
        function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
                // Add a result entry
                $r = array();
-               ApiQueryBase::addTitleInfo( $r, $title );
-               $r['revisions'] = intval( $successCount );
+
+               if ( $title === null ) {
+                       # Invalid or non-importable title
+                       $r['title'] = $pageInfo['title'];
+                       $r['invalid'] = '';
+               } else {
+                       ApiQueryBase::addTitleInfo( $r, $title );
+                       $r['revisions'] = intval( $successCount );
+               }
+
                $this->mResultArr[] = $r;
 
                // Piggyback on the parent to do the logging