Index: trunk/extensions/Call/Call.i18n.php |
— | — | @@ -555,7 +555,7 @@ |
556 | 556 | */ |
557 | 557 | $messages['id'] = array( |
558 | 558 | 'call' => 'Panggilan', |
559 | | - 'call-desc' => 'Buat sebuah pranala ke templat (atau halaman wiki biasa) dengan parameter. |
| 559 | + 'call-desc' => 'Buat sebuah pranala ke templat (atau halaman wiki biasa) dengan parameter. |
560 | 560 | Dapat digunakan pada baris perintah penjelajah web atau di antara teks wiki', |
561 | 561 | 'call-text' => "Pengaya \"Panggilan\" membutuhkan sebuah halaman wiki dan parameter opsional untuk halaman tersebut untuk digunakan sebagai argumen. |
562 | 562 | |
Index: trunk/extensions/Call/Call.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * added "return true;" at the end of wfCallLoadMessages() |
7 | 7 | */ |
8 | 8 | # Not a valid entry point, skip unless MEDIAWIKI is defined |
9 | | -if (!defined('MEDIAWIKI')) { |
| 9 | +if ( !defined( 'MEDIAWIKI' ) ) { |
10 | 10 | echo <<<EOT |
11 | 11 | To install Call as a special page, put the following line in LocalSettings.php: |
12 | 12 | require_once( "\$IP/extensions/Call/Call.php" ); |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | exit( 1 ); |
15 | 15 | } |
16 | 16 | |
17 | | -$dir = dirname(__FILE__) .'/'; |
| 17 | +$dir = dirname( __FILE__ ) . '/'; |
18 | 18 | $wgAutoloadClasses['Call'] = $dir . 'Call_body.php'; |
19 | 19 | $wgExtensionMessagesFiles['Call'] = $dir . 'Call.i18n.php'; |
20 | 20 | $wgExtensionAliasesFiles['Call'] = $dir . 'Call.alias.php'; |
Index: trunk/extensions/Call/Call_body.php |
— | — | @@ -28,215 +28,239 @@ |
29 | 29 | * link2 replaces "name" by "value" and "," by "&" |
30 | 30 | */ |
31 | 31 | |
32 | | -class Call extends SpecialPage |
33 | | -{ |
34 | | - function Call() { |
35 | | - SpecialPage::SpecialPage("Call"); |
36 | | - wfLoadExtensionMessages('Call'); |
37 | | - } |
| 32 | +class Call extends SpecialPage { |
| 33 | + function Call() { |
| 34 | + SpecialPage::SpecialPage( "Call" ); |
| 35 | + wfLoadExtensionMessages( 'Call' ); |
| 36 | + } |
38 | 37 | |
39 | | - |
40 | | - function execute($par) { |
41 | | - global $wgParser; |
42 | | - global $wgOut, $wgRequest, $wgRawHtml, $wgUser; |
43 | | - $oldRawHtml = $wgRawHtml; |
44 | | - $wgRawHtml = false; // disable raw html if it's enabled as this could be XSS security risk |
45 | | - $this->setHeaders(); |
46 | | - |
47 | | - global $_REQUEST; |
48 | | - $argkeys = array_keys($_REQUEST); |
49 | | - |
50 | | - // find the position of "title" and count succeeding arguments until we find one that matches |
51 | | - // one of the patterns which belong to typical session cookie variables |
52 | | - // store link info |
53 | | - $argTitle=-1; $argCount=0; $n=0; $link1=''; $link2=''; $label1 = 'link 1'; $label2 = 'link 2'; |
54 | | - foreach ($argkeys as $argKey) { |
55 | | - if ($argKey=='link1') $link1=$wgRequest->getText($argKey); |
56 | | - if ($argKey=='label1') $label1=$wgRequest->getText($argKey); |
57 | | - if ($argKey=='link2') $link2=$wgRequest->getText($argKey); |
58 | | - if ($argKey=='label2') $label2=$wgRequest->getText($argKey); |
59 | | - if ($argKey=='title') $argTitle = $n; |
60 | | - else if ($argTitle>=0) { |
61 | | - if (preg_match('/(UserName|UserID|_session|Token)$/',$argKey)) break; |
62 | | - ++$argCount; |
63 | | - } |
64 | | - $n++; |
65 | | - } |
66 | 38 | |
67 | | - $debug= !(strpos($wgRequest->getText('title'),'DebuG')===false); |
68 | | - if ($debug) { |
69 | | - $wgOut->addHTML("<pre>\n"); |
70 | | - foreach ($argkeys as $argKeyNr => $argKey) { |
71 | | - $wgOut->addHTML("$argKeyNr:$argKey:"); |
72 | | - $wgOut->addHTML($wgRequest->getText($argKey)."\n",1); |
73 | | - } |
74 | | - $wgOut->addHTML("\npar=$par\nargTitle=$argTitle\nargCount=$argCount</pre>"); |
75 | | - } |
| 39 | + function execute( $par ) { |
| 40 | + global $wgParser; |
| 41 | + global $wgOut, $wgRequest, $wgRawHtml, $wgUser; |
| 42 | + $oldRawHtml = $wgRawHtml; |
| 43 | + $wgRawHtml = false; // disable raw html if it's enabled as this could be XSS security risk |
| 44 | + $this->setHeaders(); |
76 | 45 | |
77 | | - $wikitext=''; $n=0; $i=-1; |
78 | | - foreach ($argkeys as $argKeyNr => $argKey) { |
79 | | - $i++; |
80 | | - if ($i<$argTitle) continue; |
81 | | - if ($i==$argTitle) { |
82 | | - $wikitext .= preg_replace(',^[^/]+/,','',$wgRequest->getText($argKey),1); |
83 | | - $wikitext = str_replace( ",", "|", $wikitext ); |
84 | | - $wikitext = str_replace( "_", " ", $wikitext ); |
85 | | - continue; |
86 | | - } |
87 | | - if (++$n > $argCount) break; |
88 | | - $arg = $wgRequest->getText($argKey); |
89 | | - if ($arg=='') { |
90 | | - $link1 = str_replace(",$argKey,",",$argKey=,",$link1); |
91 | | - $link2 = str_replace($argKey,"",$link2); |
92 | | - $arg = str_replace( "_", " ", $argKey ); |
93 | | - $wikitext .= ( '|' . $arg ); |
94 | | - } else { |
95 | | - $link1 = str_replace(",$argKey,",",$argKey=$arg,",$link1); |
96 | | - $link2 = str_replace($argKey,str_replace(' ','_',$arg),$link2); |
97 | | - $arg = str_replace( "_", " ", $arg ); |
98 | | - $wikitext .= ( '|' . $argKey . '=' . $arg ); |
| 46 | + global $_REQUEST; |
| 47 | + $argkeys = array_keys( $_REQUEST ); |
| 48 | + |
| 49 | + // find the position of "title" and count succeeding arguments until we find one that matches |
| 50 | + // one of the patterns which belong to typical session cookie variables |
| 51 | + // store link info |
| 52 | + $argTitle = -1; $argCount = 0; $n = 0; $link1 = ''; $link2 = ''; $label1 = 'link 1'; $label2 = 'link 2'; |
| 53 | + foreach ( $argkeys as $argKey ) { |
| 54 | + if ( $argKey == 'link1' ) { |
| 55 | + $link1 = $wgRequest->getText( $argKey ); |
| 56 | + } |
| 57 | + if ( $argKey == 'label1' ) { |
| 58 | + $label1 = $wgRequest->getText( $argKey ); |
| 59 | + } |
| 60 | + if ( $argKey == 'link2' ) { |
| 61 | + $link2 = $wgRequest->getText( $argKey ); |
| 62 | + } |
| 63 | + if ( $argKey == 'label2' ) { |
| 64 | + $label2 = $wgRequest->getText( $argKey ); |
| 65 | + } |
| 66 | + if ( $argKey == 'title' ) { |
| 67 | + $argTitle = $n; |
| 68 | + } else if ( $argTitle >= 0 ) { |
| 69 | + if ( preg_match( '/(UserName|UserID|_session|Token)$/', $argKey ) ) { |
| 70 | + break; |
99 | 71 | } |
100 | | - } |
| 72 | + ++$argCount; |
| 73 | + } |
| 74 | + $n++; |
| 75 | + } |
101 | 76 | |
102 | | - if ($wikitext=='' && $par!='') { |
103 | | - // the first argument may contain parameters which are separated by comma |
104 | | - // this is the case if [[Call,a=b]] syntax is used |
105 | | - $wikitext = str_replace( ",", "|", $par ); |
| 77 | + $debug = !( strpos( $wgRequest->getText( 'title' ), 'DebuG' ) === false ); |
| 78 | + if ( $debug ) { |
| 79 | + $wgOut->addHTML( "<pre>\n" ); |
| 80 | + foreach ( $argkeys as $argKeyNr => $argKey ) { |
| 81 | + $wgOut->addHTML( "$argKeyNr:$argKey:" ); |
| 82 | + $wgOut->addHTML( $wgRequest->getText( $argKey ) . "\n", 1 ); |
| 83 | + } |
| 84 | + $wgOut->addHTML( "\npar=$par\nargTitle=$argTitle\nargCount=$argCount</pre>" ); |
| 85 | + } |
| 86 | + |
| 87 | + $wikitext = ''; $n = 0; $i = -1; |
| 88 | + foreach ( $argkeys as $argKeyNr => $argKey ) { |
| 89 | + $i++; |
| 90 | + if ( $i < $argTitle ) { |
| 91 | + continue; |
| 92 | + } |
| 93 | + if ( $i == $argTitle ) { |
| 94 | + $wikitext .= preg_replace( ',^[^/]+/,', '', $wgRequest->getText( $argKey ), 1 ); |
| 95 | + $wikitext = str_replace( ",", "|", $wikitext ); |
106 | 96 | $wikitext = str_replace( "_", " ", $wikitext ); |
107 | | - } |
| 97 | + continue; |
| 98 | + } |
| 99 | + if ( ++$n > $argCount ) { |
| 100 | + break; |
| 101 | + } |
| 102 | + $arg = $wgRequest->getText( $argKey ); |
| 103 | + if ( $arg == '' ) { |
| 104 | + $link1 = str_replace( ",$argKey,", ",$argKey=,", $link1 ); |
| 105 | + $link2 = str_replace( $argKey, "", $link2 ); |
| 106 | + $arg = str_replace( "_", " ", $argKey ); |
| 107 | + $wikitext .= ( '|' . $arg ); |
| 108 | + } else { |
| 109 | + $link1 = str_replace( ",$argKey,", ",$argKey=$arg,", $link1 ); |
| 110 | + $link2 = str_replace( $argKey, str_replace( ' ', '_', $arg ), $link2 ); |
| 111 | + $arg = str_replace( "_", " ", $arg ); |
| 112 | + $wikitext .= ( '|' . $argKey . '=' . $arg ); |
| 113 | + } |
| 114 | + } |
108 | 115 | |
109 | | - // check if the result shall be saved as a wiki article |
110 | | - $saveAsPageLink=''; $saveAsPage=''; $saveAsTitle=null; |
111 | | - $wikitextS = preg_replace('/^.*\|\s*saveAsPage\s*=\s*/s','',$wikitext); |
112 | | - if ($wikitextS != $wikitext) { |
113 | | - $saveAsPageLink= preg_replace('/\s*\|.*/s','',$wikitextS); |
114 | | - $saveAsTitle = Title::newFromText($saveAsPageLink); |
115 | | - $saveAsPage = $saveAsTitle->getText(); |
116 | | - if ($saveAsTitle->getNamespace()==14) $saveAsPageLink = ':'.$saveAsPageLink; |
117 | | - } |
| 116 | + if ( $wikitext == '' && $par != '' ) { |
| 117 | + // the first argument may contain parameters which are separated by comma |
| 118 | + // this is the case if [[Call,a=b]] syntax is used |
| 119 | + $wikitext = str_replace( ",", "|", $par ); |
| 120 | + $wikitext = str_replace( "_", " ", $wikitext ); |
| 121 | + } |
118 | 122 | |
119 | | - // check if we want to execute a built-in command |
120 | | - $cmd = preg_replace('/^.*\|\s*cmd\s*=\s*/s','',$wikitext); |
121 | | - if ($cmd == $wikitext) $cmd=''; |
122 | | - else { |
123 | | - $cmd = preg_replace('/\s*\|.*/s','',$cmd); |
124 | | - } |
| 123 | + // check if the result shall be saved as a wiki article |
| 124 | + $saveAsPageLink = ''; $saveAsPage = ''; $saveAsTitle = null; |
| 125 | + $wikitextS = preg_replace( '/^.*\|\s*saveAsPage\s*=\s*/s', '', $wikitext ); |
| 126 | + if ( $wikitextS != $wikitext ) { |
| 127 | + $saveAsPageLink = preg_replace( '/\s*\|.*/s', '', $wikitextS ); |
| 128 | + $saveAsTitle = Title::newFromText( $saveAsPageLink ); |
| 129 | + $saveAsPage = $saveAsTitle->getText(); |
| 130 | + if ( $saveAsTitle->getNamespace() == 14 ) { |
| 131 | + $saveAsPageLink = ':' . $saveAsPageLink; |
| 132 | + } |
| 133 | + } |
125 | 134 | |
126 | | - // in both cases we need the raw text of the called page |
127 | | - $rawText=''; |
128 | | - if ($cmd!='' || $saveAsPage!='') { |
129 | | - $template = preg_replace('/\|.*/','',$wikitext); |
130 | | - if (strpos(':',$template) === false) $template = 'Template:'.$template; |
131 | | - else if ($template[0]==':') $template = substr($template,1); |
132 | | - $title = Title::newFromText($template); |
133 | | - if ($title!=null && !$title->exists()) $rawText= "'$template' not found."; |
134 | | - else { |
135 | | - $article = new Article($title); |
136 | | - $rawText = $article->getContent(); |
137 | | - } |
| 135 | + // check if we want to execute a built-in command |
| 136 | + $cmd = preg_replace( '/^.*\|\s*cmd\s*=\s*/s', '', $wikitext ); |
| 137 | + if ( $cmd == $wikitext ) { |
| 138 | + $cmd = ''; |
| 139 | + } else { |
| 140 | + $cmd = preg_replace( '/\s*\|.*/s', '', $cmd ); |
| 141 | + } |
| 142 | + |
| 143 | + // in both cases we need the raw text of the called page |
| 144 | + $rawText = ''; |
| 145 | + if ( $cmd != '' || $saveAsPage != '' ) { |
| 146 | + $template = preg_replace( '/\|.*/', '', $wikitext ); |
| 147 | + if ( strpos( ':', $template ) === false ) { |
| 148 | + $template = 'Template:' . $template; |
| 149 | + } else if ( $template[0] == ':' ) { |
| 150 | + $template = substr( $template, 1 ); |
138 | 151 | } |
| 152 | + $title = Title::newFromText( $template ); |
| 153 | + if ( $title != null && !$title->exists() ) { |
| 154 | + $rawText = "'$template' not found."; |
| 155 | + } else { |
| 156 | + $article = new Article( $title ); |
| 157 | + $rawText = $article->getContent(); |
| 158 | + } |
| 159 | + } |
139 | 160 | |
140 | | - if ($wikitext=='' || $wikitext=='Special:Call' ) { |
141 | | - // Called without parameters: dump explanation |
142 | | - $wgOut->addHTML(wfMsg('call-text')); |
143 | | - } |
144 | | - else if ($debug) { |
145 | | - // Called with DebuG target: dump parameter list |
146 | | - $wgOut->addHTML("<pre>\n{{".$wikitext."}}\n</pre>"); |
147 | | - if ($saveAsPage!='') $wgOut->addHTML( wfMsg('call-save',$saveAsPageLink) ); |
148 | | - } |
149 | | - else { |
150 | | - $parm=array(); |
151 | | - foreach (split('\|',$wikitext) as $parmArg) { |
152 | | - $pp = split('=',$parmArg,2); |
153 | | - if (count($pp) == 2) $parm[$pp[0]] = $pp[1]; |
154 | | - else $parm[$pp[0]] = ''; |
| 161 | + if ( $wikitext == '' || $wikitext == 'Special:Call' ) { |
| 162 | + // Called without parameters: dump explanation |
| 163 | + $wgOut->addHTML( wfMsg( 'call-text' ) ); |
| 164 | + } else if ( $debug ) { |
| 165 | + // Called with DebuG target: dump parameter list |
| 166 | + $wgOut->addHTML( "<pre>\n{{" . $wikitext . "}}\n</pre>" ); |
| 167 | + if ( $saveAsPage != '' ) { |
| 168 | + $wgOut->addHTML( wfMsg( 'call-save', $saveAsPageLink ) ); |
| 169 | + } |
| 170 | + } else { |
| 171 | + $parm = array(); |
| 172 | + foreach ( split( '\|', $wikitext ) as $parmArg ) { |
| 173 | + $pp = split( '=', $parmArg, 2 ); |
| 174 | + if ( count( $pp ) == 2 ) { |
| 175 | + $parm[$pp[0]] = $pp[1]; |
| 176 | + } else { |
| 177 | + $parm[$pp[0]] = ''; |
155 | 178 | } |
156 | | - if ($cmd=='convertTableToTemplateCalls') { |
157 | | - // execute command |
158 | | - $rawText = Call::convertTableToTemplateCalls($rawText,$parm); |
159 | | - } |
160 | | - if ($saveAsPage != '') { |
161 | | - // replace literals in text |
162 | | - foreach ($parm as $arg => $value) { |
163 | | - $rawText = str_replace($arg,$value,$rawText); |
164 | | - } |
165 | | - // do not save if article is already present |
166 | | - if (!($saveAsTitle->exists())) { |
167 | | - $article = new Article($saveAsTitle); |
168 | | - $article->doEdit( $rawText, $saveAsPage, EDIT_NEW | EDIT_FORCE_BOT ); |
169 | | - $wgOut->addHTML($wgOut->parse(wfMsg('call-save-success' ,$saveAsPageLink) ) ); |
170 | | - } |
171 | | - else { |
172 | | - $wgOut->addHTML($wgOut->parse(wfMsg('call-save-failed',$saveAsPageLink) ) ); |
173 | | - } |
174 | | - // output the text we produced as a note to the user |
175 | | - if ($link1!='') $wgOut->addHTML($wgOut->parse("[[Special:Call/$link1|$label1]]")); |
176 | | - $link2=str_replace(',','&',$link2); |
177 | | - if ($link2!='') $wgOut->addHTML($wgOut->parse("[$link2 $label2]")); |
178 | | - $wgOut->addHTML("<pre>\n$rawText\n</pre>"); |
179 | | - } |
180 | | - else { |
181 | | - // call the template and produce output |
182 | | - $wgOut->addHTML($wgOut->parse("{{".$wikitext."}}")); |
183 | | - } |
184 | | - } |
| 179 | + } |
| 180 | + if ( $cmd == 'convertTableToTemplateCalls' ) { |
| 181 | + // execute command |
| 182 | + $rawText = Call::convertTableToTemplateCalls( $rawText, $parm ); |
| 183 | + } |
| 184 | + if ( $saveAsPage != '' ) { |
| 185 | + // replace literals in text |
| 186 | + foreach ( $parm as $arg => $value ) { |
| 187 | + $rawText = str_replace( $arg, $value, $rawText ); |
| 188 | + } |
| 189 | + // do not save if article is already present |
| 190 | + if ( !( $saveAsTitle->exists() ) ) { |
| 191 | + $article = new Article( $saveAsTitle ); |
| 192 | + $article->doEdit( $rawText, $saveAsPage, EDIT_NEW | EDIT_FORCE_BOT ); |
| 193 | + $wgOut->addHTML( $wgOut->parse( wfMsg( 'call-save-success' , $saveAsPageLink ) ) ); |
| 194 | + } else { |
| 195 | + $wgOut->addHTML( $wgOut->parse( wfMsg( 'call-save-failed', $saveAsPageLink ) ) ); |
| 196 | + } |
| 197 | + // output the text we produced as a note to the user |
| 198 | + if ( $link1 != '' ) { |
| 199 | + $wgOut->addHTML( $wgOut->parse( "[[Special:Call/$link1|$label1]]" ) ); |
| 200 | + } |
| 201 | + $link2 = str_replace( ',', '&', $link2 ); |
| 202 | + if ( $link2 != '' ) { |
| 203 | + $wgOut->addHTML( $wgOut->parse( "[$link2 $label2]" ) ); |
| 204 | + } |
| 205 | + $wgOut->addHTML( "<pre>\n$rawText\n</pre>" ); |
| 206 | + } else { |
| 207 | + // call the template and produce output |
| 208 | + $wgOut->addHTML( $wgOut->parse( "{{" . $wikitext . "}}" ) ); |
| 209 | + } |
| 210 | + } |
185 | 211 | |
186 | | - $skin = $wgUser->getSkin(); |
187 | | - $wgRawHtml = $oldRawHtml; |
| 212 | + $skin = $wgUser->getSkin(); |
| 213 | + $wgRawHtml = $oldRawHtml; |
188 | 214 | |
189 | | - $newTitle = split("\,",$par,2); |
190 | | - if ($newTitle!=null && strlen($newTitle[0])>0) { |
191 | | - $newTitle[0]=str_replace("_"," ",$newTitle[0]); |
192 | | - $newTitle[0]=preg_replace("/^:/","",$newTitle[0]); |
193 | | - $wgOut->setPageTitle($newTitle[0]); |
194 | | - } |
195 | | - // $wgOut->addMeta("http:expires", "0"); |
196 | | - |
| 215 | + $newTitle = split( "\,", $par, 2 ); |
| 216 | + if ( $newTitle != null && strlen( $newTitle[0] ) > 0 ) { |
| 217 | + $newTitle[0] = str_replace( "_", " ", $newTitle[0] ); |
| 218 | + $newTitle[0] = preg_replace( "/^:/", "", $newTitle[0] ); |
| 219 | + $wgOut->setPageTitle( $newTitle[0] ); |
197 | 220 | } |
| 221 | + } |
198 | 222 | |
199 | | - static function convertTableToTemplateCalls($rawText, $parms) { |
200 | | - $text=array(); |
201 | | - $state=0; |
202 | | - $n=-1; |
203 | | - $field=array(); |
204 | | - $head=true; |
205 | | - $tpl='???'; |
206 | | - foreach (split("\n",$rawText) as $line) { |
207 | | - // $text[] = "$state $n $line"; |
208 | | - if ($state==0) { |
209 | | - if (strpos($line,'|-')!==false) { |
210 | | - $state=1; |
211 | | - $n=-1; |
212 | | - $tpl=$field[0]; |
213 | | - $field[0] = 'ID'; |
214 | | - } else if (strpos($line,'|')==0) { |
215 | | - $n++; |
216 | | - $field[$n]=substr($line,1); |
217 | | - } |
218 | | - } else if (strpos($line,'|-')!==false) { |
219 | | - $n=-1; |
220 | | - } else if (strpos($line,'|}')!==false) { |
221 | | - $text[] = '}}'; |
222 | | - break; |
223 | | - } else if ($line=='') { |
224 | | - $text[]=''; |
225 | | - } else if ($line[0]=='|') { |
226 | | - $n++; |
227 | | - if ($n==0) { |
228 | | - if ($head) { |
229 | | - $text[] = "{{DT Article|index="; |
230 | | - $head=false; |
231 | | - } |
232 | | - $text[] = "}}\n==".substr($line,1)."==\n{{".$tpl."\n|".$field[$n].'='.substr($line,1); |
233 | | - } else { |
234 | | - $text[] = '|'.$field[$n].'='; |
235 | | - $text[] = substr($line,1); |
236 | | - } |
237 | | - } else { |
238 | | - $text[] = $line; |
| 223 | + static function convertTableToTemplateCalls( $rawText, $parms ) { |
| 224 | + $text = array(); |
| 225 | + $state = 0; |
| 226 | + $n = -1; |
| 227 | + $field = array(); |
| 228 | + $head = true; |
| 229 | + $tpl = '???'; |
| 230 | + foreach ( split( "\n", $rawText ) as $line ) { |
| 231 | + // $text[] = "$state $n $line"; |
| 232 | + if ( $state == 0 ) { |
| 233 | + if ( strpos( $line, '|-' ) !== false ) { |
| 234 | + $state = 1; |
| 235 | + $n = -1; |
| 236 | + $tpl = $field[0]; |
| 237 | + $field[0] = 'ID'; |
| 238 | + } else if ( strpos( $line, '|' ) == 0 ) { |
| 239 | + $n++; |
| 240 | + $field[$n] = substr( $line, 1 ); |
239 | 241 | } |
240 | | - } |
241 | | - return join("\n",$text); |
242 | | - } |
| 242 | + } else if ( strpos( $line, '|-' ) !== false ) { |
| 243 | + $n = -1; |
| 244 | + } else if ( strpos( $line, '|}' ) !== false ) { |
| 245 | + $text[] = '}}'; |
| 246 | + break; |
| 247 | + } else if ( $line == '' ) { |
| 248 | + $text[] = ''; |
| 249 | + } else if ( $line[0] == '|' ) { |
| 250 | + $n++; |
| 251 | + if ( $n == 0 ) { |
| 252 | + if ( $head ) { |
| 253 | + $text[] = "{{DT Article|index="; |
| 254 | + $head = false; |
| 255 | + } |
| 256 | + $text[] = "}}\n==" . substr( $line, 1 ) . "==\n{{" . $tpl . "\n|" . $field[$n] . '=' . substr( $line, 1 ); |
| 257 | + } else { |
| 258 | + $text[] = '|' . $field[$n] . '='; |
| 259 | + $text[] = substr( $line, 1 ); |
| 260 | + } |
| 261 | + } else { |
| 262 | + $text[] = $line; |
| 263 | + } |
| 264 | + } |
| 265 | + return join( "\n", $text ); |
| 266 | + } |
243 | 267 | } |