* The parser creates links to this page when dealing with ISBNs in wikitext
*
* @author Rob Church <robchur@gmail.com>
- * @todo Validate ISBNs using the standard check-digit method
* @ingroup SpecialPage
*/
class SpecialBookSources extends SpecialPage {
$sum = 0;
if ( strlen( $isbn ) == 13 ) {
for ( $i = 0; $i < 12; $i++ ) {
- if ( $i % 2 == 0 ) {
+ if ( $isbn[$i] === 'X' ) {
+ return false;
+ } elseif ( $i % 2 == 0 ) {
$sum += $isbn[$i];
} else {
$sum += 3 * $isbn[$i];
}
$check = ( 10 - ( $sum % 10 ) ) % 10;
- if ( $check == $isbn[12] ) {
+ if ( (string)$check === $isbn[12] ) {
return true;
}
} elseif ( strlen( $isbn ) == 10 ) {
for ( $i = 0; $i < 9; $i++ ) {
+ if ( $isbn[$i] === 'X' ) {
+ return false;
+ }
$sum += $isbn[$i] * ( $i + 1 );
}
if ( $check == 10 ) {
$check = "X";
}
- if ( $check == $isbn[9] ) {
+ if ( (string)$check === $isbn[9] ) {
return true;
}
}