Squid branch merge. Calls to purge functions in Article.php and special pages.
[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 wfAbruptExit();
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 = "<" . "?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 );
40 }
41 $xml .= "</mediawiki>\n";
42 if($wgInputEncoding != "utf-8")
43 $xml = $wgLang->iconv( $wgInputEncoding, "utf-8", $xml );
44 return $xml;
45 }
46
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() );
59 $xml = " <page>\n";
60 $xml .= " <title>$tl</title>\n";
61 if( $full ) {
62 $xml .= " <id>$s->id</id>\n";
63 }
64 if( $s->restrictions ) {
65 $xml .= " <restrictions>$s->restrictions</restrictions>\n";
66 }
67 if( !$curonly ) {
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, old_flags as flags FROM old " .
70 "WHERE old_namespace=$ns AND old_title='$t' ORDER BY old_timestamp";
71 $res = wfQuery( $sql, DB_READ );
72
73 while( $s2 = wfFetchObject( $res ) ) {
74 $xml .= revision2xml( $s2, $full, false );
75 }
76 }
77 $xml .= revision2xml( $s, $full, true );
78 $xml .= " </page>\n";
79 return $xml;
80 } else {
81 return "";
82 }
83 }
84
85 function revision2xml( $s, $full, $cur ) {
86 $ts = wfTimestamp2ISO8601( $s->timestamp );
87 $xml = " <revision>\n";
88 if($full && !$cur)
89 $xml .= " <id>$s->id</id>\n";
90 $xml .= " <timestamp>$ts</timestamp>\n";
91 if($s->user) {
92 $u = "<username>" . htmlspecialchars( $s->user_text ) . "</username>";
93 if($full)
94 $u .= "<id>$s->user</id>";
95 } else {
96 $u = "<ip>" . htmlspecialchars( $s->user_text ) . "</ip>";
97 }
98 $xml .= " <contributor>$u</contributor>\n";
99 if($s->minor) {
100 $xml .= " <minor/>\n";
101 }
102 if($s->comment != "") {
103 $c = htmlspecialchars( $s->comment );
104 $xml .= " <comment>$c</comment>\n";
105 }
106 $t = htmlspecialchars( Article::getRevisionText( $s, "" ) );
107 $xml .= " <text>$t</text>\n";
108 $xml .= " </revision>\n";
109 return $xml;
110 }
111
112 function wfTimestamp2ISO8601( $ts ) {
113 #2003-08-05T18:30:02Z
114 return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts );
115 }
116
117 ?>