From 0a1e291036fac2376b4645f9d070bc3e76ca73d4 Mon Sep 17 00:00:00 2001 From: Tyler Anthony Romeo Date: Thu, 27 Sep 2012 13:47:42 -0400 Subject: [PATCH] Added protocol option to Linker and OutputPage::addReturnTo. Added new argument to the Linker options array to allow the forcing of an HTTP or HTTPS protocol. In order to facilitate this, a protocol argument was added to Title::getLinkURL. Also, an options argument was added to OutputPage::addReturnTo so that options can be passed to the linker and so that the returnto URL can be forced to a certain protocol. Change-Id: Ia9cc11e310ad6ef23c221bdba3a4834e7c5556e7 --- includes/Linker.php | 13 ++++++++++++- includes/OutputPage.php | 15 ++++++++++++--- includes/Title.php | 7 ++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 8e31a1cf76..97b03be800 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -188,6 +188,8 @@ class Linker { * cons. * 'forcearticlepath': Use the article path always, even with a querystring. * 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. * @return string HTML attribute */ public static function link( @@ -294,7 +296,16 @@ class Linker { $query['action'] = 'edit'; $query['redlink'] = '1'; } - $ret = $target->getLinkURL( $query ); + + if ( in_array( 'http', $options ) ) { + $proto = PROTO_HTTP; + } elseif ( in_array( 'https', $options ) ) { + $proto = PROTO_HTTPS; + } else { + $proto = PROTO_RELATIVE; + } + + $ret = $target->getLinkURL( $query, false, $proto ); wfProfileOut( __METHOD__ ); return $ret; } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 2c32c6abe0..ec72b51769 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2343,11 +2343,20 @@ $templates * @param $title Title to link * @param $query Array query string parameters * @param $text String text of the link (input is not escaped) + * @param $options Options array to pass to Linker */ - public function addReturnTo( $title, $query = array(), $text = null ) { - $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL() ) ); + public function addReturnTo( $title, $query = array(), $text = null, $options = array() ) { + if( in_array( 'http', $options ) ) { + $proto = PROTO_HTTP; + } elseif( in_array( 'https', $options ) ) { + $proto = PROTO_HTTPS; + } else { + $proto = PROTO_RELATIVE; + } + + $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL( '', false, $proto ) ) ); $link = $this->msg( 'returnto' )->rawParams( - Linker::link( $title, $text, array(), $query ) )->escaped(); + Linker::link( $title, $text, array(), $query, $options ) )->escaped(); $this->addHTML( "

{$link}

\n" ); } diff --git a/includes/Title.php b/includes/Title.php index 1b5e21d2ee..1e16c7522a 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1396,13 +1396,14 @@ class Title { * * See getLocalURL for the arguments. * + * @param $proto Protocol to use; setting this will cause a full URL to be used * @see self::getLocalURL * @return String the URL */ - public function getLinkURL( $query = '', $query2 = false ) { + public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) { wfProfileIn( __METHOD__ ); - if ( $this->isExternal() ) { - $ret = $this->getFullURL( $query, $query2 ); + if ( $this->isExternal() || $proto != PROTO_RELATIVE ) { + $ret = $this->getFullURL( $query, $query2, $proto ); } elseif ( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) { $ret = $this->getFragmentForURL(); } else { -- 2.20.1