3 function wfSpecialExport( $page = "" ) {
4 global $wgOut, $wgLang;
6 if( $_REQUEST['action'] == 'submit') {
7 $page = $_REQUEST['pages'];
8 $curonly = isset($_REQUEST['curonly']) ?
true : false;
14 header( "Content-type: application/xml; charset=utf-8" );
15 $pages = explode( "\n", $page );
16 $xml = pages2xml( $pages, $curonly );
21 $wgOut->addWikiText( wfMsg( "exporttext" ) );
22 $action = wfLocalUrlE( $wgLang->SpecialPage( "Export" ) );
24 <form method='post' action=\"$action\">
25 <input type='hidden' name='action' value='submit' />
26 <textarea name='pages' cols='40' rows='10'></textarea><br />
27 <label><input type='checkbox' name='curonly' value='true' checked />
28 " . wfMsg( "exportcuronly" ) . "</label><br />
29 <input type='submit' />
34 function pages2xml( $pages, $curonly = false ) {
35 global $wgLanguageCode, $wgInputEncoding, $wgLang;
36 $xml = "<" . "?xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n" .
37 "<mediawiki version=\"0.1\" xml:lang=\"$wgLanguageCode\">\n";
38 foreach( $pages as $page ) {
39 $xml .= page2xml( $page, $curonly );
41 $xml .= "</mediawiki>\n";
42 if($wgInputEncoding != "utf-8")
43 $xml = $wgLang->iconv( $wgInputEncoding, "utf-8", $xml );
47 function page2xml( $page, $curonly, $full = false ) {
48 global $wgInputCharset, $wgLang;
49 $title = Title
::NewFromText( $page );
50 if( !$title ) return "";
51 $t = wfStrencode( $title->getDBKey() );
52 $ns = $title->getNamespace();
53 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
54 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
55 "WHERE cur_namespace=$ns AND cur_title='$t'";
56 $res = wfQuery( $sql, DB_READ
);
57 if( $s = wfFetchObject( $res ) ) {
58 $tl = htmlspecialchars( $title->getPrefixedText() );
60 $xml .= " <title>$tl</title>\n";
62 $xml .= " <id>$s->id</id>\n";
64 if( $s->restrictions
) {
65 $xml .= " <restrictions>$s->restrictions</restrictions>\n";
68 $sql = "SELECT old_id as id,old_timestamp as timestamp, old_user as user, old_user_text as user_text," .
69 "old_comment as comment, old_text as text FROM old " .
70 "WHERE old_namespace=$ns AND old_title='$t' ORDER BY old_timestamp";
71 $res = wfQuery( $sql, DB_READ
);
73 while( $s2 = wfFetchObject( $res ) ) {
74 $xml .= revision2xml( $s2, $full, false );
77 $xml .= revision2xml( $s, $full, true );
85 function revision2xml( $s, $full, $cur ) {
86 $ts = wfTimestamp2ISO8601( $s->timestamp
);
87 $xml = " <revision>\n";
89 $xml .= " <id>$s->id</id>\n";
90 $xml .= " <timestamp>$ts</timestamp>\n";
92 $u = "<username>" . htmlspecialchars( $s->user_text
) . "</username>";
94 $u .= "<id>$s->user</id>";
96 $u = "<ip>" . htmlspecialchars( $s->user_text
) . "</ip>";
98 $xml .= " <contributor>$u</contributor>\n";
100 $xml .= " <minor/>\n";
102 if($s->comment
!= "") {
103 $c = htmlspecialchars( $s->comment
);
104 $xml .= " <comment>$c</comment>\n";
106 $t = htmlspecialchars( $s->text
);
107 $xml .= " <text>$t</text>\n";
108 $xml .= " </revision>\n";
112 function wfTimestamp2ISO8601( $ts ) {
113 #2003-08-05T18:30:02Z
114 return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts );