forked from commons-app/apps-android-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlicenses.php
71 lines (61 loc) · 1.92 KB
/
licenses.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
<?php
// Quick hack to extract default license list from UploadWizard configuration.
// In future, try to export this info via the API on wiki so we can pull dynamically.
//
// Brion Vibber <[email protected]>
// 2013-09-30
require 'include-stubs.php';
$config = require "mediawiki-extensions-UploadWizard/UploadWizard.config.php";
require "mediawiki-extensions-UploadWizard/UploadWizard.i18n.php";
$licenseList = array();
foreach ( $config['licenses'] as $key => $license ) {
// Determine template -> license mappings
if ( isset( $license['templates'] ) ) {
$templates = $license['templates'];
} else {
$templates = array( $key );
}
if ( count( $templates ) < 1 ) {
throw new Exception("No templates for $key, this is wrong.");
}
if ( count( $templates ) > 1 ) {
//echo "Skipping multi-template license: $key\n";
continue;
}
$template = $templates[0];
if ( preg_match( '/^subst:/i', $template ) ) {
//echo "Skipping subst license: $key\n";
continue;
}
$msg = $messages['en'][$license['msg']];
$licenseInfo = array(
'desc' => $msg,
'template' => $template
);
if ( isset( $license['url'] ) ) {
$url = $license['url'];
if ( substr( $url, 0, 2 ) == '//' ) {
$url = 'https:' . $url;
}
if ( isset( $license['languageCodePrefix'] ) ) {
$url .= $license['languageCodePrefix'] . '$lang';
}
$licenseInfo['url'] = $url;
}
$licenseList[$key] = $licenseInfo;
}
//var_dump( $licenseList );
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<licenses xmlns=\"https://www.mediawiki.org/wiki/Extension:UploadWizard/xmlns/licenses\">\n";
foreach( $licenseList as $key => $licenseInfo ) {
$encId = htmlspecialchars( $key );
echo " <license id=\"$encId\"";
$encTemplate = htmlspecialchars( $licenseInfo['template'] );
echo " template=\"$encTemplate\"";
if ( isset( $licenseInfo['url'] ) ) {
$encUrl = htmlspecialchars( $licenseInfo['url'] );
echo " url=\"$encUrl\"";
}
echo "/>\n";
}
echo "</licenses>\n";