[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ParserOutput: Add stateless transforms to getText()

2017-11-30 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/393260 )

Change subject: ParserOutput: Add stateless transforms to getText()
..


ParserOutput: Add stateless transforms to getText()

The stateful transforms are deprecated.

Inspired by Krinkle's If2fb32fc.

Bug: T171797
Change-Id: Ied5fe1a6159c2d4fa48170042b44d735ce7b6f9b
---
M RELEASE-NOTES-1.31
M docs/hooks.txt
M includes/parser/ParserOptions.php
M includes/parser/ParserOutput.php
M tests/phpunit/includes/parser/ParserOutputTest.php
5 files changed, 298 insertions(+), 4 deletions(-)

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



diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31
index b32e3e7..139773b 100644
--- a/RELEASE-NOTES-1.31
+++ b/RELEASE-NOTES-1.31
@@ -31,6 +31,8 @@
   [[iw:User:Example|iw>Example]].
 * (T111605) The 'ImportHandleUnknownUser' hook allows extensions to auto-create
   users during an import.
+* Added a hook, ParserOutputPostCacheTransform, to allow extensions to affect
+  the ParserOutput::getText() post-cache transformations.
 
 === External library changes in 1.31 ===
 
@@ -119,6 +121,18 @@
 * The Block class will no longer accept usable-but-missing usernames for
   'byText' or ->setBlocker(). Callers should either ensure the blocker exists
   locally or use a new interwiki-format username like "iw>Example".
+* The following methods that get and set ParserOutput state are deprecated.
+  Callers should use the new stateless $options parameter to
+  ParserOutput::getText() instead.
+  * ParserOptions::getEditSection()
+  * ParserOptions::setEditSection()
+  * ParserOutput::getEditSectionTokens()
+  * ParserOutput::setEditSectionTokens()
+  * ParserOutput::getTOCEnabled()
+  * ParserOutput::setTOCEnabled()
+  * OutputPage::enableSectionEditLinks()
+  * OutputPage::sectionEditLinksEnabled()
+  * The public ParserOutput state fields $mTOCEnabled and $mEditSectionTokens 
are also deprecated.
 
 == Compatibility ==
 MediaWiki 1.31 requires PHP 5.5.9 or later. There is experimental support for
diff --git a/docs/hooks.txt b/docs/hooks.txt
index 685a182..29883b2 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -2594,6 +2594,12 @@
   callable here. The callable is passed the ParserOptions object and the option
   name.
 
+'ParserOutputPostCacheTransform': Called from ParserOutput::getText() to do
+post-cache transforms.
+$parserOutput: The ParserOutput object.
+&$text: The text being transformed, before core transformations are done.
+&$options: The options array being used for the transformation.
+
 'ParserSectionCreate': Called each time the parser creates a document section
 from wikitext. Use this to apply per-section modifications to HTML (like
 wrapping the section in a DIV).  Caveat: DIVs are valid wikitext, and a DIV
diff --git a/includes/parser/ParserOptions.php 
b/includes/parser/ParserOptions.php
index 5e2845f..f99089b 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -869,6 +869,7 @@
 
/**
 * Create "edit section" links?
+* @deprecated since 1.31, use ParserOutput::getText() options instead.
 * @return bool
 */
public function getEditSection() {
@@ -877,6 +878,7 @@
 
/**
 * Create "edit section" links?
+* @deprecated since 1.31, use ParserOutput::getText() options instead.
 * @param bool|null $x New value (null is no change)
 * @return bool Old value
 */
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php
index 3480a51..59c27e5 100644
--- a/includes/parser/ParserOutput.php
+++ b/includes/parser/ParserOutput.php
@@ -144,6 +144,7 @@
public $mSections = [];
 
/**
+* @deprecated since 1.31 Use getText() options.
 * @var bool $mEditSectionTokens prefix/suffix markers if edit sections 
were output as tokens.
 */
public $mEditSectionTokens = false;
@@ -164,6 +165,7 @@
public $mTimestamp;
 
/**
+* @deprecated since 1.31 Use getText() options.
 * @var bool $mTOCEnabled Whether TOC should be shown, can't override 
__NOTOC__.
 */
public $mTOCEnabled = true;
@@ -250,9 +252,38 @@
return $this->mText;
}
 
