jenkins-bot has submitted this change and it was merged.
Change subject: Add option to conversion script to skip pages with a certain
template
......................................................................
Add option to conversion script to skip pages with a certain template
So you can do something like:
php convertNamespaceFromWikitext.php Help_talk --no-convert-templates=Archive
Bug: T102261
Change-Id: Idd80700bc415f31456bfc6e5d6a108e9d36279eb
---
M includes/Import/Wikitext/ConversionStrategy.php
M maintenance/convertNamespaceFromWikitext.php
2 files changed, 56 insertions(+), 2 deletions(-)
Approvals:
Sbisson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Import/Wikitext/ConversionStrategy.php
b/includes/Import/Wikitext/ConversionStrategy.php
index 6b62022..4ee8dc3 100644
--- a/includes/Import/Wikitext/ConversionStrategy.php
+++ b/includes/Import/Wikitext/ConversionStrategy.php
@@ -7,6 +7,7 @@
use Flow\Import\Converter;
use Flow\Import\IConversionStrategy;
use Flow\Import\ImportSourceStore;
+use LinkBatch;
use Parser;
use Psr\Log\LoggerInterface;
use StubObject;
@@ -56,17 +57,21 @@
/**
* @param Parser|StubObject $parser
* @param ImportSourceStore $sourceStore
+ * @param LoggerInterface $logger
+ * @param Title[] $noConvertTemplates List of templates that flag pages
that shouldn't be converted
*/
public function __construct(
$parser,
ImportSourceStore $sourceStore,
LoggerInterface $logger,
+ array $noConvertTemplates = array(),
$preferredArchiveTitle = null,
$headerSuffix = null
) {
$this->parser = $parser;
$this->sourceStore = $sourceStore;
$this->logger = $logger;
+ $this->noConvertTemplates = $noConvertTemplates;
$this->headerSuffix = $headerSuffix;
if ( isset( $preferredArchiveTitle ) && !empty(
$preferredArchiveTitle ) ) {
@@ -175,6 +180,32 @@
}
/**
+ * Check whether the given title has one of the templates that should
protect it from
+ * being converted.
+ * @param Title $sourceTitle Title to check
+ * @return bool Whether the title has such a template
+ */
+ protected function hasNoConvertTemplate( Title $sourceTitle ) {
+ if ( count( $this->noConvertTemplates ) === 0 ) {
+ return false;
+ }
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $batch = new LinkBatch( $this->noConvertTemplates );
+ $result = $dbr->select(
+ 'templatelinks',
+ 'tl_from',
+ array(
+ 'tl_from' => $sourceTitle->getArticleID(),
+ $batch->constructSet( 'tl', $dbr )
+ ),
+ __METHOD__,
+ array( 'LIMIT' => 1 )
+ );
+ return $dbr->numRows( $result ) > 0;
+ }
+
+ /**
* {@inheritDoc}
*/
public function shouldConvert( Title $sourceTitle ) {
@@ -187,7 +218,7 @@
}
}
- if ( !$this->meetsSubpageRequirements( $sourceTitle ) ) {
+ if ( !$this->meetsSubpageRequirements( $sourceTitle ) ||
$this->hasNoConvertTemplate( $sourceTitle ) ) {
return false;
}
diff --git a/maintenance/convertNamespaceFromWikitext.php
b/maintenance/convertNamespaceFromWikitext.php
index cc01fa7..890dc0a 100644
--- a/maintenance/convertNamespaceFromWikitext.php
+++ b/maintenance/convertNamespaceFromWikitext.php
@@ -17,6 +17,13 @@
parent::__construct();
$this->mDescription = "Converts a single namespace of wikitext
talk pages to Flow";
$this->addArg( 'namespace', 'Name of the namespace to convert'
);
+ $this->addOption(
+ 'no-convert-templates',
+ 'Comma-separated list of templates that indicate a page
should not be converted',
+ false, // not required
+ true, // takes argument
+ 't'
+ );
}
public function execute() {
@@ -36,6 +43,21 @@
return;
}
+ $noConvertTemplates = explode( ',', $this->getOption(
'no-convert-templates', '' ) );
+ if ( $noConvertTemplates === array( '' ) ) {
+ // explode( ',', '' ) returns array( '' )
+ $noConvertTemplates = array();
+ }
+ // Convert to Title objects
+ foreach ( $noConvertTemplates as &$template ) {
+ $title = Title::newFromText( $template, NS_TEMPLATE );
+ if ( !$title ) {
+ $this->error( "Invalid template name:
$template" );
+ return;
+ }
+ $template = $title;
+ }
+
// @todo send to prod logger?
$logger = new MaintenanceDebugLogger( $this );
@@ -48,7 +70,8 @@
new Flow\Import\Wikitext\ConversionStrategy(
$wgParser,
new Flow\Import\NullImportSourceStore(),
- $logger
+ $logger,
+ $noConvertTemplates
)
);
--
To view, visit https://gerrit.wikimedia.org/r/217975
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idd80700bc415f31456bfc6e5d6a108e9d36279eb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits