r4314 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r4313‎ | r4314 | r4315 >
Date:03:23, 18 July 2004
Author:jostrow
Status:old
Tags:
Comment:
Alters Skin::makeLinkObj() to bypass using linkcache
Adds function OutputPage::parseLinkHolders(), which works in conjunction with the modified Skin::makeLinkObj()
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Skin.php
@@ -1440,6 +1440,7 @@
14411441 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' )
14421442 {
14431443 global $wgOut, $wgUser;
 1444+ global $wgInternalLinks;
14441445 $fname = 'Skin::makeLinkObj';
14451446
14461447 if ( $nt->isExternal() ) {
@@ -1462,35 +1463,21 @@
14631464 ( Namespace::getImage() == $nt->getNamespace() ) ) {
14641465 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
14651466 } 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];
14881472 }
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 - }
14941473 }
 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}";
14951482 }
14961483 return $retVal;
14971484 }
Index: trunk/phase3/includes/OutputPage.php
@@ -345,6 +345,8 @@
346346
347347
348348 $this->sendCacheControl();
 349+
 350+ $this->mBodytext = $this->parseLinkHolders();
349351
350352 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
351353 header( "Content-language: {$wgLanguageCode}" );
@@ -754,5 +756,91 @@
755757 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'></script><![endif]-->";
756758 return $ret;
757759 }
 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+ }
758846 }
759847 ?>

Status & tagging log