Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 68 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ConvertNamespaceFromWikitext | |
0.00% |
0 / 62 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 44 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Maintenance; |
| 4 | |
| 5 | use Flow\Container; |
| 6 | use Flow\Import\Converter; |
| 7 | use Flow\Import\SourceStore\NullImportSourceStore; |
| 8 | use Flow\Import\Wikitext\ConversionStrategy; |
| 9 | use Flow\OccupationController; |
| 10 | use Flow\Utils\NamespaceIterator; |
| 11 | use MediaWiki\Maintenance\Maintenance; |
| 12 | use MediaWiki\MediaWikiServices; |
| 13 | use MediaWiki\Title\Title; |
| 14 | |
| 15 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 16 | if ( $IP === false ) { |
| 17 | $IP = __DIR__ . '/../../..'; |
| 18 | } |
| 19 | |
| 20 | require_once "$IP/maintenance/Maintenance.php"; |
| 21 | |
| 22 | /** |
| 23 | * Converts a single namespace from wikitext talk pages to flow talk pages. Does not |
| 24 | * modify LiquidThreads pages it comes across; use convertLqtPagesWithProp.php for that. Does not |
| 25 | * modify sub-pages (except talk subpages with a corresponding subject page). |
| 26 | */ |
| 27 | class ConvertNamespaceFromWikitext extends Maintenance { |
| 28 | public function __construct() { |
| 29 | parent::__construct(); |
| 30 | $this->addDescription( "Converts a single namespace of wikitext talk pages to Flow" ); |
| 31 | $this->addArg( 'namespaceName', 'Name of the namespace to convert' ); |
| 32 | $this->addOption( |
| 33 | 'no-convert-templates', |
| 34 | 'Comma-separated list of templates that indicate a page should not be converted', |
| 35 | false, // not required |
| 36 | true, // takes argument |
| 37 | 't' |
| 38 | ); |
| 39 | $this->addOption( |
| 40 | 'header-suffix', |
| 41 | 'Wikitext to add to the end of the header', |
| 42 | false, // not required |
| 43 | true, // takes argument |
| 44 | 'a' |
| 45 | ); |
| 46 | $this->requireExtension( 'Flow' ); |
| 47 | } |
| 48 | |
| 49 | public function execute() { |
| 50 | global $wgLang; |
| 51 | |
| 52 | $provided = $this->getArg( 0 ); |
| 53 | $namespace = $wgLang->getNsIndex( $provided ); |
| 54 | if ( !$namespace ) { |
| 55 | $this->error( "Invalid namespace provided: $provided" ); |
| 56 | return; |
| 57 | } |
| 58 | $namespaceName = $wgLang->getNsText( $namespace ); |
| 59 | if ( !$this->getServiceContainer()->getNamespaceInfo()->hasSubpages( $namespace ) ) { |
| 60 | $this->error( "Subpages are not enabled in the $namespaceName namespace." ); |
| 61 | $this->error( "In order to convert this namespace to Flow, you must enable subpages using:" ); |
| 62 | $this->error( "\$wgNamespacesWithSubpages[$namespace] = true;" ); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | $noConvertTemplates = explode( ',', $this->getOption( 'no-convert-templates', '' ) ); |
| 67 | if ( $noConvertTemplates === [ '' ] ) { |
| 68 | // explode( ',', '' ) returns [ '' ] |
| 69 | $noConvertTemplates = []; |
| 70 | } |
| 71 | // Convert to Title objects |
| 72 | foreach ( $noConvertTemplates as &$template ) { |
| 73 | $title = Title::newFromText( $template, NS_TEMPLATE ); |
| 74 | if ( !$title ) { |
| 75 | $this->error( "Invalid template name: $template" ); |
| 76 | return; |
| 77 | } |
| 78 | $template = $title; |
| 79 | } |
| 80 | |
| 81 | // @todo send to prod logger? |
| 82 | $logger = new MaintenanceDebugLogger( $this ); |
| 83 | |
| 84 | $dbw = $this->getPrimaryDB(); |
| 85 | /** @var OccupationController $occupationController */ |
| 86 | $occupationController = MediaWikiServices::getInstance()->getService( 'FlowTalkpageManager' ); |
| 87 | $talkpageManager = $occupationController->getTalkpageManager(); |
| 88 | $converter = new Converter( |
| 89 | $dbw, |
| 90 | Container::get( 'importer' ), |
| 91 | $logger, |
| 92 | $talkpageManager, |
| 93 | |
| 94 | new ConversionStrategy( |
| 95 | $this->getServiceContainer()->getParser(), |
| 96 | new NullImportSourceStore(), |
| 97 | $logger, |
| 98 | $talkpageManager, |
| 99 | $noConvertTemplates, |
| 100 | $this->getOption( 'header-suffix', null ) |
| 101 | ) |
| 102 | ); |
| 103 | |
| 104 | $logger->info( "Starting conversion of $namespaceName namespace" ); |
| 105 | |
| 106 | // Iterate over all existing pages of the namespace. |
| 107 | $it = new NamespaceIterator( $dbw, $namespace ); |
| 108 | // NamespaceIterator is an IteratorAggregate. Get an Iterator |
| 109 | // so we can wrap that. |
| 110 | $it = $it->getIterator(); |
| 111 | |
| 112 | $converter->convertAll( $it ); |
| 113 | |
| 114 | $logger->info( "Finished conversion of $namespaceName namespace" ); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | $maintClass = ConvertNamespaceFromWikitext::class; |
| 119 | require_once RUN_MAINTENANCE_IF_MAIN; |