* Removed redudant global decleration
[lhc/web/wiklou.git] / includes / SpecialExport.php
index 1d517ca..1ce1f4f 100644 (file)
@@ -61,7 +61,7 @@ function wfSpecialExport( $page = '' ) {
 <input type='hidden' name='action' value='submit' />
 <textarea name='pages' cols='40' rows='10'></textarea><br />
 <label><input type='checkbox' name='curonly' value='true' checked='checked' />
-" . wfMsg( "exportcuronly" ) . "</label><br />
+" . wfMsgHtml( 'exportcuronly' ) . "</label><br />
 <input type='submit' />
 </form>
 " );
@@ -121,10 +121,18 @@ class WikiExporter {
         *
         * @param mixed $callback
         */
-       function setRevCallback( $callback ) {
+       function setRevisionCallback( $callback ) {
                $this->revCallback = $callback;
        }
        
+       /**
+        * Returns the export schema version.
+        * @return string
+        */
+       function schemaVersion() {
+               return "0.3";
+       }
+       
        /**
         * Opens the XML output stream's root <mediawiki> element.
         * This does not include an xml directive, so is safe to include
@@ -136,14 +144,62 @@ class WikiExporter {
         */
        function openStream() {
                global $wgContLanguageCode;
+               $ver = $this->schemaVersion();
                print wfElement( 'mediawiki', array(
-                       'xmlns'              => 'http://www.mediawiki.org/xml/export-0.1/',
-                       'xmlns:xsi'          => 'http://www.w3.org/2001/XMLSchema-instance',
-                       'xsi:schemaLocation' => 'http://www.mediawiki.org/xml/export-0.1/ ' .
-                                               'http://www.mediawiki.org/xml/export-0.1.xsd',
-                       'version'            => '0.1',
+                       'xmlns'              => "http://www.mediawiki.org/xml/export-$ver/",
+                       'xmlns:xsi'          => "http://www.w3.org/2001/XMLSchema-instance",
+                       'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
+                                               "http://www.mediawiki.org/xml/export-$ver.xsd",
+                       'version'            => $ver,
                        'xml:lang'           => $wgContLanguageCode ),
                        null ) . "\n";
+               $this->siteInfo();
+       }
+       
+       function siteInfo() {
+               $info = array(
+                       $this->sitename(),
+                       $this->homelink(),
+                       $this->generator(),
+                       $this->caseSetting(),
+                       $this->namespaces() );
+               print "<siteinfo>\n";
+               foreach( $info as $item ) {
+                       print "  $item\n";
+               }
+               print "</siteinfo>\n";
+       }
+       
+       function sitename() {
+               global $wgSitename;
+               return wfElement( 'sitename', array(), $wgSitename );
+       }
+       
+       function generator() {
+               global $wgVersion;
+               return wfElement( 'generator', array(), "MediaWiki $wgVersion" );
+       }
+       
+       function homelink() {
+               $page = Title::newFromText( wfMsgForContent( 'mainpage' ) );
+               return wfElement( 'base', array(), $page->getFullUrl() );
+       }
+       
+       function caseSetting() {
+               global $wgCapitalLinks;
+               // "case-insensitive" option is reserved for future
+               $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
+               return wfElement( 'case', array(), $sensitivity );
+       }
+       
+       function namespaces() {
+               global $wgContLang;
+               $spaces = "<namespaces>\n";
+               foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
+                       $spaces .= '    ' . wfElement( 'namespace', array( 'key' => $ns ), $title ) . "\n";
+               }
+               $spaces .= "  </namespaces>";
+               return $spaces;
        }
        
        /**
@@ -178,7 +234,7 @@ class WikiExporter {
        function pageByName( $name ) {
                $title = Title::newFromText( $name );
                if( is_null( $title ) ) {
-                       return WikiError( "Can't export invalid title" );
+                       return new WikiError( "Can't export invalid title" );
                } else {
                        return $this->pageByTitle( $title );
                }
@@ -214,10 +270,18 @@ class WikiExporter {
                if( $this->buffer == MW_EXPORT_STREAM ) {
                        $prev = $this->db->bufferResults( false );
                }
+               if( $cond == '' ) {
+                       // Optimization hack for full-database dump
+                       $pageindex = 'FORCE INDEX (PRIMARY)';
+                       $revindex = 'FORCE INDEX(page_timestamp)';
+               } else {
+                       $pageindex = '';
+                       $revindex = '';
+               }
                $result = $this->db->query(
                        "SELECT * FROM
-                               $page FORCE INDEX (PRIMARY),
-                               $revision FORCE INDEX(page_timestamp),
+                               $page $pageindex,
+                               $revision $revindex,
                                $text
                                WHERE $where $join AND rev_text_id=old_id
                                ORDER BY page_id", $fname );
@@ -308,31 +372,32 @@ class WikiExporter {
                $fname = 'WikiExporter::dumpRev';
                wfProfileIn( $fname );
                
-               print "    <revision>\n";
-               print "      " . wfElement( 'id', null, $row->rev_id ) . "\n";
+               print "  <revision>\n";
+               print "    " . wfElement( 'id', null, $row->rev_id ) . "\n";
                
                $ts = wfTimestamp2ISO8601( $row->rev_timestamp );
-               print "      " . wfElement( 'timestamp', null, $ts ) . "\n";
+               print "    " . wfElement( 'timestamp', null, $ts ) . "\n";
                
-               print "      <contributor>";
+               print "    <contributor>\n";
                if( $row->rev_user ) {
-                       print wfElementClean( 'username', null, $row->rev_user_text );
-                       print wfElement( 'id', null, $row->rev_user );
+                       print "      " . wfElementClean( 'username', null, $row->rev_user_text ) . "\n";
+                       print "      " . wfElement( 'id', null, $row->rev_user ) . "\n";
                } else {
-                       print wfElementClean( 'ip', null, $row->rev_user_text );
+                       print "      " . wfElementClean( 'ip', null, $row->rev_user_text ) . "\n";
                }
-               print "</contributor>\n";
+               print "    </contributor>\n";
                
                if( $row->rev_minor_edit ) {
-                       print  "      <minor/>\n";
+                       print  "    <minor/>\n";
                }
                if( $row->rev_comment != '' ) {
-                       print "      " . wfElementClean( 'comment', null, $row->rev_comment ) . "\n";
+                       print "    " . wfElementClean( 'comment', null, $row->rev_comment ) . "\n";
                }
        
                $text = Revision::getRevisionText( $row );
-               print "      " . wfElementClean( 'text', array(), $text ) . "\n";
-               print "    </revision>\n";
+               print "    " . wfElementClean( 'text', array( 'xml:space' => 'preserve' ), $text ) . "\n";
+               
+               print "  </revision>\n";
                
                wfProfileOut( $fname );