Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -3444,6 +3444,9 @@ |
3445 | 3445 | 'compare-rev1', |
3446 | 3446 | 'compare-rev2', |
3447 | 3447 | 'compare-submit', |
| 3448 | + 'compare-invalid-title', |
| 3449 | + 'compare-title-not-exists', |
| 3450 | + 'compare-revision-not-exists', |
3448 | 3451 | ), |
3449 | 3452 | 'db-error-messages' => array( |
3450 | 3453 | 'dberr-header', |
Index: trunk/phase3/includes/specials/SpecialComparePages.php |
— | — | @@ -57,6 +57,7 @@ |
58 | 58 | 'label-message' => 'compare-page1', |
59 | 59 | 'size' => '40', |
60 | 60 | 'section' => 'page1', |
| 61 | + 'validation-callback' => array( $this, 'checkExistingTitle' ), |
61 | 62 | ), |
62 | 63 | 'Revision1' => array( |
63 | 64 | 'type' => 'int', |
— | — | @@ -64,6 +65,7 @@ |
65 | 66 | 'label-message' => 'compare-rev1', |
66 | 67 | 'size' => '8', |
67 | 68 | 'section' => 'page1', |
| 69 | + 'validation-callback' => array( $this, 'checkExistingRevision' ), |
68 | 70 | ), |
69 | 71 | 'Page2' => array( |
70 | 72 | 'type' => 'text', |
— | — | @@ -71,6 +73,7 @@ |
72 | 74 | 'label-message' => 'compare-page2', |
73 | 75 | 'size' => '40', |
74 | 76 | 'section' => 'page2', |
| 77 | + 'validation-callback' => array( $this, 'checkExistingTitle' ), |
75 | 78 | ), |
76 | 79 | 'Revision2' => array( |
77 | 80 | 'type' => 'int', |
— | — | @@ -78,6 +81,7 @@ |
79 | 82 | 'label-message' => 'compare-rev2', |
80 | 83 | 'size' => '8', |
81 | 84 | 'section' => 'page2', |
| 85 | + 'validation-callback' => array( $this, 'checkExistingRevision' ), |
82 | 86 | ), |
83 | 87 | 'Action' => array( |
84 | 88 | 'type' => 'hidden', |
— | — | @@ -87,16 +91,15 @@ |
88 | 92 | 'type' => 'hidden', |
89 | 93 | 'name' => 'diffonly', |
90 | 94 | ), |
91 | | - ), 'compare' ); |
| 95 | + ), $this->getContext(), 'compare' ); |
92 | 96 | $form->setSubmitText( wfMsg( 'compare-submit' ) ); |
93 | 97 | $form->suppressReset(); |
94 | 98 | $form->setMethod( 'get' ); |
95 | | - $form->setTitle( $this->getTitle() ); |
| 99 | + $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) ); |
96 | 100 | |
97 | 101 | $form->loadData(); |
98 | 102 | $form->displayForm( '' ); |
99 | | - |
100 | | - self::showDiff( $form->mFieldData ); |
| 103 | + $form->trySubmit(); |
101 | 104 | } |
102 | 105 | |
103 | 106 | public static function showDiff( $data ){ |
— | — | @@ -125,4 +128,29 @@ |
126 | 129 | } |
127 | 130 | return null; |
128 | 131 | } |
| 132 | + |
| 133 | + public function checkExistingTitle( $value, $alldata ) { |
| 134 | + if ( $value === '' ) { |
| 135 | + return true; |
| 136 | + } |
| 137 | + $title = Title::newFromText( $value ); |
| 138 | + if ( !$title instanceof Title ) { |
| 139 | + return wfMsgExt( 'compare-invalid-title', 'parse' ); |
| 140 | + } |
| 141 | + if ( !$title->exists() ) { |
| 142 | + return wfMsgExt( 'compare-title-not-exists', 'parse' ); |
| 143 | + } |
| 144 | + return true; |
| 145 | + } |
| 146 | + |
| 147 | + public function checkExistingRevision( $value, $alldata ) { |
| 148 | + if ( $value === '' ) { |
| 149 | + return true; |
| 150 | + } |
| 151 | + $revision = Revision::newFromId( $value ); |
| 152 | + if ( $revision === null ) { |
| 153 | + return wfMsgExt( 'compare-revision-not-exists', 'parse' ); |
| 154 | + } |
| 155 | + return true; |
| 156 | + } |
129 | 157 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -4567,13 +4567,16 @@ |
4568 | 4568 | 'tags-hitcount' => '$1 {{PLURAL:$1|change|changes}}', |
4569 | 4569 | |
4570 | 4570 | # Special:ComparePages |
4571 | | -'comparepages' => 'Compare pages', |
4572 | | -'compare-selector' => 'Compare page revisions', |
4573 | | -'compare-page1' => 'Page 1', |
4574 | | -'compare-page2' => 'Page 2', |
4575 | | -'compare-rev1' => 'Revision 1', |
4576 | | -'compare-rev2' => 'Revision 2', |
4577 | | -'compare-submit' => 'Compare', |
| 4571 | +'comparepages' => 'Compare pages', |
| 4572 | +'compare-selector' => 'Compare page revisions', |
| 4573 | +'compare-page1' => 'Page 1', |
| 4574 | +'compare-page2' => 'Page 2', |
| 4575 | +'compare-rev1' => 'Revision 1', |
| 4576 | +'compare-rev2' => 'Revision 2', |
| 4577 | +'compare-submit' => 'Compare', |
| 4578 | +'compare-invalid-title' => 'The title you specified is invalid.', |
| 4579 | +'compare-title-not-exists' => 'The title you specified does not exist.', |
| 4580 | +'compare-revision-not-exists' => 'The revision you specified does not exist.', |
4578 | 4581 | |
4579 | 4582 | # Database error messages |
4580 | 4583 | 'dberr-header' => 'This wiki has a problem', |