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