r93527 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93526‎ | r93527 | r93528 >
Date:15:03, 30 July 2011
Author:ialex
Status:resolved
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -3444,6 +3444,9 @@
34453445 'compare-rev1',
34463446 'compare-rev2',
34473447 'compare-submit',
 3448+ 'compare-invalid-title',
 3449+ 'compare-title-not-exists',
 3450+ 'compare-revision-not-exists',
34483451 ),
34493452 'db-error-messages' => array(
34503453 'dberr-header',
Index: trunk/phase3/includes/specials/SpecialComparePages.php
@@ -57,6 +57,7 @@
5858 'label-message' => 'compare-page1',
5959 'size' => '40',
6060 'section' => 'page1',
 61+ 'validation-callback' => array( $this, 'checkExistingTitle' ),
6162 ),
6263 'Revision1' => array(
6364 'type' => 'int',
@@ -64,6 +65,7 @@
6566 'label-message' => 'compare-rev1',
6667 'size' => '8',
6768 'section' => 'page1',
 69+ 'validation-callback' => array( $this, 'checkExistingRevision' ),
6870 ),
6971 'Page2' => array(
7072 'type' => 'text',
@@ -71,6 +73,7 @@
7274 'label-message' => 'compare-page2',
7375 'size' => '40',
7476 'section' => 'page2',
 77+ 'validation-callback' => array( $this, 'checkExistingTitle' ),
7578 ),
7679 'Revision2' => array(
7780 'type' => 'int',
@@ -78,6 +81,7 @@
7982 'label-message' => 'compare-rev2',
8083 'size' => '8',
8184 'section' => 'page2',
 85+ 'validation-callback' => array( $this, 'checkExistingRevision' ),
8286 ),
8387 'Action' => array(
8488 'type' => 'hidden',
@@ -87,16 +91,15 @@
8892 'type' => 'hidden',
8993 'name' => 'diffonly',
9094 ),
91 - ), 'compare' );
 95+ ), $this->getContext(), 'compare' );
9296 $form->setSubmitText( wfMsg( 'compare-submit' ) );
9397 $form->suppressReset();
9498 $form->setMethod( 'get' );
95 - $form->setTitle( $this->getTitle() );
 99+ $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) );
96100
97101 $form->loadData();
98102 $form->displayForm( '' );
99 -
100 - self::showDiff( $form->mFieldData );
 103+ $form->trySubmit();
101104 }
102105
103106 public static function showDiff( $data ){
@@ -125,4 +128,29 @@
126129 }
127130 return null;
128131 }
 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+ }
129157 }
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -4567,13 +4567,16 @@
45684568 'tags-hitcount' => '$1 {{PLURAL:$1|change|changes}}',
45694569
45704570 # 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.',
45784581
45794582 # Database error messages
45804583 'dberr-header' => 'This wiki has a problem',

Follow-up revisions

RevisionCommit summaryAuthorDate
r93559Follow-up r93527: $value can also be null when not setialex20:27, 30 July 2011

Status & tagging log