http://www.mediawiki.org/wiki/Special:Code/MediaWiki/93527
Revision: 93527 Author: ialex Date: 2011-07-30 15:03:21 +0000 (Sat, 30 Jul 2011) Log Message: ----------- In Special:ComparePages: * 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 Modified Paths: -------------- trunk/phase3/includes/specials/SpecialComparePages.php trunk/phase3/languages/messages/MessagesEn.php trunk/phase3/maintenance/language/messages.inc Modified: trunk/phase3/includes/specials/SpecialComparePages.php =================================================================== --- trunk/phase3/includes/specials/SpecialComparePages.php 2011-07-30 15:02:56 UTC (rev 93526) +++ trunk/phase3/includes/specials/SpecialComparePages.php 2011-07-30 15:03:21 UTC (rev 93527) @@ -57,6 +57,7 @@ 'label-message' => 'compare-page1', 'size' => '40', 'section' => 'page1', + 'validation-callback' => array( $this, 'checkExistingTitle' ), ), 'Revision1' => array( 'type' => 'int', @@ -64,6 +65,7 @@ 'label-message' => 'compare-rev1', 'size' => '8', 'section' => 'page1', + 'validation-callback' => array( $this, 'checkExistingRevision' ), ), 'Page2' => array( 'type' => 'text', @@ -71,6 +73,7 @@ 'label-message' => 'compare-page2', 'size' => '40', 'section' => 'page2', + 'validation-callback' => array( $this, 'checkExistingTitle' ), ), 'Revision2' => array( 'type' => 'int', @@ -78,6 +81,7 @@ 'label-message' => 'compare-rev2', 'size' => '8', 'section' => 'page2', + 'validation-callback' => array( $this, 'checkExistingRevision' ), ), 'Action' => array( 'type' => 'hidden', @@ -87,16 +91,15 @@ '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 @@ } 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; + } } Modified: trunk/phase3/languages/messages/MessagesEn.php =================================================================== --- trunk/phase3/languages/messages/MessagesEn.php 2011-07-30 15:02:56 UTC (rev 93526) +++ trunk/phase3/languages/messages/MessagesEn.php 2011-07-30 15:03:21 UTC (rev 93527) @@ -4567,13 +4567,16 @@ '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', Modified: trunk/phase3/maintenance/language/messages.inc =================================================================== --- trunk/phase3/maintenance/language/messages.inc 2011-07-30 15:02:56 UTC (rev 93526) +++ trunk/phase3/maintenance/language/messages.inc 2011-07-30 15:03:21 UTC (rev 93527) @@ -3444,6 +3444,9 @@ 'compare-rev1', 'compare-rev2', 'compare-submit', + 'compare-invalid-title', + 'compare-title-not-exists', + 'compare-revision-not-exists', ), 'db-error-messages' => array( 'dberr-header', _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs