Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232487
Change subject: Turn FlowCreateMentionTemplate.php into multi-template-creation
script
......................................................................
Turn FlowCreateMentionTemplate.php into multi-template-creation script
Change-Id: Ib10fc648244e24783784ed53c7789a119408309a
---
M Hooks.php
D maintenance/FlowCreateMentionTemplate.php
A maintenance/FlowCreateTemplates.php
3 files changed, 97 insertions(+), 54 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/87/232487/1
diff --git a/Hooks.php b/Hooks.php
index 43cc102..3b36e6b 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -233,8 +233,8 @@
require_once
__DIR__.'/maintenance/FlowUpdateWorkflowPageId.php';
$updater->addPostDatabaseUpdateMaintenance(
'FlowUpdateWorkflowPageId' );
- require_once
__DIR__.'/maintenance/FlowCreateMentionTemplate.php';
- $updater->addPostDatabaseUpdateMaintenance(
'FlowCreateMentionTemplate' );
+ require_once __DIR__.'/maintenance/FlowCreateTemplates.php';
+ $updater->addPostDatabaseUpdateMaintenance(
'FlowCreateTemplates' );
return true;
}
diff --git a/maintenance/FlowCreateMentionTemplate.php
b/maintenance/FlowCreateMentionTemplate.php
deleted file mode 100644
index bfbac78..0000000
--- a/maintenance/FlowCreateMentionTemplate.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
- ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
- : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
-
-/**
- * Creates Template:FlowMention, which is used to render mentions in Flow's
Visual Editor.
- * The template will be created with a default format, but can be customized.
- * If the template already exists, it will be left untouched.
- *
- * @ingroup Maintenance
- */
-class FlowCreateMentionTemplate extends LoggedUpdateMaintenance {
- public function __construct() {
- parent::__construct();
-
- $this->mDescription = "Creates Template:FlowMention, which is used te
render mentions in Flow's Visual Editor";
- }
-
- protected function getUpdateKey() {
- return __CLASS__;
- }
-
- protected function doDBUpdates() {
- // get "User:" namespace prefix in wiki language
- global $wgContLang;
- $namespaces = $wgContLang->getFormattedNamespaces();
-
- $title = Title::newFromText( wfMessage(
'flow-ve-mention-template-title' )->inContentLanguage()->plain(), NS_TEMPLATE );
- $article = new Article( $title );
- $page = $article->getPage();
-
- if ( $page->getRevision() !== null ) {
- // template already exists, don't overwrite it
- return true;
- }
-
- $status = $page->doEditContent(
- new WikitextContent( '@[[' . $namespaces[NS_USER] .
':{{{1|Example}}}|{{{2|{{{1|Example}}}}}}]]' ),
- '/* Automatically created by Flow */',
- EDIT_FORCE_BOT | EDIT_SUPPRESS_RC,
- false,
- FlowHooks::getOccupationController()->getTalkpageManager()
- );
-
- return $status->isOK();
- }
-}
-
-$maintClass = 'FlowCreateMentionTemplate';
-require_once( RUN_MAINTENANCE_IF_MAIN );
diff --git a/maintenance/FlowCreateTemplates.php
b/maintenance/FlowCreateTemplates.php
new file mode 100644
index 0000000..fdea4b7
--- /dev/null
+++ b/maintenance/FlowCreateTemplates.php
@@ -0,0 +1,95 @@
+<?php
+
+require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
+ ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
+ : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
+
+/**
+ * Creates Template:FlowMention, which is used to render mentions in Flow's
Visual Editor.
+ * The template will be created with a default format, but can be customized.
+ * If the template already exists, it will be left untouched.
+ *
+ * @ingroup Maintenance
+ */
+class FlowCreateTemplates extends LoggedUpdateMaintenance {
+ /**
+ * Returns an array of templates to be created (= pages in NS_TEMPLATE)
+ *
+ * The key in the array is an i18n message so the template titles can be
+ * internationalized and/or edited per wiki.
+ * The value is a callback function that will only receive $title and is
+ * expected to return the page content in wikitext.
+ *
+ * @return array [title i18n key => content callback]
+ */
+ protected function getTemplates() {
+ return array(
+ 'flow-ve-mention-template-title' => function( Title $title ) {
+ // get "User:" namespace prefix in wiki language
+ global $wgContLang;
+ $namespaces = $wgContLang->getFormattedNamespaces();
+
+ return '@[[' . $namespaces[NS_USER] .
':{{{1|Example}}}|{{{2|{{{1|Example}}}}}}]]';
+ },
+ );
+ }
+
+ public function __construct() {
+ parent::__construct();
+
+ $this->mDescription = "Creates Template:FlowMention, which is used te
render mentions in Flow's Visual Editor";
+ }
+
+ protected function getUpdateKey() {
+ $templates = $this->getTemplates();
+ $keys = array_keys( $templates );
+ sort( $keys );
+
+ // make the updatekey unique for the i18n keys of the pages to be
created
+ // so we can easily skip this update if there are no changes
+ return __CLASS__ . ':' . md5( implode( ',', $keys ) );
+ }
+
+ protected function doDBUpdates() {
+ $status = Status::newGood();
+
+ $templates = $this->getTemplates();
+ foreach ( $templates as $key => $callback ) {
+ $title = Title::newFromText( wfMessage( $key
)->inContentLanguage()->plain(), NS_TEMPLATE );
+ $content = new WikitextContent( $callback( $title ) );
+
+ $status->merge( $this->create( $title, $content ) );
+ }
+
+ return $status->isOK();
+ }
+
+ /**
+ * Creates a page with the given content (unless it already exists)
+ *
+ * @param Title $title
+ * @param WikitextContent $content
+ * @return Status
+ * @throws MWException
+ */
+ protected function create( Title $title, WikitextContent $content ) {
+ $article = new Article( $title );
+ $page = $article->getPage();
+
+ if ( $page->getRevision() !== null ) {
+ // template already exists, don't overwrite it
+ return Status::newGood();
+ }
+
+ return $page->doEditContent(
+ $content,
+ '/* Automatically created by Flow */',
+ EDIT_FORCE_BOT | EDIT_SUPPRESS_RC,
+ false,
+ FlowHooks::getOccupationController()->getTalkpageManager()
+ );
+ }
+}
+
+$maintClass = 'FlowCreateTemplates';
+require_once( RUN_MAINTENANCE_IF_MAIN );
--
To view, visit https://gerrit.wikimedia.org/r/232487
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib10fc648244e24783784ed53c7789a119408309a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits