Debian Codegraph @

debian/scripts/removeprivacybreach.xslt

raw
1 <?xml version="1.0"?>
2
3 <xsl:stylesheet version="1.0"
4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 xmlns:xs="http://www.w3.org/2001/XMLSchema"
6 exclude-result-prefixes="xsl xs">
7
8 <xsl:output method="xml"
9 omit-xml-declaration="yes"
10 version="1.0" encoding="UTF-8"
11 doctype-public="-//W3C//DTD XHTML 1.1//EN"
12 doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
13 indent="no"/>
14
15 <!-- ****************************** -->
16 <!-- * Some utilities function * -->
17 <!-- ****************************** -->
18
19
20 <!-- basename -->
21 <xsl:template name="basename">
22 <xsl:param name="path"/>
23 <xsl:choose>
24 <xsl:when test="contains($path, '/')">
25 <xsl:call-template name="basename">
26 <xsl:with-param name="path" select="substring-after($path, '/')"/>
27 </xsl:call-template>
28 </xsl:when>
29 <xsl:otherwise>
30 <xsl:value-of select="$path"/>
31 </xsl:otherwise>
32 </xsl:choose>
33 </xsl:template>
34
35 <!-- dirname -->
36 <xsl:template name="dirname"><xsl:param name="path"/>
37 <xsl:if test="contains($path, '/')">
38 <xsl:value-of select=" substring-before($path, '/') "/>
39 <xsl:text>/</xsl:text>
40 <xsl:call-template name="dirname"><xsl:with-param select="substring-after($path, '/')" name="path"/></xsl:call-template></xsl:if>
41 </xsl:template>
42
43 <!-- replace every dir by .. -->
44 <xsl:template name="root">
45 <xsl:param name="path"/>
46 <xsl:choose>
47 <xsl:when test="$path=''"></xsl:when>
48 <xsl:when test="contains($path, '/')">
49 <xsl:text>..</xsl:text>
50 <xsl:if test="substring-after($path, '/')">
51 <xsl:text>/</xsl:text>
52 <xsl:call-template name="root">
53 <xsl:with-param select="substring-after($path, '/')" name="path"/>
54 </xsl:call-template>
55 </xsl:if>
56 </xsl:when>
57 </xsl:choose>
58 </xsl:template>
59
60
61 <!-- ****************************** -->
62 <!-- * local function * -->
63 <!-- ****************************** -->
64
65 <!-- Replace well know legacy imagemagick website with correct local location -->
66 <xsl:template name="replacelegacy">
67 <xsl:param name="path"/>
68 <xsl:choose>
69 <xsl:when test="substring($path, string-length($path) - string-length('//') +1)='//'">
70 <xsl:call-template name="replacelegacy">
71 <xsl:with-param select="substring($path,1,string-length($path) -1)" name="path"/>
72 </xsl:call-template>
73 </xsl:when>
74 <!-- discourse server is external website -->
75 <xsl:when test="substring($path, string-length($path) - string-length('.imagemagick.org/discourse-server') +1)='.imagemagick.org/discourse-server'">
76 <xsl:text>https://www.imagemagick.org/discourse-server</xsl:text>
77 </xsl:when>
78 <xsl:when test="substring($path, string-length($path) - string-length('.imagemagick.org/discourse-server/') +1)='.imagemagick.org/discourse-server/'">
79 <xsl:text>https://www.imagemagick.org/discourse-server/</xsl:text>
80 </xsl:when>
81 <xsl:when test="contains($path,'.imagemagick.org/discourse-server')">
82 <xsl:value-of select="$path"/>
83 </xsl:when>
84 <!-- direct link to imagemagick -->
85 <xsl:when test="substring($path, string-length($path) - string-length('.imagemagick.org') +1)='.imagemagick.org'">
86 <xsl:text>https://www.imagemagick.org/</xsl:text>
87 </xsl:when>
88 <xsl:when test="substring($path, string-length($path) - string-length('.imagemagick.org/') +1)='.imagemagick.org/'">
89 <xsl:text>https://www.imagemagick.org/</xsl:text>
90 </xsl:when>
91 <!-- direct link to git -->
92 <xsl:when test="contains($path,'git.imagemagick.org/')">
93 <xsl:value-of select="$path"/>
94 </xsl:when>
95 <!-- direct link to usage -->
96 <xsl:when test="contains($path,'.imagemagick.org/Usage')">
97 <xsl:value-of select="$path"/>
98 </xsl:when>
99 <!-- direct link to download -->
100 <xsl:when test="contains($path,'.imagemagick.org/download/')">
101 <xsl:value-of select="$path"/>
102 </xsl:when>
103 <!-- direct link to download -->
104 <xsl:when test="substring($path, string-length($path) - string-length('.imagemagick.org/download') +1)='.imagemagick.org/download'">
105 <xsl:value-of select="$path"/>
106 </xsl:when>
107 <!-- direct link to ftp -->
108 <xsl:when test="contains($path,'ftp://')">
109 <xsl:value-of select="$path"/>
110 </xsl:when>
111 <!-- strip http:// -->
112 <xsl:when test="contains($path, '://')">
113 <xsl:call-template name="replacelegacy">
114 <xsl:with-param select="substring-after($path, '://')" name="path"/>
115 </xsl:call-template>
116 </xsl:when>
117 <!-- replace php by html -->
118 <xsl:when test="substring($path, string-length($path) - string-length('.php') +1)='.php'">
119 <xsl:call-template name="replacelegacy">
120 <xsl:with-param select="concat(substring($path,1,string-length($path) - string-length('.php')),'.html')" name="path" />
121 </xsl:call-template>
122 </xsl:when>
123 <xsl:when test="substring($path, string-length($path) - string-length('.php#') +1)='.php#'">
124 <xsl:call-template name="replacelegacy">
125 <xsl:with-param select="concat(substring($path,1,string-length($path) - string-length('.php#')),'.html')" name="path" />
126 </xsl:call-template>
127 </xsl:when>
128 <!-- replace legacy with www -->
129 <xsl:when test="substring($path,1,string-length('legacy.imagemagick.org/'))='legacy.imagemagick.org/'">
130 <xsl:call-template name="replacelegacy">
131 <xsl:with-param select="concat('www.imagemagick.org/',substring($path,string-length('legacy.imagemagick.org/')+1))" name="path" />
132 </xsl:call-template>
133 </xsl:when>
134 <!-- replace script sub dir with www -->
135 <xsl:when test="substring($path,1,string-length('www.imagemagick.org/script/'))='www.imagemagick.org/script/'">
136 <xsl:call-template name="replacelegacy">
137 <xsl:with-param select="concat('www.imagemagick.org/www/',substring($path,string-length('www.imagemagick.org/script/')+1))" name="path" />
138 </xsl:call-template>
139 </xsl:when>
140 <!-- replace legacy.imagemagick.org by nothing -->
141 <xsl:when test="substring($path,1,string-length('www.imagemagick.org/'))='www.imagemagick.org/'">
142 <xsl:call-template name="replacelegacy">
143 <xsl:with-param select="substring($path,string-length('www.imagemagick.org/')+1)" name="path" />
144 </xsl:call-template>
145 </xsl:when>
146 <!-- spurious / -->
147 <xsl:when test="substring($path,1,1)='/'">
148 <xsl:call-template name="replacelegacy">
149 <xsl:with-param select="substring($path,2)" name="path" />
150 </xsl:call-template>
151 </xsl:when>
152 <!-- if no dir it is default thus www/ dir -->
153 <xsl:when test="substring-before($path,'/')=''">
154 <xsl:call-template name="replacelegacy">
155 <xsl:with-param select="concat('www/',$path)" name="path" />
156 </xsl:call-template>
157 </xsl:when>
158 <!-- replace by relative path (filename part)-->
159 <xsl:otherwise>
160 <xsl:choose>
161 <xsl:when test="substring($filename,1,string-length('./www'))='./www'">
162 <xsl:call-template name="root">
163 <xsl:with-param select="substring($filename,string-length('./www')+1)" name="path"/>
164 </xsl:call-template>
165 </xsl:when>
166 </xsl:choose>
167
168 <!-- replace by relative path (link part)-->
169 <xsl:call-template name="dirname">
170 <xsl:with-param select="$path" name="path"/>
171 </xsl:call-template>
172 <xsl:call-template name="basename">
173 <xsl:with-param select="$path" name="path"/>
174 </xsl:call-template>
175 </xsl:otherwise>
176 </xsl:choose>
177 </xsl:template>
178
179
180 <xsl:template name="magickcsspath">
181 <!-- replace by relative path (filename part)-->
182 <xsl:choose>
183 <xsl:when test="substring($filename,1,string-length('./www'))='./www'">
184 <xsl:call-template name="root">
185 <xsl:with-param select="substring($filename,string-length('./www')+1)" name="path"/>
186 </xsl:call-template><xsl:text>www/css/magick.css</xsl:text>
187 </xsl:when>
188 <xsl:otherwise>
189 <xsl:text>www/css/magick.css</xsl:text>
190 </xsl:otherwise>
191 </xsl:choose>
192 </xsl:template>
193
194
195 <!-- ****************************** -->
196 <!-- * Global template * -->
197 <!-- ****************************** -->
198
199
200 <!-- the identity template -->
201 <xsl:template match="@*|node()">
202 <xsl:copy>
203 <xsl:apply-templates select="@*|node()"/>
204 </xsl:copy>
205 </xsl:template>
206
207 <!-- Add some versionning -->
208 <xsl:template match="*[local-name(.)='html']">
209 <xsl:text>&#10;</xsl:text>
210 <xsl:comment>Regenerated with privacy breach removal script</xsl:comment>
211 <xsl:text>&#10;</xsl:text>
212 <xsl:copy>
213 <xsl:apply-templates select="@* | node()" />
214 </xsl:copy>
215 </xsl:template>
216
217 <!-- replace pointer to legacy site -->
218 <xsl:template match="*[local-name(.) = 'a'][contains(@href,'legacy.imagemagick.org')]">
219 <xsl:message><xsl:text>Replace in </xsl:text><xsl:value-of select="$filename" /><xsl:text> </xsl:text><xsl:value-of select="@href" /><xsl:text> by </xsl:text><xsl:call-template name="replacelegacy"><xsl:with-param select="@href" name="path"/></xsl:call-template></xsl:message>
220 <xsl:copy>
221 <xsl:apply-templates select="@*"/>
222 <xsl:attribute name="href">
223 <xsl:call-template name="replacelegacy"><xsl:with-param select="@href" name="path"/></xsl:call-template>
224 </xsl:attribute>
225 </xsl:copy>
226 </xsl:template>
227
228 <xsl:template match="*[local-name(.) = 'img'][contains(@src,'legacy.imagemagick.org')]">
229 <xsl:message><xsl:text>Replace in </xsl:text><xsl:value-of select="$filename" /><xsl:text> </xsl:text><xsl:value-of select="@src" /><xsl:text> by </xsl:text><xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template></xsl:message>
230 <xsl:copy>
231 <xsl:apply-templates select="@*"/>
232 <xsl:attribute name="src">
233 <xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template>
234 </xsl:attribute>
235 </xsl:copy>
236 </xsl:template>
237
238 <xsl:template match="*[local-name(.) = 'input'][contains(@src,'legacy.imagemagick.org')]">
239 <xsl:message><xsl:text>Replace in </xsl:text><xsl:value-of select="$filename" /><xsl:text> </xsl:text><xsl:value-of select="@src" /><xsl:text> by </xsl:text><xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template></xsl:message>
240 <xsl:copy>
241 <xsl:apply-templates select="@*"/>
242 <xsl:attribute name="src">
243 <xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template>
244 </xsl:attribute>
245 </xsl:copy>
246 </xsl:template>
247
248 <xsl:template match="*[local-name(.) = 'link'][contains(@href,'legacy.imagemagick.org')][@rel='canonical']">
249 <xsl:message><xsl:text>Replace in !!!!</xsl:text><xsl:value-of select="$filename" /><xsl:text> </xsl:text><xsl:value-of select="@href" /><xsl:text> by </xsl:text><xsl:call-template name="replacelegacy"><xsl:with-param select="@href" name="path"/></xsl:call-template></xsl:message>
250 <xsl:copy>
251 <xsl:apply-templates select="@*"/>
252 <xsl:attribute name="href">
253 <xsl:call-template name="replacelegacy"><xsl:with-param select="@href" name="path"/></xsl:call-template>
254 </xsl:attribute>
255 </xsl:copy>
256 </xsl:template>
257
258 <!-- replace pointer to legacy site -->
259 <xsl:template match="*[local-name(.) = 'a'][contains(@href,'www.imagemagick.org')]">
260 <xsl:message><xsl:text>Replace in </xsl:text><xsl:value-of select="$filename" /><xsl:text> </xsl:text><xsl:value-of select="@href" /><xsl:text> by </xsl:text><xsl:call-template name="replacelegacy"><xsl:with-param select="@href" name="path"/></xsl:call-template></xsl:message>
261 <xsl:copy>
262 <xsl:apply-templates select="@*"/>
263 <xsl:attribute name="href">
264 <xsl:call-template name="replacelegacy"><xsl:with-param select="@href" name="path"/></xsl:call-template>
265 </xsl:attribute>
266 </xsl:copy>
267 </xsl:template>
268
269 <xsl:template match="*[local-name(.) = 'img'][contains(@src,'www.imagemagick.org')]">
270 <xsl:message><xsl:text>Replace in </xsl:text><xsl:value-of select="$filename" /><xsl:text> </xsl:text><xsl:value-of select="@src" /><xsl:text> by </xsl:text><xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template></xsl:message>
271 <xsl:copy>
272 <xsl:apply-templates select="@*"/>
273 <xsl:attribute name="src">
274 <xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template>
275 </xsl:attribute>
276 </xsl:copy>
277 </xsl:template>
278
279 <xsl:template match="*[local-name(.) = 'input'][contains(@src,'www.imagemagick.org')]">
280 <xsl:message><xsl:text>Replace in </xsl:text><xsl:value-of select="$filename" /><xsl:text> </xsl:text><xsl:value-of select="@src" /><xsl:text> by </xsl:text><xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template></xsl:message>
281 <xsl:copy>
282 <xsl:apply-templates select="@*"/>
283 <xsl:attribute name="src">
284 <xsl:call-template name="replacelegacy"><xsl:with-param select="@src" name="path"/></xsl:call-template>
285 </xsl:attribute>
286 </xsl:copy>
287 </xsl:template>
288
289
290
291 <!-- remove various privacy breach -->
292 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'googlesyndication')]" />
293 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'google_ad')]" />
294 <xsl:template match="*[local-name(.) = 'script'][contains(comment(),'google_ad')]" />
295 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'apis.google.com/js/plusone.js')]" />
296 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'GoogleAnalyticsObject')]" />
297 <xsl:template match="*[local-name(.) = 'div'][@class='g-plusone']" />
298 <xsl:template match="*[local-name(.) = 'meta'][@name='google-site-verification']" />
299 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'pagead/show_ads.js')]" />
300 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'document.getElementById(&quot;gplusone&quot;)')]" />
301 <xsl:template match="*[local-name(.) = 'adsense']" />
302 <xsl:template match="*[local-name(.) = 'CustomSearchEngine']" />
303 <xsl:template match="*[local-name(.) = 'customsearchengine']" />
304 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'google.com/jsapi')]" />
305 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'google.search.CustomSearchControl')]" />
306 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'adsbygoogle')]" />
307 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'window.adsbygoogle')]" />
308 <xsl:template match="*[local-name(.) = 'ins'][@class='adsbygoogle']" />
309 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'google-analytics.com/analytics.js')]" />
310 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'//www.google.com/cse/cse.js?cx=')]" />
311
312 <!-- remove google fonts -->
313 <xsl:template match="*[local-name(.) = 'link'][contains(@href,'//fonts.googleapis.com/css')]" />
314
315 <!-- remove strange stuff -->
316 <xsl:template match="*[local-name(.) = 'meta'][@name='magick-serial']" />
317 <xsl:template match="*[local-name(.) = 'meta'][@name='application-url']" />
318
319 <!-- flattr -->
320 <xsl:template match="*[local-name(.) = 'script'][contains(text(),'http://api.flattr.com/js/0.6/load.js?mode=auto')]" />
321 <xsl:template match="*[local-name(.) = 'img'][contains(@src,'api.flattr.com/button/flattr-badge-large.png')]" />
322 <xsl:template match="*[local-name(.) = 'iframe'][contains(@src,'tools.flattr.net/widgets/thing.html')]" />
323 <xsl:template match="*[local-name(.) = 'div'][child::a[@class='FlattrButton']]" />
324 <xsl:template match="*[local-name(.) = 'noscript'][child::*[local-name(.) = 'a'][contains(@href,'flattr.com/thing/')]]" />
325 <xsl:template match="*[local-name(.) = 'a'][@class='FlattrButton']" />
326
327
328 <!-- replace online jquery with local one -->
329 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'jquery.min.js')]">
330 <xsl:copy>
331 <xsl:apply-templates select="@*"/>
332 <xsl:attribute name="src">
333 <xsl:value-of select="'/usr/share/javascript/jquery/jquery.min.js'"/>
334 </xsl:attribute>
335 </xsl:copy>
336 </xsl:template>
337
338 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'jquery.mousewheel')]">
339 <xsl:copy>
340 <xsl:apply-templates select="@*"/>
341 <xsl:attribute name="src">
342 <xsl:value-of select="'/usr/share/javascript/jquery-mousewheel/jquery.mousewheel.js'"/>
343 </xsl:attribute>
344 </xsl:copy>
345 </xsl:template>
346
347 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'jquery.fancybox.pack.js')]">
348 <xsl:copy>
349 <xsl:apply-templates select="@*"/>
350 <xsl:attribute name="src">
351 <xsl:value-of select="'/usr/share/javascript/jquery-fancybox/jquery.fancybox.min.js'"/>
352 </xsl:attribute>
353 </xsl:copy>
354 </xsl:template>
355
356 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'/js/bootstrap.bundle.min.js')]">
357 <xsl:copy>
358 <xsl:apply-templates select="@*"/>
359 <xsl:attribute name="src">
360 <xsl:value-of select="'/usr/share/javascript/bootstrap5/js/bootstrap.bundle.min.js'"/>
361 </xsl:attribute>
362 </xsl:copy>
363 </xsl:template>
364
365 <xsl:template match="*[local-name(.) = 'link'][contains(@href,'jquery.fancybox.css')]">
366 <xsl:copy>
367 <xsl:apply-templates select="@*"/>
368 <xsl:attribute name="href">
369 <xsl:value-of select="'/usr/share/javascript/jquery-fancybox/jquery.fancybox.css'"/>
370 </xsl:attribute>
371 </xsl:copy>
372 </xsl:template>
373
374 <xsl:template match="*[local-name(.) = 'link'][contains(@href,'bootstrap.min.css')]">
375 <xsl:copy>
376 <xsl:apply-templates select="@*"/>
377 <xsl:attribute name="href">
378 <xsl:value-of select="'/usr/share/javascript/bootstrap5/css/bootstrap.min.css'"/>
379 </xsl:attribute>
380 </xsl:copy>
381 </xsl:template>
382
383 <!-- rename some error -->
384 <xsl:template match="*[local-name(.) = 'link'][substring(@href, string-length(@href) - string-length('magick.html') +1)='magick.html']">
385 <xsl:copy>
386 <xsl:apply-templates select="@*"/>
387 <xsl:attribute name="href">
388 <xsl:call-template name="magickcsspath"></xsl:call-template>
389 </xsl:attribute>
390 </xsl:copy>
391 </xsl:template>
392 <xsl:template match="*[local-name(.) = 'link'][substring(@href, string-length(@href) - string-length('magick.css') +1)='magick.css']">
393 <xsl:copy>
394 <xsl:apply-templates select="@*"/>
395 <xsl:attribute name="href">
396 <xsl:call-template name="magickcsspath"></xsl:call-template>
397 </xsl:attribute>
398 </xsl:copy>
399 </xsl:template>
400 <xsl:template match="*[local-name(.) = 'script'][substring(@src, string-length(@src) - string-length('magick.html') +1)='magick.html']">
401 <xsl:copy>
402 <xsl:apply-templates select="@*"/>
403 <xsl:attribute name="href">
404 <xsl:value-of select="substring(@src,1,string-length(@src) - string-length('.html'))"/><xsl:text>.js</xsl:text>
405 </xsl:attribute>
406 </xsl:copy>
407 </xsl:template>
408
409
410 <!-- temporary remove optionnal package -->
411 <xsl:template match="*[local-name(.) = 'link'][@type='text/css' and contains(@href,'jquery.fancybox-buttons.css')]" />
412 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'jquery.fancybox-buttons.js')]" />
413 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'jquery.fancybox-media.js')]" />
414 <xsl:template match="*[local-name(.) = 'link'][@type='text/css' and contains(@href,'jquery.fancybox-thumbs.css')]" />
415 <xsl:template match="*[local-name(.) = 'script'][contains(@src,'jquery.fancybox-thumbs.js')]" />
416
417 <!-- remove rss meta data -->
418 <xsl:template match="*[local-name(.)= 'link'][@href='http://imagemagick.org/ici.rdf']" />
419
420 <!-- remove github frame -->
421 <xsl:template match="*[local-name(.)= 'iframe'][contains(@src,'github.com/sponsors')]" />
422
423 <!-- remove wand icon -->
424 <xsl:template match="*[local-name(.)= 'link'][@rel='icon' and contains(@href,'http://')]" />
425 <xsl:template match="*[local-name(.)= 'link'][@rel='icon' and contains(@href,'https://')]" />
426 <xsl:template match="*[local-name(.)= 'img'][@class='icon' and contains(@href,'https://imagemagick.org/magick++/cache.png')]" />
427 </xsl:stylesheet>