changed git call from https to git readonly
[atutor.git] / mods / wiki / tools / t_sync.php
1 <?php
2 /*
3    Provides syncing (or simply transfering) pages with a remote Wiki
4    installation, via special RPCs or open Wiki XML-RPC interface - in
5    future.
6 */
7
8 #-- load libs
9 define("WIKISYNC_VER", 0.1);
10 #$_SERVER["SERVER_NAME"] .= " {.-prevents-readonly-test-account}";
11 include("t_config.php");
12 if (!function_exists("xmlrpc")) include("plugins/lib/xmlrpc.php");
13 if (!function_exists("phprpc")) include("plugins/lib/phprpc.php");
14 if (!function_exists("ewiki_sync_local")) include("plugins/lib/sync.php");
15
16 #-- serve XML-RPC and PHP-RPC requests
17 header("X-WikiSync: " . WIKISYNC_VER);
18 $ewiki_config["ua"] .= " WikiSync/".WIKISYNC_VER;
19 if ($_SERVER["REQUEST_METHOD"] != "GET") {
20    $phprpc_methods =
21    $xmlrpc_methods =
22    array(
23       "ewiki_db" => "ewiki_db",
24       "ewiki.sync" => "ewiki_sync_local",
25    );
26    phprpc_server();
27    xmlrpc_server();
28    die("Request Missed.");
29 }
30
31 #-- start
32 $action = $_REQUEST["action"];
33 $proto = $_REQUEST["proto"];
34 $url = $_REQUEST["url"];
35 if ($url) {  // save as preference
36   setcookie("last_sync_url", $url, time() + 90*24*60*60, dirname($_SERVER["REQUEST_URI"]));
37 }
38
39 ?>
40 <html>
41 <head>
42  <title>syncing with remote wiki database</title>
43  <link rel="stylesheet" type="text/css" href="t_config.css">
44 </head>
45 <body bgcolor="#ffffff" text="#000000">
46 <h1>WikiSync&trade;</h1>
47
48 <?php
49
50 // error_reporting(E_ALL);
51   if (!action || !$proto || !$url) {
52
53 ?>
54 This tool allows you to maintain some pages of a public Wiki in a separate
55 installation but keep both synchronized. You of course must have the sync
56 interface installed on both systems (or at least have the XML-RPC service
57 enabled on the other site).
58
59 <br>
60 <br>
61
62 There is currently no conflict resolution code built-in, so you have to
63 correct these yourself, whenever you edited a page that also was edited
64 (by someone else) on the remote WikiWikiWeb server. So this is very safe
65 as it never overwrites stuff, and quick as it typically only copies the
66 latest version of every page.
67
68 <br>
69 <br>
70
71 <form action="t_sync.php" method="GET">
72   <label for="proto">protocol</label>
73   <select id="proto" name="proto">
74     <option value="sync">WikiSync&trade; <?php echo WIKISYNC_VER; ?></option>
75     <option value="db">ewiki_db::RPC</option>
76     <option value="wiki">WikiXmlRpc v2</option>
77   </select>
78   <br>
79   <label for="url">interface</label>
80   <input type="text" name="url" id="url" size="48" value="<?php
81      if ($url = $_COOKIE["last_sync_url"]) {
82         echo $url;
83      }
84      else {
85         echo "http://user:password@" . strtok($_SERVER["SERVER_NAME"], " ") . $_SERVER["REQUEST_URI"];
86      }
87   ?>">
88   <br>
89   <small>
90      Must be either the URL to a remote <tt>z.php</tt> script or better
91      to a remote <tt>t_sync.php</tt>.
92   </small>
93   <br>
94   <br>
95   <select id="action" name="action" title="action">
96     <option value="sync">sync</option>
97     <option value="up">upload</option>
98     <option value="down">download</option>
99     <option value="exact">exact</option>
100   </select>
101   <!-- ... -->
102   <input type="submit" value="transfer">
103 </form>
104 <?php
105
106
107
108  }
109
110  #-- minimal checks beforehand ------------------------------------------
111  elseif ($proto != "sync") {
112
113     echo "Sorry, currently only the WikiSync&trade; protocol is supported.";
114
115  }
116
117  #-- get list of (remotely) existing page versions
118  elseif (! ($ls_remote = ewiki_sync_remote("::LIST")) ) {
119
120     echo "No '$proto'-connection to '$url' could be established.";
121
122  }
123
124  
125  #-- perform sync -------------------------------------------------------
126  else {
127
128     #-- init
129     set_time_limit(+2999);
130     $ls_local = ewiki_sync_local("::LIST", false);
131     $sync = ($action=="sync");
132     $correct = 1;
133
134     #-- info
135     echo "<i>info</i>: " . count($locall) . " pages found in local Wiki database<br>\n";
136     echo "&nbsp; &nbsp; &nbsp; and " . count($rlist) . " are on remote server<br>\n";
137     echo "\n\n";
138     flush();
139
140
141     #-- upload
142     if (in_array($action, array("upload", "sync", "exact"))) {
143        echo "<br>\n<h3>upload</h3>\n";
144        ewiki_sync_start(
145           "upload",
146           $ls_local, $ls_remote,
147           "ewiki_sync_local", "ewiki_sync_remote"
148        );
149     }
150
151     #-- download
152     if (in_array($action, array("download", "sync", "exact"))) {
153        echo "<br>\n<h3>download</h3>\n";
154        ewiki_sync_start(
155           "download",
156           $ls_remote, $ls_local,
157           "ewiki_sync_remote", "ewiki_sync_local"
158        );
159     }
160     
161     #-- do an in-deepth analyzation of remaining files
162     if ($action == "exact") {
163        echo "<br>\n<h3>sync - exact comparison</h3>\n";
164        foreach ($ls_local as $id=>$ver) {
165           if ($ls_remote[$id] == $ver) {
166
167              echo htmlentities($id);
168              flush();
169
170              $L = ewiki_sync_local("::GET", array($id));
171              $R = ewiki_sync_remote("::GET", array($id));
172              
173              if (!ewiki_sync_half_identical($L, $R)) {
174                 echo " - conflict";
175              }
176              else {
177                 echo " - ok";
178              }
179              echo "<br>\n";
180           }
181        }
182     }
183
184
185
186     
187  
188  }
189
190
191 ?>
192 <br>
193 <br>
194 </body>
195 </html>