Index: trunk/extensions/DSMW/DSMW_Settings.php |
— | — | @@ -0,0 +1,49 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @copyright INRIA-LORIA-ECOO project |
| 5 | + * @author jean-philippe muller |
| 6 | + */ |
| 7 | + |
| 8 | +# create namespace |
| 9 | +define( "PATCH", 110 ); |
| 10 | +define( "PUSHFEED", 200 ); |
| 11 | +define( "PULLFEED", 210 ); |
| 12 | +define( "CHANGESET", 220 ); |
| 13 | + |
| 14 | +$wgExtraNamespaces[PATCH] = "Patch"; |
| 15 | +$wgExtraNamespaces[PUSHFEED] = "PushFeed"; |
| 16 | +$wgExtraNamespaces[PULLFEED] = "PullFeed"; |
| 17 | +$wgExtraNamespaces[CHANGESET] = "ChangeSet"; |
| 18 | +# protect namespace |
| 19 | +$wgNamespaceProtection[PATCH] = Array( "editpatch" ); |
| 20 | +$wgNamespacesWithSubpages[PATCH] = true; |
| 21 | +$wgGroupPermissions['*']['editpatch'] = false; |
| 22 | +$wgGroupPermissions['sysop']['editpatch'] = true; |
| 23 | +$wgNamespaceProtection[PUSHFEED] = Array( "editpushfeed" ); |
| 24 | +$wgNamespacesWithSubpages[PUSHFEED] = true; |
| 25 | +$wgGroupPermissions['*']['editpushfeed'] = false; |
| 26 | +$wgGroupPermissions['sysop']['editpushfeed'] = true; |
| 27 | +$wgNamespaceProtection[PULLFEED] = Array( "editpullfeed" ); |
| 28 | +$wgNamespacesWithSubpages[PULLFEED] = true; |
| 29 | +$wgGroupPermissions['*']['editpullfeed'] = false; |
| 30 | +$wgGroupPermissions['sysop']['editpullfeed'] = true; |
| 31 | +$wgNamespaceProtection[CHANGESET] = Array( "editchangeset" ); |
| 32 | +$wgNamespacesWithSubpages[CHANGESET] = true; |
| 33 | +$wgGroupPermissions['*']['editchangeset'] = false; |
| 34 | +$wgGroupPermissions['sysop']['editchangeset'] = true; |
| 35 | + |
| 36 | + |
| 37 | +$wgGroupPermissions['*']['ArticleAdminPage'] = true;// sysop |
| 38 | +require_once( "$IP/extensions/DSMW/specialPage/ArticleAdminPage.php" ); |
| 39 | + |
| 40 | +$wgGroupPermissions['*']['DSMWAdmin'] = true;// sysop |
| 41 | +require_once( "$IP/extensions/DSMW/specialPage/DSMWAdmin.php" ); |
| 42 | + |
| 43 | +$wgGroupPermissions['*']['DSMWGeneralExhibits'] = true;// sysop |
| 44 | +require_once( "$IP/extensions/DSMW/specialPage/DSMWGeneralExhibits.php" ); |
| 45 | + |
| 46 | +// Simple forms extension |
| 47 | +include( "$IP/extensions/DSMW/SimpleForms/SimpleForms.php" ); |
| 48 | + |
| 49 | +// semantic mediawiki extension |
| 50 | +$smwgNamespaceIndex = 120; |
Property changes on: trunk/extensions/DSMW/DSMW_Settings.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 51 | + native |
Index: trunk/extensions/DSMW/patch/Patch.php |
— | — | @@ -197,4 +197,3 @@ |
198 | 198 | } |
199 | 199 | |
200 | 200 | } |
201 | | -?> |
Index: trunk/extensions/DSMW/DSMW.php |
— | — | @@ -1,12 +1,27 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
| 5 | + * Initialization file for the Distributed Semantic MediaWiki extension. |
| 6 | + * See https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Extension:DSMW |
| 7 | + * |
| 8 | + * @file DSMW.php |
| 9 | + * @ingroup DSMW |
| 10 | + * |
5 | 11 | * @copyright 2009 INRIA-LORIA-ECOO project |
| 12 | + * |
6 | 13 | * @author jean-philippe muller & Morel Émile |
7 | 14 | */ |
| 15 | + |
| 16 | +/** |
| 17 | + * This documenation group collects source code files belonging to DSMW. |
| 18 | + * |
| 19 | + * @defgroup DSMW Distributed Semantic MediaWiki |
| 20 | + */ |
| 21 | + |
8 | 22 | if ( !defined( 'MEDIAWIKI' ) ) { |
9 | | - exit; |
| 23 | + die( 'Not a valid entry point.' ); |
10 | 24 | } |
| 25 | + |
11 | 26 | require_once "$IP/includes/GlobalFunctions.php"; |
12 | 27 | $wgDSMWIP = dirname( __FILE__ ); |
13 | 28 | |
— | — | @@ -16,7 +31,7 @@ |
17 | 32 | require_once 'includes/SemanticFunctions.php'; |
18 | 33 | require_once 'includes/IntegrationFunctions.php'; |
19 | 34 | |
20 | | -define( 'DSMW_VERSION', '1.0' ); |
| 35 | +define( 'DSMW_VERSION', '1.1 alpha' ); |
21 | 36 | |
22 | 37 | $wgSpecialPageGroups['ArticleAdminPage'] = 'dsmw_group'; |
23 | 38 | $wgSpecialPageGroups['DSMWAdmin'] = 'dsmw_group'; |
— | — | @@ -96,706 +111,30 @@ |
97 | 112 | 'descriptionmsg' => 'dsmw-desc' |
98 | 113 | ); |
99 | 114 | |
| 115 | +$queryModules = array( |
| 116 | + 'patch' => 'ApiQueryPatch', |
| 117 | + 'changeSet' => 'ApiQueryChangeSet', |
| 118 | + 'patchPushed' => 'ApiPatchPush' |
| 119 | +); |
| 120 | + |
100 | 121 | if ( compareMWVersion( $wgVersion ) == -1 ) { |
101 | | - $wgApiQueryMetaModules = array( 'patch' => 'ApiQueryPatch', 'changeSet' => 'ApiQueryChangeSet', |
102 | | - 'patchPushed' => 'ApiPatchPush' ); |
| 122 | + $wgApiQueryMetaModules = $queryModules; |
103 | 123 | } else { |
104 | | - $wgAPIMetaModules = array( 'patch' => 'ApiQueryPatch', 'changeSet' => 'ApiQueryChangeSet', |
105 | | - 'patchPushed' => 'ApiPatchPush' ); |
| 124 | + $wgAPIMetaModules = $queryModules; |
106 | 125 | } |
| 126 | + |
107 | 127 | if ( compareMWVersion( $wgVersion, '1.16.0' ) == -1 ) { |
108 | | - $wgAPIModules = $wgAPIModules + array( 'upload' => 'ApiUpload', |
109 | | - 'ApiQueryImageInfo' => 'ApiQueryImageInfo', ); |
110 | | - $wgAutoloadLocalClasses = $wgAutoloadLocalClasses + array( |
111 | | - 'UploadBase' => $wgDSMWIP . '/api/upload/UploadBase.php', |
112 | | - 'UploadFromFile' => $wgDSMWIP . '/api/upload/UploadFromFile.php', |
113 | | - 'UploadFromStash' => $wgDSMWIP . '/api/upload/UploadFromStash.php', |
114 | | - 'UploadFromUrl' => $wgDSMWIP . '/api/upload/UploadFromUrl.php' ); |
| 128 | + $wgAPIModules += array( |
| 129 | + 'upload' => 'ApiUpload', |
| 130 | + 'ApiQueryImageInfo' => 'ApiQueryImageInfo', |
| 131 | + ); |
| 132 | + |
| 133 | + $wgAutoloadLocalClasses['UploadBase'] = dirname( __FILE__ ) . '/api/upload/UploadBase.php'; |
| 134 | + $wgAutoloadLocalClasses['UploadFromFile'] = dirname( __FILE__ ) . '/api/upload/UploadFromFile.php'; |
| 135 | + $wgAutoloadLocalClasses['UploadFromStash'] = dirname( __FILE__ ) . '/api/upload/UploadFromStash.php'; |
| 136 | + $wgAutoloadLocalClasses['UploadFromUrl'] = dirname( __FILE__ ) . '/api/upload/UploadFromUrl.php'; |
115 | 137 | } |
116 | | -define( 'INT_MAX', "1000000000000000000000" ); // 22 |
117 | | -define( 'INT_MIN', "0" ); |
118 | 138 | |
119 | | -function conflict( &$editor, &$out ) { |
120 | 139 | |
121 | | - $conctext = $editor->textbox1; |
122 | | - $actualtext = $editor->textbox2; |
123 | | - $initialtext = $editor->getBaseRevision()->mText; |
124 | | - $editor->mArticle->updateArticle( $actualtext, $editor->summary, $editor->minoredit, |
125 | | - $editor->watchthis, $bot = false, $sectionanchor = '' ); |
126 | 140 | |
127 | | - return true; |
128 | | -} |
129 | | - |
130 | | -// function performAction($output, $article, $title, $user, $request, $wiki) { |
131 | | -/// / $dbr = wfGetDB( DB_SLAVE ); |
132 | | -/// / $lastRevision = Revision::loadFromTitle($dbr, $title); |
133 | | -/// / $rawtext = $lastRevision->getRawText(); |
134 | | -// |
135 | | -// //$page = "The_angel's_game"; |
136 | | -// |
137 | | -// |
138 | | -/// / $page="Home"; |
139 | | -/// / $arrayres = utils::getDependencies($page, true, true, true, true); |
140 | | -/// / $test; |
141 | | -// |
142 | | -// global $wgRequest; |
143 | | -// $form = new UploadForm( $wgRequest ); |
144 | | -// $form->mDesiredDestName = 'Lego1.png'; |
145 | | -// $form->execute(); |
146 | | -// |
147 | | -// return true; |
148 | | -// } |
149 | | - |
150 | | -/** |
151 | | - * MW Hook used to redirect to page creation (pushfeed, pullfeed, changeset), |
152 | | - * to forms or to push/pull action testing the action param |
153 | | - * |
154 | | - * |
155 | | - * @global <Object> $wgOut |
156 | | - * @param <Object> $action |
157 | | - * @param <Object> $article |
158 | | - * @return <boolean> |
159 | | - */ |
160 | | -function onUnknownAction( $action, $article ) { |
161 | | - global $wgOut, $wgServerName, $wgScriptPath, $wgUser, $wgScriptExtension, $wgDSMWIP; |
162 | | - $urlServer = 'http://' . $wgServerName . $wgScriptPath . "/index{$wgScriptExtension}"; |
163 | | - $urlAjax = 'http://' . $wgServerName . $wgScriptPath; |
164 | | - ////////// pull form page//////// |
165 | | - if ( isset( $_GET['action'] ) && $_GET['action'] == 'addpullpage' ) { |
166 | | - wfDebugLog( 'p2p', 'addPullPage ' ); |
167 | | - $newtext = "Add a new site: |
168 | | -<div id='dsmw' style=\"color:green;\"></div> |
169 | | - |
170 | | -{{#form:action=" . $urlServer . "?action=pullpage|method=POST| |
171 | | -PushFeed Url: {{#input:type=button|value=Url test|onClick= |
172 | | -var url = document.getElementsByName('url')[0].value; |
173 | | -if(url.indexOf('PushFeed')==-1){ |
174 | | -alert('No valid PushFeed syntax, see example.'); |
175 | | -}else{ |
176 | | -var urlTmp = url.substring(0,url.indexOf('PushFeed')); |
177 | | -//alert(urlTmp); |
178 | | - |
179 | | -var pos1 = urlTmp.indexOf('index.php'); |
180 | | -//alert(pos1); |
181 | | -var pushUrl=''; |
182 | | -if(pos1!=-1){ |
183 | | -pushUrl = urlTmp.substring(0,pos1); |
184 | | -//alert('if'); |
185 | | -}else{ |
186 | | -pushUrl = urlTmp; |
187 | | -//alert('else'); |
188 | | -} |
189 | | -//alert(pushUrl); |
190 | | - |
191 | | -//alert(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml'); |
192 | | -var xhr_object = null; |
193 | | - |
194 | | - if(window.XMLHttpRequest) // Firefox |
195 | | - xhr_object = new XMLHttpRequest(); |
196 | | - else if(window.ActiveXObject) // Internet Explorer |
197 | | - xhr_object = new ActiveXObject('Microsoft.XMLHTTP'); |
198 | | - else { |
199 | | - alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest...'); |
200 | | - return; |
201 | | - } |
202 | | - try{ xhr_object.open('GET', '" . $urlAjax . "/extensions/DSMW/files/ajax.php?url='+escape(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml'), true);} |
203 | | - catch(e){ |
204 | | - //alert('There is no DSMW Server responding at this URL'); |
205 | | - document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!'; |
206 | | - document.getElementById('dsmw').style.color = 'red'; |
207 | | - } |
208 | | - xhr_object.onreadystatechange = function() { |
209 | | - |
210 | | -if(xhr_object.readyState == 4) { |
211 | | - if(xhr_object.statusText=='OK'){ |
212 | | - if(xhr_object.responseText == 'true'){ //alert('URL valid, there is a DSMW Server responding'); |
213 | | - document.getElementById('dsmw').innerHTML = 'URL valid, there is a DSMW Server responding!'; |
214 | | - document.getElementById('dsmw').style.color = 'green'; |
215 | | - } |
216 | | - else{ //alert('There is no DSMW Server responding at this URL'); |
217 | | - document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!'; |
218 | | - document.getElementById('dsmw').style.color = 'red'; |
219 | | - } |
220 | | - } |
221 | | - else{ |
222 | | - //alert('There is no DSMW Server responding at this URL'); |
223 | | - document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!'; |
224 | | - document.getElementById('dsmw').style.color = 'red'; |
225 | | -} |
226 | | - } |
227 | | - } |
228 | | - |
229 | | - xhr_object.send(null); |
230 | | -} |
231 | | -}}<br> {{#input:type=text|name=url|size=50}} <b>e.g. http://server/path/index.php?title=PushFeed:PushName</b><br> |
232 | | -PullFeed Name: <br> {{#input:type=text|name=pullname}}<br> |
233 | | -{{#input:type=submit|value=ADD}} |
234 | | -}}"; |
235 | | - |
236 | | - // if article doesn't exist insertNewArticle |
237 | | - if ( $article->mTitle->exists() ) { |
238 | | - $article->updateArticle( $newtext, $summary = "", false, false ); |
239 | | - } else { |
240 | | - $article->insertNewArticle( $newtext, $summary = "", false, false ); |
241 | | - } |
242 | | - $article->doRedirect(); |
243 | | - |
244 | | - return false; |
245 | | - } |
246 | | - |
247 | | - |
248 | | - ///////// push form page//////// |
249 | | - elseif ( isset( $_GET['action'] ) && $_GET['action'] == 'addpushpage' ) { |
250 | | - wfDebugLog( 'p2p', 'addPushPage' ); |
251 | | - $specialAsk = $urlServer . '?title=Special:Ask'; |
252 | | - $newtext = "Add a new pushfeed: |
253 | | - |
254 | | -{{#form:action=" . $urlServer . "?action=pushpage|method=POST| |
255 | | -PushFeed Name: <br> {{#input:class=test|name=name|type=text|onKeyUp=test('$urlServer');}}<div style=\"display:inline; \" id=\"state\" ></div><br /> |
256 | | -Request: {{#input:type=button|value=Test your query|title=click here to test your query results|onClick= |
257 | | -var query = document.getElementsByName('keyword')[0].value; |
258 | | -var query1 = encodeURI(query); |
259 | | -window.open('" . $specialAsk . "&q='+query1+'&eq=yes&p%5Bformat%5D=broadtable','querywindow','menubar=no, status=no, scrollbars=yes, menubar=no, width=1000, height=900');}} |
260 | | - <br>{{#input:type=textarea|cols=30 | style=width:auto |rows=2|name=keyword}} <b>e.g. [[Category:city]][[locatedIn::France]]</b><br> |
261 | | -{{#input:type=submit|value=ADD}} |
262 | | -}}"; |
263 | | - |
264 | | - $article->doEdit( $newtext, $summary = "" ); |
265 | | - $article->doRedirect(); |
266 | | - return false; |
267 | | - } |
268 | | - |
269 | | - |
270 | | - /////// PushFeed page//////// |
271 | | - elseif ( isset( $_GET['action'] ) && $_GET['action'] == 'pushpage' ) { |
272 | | - // $url = $_POST['url'];//pas url mais changesetId |
273 | | - wfDebugLog( 'p2p', 'Create new push ' . $_POST['name'] . ' with ' . $_POST['keyword'] ); |
274 | | - $name = $_POST['name']; |
275 | | - $request = $_POST['keyword']; |
276 | | - $stringReq = utils::encodeRequest( $request ); // avoid "semantic injection" :)) |
277 | | - // addPushSite($url, $name, $request); |
278 | | - |
279 | | - |
280 | | - $newtext = " |
281 | | -[[Special:ArticleAdminPage|DSMW Admin functions]] |
282 | | - |
283 | | -==Features== |
284 | | -[[name::PushFeed:" . $name . "| ]] |
285 | | -'''Semantic query:''' [[hasSemanticQuery::" . $stringReq . "| ]]<nowiki>" . $request . "</nowiki> |
286 | | - |
287 | | -'''Pages concerned:''' |
288 | | -{{#ask: " . $request . "}} |
289 | | -[[deleted::false| ]] |
290 | | - |
291 | | -==Actions== |
292 | | - |
293 | | -{{#input:type=ajax|value=PUSH|onClick=pushpull('" . $urlServer . "','PushFeed:" . $name . "', 'onpush');}} |
294 | | -The \"PUSH\" action publishes the (unpublished) modifications of the articles listed above. |
295 | | - |
296 | | -== PUSH Progress : == |
297 | | -<div id=\"state\" ></div><br /> |
298 | | -"; |
299 | | - |
300 | | - wfDebugLog( 'p2p', ' -> push page contains : ' . $newtext ); |
301 | | - $title = Title::newFromText( $_POST['name'], PUSHFEED ); |
302 | | - |
303 | | - $article = new Article( $title ); |
304 | | - $edit = $article->doEdit( $newtext, $summary = "" ); |
305 | | - $article->doRedirect(); |
306 | | - return false; |
307 | | - } |
308 | | - /////// ChangeSet page//////// |
309 | | - elseif ( isset( $_POST['action'] ) && $_POST['action'] == 'onpush' ) { |
310 | | - |
311 | | - /* In case we push directly from an article page */ |
312 | | - if ( isset( $_POST['page'] ) && isset( $_POST['request'] ) ) { |
313 | | - $articlename = Title::newFromText( $_POST['name'] ); |
314 | | - |
315 | | - if ( !$articlename->exists() ) { |
316 | | - $result = utils::createPushFeed( $_POST['name'], $_POST['request'] ); |
317 | | - utils::writeAndFlush( "Create push <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=" . $_POST['name'] . ">" . $_POST['name'] . "</a>" ); |
318 | | - if ( $result == false ) { |
319 | | - throw new MWException( |
320 | | - __METHOD__ . ': no Pushfeed created in utils:: createPushFeed: |
321 | | - name: ' . $_POST['name'] . ' request' . $_POST['request'] ); |
322 | | - } |
323 | | - } |
324 | | - } |
325 | | - |
326 | | - wfDebugLog( 'p2p', 'push on ' ); |
327 | | - $patches = array(); |
328 | | - $tmpPatches = array(); |
329 | | - if ( isset( $_POST['name'] ) ) { |
330 | | - $name1 = $_POST['name']; |
331 | | - if ( !is_array( $name1 ) ) |
332 | | - $name1 = array( $name1 ); |
333 | | - foreach ( $name1 as $push ) { |
334 | | - wfDebugLog( 'p2p', ' - ' . $push ); |
335 | | - } |
336 | | - } |
337 | | - else |
338 | | - $name1 = ""; |
339 | | - if ( $name1 == "" ) { |
340 | | - utils::writeAndFlush( '<p><b>No pushfeed selected!</b></p>' ); |
341 | | - $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
342 | | - $article = new Article( $title ); |
343 | | - $article->doRedirect(); |
344 | | - return false; |
345 | | - } |
346 | | - |
347 | | - // $name = $name1[0]; |
348 | | - utils::writeAndFlush( '<p><b>Start push </b></p>' ); |
349 | | - foreach ( $name1 as $name ) { |
350 | | - utils::writeAndFlush( "<span style=\"margin-left:30px;\">begin push: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=$name>" . $name . "</a></span> <br/>" ); |
351 | | - $patches = array(); /// / for each pushfeed name==> push |
352 | | - wfDebugLog( 'p2p', ' -> pushname ' . $name ); |
353 | | - // $name = $_GET['name'];//PushFeed name |
354 | | - $request = getPushFeedRequest( $name ); |
355 | | - // $previousCSID = getPreviousCSID($name); |
356 | | - $previousCSID = getHasPushHead( $name ); |
357 | | - if ( $previousCSID == false ) { |
358 | | - $previousCSID = "none"; |
359 | | - // $CSID = $name."_0"; |
360 | | - }// else{ |
361 | | - // $count = explode(" ", $previousCSID); |
362 | | - // $cnt = $count[1] + 1; |
363 | | - // $CSID = $name."_".$cnt; |
364 | | - // } |
365 | | - wfDebugLog( 'p2p', ' ->pushrequest ' . $request ); |
366 | | - wfDebugLog( 'p2p', ' ->pushHead : ' . $previousCSID ); |
367 | | - $CSID = utils::generateID(); // changesetID |
368 | | - if ( $request == false ) { |
369 | | - $outtext = '<p><b>No semantic request found!</b></p> <a href="' . $_SERVER['HTTP_REFERER'] . '">back</a>'; |
370 | | - $wgOut->addHTML( $outtext ); |
371 | | - return false; |
372 | | - } |
373 | | - |
374 | | - $pages = getRequestedPages( $request ); // ce sont des pages et non des patches |
375 | | - foreach ( $pages as $page ) { |
376 | | - wfDebugLog( 'p2p', ' ->requested page ' . $page ); |
377 | | - $page = str_replace( '"', '', $page ); |
378 | | - $request1 = '[[Patch:+]][[onPage::' . $page . ']]'; |
379 | | - $tmpPatches = utils::orderPatchByPrevious( $page ); |
380 | | - if ( !is_array( $tmpPatches ) ) |
381 | | - throw new MWException( __METHOD__ . ': $tmpPatches is not an array' ); |
382 | | - $patches = array_merge( $patches, $tmpPatches ); |
383 | | - wfDebugLog( 'p2p', ' -> ' . count( $tmpPatches ) . 'patchs were found for the page ' . $page ); |
384 | | - } |
385 | | - wfDebugLog( 'p2p', ' -> ' . count( $patches ) . ' patchs were found for the pushfeed ' . $name ); |
386 | | - $published = getPublishedPatches( $name ); |
387 | | - $unpublished = array_diff( $patches, $published ); /* unpublished = patches-published */ |
388 | | - wfDebugLog( 'p2p', ' -> ' . count( $published ) . ' patchs were published for the pushfeed ' . $name . ' and ' . count( $unpublished ) . ' unpublished patchs' ); |
389 | | - if ( empty( $unpublished ) ) { |
390 | | - wfDebugLog( 'p2p', ' -> no unpublished patch' ); |
391 | | - utils::writeAndFlush( "<span style=\"margin-left:60px;\">no unpublished patch</span><br/>" ); |
392 | | - // return false; //If there is no unpublished patch |
393 | | - } else { |
394 | | - utils::writeAndFlush( "<span style=\"margin-left:60px;\">" . count( $unpublished ) . " unpublished patch</span><br/>" ); |
395 | | - $pos = strrpos( $CSID, ":" ); // NS removing |
396 | | - if ( $pos === false ) { |
397 | | - // not found... |
398 | | - $articleName = $CSID; |
399 | | - $CSID = "ChangeSet:" . $articleName; |
400 | | - } else { |
401 | | - $articleName = substr( $CSID, 0, $pos + 1 ); |
402 | | - $CSID = "ChangeSet:" . $articleName; |
403 | | - } |
404 | | - $newtext = " |
405 | | -[[Special:ArticleAdminPage|DSMW Admin functions]] |
406 | | - |
407 | | -==Features== |
408 | | -[[changeSetID::" . $CSID . "| ]] |
409 | | - |
410 | | -'''Date:''' " . date( DATE_RFC822 ) . " |
411 | | - |
412 | | -'''User:''' " . $wgUser->getName() . " |
413 | | - |
414 | | -This ChangeSet is in : [[inPushFeed::" . $name . "]]<br> |
415 | | -==Published patches== |
416 | | - |
417 | | -{| class=\"wikitable\" border=\"1\" style=\"text-align:left; width:30%;\" |
418 | | -|- |
419 | | -!bgcolor=#c0e8f0 scope=col | Patch |
420 | | -|- |
421 | | -"; |
422 | | - // wfDebugLog('p2p',' -> count unpublished patch '.count($unpublished)); |
423 | | - foreach ( $unpublished as $patch ) { |
424 | | - wfDebugLog( 'p2p', ' -> unpublished patch ' . $patch ); |
425 | | - $newtext .= "|[[hasPatch::" . $patch . "]] |
426 | | -|- |
427 | | -"; |
428 | | - } |
429 | | - $newtext .= " |
430 | | -|}"; |
431 | | - $newtext .= " |
432 | | -==Previous ChangeSet== |
433 | | -[[previousChangeSet::" . $previousCSID . "]] |
434 | | -"; |
435 | | - |
436 | | - $update = updatePushFeed( $name, $CSID ); |
437 | | - if ( $update == true ) {// update the "hasPushHead" value successful |
438 | | - $title = Title::newFromText( $articleName, CHANGESET ); |
439 | | - $article = new Article( $title ); |
440 | | - $article->doEdit( $newtext, $summary = "" ); |
441 | | - } else { |
442 | | - $outtext = '<p><b>PushFeed has not been updated!</b></p>'; |
443 | | - $wgOut->addHTML( $outtext ); |
444 | | - } |
445 | | - } |
446 | | - }// end foreach pushfeed list |
447 | | - utils::writeAndFlush( '<p><b>End push</b></p>' ); |
448 | | - $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
449 | | - $article = new Article( $title ); |
450 | | - $article->doRedirect(); |
451 | | - return false; |
452 | | - } |
453 | | - |
454 | | - |
455 | | - ////////// PullFeed page//////// |
456 | | - elseif ( isset( $_GET['action'] ) && $_GET['action'] == 'pullpage' ) { |
457 | | - // wfDebugLog('p2p','Create pull '.$_POST['pullname'].' with pushName '.$_POST['pushname'].' on '.$_POST['url']); |
458 | | - // $url = rtrim($_POST['url'], "/"); //removes the final "/" if there is one |
459 | | - $urlTmp = $_POST['url']; |
460 | | - if ( utils::isValidURL( $urlTmp ) == false ) |
461 | | - throw new MWException( __METHOD__ . ': ' . $urlTmp . ' seems not to be an url' ); // throws an exception if $url is invalid |
462 | | - |
463 | | - $res = utils::parsePushURL( $urlTmp ); |
464 | | - if ( $res === false || empty( $res ) ) |
465 | | - throw new MWException( __METHOD__ . ': URL format problem' ); |
466 | | - $pushname = $res[0]; |
467 | | - $url = $res[1]; |
468 | | - |
469 | | - // $pushname = $_POST['pushname']; |
470 | | - $pullname = $_POST['pullname']; |
471 | | - |
472 | | - $newtext = " |
473 | | -[[Special:ArticleAdminPage|DSMW Admin functions]] |
474 | | - |
475 | | -==Features== |
476 | | - |
477 | | -[[name::PullFeed:" . $pullname . "| ]] |
478 | | -'''URL of the DSMW PushServer:''' [[pushFeedServer::" . $url . "]]<br> |
479 | | -'''PushFeed name:''' [[pushFeedName::PushFeed:" . $pushname . "]] |
480 | | -[[deleted::false| ]] |
481 | | - |
482 | | -==Actions== |
483 | | - |
484 | | -{{#input:type=ajax|value=PULL|onClick=pushpull('" . $urlServer . "','PullFeed:" . $pullname . "','onpull');}} |
485 | | - |
486 | | -The \"PULL\" action gets the modifications published in the PushFeed of the PushFeedServer above. |
487 | | - |
488 | | -== PULL Progress : == |
489 | | -<div id=\"state\" ></div><br /> |
490 | | -"; |
491 | | - |
492 | | - $title = Title::newFromText( $pullname, PULLFEED ); |
493 | | - $article = new Article( $title ); |
494 | | - $article->doEdit( $newtext, $summary = "" ); |
495 | | - $article->doRedirect(); |
496 | | - |
497 | | - |
498 | | - return false; |
499 | | - } |
500 | | - |
501 | | - ////////// OnPull///////////// |
502 | | - elseif ( isset( $_POST['action'] ) && $_POST['action'] == 'onpull' ) { |
503 | | - if ( isset( $_POST['name'] ) ) { |
504 | | - $name1 = $_POST['name']; |
505 | | - wfDebugLog( 'p2p', 'pull on ' ); |
506 | | - if ( !is_array( $name1 ) ) |
507 | | - $name1 = array( $name1 ); |
508 | | - } |
509 | | - else |
510 | | - $name1 = ""; |
511 | | - if ( $name1 == "" ) { |
512 | | - utils::writeAndFlush( '<p><b>No pullfeed selected!</b></p> ' ); |
513 | | - $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
514 | | - $article = new Article( $title ); |
515 | | - $article->doEdit( '', $summary = "" ); |
516 | | - $article->doRedirect(); |
517 | | - return false; |
518 | | - } |
519 | | - |
520 | | - // $name = $name1[0];//with NS |
521 | | - utils::writeAndFlush( '<p><b>Start pull</b></p>' ); |
522 | | - foreach ( $name1 as $name ) {// for each pullfeed name==> pull |
523 | | - utils::writeAndFlush( "<span style=\"margin-left:30px;\">begin pull: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=$name>" . $name . "</a></span> <br/>" ); |
524 | | - wfDebugLog( 'p2p', ' -> pull : ' . $name ); |
525 | | - |
526 | | - // $previousCSID = getPreviousPulledCSID($name); |
527 | | - // if($previousCSID==false) { |
528 | | - // $previousCSID = "none"; |
529 | | - // } |
530 | | - $previousCSID = getHasPullHead( $name ); |
531 | | - if ( $previousCSID == false ) { |
532 | | - $previousCSID = "none"; |
533 | | - } |
534 | | - wfDebugLog( 'p2p', ' -> pullHead : ' . $previousCSID ); |
535 | | - $relatedPushServer = getPushURL( $name ); |
536 | | - if ( is_null( $relatedPushServer ) |
537 | | - |
538 | | - )throw new MWException( __METHOD__ . ': no relatedPushServer url' ); |
539 | | - $namePush = getPushName( $name ); |
540 | | - $namePush = str_replace( ' ', '_', $namePush ); |
541 | | - wfDebugLog( 'p2p', ' -> pushServer : ' . $relatedPushServer ); |
542 | | - wfDebugLog( 'p2p', ' -> pushName : ' . $namePush ); |
543 | | - if ( is_null( $namePush ) |
544 | | - |
545 | | - )throw new MWException( __METHOD__ . ': no PushName' ); |
546 | | - // split NS and name |
547 | | - preg_match( "/^(.+?)_*:_*(.*)$/S", $namePush, $m ); |
548 | | - $nameWithoutNS = $m[2]; |
549 | | - |
550 | | - |
551 | | - // $url = $relatedPushServer.'/api.php?action=query&meta=changeSet&cspushName='.$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml'; |
552 | | - // $url = $relatedPushServer."/api{$wgScriptExtension}?action=query&meta=changeSet&cspushName=".$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml'; |
553 | | - wfDebugLog( 'testlog', ' -> request ChangeSet : ' . $relatedPushServer . '/api.php?action=query&meta=changeSet&cspushName=' . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
554 | | - $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
555 | | - |
556 | | - /* test if it is a xml file. If not, the server is not reachable via the url |
557 | | - * Then we try to reach it with the .php5 extension |
558 | | - */ |
559 | | - if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) { |
560 | | - $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
561 | | - } |
562 | | - if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) |
563 | | - $cs = false; |
564 | | - |
565 | | - |
566 | | - if ( $cs === false ) |
567 | | - throw new MWException( __METHOD__ . ': Cannot connect to Push Server (ChangeSet API)' ); |
568 | | - $cs = trim( $cs ); |
569 | | - $dom = new DOMDocument(); |
570 | | - $dom->loadXML( $cs ); |
571 | | - |
572 | | - $changeSet = $dom->getElementsByTagName( 'changeSet' ); |
573 | | - $CSID = null; |
574 | | - foreach ( $changeSet as $cs ) { |
575 | | - if ( $cs->hasAttribute( "id" ) ) { |
576 | | - $CSID = $cs->getAttribute( 'id' ); |
577 | | - $csName = $CSID; |
578 | | - } |
579 | | - } |
580 | | - wfDebugLog( 'p2p', ' -> changeSet found ' . $CSID ); |
581 | | - while ( $CSID != null ) { |
582 | | - // if(!utils::pageExist($CSID)) { |
583 | | - $listPatch = null; |
584 | | - $patchs = $dom->getElementsByTagName( 'patch' ); |
585 | | - foreach ( $patchs as $p ) { |
586 | | - wfDebugLog( 'p2p', ' -> patch ' . $p->firstChild->nodeValue ); |
587 | | - $listPatch[] = $p->firstChild->nodeValue; |
588 | | - } |
589 | | - |
590 | | - // $CSID = substr($CSID,strlen('changeSet:')); |
591 | | - utils::createChangeSetPull( $CSID, $name, $previousCSID, $listPatch ); |
592 | | - |
593 | | - integrate( $CSID, $listPatch, $relatedPushServer, $csName ); |
594 | | - updatePullFeed( $name, $CSID ); |
595 | | - |
596 | | - // } |
597 | | - |
598 | | - $previousCSID = $CSID; |
599 | | - wfDebugLog( 'p2p', ' -> request ChangeSet : ' . $relatedPushServer . '/api.php?action=query&meta=changeSet&cspushName=' . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
600 | | - $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
601 | | - |
602 | | - /* test if it is a xml file. If not, the server is not reachable via the url |
603 | | - * Then we try to reach it with the .php5 extension |
604 | | - */ |
605 | | - if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) { |
606 | | - $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
607 | | - } |
608 | | - if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) |
609 | | - $cs = false; |
610 | | - |
611 | | - if ( $cs === false ) |
612 | | - throw new MWException( __METHOD__ . ': Cannot connect to Push Server (ChangeSet API)' ); |
613 | | - $cs = trim( $cs ); |
614 | | - |
615 | | - $dom = new DOMDocument(); |
616 | | - $dom->loadXML( $cs ); |
617 | | - |
618 | | - $changeSet = $dom->getElementsByTagName( 'changeSet' ); |
619 | | - $CSID = null; |
620 | | - foreach ( $changeSet as $cs ) { |
621 | | - if ( $cs->hasAttribute( "id" ) ) { |
622 | | - $CSID = $cs->getAttribute( 'id' ); |
623 | | - } |
624 | | - } |
625 | | - wfDebugLog( 'p2p', ' -> changeSet found ' . $CSID ); |
626 | | - } |
627 | | - if ( is_null( $csName ) ) { |
628 | | - wfDebugLog( 'p2p', ' - redirect to Special:ArticleAdminPage' ); |
629 | | - utils::writeAndFlush( "<span style=\"margin-left:60px;\">no new patch</span><br/>" ); |
630 | | - } else { |
631 | | - wfDebugLog( 'p2p', ' - redirect to ChangeSet:' . $csName ); |
632 | | - } |
633 | | - }// end foreach list pullfeed |
634 | | - utils::writeAndFlush( '<p><b>End pull</b></p>' ); |
635 | | - $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
636 | | - $article = new Article( $title ); |
637 | | - $article->doRedirect(); |
638 | | - return false; |
639 | | - } else { |
640 | | - return true; |
641 | | - } |
642 | | -} |
643 | | - |
644 | | -/** |
645 | | - * |
646 | | - * @param <String> $version1 |
647 | | - * @param <String> $version2='1.14.0' |
648 | | - * @return <integer> |
649 | | - */ |
650 | | -function compareMWVersion( $version1, $version2 = '1.14.0' ) { |
651 | | - $version1 = explode( ".", $version1 ); |
652 | | - $version2 = explode( ".", $version2 ); |
653 | | - |
654 | | - if ( $version1[0] > $version2[0] ) |
655 | | - return 1; |
656 | | - elseif ( $version1[0] < $version2[0] ) |
657 | | - return -1; |
658 | | - elseif ( $version1[1] > $version2[1] ) |
659 | | - return 1; |
660 | | - elseif ( $version1[1] < $version2[1] ) |
661 | | - return -1; |
662 | | - elseif ( $version1[2] > $version2[2] ) |
663 | | - return 1; |
664 | | - elseif ( $version1[2] < $version2[2] ) |
665 | | - return -1; |
666 | | - else |
667 | | - return 0; |
668 | | -} |
669 | | - |
670 | | -/* * *************************************************************************** */ |
671 | | -/* |
672 | | - V0 : initial revision |
673 | | - / \ |
674 | | - / |
675 | | - P1 / \P2 |
676 | | - / |
677 | | - / \ |
678 | | - V1 V2:2nd edit of the same article |
679 | | - 1st Edit |
680 | | - */ |
681 | | -/* * *************************************************************************** */ |
682 | | - |
683 | | -function attemptSave( $editpage ) { |
684 | | - global $wgServerName, $wgScriptPath; |
685 | | - $urlServer = 'http://' . $wgServerName . $wgScriptPath; |
686 | | - |
687 | | - $ns = $editpage->mTitle->getNamespace(); |
688 | | - if ( ( $ns == PATCH ) || ( $ns == PUSHFEED ) || ( $ns == PULLFEED ) || ( $ns == CHANGESET ) |
689 | | - |
690 | | - )return true; |
691 | | - |
692 | | - $actualtext = $editpage->textbox1; // V2 |
693 | | - |
694 | | - $dbr = wfGetDB( DB_SLAVE ); |
695 | | - $lastRevision = Revision::loadFromTitle( $dbr, $editpage->mTitle ); |
696 | | - if ( is_null( $lastRevision ) ) { |
697 | | - $conctext = ""; |
698 | | - $rev_id = 0; |
699 | | - } elseif ( ( $ns == NS_FILE || $ns == NS_IMAGE || $ns == NS_MEDIA ) && $lastRevision->getRawText() == "" ) { |
700 | | - $rev_id = 0; |
701 | | - $conctext = $lastRevision->getText(); |
702 | | - } else { |
703 | | - $conctext = $lastRevision->getText(); // V1 conc |
704 | | - $rev_id = $lastRevision->getId(); |
705 | | - } |
706 | | - |
707 | | - // if there is no modification on the text |
708 | | - if ( $actualtext == $conctext ) |
709 | | - return true; |
710 | | - |
711 | | - $model = manager::loadModel( $rev_id ); |
712 | | - $logoot = new logootEngine( $model ); |
713 | | - |
714 | | - // get the revision with the edittime==>V0 |
715 | | - $rev = Revision::loadFromTimestamp( $dbr, $editpage->mTitle, $editpage->edittime ); |
716 | | - if ( is_null( $rev ) ) { |
717 | | - $text = ""; |
718 | | - $rev_id1 = 0; |
719 | | - } else { |
720 | | - $text = $rev->getText(); // VO |
721 | | - $rev_id1 = $rev->getId(); |
722 | | - } |
723 | | - |
724 | | - if ( $conctext != $text ) {// if last revision is not V0, there is editing conflict |
725 | | -// wfDebugLog('testlog',' -> CONCURRENCE: '); |
726 | | -// wfDebugLog('testlog',' -> +'.$conctext.'+('.$rev_id.') ts '.$lastRevision->getTimestamp()); |
727 | | -// wfDebugLog('testlog',' -> +'.$text.'+('.$rev_id1.') ts '.$editpage->edittime.' '.$rev->getTimestamp()); |
728 | | - $model1 = manager::loadModel( $rev_id1 ); |
729 | | - $logoot1 = new logootEngine( $model1 ); |
730 | | - $listOp1 = $logoot1->generate( $text, $actualtext ); |
731 | | - // creation Patch P2 |
732 | | - $tmp = serialize( $listOp1 ); |
733 | | - $patch = new Patch( false, false, $listOp1, $urlServer, $rev_id1 ); |
734 | | - if ( $editpage->mTitle->getNamespace() == 0 ) |
735 | | - $title = $editpage->mTitle->getText(); |
736 | | - else |
737 | | - $title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText(); |
738 | | - // integration: diffs between VO and V2 into V1 |
739 | | - |
740 | | - $modelAfterIntegrate = $logoot->integrate( $listOp1 ); |
741 | | - } else {// no edition conflict |
742 | | - $listOp = $logoot->generate( $conctext, $actualtext ); |
743 | | - $modelAfterIntegrate = $logoot->getModel(); |
744 | | - $tmp = serialize( $listOp ); |
745 | | - $patch = new Patch( false, false, $listOp, $urlServer, $rev_id1 ); |
746 | | - if ( $editpage->mTitle->getNamespace() == 0 ) |
747 | | - $title = $editpage->mTitle->getText(); |
748 | | - else |
749 | | - $title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText(); |
750 | | - } |
751 | | - $revId = utils::getNewArticleRevId(); |
752 | | - wfDebugLog( 'p2p', ' -> store model rev : ' . $revId . ' session ' . session_id() . ' model ' . $modelAfterIntegrate->getText() ); |
753 | | - manager::storeModel( $revId + 1, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 ); |
754 | | - |
755 | | - $patch->storePage( $title, $revId + 1 ); // stores the patch in a wikipage |
756 | | - $editpage->textbox1 = $modelAfterIntegrate->getText(); |
757 | | - return true; |
758 | | -} |
759 | | - |
760 | | -function uploadComplete( $image ) { |
761 | | - global $wgServerName, $wgScriptPath, $wgServer, $wgVersion; |
762 | | - $urlServer = 'http://' . $wgServerName . $wgScriptPath; |
763 | | - |
764 | | - // $classe = get_class($image); |
765 | | - if ( compareMWVersion( $wgVersion, '1.16.0' ) == -1 ) { |
766 | | - $localfile = $image->mLocalFile; |
767 | | - } else { |
768 | | - |
769 | | - $localfile = $image->getLocalFile(); |
770 | | - } |
771 | | - $path = utils::prepareString( $localfile->mime, $localfile->size, $wgServer . urldecode( $localfile->url ) ); |
772 | | - if ( !file_exists( $path ) ) { |
773 | | - $dbr = wfGetDB( DB_SLAVE ); |
774 | | - $lastRevision = Revision::loadFromTitle( $dbr, $localfile->getTitle() ); |
775 | | - if ( $lastRevision->getPrevious() == null ) { |
776 | | - $rev_id = 0; |
777 | | - } else { |
778 | | - $rev_id = $lastRevision->getPrevious()->getId(); |
779 | | - } |
780 | | - $revID = $lastRevision->getId(); |
781 | | - $model = manager::loadModel( $rev_id ); |
782 | | - $patch = new Patch( false, true, null, $urlServer, $rev_id, null, null, null, $localfile->mime, $localfile->size, urldecode( $localfile->url ), null ); |
783 | | - $patch->storePage( $localfile->getTitle(), $revID ); // stores the patch in a wikipage |
784 | | - manager::storeModel( $revID, $sessionId = session_id(), $model, $blobCB = 0 ); |
785 | | - } |
786 | | - return true; |
787 | | -} |
788 | | - |
789 | | -function dsmwgSetupFunction() { |
790 | | - global $smwgNamespacesWithSemanticLinks; |
791 | | - $smwgNamespacesWithSemanticLinks = $smwgNamespacesWithSemanticLinks + array( |
792 | | - PATCH => true, PUSHFEED => true, PULLFEED => true, CHANGESET => true ); |
793 | | - |
794 | | - if ( defined( 'SRF_VERSION' ) ) { |
795 | | - |
796 | | - global $wgDSMWExhibits; |
797 | | - if ( !is_object( $wgDSMWExhibits ) ) |
798 | | - $wgDSMWExhibits = new DSMWExhibits(); |
799 | | - } |
800 | | -} |
801 | | - |
802 | | -require_once "$IP/extensions/DSMW/includes/DSMWSettingsInc.inc"; |
| 141 | +require_once dirname( __FILE__ ) . 'DSMW_Settings.php'; |
Index: trunk/extensions/DSMW/includes/DSMWSettingsInc.inc |
— | — | @@ -1,121 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @copyright INRIA-LORIA-ECOO project |
5 | | - * @author jean-philippe muller |
6 | | - */ |
7 | | - |
8 | | -# create namespace |
9 | | -define("PATCH",110); |
10 | | -define("PUSHFEED",200); |
11 | | -define("PULLFEED",210); |
12 | | -define("CHANGESET",220); |
13 | | - |
14 | | -$wgExtraNamespaces[PATCH] = "Patch"; |
15 | | -$wgExtraNamespaces[PUSHFEED] = "PushFeed"; |
16 | | -$wgExtraNamespaces[PULLFEED] = "PullFeed"; |
17 | | -$wgExtraNamespaces[CHANGESET] = "ChangeSet"; |
18 | | -# protect namespace |
19 | | -$wgNamespaceProtection[PATCH] = Array("editpatch"); |
20 | | -$wgNamespacesWithSubpages[PATCH] = true; |
21 | | -$wgGroupPermissions['*']['editpatch'] = false; |
22 | | -$wgGroupPermissions['sysop']['editpatch'] = true; |
23 | | -$wgNamespaceProtection[PUSHFEED] = Array("editpushfeed"); |
24 | | -$wgNamespacesWithSubpages[PUSHFEED] = true; |
25 | | -$wgGroupPermissions['*']['editpushfeed'] = false; |
26 | | -$wgGroupPermissions['sysop']['editpushfeed'] = true; |
27 | | -$wgNamespaceProtection[PULLFEED] = Array("editpullfeed"); |
28 | | -$wgNamespacesWithSubpages[PULLFEED] = true; |
29 | | -$wgGroupPermissions['*']['editpullfeed'] = false; |
30 | | -$wgGroupPermissions['sysop']['editpullfeed'] = true; |
31 | | -$wgNamespaceProtection[CHANGESET] = Array("editchangeset"); |
32 | | -$wgNamespacesWithSubpages[CHANGESET] = true; |
33 | | -$wgGroupPermissions['*']['editchangeset'] = false; |
34 | | -$wgGroupPermissions['sysop']['editchangeset'] = true; |
35 | | - |
36 | | - |
37 | | -$wgGroupPermissions['*']['ArticleAdminPage'] = true;//sysop |
38 | | -require_once("$IP/extensions/DSMW/specialPage/ArticleAdminPage.php" ); |
39 | | - |
40 | | -$wgGroupPermissions['*']['DSMWAdmin'] = true;//sysop |
41 | | -require_once("$IP/extensions/DSMW/specialPage/DSMWAdmin.php" ); |
42 | | - |
43 | | -$wgGroupPermissions['*']['DSMWGeneralExhibits'] = true;//sysop |
44 | | -require_once("$IP/extensions/DSMW/specialPage/DSMWGeneralExhibits.php" ); |
45 | | - |
46 | | -//Simple forms extension |
47 | | -include("$IP/extensions/DSMW/SimpleForms/SimpleForms.php"); |
48 | | - |
49 | | -//semantic mediawiki extension |
50 | | - $smwgNamespaceIndex = 120; |
51 | | - |
52 | | - |
53 | | -//Database update |
54 | | -//updateDB(); |
55 | | -// |
56 | | -// //define unique serverId |
57 | | -// global $serverId; |
58 | | -// $serverId = getServerId(); |
59 | | -// if($serverId=="0"){ |
60 | | -// $serverId = md5(uniqid(mt_rand(), true)); |
61 | | -// store(strtoupper($serverId)); |
62 | | -// } |
63 | | -// |
64 | | -// /** |
65 | | -// * Gets the Server id (unique) |
66 | | -// * |
67 | | -// * @return <String> |
68 | | -// */ |
69 | | -// function getServerId(){ |
70 | | -// $db = wfGetDB( DB_SLAVE ); |
71 | | -// $res = $db->selectField('p2p_params','server_id'); |
72 | | -// return $res; |
73 | | -// } |
74 | | -// |
75 | | -///** |
76 | | -// * Stores the server id |
77 | | -// * |
78 | | -// * @param <String> $serverId |
79 | | -// */ |
80 | | -// function store($serverId){ |
81 | | -// $dbw = wfGetDB( DB_MASTER ); |
82 | | -// $dbw->update( 'p2p_params', array( |
83 | | -// 'server_id' => $serverId, |
84 | | -// ), '*', __METHOD__ ); |
85 | | -// } |
86 | | -// |
87 | | -// /** |
88 | | -// * |
89 | | -// * @global <type> $wgDBname |
90 | | -// * @global <type> $wgDSMWIP |
91 | | -// */ |
92 | | -// function setDBName(){ |
93 | | -// global $wgDBname, $wgDSMWIP; |
94 | | -// $content = file_get_contents($wgDSMWIP.'/db/addedTables.sql'); |
95 | | -// if ( false === $content ) { |
96 | | -// throw new MWException( "Could not open \"../db/addedTables.sql\".\n" ); |
97 | | -// } |
98 | | -// $newContent = str_replace('`wikidb`', "`".$wgDBname."`", $content); |
99 | | -// |
100 | | -// $fp = fopen( $wgDSMWIP.'/db/addedTables.sql', 'w+' ); |
101 | | -// if ( false === $fp ) { |
102 | | -// throw new MWException( "Could not open \"../db/addedTables.sql\".\n" ); |
103 | | -// } |
104 | | -// fwrite($fp, $newContent); |
105 | | -// |
106 | | -// fclose( $fp ); |
107 | | -// } |
108 | | -// |
109 | | -// /** |
110 | | -// * Automatic database tables creation |
111 | | -// * @global <String> $wgDSMWIP |
112 | | -// */ |
113 | | -// function updateDB() { |
114 | | -// global $wgDSMWIP; |
115 | | -// |
116 | | -// $db = &wfGetDB(DB_SLAVE); |
117 | | -// if ($db->tableExists('model') === false && $db->tableExists('p2p_params') === false) { |
118 | | -// //if the dsmw tables doesn't exist, there are created automatically |
119 | | -// setDBName(); |
120 | | -// $db->sourceFile($wgDSMWIP.'/db/addedTables.sql' ); |
121 | | -// } |
122 | | -// } |
Index: trunk/extensions/DSMW/includes/DSMW_GlobalFunctions.php |
— | — | @@ -0,0 +1,693 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Global functions for the Distributed Semantic MediaWiki extension. |
| 6 | + * |
| 7 | + * @file DSMW_GlobalFunctions.php |
| 8 | + * @ingroup DSMW |
| 9 | + * |
| 10 | + * @author jean-philippe muller & Morel Émile |
| 11 | + */ |
| 12 | + |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + die( 'Not a valid entry point.' ); |
| 15 | +} |
| 16 | + |
| 17 | +define( 'INT_MAX', '1000000000000000000000' ); // 22 |
| 18 | +define( 'INT_MIN', '0' ); |
| 19 | + |
| 20 | +function conflict( &$editor, &$out ) { |
| 21 | + $conctext = $editor->textbox1; |
| 22 | + $actualtext = $editor->textbox2; |
| 23 | + $initialtext = $editor->getBaseRevision()->mText; |
| 24 | + |
| 25 | + // TODO: WTF?! |
| 26 | + $editor->mArticle->updateArticle( |
| 27 | + $actualtext, |
| 28 | + $editor->summary, |
| 29 | + $editor->minoredit, |
| 30 | + $editor->watchthis, |
| 31 | + $bot = false, |
| 32 | + $sectionanchor = '' |
| 33 | + ); |
| 34 | + |
| 35 | + return true; |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * MW Hook used to redirect to page creation (pushfeed, pullfeed, changeset), |
| 40 | + * to forms or to push/pull action testing the action param |
| 41 | + * |
| 42 | + * |
| 43 | + * @global <Object> $wgOut |
| 44 | + * @param <Object> $action |
| 45 | + * @param <Object> $article |
| 46 | + * @return <boolean> |
| 47 | + */ |
| 48 | +function onUnknownAction( $action, $article ) { |
| 49 | + global $wgOut, $wgServerName, $wgScriptPath, $wgUser, $wgScriptExtension, $wgDSMWIP; |
| 50 | + $urlServer = 'http://' . $wgServerName . $wgScriptPath . "/index{$wgScriptExtension}"; |
| 51 | + $urlAjax = 'http://' . $wgServerName . $wgScriptPath; |
| 52 | + ////////// pull form page//////// |
| 53 | + if ( isset( $_GET['action'] ) && $_GET['action'] == 'addpullpage' ) { |
| 54 | + wfDebugLog( 'p2p', 'addPullPage ' ); |
| 55 | + $newtext = "Add a new site: |
| 56 | +<div id='dsmw' style=\"color:green;\"></div> |
| 57 | + |
| 58 | +{{#form:action=" . $urlServer . "?action=pullpage|method=POST| |
| 59 | +PushFeed Url: {{#input:type=button|value=Url test|onClick= |
| 60 | +var url = document.getElementsByName('url')[0].value; |
| 61 | +if(url.indexOf('PushFeed')==-1){ |
| 62 | +alert('No valid PushFeed syntax, see example.'); |
| 63 | +}else{ |
| 64 | +var urlTmp = url.substring(0,url.indexOf('PushFeed')); |
| 65 | +//alert(urlTmp); |
| 66 | + |
| 67 | +var pos1 = urlTmp.indexOf('index.php'); |
| 68 | +//alert(pos1); |
| 69 | +var pushUrl=''; |
| 70 | +if(pos1!=-1){ |
| 71 | +pushUrl = urlTmp.substring(0,pos1); |
| 72 | +//alert('if'); |
| 73 | +}else{ |
| 74 | +pushUrl = urlTmp; |
| 75 | +//alert('else'); |
| 76 | +} |
| 77 | +//alert(pushUrl); |
| 78 | + |
| 79 | +//alert(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml'); |
| 80 | +var xhr_object = null; |
| 81 | + |
| 82 | + if(window.XMLHttpRequest) // Firefox |
| 83 | + xhr_object = new XMLHttpRequest(); |
| 84 | + else if(window.ActiveXObject) // Internet Explorer |
| 85 | + xhr_object = new ActiveXObject('Microsoft.XMLHTTP'); |
| 86 | + else { |
| 87 | + alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest...'); |
| 88 | + return; |
| 89 | + } |
| 90 | + try{ xhr_object.open('GET', '" . $urlAjax . "/extensions/DSMW/files/ajax.php?url='+escape(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml'), true);} |
| 91 | + catch(e){ |
| 92 | + //alert('There is no DSMW Server responding at this URL'); |
| 93 | + document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!'; |
| 94 | + document.getElementById('dsmw').style.color = 'red'; |
| 95 | + } |
| 96 | + xhr_object.onreadystatechange = function() { |
| 97 | + |
| 98 | +if(xhr_object.readyState == 4) { |
| 99 | + if(xhr_object.statusText=='OK'){ |
| 100 | + if(xhr_object.responseText == 'true'){ //alert('URL valid, there is a DSMW Server responding'); |
| 101 | + document.getElementById('dsmw').innerHTML = 'URL valid, there is a DSMW Server responding!'; |
| 102 | + document.getElementById('dsmw').style.color = 'green'; |
| 103 | + } |
| 104 | + else{ //alert('There is no DSMW Server responding at this URL'); |
| 105 | + document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!'; |
| 106 | + document.getElementById('dsmw').style.color = 'red'; |
| 107 | + } |
| 108 | + } |
| 109 | + else{ |
| 110 | + //alert('There is no DSMW Server responding at this URL'); |
| 111 | + document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!'; |
| 112 | + document.getElementById('dsmw').style.color = 'red'; |
| 113 | +} |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + xhr_object.send(null); |
| 118 | +} |
| 119 | +}}<br> {{#input:type=text|name=url|size=50}} <b>e.g. http://server/path/index.php?title=PushFeed:PushName</b><br> |
| 120 | +PullFeed Name: <br> {{#input:type=text|name=pullname}}<br> |
| 121 | +{{#input:type=submit|value=ADD}} |
| 122 | +}}"; |
| 123 | + |
| 124 | + // if article doesn't exist insertNewArticle |
| 125 | + if ( $article->mTitle->exists() ) { |
| 126 | + $article->updateArticle( $newtext, $summary = "", false, false ); |
| 127 | + } else { |
| 128 | + $article->insertNewArticle( $newtext, $summary = "", false, false ); |
| 129 | + } |
| 130 | + $article->doRedirect(); |
| 131 | + |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | + |
| 136 | + ///////// push form page//////// |
| 137 | + elseif ( isset( $_GET['action'] ) && $_GET['action'] == 'addpushpage' ) { |
| 138 | + wfDebugLog( 'p2p', 'addPushPage' ); |
| 139 | + $specialAsk = $urlServer . '?title=Special:Ask'; |
| 140 | + $newtext = "Add a new pushfeed: |
| 141 | + |
| 142 | +{{#form:action=" . $urlServer . "?action=pushpage|method=POST| |
| 143 | +PushFeed Name: <br> {{#input:class=test|name=name|type=text|onKeyUp=test('$urlServer');}}<div style=\"display:inline; \" id=\"state\" ></div><br /> |
| 144 | +Request: {{#input:type=button|value=Test your query|title=click here to test your query results|onClick= |
| 145 | +var query = document.getElementsByName('keyword')[0].value; |
| 146 | +var query1 = encodeURI(query); |
| 147 | +window.open('" . $specialAsk . "&q='+query1+'&eq=yes&p%5Bformat%5D=broadtable','querywindow','menubar=no, status=no, scrollbars=yes, menubar=no, width=1000, height=900');}} |
| 148 | + <br>{{#input:type=textarea|cols=30 | style=width:auto |rows=2|name=keyword}} <b>e.g. [[Category:city]][[locatedIn::France]]</b><br> |
| 149 | +{{#input:type=submit|value=ADD}} |
| 150 | +}}"; |
| 151 | + |
| 152 | + $article->doEdit( $newtext, $summary = "" ); |
| 153 | + $article->doRedirect(); |
| 154 | + return false; |
| 155 | + } |
| 156 | + |
| 157 | + |
| 158 | + /////// PushFeed page//////// |
| 159 | + elseif ( isset( $_GET['action'] ) && $_GET['action'] == 'pushpage' ) { |
| 160 | + // $url = $_POST['url'];//pas url mais changesetId |
| 161 | + wfDebugLog( 'p2p', 'Create new push ' . $_POST['name'] . ' with ' . $_POST['keyword'] ); |
| 162 | + $name = $_POST['name']; |
| 163 | + $request = $_POST['keyword']; |
| 164 | + $stringReq = utils::encodeRequest( $request ); // avoid "semantic injection" :)) |
| 165 | + // addPushSite($url, $name, $request); |
| 166 | + |
| 167 | + |
| 168 | + $newtext = " |
| 169 | +[[Special:ArticleAdminPage|DSMW Admin functions]] |
| 170 | + |
| 171 | +==Features== |
| 172 | +[[name::PushFeed:" . $name . "| ]] |
| 173 | +'''Semantic query:''' [[hasSemanticQuery::" . $stringReq . "| ]]<nowiki>" . $request . "</nowiki> |
| 174 | + |
| 175 | +'''Pages concerned:''' |
| 176 | +{{#ask: " . $request . "}} |
| 177 | +[[deleted::false| ]] |
| 178 | + |
| 179 | +==Actions== |
| 180 | + |
| 181 | +{{#input:type=ajax|value=PUSH|onClick=pushpull('" . $urlServer . "','PushFeed:" . $name . "', 'onpush');}} |
| 182 | +The \"PUSH\" action publishes the (unpublished) modifications of the articles listed above. |
| 183 | + |
| 184 | +== PUSH Progress : == |
| 185 | +<div id=\"state\" ></div><br /> |
| 186 | +"; |
| 187 | + |
| 188 | + wfDebugLog( 'p2p', ' -> push page contains : ' . $newtext ); |
| 189 | + $title = Title::newFromText( $_POST['name'], PUSHFEED ); |
| 190 | + |
| 191 | + $article = new Article( $title ); |
| 192 | + $edit = $article->doEdit( $newtext, $summary = "" ); |
| 193 | + $article->doRedirect(); |
| 194 | + return false; |
| 195 | + } |
| 196 | + /////// ChangeSet page//////// |
| 197 | + elseif ( isset( $_POST['action'] ) && $_POST['action'] == 'onpush' ) { |
| 198 | + |
| 199 | + /* In case we push directly from an article page */ |
| 200 | + if ( isset( $_POST['page'] ) && isset( $_POST['request'] ) ) { |
| 201 | + $articlename = Title::newFromText( $_POST['name'] ); |
| 202 | + |
| 203 | + if ( !$articlename->exists() ) { |
| 204 | + $result = utils::createPushFeed( $_POST['name'], $_POST['request'] ); |
| 205 | + utils::writeAndFlush( "Create push <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=" . $_POST['name'] . ">" . $_POST['name'] . "</a>" ); |
| 206 | + if ( $result == false ) { |
| 207 | + throw new MWException( |
| 208 | + __METHOD__ . ': no Pushfeed created in utils:: createPushFeed: |
| 209 | + name: ' . $_POST['name'] . ' request' . $_POST['request'] ); |
| 210 | + } |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + wfDebugLog( 'p2p', 'push on ' ); |
| 215 | + $patches = array(); |
| 216 | + $tmpPatches = array(); |
| 217 | + if ( isset( $_POST['name'] ) ) { |
| 218 | + $name1 = $_POST['name']; |
| 219 | + if ( !is_array( $name1 ) ) |
| 220 | + $name1 = array( $name1 ); |
| 221 | + foreach ( $name1 as $push ) { |
| 222 | + wfDebugLog( 'p2p', ' - ' . $push ); |
| 223 | + } |
| 224 | + } |
| 225 | + else |
| 226 | + $name1 = ""; |
| 227 | + if ( $name1 == "" ) { |
| 228 | + utils::writeAndFlush( '<p><b>No pushfeed selected!</b></p>' ); |
| 229 | + $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
| 230 | + $article = new Article( $title ); |
| 231 | + $article->doRedirect(); |
| 232 | + return false; |
| 233 | + } |
| 234 | + |
| 235 | + // $name = $name1[0]; |
| 236 | + utils::writeAndFlush( '<p><b>Start push </b></p>' ); |
| 237 | + foreach ( $name1 as $name ) { |
| 238 | + utils::writeAndFlush( "<span style=\"margin-left:30px;\">begin push: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=$name>" . $name . "</a></span> <br/>" ); |
| 239 | + $patches = array(); /// / for each pushfeed name==> push |
| 240 | + wfDebugLog( 'p2p', ' -> pushname ' . $name ); |
| 241 | + // $name = $_GET['name'];//PushFeed name |
| 242 | + $request = getPushFeedRequest( $name ); |
| 243 | + // $previousCSID = getPreviousCSID($name); |
| 244 | + $previousCSID = getHasPushHead( $name ); |
| 245 | + if ( $previousCSID == false ) { |
| 246 | + $previousCSID = "none"; |
| 247 | + // $CSID = $name."_0"; |
| 248 | + }// else{ |
| 249 | + // $count = explode(" ", $previousCSID); |
| 250 | + // $cnt = $count[1] + 1; |
| 251 | + // $CSID = $name."_".$cnt; |
| 252 | + // } |
| 253 | + wfDebugLog( 'p2p', ' ->pushrequest ' . $request ); |
| 254 | + wfDebugLog( 'p2p', ' ->pushHead : ' . $previousCSID ); |
| 255 | + $CSID = utils::generateID(); // changesetID |
| 256 | + if ( $request == false ) { |
| 257 | + $outtext = '<p><b>No semantic request found!</b></p> <a href="' . $_SERVER['HTTP_REFERER'] . '">back</a>'; |
| 258 | + $wgOut->addHTML( $outtext ); |
| 259 | + return false; |
| 260 | + } |
| 261 | + |
| 262 | + $pages = getRequestedPages( $request ); // ce sont des pages et non des patches |
| 263 | + foreach ( $pages as $page ) { |
| 264 | + wfDebugLog( 'p2p', ' ->requested page ' . $page ); |
| 265 | + $page = str_replace( '"', '', $page ); |
| 266 | + $request1 = '[[Patch:+]][[onPage::' . $page . ']]'; |
| 267 | + $tmpPatches = utils::orderPatchByPrevious( $page ); |
| 268 | + if ( !is_array( $tmpPatches ) ) |
| 269 | + throw new MWException( __METHOD__ . ': $tmpPatches is not an array' ); |
| 270 | + $patches = array_merge( $patches, $tmpPatches ); |
| 271 | + wfDebugLog( 'p2p', ' -> ' . count( $tmpPatches ) . 'patchs were found for the page ' . $page ); |
| 272 | + } |
| 273 | + wfDebugLog( 'p2p', ' -> ' . count( $patches ) . ' patchs were found for the pushfeed ' . $name ); |
| 274 | + $published = getPublishedPatches( $name ); |
| 275 | + $unpublished = array_diff( $patches, $published ); /* unpublished = patches-published */ |
| 276 | + wfDebugLog( 'p2p', ' -> ' . count( $published ) . ' patchs were published for the pushfeed ' . $name . ' and ' . count( $unpublished ) . ' unpublished patchs' ); |
| 277 | + if ( empty( $unpublished ) ) { |
| 278 | + wfDebugLog( 'p2p', ' -> no unpublished patch' ); |
| 279 | + utils::writeAndFlush( "<span style=\"margin-left:60px;\">no unpublished patch</span><br/>" ); |
| 280 | + // return false; //If there is no unpublished patch |
| 281 | + } else { |
| 282 | + utils::writeAndFlush( "<span style=\"margin-left:60px;\">" . count( $unpublished ) . " unpublished patch</span><br/>" ); |
| 283 | + $pos = strrpos( $CSID, ":" ); // NS removing |
| 284 | + if ( $pos === false ) { |
| 285 | + // not found... |
| 286 | + $articleName = $CSID; |
| 287 | + $CSID = "ChangeSet:" . $articleName; |
| 288 | + } else { |
| 289 | + $articleName = substr( $CSID, 0, $pos + 1 ); |
| 290 | + $CSID = "ChangeSet:" . $articleName; |
| 291 | + } |
| 292 | + $newtext = " |
| 293 | +[[Special:ArticleAdminPage|DSMW Admin functions]] |
| 294 | + |
| 295 | +==Features== |
| 296 | +[[changeSetID::" . $CSID . "| ]] |
| 297 | + |
| 298 | +'''Date:''' " . date( DATE_RFC822 ) . " |
| 299 | + |
| 300 | +'''User:''' " . $wgUser->getName() . " |
| 301 | + |
| 302 | +This ChangeSet is in : [[inPushFeed::" . $name . "]]<br> |
| 303 | +==Published patches== |
| 304 | + |
| 305 | +{| class=\"wikitable\" border=\"1\" style=\"text-align:left; width:30%;\" |
| 306 | +|- |
| 307 | +!bgcolor=#c0e8f0 scope=col | Patch |
| 308 | +|- |
| 309 | +"; |
| 310 | + // wfDebugLog('p2p',' -> count unpublished patch '.count($unpublished)); |
| 311 | + foreach ( $unpublished as $patch ) { |
| 312 | + wfDebugLog( 'p2p', ' -> unpublished patch ' . $patch ); |
| 313 | + $newtext .= "|[[hasPatch::" . $patch . "]] |
| 314 | +|- |
| 315 | +"; |
| 316 | + } |
| 317 | + $newtext .= " |
| 318 | +|}"; |
| 319 | + $newtext .= " |
| 320 | +==Previous ChangeSet== |
| 321 | +[[previousChangeSet::" . $previousCSID . "]] |
| 322 | +"; |
| 323 | + |
| 324 | + $update = updatePushFeed( $name, $CSID ); |
| 325 | + if ( $update == true ) {// update the "hasPushHead" value successful |
| 326 | + $title = Title::newFromText( $articleName, CHANGESET ); |
| 327 | + $article = new Article( $title ); |
| 328 | + $article->doEdit( $newtext, $summary = "" ); |
| 329 | + } else { |
| 330 | + $outtext = '<p><b>PushFeed has not been updated!</b></p>'; |
| 331 | + $wgOut->addHTML( $outtext ); |
| 332 | + } |
| 333 | + } |
| 334 | + }// end foreach pushfeed list |
| 335 | + utils::writeAndFlush( '<p><b>End push</b></p>' ); |
| 336 | + $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
| 337 | + $article = new Article( $title ); |
| 338 | + $article->doRedirect(); |
| 339 | + return false; |
| 340 | + } |
| 341 | + |
| 342 | + |
| 343 | + ////////// PullFeed page//////// |
| 344 | + elseif ( isset( $_GET['action'] ) && $_GET['action'] == 'pullpage' ) { |
| 345 | + // wfDebugLog('p2p','Create pull '.$_POST['pullname'].' with pushName '.$_POST['pushname'].' on '.$_POST['url']); |
| 346 | + // $url = rtrim($_POST['url'], "/"); //removes the final "/" if there is one |
| 347 | + $urlTmp = $_POST['url']; |
| 348 | + if ( utils::isValidURL( $urlTmp ) == false ) |
| 349 | + throw new MWException( __METHOD__ . ': ' . $urlTmp . ' seems not to be an url' ); // throws an exception if $url is invalid |
| 350 | + |
| 351 | + $res = utils::parsePushURL( $urlTmp ); |
| 352 | + if ( $res === false || empty( $res ) ) |
| 353 | + throw new MWException( __METHOD__ . ': URL format problem' ); |
| 354 | + $pushname = $res[0]; |
| 355 | + $url = $res[1]; |
| 356 | + |
| 357 | + // $pushname = $_POST['pushname']; |
| 358 | + $pullname = $_POST['pullname']; |
| 359 | + |
| 360 | + $newtext = " |
| 361 | +[[Special:ArticleAdminPage|DSMW Admin functions]] |
| 362 | + |
| 363 | +==Features== |
| 364 | + |
| 365 | +[[name::PullFeed:" . $pullname . "| ]] |
| 366 | +'''URL of the DSMW PushServer:''' [[pushFeedServer::" . $url . "]]<br> |
| 367 | +'''PushFeed name:''' [[pushFeedName::PushFeed:" . $pushname . "]] |
| 368 | +[[deleted::false| ]] |
| 369 | + |
| 370 | +==Actions== |
| 371 | + |
| 372 | +{{#input:type=ajax|value=PULL|onClick=pushpull('" . $urlServer . "','PullFeed:" . $pullname . "','onpull');}} |
| 373 | + |
| 374 | +The \"PULL\" action gets the modifications published in the PushFeed of the PushFeedServer above. |
| 375 | + |
| 376 | +== PULL Progress : == |
| 377 | +<div id=\"state\" ></div><br /> |
| 378 | +"; |
| 379 | + |
| 380 | + $title = Title::newFromText( $pullname, PULLFEED ); |
| 381 | + $article = new Article( $title ); |
| 382 | + $article->doEdit( $newtext, $summary = "" ); |
| 383 | + $article->doRedirect(); |
| 384 | + |
| 385 | + |
| 386 | + return false; |
| 387 | + } |
| 388 | + |
| 389 | + ////////// OnPull///////////// |
| 390 | + elseif ( isset( $_POST['action'] ) && $_POST['action'] == 'onpull' ) { |
| 391 | + if ( isset( $_POST['name'] ) ) { |
| 392 | + $name1 = $_POST['name']; |
| 393 | + wfDebugLog( 'p2p', 'pull on ' ); |
| 394 | + if ( !is_array( $name1 ) ) |
| 395 | + $name1 = array( $name1 ); |
| 396 | + } |
| 397 | + else |
| 398 | + $name1 = ""; |
| 399 | + if ( $name1 == "" ) { |
| 400 | + utils::writeAndFlush( '<p><b>No pullfeed selected!</b></p> ' ); |
| 401 | + $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
| 402 | + $article = new Article( $title ); |
| 403 | + $article->doEdit( '', $summary = "" ); |
| 404 | + $article->doRedirect(); |
| 405 | + return false; |
| 406 | + } |
| 407 | + |
| 408 | + // $name = $name1[0];//with NS |
| 409 | + utils::writeAndFlush( '<p><b>Start pull</b></p>' ); |
| 410 | + foreach ( $name1 as $name ) {// for each pullfeed name==> pull |
| 411 | + utils::writeAndFlush( "<span style=\"margin-left:30px;\">begin pull: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=$name>" . $name . "</a></span> <br/>" ); |
| 412 | + wfDebugLog( 'p2p', ' -> pull : ' . $name ); |
| 413 | + |
| 414 | + // $previousCSID = getPreviousPulledCSID($name); |
| 415 | + // if($previousCSID==false) { |
| 416 | + // $previousCSID = "none"; |
| 417 | + // } |
| 418 | + $previousCSID = getHasPullHead( $name ); |
| 419 | + if ( $previousCSID == false ) { |
| 420 | + $previousCSID = "none"; |
| 421 | + } |
| 422 | + wfDebugLog( 'p2p', ' -> pullHead : ' . $previousCSID ); |
| 423 | + $relatedPushServer = getPushURL( $name ); |
| 424 | + if ( is_null( $relatedPushServer ) |
| 425 | + |
| 426 | + )throw new MWException( __METHOD__ . ': no relatedPushServer url' ); |
| 427 | + $namePush = getPushName( $name ); |
| 428 | + $namePush = str_replace( ' ', '_', $namePush ); |
| 429 | + wfDebugLog( 'p2p', ' -> pushServer : ' . $relatedPushServer ); |
| 430 | + wfDebugLog( 'p2p', ' -> pushName : ' . $namePush ); |
| 431 | + if ( is_null( $namePush ) |
| 432 | + |
| 433 | + )throw new MWException( __METHOD__ . ': no PushName' ); |
| 434 | + // split NS and name |
| 435 | + preg_match( "/^(.+?)_*:_*(.*)$/S", $namePush, $m ); |
| 436 | + $nameWithoutNS = $m[2]; |
| 437 | + |
| 438 | + |
| 439 | + // $url = $relatedPushServer.'/api.php?action=query&meta=changeSet&cspushName='.$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml'; |
| 440 | + // $url = $relatedPushServer."/api{$wgScriptExtension}?action=query&meta=changeSet&cspushName=".$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml'; |
| 441 | + wfDebugLog( 'testlog', ' -> request ChangeSet : ' . $relatedPushServer . '/api.php?action=query&meta=changeSet&cspushName=' . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
| 442 | + $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
| 443 | + |
| 444 | + /* test if it is a xml file. If not, the server is not reachable via the url |
| 445 | + * Then we try to reach it with the .php5 extension |
| 446 | + */ |
| 447 | + if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) { |
| 448 | + $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
| 449 | + } |
| 450 | + if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) |
| 451 | + $cs = false; |
| 452 | + |
| 453 | + |
| 454 | + if ( $cs === false ) |
| 455 | + throw new MWException( __METHOD__ . ': Cannot connect to Push Server (ChangeSet API)' ); |
| 456 | + $cs = trim( $cs ); |
| 457 | + $dom = new DOMDocument(); |
| 458 | + $dom->loadXML( $cs ); |
| 459 | + |
| 460 | + $changeSet = $dom->getElementsByTagName( 'changeSet' ); |
| 461 | + $CSID = null; |
| 462 | + foreach ( $changeSet as $cs ) { |
| 463 | + if ( $cs->hasAttribute( "id" ) ) { |
| 464 | + $CSID = $cs->getAttribute( 'id' ); |
| 465 | + $csName = $CSID; |
| 466 | + } |
| 467 | + } |
| 468 | + wfDebugLog( 'p2p', ' -> changeSet found ' . $CSID ); |
| 469 | + while ( $CSID != null ) { |
| 470 | + // if(!utils::pageExist($CSID)) { |
| 471 | + $listPatch = null; |
| 472 | + $patchs = $dom->getElementsByTagName( 'patch' ); |
| 473 | + foreach ( $patchs as $p ) { |
| 474 | + wfDebugLog( 'p2p', ' -> patch ' . $p->firstChild->nodeValue ); |
| 475 | + $listPatch[] = $p->firstChild->nodeValue; |
| 476 | + } |
| 477 | + |
| 478 | + // $CSID = substr($CSID,strlen('changeSet:')); |
| 479 | + utils::createChangeSetPull( $CSID, $name, $previousCSID, $listPatch ); |
| 480 | + |
| 481 | + integrate( $CSID, $listPatch, $relatedPushServer, $csName ); |
| 482 | + updatePullFeed( $name, $CSID ); |
| 483 | + |
| 484 | + // } |
| 485 | + |
| 486 | + $previousCSID = $CSID; |
| 487 | + wfDebugLog( 'p2p', ' -> request ChangeSet : ' . $relatedPushServer . '/api.php?action=query&meta=changeSet&cspushName=' . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
| 488 | + $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
| 489 | + |
| 490 | + /* test if it is a xml file. If not, the server is not reachable via the url |
| 491 | + * Then we try to reach it with the .php5 extension |
| 492 | + */ |
| 493 | + if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) { |
| 494 | + $cs = utils::file_get_contents_curl( utils::lcfirst( $relatedPushServer ) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml' ); |
| 495 | + } |
| 496 | + if ( strpos( $cs, "<?xml version=\"1.0\"?>" ) === false ) |
| 497 | + $cs = false; |
| 498 | + |
| 499 | + if ( $cs === false ) |
| 500 | + throw new MWException( __METHOD__ . ': Cannot connect to Push Server (ChangeSet API)' ); |
| 501 | + $cs = trim( $cs ); |
| 502 | + |
| 503 | + $dom = new DOMDocument(); |
| 504 | + $dom->loadXML( $cs ); |
| 505 | + |
| 506 | + $changeSet = $dom->getElementsByTagName( 'changeSet' ); |
| 507 | + $CSID = null; |
| 508 | + foreach ( $changeSet as $cs ) { |
| 509 | + if ( $cs->hasAttribute( "id" ) ) { |
| 510 | + $CSID = $cs->getAttribute( 'id' ); |
| 511 | + } |
| 512 | + } |
| 513 | + wfDebugLog( 'p2p', ' -> changeSet found ' . $CSID ); |
| 514 | + } |
| 515 | + if ( is_null( $csName ) ) { |
| 516 | + wfDebugLog( 'p2p', ' - redirect to Special:ArticleAdminPage' ); |
| 517 | + utils::writeAndFlush( "<span style=\"margin-left:60px;\">no new patch</span><br/>" ); |
| 518 | + } else { |
| 519 | + wfDebugLog( 'p2p', ' - redirect to ChangeSet:' . $csName ); |
| 520 | + } |
| 521 | + }// end foreach list pullfeed |
| 522 | + utils::writeAndFlush( '<p><b>End pull</b></p>' ); |
| 523 | + $title = Title::newFromText( 'Special:ArticleAdminPage' ); |
| 524 | + $article = new Article( $title ); |
| 525 | + $article->doRedirect(); |
| 526 | + return false; |
| 527 | + } else { |
| 528 | + return true; |
| 529 | + } |
| 530 | +} |
| 531 | + |
| 532 | +/** |
| 533 | + * |
| 534 | + * @param <String> $version1 |
| 535 | + * @param <String> $version2='1.14.0' |
| 536 | + * @return <integer> |
| 537 | + */ |
| 538 | +function compareMWVersion( $version1, $version2 = '1.14.0' ) { |
| 539 | + $version1 = explode( ".", $version1 ); |
| 540 | + $version2 = explode( ".", $version2 ); |
| 541 | + |
| 542 | + if ( $version1[0] > $version2[0] ) |
| 543 | + return 1; |
| 544 | + elseif ( $version1[0] < $version2[0] ) |
| 545 | + return -1; |
| 546 | + elseif ( $version1[1] > $version2[1] ) |
| 547 | + return 1; |
| 548 | + elseif ( $version1[1] < $version2[1] ) |
| 549 | + return -1; |
| 550 | + elseif ( $version1[2] > $version2[2] ) |
| 551 | + return 1; |
| 552 | + elseif ( $version1[2] < $version2[2] ) |
| 553 | + return -1; |
| 554 | + else |
| 555 | + return 0; |
| 556 | +} |
| 557 | + |
| 558 | +/* * *************************************************************************** */ |
| 559 | +/* |
| 560 | + V0 : initial revision |
| 561 | + / \ |
| 562 | + / |
| 563 | + P1 / \P2 |
| 564 | + / |
| 565 | + / \ |
| 566 | + V1 V2:2nd edit of the same article |
| 567 | + 1st Edit |
| 568 | + */ |
| 569 | +/* * *************************************************************************** */ |
| 570 | + |
| 571 | +function attemptSave( $editpage ) { |
| 572 | + global $wgServerName, $wgScriptPath; |
| 573 | + $urlServer = 'http://' . $wgServerName . $wgScriptPath; |
| 574 | + |
| 575 | + $ns = $editpage->mTitle->getNamespace(); |
| 576 | + if ( ( $ns == PATCH ) || ( $ns == PUSHFEED ) || ( $ns == PULLFEED ) || ( $ns == CHANGESET ) |
| 577 | + |
| 578 | + )return true; |
| 579 | + |
| 580 | + $actualtext = $editpage->textbox1; // V2 |
| 581 | + |
| 582 | + $dbr = wfGetDB( DB_SLAVE ); |
| 583 | + $lastRevision = Revision::loadFromTitle( $dbr, $editpage->mTitle ); |
| 584 | + if ( is_null( $lastRevision ) ) { |
| 585 | + $conctext = ""; |
| 586 | + $rev_id = 0; |
| 587 | + } elseif ( ( $ns == NS_FILE || $ns == NS_IMAGE || $ns == NS_MEDIA ) && $lastRevision->getRawText() == "" ) { |
| 588 | + $rev_id = 0; |
| 589 | + $conctext = $lastRevision->getText(); |
| 590 | + } else { |
| 591 | + $conctext = $lastRevision->getText(); // V1 conc |
| 592 | + $rev_id = $lastRevision->getId(); |
| 593 | + } |
| 594 | + |
| 595 | + // if there is no modification on the text |
| 596 | + if ( $actualtext == $conctext ) |
| 597 | + return true; |
| 598 | + |
| 599 | + $model = manager::loadModel( $rev_id ); |
| 600 | + $logoot = new logootEngine( $model ); |
| 601 | + |
| 602 | + // get the revision with the edittime==>V0 |
| 603 | + $rev = Revision::loadFromTimestamp( $dbr, $editpage->mTitle, $editpage->edittime ); |
| 604 | + if ( is_null( $rev ) ) { |
| 605 | + $text = ""; |
| 606 | + $rev_id1 = 0; |
| 607 | + } else { |
| 608 | + $text = $rev->getText(); // VO |
| 609 | + $rev_id1 = $rev->getId(); |
| 610 | + } |
| 611 | + |
| 612 | + if ( $conctext != $text ) {// if last revision is not V0, there is editing conflict |
| 613 | +// wfDebugLog('testlog',' -> CONCURRENCE: '); |
| 614 | +// wfDebugLog('testlog',' -> +'.$conctext.'+('.$rev_id.') ts '.$lastRevision->getTimestamp()); |
| 615 | +// wfDebugLog('testlog',' -> +'.$text.'+('.$rev_id1.') ts '.$editpage->edittime.' '.$rev->getTimestamp()); |
| 616 | + $model1 = manager::loadModel( $rev_id1 ); |
| 617 | + $logoot1 = new logootEngine( $model1 ); |
| 618 | + $listOp1 = $logoot1->generate( $text, $actualtext ); |
| 619 | + // creation Patch P2 |
| 620 | + $tmp = serialize( $listOp1 ); |
| 621 | + $patch = new Patch( false, false, $listOp1, $urlServer, $rev_id1 ); |
| 622 | + if ( $editpage->mTitle->getNamespace() == 0 ) |
| 623 | + $title = $editpage->mTitle->getText(); |
| 624 | + else |
| 625 | + $title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText(); |
| 626 | + // integration: diffs between VO and V2 into V1 |
| 627 | + |
| 628 | + $modelAfterIntegrate = $logoot->integrate( $listOp1 ); |
| 629 | + } else {// no edition conflict |
| 630 | + $listOp = $logoot->generate( $conctext, $actualtext ); |
| 631 | + $modelAfterIntegrate = $logoot->getModel(); |
| 632 | + $tmp = serialize( $listOp ); |
| 633 | + $patch = new Patch( false, false, $listOp, $urlServer, $rev_id1 ); |
| 634 | + if ( $editpage->mTitle->getNamespace() == 0 ) |
| 635 | + $title = $editpage->mTitle->getText(); |
| 636 | + else |
| 637 | + $title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText(); |
| 638 | + } |
| 639 | + |
| 640 | + $revId = utils::getNewArticleRevId(); |
| 641 | + wfDebugLog( 'p2p', ' -> store model rev : ' . $revId . ' session ' . session_id() . ' model ' . $modelAfterIntegrate->getText() ); |
| 642 | + manager::storeModel( $revId + 1, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0 ); |
| 643 | + |
| 644 | + $patch->storePage( $title, $revId + 1 ); // stores the patch in a wikipage |
| 645 | + $editpage->textbox1 = $modelAfterIntegrate->getText(); |
| 646 | + return true; |
| 647 | +} |
| 648 | + |
| 649 | +function uploadComplete( $image ) { |
| 650 | + global $wgServerName, $wgScriptPath, $wgServer, $wgVersion; |
| 651 | + $urlServer = 'http://' . $wgServerName . $wgScriptPath; |
| 652 | + |
| 653 | + // $classe = get_class($image); |
| 654 | + if ( compareMWVersion( $wgVersion, '1.16.0' ) == -1 ) { |
| 655 | + $localfile = $image->mLocalFile; |
| 656 | + } else { |
| 657 | + |
| 658 | + $localfile = $image->getLocalFile(); |
| 659 | + } |
| 660 | + $path = utils::prepareString( $localfile->mime, $localfile->size, $wgServer . urldecode( $localfile->url ) ); |
| 661 | + if ( !file_exists( $path ) ) { |
| 662 | + $dbr = wfGetDB( DB_SLAVE ); |
| 663 | + $lastRevision = Revision::loadFromTitle( $dbr, $localfile->getTitle() ); |
| 664 | + if ( $lastRevision->getPrevious() == null ) { |
| 665 | + $rev_id = 0; |
| 666 | + } else { |
| 667 | + $rev_id = $lastRevision->getPrevious()->getId(); |
| 668 | + } |
| 669 | + $revID = $lastRevision->getId(); |
| 670 | + $model = manager::loadModel( $rev_id ); |
| 671 | + $patch = new Patch( false, true, null, $urlServer, $rev_id, null, null, null, $localfile->mime, $localfile->size, urldecode( $localfile->url ), null ); |
| 672 | + $patch->storePage( $localfile->getTitle(), $revID ); // stores the patch in a wikipage |
| 673 | + manager::storeModel( $revID, $sessionId = session_id(), $model, $blobCB = 0 ); |
| 674 | + } |
| 675 | + return true; |
| 676 | +} |
| 677 | + |
| 678 | +function dsmwgSetupFunction() { |
| 679 | + global $smwgNamespacesWithSemanticLinks; |
| 680 | + |
| 681 | + $smwgNamespacesWithSemanticLinks += array( |
| 682 | + PATCH => true, |
| 683 | + PUSHFEED => true, |
| 684 | + PULLFEED => true, |
| 685 | + CHANGESET => true |
| 686 | + ); |
| 687 | + |
| 688 | + if ( defined( 'SRF_VERSION' ) ) { |
| 689 | + global $wgDSMWExhibits; |
| 690 | + if ( !is_object( $wgDSMWExhibits ) ) { |
| 691 | + $wgDSMWExhibits = new DSMWExhibits(); |
| 692 | + } |
| 693 | + } |
| 694 | +} |
Property changes on: trunk/extensions/DSMW/includes/DSMW_GlobalFunctions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 695 | + native |
Index: trunk/extensions/DSMW/DSMW.i18n.php |
— | — | @@ -9,8 +9,8 @@ |
10 | 10 | |
11 | 11 | $messages = array(); |
12 | 12 | |
13 | | -/** |
14 | | - * English |
| 13 | +/** English |
| 14 | + * @author Jeroen De Dauw |
15 | 15 | */ |
16 | 16 | $messages['en'] = array( |
17 | 17 | 'dsmw-desc' => 'Allows to create a network of Semantic MediaWiki servers that share common semantic wiki pages. ([http://www.dsmw.org www.dsmw.org])', |