Index: trunk/phase3/includes/Skin.php |
— | — | @@ -1440,6 +1440,7 @@ |
1441 | 1441 | function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) |
1442 | 1442 | { |
1443 | 1443 | global $wgOut, $wgUser; |
| 1444 | + global $wgInternalLinks; |
1444 | 1445 | $fname = 'Skin::makeLinkObj'; |
1445 | 1446 | |
1446 | 1447 | if ( $nt->isExternal() ) { |
— | — | @@ -1462,35 +1463,21 @@ |
1463 | 1464 | ( Namespace::getImage() == $nt->getNamespace() ) ) { |
1464 | 1465 | $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); |
1465 | 1466 | } else { |
1466 | | - $aid = $nt->getArticleID() ; |
1467 | | - if ( 0 == $aid ) { |
1468 | | - $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); |
1469 | | - } else { |
1470 | | - $threshold = $wgUser->getOption('stubthreshold') ; |
1471 | | - if ( $threshold > 0 ) { |
1472 | | - $s = $dbr->getArray( 'cur', |
1473 | | - array( 'LENGTH(cur_text) AS x', 'cur_namespace', 'cur_is_redirect' ), |
1474 | | - array( 'cur_id' => $aid ), |
1475 | | - $fname |
1476 | | - ); |
1477 | | - |
1478 | | - if ( $s !== false ) { |
1479 | | - $size = $s->x; |
1480 | | - if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) { |
1481 | | - $size = $threshold*2 ; # Really big |
1482 | | - } |
1483 | | - } else { |
1484 | | - $size = $threshold*2 ; # Really big |
1485 | | - } |
1486 | | - } else { |
1487 | | - $size = 1 ; |
| 1467 | + $inside = ''; |
| 1468 | + if ( '' != $trail ) { |
| 1469 | + if ( preg_match( $this->linktrail, $trail, $m ) ) { |
| 1470 | + $inside = $m[1]; |
| 1471 | + $trail = $m[2]; |
1488 | 1472 | } |
1489 | | - if ( $size < $threshold ) { |
1490 | | - $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); |
1491 | | - } else { |
1492 | | - $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); |
1493 | | - } |
1494 | 1473 | } |
| 1474 | + |
| 1475 | + # Allows wiki to bypass using linkcache, see OutputPage::parseLinkHolders() |
| 1476 | + $wgInternalLinks['obj'][] = $nt; |
| 1477 | + $wgInternalLinks['text'][] = $text . $inside; |
| 1478 | + $wgInternalLinks['query'][] = $query; |
| 1479 | + $wgInternalLinks['prefix'][] = $prefix; |
| 1480 | + $wgInternalLinks['ns'][] = $nt->getNamespace(); |
| 1481 | + $retVal = "<tmp=" . $nt->getDBkey() . ">{$trail}"; |
1495 | 1482 | } |
1496 | 1483 | return $retVal; |
1497 | 1484 | } |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -345,6 +345,8 @@ |
346 | 346 | |
347 | 347 | |
348 | 348 | $this->sendCacheControl(); |
| 349 | + |
| 350 | + $this->mBodytext = $this->parseLinkHolders(); |
349 | 351 | |
350 | 352 | header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" ); |
351 | 353 | header( "Content-language: {$wgLanguageCode}" ); |
— | — | @@ -754,5 +756,91 @@ |
755 | 757 | # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'></script><![endif]-->"; |
756 | 758 | return $ret; |
757 | 759 | } |
| 760 | + |
| 761 | + # Parse <tmp=> link placeholders to avoid using linkcache |
| 762 | + # $wgInternalLinks populated in Skin::makeLinkObj() |
| 763 | + function parseLinkHolders() |
| 764 | + { |
| 765 | + global $wgUser, $wgInternalLinks; |
| 766 | + |
| 767 | + $fname = 'OutputPage::parseLinkHolders'; |
| 768 | + wfProfileIn( $fname ); |
| 769 | + |
| 770 | + # Get placeholders from body |
| 771 | + preg_match_all( "/<tmp=(.*?)>/", $this->mBodytext, $tmpLinks ); |
| 772 | + |
| 773 | + if ( !empty( $tmpLinks[0] ) ) { |
| 774 | + $dbr =& wfGetDB( DB_READ ); |
| 775 | + $sk = $wgUser->getSkin(); |
| 776 | + |
| 777 | + # Index the DB key along with other information |
| 778 | + foreach ( $tmpLinks[1] as $key => $val ) { |
| 779 | + $wgInternalLinks['dbkey'][$key] = $wgInternalLinks['obj'][$key]->getDBkey(); |
| 780 | + } |
| 781 | + |
| 782 | + # Sort according to namespace |
| 783 | + asort($wgInternalLinks['ns']); |
| 784 | + |
| 785 | + # Generate query |
| 786 | + foreach ( $wgInternalLinks['ns'] as $key => $val ) { |
| 787 | + if ( !isset( $current ) ) { |
| 788 | + $current = $val; |
| 789 | + $query = "SELECT cur_title, LENGTH(cur_text) AS cur_len, cur_is_redirect FROM cur "; |
| 790 | + $query .= "WHERE (cur_namespace=$val AND cur_title IN("; |
| 791 | + } elseif ( $current != $val ) { |
| 792 | + $current = $val; |
| 793 | + $query .= ")) OR (cur_namespace=$val AND cur_title IN("; |
| 794 | + } else { |
| 795 | + $query .= ", "; |
| 796 | + } |
| 797 | + |
| 798 | + $query .= $dbr->addQuotes( $wgInternalLinks['dbkey'][$key] ); |
| 799 | + } |
| 800 | + |
| 801 | + $query .= "))"; |
| 802 | + |
| 803 | + $res = $dbr->query( $query ); |
| 804 | + |
| 805 | + # Fetch data and pass to appropriate make*LinkObj() |
| 806 | + # Index search and replace strings to substitute placeholders for actual links |
| 807 | + while ( $s = $dbr->fetchRow($res) ) { |
| 808 | + $i = array_search($s['cur_title'], $wgInternalLinks['dbkey']); |
| 809 | + $threshold = $wgUser->getOption('stubthreshold'); |
| 810 | + if ( $threshold > 0 ) { |
| 811 | + $size = $s['cur_len']; |
| 812 | + if ( $s['cur_is_redirect'] || ( $wgInternalLinks['ns'][$i] != 0 ) ) { |
| 813 | + $size = $threshold * 2; # Really big |
| 814 | + } |
| 815 | + } else { |
| 816 | + $size = 1; |
| 817 | + } |
| 818 | + |
| 819 | + if ( $size < $threshold ) { |
| 820 | + $wgInternalLinks['replace'][$i] = $sk->makeStubLinkObj( $wgInternalLinks['obj'][$i], |
| 821 | + $wgInternalLinks['text'][$i], $wgInternalLinks['query'][$i], '', |
| 822 | + $wgInternalLinks['prefix'][$i]); |
| 823 | + } else { |
| 824 | + $wgInternalLinks['replace'][$i] = $sk->makeKnownLinkObj( $wgInternalLinks['obj'][$i], |
| 825 | + $wgInternalLinks['text'][$i], $wgInternalLinks['query'][$i], '', |
| 826 | + $wgInternalLinks['prefix'][$i]); |
| 827 | + } |
| 828 | + } |
| 829 | + |
| 830 | + # Finish populating search and replace arrays for broken links |
| 831 | + foreach ( $wgInternalLinks['ns'] as $key => $val ) { |
| 832 | + $search[] = $tmpLinks[0][$key]; |
| 833 | + $replace[] = ( empty ( $wgInternalLinks['replace'][$key] ) ) ? |
| 834 | + $sk->makeBrokenLinkObj( $wgInternalLinks['obj'][$key], |
| 835 | + $wgInternalLinks['text'][$key], $wgInternalLinks['query'][$key], '', |
| 836 | + $wgInternalLinks['prefix'][$key]) |
| 837 | + : $wgInternalLinks['replace'][$key]; |
| 838 | + } |
| 839 | + |
| 840 | + $out = str_replace( $search, $replace, $this->mBodytext ); |
| 841 | + } |
| 842 | + |
| 843 | + wfProfileOut( $fname ); |
| 844 | + return ( $out ); |
| 845 | + } |
758 | 846 | } |
759 | 847 | ?> |