-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFragmentLoader.php
121 lines (107 loc) · 3.04 KB
/
FragmentLoader.php
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
<?php
require_once('WikiLoader.php');
require_once('config.php');
class FragmentLoader {
static private function processString($s, $title)
{
$source = WikiLoader::parseSource($s, 'SMWFragment');
if($source === false)
return false;
$renames = array(
'SeiteArbeit' => 'seite',
'ZeileArbeit' => 'zeilen',
'TextArbeit' => 'plagiat',
'SeiteQuelle' => 'seitefund',
'ZeileQuelle' => 'zeilenfund',
'TextQuelle' => 'orig',
'Anmerkungen' => 'anmerkung',
'Typus' => 'typus',
'Bearbeiter' => false,
'Sichter' => false,
'Kuerzel' => false,
'Quelle' => false,
'FragmentStatus' => false,
'Markierungslaufweite' => false,
'QuelleAlt' => false,
);
foreach($source as $key => $val) {
if(in_array($key, array_keys($renames))) {
if($val && $renames[$key])
$ret[$renames[$key]] = $val;
} else {
print "Fehler: Unbekannter Wert: $key. Fragment: $title\n";
}
}
return $ret;
}
static private function collectCategories($entry)
{
$cats = array();
if(isset($entry['categories']))
foreach($entry['categories'] as $c)
$cats[] = $c['title'];
$cats = array_unique($cats);
sort($cats);
return $cats;
}
static private function processFrags($entries, &$ignored = array())
{
$fragments = array();
foreach($entries as $e) {
$a = self::processString($e['revisions'][0]['*'], $e['title']);
if($a !== false) {
$a['wikiTitle'] = $e['title'];
$a['categories'] = self::collectCategories($e);
$fragments[] = $a;
} else {
$ignored[$e['title']] = $e['revisions'][0]['*'];
}
}
return $fragments;
}
static public function getFragments(&$ignored = array())
{
$entries = WikiLoader::getEntriesWithPrefix(NAME_PREFIX.'/Fragment ', true, true);
return self::processFrags($entries, $ignored);
}
static private function parseFragmentType($rawText)
{
$fragtype = array();
if(preg_match('/<!--\s*prioritaet\s*=\s*(-?\s*\d+)/si', $rawText, $match)) {
$fragtype['priority'] = (int) preg_replace('/\s/', '', $match[1]);
} else {
$fragtype['priority'] = 0;
}
return $fragtype;
}
static public function getFragmentTypes(&$ignored = array())
{
$pageids = WikiLoader::getCategoryMembers('Kategorie:Plagiatsarten');
$entries = WikiLoader::getEntries($pageids, true, true);
$fragtypes = array();
foreach($entries as $entry) {
if (substr($entry['title'], 0, 10) == 'Kategorie:') {
$fragtype = self::parseFragmentType($entry['revisions'][0]['*']);
if ($fragtype !== false) {
$fragtype['title'] = $entry['title'];
$fragtypes[] = $fragtype;
} else {
$ignored[] = $entry['title'];
}
}
}
usort($fragtypes, 'fragmentLoaderTypePriorityCmp');
return $fragtypes;
}
}
// these functions have to be defined outside of the class --
// they are used as callbacks
function fragmentLoaderTypePriorityCmp($fragtype1, $fragtype2) {
if($fragtype1['priority'] < $fragtype2['priority']) {
return -1;
} else if($fragtype1['priority'] > $fragtype2['priority']) {
return 1;
} else {
return strcmp($fragtype1['title'], $fragtype2['title']);
}
}