-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDSMW.php
More file actions
1116 lines (965 loc) · 44.9 KB
/
DSMW.php
File metadata and controls
1116 lines (965 loc) · 44.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @copyright 2009 INRIA-LORIA-ECOO project
* @author jean-philippe muller
*/
if (!defined('MEDIAWIKI')) {
exit;
}
require_once "$IP/includes/GlobalFunctions.php";
$wgDSMWIP = dirname(__FILE__);
if (!defined('LOGOOTMODE')) {
//define('LOGOOTMODE', 'STD');
define('LOGOOTMODE', 'PLS');
}
if (!defined('DIGIT')) {
define('DIGIT', 3);
}
if (!defined('INT_MAX')) {
define('INT_MAX', (integer) pow(10, DIGIT));
}
if (!defined('INT_MIN')) {
define('INT_MIN', 0);
}
if (!defined('BASE')) {
define('BASE', (integer) (INT_MAX - INT_MIN));
}
if (!defined('CLOCK_MAX')) {
define('CLOCK_MAX', "100000000000000000000000");
}
if (!defined('CLOCK_MIN')) {
define('CLOCK_MIN', "0");
}
if (!defined('SESSION_MAX')) {
define('SESSION_MAX', "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");//.CLOCK_MAX);
//050F550EB44F6DE53333AE460EE85396
}
if (!defined('SESSION_MIN')) {
define('SESSION_MIN', "0");
}
if (!defined('BOUNDARY')) {
define('BOUNDARY', (integer) pow(10, DIGIT / 2));
}
require_once("$wgDSMWIP/includes/DSMWButton.php");
require_once("$wgDSMWIP/includes/Ajax/include.php");
require_once 'includes/SemanticFunctions.php';
require_once 'includes/IntegrationFunctions.php';
///////////////BEN///////////////
require_once 'includes/UndoIntegrationFunctions.php';
///////////////BEN///////////////
define('DSMW_VERSION', '1.2');
$wgSpecialPageGroups['ArticleAdminPage'] = 'dsmw_group';
$wgSpecialPageGroups['DSMWAdmin'] = 'dsmw_group';
$wgSpecialPageGroups['DSMWGeneralExhibits'] = 'dsmw_group';
/////////////////////////BEN/////////////////////////
$wgSpecialPageGroups['DSMWUndoAdmin'] = 'dsmw_group';
/////////////////////////BEN/////////////////////////
$wgGroupPermissions['*']['upload_by_url'] = true;
$wgGroupPermissions['*']['reupload'] = true;
$wgGroupPermissions['*']['upload'] = true;
$wgAllowCopyUploads = true;
$wgExtensionMessagesFiles['DSMW'] = $wgDSMWIP . '/languages/DSMW_Messages.php';
$wgHooks['UnknownAction'][] = 'onUnknownAction';
//$wgHooks['MediaWikiPerformAction'][] = 'performAction';
$wgHooks['EditPage::attemptSave'][] = 'attemptSave';
$wgHooks['EditPageBeforeConflictDiff'][] = 'conflict';
$wgHooks['UploadComplete'][] = 'uploadComplete';
$wgAutoloadClasses['logootEngine'] = "$wgDSMWIP/logootComponent/logootEngine.php";
$wgAutoloadClasses['logootPlusEngine'] = "$wgDSMWIP/logootComponent/logootPlusEngine.php";
$wgAutoloadClasses['logoot'] = "$wgDSMWIP/logootComponent/logoot.php";
$wgAutoloadClasses['logootPlus'] = "$wgDSMWIP/logootComponent/logootPlus.php";
$wgAutoloadClasses['LogootPatch'] = "$wgDSMWIP/logootComponent/LogootPatch.php";
$wgAutoloadClasses['LogootId'] = "$wgDSMWIP/logootComponent/LogootId.php";
$wgAutoloadClasses['LogootPosition'] =
"$wgDSMWIP/logootComponent/LogootPosition.php";
$wgAutoloadClasses['Diff1']
= $wgAutoloadClasses['_DiffEngine1']
= $wgAutoloadClasses['_DiffOp1']
= $wgAutoloadClasses['_DiffOp_Add1']
= $wgAutoloadClasses['_DiffOp_Change1']
= $wgAutoloadClasses['_DiffOp_Copy1']
= $wgAutoloadClasses['_DiffOp_Delete1']
= "$wgDSMWIP/logootComponent/DiffEngine.php";
$wgAutoloadClasses['LogootOperation'] = "$wgDSMWIP/logootComponent/LogootOperation.php";
$wgAutoloadClasses['LogootPlusOperation'] = "$wgDSMWIP/logootComponent/LogootPlusOperation.php";
$wgAutoloadClasses['LogootIns'] = "$wgDSMWIP/logootComponent/LogootIns.php";
$wgAutoloadClasses['LogootDel'] = "$wgDSMWIP/logootComponent/LogootDel.php";
$wgAutoloadClasses['LogootPlusIns'] = "$wgDSMWIP/logootComponent/LogootPlusIns.php";
$wgAutoloadClasses['LogootPlusDel'] = "$wgDSMWIP/logootComponent/LogootPlusDel.php";
$wgAutoloadClasses['boModel'] = "$wgDSMWIP/logootModel/boModel.php";
$wgAutoloadClasses['boModelPlus'] = "$wgDSMWIP/logootModel/boModelPlus.php";
$wgAutoloadClasses['dao'] = "$wgDSMWIP/logootModel/dao.php";
$wgAutoloadClasses['manager'] = "$wgDSMWIP/logootModel/manager.php";
$wgAutoloadClasses['Patch'] = "$wgDSMWIP/patch/Patch.php";
$wgAutoloadClasses['persistentClock'] = "$wgDSMWIP/clockEngine/persistentClock.php";
$wgAutoloadClasses['ApiQueryPatch'] = "$wgDSMWIP/api/ApiQueryPatch.php";
$wgAutoloadClasses['ApiQueryChangeSet'] = "$wgDSMWIP/api/ApiQueryChangeSet.php";
$wgAutoloadClasses['ApiUpload'] = "$wgDSMWIP/api/upload/ApiUpload.php";
$wgAutoloadClasses['ApiQueryImageInfo'] = "$wgDSMWIP/api/upload/ApiQueryImageInfo.php";
$wgAutoloadClasses['ApiPatchPush'] = "$wgDSMWIP/api/ApiPatchPush.php";
$wgAutoloadClasses['utils'] = "$wgDSMWIP/files/utils.php";
$wgAutoloadClasses['Math_BigInteger'] = "$wgDSMWIP/logootComponent/Math/BigInteger.php";
$wgAutoloadClasses['DSMWDBHelpers'] = "$wgDSMWIP/db/DSMWDBHelpers.php";
///// Register Jobs
$wgJobClasses['DSMWUpdateJob'] = 'DSMWUpdateJob';
$wgAutoloadClasses['DSMWUpdateJob'] = "$wgDSMWIP/jobs/DSMWUpdateJob.php";
$wgJobClasses['DSMWPropertyTypeJob'] = 'DSMWPropertyTypeJob';
$wgAutoloadClasses['DSMWPropertyTypeJob'] = "$wgDSMWIP/jobs/DSMWPropertyTypeJob.php";
$wgAutoloadClasses['DSMWSiteId'] = "$wgDSMWIP/includes/DSMWSiteId.php";
$wgAutoloadClasses['DSMWExhibits'] = "$wgDSMWIP/includes/DSMWExhibits.php";
$wgExtensionFunctions[] = 'dsmwgSetupFunction';
///// credits (see "Special:Version") /////
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'Distributed Semantic MediaWiki',
'version' => DSMW_VERSION,
'author' => "[http://www.loria.fr/~mullejea Jean–Philippe Muller], [http://www.loria.fr/~molli Pascal Molli], [http://www.loria.fr/~skaf Hala Skaf–Molli],<br>[http://www.loria.fr/~canals Gérôme Canals], [http://www.loria.fr/~rahalcha Charbel Rahal], [http://www.loria.fr/~weiss Stéphane Weiss],
[http://www.univ-nantes.fr/~desmontils-e Emmanuel Desmontils], and [http://m3p.gforge.inria.fr/pmwiki/pmwiki.php?n=Site.Team others].",
'url' => 'http://momo54.github.com/DSMW',
'description' => 'Allows to create a network of Semantic MediaWiki servers that share common semantic wiki pages. ([http://momo54.github.com/DSMW http://momo54.github.com/DSMW])',
);
global $wgVersion;
if (compareMWVersion($wgVersion) == -1) {
$wgApiQueryMetaModules = array('patch' => 'ApiQueryPatch', 'changeSet' => 'ApiQueryChangeSet',
'patchPushed' => 'ApiPatchPush');
} else {
//global $wgAPIMetaModules;
$wgAPIMetaModules = array('patch' => 'ApiQueryPatch', 'changeSet' => 'ApiQueryChangeSet',
'patchPushed' => 'ApiPatchPush');
}
if (compareMWVersion($wgVersion, '1.16.0') == -1) {
$wgAPIModules = $wgAPIModules + array('upload' => 'ApiUpload',
'ApiQueryImageInfo' => 'ApiQueryImageInfo',);
$wgAutoloadLocalClasses = $wgAutoloadLocalClasses + array(
'UploadBase' => $wgDSMWIP . '/api/upload/UploadBase.php',
'UploadFromFile' => $wgDSMWIP . '/api/upload/UploadFromFile.php',
'UploadFromStash' => $wgDSMWIP . '/api/upload/UploadFromStash.php',
'UploadFromUrl' => $wgDSMWIP . '/api/upload/UploadFromUrl.php');
}
function conflict(&$editor, &$out) {
$conctext = $editor->textbox1;
$actualtext = $editor->textbox2;
$initialtext = $editor->getBaseRevision()->mText;
$editor->mArticle->updateArticle($actualtext, $editor->summary, $editor->minoredit,
$editor->watchthis, $bot = false, $sectionanchor = '');
return true;
}
//function performAction($output, $article, $title, $user, $request, $wiki) {
//// $dbr = wfGetDB( DB_SLAVE );
//// $lastRevision = Revision::loadFromTitle($dbr, $title);
//// $rawtext = $lastRevision->getRawText();
//
// //$page = "The_angel's_game";
//
//
//// $page="Home";
//// $arrayres = utils::getDependencies($page, true, true, true, true);
//// $test;
//
// global $wgRequest;
// $form = new UploadForm( $wgRequest );
// $form->mDesiredDestName = 'Lego1.png';
// $form->execute();
//
// return true;
//}
/**
* MW Hook used to redirect to page creation (pushfeed, pullfeed, changeset),
* to forms or to push/pull action testing the action param
*
*
* @global <Object> $wgOut
* @param <Object> $action
* @param <Object> $article
* @return <boolean>
*/
function onUnknownAction($action, $article) {
global $wgOut, $wgServerName, $wgScriptPath, $wgUser, $wgScriptExtension, $wgDSMWIP;
$urlServer = 'http://' . $wgServerName . $wgScriptPath . "/index{$wgScriptExtension}";
$urlAjax = 'http://'.$wgServerName.$wgScriptPath;
//////////pull form page////////
if (isset($_GET['action']) && $_GET['action'] == 'addpullpage') {
wfDebugLog('p2p', '@@@@@@@@@@@@@@@@@@ addPullPage ');
$newtext = "Add a new site:
<div id='dsmw' style=\"color:green;\"></div>
{{#form:action=" . $urlServer . "?action=pullpage|method=POST|
PushFeed Url: {{#input:type=button|value=Url test|onClick=
var url = document.getElementsByName('url')[0].value;
if(url.indexOf('PushFeed')==-1){
alert('No valid PushFeed syntax, see example.');
}else{
var urlTmp = url.substring(0,url.indexOf('PushFeed'));
//alert(urlTmp);
var pos1 = urlTmp.indexOf('index.php');
//alert(pos1);
var pushUrl='';
if(pos1!=-1){
pushUrl = urlTmp.substring(0,pos1);
//alert('if');
}else{
pushUrl = urlTmp;
//alert('else');
}
//alert(pushUrl);
//alert(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml');
var xhr_object = null;
if(window.XMLHttpRequest) // Firefox
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // Internet Explorer
xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
else {
alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest...');
return;
}
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);}
catch(e){
//alert('There is no DSMW Server responding at this URL');
document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';
document.getElementById('dsmw').style.color = 'red';
}
xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 4) {
if(xhr_object.statusText=='OK'){
if(xhr_object.responseText == 'true'){ //alert('URL valid, there is a DSMW Server responding');
document.getElementById('dsmw').innerHTML = 'URL valid, there is a DSMW Server responding!';
document.getElementById('dsmw').style.color = 'green';
}
else{ //alert('There is no DSMW Server responding at this URL');
document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';
document.getElementById('dsmw').style.color = 'red';
}
}
else{
//alert('There is no DSMW Server responding at this URL');
document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';
document.getElementById('dsmw').style.color = 'red';
}
}
}
xhr_object.send(null);
}
}}<br> {{#input:type=text|name=url|size=50}} <b>e.g. http://server/path/index.php?title=PushFeed:PushName</b><br>
PullFeed Name: <br> {{#input:type=text|name=pullname}}<br>
{{#input:type=submit|value=ADD}}
}}";
//if article doesn't exist insertNewArticle
if ($article->mTitle->exists()) {
$article->updateArticle($newtext, $summary = "", false, false);
} else {
$article->insertNewArticle($newtext, $summary = "", false, false);
}
$article->doRedirect();
return false;
}
/////////push form page////////
elseif (isset($_GET['action']) && $_GET['action'] == 'addpushpage') {
wfDebugLog('p2p', '@@@@@@@@@@@@@@@@ addPushPage');
$specialAsk = $urlServer . '?title=Special:Ask';
$newtext = "Add a new pushfeed:
{{#form:action=" . $urlServer . "?action=pushpage|method=POST|
PushFeed Name: <br> {{#input:class=test|name=name|type=text|onKeyUp=test('$urlServer');}}<div style=\"display:inline; \" id=\"state\" ></div><br />
Request: {{#input:type=button|value=Test your query|title=click here to test your query results|onClick=
var query = document.getElementsByName('keyword')[0].value;
var query1 = encodeURI(query);
window.open('" . $specialAsk . "&q='+query1+'&eq=yes&p%5Bformat%5D=broadtable','querywindow','menubar=no, status=no, scrollbars=yes, menubar=no, width=1000, height=900');}}
<br>{{#input:type=textarea|cols=30 | style=width:auto |rows=2|name=keyword}} <b>e.g. [[Category:city]][[locatedIn::France]]</b><br>
{{#input:type=submit|value=ADD}}
}}";
$article->doEdit($newtext, $summary = "");
$article->doRedirect();
return false;
}
///////PushFeed page////////
elseif (isset($_GET['action']) && $_GET['action'] == 'pushpage') {
//$url = $_POST['url'];//pas url mais changesetId
wfDebugLog('p2p', '@@@@@@@@@@@@@@@@@ Create new push ' . $_POST['name'] . ' with ' . $_POST['keyword']);
$name = $_POST['name'];
$request = $_POST['keyword'];
$stringReq = utils::encodeRequest($request); //avoid "semantic injection" :))
//addPushSite($url, $name, $request);
$newtext = "
[[Special:ArticleAdminPage|DSMW Admin functions]]
==Features==
[[name::PushFeed:" . $name . "| ]]
'''Semantic query:''' [[hasSemanticQuery::" . $stringReq . "| ]]<nowiki>" . $request . "</nowiki>
'''Pages concerned:'''
{{#ask: " . $request . "}}
[[deleted::false| ]]
==Actions==
{{#input:type=ajax|value=PUSH|onClick=pushpull('" . $urlServer . "','PushFeed:" . $name . "', 'onpush');}}
The \"PUSH\" action publishes the (unpublished) modifications of the articles listed above.
== PUSH Progress : ==
<div id=\"state\" ></div><br />
";
wfDebugLog('p2p', ' -> push page contains : ' . $newtext);
$title = Title::newFromText($_POST['name'], PUSHFEED);
$article = new Article($title);
$edit = $article->doEdit($newtext, $summary = "");
$article->doRedirect();
return false;
}
///////onpush action////////
elseif (isset($_POST['action']) && $_POST['action'] == 'onpush') {
wfDebugLog('p2p', '@@@@@@@@@@@@ onpush');
/* In case we push directly from an article page */
if (isset($_POST['page']) && isset($_POST['request'])) {
$articlename = Title::newFromText($_POST['name']);
if (!$articlename->exists()) {
$result = utils::createPushFeed($_POST['name'], $_POST['request']);
utils::writeAndFlush("Create push <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=".$_POST['name'].">" . $_POST['name'] . "</a>");
if ($result == false) {
throw new MWException(
__METHOD__ . ': no Pushfeed created in utils:: createPushFeed:
name: ' . $_POST['name'] . ' request' . $_POST['request']);
}
}
}
wfDebugLog('p2p', 'push on ');
$patches = array();
$tmpPatches = array();
if (isset($_POST['name'])) {
$name1 = $_POST['name'];
if (!is_array($name1))
$name1 = array($name1);
foreach ($name1 as $push) {
wfDebugLog('p2p', ' - ' . $push);
}
} else {
$name1="";
}
if ($name1 == "") {
utils::writeAndFlush('<p><b>No pushfeed selected!</b></p>');
$title = Title::newFromText('Special:ArticleAdminPage');
$article = new Article($title);
$article->doRedirect();
return false;
}
//
// Push Starting !!
//
utils::writeAndFlush('<p><b>Start push </b></p>');
foreach ($name1 as $name) {
utils::writeAndFlush("<span style=\"margin-left:30px;\">begin push: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=$name>" . $name . "</a></span> <br/>");
$patches = array(); //// for each pushfeed name==> push
wfDebugLog('p2p', ' -> pushname ' . $name);
$request = getPushFeedRequest($name);
$previousCSID = getHasPushHead($name);
if ($previousCSID == false) {
$previousCSID = "none";
}
wfDebugLog('p2p', ' ->pushrequest ' . $request);
wfDebugLog('p2p', ' ->pushHead : ' . $previousCSID);
$CSID = utils::generateID(); //changesetID
if ($request == false) {
$outtext = '<p><b>No semantic request found!</b></p> <a href="' . $_SERVER['HTTP_REFERER'] . '">back</a>';
$wgOut->addHTML($outtext);
return false;
}
$pages = getRequestedPages($request); //ce sont des pages et non des patches
foreach ($pages as $page) {
wfDebugLog('p2p', ' ->requested page ' . $page);
$page = str_replace('"', '', $page);
$request1 = '[[Patch:+]][[onPage::' . $page . ']]';
$tmpPatches = utils::orderPatchByPrevious($page);
if (!is_array($tmpPatches))
throw new MWException(__METHOD__ . ': $tmpPatches is not an array');
$patches = array_merge($patches, $tmpPatches);
wfDebugLog('p2p', ' -> ' . count($tmpPatches) . 'patchs were found for the page ' . $page);
}
wfDebugLog('p2p', ' -> ' . count($patches) . ' patchs were found for the pushfeed ' . $name);
$published = getPublishedPatches($name);
$unpublished = array_diff($patches, $published); /* unpublished = patches-published */
wfDebugLog('p2p', ' -> ' . count($published) . ' patchs were published for the pushfeed ' . $name . ' and ' . count($unpublished) . ' unpublished patchs');
if (empty($unpublished)) {
wfDebugLog('p2p', ' -> no unpublished patch');
utils::writeAndFlush("<span style=\"margin-left:60px;\">no unpublished patch</span><br/>");
//return false; //If there is no unpublished patch
} else {
utils::writeAndFlush("<span style=\"margin-left:60px;\">".count($unpublished)." unpublished patch</span><br/>");
$pos = strrpos($CSID, ":"); //NS removing
if ($pos === false) {
// not found...
$articleName = $CSID;
$CSID = "ChangeSet:" . $articleName;
} else {
$articleName = substr($CSID, 0, $pos + 1);
$CSID = "ChangeSet:" . $articleName;
}
$newtext = "
[[Special:ArticleAdminPage|DSMW Admin functions]]
==Features==
[[changeSetID::" . $CSID . "| ]]
'''Date:''' " . date(DATE_RFC822) . "
'''User:''' " . $wgUser->getName() . "
This ChangeSet is in : [[inPushFeed::" . $name . "]]<br>
==Published patches==
{| class=\"wikitable\" border=\"1\" style=\"text-align:left; width:30%;\"
|-
!bgcolor=#c0e8f0 scope=col | Patch
|-
";
//wfDebugLog('p2p',' -> count unpublished patch '.count($unpublished));
foreach ($unpublished as $patch) {
wfDebugLog('p2p', ' -> unpublished patch ' . $patch);
$newtext.="|[[hasPatch::" . $patch . "]]
|-
";
}
$newtext.="
|}";
$newtext.="
==Previous ChangeSet==
[[previousChangeSet::" . $previousCSID . "]]
";
$update = updatePushFeed($name, $CSID);
if ($update == true) {// update the "hasPushHead" value successful
$title = Title::newFromText($articleName, CHANGESET);
$article = new Article($title);
$article->doEdit($newtext, $summary = "");
} else {
$outtext = '<p><b>PushFeed has not been updated!</b></p>';
$wgOut->addHTML($outtext);
}
}
}//end foreach pushfeed list
utils::writeAndFlush('<p><b>End push</b></p>');
$title = Title::newFromText('Special:ArticleAdminPage');
$article = new Article($title);
$article->doRedirect();
return false;
}
//////////PullFeed page////////
elseif (isset($_GET['action']) && $_GET['action'] == 'pullpage') {
//$url = rtrim($_POST['url'], "/"); //removes the final "/" if there is one
$urlTmp = $_POST['url'];
if (utils::isValidURL($urlTmp) == false)
throw new MWException(__METHOD__ . ': ' . $urlTmp . ' seems not to be an url'); //throws an exception if $url is invalid
$res = utils::parsePushURL($urlTmp);
if ($res === false || empty($res))
throw new MWException(__METHOD__ . ': URL format problem');
$pushname = $res[0];
$url = $res[1];
//$pushname = $_POST['pushname'];
$pullname = $_POST['pullname'];
wfDebugLog('p2p','@@@@@@@@@@@@@ Create pull '.$pullname.' with pushName '.$pushname.' on '.$url);
$newtext = "
[[Special:ArticleAdminPage|DSMW Admin functions]]
==Features==
[[name::PullFeed:" . $pullname . "| ]]
'''URL of the DSMW PushServer:''' [[pushFeedServer::" . $url . "]]<br>
'''PushFeed name:''' [[pushFeedName::PushFeed:" . $pushname . "]]
[[deleted::false| ]]
==Actions==
{{#input:type=ajax|value=PULL|onClick=pushpull('" . $urlServer . "','PullFeed:" . $pullname . "','onpull');}}
The \"PULL\" action gets the modifications published in the PushFeed of the PushFeedServer above.
== PULL Progress : ==
<div id=\"state\" ></div><br />
";
$title = Title::newFromText($pullname, PULLFEED);
$article = new Article($title);
$article->doEdit($newtext, $summary = "");
$article->doRedirect();
return false;
}
//////////OnPull/////////////
elseif (isset($_POST['action']) && $_POST['action'] == 'onpull') {
if (isset($_POST['name'])) {
$name1 = $_POST['name'];
wfDebugLog('p2p', '@@@@@@@@@@@@@ pull on ');
if (!is_array($name1))
$name1 = array($name1);
}
else
$name1="";
if ($name1 == "") {
utils::writeAndFlush('<p><b>No pullfeed selected!</b></p> ');
$title = Title::newFromText('Special:ArticleAdminPage');
$article = new Article($title);
$article->doEdit('', $summary = "");
$article->doRedirect();
return false;
}
//$name = $name1[0];//with NS
utils::writeAndFlush('<p><b>Start pull</b></p>');
foreach ($name1 as $name) {// for each pullfeed name==> pull
utils::writeAndFlush("<span style=\"margin-left:30px;\">begin pull: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=$name>" . $name . "</a></span> <br/>");
wfDebugLog('p2p', ' -> pull : ' . $name);
// $previousCSID = getPreviousPulledCSID($name);
// if($previousCSID==false) {
// $previousCSID = "none";
// }
$previousCSID = getHasPullHead($name);
if ($previousCSID == false) {
$previousCSID = "none";
}
wfDebugLog('p2p', ' -> pullHead : ' . $previousCSID);
$relatedPushServer = getPushURL($name);
if (is_null($relatedPushServer)
)throw new MWException(__METHOD__ . ': no relatedPushServer url');
$namePush = getPushName($name);
$namePush = str_replace(' ', '_', $namePush);
wfDebugLog('p2p', ' -> pushServer : ' . $relatedPushServer);
wfDebugLog('p2p', ' -> pushName : ' . $namePush);
if (is_null($namePush)
)throw new MWException(__METHOD__ . ': no PushName');
//split NS and name
preg_match("/^(.+?)_*:_*(.*)$/S", $namePush, $m);
$nameWithoutNS = $m[2];
//$url = $relatedPushServer.'/api.php?action=query&meta=changeSet&cspushName='.$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml';
//$url = $relatedPushServer."/api{$wgScriptExtension}?action=query&meta=changeSet&cspushName=".$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml';
wfDebugLog('p2p', ' -> request ChangeSet : '.$relatedPushServer.'/api.php?action=query&meta=changeSet&cspushName='.$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml');
$cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
/* test if it is a xml file. If not, the server is not reachable via the url
* Then we try to reach it with the .php5 extension
*/
if (strpos($cs, "<?xml version=\"1.0\"?>") === false) {
$cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
}
if (strpos($cs, "<?xml version=\"1.0\"?>") === false)
$cs = false;
if ($cs === false)
throw new MWException(__METHOD__ . ': Cannot connect to Push Server (ChangeSet API)');
$cs = trim($cs);
$dom = new DOMDocument();
$dom->loadXML($cs);
$changeSet = $dom->getElementsByTagName('changeSet');
$CSID = null;
$csName = null;
foreach ($changeSet as $cs) {
if ($cs->hasAttribute("id")) {
$CSID = $cs->getAttribute('id');
$csName = $CSID;
}
}
wfDebugLog('p2p', ' -> changeSet found ' . $CSID);
while ($CSID != null) {
//if(!utils::pageExist($CSID)) {
$listPatch = null;
$patchs = $dom->getElementsByTagName('patch');
foreach ($patchs as $p) {
wfDebugLog('p2p', ' -> patch ' . $p->firstChild->nodeValue);
$listPatch[] = $p->firstChild->nodeValue;
}
// $CSID = substr($CSID,strlen('changeSet:'));
utils::createChangeSetPull($CSID, $name, $previousCSID, $listPatch);
integrate($CSID, $listPatch, $relatedPushServer, $csName);
updatePullFeed($name, $CSID);
// }
$previousCSID = $CSID;
wfDebugLog('p2p', ' -> request ChangeSet : ' . $relatedPushServer . '/api.php?action=query&meta=changeSet&cspushName=' . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
$cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
/* test if it is a xml file. If not, the server is not reachable via the url
* Then we try to reach it with the .php5 extension
*/
if (strpos($cs, "<?xml version=\"1.0\"?>") === false) {
$cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
}
if (strpos($cs, "<?xml version=\"1.0\"?>") === false)
$cs = false;
if ($cs === false)
throw new MWException(__METHOD__ . ': Cannot connect to Push Server (ChangeSet API)');
$cs = trim($cs);
$dom = new DOMDocument();
$dom->loadXML($cs);
$changeSet = $dom->getElementsByTagName('changeSet');
$CSID = null;
foreach ($changeSet as $cs) {
if ($cs->hasAttribute("id")) {
$CSID = $cs->getAttribute('id');
}
}
wfDebugLog('p2p', ' -> changeSet found ' . $CSID);
}
if (is_null($csName)) {
wfDebugLog('p2p', ' - redirect to Special:ArticleAdminPage');
utils::writeAndFlush("<span style=\"margin-left:60px;\">no new patch</span><br/>");
} else {
wfDebugLog('p2p', ' - redirect to ChangeSet:' . $csName);
}
}//end foreach list pullfeed
utils::writeAndFlush('<p><b>End pull</b></p>');
$title = Title::newFromText('Special:ArticleAdminPage');
$article = new Article($title);
$article->doRedirect();
return false;
}
/////////////OnUndo///BEN////////////////////////////////////////////////////
elseif (isset($_POST['action']) && $_POST['action'] == 'onundo') {
$patches = array();
$urlServer = 'http://'.$wgServerName.$wgScriptPath;
$title = 'Special:DSMWUndoAdmin';
//if it has been called to display the patches researched
if (isset($_POST['name']) && $_POST['name']=="")
{
$output = '';
$reqs = json_decode($_POST['req']);
$patches = utils::getSemanticQuery($reqs[0].$reqs[1].$reqs[2],"?onPage\n?Modification date\n?previous");
$output .= '
<div style="overflow:auto;">
<table style="border-bottom: 2px solid #000;">
<tr>
';
if ($patches===false)
{
$output .= 'An appropriate Message of error';//BEN//
echo($output);
return true;
}
else
{
$count = $patches->getCount();
if ($count<1)
{
$output .= '<td><b>No Patch corresponding to this request</b></td></tr></table></div>';
}
else
{
$output .= '
<td><b>Page</b></td>
<td><b>|Modification Date</b></td>
<td><b>|Patch ID</b></td>
<td><b>|Operations</b></td>
</tr>
<tr>';
//order the patchs in reverse order of age
//bubblesort...(could be improved)
//We will first extract the date of edition of the different patchs and the associated "text" to be displayed
//as the object SMWQueryResult seems to not being able to be scanned more than once
//then we will order the dates and "simultaneously" make the same changes onto the order of the "text"
for( $i=0 ; $i<$count ; $i++ )
{
//patch
$row = $patches->getNext();
if ($row===false) {break;}
$rowS = $row[1];//OnPage
$colS = $rowS->getContent();
$objectS = $colS[0];
$wikivalueS = $objectS->getWikiValue();
$tmpOutput = '<td>'.$wikivalueS.'</td>';//we use = instead of .= to "reset" the variable
$rowT = $row[2];//Modification date
$colT = $rowT->getContent();
$objectT = $colT[0];
$wikivalueT = $objectT->getWikiValue();
$tmpKey = $wikivalueT;//we will use the date as a key
$tmpOutput .= '<td>'.$wikivalueT.'</td>';
$rowR = $row[0];//PatchID
$colR = $rowR->getContent();
$objectR = $colR[0];
$wikivalueR = $objectR->getWikiValue();
$tmpOutput .= '<td>(<a href="'.$_SERVER['PHP_SELF'].'?title='.$wikivalueR.'">'.$wikivalueR.'</a>)</td>';
//actions of the patch
$results = array();
$op = utils::getSemanticQuery('[[patchID::'.$wikivalueR.']]','?hasOperation');
$nbOp = $op->getCount();
for($j=0; $j<$nbOp; $j++)
{
$tmpRow = $op->getNext();
if ($tmpRow===false) break;
$tmpRow = $tmpRow[1];
$tmpCol = $tmpRow->getContent();//SMWResultArray object
foreach($tmpCol as $object) {//SMWDataValue object
$tmpWikiValue = $object->getWikiValue();
$results[] = $tmpWikiValue;
}
}
$countOp = utils::countOperation($results);//old code passed $op parameter
$tmpOutput .= '<td>('.$countOp['insert'].' insert, '.$countOp['delete'].' delete)</td>';
$tmpOutput .= '<td><input type="checkbox" name="checkbox[]" id="check';
$tmpArrayToSort[$tmpKey] = array($tmpOutput,'" value="'.$wikivalueR.'"/></td></tr>');//we use that trick to be able to have indices in the order of the display once ordered
}
uksort($tmpArrayToSort, "cmpDateStr");
$tmpArraySorted = array_values($tmpArrayToSort);//the new array only contains the values with an access by numbers
for($i=0 ; $i<$count ; $i++)
{
$output .= $tmpArraySorted[$i][0];
$output .= $i;
$output .= $tmpArraySorted[$i][1];
}
echo($output);//we must echo the table so we can access it using the DOM
$output='';
$output .= '</table></div>';
$output .= '<p><h2>Actions:</h2></p>';
$url = "http://".$wgServerName.$wgScriptPath."/index{$wgScriptExtension}";
$output .= '
<form name="formUndo">
<table >
<tr>
<td> <input type="button" value="UNDO" onClick="undopatchs(\''.$url.'\',\''.$title.'\','.$count.');"></input></td>
<td>This action will undo the selected patchs.</td>
</tr>
</table>
</form>
<div id="undostatus" style="display: none; width: 100%; clear: both;" >
<a name="UNDO_Progress_:" id="UNDO_Progress_:"></a><h2> <span class="mw-headline"> UNDO Progress : </span></h2>
<div id="stateundo" ></div><br />
</div>
';
}
}
utils::writeAndFlush($output);
$title = Title::newFromText($_POST['page']);
$article = new Article($title);
$article->doEdit('', $summary = "");
$article->doRedirect();
return false;
}
else
{
//Warning: use of the lazy evaluation
//if name is empty its value is []
if (isset($_POST['name']) && !($_POST['name'][1]==']')) {
$patches = json_decode($_POST['name'], true);
wfDebugLog('p2p', 'undo on ');
}
else {
$patches = "";
}
if ($patches == "") {
utils::writeAndFlush('<p><b>No patch selected!</b></p> ');
$title = Title::newFromText($_POST['page']);
$article = new Article($title);
$article->doEdit('', $summary = "");
$article->doRedirect();
return false; //WARNING this will brutally interrupt the execution of the function
}
utils::writeAndFlush('<p><b>Start undo</b></p>');
$count = count($patches);
$dbr = wfGetDB( DB_SLAVE );
for($i=0 ; $i<1 ; $i++)
{
echo('<p>post'.$i.': '.$patches[$i].'</p><br/>');
integrateUndo($patches, $urlServer/*, $csName*/);//will execute the integration of the patches
wfDebugLog('p2p', "@@@@@@@@@@@@@@@@@@@@@ attemptUndo : $wgServerName, $wgScriptPath - ");
}
utils::writeAndFlush('<p><b>End undo</b></p>');
$title = Title::newFromText($_POST['page']);
$article = new Article($title);
$article->doRedirect();
return false;
}
}
///////////////////BEN//////////////////
else {
return true;
}
}
/**
*
* @param <String> $version1
* @param <String> $version2='1.14.0'
* @return <integer>
*/
function compareMWVersion($version1, $version2='1.14.0') {
$version1 = explode(".", $version1);
$version2 = explode(".", $version2);
if ($version1[0] > $version2[0])
return 1;
elseif ($version1[0] < $version2[0])
return -1;
elseif ($version1[1] > $version2[1])
return 1;
elseif ($version1[1] < $version2[1])
return -1;
elseif ($version1[2] > $version2[2])
return 1;
elseif ($version1[2] < $version2[2])
return -1;
else
return 0;
}
/* * *************************************************************************** */
/*
V0 : initial revision
/ \
/
P1 / \P2
/
/ \
V1 V2:2nd edit of the same article
1st Edit
*/
/* * *************************************************************************** */
function attemptSave($editpage) {
global $wgServerName, $wgScriptPath;
$urlServer = 'http://' . $wgServerName . $wgScriptPath;
wfDebugLog('p2p', "@@@@@@@@@@@@@@@@@@@@@ attemptSave : $wgServerName, $wgScriptPath - ");
$ns = $editpage->mTitle->getNamespace();
if (($ns == PATCH) || ($ns == PUSHFEED) || ($ns == PULLFEED) || ($ns == CHANGESET)) return true;
$actualtext = $editpage->textbox1; //V2
$dbr = wfGetDB(DB_SLAVE);
$lastRevision = Revision::loadFromTitle($dbr, $editpage->mTitle);
if (is_null($lastRevision)) {
$conctext = "";
$rev_id = 0;
} elseif (($ns == NS_FILE || $ns == NS_IMAGE || $ns == NS_MEDIA) && $lastRevision->getRawText() == "") {
$rev_id = 0;
$conctext = $lastRevision->getText();
} else {
$conctext = $lastRevision->getText(); //V1 conc
$rev_id = $lastRevision->getId();
}
//if there is no modification on the text
if ($actualtext == $conctext) {
return true;
}
$model = manager::loadModel($rev_id);
$logoot = manager::getNewEngine($model,DSMWSiteId::getInstance()->getSiteId());// new logootEngine($model);
//get the revision with the edittime==>V0
$rev = Revision::loadFromTimestamp($dbr, $editpage->mTitle, $editpage->edittime);
if (is_null($rev)) {
$text = "";
$rev_id1 = 0;
} else {
$text = $rev->getText(); //VO
$rev_id1 = $rev->getId();
}
if ($conctext != $text) {//if last revision is not V0, there is editing conflict
wfDebugLog('p2p',' -> CONCURRENCE: ');
wfDebugLog('p2p',' -> + conctext :'.$conctext.'+('.$rev_id.') ts '.$lastRevision->getTimestamp());
wfDebugLog('p2p',' -> + text '.$text.'+('.$rev_id1.') ts '.$editpage->edittime.' '.$rev->getTimestamp());
$model1 = manager::loadModel($rev_id1);
$logoot1 = manager::getNewEngine($model1,DSMWSiteId::getInstance()->getSiteId());// new logootEngine($model1);
wfDebugLog('p2p', "========== Conc - $urlServer : \n".$conctext."\n--\n".$text."\n--\n".$actualtext."\n--\n");
$listOp1 = $logoot1->generate($text, $actualtext);
wfDebugLog('p2p', $listOp1."===\n\n");
//creation Patch P2
$tmp = serialize($listOp1);
$patch = new Patch(false, false, $listOp1, $urlServer, $rev_id1);
if ($editpage->mTitle->getNamespace() == 0)
$title = $editpage->mTitle->getText();
else
$title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText();
//integration: diffs between VO and V2 into V1
$logoot->integrate($listOp1);
$modelAfterIntegrate = $logoot->getModel();
}else {//no edition conflict
wfDebugLog('p2p', "=========== Std - $urlServer : \n".$conctext."\n--\n".$actualtext."\n--\n");
$listOp = $logoot->generate($conctext, $actualtext);
wfDebugLog('p2p', $listOp."===\n\n");
$modelAfterIntegrate = $logoot->getModel();
$tmp = serialize($listOp);
$patch = new Patch(false, false, $listOp, $urlServer, $rev_id1);
if ($editpage->mTitle->getNamespace() == 0)
$title = $editpage->mTitle->getText();
else
$title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText();
}
$revId = utils::getNewArticleRevId()+1;
wfDebugLog('p2p', ' -> store model rev : ' . $revId . ' session ' . session_id() . ' model ' . $modelAfterIntegrate->getText());
manager::storeModel($revId, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0);
$patch->storePage($title, $revId); //stores the patch in a wikipage
$editpage->textbox1 = $modelAfterIntegrate->getText();
return true;
}
/////////////////////////BEN/////////////////////////
//will compare the dates $date1 and $date2 received as strings
//WARNING: unlike usual comparison functions we will use positive for inferior and negative for superior
//because we must use this function to order an array in reverse order
//(we multiplicate $res by (-1) so, obtaining a regular function could be done by erasing that line)