r61526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61525‎ | r61526 | r61527 >
Date:18:55, 26 January 2010
Author:platonides
Status:reverted
Tags:
Comment:
Step 2: Take out countBoldAndItalic()
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -1112,36 +1112,21 @@
11131113 * Helper function for doAllQuotes()
11141114 */
11151115 public function doQuotes( $text ) {
1116 - # Split in groups of 2, 3, 5 or 6 apostrophes.
1117 - # If there are ever four apostrophes, assume the first is supposed to
1118 - # be text, and the remaining three constitute mark-up for bold text.
1119 - # If there are more than 6 apostrophes in a row, assume they're all
1120 - # text except for the last 6.
1121 - $arr = preg_split( "/('{2,3}(?:''')?)(?!')/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
 1116+ # Counts the number of occurrences of bold and italics mark-ups.
 1117+ self::countBoldAndItalic($text, $numbold, $numitalics);
11221118
1123 - if ( count( $arr ) == 1 )
 1119+ if ( ( $numbold == 0 ) && ( $numitalics == 0 ) )
11241120 return $text;
11251121 else
11261122 {
1127 - # First, do some preliminary work. This may shift some apostrophes from
1128 - # being mark-up to being text. It also counts the number of occurrences
1129 - # of bold and italics mark-ups.
1130 - $i = 0;
1131 - $numbold = 0;
1132 - $numitalics = 0;
1133 - foreach ( $arr as $r )
1134 - {
1135 - if ( ( $i % 2 ) == 1 )
1136 - {
1137 - # Count the number of occurrences of bold and italics mark-ups.
1138 - if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; }
1139 - elseif ( strlen( $arr[$i] ) == 3 ) { $numbold++; }
1140 - elseif ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
1141 - elseif ( strlen( $arr[$i] ) == 6 ) { $numbold+=2; }
1142 - }
1143 - $i++;
1144 - }
 1123+ # Split in groups of 2, 3, 5 or 6 apostrophes.
 1124+ # If there are ever four apostrophes, assume the first is supposed to
 1125+ # be text, and the remaining three constitute mark-up for bold text.
 1126+ # If there are more than 6 apostrophes in a row, assume they're all
 1127+ # text except for the last 6.
 1128+ $arr = preg_split( "/('{2,3}(?:''')?)(?!')/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
11451129
 1130+
11461131 # If there is an odd number of both bold and italics, it is likely
11471132 # that one of the bold ones was meant to be an apostrophe followed
11481133 # by italics. Which one we cannot know for certain, but it is more
@@ -1288,6 +1273,57 @@
12891274 }
12901275
12911276 /**
 1277+ * Counts the number of bold and italic items from a line of text.
 1278+ * Helper function for doQuotes()
 1279+ */
 1280+ private static function countBoldAndItalic($text, &$numBold, &$numItalics) {
 1281+ $numBold = 0;
 1282+ $numItalics = 0;
 1283+ $offset = 0;
 1284+
 1285+ do {
 1286+ $offset = strpos($text, "'", $offset);
 1287+ if ($offset === false)
 1288+ return;
 1289+
 1290+ $quoteLen = strspn($text, "'", $offset);
 1291+ $offset += $quoteLen;
 1292+
 1293+ switch ($quoteLen) {
 1294+ case 0:
 1295+ case 1:
 1296+ break;
 1297+
 1298+ case 2:
 1299+ $numItalics++;
 1300+ break;
 1301+
 1302+ case 3:
 1303+ $numBold++;
 1304+ break;
 1305+
 1306+ case 4:
 1307+ # If there are ever four apostrophes, assume the first is supposed to
 1308+ # be text, and the remaining three constitute mark-up for bold text.
 1309+ $numBold++;
 1310+ $numItalics++;
 1311+ break;
 1312+
 1313+ case 5:
 1314+ $numItalics++;
 1315+ $numBold++;
 1316+ break;
 1317+
 1318+ case 6:
 1319+ default:
 1320+ # If there are more than 6 apostrophes in a row, assume they're all
 1321+ # text except for the last 6.
 1322+ $numBold+=2;
 1323+ }
 1324+ } while (true);
 1325+ }
 1326+
 1327+ /**
12921328 * Replace external links (REL)
12931329 *
12941330 * Note: this is all very hackish and the order of execution matters a lot.

Follow-up revisions

RevisionCommit summaryAuthorDate
r61551Revert r61528, r61527, r61526, r61525, r61519, r61515, r61053, r61052 (Parser...tstarling02:41, 27 January 2010

Status & tagging log