Anomie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/347433 )

Change subject: API: Add terms to auto-generated documentation
......................................................................

API: Add terms to auto-generated documentation

By default this just reuses copyrightwarning, but WMF will override (see
I6f50a552a).

Bug: T42459
Change-Id: Ie0b306bc6befe0accf5208eb25f91043a9ed3f91
---
M docs/hooks.txt
M includes/api/ApiHelp.php
M includes/api/ApiMain.php
M includes/api/i18n/en.json
M includes/api/i18n/qqq.json
5 files changed, 61 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/33/347433/1

diff --git a/docs/hooks.txt b/docs/hooks.txt
index af0eb06..7d8e326 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -369,6 +369,11 @@
  * 1.27+: IApiMessage, or a key or key+parameters in ApiBase::$messageMap.
  * Earlier: A key or key+parameters in ApiBase::$messageMap.
 
+'APICopyrightWarning': Allow for site and per-namespace customization of
+contribution/copyright notice.
+&$msg: Message object, overridable.
+$context: IContextSource object.
+
 'ApiDeprecationHelp': Add messages to the 'deprecation-help' warning generated
 from ApiBase::addDeprecation().
 &$msgs: Message[] Messages to include in the help. Multiple messages will be
diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php
index df9ca98..9f606e9 100644
--- a/includes/api/ApiHelp.php
+++ b/includes/api/ApiHelp.php
@@ -141,6 +141,8 @@
                        if ( !$msg->isDisabled() ) {
                                $out->addHTML( $msg->parseAsBlock() );
                        }
+
+                       $out->addHTML( self::getRightsMessage( $context 
)->parseAsBlock() );
                }
 
                $haveModules = [];
@@ -795,6 +797,28 @@
                return $out;
        }
 
+       /**
+        * Fetch the Message for the API terms
+        * @param IContextSource $context
+        */
+       public static function getRightsMessage( IContextSource $context ) {
+               $rightsText = $context->getConfig()->get( 'RightsText' );
+               if ( $rightsText ) {
+                       $msg = $context->msg(
+                               array( 'api-terms', 'copyrightwarning' ),
+                               '[[' . $context->msg( 'copyrightpage' 
)->inContentLanguage()->text() . ']]',
+                               $rightsText
+                       );
+               } else {
+                       $msg = $context->msg(
+                               array( 'api-terms2', 'copyrightwarning2' ),
+                               '[[' . $context->msg( 'copyrightpage' 
)->inContentLanguage()->text() . ']]'
+                       );
+               }
+               Hooks::run( 'APICopyrightWarning', array( &$msg, $context ) );
+               return $msg;
+       }
+
        public function shouldCheckMaxlag() {
                return false;
        }
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index b5eff70..397e2b0 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -1853,6 +1853,7 @@
                        $help[$k] = $v;
                }
                $help['datatypes'] = '';
+               $help['terms'] = '';
                $help['credits'] = '';
 
                // Fill 'permissions'
@@ -1885,7 +1886,7 @@
                $help['permissions'] .= Html::closeElement( 'dl' );
                $help['permissions'] .= Html::closeElement( 'div' );
 
-               // Fill 'datatypes' and 'credits', if applicable
+               // Fill 'datatypes', 'terms', and 'credits', if applicable
                if ( empty( $options['nolead'] ) ) {
                        $level = $options['headerlevel'];
                        $tocnumber = &$options['tocnumber'];
@@ -1916,6 +1917,30 @@
 
                        // Add an additional span with sanitized ID
                        if ( !$this->getConfig()->get( 'ExperimentalHtmlIds' ) 
) {
+                               $header = Html::element( 'span', [ 'id' => 
Sanitizer::escapeId( 'main/terms' ) ] ) .
+                                       $header;
+                       }
+                       $header = $this->msg( 'api-terms-header' )->parse();
+                       $help['terms'] .= Html::rawelement( 'h' . min( 6, 
$level ),
+                               array( 'id' => 'main/terms', 'class' => 
'apihelp-header' ),
+                               Html::element( 'span', array( 'id' => 
Sanitizer::escapeId( 'main/terms' ) ) ) .
+                               $header
+                       );
+                       $help['terms'] .= ApiHelp::getRightsMessage( $this 
)->parseAsBlock();
+                       if ( !isset( $tocData['main/terms'] ) ) {
+                               $tocnumber[$level]++;
+                               $tocData['main/terms'] = array(
+                                       'toclevel' => count( $tocnumber ),
+                                       'level' => $level,
+                                       'anchor' => 'main/terms',
+                                       'line' => $header,
+                                       'number' => join( '.', $tocnumber ),
+                                       'index' => false,
+                               );
+                       }
+
+                       // Add an additional span with sanitized ID
+                       if ( !$this->getConfig()->get( 'ExperimentalHtmlIds' ) 
) {
                                $header = Html::element( 'span', [ 'id' => 
Sanitizer::escapeId( 'main/credits' ) ] ) .
                                        $header;
                        }
diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json
index 7a04caf..b8d168c 100644
--- a/includes/api/i18n/en.json
+++ b/includes/api/i18n/en.json
@@ -1808,6 +1808,9 @@
        "api-usage-docref": "See $1 for API usage.",
        "api-usage-mailinglist-ref": "Subscribe to the mediawiki-api-announce 
mailing list at 
<https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for 
notice of API deprecations and breaking changes.",
        "api-exception-trace": "$1 at $2($3)\n$4",
+       "api-terms-header": "Terms",
+       "api-terms": "",
+       "api-terms2": "",
        "api-credits-header": "Credits",
        "api-credits": "API developers:\n* Yuri Astrakhan (creator, lead 
developer Sep 2006–Sep 2007)\n* Roan Kattouw (lead developer Sep 2007–2009)\n* 
Victor Vasiliev\n* Bryan Tong Minh\n* Sam Reed\n* Brad Jorsch (lead developer 
2013–present)\n\nPlease send your comments, suggestions and questions to 
[email protected]\nor file a bug report at 
https://phabricator.wikimedia.org/.";
 }
diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json
index 6e70653..20f9f46 100644
--- a/includes/api/i18n/qqq.json
+++ b/includes/api/i18n/qqq.json
@@ -1698,6 +1698,9 @@
        "api-usage-docref": "\n\nParameters:\n* $1 - URL of the API 
auto-generated documentation.",
        "api-usage-mailinglist-ref": "{{doc-apierror}} Also used in the error 
response.",
        "api-exception-trace": "\n\nParameters:\n* $1 - Exception class.\n* $2 
- File from which the exception was thrown.\n* $3 - Line number from which the 
exception was thrown.\n* $4 - Exception backtrace.",
+       "api-terms-header": "Header for the API terms section in the API help 
output",
+       "api-terms": "{{notranslate}} Copyright warning displayed on action API 
auto-generated help pages. If empty, {{msg-mw|copyrightwarning}} will be used. 
Parameters:\n* $1 - link\n* $2 - license name",
+       "api-terms2": "{{notranslate}} Copyright warning displayed on action 
API auto-generated help pages. If empty, {{msg-mw|copyrightwarning2}} will be 
used. Parameters:\n* $1 - link",
        "api-credits-header": "Header for the API credits section in the API 
help output\n{{Identical|Credit}}",
        "api-credits": "API credits text, displayed in the API help output"
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/347433
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie0b306bc6befe0accf5208eb25f91043a9ed3f91
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to