r5506 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5505‎ | r5506 | r5507 >
Date:20:13, 25 September 2004
Author:wmahan
Status:old
Tags:
Comment:
Fix bug 561: {{/Subpage}} acts like {{Template:/Subpage}}, by
breaking out a maybeDoSubpageLink() function and using it when
including a template.
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -1057,7 +1057,6 @@
10581058 */
10591059 function replaceInternalLinks( $s ) {
10601060 global $wgLang, $wgContLang, $wgLinkCache;
1061 - global $wgNamespacesWithSubpages;
10621061 static $fname = 'Parser::replaceInternalLinks' ;
10631062 wfProfileIn( $fname );
10641063
@@ -1134,45 +1133,10 @@
11351134 continue;
11361135 }
11371136
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 );
11431140
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 -
11771141 $wasblank = ( '' == $text );
11781142 if( $wasblank ) $text = $link;
11791143
@@ -1250,6 +1214,58 @@
12511215 return $s;
12521216 }
12531217
 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+
12541270 /**#@+
12551271 * Used by doBlockLevels()
12561272 * @access private
@@ -1795,7 +1811,12 @@
17961812 # Load from database
17971813 $itcamefromthedatabase = false;
17981814 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 );
18001821 if ( !is_null( $title ) && !$title->isExternal() ) {
18011822 # Check for excessive inclusion
18021823 $dbk = $title->getPrefixedDBkey();

Follow-up revisions

RevisionCommit summaryAuthorDate
r6003Return 'false' from fetchContent if article doesn't exist. Fixes two tests:...vibber07:28, 23 October 2004
r27906Fix regressions in r27759 -- pages already marked in link cache at link parsi...brion20:45, 27 November 2007

Status & tagging log