forked from ms609/citation-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComment.php
62 lines (48 loc) · 2.26 KB
/
Comment.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
<?php
declare(strict_types=1);
/*
* Contains constants and text-parsing functions for wikitext comments.
*/
// Do not ever remove CITATION_BOT_PLACEHOLDER from strings, there are lots of REGEX and stripos() calls in the code
abstract class WikiThings {
public const TREAT_IDENTICAL_SEPARATELY = false; // The contents of theses items never get edited, so this is safe
private string $rawtext; // Uninitialized. Will crash if read before set; which is good.
public function parse_text(string $text): void {
$this->rawtext = $text;
}
public function parsed_text(): string {
return $this->rawtext;
}
}
final class Comment extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_COMMENT %s # # #';
public const REGEXP = ['~<!--[^\<\>\-]*?-->~us', '~<!--[\s\S]*?-->~us'];
}
final class Nowiki extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_NOWIKI %s # # #';
public const REGEXP = ['~<nowiki>[^\<\>]*?</nowiki>~us', '~<nowiki>[\s\S]*?</nowiki>~us'];
}
final class Chemistry extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_CHEMISTRY %s # # #';
public const REGEXP = ['~<chem>[\s\S]*?</chem>~us'];
}
final class Mathematics extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_MATHEMATICS %s # # #';
public const REGEXP = ['~<math(?:| chem)(?:| display=.inline.|display=.block.)>[\s\S]*?</math>~us'];
}
final class Musicscores extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_MUSIC %s # # #';
public const REGEXP = ['~<score>[\s\S]*?</score>~us'];
}
final class Preformated extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_PREFORMAT %s # # #';
public const REGEXP = ['~<pre>[\s\S]*?</pre>~us'];
}
final class SingleBracket extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_SINGLE_BRACKET %s # # #';
public const REGEXP = ['~(?<!\{)\{[^\{\}]+\}(?!\})~us'];
}
final class TripleBracket extends WikiThings {
public const PLACEHOLDER_TEXT = '# # # CITATION_BOT_PLACEHOLDER_TRIPLE_BRACKET %s # # #';
public const REGEXP = ['~(?<!\{)\{\{\{[^\{\}]+\}\}\}(?!\})~us'];
}