[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: "Form chooser" UI now displays most popular forms separately

2016-11-29 Thread Yaron Koren (Code Review)
Yaron Koren has submitted this change and it was merged.

Change subject: "Form chooser" UI now displays most popular forms separately
..


"Form chooser" UI now displays most popular forms separately

Change-Id: Ia415ab00f19b241d7e07e11c83ae421e6644e778
---
M i18n/en.json
M i18n/qqq.json
M includes/PF_FormEditAction.php
3 files changed, 104 insertions(+), 10 deletions(-)

Approvals:
  Yaron Koren: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index d15d05d..5f34e44 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -147,6 +147,8 @@
"pf_formstart_createoredit": "Create or edit",
"formedit": "Edit with form",
"pf-formedit-selectform": "Select a form to create this page:",
+   "pf-formedit-mainforms": "Main forms:",
+   "pf-formedit-otherforms": "Other forms:",
"pf-formedit-donotuseform": "Create page without a form.",
"pf_formedit_createtitle": "Create $1: $2",
"pf_formedit_createtitlenotarget": "Create $1",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index d5ceebd..5dd4282 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -153,7 +153,7 @@
"pf_createclass_listofvalues": "In response the user has to tick a box 
deciding whether it is allowed to enter or store a list of values. No values 
are entered at this point.",
"pf_createclass_nameinput": "Label for a text field, the form 
associated to the class.",
"pf_createclass_missingvalues": "Error message, which appears after the 
user saves without all required field.",
-   "pf_createclass_success": "Informational message, which appears after 
the user succespfully filled the form.",
+   "pf_createclass_success": "Informational message, which appears after 
the user successfully filled out the form.",
"pf_createclass_create": "{{Identical|Create}}",
"formstart": "{{doc-special|FormStart}}",
"pf_formstart_badform": "Used as error message. Parameters:\n* $1 - 
form name (with link)",
@@ -163,6 +163,8 @@
"pf_formstart_createoredit": "Button",
"formedit": "{{doc-special|FormEdit}}",
"pf-formedit-selectform": "A header displayed above a group of choices 
for the user",
+   "pf-formedit-mainforms": "A header above a list of the most widely-used 
forms in the wiki",
+   "pf-formedit-otherforms": "A header above a list of the forms on the 
wiki that are not the most widely-used",
"pf-formedit-donotuseform": "An option displayed to users as a link. 
Doing without a form means using the normal wiki editor/textarea, while the 
forms provided by this extension present a list of fields to fill in order to 
create a page.",
"pf_formedit_createtitle": "Used as page title. Parameters:\n* $1 - the 
main part of the title of a page form\n* $2 - the prefixed title, with spaces 
for the target page\nSee also:\n* {{msg-mw|pf formedit createtitlenotarget}}\n* 
{{msg-mw|pf formedit edittitle}}\n{{Identical|Create}}",
"pf_formedit_createtitlenotarget": "Used as page title. Parameters:\n* 
$1 - the main part of the title of a page form\nSee also:\n* {{msg-mw|pf 
formedit edittitle}}\n* {{msg-mw|pf formedit 
createtitle}}\n{{Identical|Create}}",
diff --git a/includes/PF_FormEditAction.php b/includes/PF_FormEditAction.php
index 9cd71b3..06773a3 100644
--- a/includes/PF_FormEditAction.php
+++ b/includes/PF_FormEditAction.php
@@ -1,7 +1,8 @@
-   addHTML( Html::element( 'p', null, wfMessage( 
'pf-formedit-selectform' )->text() ) );
$formNames = PFUtils::getAllForms();
+   $pagesPerForm = self::getNumPagesPerForm();
+   $totalPages = 0;
+   foreach ( $pagesPerForm as $formName => $numPages ) {
+   $totalPages += $numPages;
+   }
+   // We define "popular forms" as those that are used to
+   // edit more than 1% of the wiki's form-editable pages.
+   $popularForms = array();
+   foreach ( $pagesPerForm as $formName => $numPages ) {
+   if ( $numPages > $totalPages / 100 ) {
+   $popularForms[] = $formName;
+   }
+   }
+   $otherForms = array();
+   foreach( $formNames as $i => $formName ) {
+   if ( !in_array( $formName, $popularForms ) ) {
+   $otherForms[] = $formName;
+   }
+   }
+
$fe = SpecialPageFactory::getPage( 'FormEdit' );
+
+   if ( count( $popularForms ) > 0 ) {
+   if ( count( $otherForms ) > 0 ) {
+   $output->addHTML( Html::element(
+   'p',
+   array(),
+   wfMessage( 'pf-formedit-mainforms' 
)->text()
+

[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: "Form chooser" UI now displays most popular forms separately

2016-11-29 Thread Yaron Koren (Code Review)
Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324378

Change subject: "Form chooser" UI now displays most popular forms separately
..

"Form chooser" UI now displays most popular forms separately

Change-Id: Ia415ab00f19b241d7e07e11c83ae421e6644e778
---
M i18n/en.json
M i18n/qqq.json
M includes/PF_FormEditAction.php
3 files changed, 104 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms 
refs/changes/78/324378/2

diff --git a/i18n/en.json b/i18n/en.json
index d15d05d..5f34e44 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -147,6 +147,8 @@
"pf_formstart_createoredit": "Create or edit",
"formedit": "Edit with form",
"pf-formedit-selectform": "Select a form to create this page:",
+   "pf-formedit-mainforms": "Main forms:",
+   "pf-formedit-otherforms": "Other forms:",
"pf-formedit-donotuseform": "Create page without a form.",
"pf_formedit_createtitle": "Create $1: $2",
"pf_formedit_createtitlenotarget": "Create $1",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index d5ceebd..8544eb6 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -153,7 +153,7 @@
"pf_createclass_listofvalues": "In response the user has to tick a box 
deciding whether it is allowed to enter or store a list of values. No values 
are entered at this point.",
"pf_createclass_nameinput": "Label for a text field, the form 
associated to the class.",
"pf_createclass_missingvalues": "Error message, which appears after the 
user saves without all required field.",
-   "pf_createclass_success": "Informational message, which appears after 
the user succespfully filled the form.",
+   "pf_createclass_success": "Informational message, which appears after 
the user successfully filled out the form.",
"pf_createclass_create": "{{Identical|Create}}",
"formstart": "{{doc-special|FormStart}}",
"pf_formstart_badform": "Used as error message. Parameters:\n* $1 - 
form name (with link)",
@@ -163,6 +163,8 @@
"pf_formstart_createoredit": "Button",
"formedit": "{{doc-special|FormEdit}}",
"pf-formedit-selectform": "A header displayed above a group of choices 
for the user",
+   "pf-formedit-mainforms": "A header above a list of the most widely-used 
forms in the wiki",
++   "pf-formedit-otherforms": "A header above a list of the forms on the 
wiki that are not the most widely-used",
"pf-formedit-donotuseform": "An option displayed to users as a link. 
Doing without a form means using the normal wiki editor/textarea, while the 
forms provided by this extension present a list of fields to fill in order to 
create a page.",
"pf_formedit_createtitle": "Used as page title. Parameters:\n* $1 - the 
main part of the title of a page form\n* $2 - the prefixed title, with spaces 
for the target page\nSee also:\n* {{msg-mw|pf formedit createtitlenotarget}}\n* 
{{msg-mw|pf formedit edittitle}}\n{{Identical|Create}}",
"pf_formedit_createtitlenotarget": "Used as page title. Parameters:\n* 
$1 - the main part of the title of a page form\nSee also:\n* {{msg-mw|pf 
formedit edittitle}}\n* {{msg-mw|pf formedit 
createtitle}}\n{{Identical|Create}}",
diff --git a/includes/PF_FormEditAction.php b/includes/PF_FormEditAction.php
index 9cd71b3..06773a3 100644
--- a/includes/PF_FormEditAction.php
+++ b/includes/PF_FormEditAction.php
@@ -1,7 +1,8 @@
-   addHTML( Html::element( 'p', null, wfMessage( 
'pf-formedit-selectform' )->text() ) );
$formNames = PFUtils::getAllForms();
+   $pagesPerForm = self::getNumPagesPerForm();
+   $totalPages = 0;
+   foreach ( $pagesPerForm as $formName => $numPages ) {
+   $totalPages += $numPages;
+   }
+   // We define "popular forms" as those that are used to
+   // edit more than 1% of the wiki's form-editable pages.
+   $popularForms = array();
+   foreach ( $pagesPerForm as $formName => $numPages ) {
+   if ( $numPages > $totalPages / 100 ) {
+   $popularForms[] = $formName;
+   }
+   }
+   $otherForms = array();
+   foreach( $formNames as $i => $formName ) {
+   if ( !in_array( $formName, $popularForms ) ) {
+   $otherForms[] = $formName;
+   }
+   }
+
$fe = SpecialPageFactory::getPage( 'FormEdit' );
+
+   if ( count( $popularForms ) > 0 ) {
+   if ( count( $otherForms ) > 0 ) {
+   $output->addHTML( Html::element(
+   'p',
+   array(),
+