jenkins-bot has submitted this change and it was merged.
Change subject: Add server-side logging to snippets, with i18n for header.
......................................................................
Add server-side logging to snippets, with i18n for header.
* Use Html::element for header, since it is HTML, and I think this is
the most straight-forward way to do a correctly escaped HTML element.
Change-Id: I6a943671471253a5dc7a76988b6cb2caf35c442f
---
M EventLogging.i18n.php
M includes/JsonSchemaContent.php
2 files changed, 30 insertions(+), 7 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/EventLogging.i18n.php b/EventLogging.i18n.php
index af7f384..f5f3a9f 100644
--- a/EventLogging.i18n.php
+++ b/EventLogging.i18n.php
@@ -16,6 +16,9 @@
'eventlogging-desc' => 'Framework for logging events from client-side
code',
'eventlogging-invalid-json' => 'Invalid JSON',
'eventlogging-revision-id' => 'Revision $1',
+ 'eventlogging-code-sample-logging-on-server-side' => 'PHP logging',
+ 'eventlogging-code-sample-module-setup' => 'PHP setup for JavaScript
logging',
+ 'eventlogging-code-sample-logging-on-client-side' => 'JavaScript
logging',
);
/** Message documentation (Message documentation)
@@ -28,6 +31,9 @@
'eventlogging-invalid-json' => 'Error shown when an editor attempts to
save a Schema article edit that is not valid JSON',
'eventlogging-revision-id' => 'The numeric ID of the displayed
revision, shown in the page subtitle.
{{Identical|Revision}}',
+ 'eventlogging-code-sample-logging-on-server-side' => 'Code sample for
logging a server-side event',
+ 'eventlogging-code-sample-module-setup' => 'Code sample for setting up
a ResourceLoader module',
+ 'eventlogging-code-sample-logging-on-client-side' => 'Code sample for
logging a client-side event',
);
/** Asturian (asturianu)
diff --git a/includes/JsonSchemaContent.php b/includes/JsonSchemaContent.php
index 38460d0..053d131 100644
--- a/includes/JsonSchemaContent.php
+++ b/includes/JsonSchemaContent.php
@@ -97,18 +97,30 @@
* use a schema.
* @param string $dbKey DB key of schema article
* @param int $revId Revision ID of schema article
- * @return array: Array mapping language names to source code
+ * @return array: Nested array with each sub-array having a language,
header
+ * (message key), and code
*/
public function getCodeSamples( $dbKey, $revId ) {
return array(
- 'PHP' =>
- "\$wgResourceModules[ 'schema.{$dbKey}' ] =
array(\n" .
+ array(
+ 'language' => 'php',
+ 'header' =>
'eventlogging-code-sample-logging-on-server-side',
+ 'code' => "efLogServerSideEvent( '$dbKey',
$revId, \$event );",
+ ),
+ array(
+ 'language' => 'php',
+ 'header' =>
'eventlogging-code-sample-module-setup',
+ 'code' => "\$wgResourceModules[
'schema.{$dbKey}' ] = array(\n" .
" 'class' =>
'ResourceLoaderSchemaModule',\n" .
" 'schema' => '{$dbKey}',\n" .
" 'revision' => {$revId},\n" .
");",
- 'JavaScript' =>
- "mw.eventLog.logEvent( '{$dbKey}', { /* ... */
} );"
+ ),
+ array(
+ 'language' => 'javascript',
+ 'header' =>
'eventlogging-code-sample-logging-on-client-side',
+ 'code' => "mw.eventLog.logEvent( '{$dbKey}', {
/* ... */ } );",
+ ),
);
}
@@ -134,10 +146,15 @@
if ( $revId !== null && class_exists( 'SyntaxHighlight_GeSHi' )
) {
$html = '';
$highlighter = new SyntaxHighlight_GeSHi();
- foreach( self::getCodeSamples( $title->getDBkey(),
$revId ) as $lang => $code ) {
+ foreach( self::getCodeSamples( $title->getDBkey(),
$revId ) as $sample ) {
+ $lang = $sample['language'];
+ $code = $sample['code'];
$geshi = $highlighter->prepare( $code, $lang );
$out->addHeadItem( $highlighter::buildHeadItem(
$geshi ), "source-$lang" );
- $html .= Xml::tags( 'h2', array(), $lang ) .
$geshi->parse_code();
+ $html .= Html::element( 'h2',
+ array(),
+ wfMessage( $sample['header'] )->text()
+ ) . $geshi->parse_code();
}
// The glyph is '< >' from the icon font 'Entypo' (see
../modules).
$html = Xml::tags( 'div', array( 'class' =>
'mw-json-schema-code-glyph' ), '' ) .
--
To view, visit https://gerrit.wikimedia.org/r/63601
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6a943671471253a5dc7a76988b6cb2caf35c442f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits