-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateOpenKnowHowManifests.php
More file actions
60 lines (52 loc) · 1.82 KB
/
generateOpenKnowHowManifests.php
File metadata and controls
60 lines (52 loc) · 1.82 KB
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
<?php
/**
* This script generates an Open Know How Manifest for each project in Appropedia
* and adds it to the manifests directory
*/
$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
class GenerateOpenKnowHowManifests extends Maintenance {
public function execute() {
// Make sure the manifests directory exists and is empty
$dir = '/home/appropedia/public_html/manifests';
if ( is_dir( $dir ) ) {
exec( "rm -f $dir/*" );
} else {
mkdir( $dir );
}
// Make a manifest for each project
$manifests = [];
$category = Category::newFromName( 'Projects' );
$projects = $category->getMembers();
$total = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
foreach ( $projects as $count => $project ) {
if ( !$project->isContentPage() ) {
continue;
}
$title = $project->getFullText();
if ( preg_match( '#/[a-z]{2}$#', $title ) ) {
continue; // Skip automatic translations, for now
}
$titlee = str_replace( ' ', '_', $title ); // Extra "e" means "encoded"
$url = "https://www.appropedia.org/scripts/generateOpenKnowHowManifest.php?title=$titlee";
$manifest = @file_get_contents( $url );
if ( !$manifest or $manifest === 'Page not found' ) {
continue;
}
$hash = md5( $title );
$manifests[] = "https://www.appropedia.org/manifests/$hash.yaml";
file_put_contents( "$dir/$hash.yaml", $manifest );
$this->output( "$count/$total $title" . PHP_EOL );
//break; // Uncomment to debug
}
// Make the list.json index
$json = json_encode( $manifests, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT );
file_put_contents( $dir . '/list.json', $json );
$this->output( 'list.json' . PHP_EOL );
}
}
$maintClass = GenerateOpenKnowHowManifests::class;
require_once RUN_MAINTENANCE_IF_MAIN;