Merge "Consistently handle trailing slashes in subpage links."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 17 Nov 2014 17:05:58 +0000 (17:05 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 17 Nov 2014 17:05:58 +0000 (17:05 +0000)
1  2 
includes/Linker.php

diff --combined includes/Linker.php
@@@ -209,9 -209,8 +209,9 @@@ class Linker 
                $dummy = new DummyLinker; // dummy linker instance for bc on the hooks
  
                $ret = null;
 -              if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html,
 -              &$customAttribs, &$query, &$options, &$ret ) ) ) {
 +              if ( !wfRunHooks( 'LinkBegin',
 +                      array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) )
 +              ) {
                        wfProfileOut( __METHOD__ );
                        return $ret;
                }
                # Foobar -- normal
                # :Foobar -- override special treatment of prefix (images, language links)
                # /Foobar -- convert to CurrentPage/Foobar
-               # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
+               # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
                # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
-               # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
+               # ../Foobar -- convert to CurrentPage/Foobar,
+               #              (from CurrentPage/CurrentSubPage)
+               # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
+               #              (from CurrentPage/CurrentSubPage)
  
                wfProfileIn( __METHOD__ );
                $ret = $target; # default return value is no change
                                                $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
                                                # / at the end means don't show full path
                                                if ( substr( $nodotdot, -1, 1 ) === '/' ) {
-                                                       $nodotdot = substr( $nodotdot, 0, -1 );
+                                                       $nodotdot = rtrim( $nodotdot, '/' );
                                                        if ( $text === '' ) {
                                                                $text = $nodotdot . $suffix;
                                                        }