Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/191533
Change subject: API: Allow requesting fully qualified urls action=parse
......................................................................
API: Allow requesting fully qualified urls action=parse
Remove the special-casing of action=render in Title::getLocalURL()
and turn fully expanding urls into a parser option which is then
passed to Linker.
Bug: T89916
Change-Id: Ic11cd1f155c4a7222d50982bf76e369fb795193c
---
M includes/Linker.php
M includes/Title.php
M includes/api/ApiParse.php
M includes/api/i18n/en.json
M includes/api/i18n/qqq.json
M includes/page/Article.php
M includes/page/ImagePage.php
M includes/parser/LinkHolderArray.php
M includes/parser/ParserOptions.php
M tests/phpunit/includes/LinkerTest.php
10 files changed, 81 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/33/191533/1
diff --git a/includes/Linker.php b/includes/Linker.php
index 238bb53..7e088ec 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -188,6 +188,7 @@
* Has compatibility issues on some setups, so avoid wherever
possible.
* 'http': Force a full URL with http:// as the scheme.
* 'https': Force a full URL with https:// as the scheme.
+ * 'fullyqualify': Force a full URL without preference to a
specific protocol
* @return string HTML <a> attribute
*/
public static function link(
@@ -300,6 +301,9 @@
}
$ret = $target->getLinkURL( $query, false, $proto );
+ if ( in_array( 'fullyqualify', $options ) ) {
+ $ret = wfExpandUrl( $ret, $proto );
+ }
return $ret;
}
diff --git a/includes/Title.php b/includes/Title.php
index 2ef4ee4..c4ae359 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -1690,7 +1690,7 @@
* @return string String of the URL.
*/
public function getLocalURL( $query = '', $query2 = false ) {
- global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
+ global $wgArticlePath, $wgScript;
$query = self::fixUrlQueryArgs( $query, $query2 );
@@ -1754,12 +1754,6 @@
}
Hooks::run( 'GetLocalURL::Internal', array( &$this,
&$url, $query ) );
-
- // @todo FIXME: This causes breakage in various places
when we
- // actually expected a local URL and end up with dupe
prefixes.
- if ( $wgRequest->getVal( 'action' ) == 'render' ) {
- $url = $wgServer . $url;
- }
}
Hooks::run( 'GetLocalURL', array( &$this, &$url, $query ) );
return $url;
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 83d2cbc..9b5b731 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -425,6 +425,7 @@
$popts->setIsPreview( $params['preview'] ||
$params['sectionpreview'] );
$popts->setIsSectionPreview( $params['sectionpreview'] );
$popts->setEditSection( !$params['disableeditsection'] );
+ $popts->setFullyQualifiedURLs( $params['fullyqualifyurls'] );
return $popts;
}
@@ -700,6 +701,7 @@
'section' => null,
'disablepp' => false,
'disableeditsection' => false,
+ 'fullyqualifyurls' => false,
'generatexml' => array(
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_HELP_MSG => array(
diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json
index 6779571..63986d4 100644
--- a/includes/api/i18n/en.json
+++ b/includes/api/i18n/en.json
@@ -271,6 +271,7 @@
"apihelp-parse-param-section": "Only retrieve the content of this
section number.",
"apihelp-parse-param-disablepp": "Disable the PP Report from the parser
output.",
"apihelp-parse-param-disableeditsection": "Disable edit section links
from the parser output.",
+ "apihelp-parse-param-fullyqualifyurls": "Fully qualify urls used for
internal links.",
"apihelp-parse-param-generatexml": "Generate XML parse tree (requires
content model <code>$1</code>).",
"apihelp-parse-param-preview": "Parse in preview mode.",
"apihelp-parse-param-sectionpreview": "Parse in section preview mode
(enables preview mode too).",
diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json
index f539ac6..4e5f746 100644
--- a/includes/api/i18n/qqq.json
+++ b/includes/api/i18n/qqq.json
@@ -250,6 +250,7 @@
"apihelp-parse-param-section": "{{doc-apihelp-param|parse|section}}",
"apihelp-parse-param-disablepp":
"{{doc-apihelp-param|parse|disablepp}}",
"apihelp-parse-param-disableeditsection":
"{{doc-apihelp-param|parse|disableeditsection}}",
+ "apihelp-parse-param-fullyqualifyurls":
"{{doc-apihelp-param|parse|fullyqualifyurls}}",
"apihelp-parse-param-generatexml":
"{{doc-apihelp-param|parse|generatexml|params=* $1 - Value of the constant
CONTENT_MODEL_WIKITEXT|paramstart=2}}",
"apihelp-parse-param-preview": "{{doc-apihelp-param|parse|preview}}",
"apihelp-parse-param-sectionpreview":
"{{doc-apihelp-param|parse|sectionpreview}}",
diff --git a/includes/page/Article.php b/includes/page/Article.php
index 59f2ae7..c206807 100644
--- a/includes/page/Article.php
+++ b/includes/page/Article.php
@@ -472,8 +472,13 @@
/**
* This is the default action of the index.php entry point: just view
the
* page of the given title.
+ *
+ * @param array $options
+ * - "fullyqualify": @see ParserOptions::getFullyQualifiedURLs
+ *
+ * @throws PermissionsError if User can't read the page
*/
- public function view() {
+ public function view( array $options = array() ) {
global $wgUseFileCache, $wgUseETag, $wgDebugToolbar,
$wgMaxRedirects;
# Get variables from query string
@@ -517,6 +522,9 @@
$parserCache = ParserCache::singleton();
$parserOptions = $this->getParserOptions();
+ if ( in_array( 'fullyqualify', $options ) ) {
+ $parserOptions->setFullyQualifiedURLs( true );
+ }
# Render printable version, use printable version cache
if ( $outputPage->isPrintable() ) {
$parserOptions->setIsPrintable( true );
@@ -1510,7 +1518,7 @@
$this->getContext()->getRequest()->response()->header(
'X-Robots-Tag: noindex' );
$this->getContext()->getOutput()->setArticleBodyOnly( true );
$this->getContext()->getOutput()->enableSectionEditLinks( false
);
- $this->view();
+ $this->view( array( 'fullyqualify' ) );
}
/**
diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php
index b8f67c2..6a8614f 100644
--- a/includes/page/ImagePage.php
+++ b/includes/page/ImagePage.php
@@ -96,7 +96,7 @@
*/
public function render() {
$this->getContext()->getOutput()->setArticleBodyOnly( true );
- parent::view();
+ parent::view( array( 'fullyqualified' ) );
}
public function view() {
diff --git a/includes/parser/LinkHolderArray.php
b/includes/parser/LinkHolderArray.php
index 7026c5c..c52988e 100644
--- a/includes/parser/LinkHolderArray.php
+++ b/includes/parser/LinkHolderArray.php
@@ -410,6 +410,9 @@
}
$type = array( 'known', 'noclasses' );
}
+ if (
$this->parent->getOptions()->getFullyQualifiedURLs() ) {
+ $type[] = 'fullyqualify';
+ }
$replacePairs[$searchkey] = Linker::link(
$title, $displayText,
$attribs, $query, $type );
}
diff --git a/includes/parser/ParserOptions.php
b/includes/parser/ParserOptions.php
index b09fe76..58e3be1 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -213,6 +213,11 @@
public $mExtraKey = '';
/**
+ * @var bool
+ */
+ protected $mFullyQualifiedURLs = false;
+
+ /**
* Function to be called when an option is accessed.
*/
protected $onAccessCallback = null;
@@ -404,6 +409,25 @@
return $this->getUserLangObj()->getCode();
}
+ /**
+ * If true, URLs should be fully qualified and include the domain name
in them
+ *
+ * @since 1.25
+ * @return bool
+ */
+ public function getFullyQualifiedURLs() {
+ return $this->mFullyQualifiedURLs;
+ }
+
+ /**
+ * @since 1.25
+ * @param bool $x
+ * @return bool
+ */
+ public function setFullyQualifiedURLs( $x ) {
+ return wfSetVar( $this->mFullyQualifiedURLs, $x );
+ }
+
public function setInterwikiMagic( $x ) {
return wfSetVar( $this->mInterwikiMagic, $x );
}
diff --git a/tests/phpunit/includes/LinkerTest.php
b/tests/phpunit/includes/LinkerTest.php
index 823c933..a7b9e3d 100644
--- a/tests/phpunit/includes/LinkerTest.php
+++ b/tests/phpunit/includes/LinkerTest.php
@@ -243,4 +243,38 @@
),
);
}
+
+ /**
+ * @todo Incomplete, only covers 'fullyqualify' option
+ * @covers Linker::linkUrl
+ * @dataProvider provideCasesForLinkUrl
+ */
+ public function testLinkUrl( $target, $options, $expected ) {
+ $this->setMwGlobals( array(
+ 'wgScript' => '/wiki/index.php',
+ 'wgArticlePath' => '/wiki/$1',
+ 'wgServer' => '//localhost',
+ 'wgWellFormedXml' => true,
+ 'wgCapitalLinks' => true,
+ ) );
+
+ $title = Title::newFromText( $target );
+ $link = Linker::link( $title, null, array(), array(), $options
);
+ $this->assertEquals( $expected, $link );
+ }
+
+ public static function provideCasesForLinkUrl() {
+ return array(
+ array(
+ 'FooBar',
+ array(),
+ '<a
href="/wiki/index.php?title=FooBar&action=edit&redlink=1" class="new"
title="FooBar (page does not exist)">FooBar</a>',
+ ),
+ array(
+ 'FooBar',
+ array( 'fullyqualify' ),
+ '<a
href="//localhost/wiki/index.php?title=FooBar&action=edit&redlink=1"
class="new" title="FooBar (page does not exist)">FooBar</a>'
+ ),
+ );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/191533
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic11cd1f155c4a7222d50982bf76e369fb795193c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits