Gergő Tisza has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189180
Change subject: New resource to import wiki pages from strings/text files
......................................................................
New resource to import wiki pages from strings/text files
Bug: T88872
Change-Id: Ice89478f2440eb31b1599ab3e86235ffeec66db6
---
M puppet/modules/mediawiki/manifests/import_dump.pp
A puppet/modules/mediawiki/manifests/import_text.pp
2 files changed, 70 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant
refs/changes/80/189180/1
diff --git a/puppet/modules/mediawiki/manifests/import_dump.pp
b/puppet/modules/mediawiki/manifests/import_dump.pp
index f2a196b..b193e48 100644
--- a/puppet/modules/mediawiki/manifests/import_dump.pp
+++ b/puppet/modules/mediawiki/manifests/import_dump.pp
@@ -1,6 +1,8 @@
# == Define: mediawiki::import_dump
#
-# Imports an xml dump into the wiki.
+# Imports an xml dump into the wiki. This is the recommended method for
+# importing "live" content from a wiki; for importing content that should live
+# in the puppet repository, see import_text.
#
# === Parameters
# [*xml_dump*]
diff --git a/puppet/modules/mediawiki/manifests/import_text.pp
b/puppet/modules/mediawiki/manifests/import_text.pp
new file mode 100644
index 0000000..0529277
--- /dev/null
+++ b/puppet/modules/mediawiki/manifests/import_text.pp
@@ -0,0 +1,67 @@
+# == Define: mediawiki::import_text
+#
+# Imports a string or text file into the wiki. This is the recommended method
for
+# importing version-controlled content such as documentation for vagrant roles;
+# for importing current content from a wiki, see import_dump.
+#
+# Apart from cleaner diffs when put into version control, the main difference
+# from import_dump is that import_text will update existing pages when
necessary.
+#
+# Required parameters are page_title and exactly one of path or content.
+#
+# === Parameters
+# [*page_title*]
+# Full title of the page where the text should be imported. Defaults to the
resource title.
+#
+# [*source*]
+# Fully qualified path to the file to import.
+#
+# [*content*]
+# Page content as a string.
+#
+# [*db_name*]
+# Wiki database to import page into. The default will import into the
+# primary wiki.
+#
+# [*wiki*]
+# Wiki to import page into. The default will import into the primary wiki.
+#
+# == Usage
+#
+# mediawiki::import_text { 'Main_Page':
+# content => template('mediawiki/mainpage.erb'),
+# }
+#
+define mediawiki::import_text(
+ $page_title = $title,
+ $source = undef,
+ $content = undef,
+ $db_name = $::mediawiki::db_name,
+ $wiki = $::mediawiki::wiki_name,
+) {
+ if $source == undef and $content == undef { fail('you must provide either
"source" or "content"') }
+ if $source != undef and $content != undef { fail('"source" and "content"
are mutually exclusive') }
+
+ if $wiki == $::mediawiki::wiki_name {
+ $path = "/srv/pages/${page_title}"
+ } else {
+ $path = "/srv/pages/wiki/${wiki}/${page_title}"
+ }
+
+ # workaround different instances of this resource not being able to define
the same directory
+ exec { "mkdir -p `basename ${path}`": }
+
+ file { $path:
+ source => $source,
+ content => $content,
+ require => Exec["mkdir -p `basename ${path}`"],
+ notify => Exec["add page ${wiki}/${page_title}"],
+ }
+
+ exec { "add page ${wiki}/${page_title}":
+ command => "mwscript edit.php --wiki=${db_name} --summary='Vagrant
import' --no-rc '${page_title}' < ${path}",
+ refreshonly => true,
+ user => 'www-data',
+ require => Mediawiki::Wiki[$wiki],
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/189180
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice89478f2440eb31b1599ab3e86235ffeec66db6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits