diff options
Diffstat (limited to 'includes/Import.php')
-rw-r--r-- | includes/Import.php | 144 |
1 files changed, 111 insertions, 33 deletions
diff --git a/includes/Import.php b/includes/Import.php index 480239fe..bb5d6349 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -225,7 +225,7 @@ class WikiImporter { } else { // set namespace to 'all', so the namespace check in processTitle() can passed $this->setTargetNamespace( null ); - $this->mTargetRootPage = $title->getPrefixedDBKey(); + $this->mTargetRootPage = $title->getPrefixedDBkey(); } } } @@ -252,8 +252,16 @@ class WikiImporter { * @return bool */ public function importRevision( $revision ) { - $dbw = wfGetDB( DB_MASTER ); - return $dbw->deadlockLoop( array( $revision, 'importOldRevision' ) ); + try { + $dbw = wfGetDB( DB_MASTER ); + return $dbw->deadlockLoop( array( $revision, 'importOldRevision' ) ); + } catch ( MWContentSerializationException $ex ) { + $this->notice( 'import-error-unserialize', + $revision->getTitle()->getPrefixedText(), + $revision->getID(), + $revision->getModel(), + $revision->getFormat() ); + } } /** @@ -322,8 +330,8 @@ class WikiImporter { * @param $title Title * @param $origTitle Title * @param $revCount Integer - * @param $sucCount Int: number of revisions for which callback returned true - * @param $pageInfo Array: associative array of page information + * @param int $sucCount number of revisions for which callback returned true + * @param array $pageInfo associative array of page information */ private function pageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ) { if( isset( $this->mPageOutCallback ) ) { @@ -392,7 +400,7 @@ class WikiImporter { /** Left in for debugging */ private function dumpElement() { static $lookup = null; - if (!$lookup) { + if ( !$lookup ) { $xmlReaderConstants = array( "NONE", "ELEMENT", @@ -429,6 +437,7 @@ class WikiImporter { /** * Primary entry point + * @throws MWException * @return bool */ public function doImport() { @@ -441,7 +450,7 @@ class WikiImporter { if ( $this->reader->name != 'mediawiki' ) { libxml_disable_entity_loader( $oldDisable ); - throw new MWException( "Expected <mediawiki> tag, got " . + throw new MWException( "Expected <mediawiki> tag, got ". $this->reader->name ); } $this->debug( "<mediawiki> tag is correct." ); @@ -470,7 +479,7 @@ class WikiImporter { $skip = true; } - if ($skip) { + if ( $skip ) { $keepReading = $this->reader->next(); $skip = false; $this->debug( "Skip" ); @@ -507,7 +516,7 @@ class WikiImporter { while ( $this->reader->read() ) { if ( $this->reader->nodeType == XmlReader::END_ELEMENT && - $this->reader->name == 'logitem') { + $this->reader->name == 'logitem' ) { break; } @@ -570,7 +579,7 @@ class WikiImporter { while ( $skip ? $this->reader->next() : $this->reader->read() ) { if ( $this->reader->nodeType == XmlReader::END_ELEMENT && - $this->reader->name == 'page') { + $this->reader->name == 'page' ) { break; } @@ -618,13 +627,13 @@ class WikiImporter { $this->debug( "Enter revision handler" ); $revisionInfo = array(); - $normalFields = array( 'id', 'timestamp', 'comment', 'minor', 'text' ); + $normalFields = array( 'id', 'timestamp', 'comment', 'minor', 'model', 'format', 'text' ); $skip = false; while ( $skip ? $this->reader->next() : $this->reader->read() ) { if ( $this->reader->nodeType == XmlReader::END_ELEMENT && - $this->reader->name == 'revision') { + $this->reader->name == 'revision' ) { break; } @@ -663,6 +672,12 @@ class WikiImporter { if ( isset( $revisionInfo['text'] ) ) { $revision->setText( $revisionInfo['text'] ); } + if ( isset( $revisionInfo['model'] ) ) { + $revision->setModel( $revisionInfo['model'] ); + } + if ( isset( $revisionInfo['format'] ) ) { + $revision->setFormat( $revisionInfo['format'] ); + } $revision->setTitle( $pageInfo['_title'] ); if ( isset( $revisionInfo['timestamp'] ) ) { @@ -704,7 +719,7 @@ class WikiImporter { while ( $skip ? $this->reader->next() : $this->reader->read() ) { if ( $this->reader->nodeType == XmlReader::END_ELEMENT && - $this->reader->name == 'upload') { + $this->reader->name == 'upload' ) { break; } @@ -801,7 +816,7 @@ class WikiImporter { while ( $this->reader->read() ) { if ( $this->reader->nodeType == XmlReader::END_ELEMENT && - $this->reader->name == 'contributor') { + $this->reader->name == 'contributor' ) { break; } @@ -889,7 +904,7 @@ class UploadSourceAdapter { * @return bool */ function stream_open( $path, $mode, $options, &$opened_path ) { - $url = parse_url($path); + $url = parse_url( $path ); $id = $url['host']; if ( !isset( self::$sourceRegistrations[$id] ) ) { @@ -910,22 +925,22 @@ class UploadSourceAdapter { $leave = false; while ( !$leave && !$this->mSource->atEnd() && - strlen($this->mBuffer) < $count ) { + strlen( $this->mBuffer ) < $count ) { $read = $this->mSource->readChunk(); - if ( !strlen($read) ) { + if ( !strlen( $read ) ) { $leave = true; } $this->mBuffer .= $read; } - if ( strlen($this->mBuffer) ) { + if ( strlen( $this->mBuffer ) ) { $return = substr( $this->mBuffer, 0, $count ); $this->mBuffer = substr( $this->mBuffer, $count ); } - $this->mPosition += strlen($return); + $this->mPosition += strlen( $return ); return $return; } @@ -1015,7 +1030,10 @@ class WikiRevision { var $timestamp = "20010115000000"; var $user = 0; var $user_text = ""; + var $model = null; + var $format = null; var $text = ""; + var $content = null; var $comment = ""; var $minor = false; var $type = ""; @@ -1072,6 +1090,20 @@ class WikiRevision { } /** + * @param $model + */ + function setModel( $model ) { + $this->model = $model; + } + + /** + * @param $format + */ + function setFormat( $format ) { + $this->format = $format; + } + + /** * @param $text */ function setText( $text ) { @@ -1194,12 +1226,55 @@ class WikiRevision { /** * @return string + * + * @deprecated Since 1.21, use getContent() instead. */ function getText() { + ContentHandler::deprecated( __METHOD__, '1.21' ); + return $this->text; } /** + * @return Content + */ + function getContent() { + if ( is_null( $this->content ) ) { + $this->content = + ContentHandler::makeContent( + $this->text, + $this->getTitle(), + $this->getModel(), + $this->getFormat() + ); + } + + return $this->content; + } + + /** + * @return String + */ + function getModel() { + if ( is_null( $this->model ) ) { + $this->model = $this->getTitle()->getContentModel(); + } + + return $this->model; + } + + /** + * @return String + */ + function getFormat() { + if ( is_null( $this->model ) ) { + $this->format = ContentHandler::getForTitle( $this->getTitle() )->getDefaultFormat(); + } + + return $this->format; + } + + /** * @return string */ function getComment() { @@ -1322,7 +1397,7 @@ class WikiRevision { array( 'rev_page' => $pageId, 'rev_timestamp' => $dbw->timestamp( $this->timestamp ), 'rev_user_text' => $userText, - 'rev_comment' => $this->getComment() ), + 'rev_comment' => $this->getComment() ), __METHOD__ ); if( $prior ) { @@ -1337,12 +1412,15 @@ class WikiRevision { # @todo FIXME: Use original rev_id optionally (better for backups) # Insert the row $revision = new Revision( array( - 'page' => $pageId, - 'text' => $this->getText(), - 'comment' => $this->getComment(), - 'user' => $userId, - 'user_text' => $userText, - 'timestamp' => $this->timestamp, + 'title' => $this->title, + 'page' => $pageId, + 'content_model' => $this->getModel(), + 'content_format' => $this->getFormat(), + 'text' => $this->getContent()->serialize( $this->getFormat() ), //XXX: just set 'content' => $this->getContent()? + 'comment' => $this->getComment(), + 'user' => $userId, + 'user_text' => $userText, + 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor, ) ); $revision->insertOn( $dbw ); @@ -1371,13 +1449,13 @@ class WikiRevision { // @todo FIXME: Use original log ID (better for backups) $prior = $dbw->selectField( 'logging', '1', array( 'log_type' => $this->getType(), - 'log_action' => $this->getAction(), + 'log_action' => $this->getAction(), 'log_timestamp' => $dbw->timestamp( $this->timestamp ), 'log_namespace' => $this->getTitle()->getNamespace(), - 'log_title' => $this->getTitle()->getDBkey(), - 'log_comment' => $this->getComment(), + 'log_title' => $this->getTitle()->getDBkey(), + 'log_comment' => $this->getComment(), #'log_user_text' => $this->user_text, - 'log_params' => $this->params ), + 'log_params' => $this->params ), __METHOD__ ); // @todo FIXME: This could fail slightly for multiple matches :P @@ -1460,7 +1538,7 @@ class WikiRevision { } if ( $status->isGood() ) { - wfDebug( __METHOD__ . ": Succesful\n" ); + wfDebug( __METHOD__ . ": Successful\n" ); return true; } else { wfDebug( __METHOD__ . ': failed: ' . $status->getXml() . "\n" ); @@ -1575,11 +1653,11 @@ class ImportStreamSource { static function newFromUpload( $fieldname = "xmlimport" ) { $upload =& $_FILES[$fieldname]; - if( !isset( $upload ) || !$upload['name'] ) { + if( $upload === null || !$upload['name'] ) { return Status::newFatal( 'importnofile' ); } if( !empty( $upload['error'] ) ) { - switch($upload['error']){ + switch( $upload['error'] ) { case 1: # The uploaded file exceeds the upload_max_filesize directive in php.ini. return Status::newFatal( 'importuploaderrorsize' ); case 2: # The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. |