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 );
18 # exit(1) actually prints 1 in some PHP versions
22 $wgOut->addWikiText( wfMsg( "exporttext" ) );
23 $action = wfLocalUrlE( $wgLang->SpecialPage( "Export" ) );
25 <form method='post' action=\"$action\">
26 <input type='hidden' name='action' value='submit' />
27 <textarea name='pages' cols='40' rows='10'></textarea><br />
28 <label><input type='checkbox' name='curonly' value='true' checked />
29 " . wfMsg( "exportcuronly" ) . "</label><br />
30 <input type='submit' />
35 function pages2xml( $pages, $curonly = false ) {
36 global $wgLanguageCode, $wgInputEncoding, $wgLang;
37 $xml = "<mediawiki version=\"0.1\" xml:ns=\"$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 $t = wfStrencode( $title->getDBKey() );
51 $ns = $title->getNamespace();
52 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
53 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
54 "WHERE cur_namespace=$ns AND cur_title='$t'";
55 $res = wfQuery( $sql, DB_READ
);
56 if( $s = wfFetchObject( $res ) ) {
57 $tl = htmlspecialchars( $title->getPrefixedText() );
59 $xml .= " <title>$tl</title>\n";
61 $xml .= " <id>$s->id</id>\n";
63 if( $s->restrictions
) {
64 $xml .= " <restrictions>$s->restrictions</restrictions>\n";
67 $sql = "SELECT old_id as id,old_timestamp as timestamp, old_user as user, old_user_text as user_text," .
68 "old_comment as comment, old_text as text FROM old " .
69 "WHERE old_namespace=$ns AND old_title='$t' ORDER BY old_timestamp";
70 $res = wfQuery( $sql, DB_READ
);
72 while( $s = wfFetchObject( $res ) ) {
73 $xml .= revision2xml( $s, $full, false );
76 $xml .= revision2xml( $s, $full, true );
84 function revision2xml( $s, $full, $cur ) {
85 $ts = wfTimestamp2ISO8601( $s->timestamp
);
86 $xml = " <revision>\n";
88 $xml .= " <id>$s->id</id>\n";
89 $xml .= " <timestamp>$ts</timestamp>\n";
91 $u = "<username>" . htmlspecialchars( $s->user_text
) . "</username>";
93 $u .= "<id>$s->user</id>";
95 $u = "<ip>" . htmlspecialchars( $s->user_text
) . "</ip>";
97 $xml .= " <contributor>$u</contributor>\n";
99 $xml .= " <minor/>\n";
101 if($s->comment
!= "") {
102 $c = htmlspecialchars( $s->comment
);
103 $xml .= " <comment>$c</comment>\n";
105 $t = htmlspecialchars( $s->text
);
106 $xml .= " <text>$t</text>\n";
107 $xml .= " </revision>\n";
111 function wfTimestamp2ISO8601( $ts ) {
112 #2003-08-05T18:30:02Z
113 return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts );