update relnotes
[lhc/web/wiklou.git] / includes / SpecialImport.php
index 9e15d90..10ab239 100644 (file)
@@ -19,8 +19,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 
 /**
@@ -142,7 +141,7 @@ function wfSpecialImport( $page = '' ) {
                        <tr>
                                <td></td>
                                <td>
-                                       Transfer pages into namespace: " .
+                                       " . wfMsgHtml( 'import-interwiki-namespace' ) . " " .
                                                HTMLnamespaceselector( $namespace, '' ) . "
                                </td>
                        </tr>
@@ -175,39 +174,41 @@ class ImportReporter {
                $wgOut->addHtml( "<ul>\n" );
        }
        
-       function reportPage( $title, $origTitle, $revisionCount ) {
+       function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
                global $wgOut, $wgUser, $wgLang, $wgContLang;
                
                $skin = $wgUser->getSkin();
                
                $this->mPageCount++;
                
-               $localCount = $wgLang->formatNum( $revisionCount );
-               $contentCount = $wgContLang->formatNum( $revisionCount );
+               $localCount = $wgLang->formatNum( $successCount );
+               $contentCount = $wgContLang->formatNum( $successCount );
                
                $wgOut->addHtml( "<li>" . $skin->makeKnownLinkObj( $title ) .
                        " " .
-                       wfMsgHtml( 'import-revision-count', $localCount ) .
+                       wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
                        "</li>\n" );
                
-               $log = new LogPage( 'import' );
-               if( $this->mIsUpload ) {
-                       $detail = wfMsgForContent( 'import-logentry-upload-detail',
-                               $contentCount );
-                       $log->addEntry( 'upload', $title, $detail );
-               } else {
-                       $interwiki = '[[:' . $this->mInterwiki . ':' .
-                               $origTitle->getPrefixedText() . ']]';
-                       $detail = wfMsgForContent( 'import-logentry-interwiki-detail',
-                               $contentCount, $interwiki );
-                       $log->addEntry( 'interwiki', $title, $detail );
+               if( $successCount > 0 ) {
+                       $log = new LogPage( 'import' );
+                       if( $this->mIsUpload ) {
+                               $detail = wfMsgForContent( 'import-logentry-upload-detail',
+                                       $contentCount );
+                               $log->addEntry( 'upload', $title, $detail );
+                       } else {
+                               $interwiki = '[[:' . $this->mInterwiki . ':' .
+                                       $origTitle->getPrefixedText() . ']]';
+                               $detail = wfMsgForContent( 'import-logentry-interwiki-detail',
+                                       $contentCount, $interwiki );
+                               $log->addEntry( 'interwiki', $title, $detail );
+                       }
+                       
+                       $comment = $detail; // quick
+                       $dbw = wfGetDB( DB_MASTER );
+                       $nullRevision = Revision::newNullRevision(
+                               $dbw, $title->getArticleId(), $comment, true );
+                       $nullRevision->insertOn( $dbw );
                }
-               
-               $comment = $detail; // quick
-               $dbw = wfGetDB( DB_MASTER );
-               $nullRevision = Revision::newNullRevision(
-                       $dbw, $title->getArticleId(), $comment, true );
-               $nullRevId = $nullRevision->insertOn( $dbw );
        }
        
        function close() {
@@ -221,8 +222,7 @@ class ImportReporter {
 
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 class WikiRevision {
        var $title = null;
@@ -238,7 +238,7 @@ class WikiRevision {
                if( is_object( $title ) ) {
                        $this->title = $title;
                } elseif( is_null( $title ) ) {
-                       throw new MWException( "WikiRevision given a null title in import." );
+                       throw new MWException( "WikiRevision given a null title in import. You may need to adjust \$wgLegalTitleChars." );
                } else {
                        throw new MWException( "WikiRevision given non-object title in import." );
                }
@@ -302,8 +302,7 @@ class WikiRevision {
        }
 
        function importOldRevision() {
-               $fname = "WikiImporter::importOldRevision";
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
 
                # Sneak a single revision into place
                $user = User::newFromName( $this->getUser() );
@@ -327,9 +326,17 @@ class WikiRevision {
                        $created = true;
                } else {
                        $created = false;
-               }
 
-               # FIXME: Check for exact conflicts
+                       $prior = Revision::loadFromTimestamp( $dbw, $this->title, $this->timestamp );
+                       if( !is_null( $prior ) ) {
+                               // FIXME: this could fail slightly for multiple matches :P
+                               wfDebug( __METHOD__ . ": skipping existing revision for [[" .
+                                       $this->title->getPrefixedText() . "]], timestamp " .
+                                       $this->timestamp . "\n" );
+                               return false;
+                       }
+               }
+               
                # FIXME: Use original rev_id optionally
                # FIXME: blah blah blah
 
@@ -353,13 +360,14 @@ class WikiRevision {
                if( $created ) {
                        wfDebug( __METHOD__ . ": running onArticleCreate\n" );
                        Article::onArticleCreate( $this->title );
-               } else {
-                       if( $changed ) {
-                               wfDebug( __METHOD__ . ": running onArticleEdit\n" );
-                               Article::onArticleEdit( $this->title );
-                       }
-               }
-               if( $created || $changed ) {
+                       
+                       wfDebug( __METHOD__ . ": running create updates\n" );
+                       $article->createUpdates( $revision );
+                       
+               } elseif( $changed ) {
+                       wfDebug( __METHOD__ . ": running onArticleEdit\n" );
+                       Article::onArticleEdit( $this->title );
+                       
                        wfDebug( __METHOD__ . ": running edit updates\n" );
                        $article->editUpdates(
                                $this->getText(),
@@ -376,8 +384,7 @@ class WikiRevision {
 
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 class WikiImporter {
        var $mSource = null;
@@ -498,8 +505,8 @@ class WikiImporter {
         * @private
         */
        function importRevision( &$revision ) {
-               $dbw =& wfGetDB( DB_MASTER );
-               $dbw->deadlockLoop( array( &$revision, 'importOldRevision' ) );
+               $dbw = wfGetDB( DB_MASTER );
+               return $dbw->deadlockLoop( array( &$revision, 'importOldRevision' ) );
        }
 
        /**
@@ -536,12 +543,13 @@ class WikiImporter {
         * @param Title $title
         * @param Title $origTitle
         * @param int $revisionCount
+        * @param int $successCount number of revisions for which callback returned true
         * @private
         */
