From fbdfda2a2fe05ce5c1fc13fbbccf4cfe724d5c1b Mon Sep 17 00:00:00 2001 From: Julian Ostrow Date: Sun, 18 Jul 2004 03:23:11 +0000 Subject: [PATCH] Alters Skin::makeLinkObj() to bypass using linkcache Adds function OutputPage::parseLinkHolders(), which works in conjunction with the modified Skin::makeLinkObj() --- includes/OutputPage.php | 88 +++++++++++++++++++++++++++++++++++++++++ includes/Skin.php | 41 +++++++------------ 2 files changed, 102 insertions(+), 27 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 5e17bbf664..fb662679f9 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -345,6 +345,8 @@ class OutputPage { $this->sendCacheControl(); + + $this->mBodytext = $this->parseLinkHolders(); header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" ); header( "Content-language: {$wgLanguageCode}" ); @@ -754,5 +756,91 @@ class OutputPage { # $ret .= ""; return $ret; } + + # Parse link placeholders to avoid using linkcache + # $wgInternalLinks populated in Skin::makeLinkObj() + function parseLinkHolders() + { + global $wgUser, $wgInternalLinks; + + $fname = 'OutputPage::parseLinkHolders'; + wfProfileIn( $fname ); + + # Get placeholders from body + preg_match_all( "//", $this->mBodytext, $tmpLinks ); + + if ( !empty( $tmpLinks[0] ) ) { + $dbr =& wfGetDB( DB_READ ); + $sk = $wgUser->getSkin(); + + # Index the DB key along with other information + foreach ( $tmpLinks[1] as $key => $val ) { + $wgInternalLinks['dbkey'][$key] = $wgInternalLinks['obj'][$key]->getDBkey(); + } + + # Sort according to namespace + asort($wgInternalLinks['ns']); + + # Generate query + foreach ( $wgInternalLinks['ns'] as $key => $val ) { + if ( !isset( $current ) ) { + $current = $val; + $query = "SELECT cur_title, LENGTH(cur_text) AS cur_len, cur_is_redirect FROM cur "; + $query .= "WHERE (cur_namespace=$val AND cur_title IN("; + } elseif ( $current != $val ) { + $current = $val; + $query .= ")) OR (cur_namespace=$val AND cur_title IN("; + } else { + $query .= ", "; + } + + $query .= $dbr->addQuotes( $wgInternalLinks['dbkey'][$key] ); + } + + $query .= "))"; + + $res = $dbr->query( $query ); + + # Fetch data and pass to appropriate make*LinkObj() + # Index search and replace strings to substitute placeholders for actual links + while ( $s = $dbr->fetchRow($res) ) { + $i = array_search($s['cur_title'], $wgInternalLinks['dbkey']); + $threshold = $wgUser->getOption('stubthreshold'); + if ( $threshold > 0 ) { + $size = $s['cur_len']; + if ( $s['cur_is_redirect'] || ( $wgInternalLinks['ns'][$i] != 0 ) ) { + $size = $threshold * 2; # Really big + } + } else { + $size = 1; + } + + if ( $size < $threshold ) { + $wgInternalLinks['replace'][$i] = $sk->makeStubLinkObj( $wgInternalLinks['obj'][$i], + $wgInternalLinks['text'][$i], $wgInternalLinks['query'][$i], '', + $wgInternalLinks['prefix'][$i]); + } else { + $wgInternalLinks['replace'][$i] = $sk->makeKnownLinkObj( $wgInternalLinks['obj'][$i], + $wgInternalLinks['text'][$i], $wgInternalLinks['query'][$i], '', + $wgInternalLinks['prefix'][$i]); + } + } + + # Finish populating search and replace arrays for broken links + foreach ( $wgInternalLinks['ns'] as $key => $val ) { + $search[] = $tmpLinks[0][$key]; + $replace[] = ( empty ( $wgInternalLinks['replace'][$key] ) ) ? + $sk->makeBrokenLinkObj( $wgInternalLinks['obj'][$key], + $wgInternalLinks['text'][$key], $wgInternalLinks['query'][$key], '', + $wgInternalLinks['prefix'][$key]) + : $wgInternalLinks['replace'][$key]; + } + + $out = str_replace( $search, $replace, $this->mBodytext ); + } + + wfProfileOut( $fname ); + return ( $out ); + } } ?> diff --git a/includes/Skin.php b/includes/Skin.php index 5c16a87fb1..bf4efbbe0c 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1440,6 +1440,7 @@ class Skin { function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) { global $wgOut, $wgUser; + global $wgInternalLinks; $fname = 'Skin::makeLinkObj'; if ( $nt->isExternal() ) { @@ -1462,35 +1463,21 @@ class Skin { ( Namespace::getImage() == $nt->getNamespace() ) ) { $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } else { - $aid = $nt->getArticleID() ; - if ( 0 == $aid ) { - $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); - } else { - $threshold = $wgUser->getOption('stubthreshold') ; - if ( $threshold > 0 ) { - $s = $dbr->getArray( 'cur', - array( 'LENGTH(cur_text) AS x', 'cur_namespace', 'cur_is_redirect' ), - array( 'cur_id' => $aid ), - $fname - ); - - if ( $s !== false ) { - $size = $s->x; - if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) { - $size = $threshold*2 ; # Really big - } - } else { - $size = $threshold*2 ; # Really big - } - } else { - $size = 1 ; - } - if ( $size < $threshold ) { - $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); - } else { - $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); + $inside = ''; + if ( '' != $trail ) { + if ( preg_match( $this->linktrail, $trail, $m ) ) { + $inside = $m[1]; + $trail = $m[2]; } } + + # Allows wiki to bypass using linkcache, see OutputPage::parseLinkHolders() + $wgInternalLinks['obj'][] = $nt; + $wgInternalLinks['text'][] = $text . $inside; + $wgInternalLinks['query'][] = $query; + $wgInternalLinks['prefix'][] = $prefix; + $wgInternalLinks['ns'][] = $nt->getNamespace(); + $retVal = "getDBkey() . ">{$trail}"; } return $retVal; } -- 2.20.1