[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Parser: Allow disabling magic link functionality

2016-09-12 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Parser: Allow disabling magic link functionality
..


Parser: Allow disabling magic link functionality

The magic link functionality is "old backwards-compatibility baggage"
that we probably want to get rid of eventually. The first step to doing
so would be making it configurable and allowing it to be turned off on
wikis that don't use it.

This adds each of the 3 magic link types as individual parser options,
which can be controlled by the $wgEnableMagicLinks setting.

Additionally, wfEscapeWikiText() was updated to only escape enabled
magic link types.

Bug: T47942
Change-Id: If63965f31d17da4b864510146e0018da1cae188c
---
M includes/DefaultSettings.php
M includes/GlobalFunctions.php
M includes/parser/Parser.php
M includes/parser/ParserOptions.php
M tests/parser/ParserTestRunner.php
M tests/parser/parserTests.txt
6 files changed, 108 insertions(+), 4 deletions(-)

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



diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index ff7430b..3ab8829 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -4353,6 +4353,18 @@
  */
 $wgTranscludeCacheExpiry = 3600;
 
+/**
+ * Enable the magic links feature of automatically turning ISBN xxx,
+ * PMID xxx, RFC xxx into links
+ *
+ * @since 1.28
+ */
+$wgEnableMagicLinks = [
+   'ISBN' => true,
+   'PMID' => true,
+   'RFC' => true
+];
+
 /** @} */ # end of parser settings }
 
 ///**
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index f93c64e..0e59653 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -1665,6 +1665,7 @@
  * @return string
  */
 function wfEscapeWikiText( $text ) {
+   global $wgEnableMagicLinks;
static $repl = null, $repl2 = null;
if ( $repl === null ) {
$repl = [
@@ -1682,8 +1683,9 @@
'__' => '_', '://' => '//',
];
 
+   $magicLinks = array_keys( array_filter( $wgEnableMagicLinks ) );
// We have to catch everything "\s" matches in PCRE
-   foreach ( [ 'ISBN', 'RFC', 'PMID' ] as $magic ) {
+   foreach ( $magicLinks as $magic ) {
$repl["$magic "] = "$magic";
$repl["$magic\t"] = "$magic";
$repl["$magic\r"] = "$magic";
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index d83ea34..7c18798 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -1439,11 +1439,17 @@
} elseif ( isset( $m[5] ) && $m[5] !== '' ) {
# RFC or PMID
if ( substr( $m[0], 0, 3 ) === 'RFC' ) {
+   if ( !$this->mOptions->getMagicRFCLinks() ) {
+   return $m[0];
+   }
$keyword = 'RFC';
$urlmsg = 'rfcurl';
$cssClass = 'mw-magiclink-rfc';
$id = $m[5];
} elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) {
+   if ( !$this->mOptions->getMagicPMIDLinks() ) {
+   return $m[0];
+   }
$keyword = 'PMID';
$urlmsg = 'pubmedurl';
$cssClass = 'mw-magiclink-pmid';
@@ -1454,7 +1460,9 @@
}
$url = wfMessage( $urlmsg, $id 
)->inContentLanguage()->text();
return Linker::makeExternalLink( $url, "{$keyword} 
{$id}", true, $cssClass, [], $this->mTitle );
-   } elseif ( isset( $m[6] ) && $m[6] !== '' ) {
+   } elseif ( isset( $m[6] ) && $m[6] !== ''
+   && $this->mOptions->getMagicISBNLinks()
+   ) {
# ISBN
$isbn = $m[6];
$space = self::SPACE_NOT_NL; #  non-newline space
diff --git a/includes/parser/ParserOptions.php 
b/includes/parser/ParserOptions.php
index 891c4dd..fd826a2 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -216,6 +216,21 @@
private $mExtraKey = '';
 
/**
+* Are magic ISBN links enabled?
+*/
+   private $mMagicISBNLinks = true;
+
+   /**
+* Are magic PMID links enabled?
+*/
+   private $mMagicPMIDLinks = true;
+
+   /**
+* Are magic RFC links enabled?
+*/
+   private $mMagicRFCLinks = true;
+
+   /**
 * Function to be called when an option is 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Parser: Allow disabling magic link functionality

2016-09-09 Thread Legoktm (Code Review)
Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/309528

Change subject: Parser: Allow disabling magic link functionality
..

Parser: Allow disabling magic link functionality

The magic link functionality is "old backwards-compatibility baggage"
that we probably want to get rid of eventually. The first step to doing
so would be making it configurable and allowing it to be turned off on
wikis that don't use it.

This adds each of the 3 magic link types as individual parser options,
which can be controlled by the $wgEnableMagicLinks setting.

Additionally, wfEscapeWikiText() was updated to only escape enabled
magic link types.

Bug: T47942
Change-Id: If63965f31d17da4b864510146e0018da1cae188c
---
M includes/DefaultSettings.php
M includes/GlobalFunctions.php
M includes/parser/Parser.php
M includes/parser/ParserOptions.php
4 files changed, 87 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/28/309528/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index bae7420..c563928 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -4353,6 +4353,18 @@
  */
 $wgTranscludeCacheExpiry = 3600;
 
+/**
+ * Enable the magic links feature of automatically turning ISBN xxx,
+ * PMID xxx, RFC xxx into links
+ *
+ * @since 1.28
+ */
+$wgEnableMagicLinks = [
+   'ISBN' => true,
+   'PMID' => true,
+   'RFC' => true
+];
+
 /** @} */ # end of parser settings }
 
 ///**
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index bc78be5..b2a3726 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -1665,6 +1665,7 @@
  * @return string
  */
 function wfEscapeWikiText( $text ) {
+   global $wgEnableMagicLinks;
static $repl = null, $repl2 = null;
if ( $repl === null ) {
$repl = [
@@ -1682,8 +1683,9 @@
'__' => '_', '://' => '//',
];
 
+   $magicLinks = array_keys( array_filter( $wgEnableMagicLinks ) );
// We have to catch everything "\s" matches in PCRE
-   foreach ( [ 'ISBN', 'RFC', 'PMID' ] as $magic ) {
+   foreach ( $magicLinks as $magic ) {
$repl["$magic "] = "$magic";
$repl["$magic\t"] = "$magic";
$repl["$magic\r"] = "$magic";
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index b53920b..a71373d 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -1439,11 +1439,17 @@
} elseif ( isset( $m[5] ) && $m[5] !== '' ) {
# RFC or PMID
if ( substr( $m[0], 0, 3 ) === 'RFC' ) {
+   if ( !$this->mOptions->getMagicRFCLinks() ) {
+   return $m[0];
+   }
$keyword = 'RFC';
$urlmsg = 'rfcurl';
$cssClass = 'mw-magiclink-rfc';
$id = $m[5];
} elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) {
+   if ( !$this->mOptions->getMagicPMIDLinks() ) {
+   return $m[0];
+   }
$keyword = 'PMID';
$urlmsg = 'pubmedurl';
$cssClass = 'mw-magiclink-pmid';
@@ -1454,7 +1460,9 @@
}
$url = wfMessage( $urlmsg, $id 
)->inContentLanguage()->text();
return Linker::makeExternalLink( $url, "{$keyword} 
{$id}", true, $cssClass, [], $this->mTitle );
-   } elseif ( isset( $m[6] ) && $m[6] !== '' ) {
+   } elseif ( isset( $m[6] ) && $m[6] !== ''
+   && $this->mOptions->getMagicISBNLinks()
+   ) {
# ISBN
$isbn = $m[6];
$space = self::SPACE_NOT_NL; #  non-newline space
diff --git a/includes/parser/ParserOptions.php 
b/includes/parser/ParserOptions.php
index 891c4dd..fd826a2 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -216,6 +216,21 @@
private $mExtraKey = '';
 
/**
+* Are magic ISBN links enabled?
+*/
+   private $mMagicISBNLinks = true;
+
+   /**
+* Are magic PMID links enabled?
+*/
+   private $mMagicPMIDLinks = true;
+
+   /**
+* Are magic RFC links enabled?
+*/
+   private $mMagicRFCLinks = true;
+
+   /**
 * Function to be called when an option is accessed.
 */
private