Switch some HTMLForms in special pages to OOUI
[lhc/web/wiklou.git] / includes / specials / SpecialBooksources.php
index e6750e1..7028fdc 100644 (file)
@@ -26,7 +26,6 @@
  * 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 {
@@ -73,7 +72,9 @@ 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];
@@ -81,11 +82,14 @@ class SpecialBookSources extends SpecialPage {
                        }
 
                        $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 );
                        }
 
@@ -93,7 +97,7 @@ class SpecialBookSources extends SpecialPage {
                        if ( $check == 10 ) {
                                $check = "X";
                        }
-                       if ( $check == $isbn[9] ) {
+                       if ( (string)$check === $isbn[9] ) {
                                return true;
                        }
                }
@@ -131,19 +135,13 @@ class SpecialBookSources extends SpecialPage {
                        'isbn',
                        20,
                        $this->isbn,
-                       array( 'autofocus' => true, 'class' => 'mw-ui-input-inline' )
+                       array( 'autofocus' => '', 'class' => 'mw-ui-input-inline' )
                );
 
-               if ( $this->getConfig()->get( 'UseMediaWikiUIEverywhere' ) ) {
-                       $form .= '&#160;' . Xml::submitButton(
-                               $this->msg( 'booksources-search' )->text(),
-                               array( 'class' => 'mw-ui-button mw-ui-progressive' )
-                       ) . "</p>\n";
-               } else {
-                       $form .= '&#160;' . Xml::submitButton(
-                               $this->msg( 'booksources-search' )->text()
-                       ) . "</p>\n";
-               }
+               $form .= '&#160;' . Html::submitButton(
+                       $this->msg( 'booksources-search' )->text(),
+                       array(), array( 'mw-ui-progressive' )
+               ) . "</p>\n";
 
                $form .= Html::closeElement( 'form' ) . "\n";
                $form .= Html::closeElement( 'fieldset' ) . "\n";
@@ -163,7 +161,7 @@ class SpecialBookSources extends SpecialPage {
 
                # Hook to allow extensions to insert additional HTML,
                # e.g. for API-interacting plugins and so on
-               wfRunHooks( 'BookInformation', array( $this->isbn, $this->getOutput() ) );
+               Hooks::run( 'BookInformation', array( $this->isbn, $this->getOutput() ) );
 
                # Check for a local page such as Project:Book_sources and use that if available
                $page = $this->msg( 'booksources' )->inContentLanguage()->text();