forked from Nikerabbit/mediawiki-extensions-Termbank
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexportCategory.php
67 lines (47 loc) · 1.41 KB
/
exportCategory.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
<?php
/**
* ...
*
* @author Antti Kanner
* @copyright Copyright © 2011-2012, Antti Kanner
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
* @file
*/
// Standard boilerplate to define $IP
if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
$dir = dirname( __FILE__ ); $IP = "$dir/../..";
}
require_once( "$IP/maintenance/Maintenance.php" );
class TBExportExternalDatabaseByCategory extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = '...';
$this->addOption( 'category', '.', true, true );
}
public function execute() {
$categoryname = $this -> getOption( 'category' );
$this->getTitles( $categoryname );
}
protected function getTitles( $categoryname ) {
$category = Category::newFromName($categoryname);
$titles = $category-> getMembers();
$pagecount = $category->getPageCount();
echo "$pagecount";
file_put_contents("lista.txt", "");
foreach ($titles as $title) {
$this->getContent($title);
}
}
protected function getContent($title) {
$page = new WikiPage( $title );
$content = $page->getContent();
$pagename = $title->getFullText();
$native = "pagename=$pagename\n";
$native .= $content->getNativeData();
file_put_contents( "lista.txt", "$native\n", FILE_APPEND );
}
}
$maintClass = 'TBExportExternalDatabaseByCategory';
require_once( DO_MAINTENANCE );