| Index: trunk/extensions/DoubleWiki/DoubleWiki_body.php |
| — | — | @@ -55,7 +55,7 @@ |
| 56 | 56 | * @param $text |
| 57 | 57 | */ |
| 58 | 58 | function addMatchedText( &$out, &$text ) { |
| 59 | | - global $wgContLang, $wgRequest, $wgLang, $wgContLanguageCode; |
| | 59 | + global $wgContLang, $wgRequest, $wgLang, $wgMemc, $wgDoubleWikiCacheTime; |
| 60 | 60 | |
| 61 | 61 | $match_request = $wgRequest->getText( 'match' ); |
| 62 | 62 | if ( $match_request === '' ) { |
| — | — | @@ -68,48 +68,54 @@ |
| 69 | 69 | if ( isset( $langLinks[$match_request] ) ) { |
| 70 | 70 | $nt = Title::newFromText( $langLinks[$match_request] ); |
| 71 | 71 | |
| 72 | | - $url = $nt->getFullURL(); |
| 73 | | - $myURL = $out->getTitle()->getLocalURL(); |
| 74 | | - $languageName = $wgContLang->getLanguageName( $nt->getInterwiki() ); |
| 75 | | - $myLanguage = $wgLang->getLanguageName( $wgContLanguageCode ); |
| | 72 | + $key = wfMemcKey( 'doublewiki', $wgLang->getCode(), $nt->getPrefixedDbKey() ); |
| | 73 | + $cachedText = $wgMemc->get( $key ); |
| | 74 | + if( $cachedText ) { |
| | 75 | + $text = $cachedText; |
| | 76 | + } else { |
| | 77 | + $url = $nt->getFullURL(); |
| | 78 | + $myURL = $out->getTitle()->getLocalURL(); |
| | 79 | + $languageName = $wgContLang->getLanguageName( $nt->getInterwiki() ); |
| | 80 | + $myLanguage = $wgLang->getLanguageName( $wgContLang->getCode() ); |
| | 81 | + $translation = Http::get( wfAppendQuery( $url, array( 'action' => 'render' ) ) ); |
| | 82 | + if ( $translation !== null ) { |
| | 83 | + /** |
| | 84 | + * first find all links that have no 'class' parameter. |
| | 85 | + * these links are local so we add '?match=xx' to their url, |
| | 86 | + * unless it already contains a '?' |
| | 87 | + */ |
| | 88 | + $translation = preg_replace( |
| | 89 | + "/<a href=\"http:\/\/([^\"\?]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
| | 90 | + "<a href=\"http://\\1?match={$wgContLanguageCode}\"\\2>", $translation ); |
| | 91 | + // now add class='extiw' to these links |
| | 92 | + $translation = preg_replace( |
| | 93 | + "/<a href=\"http:\/\/([^\"]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
| | 94 | + "<a href=\"http://\\1\" class=\"extiw\"\\3>", $translation ); |
| | 95 | + // use class='extiw' for images too |
| | 96 | + $translation = preg_replace( |
| | 97 | + "/<a href=\"http:\/\/([^\"]*)\"([^\>]*)class=\"image\"([^\>]*)\>/i", |
| | 98 | + "<a href=\"http://\\1\"\\2class=\"extiw\"\\3>", $translation ); |
| 76 | 99 | |
| 77 | | - $translation = Http::get( wfAppendQuery( $url, array( 'action' => 'render' ) ) ); |
| 78 | | - if ( $translation !== null ) { |
| 79 | | - /** |
| 80 | | - * first find all links that have no 'class' parameter. |
| 81 | | - * these links are local so we add '?match=xx' to their url, |
| 82 | | - * unless it already contains a '?' |
| 83 | | - */ |
| 84 | | - $translation = preg_replace( |
| 85 | | - "/<a href=\"http:\/\/([^\"\?]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
| 86 | | - "<a href=\"http://\\1?match={$wgContLanguageCode}\"\\2>", $translation ); |
| 87 | | - // now add class='extiw' to these links |
| 88 | | - $translation = preg_replace( |
| 89 | | - "/<a href=\"http:\/\/([^\"]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
| 90 | | - "<a href=\"http://\\1\" class=\"extiw\"\\3>", $translation ); |
| 91 | | - // use class='extiw' for images too |
| 92 | | - $translation = preg_replace( |
| 93 | | - "/<a href=\"http:\/\/([^\"]*)\"([^\>]*)class=\"image\"([^\>]*)\>/i", |
| 94 | | - "<a href=\"http://\\1\"\\2class=\"extiw\"\\3>", $translation ); |
| | 100 | + // add prefixes to internal links, in order to prevent duplicates |
| | 101 | + $translation = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#l_\\1\"", |
| | 102 | + $translation ); |
| | 103 | + $translation = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"l_\\1\"", |
| | 104 | + $translation ); |
| | 105 | + $text = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#r_\\1\"", $text ); |
| | 106 | + $text = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"r_\\1\"", $text ); |
| 95 | 107 | |
| 96 | | - // add prefixes to internal links, in order to prevent duplicates |
| 97 | | - $translation = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#l_\\1\"", |
| 98 | | - $translation ); |
| 99 | | - $translation = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"l_\\1\"", |
| 100 | | - $translation ); |
| 101 | | - $text = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#r_\\1\"", $text ); |
| 102 | | - $text = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"r_\\1\"", $text ); |
| | 108 | + // add ?match= to local links of the local wiki |
| | 109 | + $text = preg_replace( "/<a href=\"\/([^\"\?]*)\"/i", |
| | 110 | + "<a href=\"/\\1?match={$match_request}\"", $text ); |
| 103 | 111 | |
| 104 | | - // add ?match= to local links of the local wiki |
| 105 | | - $text = preg_replace( "/<a href=\"\/([^\"\?]*)\"/i", |
| 106 | | - "<a href=\"/\\1?match={$match_request}\"", $text ); |
| | 112 | + // do the job |
| | 113 | + $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode, |
| | 114 | + $translation, $languageName, $url, $match_request ); |
| 107 | 115 | |
| 108 | | - // do the job |
| 109 | | - $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode, |
| 110 | | - $translation, $languageName, $url, $match_request ); |
| | 116 | + $wgMemc->set( $key, $text, $wgDoubleWikiCacheTime ); |
| | 117 | + } |
| 111 | 118 | } |
| 112 | 119 | } |
| 113 | | - |
| 114 | 120 | return true; |
| 115 | 121 | } |
| 116 | 122 | |
| Index: trunk/extensions/DoubleWiki/DoubleWiki.php |
| — | — | @@ -25,6 +25,8 @@ |
| 26 | 26 | $wgExtensionMessagesFiles['DoubleWiki'] = dirname(__FILE__) . '/DoubleWiki.i18n.php'; |
| 27 | 27 | $wgAutoloadClasses['DoubleWiki'] = dirname( __FILE__ ) . "/DoubleWiki_body.php"; |
| 28 | 28 | $wgHooks['OutputPageBeforeHTML'][] = 'DoubleWiki::OutputPageBeforeHTML'; |
| | 29 | +// How long cached page output is stored in memcached |
| | 30 | +$wgDoubleWikiCacheTime = 3600 * 12; |
| 29 | 31 | |
| 30 | 32 | $wgExtensionCredits['other'][] = array( |
| 31 | 33 | 'path' => __FILE__, |