In Special:ComparePages:
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 30 Jul 2011 15:03:21 +0000 (15:03 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 30 Jul 2011 15:03:21 +0000 (15:03 +0000)
* Validate title and revision when passed
* Don't display the diff if a field is not valid
* Pass the context to the HTMLForm and removed the setTitle() call

includes/specials/SpecialComparePages.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 6b9ef0a..5531a6d 100644 (file)
@@ -57,6 +57,7 @@ class SpecialComparePages extends SpecialPage {
                                'label-message' => 'compare-page1',
                                'size' => '40',
                                'section' => 'page1',
+                               'validation-callback' => array( $this, 'checkExistingTitle' ),
                        ),
                        'Revision1' => array(
                                'type' => 'int',
@@ -64,6 +65,7 @@ class SpecialComparePages extends SpecialPage {
                                'label-message' => 'compare-rev1',
                                'size' => '8',
                                'section' => 'page1',
+                               'validation-callback' => array( $this, 'checkExistingRevision' ),
                        ),
                        'Page2' => array(
                                'type' => 'text',
@@ -71,6 +73,7 @@ class SpecialComparePages extends SpecialPage {
                                'label-message' => 'compare-page2',
                                'size' => '40',
                                'section' => 'page2',
+                               'validation-callback' => array( $this, 'checkExistingTitle' ),
                        ),
                        'Revision2' => array(
                                'type' => 'int',
@@ -78,6 +81,7 @@ class SpecialComparePages extends SpecialPage {
                                'label-message' => 'compare-rev2',
                                'size' => '8',
                                'section' => 'page2',
+                               'validation-callback' => array( $this, 'checkExistingRevision' ),
                        ),
                        'Action' => array(
                                'type' => 'hidden',
@@ -87,16 +91,15 @@ class SpecialComparePages extends SpecialPage {
                                'type' => 'hidden',
                                'name' => 'diffonly',
                        ),
-               ), 'compare' );
+               ), $this->getContext(), 'compare' );
                $form->setSubmitText( wfMsg( 'compare-submit' ) );
                $form->suppressReset();
                $form->setMethod( 'get' );
-               $form->setTitle( $this->getTitle() );
+               $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) );
 
                $form->loadData();
                $form->displayForm( '' );
-
-               self::showDiff( $form->mFieldData );
+               $form->trySubmit();
        }
 
        public static function showDiff( $data ){
@@ -125,4 +128,29 @@ class SpecialComparePages extends SpecialPage {
                }
                return null;
        }
+
+       public function checkExistingTitle( $value, $alldata ) {
+               if ( $value === '' ) {
+                       return true;
+               }
+               $title = Title::newFromText( $value );
+               if ( !$title instanceof Title ) {
+                       return wfMsgExt( 'compare-invalid-title', 'parse' );
+               }
+               if ( !$title->exists() ) {
+                       return wfMsgExt( 'compare-title-not-exists', 'parse' );
+               }
+               return true;
+       }
+
+       public function checkExistingRevision( $value, $alldata ) {
+               if ( $value === '' ) {
+                       return true;
+               }
+               $revision = Revision::newFromId( $value );
+               if ( $revision === null ) {
+                       return wfMsgExt( 'compare-revision-not-exists', 'parse' );
+               }
+               return true;
+       }
 }
index 2903cdc..ec19c9b 100644 (file)
@@ -4567,13 +4567,16 @@ Enter the file name without the "{{ns:file}}:" prefix.',
 'tags-hitcount'           => '$1 {{PLURAL:$1|change|changes}}',
 
 # Special:ComparePages
-'comparepages'     => 'Compare pages',
-'compare-selector' => 'Compare page revisions',
-'compare-page1'    => 'Page 1',
-'compare-page2'    => 'Page 2',
-'compare-rev1'     => 'Revision 1',
-'compare-rev2'     => 'Revision 2',
-'compare-submit'   => 'Compare',
+'comparepages'                => 'Compare pages',
+'compare-selector'            => 'Compare page revisions',
+'compare-page1'               => 'Page 1',
+'compare-page2'               => 'Page 2',
+'compare-rev1'                => 'Revision 1',
+'compare-rev2'                => 'Revision 2',
+'compare-submit'              => 'Compare',
+'compare-invalid-title'       => 'The title you specified is invalid.',
+'compare-title-not-exists'    => 'The title you specified does not exist.',
+'compare-revision-not-exists' => 'The revision you specified does not exist.',
 
 # Database error messages
 'dberr-header'      => 'This wiki has a problem',
index 91c25fc..82b168c 100644 (file)
@@ -3444,6 +3444,9 @@ $wgMessageStructure = array(
                'compare-rev1',
                'compare-rev2',
                'compare-submit',
+               'compare-invalid-title',
+               'compare-title-not-exists',
+               'compare-revision-not-exists',
        ),
        'db-error-messages' => array(
                'dberr-header',