jenkins-bot has submitted this change and it was merged.
Change subject: ContentTranslationStats special page
......................................................................
ContentTranslationStats special page
Change-Id: Ia7bd3580e43da928d5328dc99d920591a46bc33d
---
M Autoload.php
M ContentTranslation.alias.php
M ContentTranslation.php
M i18n/en.json
M i18n/qqq.json
A specials/SpecialContentTranslationStats.php
A utils/ContentTranslationStats.php
7 files changed, 177 insertions(+), 2 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Autoload.php b/Autoload.php
index 73f4a36..01929bf 100644
--- a/Autoload.php
+++ b/Autoload.php
@@ -13,5 +13,7 @@
$wgAutoloadClasses += array(
'ApiContentTranslationPublish' =>
"$dir/api/ApiContentTranslationPublish.php",
'ContentTranslationHooks' => "$dir/ContentTranslation.hooks.php",
+ 'ContentTranslationStats' => "$dir/utils/ContentTranslationStats.php",
'SpecialContentTranslation' =>
"$dir/specials/SpecialContentTranslation.php",
+ 'SpecialContentTranslationStats' =>
"$dir/specials/SpecialContentTranslationStats.php",
);
diff --git a/ContentTranslation.alias.php b/ContentTranslation.alias.php
index 3969c7f..3283e38 100644
--- a/ContentTranslation.alias.php
+++ b/ContentTranslation.alias.php
@@ -14,6 +14,7 @@
/** English (English) */
$specialPageAliases['en'] = array(
'ContentTranslation' => array( 'ContentTranslation', 'CX' ),
+ 'ContentTranslationStats' => array( 'ContentTranslationStats',
'CXStats' ),
);
/** Arabic (العربية) */
@@ -44,6 +45,7 @@
/** Hebrew (עברית) */
$specialPageAliases['he'] = array(
'ContentTranslation' => array( 'תרגום_תוכן' ),
+ 'ContentTranslation' => array( 'סטטיסטיקות_תרגום_תוכן' ),
);
/** Upper Sorbian (hornjoserbsce) */
diff --git a/ContentTranslation.php b/ContentTranslation.php
index 12804eb..375bb2b 100644
--- a/ContentTranslation.php
+++ b/ContentTranslation.php
@@ -58,6 +58,7 @@
// Special pages
$GLOBALS['wgSpecialPages']['ContentTranslation'] = 'SpecialContentTranslation';
+$GLOBALS['wgSpecialPages']['ContentTranslationStats'] =
'SpecialContentTranslationStats';
// API modules
$GLOBALS['wgAPIModules']['cxpublish'] = 'ApiContentTranslationPublish';
diff --git a/i18n/en.json b/i18n/en.json
index ac07130..9f244eb 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -39,5 +39,12 @@
"cx-tools-dictionary-title": "Definition",
"cx-tools-link-title": "Link",
"cx-tools-link-add": "Add link",
- "cx-tools-link-remove": "Remove link"
+ "cx-tools-link-remove": "Remove link",
+ "cx-stats-title": "Content translation statistics",
+ "cx-stats-page-title": "Page",
+ "cx-stats-from": "Source language",
+ "cx-stats-to": "Target language",
+ "cx-stats-pages-title": "Translated pages",
+ "cx-stats-unknown": "unknown",
+ "cx-stats-summary": "{{PLURAL:$1|One page|$1/$2 pages ($3%)}} in the
main namespace."
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f38a1f8..6444d3e 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -41,5 +41,13 @@
"cx-tools-dictionary-title": "Title of definition tool
card.\n{{Identical|Definition}}",
"cx-tools-link-title": "Title of link tool card.\n{{Identical|Link}}",
"cx-tools-link-add": "Text shown in link tool card. Clicking on it adds
the link in the cursor position.\n{{Identical|Add link}}",
- "cx-tools-link-remove": "Text shown in link tool card. Clicking on it
removes the link in the context.\n{{Identical|Remove link}}"
+ "cx-tools-link-remove": "Text shown in link tool card. Clicking on it
removes the link in the context.\n{{Identical|Remove link}}",
+ "cx-stats-title": "The title for the Special:ContentTranslationStats
special page.",
+ "cx-stats-page-title": "A header for a table column. The column lists
titles of translated pages.",
+ "cx-stats-from": "A header for a table column. The column lists the
languages from which the pages were translated.",
+ "cx-stats-to": "A header for a table column. The column lists the
languages into which the pages were translated.",
+ "cx-stats-pages-title": "A heading for the section at
Special:ContentTranslationStats. The section shows a list of translated
articles.",
+ "cx-stats-languages-title": "A heading for the section at
Special:ContentTranslationStats. The section shows a list of languages between
which articles were translated, and the number of translations.",
+ "cx-stats-unknown": "Text when the source or target language is
unknown",
+ "cx-stats-summary": "A summary of the number of published pages. $1 is
the number of translated pages that were moved to the main namespace, $2 is the
total number of translated pages, and $3 is percent of pages in the main
namespace."
}
diff --git a/specials/SpecialContentTranslationStats.php
b/specials/SpecialContentTranslationStats.php
new file mode 100644
index 0000000..2b73b7f
--- /dev/null
+++ b/specials/SpecialContentTranslationStats.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * Contains the special page Special:ContentTranslationStats.
+ *
+ * @file
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+
+/**
+ * Shows some metrics about ContentTranslation usage.
+ * @ingroup SpecialPage
+ */
+class SpecialContentTranslationStats extends SpecialPage {
+ function __construct() {
+ parent::__construct( 'ContentTranslationStats' );
+ }
+
+ public function getDescription() {
+ return $this->msg( 'cx-stats-title' )->text();
+ }
+
+ public function execute( $parameters ) {
+ $out = $this->getOutput();
+ $skin = $this->getSkin();
+
+ $this->setHeaders();
+ $this->outputHeader();
+
+ $out->wrapWikiMsg( '== $1 ==', array( 'cx-stats-pages-title' )
);
+
+ // @TODO better to return title => stats iterator
+ $stats = ContentTranslationStats::getStats();
+ $out->addHtml( $this->getPagesTable( $stats ) );
+ }
+
+ private function getPagesTable( $pages ) {
+ global $wgContLang;
+
+ $namespaces = $wgContLang->getFormattedNamespaces();
+ $blanknamespace = $this->msg( 'blanknamespace' )->text();
+
+ $headingMsgs = array(
+ 'cx-stats-page-title',
+ 'cx-stats-from',
+ 'cx-stats-to',
+ );
+
+ // @TODO want to use html template here
+ $headingRow = '';
+ foreach ( $headingMsgs as $headingMsg ) {
+ $headingRow .= Html::element( 'th',
+ array(),
+ $this->msg( $headingMsg )->text()
+ );
+ }
+
+ $rows = array( Html::rawElement( 'tr',
+ array(),
+ $headingRow
+ ) );
+
+ $total = $main = 0;
+
+ foreach ( $pages as $row ) {
+ $title = Title::newFromRow( $row );
+
+ $total++;
+ if ( $title->inNamespace( NS_MAIN ) ) {
+ $main++;
+ }
+
+ $titleCell = Html::rawElement( 'td', array(),
Linker::link( $title ) );
+
+ $languages = FormatJson::decode( $row->ct_params );
+ if ( $languages === null ) {
+ $from = $to = $this->msg( 'cx-stats-unknown'
)->text();
+ } else {
+ $from = $languages->from;
+ $to = $languages->to;
+ }
+
+ $fromCell = Html::element( 'td', array(), $from );
+ $toCell = Html::element( 'td', array(), $to );
+
+ $rows[] = Html::rawElement( 'tr',
+ array(),
+ $titleCell . $fromCell . $toCell
+ );
+ }
+
+ $table = Html::rawElement( 'table',
+ array(
+ 'class' => 'wikitable sortable',
+ ),
+ implode( "\n", $rows )
+ );
+
+ $percentage = round( $main / $total * 100 );
+ $summary = wfMessage( 'cx-stats-summary' )
+ ->numParams( $main, $total, $percentage )
+ ->parse();
+
+ return $table . $summary;
+ }
+}
diff --git a/utils/ContentTranslationStats.php
b/utils/ContentTranslationStats.php
new file mode 100644
index 0000000..bd35c71
--- /dev/null
+++ b/utils/ContentTranslationStats.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Functions for getting ContentTranslation metrics.
+ *
+ * @file
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+
+/**
+ * Functions for getting ContentTranslation metrics.
+ */
+class ContentTranslationStats {
+ /**
+ * Get CX-related stats.
+ *
+ * @return ResultWrapper Current CX stats.
+ */
+ public static function getStats() {
+ $dbr = wfGetDB( DB_SLAVE );
+
+ return $dbr->select(
+ array(
+ 'change_tag',
+ 'revision',
+ 'page',
+ ),
+ array(
+ 'page_id',
+ 'page_namespace',
+ 'page_title',
+ 'max(ct_rev_id)',
+ 'ct_params',
+ 'rev_user',
+ ),
+ array (
+ 'ct_tag' => 'contenttranslation',
+ 'rev_id = ct_rev_id',
+ 'rev_page = page_id',
+ ),
+ __METHOD__,
+ array(
+ 'GROUP BY' => 'page_id',
+ // This prevents filesort
+ 'ORDER BY' => 'null',
+ )
+ );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/140690
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia7bd3580e43da928d5328dc99d920591a46bc33d
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits