*/
$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 }
/************************************************************************//**
* @return string
*/
function wfEscapeWikiText( $text ) {
+ global $wgEnableMagicLinks;
static $repl = null, $repl2 = null;
if ( $repl === null ) {
$repl = [
'__' => '__', '://' => '://',
];
+ $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 ";
} 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';
}
$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
*/
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.
*/
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 );
}
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.
*
$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;
$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' );
'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 ],
];
if ( $config ) {
#
# 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
<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
+
###
### Templates
####