r99937 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99936‎ | r99937 | r99938 >
Date:02:51, 16 October 2011
Author:reedy
Status:reverted (Comments)
Tags:
Comment:
De-indent a large block of code
Modified paths:
  • /trunk/extensions/DoubleWiki/DoubleWiki_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DoubleWiki/DoubleWiki_body.php
@@ -66,59 +66,60 @@
6767 $nt = Title::newFromText( $l );
6868 $iw = $nt->getInterwiki();
6969
70 - if ( $iw === $match_request ) {
 70+ if ( $iw !== $match_request ) {
 71+ continue;
 72+ }
 73+ $key = wfMemcKey( 'doublewiki', $wgLang->getCode(), $nt->getPrefixedDbKey() );
 74+ $cachedText = $wgMemc->get( $key );
7175
72 - $key = wfMemcKey( 'doublewiki', $wgLang->getCode(), $nt->getPrefixedDbKey() );
73 - $cachedText = $wgMemc->get( $key );
 76+ if( $cachedText ) {
 77+ $text = $cachedText;
 78+ } else {
 79+ $url = $nt->getCanonicalURL();
 80+ $myURL = $out->getTitle()->getLocalURL();
 81+ $languageName = $wgContLang->getLanguageName( $iw );
 82+ $myLanguage = $wgLang->getLanguageName( $wgContLang->getCode() );
 83+ $translation = Http::get( wfAppendQuery( $url, array( 'action' => 'render' ) ) );
7484
75 - if( $cachedText ) {
76 - $text = $cachedText;
77 - } else {
78 - $url = $nt->getCanonicalURL();
79 - $myURL = $out->getTitle()->getLocalURL();
80 - $languageName = $wgContLang->getLanguageName( $iw );
81 - $myLanguage = $wgLang->getLanguageName( $wgContLang->getCode() );
82 - $translation = Http::get( wfAppendQuery( $url, array( 'action' => 'render' ) ) );
 85+ if ( $translation !== null ) {
 86+ break;
 87+ }
 88+ /**
 89+ * first find all links that have no 'class' parameter.
 90+ * these links are local so we add '?match=xx' to their url,
 91+ * unless it already contains a '?'
 92+ */
 93+ $translation = preg_replace(
 94+ "/<a href=\"http:\/\/([^\"\?]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i",
 95+ "<a href=\"http://\\1?match={$wgContLanguageCode}\"\\2>", $translation );
 96+ // now add class='extiw' to these links
 97+ $translation = preg_replace(
 98+ "/<a href=\"http:\/\/([^\"]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i",
 99+ "<a href=\"http://\\1\" class=\"extiw\"\\3>", $translation );
 100+ // use class='extiw' for images too
 101+ $translation = preg_replace(
 102+ "/<a href=\"http:\/\/([^\"]*)\"([^\>]*)class=\"image\"([^\>]*)\>/i",
 103+ "<a href=\"http://\\1\"\\2class=\"extiw\"\\3>", $translation );
83104
84 - if ( $translation !== null ) {
85 - /**
86 - * first find all links that have no 'class' parameter.
87 - * these links are local so we add '?match=xx' to their url,
88 - * unless it already contains a '?'
89 - */
90 - $translation = preg_replace(
91 - "/<a href=\"http:\/\/([^\"\?]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i",
92 - "<a href=\"http://\\1?match={$wgContLanguageCode}\"\\2>", $translation );
93 - // now add class='extiw' to these links
94 - $translation = preg_replace(
95 - "/<a href=\"http:\/\/([^\"]*)\"(([\s]+)(c(?!lass=)|[^c\>\s])([^\>\s]*))*\>/i",
96 - "<a href=\"http://\\1\" class=\"extiw\"\\3>", $translation );
97 - // use class='extiw' for images too
98 - $translation = preg_replace(
99 - "/<a href=\"http:\/\/([^\"]*)\"([^\>]*)class=\"image\"([^\>]*)\>/i",
100 - "<a href=\"http://\\1\"\\2class=\"extiw\"\\3>", $translation );
 105+ // add prefixes to internal links, in order to prevent duplicates
 106+ $translation = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#l_\\1\"",
 107+ $translation );
 108+ $translation = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"l_\\1\"",
 109+ $translation );
 110+ $text = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#r_\\1\"", $text );
 111+ $text = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"r_\\1\"", $text );
101112
102 - // add prefixes to internal links, in order to prevent duplicates
103 - $translation = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#l_\\1\"",
104 - $translation );
105 - $translation = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"l_\\1\"",
106 - $translation );
107 - $text = preg_replace( "/<a href=\"#(.*?)\"/i", "<a href=\"#r_\\1\"", $text );
108 - $text = preg_replace( "/<li id=\"(.*?)\"/i", "<li id=\"r_\\1\"", $text );
 113+ // add ?match= to local links of the local wiki
 114+ $text = preg_replace( "/<a href=\"\/([^\"\?]*)\"/i",
 115+ "<a href=\"/\\1?match={$match_request}\"", $text );
109116
110 - // add ?match= to local links of the local wiki
111 - $text = preg_replace( "/<a href=\"\/([^\"\?]*)\"/i",
112 - "<a href=\"/\\1?match={$match_request}\"", $text );
 117+ // do the job
 118+ $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode,
 119+ $translation, $languageName, $url, $match_request );
113120
114 - // do the job
115 - $text = $this->matchColumns ( $text, $myLanguage, $myURL, $wgContLanguageCode,
116 - $translation, $languageName, $url, $match_request );
117 -
118 - $wgMemc->set( $key, $text, $wgDoubleWikiCacheTime );
119 - }
120 - }
121 - break;
 121+ $wgMemc->set( $key, $text, $wgDoubleWikiCacheTime );
122122 }
 123+ break;
123124 }
124125 return true;
125126 }
@@ -127,7 +128,7 @@
128129 * Format the text as a two-column table with aligned paragraphs
129130 */
130131 function matchColumns( $left_text, $left_title, $left_url, $left_lang,
131 - $right_text, $right_title, $right_url, $right_lang ) {
 132+ $right_text, $right_title, $right_url, $right_lang ) {
132133
133134 list( $left_slices, $left_tags ) = $this->find_slices( $left_text );
134135
@@ -136,7 +137,7 @@
137138 $right_chunk = '';
138139
139140 $leftSliceCount = count( $left_slices );
140 - for ( $i = 0 ; $i < $leftSliceCount; $i++ ) {
 141+ for ( $i = 0; $i < $leftSliceCount; $i++ ) {
141142
142143 // some slices might be empty
143144 if ( $left_slices[$i] == '' ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r112292Reverting r99937 to see if it fixes bug 34674reedy03:33, 24 February 2012
r112295Revert r99937 to fix bug 34674 in trunkreedy03:40, 24 February 2012

Comments

#Comment by Reedy (talk | contribs)   03:37, 24 February 2012

Status & tagging log