-   public function getText() {
+   /**
+* Get the output HTML
+*
+* @param array $options (since 1.31) Transformations to apply to the 
HTML
+*  - allowTOC: (bool) Show the TOC, assuming there were enough headings
+* to generate one and `__NOTOC__` wasn't used. Default is true,
+* but might be statefully overridden.
+*  - enableSectionEditLinks: (bool) Include section edit links, 
assuming
+*section edit link tokens are present in the HTML. Default is true,
+* but might be statefully overridden.
+* @return string 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ParserOutput: Add stateless transforms to getText()

2017-11-24 Thread Anomie (Code Review)
Anomie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393260 )

Change subject: ParserOutput: Add stateless transforms to getText()
..

ParserOutput: Add stateless transforms to getText()

The stateful transforms are deprecated.

Inspired by Krinkle's If2fb32fc.

Bug: T171797
Change-Id: Ied5fe1a6159c2d4fa48170042b44d735ce7b6f9b
---
M RELEASE-NOTES-1.31
M docs/hooks.txt
M includes/parser/ParserOptions.php
M includes/parser/ParserOutput.php
M tests/phpunit/includes/parser/ParserOutputTest.php
5 files changed, 290 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/60/393260/1

diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31
index 3de0e17..4fd3f20 100644
--- a/RELEASE-NOTES-1.31
+++ b/RELEASE-NOTES-1.31
@@ -22,6 +22,8 @@
 * As a first pass in standardizing dialog boxes across the MediaWiki product,
   Html class now provides helper methods for messageBox, successBox, errorBox 
and
   warningBox generation.
+* Added a hook, ParserOutputPostCacheTransform, to allow extensions to affect
+  the ParserOutput::getText() post-cache transformations.
 
 === External library changes in 1.31 ===
 
@@ -105,6 +107,18 @@
 * Use of Maintenance::error( $err, $die ) to exit script was deprecated. Use
   Maintenance::fatalError() instead.
 * Passing a ParserOptions object to OutputPage::parserOptions() is deprecated.
+* The following methods that get and set ParserOutput state are deprecated.
+  Callers should use the new stateless $options parameter to
+  ParserOutput::getText() instead.
+  * ParserOptions::getEditSection()
+  * ParserOptions::setEditSection()
+  * ParserOutput::getEditSectionTokens()
+  * ParserOutput::setEditSectionTokens()
+  * ParserOutput::getTOCEnabled()
+  * ParserOutput::setTOCEnabled()
+  * OutputPage::enableSectionEditLinks()
+  * OutputPage::sectionEditLinksEnabled()
+  * The public ParserOutput state fields $mTOCEnabled and $mEditSectionTokens 
are also deprecated.
 
 == Compatibility ==
 MediaWiki 1.31 requires PHP 5.5.9 or later. There is experimental support for
diff --git a/docs/hooks.txt b/docs/hooks.txt
index 6c1597f..216c078 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -2589,6 +2589,12 @@
   callable here. The callable is passed the ParserOptions object and the option
   name.
 
+'ParserOutputPostCacheTransform': Called from ParserOutput::getText() to do
+post-cache transforms.
+$parserOutput: The ParserOutput object.
+&$text: The text being transformed, before core transformations are done.
+&$options: The options array being used for the transformation.
+
 'ParserSectionCreate': Called each time the parser creates a document section
 from wikitext. Use this to apply per-section modifications to HTML (like
 wrapping the section in a DIV).  Caveat: DIVs are valid wikitext, and a DIV
diff --git a/includes/parser/ParserOptions.php 
b/includes/parser/ParserOptions.php
index 5e2845f..f99089b 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -869,6 +869,7 @@
 
/**
 * Create "edit section" links?
+* @deprecated since 1.31, use ParserOutput::getText() options instead.
 * @return bool
 */
public function getEditSection() {
@@ -877,6 +878,7 @@
 
/**
 * Create "edit section" links?
+* @deprecated since 1.31, use ParserOutput::getText() options instead.
 * @param bool|null $x New value (null is no change)
 * @return bool Old value
 */
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php
index 3480a51..7cbccf7 100644
--- a/includes/parser/ParserOutput.php
+++ b/includes/parser/ParserOutput.php
@@ -144,6 +144,7 @@
public $mSections = [];
 
/**
+* @deprecated since 1.31 Use getText() options.
 * @var bool $mEditSectionTokens prefix/suffix markers if edit sections 
were output as tokens.
 */
public $mEditSectionTokens = false;
@@ -164,6 +165,7 @@
public $mTimestamp;
 
/**
+* @deprecated since 1.31 Use getText() options.
 * @var bool $mTOCEnabled Whether TOC should be shown, can't override 
__NOTOC__.
 */
public $mTOCEnabled = true;
@@ -250,9 +252,36 @@
return $this->mText;
}
 
-   public function getText() {
+   /**
+* Get the output HTML
+*
+* @param array $options (since 1.31) Transformations to apply to the 
HTML
+*  - allowTOC: (bool) Show the TOC, assuming there were enough headings
+* to generate one and `__NOTOC__` wasn't used. Default is true,
+* but might be statefully overridden.
+*  - enableSectionEditLinks: (bool) Include section edit links, 
assuming
+*section edit link tokens are present in the HTML. Default is true,
+* but might be statefully overridden.
+