Index: potx.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/potx/Attic/potx.inc,v retrieving revision 1.1.2.17.2.7.2.10 diff -u -p -r1.1.2.17.2.7.2.10 potx.inc --- potx.inc 10 Sep 2008 10:18:39 -0000 1.1.2.17.2.7.2.10 +++ potx.inc 24 Sep 2008 15:55:59 -0000 @@ -33,13 +33,20 @@ define('POTX_STATUS_SILENT', 0); define('POTX_STATUS_MESSAGE', 1); /** - * Command line status reporting: - * - status to standard output - * - errors to standard error + * Command line status reporting. + * + * Status goes to standard output, errors to standard error. */ define('POTX_STATUS_CLI', 2); /** + * Structured array status logging. + * + * Useful for coder review status reporting. + */ +define('POTX_STATUS_STRUCTURED', 3); + +/** * Core parsing mode: * - .info files folded into general.pot * - separate files generated for modules @@ -561,7 +568,7 @@ function _potx_marker_error($file, $line } $ti++; } - potx_status('error', t("Invalid marker content in %filename:%lineno\n* %marker(%tokens\n\n", array('%filename' => $file, '%lineno' => $line, '%marker' => $marker, '%tokens' => $tokens))); + potx_status('error', t('Invalid localization code: %marker%tokens', array('%marker' => $marker, '%tokens' => '('. $tokens)), $file, $line); } /** @@ -570,14 +577,19 @@ function _potx_marker_error($file, $line * @param $op * Operation to perform or type of message text. * - set: sets the reporting mode to $value - * use the POTX_STATUS_* constants as $values + * use one of the POTX_STATUS_* constants as $value * - get: returns the list of error messages recorded - * - error: sends an error message in $value + * if $value is true, it also clears the internal message cache + * - error: sends an error message in $value with optional $file and $line * - status: sends a status message in $value * @param $value - * Value depending on $op, unused with the 'get' op. + * Value depending on $op. + * @param $file + * Name of file the error message is related to. + * @param $line + * Number of line the error message is related to. */ -function potx_status($op, $value) { +function potx_status($op, $value = NULL, $file = NULL, $line = NULL) { static $mode = POTX_STATUS_CLI; static $messages = array(); @@ -590,24 +602,43 @@ function potx_status($op, $value) { case 'get': // Getting the errors. Optionally deleting the messages. $errors = $messages; - if ($value) { + if (!empty($value)) { $messages = array(); } return $errors; case 'error': case 'status': + + // Location information is required in 3 of the four possible reporting + // modes as part of the error message. The structured mode needs the + // file and line info separately, not in the text. + $location_info = ''; + if (($mode != POTX_STATUS_STRUCTURED) && isset($file)) { + if (isset($line)) { + $location_info = t('In %file on line %line.', array('%file' => $file, '%line' => $line)); + } + else { + $location_info = t('In %file.', array('%file' => $file)); + } + } + // Error message or progress text to display. switch ($mode) { case POTX_STATUS_MESSAGE: - drupal_set_message($value, $op); + drupal_set_message($value . ($location_info ? ' '. $location_info : ''), $op); break; case POTX_STATUS_CLI: - fwrite($op == 'error' ? STDERR : STDOUT, $value); + fwrite($op == 'error' ? STDERR : STDOUT, $value . ($location_info ? "\n". $location_info : '') ."\n\n"); break; case POTX_STATUS_SILENT: if ($op == 'error') { - $messages[] = $value; + $messages[] = $value . ($location_info ? ' '. $location_info : ''); + } + break; + case POTX_STATUS_STRUCTURED: + if ($op == 'error') { + $messages[] = array($value, $file, $line); } break; } @@ -786,7 +817,7 @@ function _potx_find_perm_hook($file, $fi } } if (!$count) { - potx_status('error', t("Found a hook_perm() implementation in %filename, but there were no literally provided permissions to record.\n\n", array('%filename' => $file))); + potx_status('error', t('Found a hook_perm() implementation, but there were no literally provided permissions to record.'), $file); } } } @@ -850,7 +881,7 @@ function _potx_find_menu_hook($file, $fi $tn+=2; // Jump forward by 2. } else { - potx_status('error', t("Invalid menu %element definition found in %hook in %filename on line %lineno\n\n", array('%element' => $_potx_tokens[$tn][1], '%filename' => $file, '%hook' => $filebase .'_menu()', '%lineno' => $_potx_tokens[$tn][2]))); + potx_status('error', t('Invalid menu %element definition found in %hook.', array('%element' => $_potx_tokens[$tn][1], '%hook' => $filebase .'_menu()')), $file, $_potx_tokens[$tn][2]); } } $tn++; @@ -1071,7 +1102,7 @@ function _potx_parse_js_file($code, $fil preg_match_all('~[^\w]Drupal\s*\.\s*(t|formatPlural)\s*\([^)]+\)~s', $code, $faulty_matches, PREG_SET_ORDER); if (isset($faulty_matches) && count($faulty_matches)) { foreach($faulty_matches as $index => $match) { - potx_status('error', t("Invalid marker content in %filename\n* %marker\n\n", array('%filename' => $file, '%marker' => $match[0]))); + potx_status('error', t('Invalid localization code: %marker.', array('%marker' => $match[0])), $file); } } } Index: potx.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/potx/Attic/potx.module,v retrieving revision 1.1.2.12.2.2.2.3 diff -u -p -r1.1.2.12.2.2.2.3 potx.module --- potx.module 9 Sep 2008 14:03:01 -0000 1.1.2.12.2.2.2.3 +++ potx.module 24 Sep 2008 15:55:59 -0000 @@ -318,15 +318,29 @@ function potx_reviews() { function potx_coder_review(&$coder_args, $review, $rule, $lines, &$results) { include_once drupal_get_path('module', 'potx') .'/potx.inc'; - // Request collection of error messages internally. - potx_status('set', POTX_STATUS_SILENT); - // Process the file (but throw away the result); - _potx_process_file(realpath($coder_args['#filename'])); + // Request collection of error messages internally in a structured format. + potx_status('set', POTX_STATUS_STRUCTURED); + // Process the file (but throw away the result). + $filename = realpath($coder_args['#filename']); + _potx_process_file($filename); // Grab the errors and empty the error list. $errors = potx_status('get', TRUE); - + $severity_name = _coder_severity_name($coder_args, $review, $rule); foreach ($errors as $error) { - $results[] = theme('coder_warning', array('#warning' => $error), $severity_name, 0, ''); + // Errors contain the message, file name (which we did not use here), and + // in most cases the line number for the error. Not all errors know about + // the exact line number, so it might not be there. + list($message, $file, $lineno) = $error; + if (empty($lineno)) { + // $lineno might be NULL so set to 0. + $lineno = 0; + $line = ''; + } + else { + $line = $coder_args['#all_lines'][$lineno]; + } + $rule['#warning'] = htmlspecialchars_decode($message, ENT_QUOTES); + _coder_error($results, $rule, $severity_name, $lineno, $line); } }