Index: trunk/phase3/includes/Parser.php |
— | — | @@ -1057,7 +1057,6 @@ |
1058 | 1058 | */ |
1059 | 1059 | function replaceInternalLinks( $s ) { |
1060 | 1060 | global $wgLang, $wgContLang, $wgLinkCache; |
1061 | | - global $wgNamespacesWithSubpages; |
1062 | 1061 | static $fname = 'Parser::replaceInternalLinks' ; |
1063 | 1062 | wfProfileIn( $fname ); |
1064 | 1063 | |
— | — | @@ -1134,45 +1133,10 @@ |
1135 | 1134 | continue; |
1136 | 1135 | } |
1137 | 1136 | |
1138 | | - # Valid link forms: |
1139 | | - # Foobar -- normal |
1140 | | - # :Foobar -- override special treatment of prefix (images, language links) |
1141 | | - # /Foobar -- convert to CurrentPage/Foobar |
1142 | | - # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text |
| 1137 | + # Make subpage if necessary, and check for leading ':' |
| 1138 | + $noforce = true; |
| 1139 | + $link = $this->maybeDoSubpageLink( $m[1], $noforce, $text ); |
1143 | 1140 | |
1144 | | - # Look at the first character |
1145 | | - $c = substr($m[1],0,1); |
1146 | | - $noforce = ($c != ':'); |
1147 | | - |
1148 | | - # subpage |
1149 | | - if( $c == '/' ) { |
1150 | | - # / at end means we don't want the slash to be shown |
1151 | | - if(substr($m[1],-1,1)=='/') { |
1152 | | - $m[1]=substr($m[1],1,strlen($m[1])-2); |
1153 | | - $noslash=$m[1]; |
1154 | | - } else { |
1155 | | - $noslash=substr($m[1],1); |
1156 | | - } |
1157 | | - |
1158 | | - # Some namespaces don't allow subpages |
1159 | | - if(!empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()])) { |
1160 | | - # subpages allowed here |
1161 | | - $link = $this->mTitle->getPrefixedText(). '/' . trim($noslash); |
1162 | | - if( '' == $text ) { |
1163 | | - $text= $m[1]; |
1164 | | - } # this might be changed for ugliness reasons |
1165 | | - } else { |
1166 | | - # no subpage allowed, use standard link |
1167 | | - $link = $noslash; |
1168 | | - } |
1169 | | - |
1170 | | - } elseif( $noforce ) { # no subpage |
1171 | | - $link = $m[1]; |
1172 | | - } else { |
1173 | | - # We don't want to keep the first character |
1174 | | - $link = substr( $m[1], 1 ); |
1175 | | - } |
1176 | | - |
1177 | 1141 | $wasblank = ( '' == $text ); |
1178 | 1142 | if( $wasblank ) $text = $link; |
1179 | 1143 | |
— | — | @@ -1250,6 +1214,58 @@ |
1251 | 1215 | return $s; |
1252 | 1216 | } |
1253 | 1217 | |
| 1218 | + /** |
| 1219 | + * Handle link to subpage if necessary |
| 1220 | + * @param $target string the source of the link |
| 1221 | + * @param $target set to true unless target began with ':' |
| 1222 | + * @param &$text the link text, modified as necessary |
| 1223 | + * @return string the full name of the link |
| 1224 | + * @access private |
| 1225 | + */ |
| 1226 | + function maybeDoSubpageLink($target, &$noforce, &$text) { |
| 1227 | + # Valid link forms: |
| 1228 | + # Foobar -- normal |
| 1229 | + # :Foobar -- override special treatment of prefix (images, language links) |
| 1230 | + # /Foobar -- convert to CurrentPage/Foobar |
| 1231 | + # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text |
| 1232 | + global $wgNamespacesWithSubpages; |
| 1233 | + |
| 1234 | + # Look at the first character |
| 1235 | + $c = $target{0}; |
| 1236 | + $noforce = ($c != ':'); |
| 1237 | + |
| 1238 | + # subpage |
| 1239 | + if( $c == '/' ) { |
| 1240 | + # / at end means we don't want the slash to be shown |
| 1241 | + if(substr($target,-1,1)=='/') { |
| 1242 | + $target=substr($target,1,-1); |
| 1243 | + $noslash=$target; |
| 1244 | + } else { |
| 1245 | + $noslash=substr($target,1); |
| 1246 | + } |
| 1247 | + |
| 1248 | + # Some namespaces don't allow subpages |
| 1249 | + if(!empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()])) { |
| 1250 | + # subpages allowed here |
| 1251 | + $ret = $this->mTitle->getPrefixedText(). '/' . trim($noslash); |
| 1252 | + if( '' === $text ) { |
| 1253 | + $text = $target; |
| 1254 | + } # this might be changed for ugliness reasons |
| 1255 | + } else { |
| 1256 | + # no subpage allowed, use standard link |
| 1257 | + $ret = $target; |
| 1258 | + } |
| 1259 | + } elseif( $noforce ) { |
| 1260 | + # no subpage |
| 1261 | + $ret = $target; |
| 1262 | + } else { |
| 1263 | + # We don't want to keep the first character |
| 1264 | + $ret = substr( $target, 1 ); |
| 1265 | + } |
| 1266 | + |
| 1267 | + return $ret; |
| 1268 | + } |
| 1269 | + |
1254 | 1270 | /**#@+ |
1255 | 1271 | * Used by doBlockLevels() |
1256 | 1272 | * @access private |
— | — | @@ -1795,7 +1811,12 @@ |
1796 | 1812 | # Load from database |
1797 | 1813 | $itcamefromthedatabase = false; |
1798 | 1814 | if ( !$found ) { |
1799 | | - $title = Title::newFromText( $part1, NS_TEMPLATE ); |
| 1815 | + $ns = NS_TEMPLATE; |
| 1816 | + $part1 = $this->maybeDoSubpageLink( $part1, $noforce, $subpage='' ); |
| 1817 | + if ($subpage !== '') { |
| 1818 | + $ns = $this->mTitle->getNamespace(); |
| 1819 | + } |
| 1820 | + $title = Title::newFromText( $part1, $ns ); |
1800 | 1821 | if ( !is_null( $title ) && !$title->isExternal() ) { |
1801 | 1822 | # Check for excessive inclusion |
1802 | 1823 | $dbk = $title->getPrefixedDBkey(); |