Index: trunk/extensions/DoubleWiki/DoubleWiki_body.php |
— | — | @@ -63,55 +63,53 @@ |
64 | 64 | } |
65 | 65 | $this->addMatchingTags ( $text, $match_request ); |
66 | 66 | |
67 | | - foreach ( $out->mLanguageLinks as $l ) { |
68 | | - $nt = Title::newFromText( $l ); |
69 | | - $iw = $nt->getInterwiki(); |
| 67 | + $langLinks = $out->getLanguageLinks(); |
70 | 68 | |
71 | | - if ( $iw === $match_request ) { |
72 | | - $url = $nt->getFullURL(); |
73 | | - $myURL = $out->getTitle()->getLocalURL(); |
74 | | - $languageName = $wgContLang->getLanguageName( $nt->getInterwiki() ); |
75 | | - $myLanguage = $wgLang->getLanguageName( $wgContLanguageCode ); |
| 69 | + if ( isset( $langLinks[$match_request] ) ) { |
| 70 | + $nt = Title::newFromText( $langLinks[$match_request] ); |
76 | 71 | |
77 | | - $translation = Http::get( wfAppendQuery( $url, array( 'action' => 'render' ) ) ); |
78 | | - if ( $translation !== null ) { |
79 | | - /* first find all links that have no 'class' parameter. |
80 | | - * these links are local so we add '?match=xx' to their url, |
81 | | - * unless it already contains a '?' |
82 | | - */ |
83 | | - $translation = preg_replace( |
84 | | - "/<a href=\"http:\/\/([^\"\?]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
85 | | - "<a href=\"http://\\1?match={$wgContLanguageCode}\"\\2>", $translation ); |
86 | | - // now add class='extiw' to these links |
87 | | - $translation = preg_replace( |
88 | | - "/<a href=\"http:\/\/([^\"]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i", |
89 | | - "<a href=\"http://\\1\" class=\"extiw\"\\3>", $translation ); |
90 | | - // use class='extiw' for images too |
91 | | - $translation = preg_replace( |
92 | | - "/<a href=\"http:\/\/([^\"]*)\"([^\>]*)class=\"image\"([^\>]*)\>/i", |
93 | | - "<a href=\"http://\\1\"\\2class=\"extiw\"\\3>", $translation ); |
| 72 | + $url = $nt->getFullURL(); |
| 73 | + $myURL = $out->getTitle()->getLocalURL(); |
| 74 | + $languageName = $wgContLang->getLanguageName( $nt->getInterwiki() ); |
| 75 | + $myLanguage = $wgLang->getLanguageName( $wgContLanguageCode ); |
94 | 76 | |
95 | | - // add prefixes to internal links, in order to prevent duplicates |
96 | | - $translation = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#l_\\1\"", |
97 | | - $translation ); |
98 | | - $translation = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"l_\\1\"", |
99 | | - $translation ); |
100 | | - $text = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#r_\\1\"", $text ); |
101 | | - $text = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"r_\\1\"", $text ); |
| 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 ); |
102 | 95 | |
103 | | - // add ?match= to local links of the local wiki |
104 | | - $text = preg_replace( "/<a href=\"\/([^\"\?]*)\"/i", |
105 | | - "<a href=\"/\\1?match={$match_request}\"", $text ); |
| 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 ); |
106 | 103 | |
107 | | - // do the job |
108 | | - $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode, |
109 | | - $translation, $languageName, $url, $match_request ); |
110 | | - } |
| 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 ); |
111 | 107 | |
112 | | - //Break once we've matched a language link, no point in continuing processing |
113 | | - break; |
| 108 | + // do the job |
| 109 | + $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode, |
| 110 | + $translation, $languageName, $url, $match_request ); |
114 | 111 | } |
115 | 112 | } |
| 113 | + |
116 | 114 | return true; |
117 | 115 | } |
118 | 116 | |