Added protocol option to Linker and OutputPage::addReturnTo.
authorTyler Anthony Romeo <tylerromeo@gmail.com>
Thu, 27 Sep 2012 17:47:42 +0000 (13:47 -0400)
committerTyler Anthony Romeo <tylerromeo@gmail.com>
Thu, 27 Sep 2012 17:47:42 +0000 (13:47 -0400)
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
includes/OutputPage.php
includes/Title.php

index 8e31a1c..97b03be 100644 (file)
@@ -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 <a> 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;
        }
index 2c32c6a..ec72b51 100644 (file)
@@ -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( "<p id=\"mw-returnto\">{$link}</p>\n" );
        }
 
index 1b5e21d..1e16c75 100644 (file)
@@ -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 {