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
*/
$wgTranscludeCacheExpiry = 3600;
*/
$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 }
/************************************************************************//**
/** @} */ # end of parser settings }
/************************************************************************//**
* @return string
*/
function wfEscapeWikiText( $text ) {
* @return string
*/
function wfEscapeWikiText( $text ) {
+ global $wgEnableMagicLinks;
static $repl = null, $repl2 = null;
if ( $repl === null ) {
$repl = [
static $repl = null, $repl2 = null;
if ( $repl === null ) {
$repl = [
'__' => '__', '://' => '://',
];
'__' => '__', '://' => '://',
];
+ $magicLinks = array_keys( array_filter( $wgEnableMagicLinks ) );
// We have to catch everything "\s" matches in PCRE
// 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 ";
$repl["$magic "] = "$magic ";
$repl["$magic\t"] = "$magic	";
$repl["$magic\r"] = "$magic ";
} elseif ( isset( $m[5] ) && $m[5] !== '' ) {
# RFC or PMID
if ( substr( $m[0], 0, 3 ) === 'RFC' ) {
} 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' ) {
$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';
$keyword = 'PMID';
$urlmsg = 'pubmedurl';
$cssClass = 'mw-magiclink-pmid';
}
$url = wfMessage( $urlmsg, $id )->inContentLanguage()->text();
return Linker::makeExternalLink( $url, "{$keyword} {$id}", true, $cssClass, [], $this->mTitle );
}
$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
# ISBN
$isbn = $m[6];
$space = self::SPACE_NOT_NL; # non-newline space
*/
private $mExtraKey = '';
*/
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.
*/
/**
* Function to be called when an option is accessed.
*/
return $this->getUserLangObj()->getCode();
}
return $this->getUserLangObj()->getCode();
}
+ /**
+ * @since 1.28
+ * @return bool
+ */
+ public function getMagicISBNLinks() {
+ return $this->mMagicISBNLinks;
+ }
+
+ /**
+ * @since 1.28
+ * @return bool
+ */
+ public function getMagicPMIDLinks() {
+ return $this->mMagicPMIDLinks;
+ }
+ /**
+ * @since 1.28
+ * @return bool
+ */
+ public function getMagicRFCLinks() {
+ return $this->mMagicRFCLinks;
+ }
public function setInterwikiMagic( $x ) {
return wfSetVar( $this->mInterwikiMagic, $x );
}
public function setInterwikiMagic( $x ) {
return wfSetVar( $this->mInterwikiMagic, $x );
}
return wfSetVar( $this->mIsPrintable, $x );
}
return wfSetVar( $this->mIsPrintable, $x );
}
+ /**
+ * @since 1.28
+ */
+ public function setMagicISBNLinks( $x ) {
+ return wfSetVar( $this->mMagicISBNLinks, $x );
+ }
+
+ /**
+ * @since 1.28
+ */
+ public function setMagicPMIDLinks( $x ) {
+ return wfSetVar( $this->mMagicPMIDLinks, $x );
+ }
+
+ /**
+ * @since 1.28
+ */
+ public function setMagicRFCLinks( $x ) {
+ return wfSetVar( $this->mMagicRFCLinks, $x );
+ }
+
/**
* Set the redirect target.
*
/**
* Set the redirect target.
*
$wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion,
$wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth,
$wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit,
$wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion,
$wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth,
$wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit,
- $wgMaxGeneratedPPNodeCount, $wgDisableLangConversion, $wgDisableTitleConversion;
+ $wgMaxGeneratedPPNodeCount, $wgDisableLangConversion, $wgDisableTitleConversion,
+ $wgEnableMagicLinks;
// *UPDATE* ParserOptions::matches() if any of this changes as needed
$this->mInterwikiMagic = $wgInterwikiMagic;
// *UPDATE* ParserOptions::matches() if any of this changes as needed
$this->mInterwikiMagic = $wgInterwikiMagic;
$this->mExternalLinkTarget = $wgExternalLinkTarget;
$this->mDisableContentConversion = $wgDisableLangConversion;
$this->mDisableTitleConversion = $wgDisableLangConversion || $wgDisableTitleConversion;
$this->mExternalLinkTarget = $wgExternalLinkTarget;
$this->mDisableContentConversion = $wgDisableLangConversion;
$this->mDisableTitleConversion = $wgDisableLangConversion || $wgDisableTitleConversion;
+ $this->mMagicISBNLinks = $wgEnableMagicLinks['ISBN'];
+ $this->mMagicPMIDLinks = $wgEnableMagicLinks['PMID'];
+ $this->mMagicRFCLinks = $wgEnableMagicLinks['RFC'];
$this->mUser = $user;
$this->mNumberHeadings = $user->getOption( 'numberheadings' );
$this->mUser = $user;
$this->mNumberHeadings = $user->getOption( 'numberheadings' );
'wgThumbLimits' => [ self::getOptionValue( 'thumbsize', $opts, 180 ) ],
'wgDefaultLanguageVariant' => $variant,
'wgLinkHolderBatchSize' => $linkHolderBatchSize,
'wgThumbLimits' => [ self::getOptionValue( 'thumbsize', $opts, 180 ) ],
'wgDefaultLanguageVariant' => $variant,
'wgLinkHolderBatchSize' => $linkHolderBatchSize,
+ // Set as a JSON object like:
+ // wgEnableMagicLinks={"ISBN":false, "PMID":false, "RFC":false}
+ 'wgEnableMagicLinks' => self::getOptionValue( 'wgEnableMagicLinks', $opts, [] )
+ + [ 'ISBN' => true, 'PMID' => true, 'RFC' => true ],
#
# You can also set the following parser properties via test options:
# wgEnableUploads, wgAllowExternalImages, wgMaxTocLevel,
#
# You can also set the following parser properties via test options:
# wgEnableUploads, wgAllowExternalImages, wgMaxTocLevel,
-# wgLinkHolderBatchSize, wgRawHtml, wgInterwikiMagic
+# wgLinkHolderBatchSize, wgRawHtml, wgInterwikiMagic,
+# wgEnableMagicLinks
#
# For testing purposes, temporary articles can created:
# !!article / NAMESPACE:TITLE / !!text / ARTICLE TEXT / !!endarticle
#
# For testing purposes, temporary articles can created:
# !!article / NAMESPACE:TITLE / !!text / ARTICLE TEXT / !!endarticle
<p>X<a rel="mw:ExtLink" href="//tools.ietf.org/html/rfc1234">foo</a></p>
!! end
<p>X<a rel="mw:ExtLink" href="//tools.ietf.org/html/rfc1234">foo</a></p>
!! end
+!! test
+Magic links: All disabled (T47942)
+!! options
+wgEnableMagicLinks={"ISBN":false, "PMID":false, "RFC":false}
+!! wikitext
+ISBN 0-306-40615-2
+PMID 1234
+RFC 4321
+!! html/php
+<p>ISBN 0-306-40615-2
+PMID 1234
+RFC 4321
+</p>
+!! end
+