Provide Status::__toString()
[lhc/web/wiklou.git] / includes / Import.php
index e6b5dc2..4eb8e97 100644 (file)
@@ -37,13 +37,21 @@ class WikiImporter {
        private $mNoticeCallback, $mDebug;
        private $mImportUploads, $mImageBasePath;
        private $mNoUpdates = false;
+       /** @var Config */
+       private $config;
 
        /**
         * Creates an ImportXMLReader drawing from the source provided
         * @param ImportStreamSource $source
+        * @param Config $config
         */
-       function __construct( ImportStreamSource $source ) {
+       function __construct( ImportStreamSource $source, Config $config = null ) {
                $this->reader = new XMLReader();
+               if ( !$config ) {
+                       wfDeprecated( __METHOD__ . ' without a Config instance', '1.25' );
+                       $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+               }
+               $this->config = $config;
 
                if ( !in_array( 'uploadsource', stream_get_wrappers() ) ) {
                        stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' );
@@ -429,53 +437,12 @@ class WikiImporter {
                return '';
        }
 
-       # --------------
-
-       /** Left in for debugging */
-       private function dumpElement() {
-               static $lookup = null;
-               if ( !$lookup ) {
-                       $xmlReaderConstants = array(
-                               "NONE",
-                               "ELEMENT",
-                               "ATTRIBUTE",
-                               "TEXT",
-                               "CDATA",
-                               "ENTITY_REF",
-                               "ENTITY",
-                               "PI",
-                               "COMMENT",
-                               "DOC",
-                               "DOC_TYPE",
-                               "DOC_FRAGMENT",
-                               "NOTATION",
-                               "WHITESPACE",
-                               "SIGNIFICANT_WHITESPACE",
-                               "END_ELEMENT",
-                               "END_ENTITY",
-                               "XML_DECLARATION",
-                       );
-                       $lookup = array();
-
-                       foreach ( $xmlReaderConstants as $name ) {
-                               $lookup[constant( "XmlReader::$name" )] = $name;
-                       }
-               }
-
-               print var_dump(
-                       $lookup[$this->reader->nodeType],
-                       $this->reader->name,
-                       $this->reader->value
-               ) . "\n\n";
-       }
-
        /**
         * Primary entry point
         * @throws MWException
         * @return bool
         */
        public function doImport() {
-
                // Calls to reader->read need to be wrapped in calls to
                // libxml_disable_entity_loader() to avoid local file
                // inclusion attacks (bug 46932).
@@ -577,7 +544,7 @@ class WikiImporter {
         * @return bool|mixed
         */
        private function processLogItem( $logInfo ) {
-               $revision = new WikiRevision;
+               $revision = new WikiRevision( $this->config );
 
                $revision->setID( $logInfo['id'] );
                $revision->setType( $logInfo['type'] );
@@ -711,7 +678,7 @@ class WikiImporter {
         * @return bool|mixed
         */
        private function processRevision( $pageInfo, $revisionInfo ) {
-               $revision = new WikiRevision;
+               $revision = new WikiRevision( $this->config );
 
                if ( isset( $revisionInfo['id'] ) ) {
                        $revision->setID( $revisionInfo['id'] );
@@ -827,7 +794,7 @@ class WikiImporter {
         * @return mixed
         */
        private function processUpload( $pageInfo, $uploadInfo ) {
-               $revision = new WikiRevision;
+               $revision = new WikiRevision( $this->config );
                $text = isset( $uploadInfo['text'] ) ? $uploadInfo['text'] : '';
 
                $revision->setTitle( $pageInfo['_title'] );
@@ -888,8 +855,6 @@ class WikiImporter {
         * @return array|bool
         */
        private function processTitle( $text ) {
-               global $wgCommandLineMode;
-
                $workTitle = $text;
                $origTitle = Title::newFromText( $workTitle );
 
@@ -905,6 +870,7 @@ class WikiImporter {
                        $title = Title::newFromText( $workTitle );
                }
 
+               $commandLineMode = $this->config->get( 'CommandLineMode' );
                if ( is_null( $title ) ) {
                        # Invalid page title? Ignore the page
                        $this->notice( 'import-error-invalid', $workTitle );
@@ -915,11 +881,11 @@ class WikiImporter {
                } elseif ( !$title->canExist() ) {
                        $this->notice( 'import-error-special', $title->getPrefixedText() );
                        return false;
-               } elseif ( !$title->userCan( 'edit' ) && !$wgCommandLineMode ) {
+               } elseif ( !$title->userCan( 'edit' ) && !$commandLineMode ) {
                        # Do not import if the importing wiki user cannot edit this page
                        $this->notice( 'import-error-edit', $title->getPrefixedText() );
                        return false;
-               } elseif ( !$title->exists() && !$title->userCan( 'create' ) && !$wgCommandLineMode ) {
+               } elseif ( !$title->exists() && !$title->userCan( 'create' ) && !$commandLineMode ) {
                        # Do not import if the importing wiki user cannot create this page
                        $this->notice( 'import-error-create', $title->getPrefixedText() );
                        return false;
@@ -932,7 +898,7 @@ class WikiImporter {
 /** This is a horrible hack used to keep source compatibility */
 class UploadSourceAdapter {
        /** @var array */
-       private static $sourceRegistrations = array();
+       public static $sourceRegistrations = array();
 
        /** @var string */
        private $mSource;
@@ -1056,13 +1022,13 @@ class UploadSourceAdapter {
  */
 class WikiRevision {
        /** @todo Unused? */
-       private $importer = null;
+       public $importer = null;
 
        /** @var Title */
        public $title = null;
 
        /** @var int */
-       private $id = 0;
+       public $id = 0;
 
        /** @var string */
        public $timestamp = "20010115000000";
@@ -1076,10 +1042,10 @@ class WikiRevision {
        public $user_text = "";
 
        /** @var string */
-       protected $model = null;
+       public $model = null;
 
        /** @var string */
-       protected $format = null;
+       public $format = null;
 
        /** @var string */
        public $text = "";
@@ -1088,7 +1054,7 @@ class WikiRevision {
        protected $size;
 
        /** @var Content */
-       protected $content = null;
+       public $content = null;
 
        /** @var ContentHandler */
        protected $contentHandler = null;
@@ -1097,31 +1063,31 @@ class WikiRevision {
        public $comment = "";
 
        /** @var bool */
-       protected $minor = false;
+       public $minor = false;
 
        /** @var string */
-       protected $type = "";
+       public $type = "";
 
        /** @var string */
-       protected $action = "";
+       public $action = "";
 
        /** @var string */
-       protected $params = "";
+       public $params = "";
 
        /** @var string */
-       protected $fileSrc = '';
+       public $fileSrc = '';
 
        /** @var bool|string */
-       protected $sha1base36 = false;
+       public $sha1base36 = false;
 
        /**
         * @var bool
         * @todo Unused?
         */
-       private $isTemp = false;
+       public $isTemp = false;
 
        /** @var string */
-       protected $archiveName = '';
+       public $archiveName = '';
 
        protected $filename;
 
@@ -1129,11 +1095,18 @@ class WikiRevision {
        protected $src;
 
        /** @todo Unused? */
-       private $fileIsTemp;
+       public $fileIsTemp;
 
        /** @var bool */
        private $mNoUpdates = false;
 
+       /** @var Config $config */
+       private $config;
+
+       public function __construct( Config $config ) {
+               $this->config = $config;
+       }
+
        /**
         * @param Title $title
         * @throws MWException
@@ -1535,9 +1508,6 @@ class WikiRevision {
                return true;
        }
 
-       /**
-        * @return mixed
-        */
        function importLogItem() {
                $dbw = wfGetDB( DB_MASTER );
                # @todo FIXME: This will not record autoblocks
@@ -1652,8 +1622,7 @@ class WikiRevision {
         * @return bool|string
         */
        function downloadSource() {
-               global $wgEnableUploads;
-               if ( !$wgEnableUploads ) {
+               if ( !$this->config->get( 'EnableUploads' ) ) {
                        return false;
                }