Title::getLinkURL(): Allow expanding PROTO_RELATIVE too
authorKunal Mehta <legoktm@member.fsf.org>
Wed, 1 Jun 2016 03:11:31 +0000 (20:11 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Fri, 1 Jul 2016 18:31:56 +0000 (11:31 -0700)
Allow callers to get protocol-relative URLs by passing the
PROTO_RELATIVE constant. Since most callers don't pass in $proto, this
shouldn't change very much since the default of non-expanded is
effectively the same, but expanding to a protocol-relative URL when it
is not intended should still be safe.

A few callers that explicitly specified the default in core were also
updated.

Change-Id: I214f17aa6e8e30b647f21f0951fc3a15e87850c7

includes/Title.php
includes/linker/LinkRenderer.php
includes/revisiondelete/RevDelArchivedFileItem.php
includes/revisiondelete/RevDelFileItem.php

index 4555f16..bae3a76 100644 (file)
@@ -1773,12 +1773,13 @@ class Title implements LinkTarget {
         *
         * @param array $query
         * @param bool $query2
-        * @param string $proto Protocol to use; setting this will cause a full URL to be used
+        * @param string|int|bool $proto A PROTO_* constant on how the URL should be expanded,
+        *                               or false (default) for no expansion
         * @see self::getLocalURL for the arguments.
         * @return string The URL
         */
-       public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
-               if ( $this->isExternal() || $proto !== PROTO_RELATIVE ) {
+       public function getLinkURL( $query = '', $query2 = false, $proto = false ) {
+               if ( $this->isExternal() || $proto !== false ) {
                        $ret = $this->getFullURL( $query, $query2, $proto );
                } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
                        $ret = $this->getFragmentForURL();
index 432dcb2..c1ed248 100644 (file)
@@ -391,16 +391,13 @@ class LinkRenderer {
        private function getLinkURL( LinkTarget $target, array $query = [] ) {
                // TODO: Use a LinkTargetResolver service instead of Title
                $title = Title::newFromLinkTarget( $target );
-               $proto = $this->expandUrls !== false
-                       ? $this->expandUrls
-                       : PROTO_RELATIVE;
                if ( $this->forceArticlePath ) {
                        $realQuery = $query;
                        $query = [];
                } else {
                        $realQuery = [];
                }
-               $url = $title->getLinkURL( $query, false, $proto );
+               $url = $title->getLinkURL( $query, false, $this->expandUrls );
 
                if ( $this->forceArticlePath && $realQuery ) {
                        $url = wfAppendQuery( $url, $realQuery );
index e2bb516..f47a70b 100644 (file)
@@ -107,8 +107,7 @@ class RevDelArchivedFileItem extends RevDelFileItem {
                                                'target' => $this->list->title->getPrefixedText(),
                                                'file' => $file->getKey(),
                                                'token' => $user->getEditToken( $file->getKey() )
-                                       ],
-                                       false, PROTO_RELATIVE
+                                       ]
                                ),
                        ];
                }
index 921fe5a..dca4d5a 100644 (file)
@@ -215,8 +215,7 @@ class RevDelFileItem extends RevDelItem {
                                                'target' => $this->list->title->getPrefixedText(),
                                                'file' => $file->getArchiveName(),
                                                'token' => $user->getEditToken( $file->getArchiveName() )
-                                       ],
-                                       false, PROTO_RELATIVE
+                                       ]
                                ),
                        ];
                }