r49221 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49220‎ | r49221 | r49222 >
Date:19:07, 5 April 2009
Author:vasilievvv
Status:ok
Tags:
Comment:
* Use lists instead of implode()d strings in built-in variables wherever it's possible

ATTENTION! This may break filters that rely on "added_lines contains 'bla-bla'" syntax. They'll need to be replaced with "string(added_lines) contains 'bla-bla'"
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php (modified) (history)
  • /trunk/extensions/AbuseFilter/tests/wptest2.t (modified) (history)
  • /trunk/extensions/AbuseFilter/tests/wptest3.t (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php
@@ -187,7 +187,7 @@
188188 $interest_lines[] = substr( $line, strlen($line_prefix) );
189189 }
190190 }
191 - $result = implode( "\n", $interest_lines );
 191+ $result = $interest_lines;
192192 break;
193193 case 'links-from-wikitext':
194194 $article = self::articleFromTitle( $parameters['namespace'],
@@ -197,7 +197,7 @@
198198 $new_text = $vars->getVar( $textVar )->toString();
199199 $editInfo = $article->prepareTextForEdit( $new_text );
200200 $links = array_keys( $editInfo->output->getExternalLinks() );
201 - $result = implode( "\n", $links );
 201+ $result = $links;
202202 break;
203203 case 'links-from-wikitext-nonedit':
204204 case 'links-from-wikitext-or-database':
@@ -216,7 +216,7 @@
217217 $links = array_keys( $editInfo->output->getExternalLinks() );
218218 }
219219
220 - $result = implode( "\n", $links );
 220+ $result = $links;
221221 break;
222222 case 'link-diff-added':
223223 $oldLinkVar = $parameters['oldlink-var'];
@@ -229,7 +229,7 @@
230230 $newLinks = explode( "\n", $newLinks );
231231
232232 $added = array_diff( $newLinks, $oldLinks );
233 - $result = implode( "\n", $added );
 233+ $result = $added;
234234 break;
235235 case 'link-diff-removed':
236236 $oldLinkVar = $parameters['oldlink-var'];
@@ -242,7 +242,7 @@
243243 $newLinks = explode( "\n", $newLinks );
244244
245245 $removed = array_diff( $oldLinks, $newLinks );
246 - $result = implode( "\n", $removed );
 246+ $result = $removed;
247247 break;
248248 case 'parse-wikitext':
249249 $article = self::articleFromTitle( $parameters['namespace'], $parameters['title'] );
@@ -290,7 +290,7 @@
291291 while ($user = $dbr->fetchRow($res)) {
292292 $users[] = $user[0];
293293 }
294 - $result = implode( ", ", $users );
 294+ $result = $users;
295295 break;
296296 case 'get-page-restrictions':
297297 $action = $parameters['action'];
@@ -298,7 +298,7 @@
299299
300300 $rights = $title->getRestrictions( $action );
301301 $rights = count($rights) ? $rights : array();
302 - $result = implode(',', $rights );
 302+ $result = $rights;
303303 break;
304304 case 'simple-user-accessor':
305305 $user = $parameters['user'];
@@ -334,7 +334,7 @@
335335 case 'user-groups':
336336 $user = $parameters['user'];
337337 $obj = self::userObjectFromName( $user );
338 - $result = implode(',', $obj->getEffectiveGroups() );
 338+ $result = $obj->getEffectiveGroups();
339339 break;
340340 case 'length':
341341 $s = $vars->getVar( $parameters['length-var'] )->toString();
Index: trunk/extensions/AbuseFilter/tests/wptest2.t
@@ -3,8 +3,8 @@
44 new_size_test := 100;
55 article_namespace_test := 0;
66 edit_delta_test := -22;
7 -added_lines_test := '<ref name="bah">test</ref> test2!';
8 -removed_lines_test := '<ref name="bah">test</ref><ref name="wah">test2</ref>';
 7+added_lines_test := ['<ref name="bah">test</ref> test2!'];
 8+removed_lines_test := ['<ref name="bah">test</ref><ref name="wah">test2</ref>'];
99
1010 !("autoconfirmed" in user_groups_test)
1111 /* this edit_delta ignores large blankings that are treated by another filter */
@@ -18,4 +18,4 @@
1919 /*Excludes changing to the named reference format and removing closing tags attached to formerly named refs. Unequality is to account for closing the first named tag */
2020 & !(rcount("<ref>",removed_lines_test) = rcount("<ref\sname",added_lines_test) | rcount("</ref>",removed_lines_test) <= rcount("<ref\sname",added_lines_test))
2121 /*Excludes removal of references to Wikipedia itself */
22 -& !(count("http://en.wikipedia.org",removed_lines_test) > count("http://en.wikipedia.org",added_lines_test))
 22+& !(count("http://en.wikipedia.org",string(removed_lines_test)) > count("http://en.wikipedia.org",string(added_lines_test)))
Index: trunk/extensions/AbuseFilter/tests/wptest3.t
@@ -1,11 +1,11 @@
22 /* Filter 18 from English Wikipedia (test type edits from clicking on edit bar) */
33 user_groups_test := ["*"];
44 article_namespace_test := 0;
5 -added_lines_test := "Hello world! '''Bold text''' [http://www.example.com link title]";
 5+added_lines_test := ["Hello world! '''Bold text''' [http://www.example.com link title]"];
66
77 (article_namespace_test == 0) &
88 !("autoconfirmed" in user_groups_test) &
9 -(contains_any(added_lines_test,
 9+(contains_any(string(added_lines_test),
1010 "'''Bold text'''",
1111 "''Italic text''",
1212 "[[Link title]]",

Status & tagging log