exit()
[lhc/web/wiklou.git] / includes / SpecialExport.php
1 <?
2
3 function wfSpecialExport( $page = "" ) {
4 global $wgOut, $wgLang;
5
6 if( $_REQUEST['action'] == 'submit') {
7 $page = $_REQUEST['pages'];
8 $curonly = isset($_REQUEST['curonly']) ? true : false;
9 } else {
10 $curonly = true;
11 }
12
13 if( $page != "" ) {
14 header( "Content-type: application/xml; charset=utf-8" );
15 $pages = explode( "\n", $page );
16 $xml = pages2xml( $pages, $curonly );
17 echo $xml;
18 exit();
19 }
20
21 $wgOut->addWikiText( wfMsg( "exporttext" ) );
22 $action = wfLocalUrlE( $wgLang->SpecialPage( "Export" ) );
23 $wgOut->addHTML( "
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' />
30 </form>
31 " );
32 }
33
34 function pages2xml( $pages, $curonly = false ) {
35 global $wgLanguageCode, $wgInputEncoding, $wgLang;
36 $xml = "<mediawiki version=\"0.1\" xml:ns=\"$wgLanguageCode\">\n";
37 foreach( $pages as $page ) {
38 $xml .= page2xml( $page, $curonly );
39 }
40 $xml .= "</mediawiki>\n";
41 if($wgInputEncoding != "utf-8")
42 $xml = $wgLang->iconv( $wgInputEncoding, "utf-8", $xml );
43 return $xml;
44 }
45
46 function page2xml( $page, $curonly, $full = false ) {
47 global $wgInputCharset, $wgLang;
48 $title = Title::NewFromText( $page );
49 $t = wfStrencode( $title->getDBKey() );
50 $ns = $title->getNamespace();
51 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
52 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
53 "WHERE cur_namespace=$ns AND cur_title='$t'";
54 $res = wfQuery( $sql, DB_READ );
55 if( $s = wfFetchObject( $res ) ) {
56 $tl = htmlspecialchars( $title->getPrefixedText() );
57 $xml = " <page>\n";
58 $xml .= " <title>$tl</title>\n";
59 if( $full ) {
60 $xml .= " <id>$s->id</id>\n";
61 }
62 if( $s->restrictions ) {
63 $xml .= " <restrictions>$s->restrictions</restrictions>\n";
64 }
65 if( !$curonly ) {
66 $sql = "SELECT old_id as id,old_timestamp as timestamp, old_user as user, old_user_text as user_text," .
67 "old_comment as comment, old_text as text FROM old " .
68 "WHERE old_namespace=$ns AND old_title='$t' ORDER BY old_timestamp";
69 $res = wfQuery( $sql, DB_READ );
70
71 while( $s = wfFetchObject( $res ) ) {
72 $xml .= revision2xml( $s, $full, false );
73 }
74 }
75 $xml .= revision2xml( $s, $full, true );
76 $xml .= " </page>\n";
77 return $xml;
78 } else {
79 return "";
80 }
81 }
82
83 function revision2xml( $s, $full, $cur ) {
84 $ts = wfTimestamp2ISO8601( $s->timestamp );
85 $xml = " <revision>\n";
86 if($full && !$cur)
87 $xml .= " <id>$s->id</id>\n";
88 $xml .= " <timestamp>$ts</timestamp>\n";
89 if($s->user) {
90 $u = "<username>" . htmlspecialchars( $s->user_text ) . "</username>";
91 if($full)
92 $u .= "<id>$s->user</id>";
93 } else {
94 $u = "<ip>" . htmlspecialchars( $s->user_text ) . "</ip>";
95 }
96 $xml .= " <contributor>$u</contributor>\n";
97 if($s->minor) {
98 $xml .= " <minor/>\n";
99 }
100 if($s->comment != "") {
101 $c = htmlspecialchars( $s->comment );
102 $xml .= " <comment>$c</comment>\n";
103 }
104 $t = htmlspecialchars( $s->text );
105 $xml .= " <text>$t</text>\n";
106 $xml .= " </revision>\n";
107 return $xml;
108 }
109
110 function wfTimestamp2ISO8601( $ts ) {
111 #2003-08-05T18:30:02Z
112 return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts );
113 }
114
115 ?>