-       function pageOutCallback( $title, $origTitle, $revisionCount ) {
+       function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) {
                if( is_callable( $this->mPageOutCallback ) ) {
                        call_user_func( $this->mPageOutCallback, $title, $origTitle,
-                               $revisionCount );
+                               $revisionCount, $successCount );
                }
        }
 
@@ -565,6 +573,7 @@ class WikiImporter {
                        xml_set_element_handler( $parser, "in_siteinfo", "out_siteinfo" );
                } elseif( $name == 'page' ) {
                        $this->workRevisionCount = 0;
+                       $this->workSuccessCount = 0;
                        xml_set_element_handler( $parser, "in_page", "out_page" );
                } else {
                        return $this->throwXMLerror( "Expected <page>, got <$name>" );
@@ -633,11 +642,12 @@ class WikiImporter {
                xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
 
                $this->pageOutCallback( $this->pageTitle, $this->origTitle,
-                       $this->workRevisionCount );
+                       $this->workRevisionCount, $this->workSuccessCount );
                
                $this->workTitle = null;
                $this->workRevision = null;
                $this->workRevisionCount = 0;
+               $this->workSuccessCount = 0;
                $this->pageTitle = null;
                $this->origTitle = null;
        }
@@ -728,11 +738,10 @@ class WikiImporter {
                }
                xml_set_element_handler( $parser, "in_page", "out_page" );
 
-               $out = call_user_func_array( $this->mRevisionCallback,
+               $ok = call_user_func_array( $this->mRevisionCallback,
                        array( &$this->workRevision, &$this ) );
-               if( !empty( $out ) ) {
-                       global $wgOut;
-                       $wgOut->addHTML( "<li>" . $out . "</li>\n" );
+               if( $ok ) {
+                       $this->workSuccessCount++;
                }
        }
 
@@ -762,7 +771,6 @@ class WikiImporter {
 
 }
 
-/** @package MediaWiki */
 class ImportStringSource {
        function ImportStringSource( $string ) {
                $this->mString = $string;
@@ -783,7 +791,6 @@ class ImportStringSource {
        }
 }
 
-/** @package MediaWiki */
 class ImportStreamSource {
        function ImportStreamSource( $handle ) {
                $this->mHandle = $handle;
@@ -797,7 +804,7 @@ class ImportStreamSource {
                return fread( $this->mHandle, 32768 );
        }
 
-       function newFromFile( $filename ) {
+       static function newFromFile( $filename ) {
                $file = @fopen( $filename, 'rt' );
                if( !$file ) {
                        return new WikiErrorMsg( "importcantopen" );
@@ -805,7 +812,7 @@ class ImportStreamSource {
                return new ImportStreamSource( $file );
        }
 
-       function newFromUpload( $fieldname = "xmlimport" ) {
+       static function newFromUpload( $fieldname = "xmlimport" ) {
                $upload =& $_FILES[$fieldname];
 
                if( !isset( $upload ) || !$upload['name'] ) {
@@ -831,10 +838,9 @@ class ImportStreamSource {
                return $ret;
        }
 
-       function newFromInterwiki( $interwiki, $page, $history=false ) {
-               $base = Title::getInterwikiLink( $interwiki );
+       public static function newFromInterwiki( $interwiki, $page, $history=false ) {
                $link = Title::newFromText( "$interwiki:Special:Export/$page" );
-               if( empty( $base ) || empty( $link ) ) {
+               if( is_null( $link ) || $link->getInterwiki() == '' ) {
                        return new WikiErrorMsg( 'importbadinterwiki' );
                } else {
                        $params = $history ? 'history=1' : '';