jenkins-bot has submitted this change and it was merged.
Change subject: Allow admin to specify twig template for wikitext export report
......................................................................
Allow admin to specify twig template for wikitext export report
Bug: T93248
Change-Id: I154ae4d1eff4db2831ac424604468e2cc77bdd99
---
A data/db/migrations/20150517-add-campaigns-wikitext.sql
M data/db/schema.mysql
M data/i18n/en.json
M data/i18n/qqq.json
M data/templates/admin/campaign.html
M data/templates/reports/wikitext.html
M src/App.php
M src/Controllers/Admin/Campaign.php
M src/Controllers/Reports/Wikitext.php
M src/Dao/Campaigns.php
10 files changed, 101 insertions(+), 36 deletions(-)
Approvals:
BryanDavis: Looks good to me, approved
jenkins-bot: Verified
diff --git a/data/db/migrations/20150517-add-campaigns-wikitext.sql
b/data/db/migrations/20150517-add-campaigns-wikitext.sql
new file mode 100644
index 0000000..1d30e3f
--- /dev/null
+++ b/data/db/migrations/20150517-add-campaigns-wikitext.sql
@@ -0,0 +1,4 @@
+-- Add wikitext field to campaigns table for holding the wikitext template
+ALTER TABLE campaigns
+ ADD COLUMN wikitext BLOB
+ AFTER end_date;
\ No newline at end of file
diff --git a/data/db/schema.mysql b/data/db/schema.mysql
index 1c121a0..8d34383 100644
--- a/data/db/schema.mysql
+++ b/data/db/schema.mysql
@@ -31,6 +31,7 @@
, status TINYINT(1) DEFAULT 0
, start_date TIMESTAMP NOT NULL
, end_date TIMESTAMP NOT NULL
+ , wikitext BLOB
, PRIMARY KEY (id)
, UNIQUE KEY name (name)
, CONSTRAINT FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
diff --git a/data/i18n/en.json b/data/i18n/en.json
index e819909..9221e45 100644
--- a/data/i18n/en.json
+++ b/data/i18n/en.json
@@ -114,12 +114,14 @@
"admin-new-campaign-in-progress": "Cannot create a new campaign if one
is already in progress. Please end the current campaign before starting a new
one.",
"admin-campaign-reviewers": "Campaign reviewers:",
"admin-campaign-question": "Question $1:",
+ "admin-campaign-wikitext": "Wikitext report row template:",
"admin-campaign-questionbody-placeholder": "Add question text here",
"admin-campaign-name-placeholder": "Must be unique",
"admin-campaign-date-placeholder": "YYYY-MM-DD HH:MM:SS (UTC only)",
"admin-campaign-questiontitle-placeholder": "Add question title here.
For example: Criteria A: Innovation",
"admin-campaign-questionfooter-placeholder": "Add question footer
string here",
"admin-campaign-reporthead-placeholder": "Aggregated report column
header. For example: Innovation",
+ "admin-campaign-wikitext-placeholder": "Wikitext template",
"admin-reviewer-name": "Reviewer name",
"admin-reviewer-percentage": "Percentage reviewed",
diff --git a/data/i18n/qqq.json b/data/i18n/qqq.json
index 286854b..482605b 100644
--- a/data/i18n/qqq.json
+++ b/data/i18n/qqq.json
@@ -62,6 +62,8 @@
"admin-proposal-title": "Table column header",
"admin-proposal-theme": "Table column header",
"admin-proposal-amount": "Table column header",
+ "admin-campaign-wikitext": "Label for a wikitext template textarea",
+ "admin-campaign-wikitext-placeholder": "Placehodler for wikitext
template textarea placeholder",
"change-password": "Navigation menu item, links to password change
page.\n{{Identical|Change password}}",
"credits": "Credits page heading",
diff --git a/data/templates/admin/campaign.html
b/data/templates/admin/campaign.html
index 878b9de..c4e272e 100644
--- a/data/templates/admin/campaign.html
+++ b/data/templates/admin/campaign.html
@@ -4,6 +4,9 @@
{% if flash.form_defaults|default(false) %}
{% set ques = flash.form_defaults %}
{% endif %}
+{% if flash.campaign|default(false) %}
+{% set campaign = flash.campaign %}
+{% endif %}
{% block javascript %}
<script src="{{ siteUrl( 'js/campaign.js' ) }}"></script>
@@ -82,6 +85,15 @@
{% endfor %}
<div class="form-group">
+ <label for="wikitext" class="col-sm-2 control-label">
+ {{ 'admin-campaign-wikitext'|message }}
+ </label>
+ <div class="col-sm-10 {{ 'wikitext' in errors ? 'has-error' }}">
+ <textarea class="form-control monospace" rows="10" name="wikitext"
id="wikitext" placeholder="{{ 'admin-campaign-wikitext-placeholder'|message
}}">{{ campaign.wikitext }}</textarea>
+ </div>
+ </div>
+
+ <div class="form-group">
<label for="reviewers" class="col-sm-2 control-label">
{{ 'admin-campaign-reviewers'|message }}
</label>
diff --git a/data/templates/reports/wikitext.html
b/data/templates/reports/wikitext.html
index 9cc109b..d100758 100644
--- a/data/templates/reports/wikitext.html
+++ b/data/templates/reports/wikitext.html
@@ -30,39 +30,7 @@
<p></p>
<div class="panel-group" id="accordion">
{% for row in report.rows %}
- <div class="panel panel-default">
- <div class="panel-heading">
- <h4 class="panel-title">
- <a class="accordion-toggle collapsed block" data-toggle="collapse"
data-parent="#accordion" href="#proposal{{ row.id }}">
- {{ row.title }}
- ·
- <small>{{ "theme-#{row.theme}"|message }}</small>
- ·
- <small>
- {{ row.pcnt|number_format(2) }}%
- ({{ row.recommend }}/{{ row.rcnt }}){{ row.conditional }}
- </small>
- </a>
- </h4>
- </div>
- <div id="proposal{{ row.id }}" class="panel-collapse collapse">
- <div class="panel-body form-group">
- <a href="{{ row.url|raw }}" target="_blank">{{ row.title }}</a>
- <textarea class="form-control" rows="10" readonly>
-==Aggregated feedback from the committee for ''{{ row.title }}''==
-{{ '{{' }}Inspire/Review/Score
-{% for label, qid in questions %}
-| {{ label }} score={{ row[qid]|number_format(1) }}
-{% endfor %}
-| comments=
-{% for comment in row.comments %}
-* {{ comment|replace( { "\n":' ' } ) }}
-{% endfor %}
-{{ '}}' }}
-</textarea>
- </div>
- </div>
- </div>
+ {% include( template_from_string( template ) ) %}
{% endfor %}
</div>
diff --git a/src/App.php b/src/App.php
index 70d8e21..1c3bee1 100644
--- a/src/App.php
+++ b/src/App.php
@@ -277,6 +277,7 @@
new \Slim\Views\TwigExtension(),
new TwigExtension( $this->slim->parsoid ),
new \Wikimedia\SimpleI18n\TwigExtension(
$this->slim->i18nContext ),
+ new \Twig_Extension_StringLoader(),
);
// Set default view data
diff --git a/src/Controllers/Admin/Campaign.php
b/src/Controllers/Admin/Campaign.php
index 808c8e5..02af1ca 100644
--- a/src/Controllers/Admin/Campaign.php
+++ b/src/Controllers/Admin/Campaign.php
@@ -34,6 +34,45 @@
*/
class Campaign extends Controller {
+ /** @var string Default wikitext report template **/
+ protected $defaultWikitextTemplate = <<<ENDTWIG
+<div class="panel panel-default">
+ <div class="panel-heading">
+ <h4 class="panel-title">
+ <a class="accordion-toggle collapsed block"
data-toggle="collapse"
+ data-parent="#accordion" href="#proposal{{ row.id }}">
+ {{ row.title }}
+ ·
+ <small>{{ "theme-#{row.theme}"|message }}</small>
+ ·
+ <small>
+ {{ row.pcnt|number_format(2) }}%
+ ( {{ row.recommend }} / {{ row.rcnt }} ) {{
row.conditional }}
+ </small>
+ </a>
+ </h4>
+ </div>
+<div id="proposal{{ row.id }}" class="panel-collapse collapse">
+ <div class="panel-body form-group">
+ <a href="{{ row.url|raw }}" target="_blank">{{ row.title }}</a>
+ <textarea class="form-control" rows="10" readonly>
+==Aggregated feedback from the committee for ''{{ row.title }}''==
+{{ '{{' }}Inspire/Review/Score
+{% for label, qid in questions %}
+| {{ label }} score={{ row[qid]|number_format(1) }}
+{% endfor %}
+| comments=
+{% for comment in row.comments %}
+* {{ comment|replace( { "\n":' ' } ) }}
+{% endfor %}
+{{ '}}' }}
+</textarea>
+ </div>
+ </div>
+</div>
+ENDTWIG;
+
+
protected function handleGet( $id ) {
$reviewers = $this->dao->getReviewers();
if ( $id === 'new' ) {
@@ -41,6 +80,7 @@
'name' => '',
'start_date' => date( 'Y-m-d H:i:s' ),
'end_date' => date( 'Y-m-d H:i:s', strtotime(
'+30 days' ) ),
+ 'wikitext' => $this->defaultWikitextTemplate
);
$questions = array();
for ( $idx = 0; $idx < 5; $idx ++ ) {
@@ -92,11 +132,28 @@
$this->form->requireStringArray( 'qfooters' );
$this->form->requireStringArray( 'qreporthead' );
+ $this->form->expectString( 'wikitext',
+ array( 'validate' => function ( $value ) {
+ $twig = $this->view->getInstance();
+ try {
+ $twig->parse( $twig->tokenize( $value )
);
+ } catch( \Twig_Error_Syntax $e ) {
+ $this->log->error( 'Invalid template
submitted', array(
+ 'template' => $value,
+ 'exception' => $e,
+ ) );
+ return false;
+ }
+ return true;
+ } )
+ );
+
if ( $this->form->validate() ) {
$params = array(
'name' => $this->form->get( 'name' ),
'start_date' => $this->form->get( 'start_date'
),
'end_date' => $this->form->get( 'end_date' ),
+ 'wikitext' => $this->form->get( 'wikitext' )
);
$questions = $this->form->get( 'questions' );
@@ -215,7 +272,14 @@
);
}
}
+ $campaignDefaults = array(
+ 'name' => $this->form->get( 'name' ),
+ 'start_date' => $this->form->get( 'start_date'
),
+ 'end_date' => $this->form->get( 'end_date' ),
+ 'wikitext' => $this->request->post( 'wikitext' )
+ );
$this->flash( 'form_defaults', $quesDefaults );
+ $this->flash( 'campaign', $campaignDefaults );
}
$this->redirect( $this->urlFor( 'admin_campaign', array( 'id'
=> $id ) ) );
@@ -223,4 +287,3 @@
}
}
-
diff --git a/src/Controllers/Reports/Wikitext.php
b/src/Controllers/Reports/Wikitext.php
index 5885ec3..6d265cd 100644
--- a/src/Controllers/Reports/Wikitext.php
+++ b/src/Controllers/Reports/Wikitext.php
@@ -60,7 +60,7 @@
$records = $this->dao->export(
$this->activeCampaign, $this->getQuestions(), $params
);
-
+ $template = $this->campaignsDao->getTemplate(
$this->activeCampaign );
// HACK: map questions to A, B, C, D criteria labels for use in
output
// template.
// FIXME: find a better way to associate questions and the
wikitext
@@ -75,6 +75,7 @@
$this->view->set( 'questions', $questions );
$this->view->setData( 'report', $records );
$this->view->set( 'th', $this->form->get( 'th' ) );
+ $this->view->set( 'template', $template['wikitext'] );
$this->render( 'reports/wikitext.html' );
}
}
diff --git a/src/Dao/Campaigns.php b/src/Dao/Campaigns.php
index eba0bd2..a62b952 100644
--- a/src/Dao/Campaigns.php
+++ b/src/Dao/Campaigns.php
@@ -351,7 +351,7 @@
* @return bool True if update suceeded, false otherwise
*/
public function updateCampaign( $params, $id ) {
- $fields = array( 'name', 'start_date', 'end_date' );
+ $fields = array_keys( $params );
$placeholders = array();
foreach ( $fields as $field ) {
$placeholders[] = "{$field} = :{$field}";
@@ -403,6 +403,17 @@
/**
+ * Fetch the wikitext template for given campaign ID
+ */
+ public function getTemplate( $campaign ) {
+ return $this->fetch(
+ 'SELECT wikitext from campaigns WHERE id = ?',
+ array( $campaign )
+ );
+ }
+
+
+ /**
* Inserts new questions into the campaign_questions table
* @param integer $campaign Campaign id
* @param array $questions Array of questions to be added
--
To view, visit https://gerrit.wikimedia.org/r/211525
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I154ae4d1eff4db2831ac424604468e2cc77bdd99
Gerrit-PatchSet: 7
Gerrit-Project: wikimedia/iegreview
Gerrit-Branch: master
Gerrit-Owner: Niharika29 <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Niharika29 <[email protected]>
Gerrit-Reviewer: Springle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits