jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/325732 )
Change subject: Override license messages for edit
......................................................................
Override license messages for edit
* Add config->license config string field to specify default content license
* New messages are shown at the bottom of the pages, edit notice, and edit
copyright msg
To enable, config object in $wgJsonConfigs must contain 'license': 'CC0-1.0+'
value
In the future, we have an easy way of implementing it per-page rather than per
content handler.
Bug: T152553
Change-Id: Ife272fbdd4b67a040f8c7753e82f4d461129fa70
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/JCDataContent.php
M includes/JCSingleton.php
M modules/JsonConfig.css
M tests/phpunit/JCLoaderTest.php
7 files changed, 114 insertions(+), 22 deletions(-)
Approvals:
JGirault: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index 292610b..82ede04 100644
--- a/extension.json
+++ b/extension.json
@@ -112,6 +112,9 @@
"EditFilterMergedContent": [
"JsonConfig\\JCSingleton::onEditFilterMergedContent"
],
+ "EditPageCopyrightWarning": [
+ "JsonConfig\\JCSingleton::onEditPageCopyrightWarning"
+ ],
"MovePageIsValidMove": [
"JsonConfig\\JCSingleton::onMovePageIsValidMove"
],
@@ -121,6 +124,12 @@
"ScribuntoExternalLibraries": [
"JsonConfig\\JCLuaLibrary::onScribuntoExternalLibraries"
],
+ "SkinCopyrightFooter": [
+ "JsonConfig\\JCSingleton::onSkinCopyrightFooter"
+ ],
+ "TitleGetEditNotices": [
+ "JsonConfig\\JCSingleton::onTitleGetEditNotices"
+ ],
"TitleMoveComplete": [
"JsonConfig\\JCSingleton::onTitleMoveComplete"
],
diff --git a/i18n/en.json b/i18n/en.json
index e4e452f..e6f1988 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -39,10 +39,12 @@
"jsonconfig-type-name-number": "number",
"jsonconfig-type-abbr-boolean": "(B)",
"jsonconfig-type-name-boolean": "boolean",
- "jsonconfig-license": "Data available under $1",
- "jsonconfig-license-or-later": "$1, or (at your option) any later
version",
- "jsonconfig-license-CC0-1.0": "Creative Commons Zero",
- "jsonconfig-license-url-CC0-1.0":
"https://creativecommons.org/publicdomain/zero/1.0/",
+ "jsonconfig-license": "Data available under $1.",
+ "jsonconfig-license-name-CC0-1.0+": "Creative Commons Zero",
+ "jsonconfig-license-url-CC0-1.0+":
"https://creativecommons.org/publicdomain/zero/1.0/",
+ "jsonconfig-license-copyrightwarning-CC0-1.0+": "By saving changes, you
agree to the [https://wikimediafoundation.org/wiki/Terms_of_Use Terms of Use],
and you irrevocably agree to release your contribution to the public domain
under [https://creativecommons.org/publicdomain/zero/1.0/ CC0].",
+ "jsonconfig-license-notice-box-CC0-1.0+": "{|
class='mw-jsonconfig-editnotice'\n| style='mw-jsonconfig-editnotice-icon' |
[[Image:PD-icon.svg|30px|link=|PD]]\n| $1\n|
style='mw-jsonconfig-editnotice-icon' |
[[Image:PD-icon.svg|30px|link=|PD]]\n|}",
+ "jsonconfig-license-notice-CC0-1.0+": "'''Note:''' When you edit this
page, you agree to release your contribution under the
[https://creativecommons.org/publicdomain/zero/1.0/ CC0].",
"right-jsonconfig-flush": "Manipulate JsonConfig via API",
"apihelp-jsonconfig-description": "Allows direct access to JsonConfig
subsystem.",
"apihelp-jsonconfig-param-command": "Which sub-action to perform on
JsonConfig:\n;status:Shows JsonConfig configuration.\n;reset:Clears
configurations from cache. Requires $1title parameter and jsonconfig-reset
right.\n;reload:Reloads and caches configurations from config store. Requires
$1title parameter and jsonconfig-reset right.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index c6aea8e..0566d4a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -48,9 +48,11 @@
"jsonconfig-type-abbr-boolean": "A very short indicator of the type of
data contained in this column. Shown for columns that contain booleans (true or
false)",
"jsonconfig-type-name-boolean": "Description of the type of data
contained in this column. Shown for columns that contain booleans (true or
false)\n{{Identical|Boolean}}",
"jsonconfig-license": "Shows license text prefix before giving the
specific license.\n\nParameters:\n* $1 - *
{{msg-mw|jsonconfig-license-or-later}} or {{msg-mw|jsonconfig-license-CC0-1.0}}
or other similar license messages",
- "jsonconfig-license-or-later": "In case the data can be used with any
future versions of a license, this string will be used instead of
'jsonconfig-license-*' message.\n\nParameters:\n* $1 - license name, as defined
in the {{msg-mw|jsonconfig-license-CC0-1.0}} and similar messages",
- "jsonconfig-license-CC0-1.0": "Name of the license",
- "jsonconfig-license-url-CC0-1.0": "URL to the license description,
localized if available",
+ "jsonconfig-license-name-CC0-1.0+": "Name of the CC0-1.0 license",
+ "jsonconfig-license-url-CC0-1.0+": "URL to the CC0-1.0 license
description, localized if available",
+ "jsonconfig-license-copyrightwarning-CC0-1.0+": "Wiki markup of the
message to show instead of {{msg-mw|Wikimedia-copyrightwarning}}",
+ "jsonconfig-license-notice-box-CC0-1.0+": "This box is shown during CC0
data editing. {{optional}}\n\nParameters:\n* $1 -
{{msg-mw|jsonconfig-license-notice-box-CC0-1.0+}}",
+ "jsonconfig-license-notice-CC0-1.0+": "Text to warn the user about CC0
nature of the data that they are editing. This text is shown inside the box
{{msg-mw|jsonconfig-license-notice-box-CC0-1.0+}}",
"right-jsonconfig-flush": "{{doc-right|jsonconfig-flush}}",
"apihelp-jsonconfig-description":
"{{doc-apihelp-description|jsonconfig}}",
"apihelp-jsonconfig-param-command": "The \"config store\" is the new
way to store the MediaWiki configuration outside
<code>LocalSettings.php</code>, namely in JSON files.
\n----\n{{doc-apihelp-param|jsonconfig|command}}",
diff --git a/includes/JCDataContent.php b/includes/JCDataContent.php
index b71fb02..c642e73 100644
--- a/includes/JCDataContent.php
+++ b/includes/JCDataContent.php
@@ -72,11 +72,6 @@
$license = $this->getLicenseObject();
if ( $license ) {
$text = $license['text']->inLanguage( $lang )->plain();
- // Legal suggested we don't add this just yet
-// if ( $license['laterVersion'] ) {
-// $text = wfMessage(
'jsonconfig-license-or-later', $text )
-// ->inLanguage( $lang )->plain();
-// }
$result->license = (object)[
'code' => $license['code'],
'text' => $text,
@@ -113,11 +108,6 @@
'href' => $license['url']->plain()
], $license['text']->plain() );
- // Legal suggested we don't add this just yet
-// if ( $license['laterVersion'] ) {
-// $text = wfMessage(
'jsonconfig-license-or-later', $text )->plain();
-// }
-
$text = wfMessage( 'jsonconfig-license' )->rawParams(
$text )->parse();
$html = Html::rawElement( 'p', [ 'class' =>
'mw-jsonconfig-license' ], $text );
@@ -132,14 +122,11 @@
$license = $this->getField( 'license' );
if ( $license && !$license->error() ) {
$code = $license->getValue();
- $laterVersion = substr( $code, -1 ) === '+';
- $baseCode = $laterVersion ? substr( $code, 0, - 1 ) :
$code;
return [
'code' => $code,
- 'laterVersion' => $laterVersion,
- 'text' => wfMessage( 'jsonconfig-license-' .
$baseCode ),
- 'url' => wfMessage( 'jsonconfig-license-url-' .
$baseCode ),
+ 'text' => wfMessage( 'jsonconfig-license-name-'
. $code ),
+ 'url' => wfMessage( 'jsonconfig-license-url-' .
$code ),
];
}
return false;
diff --git a/includes/JCSingleton.php b/includes/JCSingleton.php
index 555b1fc..797cd90 100644
--- a/includes/JCSingleton.php
+++ b/includes/JCSingleton.php
@@ -6,6 +6,7 @@
use ContentHandler;
use Exception;
use GenderCache;
+use Html;
use Language;
use MalformedTitleException;
use MapCacheLRU;
@@ -136,6 +137,7 @@
self::getConfVal( $conf, 'cacheExp', 24 * 60 * 60 );
self::getConfVal( $conf, 'cacheKey', '' );
self::getConfVal( $conf, 'flaggedRevs', false );
+ self::getConfVal( $conf, 'license', false );
$islocal = self::getConfVal( $conf, 'isLocal', true );
// Decide if matching configs should be stored on this
wiki
@@ -667,6 +669,80 @@
}
/**
+ * Override a per-page specific edit page copyright warning
+ *
+ * @param Title $title
+ * @param string[] $msg
+ *
+ * @return bool
+ */
+ public static function onEditPageCopyrightWarning( $title, &$msg ) {
+ if ( self::jsonConfigIsStorage() ) {
+ $jct = self::parseTitle( $title );
+ if ( $jct ) {
+ $code = $jct->getConfig()->license;
+ if ( $code ) {
+ $msg = [
'jsonconfig-license-copyrightwarning-' . $code ];
+ return false; // Do not allow any other
hook handler to override this
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Display a page-specific edit notice
+ *
+ * @param Title $title
+ * @param integer $oldid
+ * @param array &$notices
+ * @return bool
+ */
+ public static function onTitleGetEditNotices( Title $title, $oldid,
array &$notices ) {
+ if ( self::jsonConfigIsStorage() ) {
+ $jct = self::parseTitle( $title );
+ if ( $jct ) {
+ $code = $jct->getConfig()->license;
+ if ( $code ) {
+ $noticeText = wfMessage(
'jsonconfig-license-notice-' . $code )->parse();
+ $notices['jsonconfig'] =
+ wfMessage(
'jsonconfig-license-notice-box-' . $code )
+ ->rawParams(
$noticeText )
+ ->parseAsBlock();
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Override with per-page specific copyright message
+ *
+ * @param Title $title
+ * @param string $type
+ * @param string $msg
+ * @param $link
+ *
+ * @return bool
+ */
+ public static function onSkinCopyrightFooter( $title, $type, &$msg,
&$link ) {
+ if ( self::jsonConfigIsStorage() ) {
+ $jct = self::parseTitle( $title );
+ if ( $jct ) {
+ $code = $jct->getConfig()->license;
+ if ( $code ) {
+ $msg = 'jsonconfig-license';
+ $link = Html::element( 'a', [
+ 'href' => wfMessage(
'jsonconfig-license-url-' . $code )->plain()
+ ], wfMessage(
'jsonconfig-license-name-' . $code )->plain() );
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
* Adds CSS for pretty-printing configuration on NS_CONFIG pages.
* @param \OutputPage &$out
* @param \Skin &$skin
diff --git a/modules/JsonConfig.css b/modules/JsonConfig.css
index d8bf839..c3e4325 100644
--- a/modules/JsonConfig.css
+++ b/modules/JsonConfig.css
@@ -82,3 +82,18 @@
margin-bottom: 0.5em;
text-align: left;
}
+
+.mw-jsonconfig-editnotice {
+ color: #000;
+ border: solid 1px #A8A8A8;
+ padding: 0.5em;
+ margin: 0.5em 0;
+ background-color: #FFF;
+ font-size: 95%;
+ vertical-align: middle;
+}
+
+.mw-jsonconfig-editnotice-icon {
+ padding: 1em;
+ width: 30px;
+}
diff --git a/tests/phpunit/JCLoaderTest.php b/tests/phpunit/JCLoaderTest.php
index b431fc0..7181702 100644
--- a/tests/phpunit/JCLoaderTest.php
+++ b/tests/phpunit/JCLoaderTest.php
@@ -92,6 +92,7 @@
$result = (object)array_merge( [
'model' => 'test.model',
'isLocal' => true,
+ 'license' => false,
'namespace' => 482,
'pattern' => '',
'cacheExp' => 86400,
--
To view, visit https://gerrit.wikimedia.org/r/325732
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ife272fbdd4b67a040f8c7753e82f4d461129fa70
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: JGirault <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits