Sbisson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/238772
Change subject: [WIP] Use localized version of LQT magic word
......................................................................
[WIP] Use localized version of LQT magic word
Bug: T110723
Change-Id: Ifffce009d2dbe5373646d74687dc2a233065fe71
---
M includes/Import/LiquidThreadsApi/ConversionStrategy.php
M includes/Import/LiquidThreadsApi/Objects.php
M tests/phpunit/Import/Wikitext/ConversionStrategyTest.php
3 files changed, 29 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/72/238772/1
diff --git a/includes/Import/LiquidThreadsApi/ConversionStrategy.php
b/includes/Import/LiquidThreadsApi/ConversionStrategy.php
index 787cb93..6b7e834 100644
--- a/includes/Import/LiquidThreadsApi/ConversionStrategy.php
+++ b/includes/Import/LiquidThreadsApi/ConversionStrategy.php
@@ -13,6 +13,7 @@
use Flow\NotificationController;
use Flow\UrlGenerator;
use LqtDispatch;
+use MagicWord;
use MWTimestamp;
use Title;
use User;
@@ -58,10 +59,6 @@
* @var NotificationController
*/
protected $notificationController;
-
- const LQT_ENABLE_MAGIC_WORD_REGEX =
'/{{\s*#useliquidthreads:\s*0*1\s*}}/i';
-
- const LQT_DISABLE_MAGIC_WORD = '{{#useliquidthreads:0}}';
public function __construct(
DatabaseBase $dbw,
@@ -134,12 +131,8 @@
'date=' .
MWTimestamp::getInstance()->timestamp->format( 'Y-m-d' ),
) );
- $newWikitext = preg_replace(
- self::LQT_ENABLE_MAGIC_WORD_REGEX,
- '',
- $content->getNativeData()
- );
- $newWikitext = self::LQT_DISABLE_MAGIC_WORD . "\n\n" .
$newWikitext;
+ $newWikitext = self::removeLqtMagicWord(
$content->getNativeData() );
+ $newWikitext = self::getDisableLqtMagicWord() . "\n\n" .
$newWikitext;
$template = wfMessage(
'flow-importer-lqt-converted-archive-template' )->inContentLanguage()->plain();
$newWikitext = "{{{$template}|$arguments}}\n\n" . $newWikitext;
@@ -162,4 +155,25 @@
// The expensive part of this (user-override checking) is
cached by LQT.
return LqtDispatch::isLqtPage( $sourceTitle );
}
+
+ /**
+ * Remove the LQT magic word or its localized version
+ * @param string $content
+ * @return string
+ */
+ public static function removeLqtMagicWord( $content ) {
+ $patterns = array_map(
+ function( $word ) { return
"/{{\\s*#$word:\\s*0*1\\s*}}/i"; },
+ array( 'useliquidthreads', MagicWord::get(
'useliquidthreads' )->getSynonym( 0 ) ) );
+
+ return preg_replace( $patterns, '', $content );
+ }
+
+ /**
+ * @return string The localized magic word to disable LQT on a page
+ */
+ public static function getDisableLqtMagicWord() {
+ $magicWord = strtolower( MagicWord::get( 'useliquidthreads'
)->getSynonym( 0 ) );
+ return "{{#$magicWord:0}}";
+ }
}
diff --git a/includes/Import/LiquidThreadsApi/Objects.php
b/includes/Import/LiquidThreadsApi/Objects.php
index b3b7848..7086219 100644
--- a/includes/Import/LiquidThreadsApi/Objects.php
+++ b/includes/Import/LiquidThreadsApi/Objects.php
@@ -526,11 +526,7 @@
// This is will remove all instances, without attempting to
check if it's in
// nowiki, etc. It also ignores case and spaces in places
where it doesn't
// matter.
- $newWikitext = preg_replace(
- ConversionStrategy::LQT_ENABLE_MAGIC_WORD_REGEX,
- '',
- $wikitextForLastRevision
- );
+ $newWikitext = ConversionStrategy::removeLqtMagicWord(
$wikitextForLastRevision );
$templateName = wfMessage(
'flow-importer-lqt-converted-template' )->inContentLanguage()->plain();
$arguments = implode( '|', array(
'archive=' . $archiveTitle->getPrefixedText(),
diff --git a/tests/phpunit/Import/Wikitext/ConversionStrategyTest.php
b/tests/phpunit/Import/Wikitext/ConversionStrategyTest.php
index 293bc7f..4c8139e 100644
--- a/tests/phpunit/Import/Wikitext/ConversionStrategyTest.php
+++ b/tests/phpunit/Import/Wikitext/ConversionStrategyTest.php
@@ -68,6 +68,10 @@
}
public function testCreateArchiveCleanupRevisionContent() {
+ if( !class_exists( 'LqtDispatch' ) ) {
+ $this->markTestSkipped( 'LiquidThreads not enabled' );
+ }
+
// @todo superm401 suggested finding library that lets us
control time during tests,
// would probably be better
$now = new DateTime( "now", new DateTimeZone( "GMT" ) );
--
To view, visit https://gerrit.wikimedia.org/r/238772
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifffce009d2dbe5373646d74687dc2a233065fe71
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits