Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
DataAccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPageInfo | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getFileInfo | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
parseWikitext | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
preprocessWikitext | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
fetchTemplateSource | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
fetchTemplateData | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
logLinterData | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
addTrackingCategory | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\Config; |
5 | |
6 | use Wikimedia\Parsoid\Core\ContentMetadataCollector; |
7 | use Wikimedia\Parsoid\Core\LinkTarget; |
8 | use Wikimedia\Parsoid\Fragments\PFragment; |
9 | |
10 | /** |
11 | * MediaWiki data access abstract class for Parsoid |
12 | */ |
13 | abstract class DataAccess { |
14 | /** |
15 | * Base constructor. |
16 | * |
17 | * This constructor is public because it is used to create mock objects |
18 | * in our test suite. |
19 | */ |
20 | public function __construct() { |
21 | } |
22 | |
23 | /** |
24 | * Return target data for formatting links. |
25 | * |
26 | * Replaces Batcher.getPageProps() |
27 | * |
28 | * @param PageConfig|LinkTarget $pageConfigOrTitle |
29 | * Either a PageConfig or else just the context title from the PageConfig |
30 | * (as a LinkTarget) |
31 | * @param string[] $titles |
32 | * @return array<string,array> [ string Title => array ], where the array contains |
33 | * - pageId: (int|null) Page ID |
34 | * - revId: (int|null) Current revision of the page |
35 | * - missing: (bool) Whether the page is missing |
36 | * - known: (bool) Whether the special page is known |
37 | * - redirect: (bool) Whether the page is a redirect |
38 | * - linkclasses: (string[]) Extensible "link color" information; see |
39 | * ApiQueryInfo::getLinkClasses() in MediaWiki core |
40 | */ |
41 | abstract public function getPageInfo( $pageConfigOrTitle, array $titles ): array; |
42 | |
43 | /** |
44 | * Return information about files (images) |
45 | * |
46 | * This replaces ImageInfoRequest and Batcher.imageinfo() |
47 | * |
48 | * @param PageConfig $pageConfig |
49 | * @param array $files [ [string Name, array Dims] ]. The array may contain |
50 | * - width: (int) Requested thumbnail width |
51 | * - height: (int) Requested thumbnail height |
52 | * - page: (int) Requested thumbnail page number |
53 | * - seek: (int) Requested thumbnail time offset |
54 | * @return array [ array|null ], where the array contains |
55 | * - width: (int|false) File width, false if unknown |
56 | * - height: (int|false) File height, false if unknown |
57 | * - size: (int|false) File size in bytes, false if unknown |
58 | * - mediatype: (string) File media type |
59 | * - mime: (string) File MIME type |
60 | * - url: (string) File URL |
61 | * - mustRender: (bool) False if the file can be directly rendered by browsers |
62 | * - badFile: (bool) Whether the file is on the "bad image list" |
63 | * - duration: (float, optional) Duration of the media in seconds |
64 | * - thumberror: (string, optional) Error text if thumbnailing failed. Ugh. |
65 | * - responsiveUrls: (string[], optional) Map of display densities to URLs. |
66 | * - thumbdata: (mixed, optional) MediaWiki File->getAPIData() |
67 | * - thumburl: (string, optional) Thumbnail URL |
68 | * - thumbwidth: (int, optional) Thumbnail width |
69 | * - thumbheight: (int, optional) Thumbnail height |
70 | * - timestamp: (string, optional) Timestamp |
71 | * - sha1: (string, optional) SHA-1 |
72 | */ |
73 | abstract public function getFileInfo( PageConfig $pageConfig, array $files ): array; |
74 | |
75 | /** |
76 | * Perform a parse on wikitext |
77 | * |
78 | * This replaces PHPParseRequest with onlypst = false, and Batcher.parse() |
79 | * |
80 | * @todo Parsoid should be able to do this itself. |
81 | * @param PageConfig $pageConfig |
82 | * @param ContentMetadataCollector $metadata Will collect metadata about |
83 | * the parsed content. |
84 | * @param string $wikitext |
85 | * @return string Output HTML |
86 | */ |
87 | abstract public function parseWikitext( |
88 | PageConfig $pageConfig, |
89 | ContentMetadataCollector $metadata, |
90 | string $wikitext |
91 | ): string; |
92 | |
93 | /** |
94 | * Preprocess wikitext |
95 | * |
96 | * This replaces PreprocessorRequest and Batcher.preprocess() |
97 | * |
98 | * @todo Parsoid should be able to do this itself. |
99 | * @param PageConfig $pageConfig |
100 | * @param ContentMetadataCollector $metadata Will collect metadata about |
101 | * the preprocessed content. |
102 | * @param string $wikitext |
103 | * @return string|PFragment Expanded wikitext |
104 | */ |
105 | abstract public function preprocessWikitext( |
106 | PageConfig $pageConfig, |
107 | ContentMetadataCollector $metadata, |
108 | string $wikitext |
109 | ); |
110 | |
111 | /** |
112 | * Fetch latest revision of article/template content for transclusion. |
113 | * |
114 | * Technically, the ParserOptions might select a different |
115 | * revision other than the latest via |
116 | * ParserOptions::getTemplateCallback() (used for FlaggedRevisions, |
117 | * etc), but the point is that template lookups are by title, not |
118 | * revision id. |
119 | * |
120 | * This replaces TemplateRequest |
121 | * |
122 | * @todo TemplateRequest also returns a bunch of other data, but seems to never use it except for |
123 | * TemplateRequest.setPageSrcInfo() which is replaced by PageConfig. |
124 | * @param PageConfig $pageConfig |
125 | * @param LinkTarget $title Title of the page to fetch |
126 | * @return PageContent|null |
127 | */ |
128 | abstract public function fetchTemplateSource( |
129 | PageConfig $pageConfig, LinkTarget $title |
130 | ): ?PageContent; |
131 | |
132 | /** |
133 | * Fetch templatedata for a title |
134 | * |
135 | * This replaces TemplateDataRequest |
136 | * |
137 | * @param PageConfig $pageConfig |
138 | * @param LinkTarget $title |
139 | * @return array|null |
140 | */ |
141 | abstract public function fetchTemplateData( PageConfig $pageConfig, LinkTarget $title ): ?array; |
142 | |
143 | /** |
144 | * Log linter data. |
145 | * |
146 | * @param PageConfig $pageConfig |
147 | * @param array $lints |
148 | */ |
149 | abstract public function logLinterData( PageConfig $pageConfig, array $lints ): void; |
150 | |
151 | /** |
152 | * Add a tracking category with the given key to the metadata for the page. |
153 | * |
154 | * @param PageConfig $pageConfig the page on which the tracking category |
155 | * is to be added |
156 | * @param ContentMetadataCollector $metadata The metadata for the page |
157 | * @param string $key Message key (not localized) |
158 | */ |
159 | abstract public function addTrackingCategory( |
160 | PageConfig $pageConfig, |
161 | ContentMetadataCollector $metadata, |
162 | string $key |
163 | ): void; |
164 | |
165 | } |