Index: trunk/extensions/VipsScaler/VipsScaler.i18n.php |
— | — | @@ -13,6 +13,13 @@ |
14 | 14 | 'vipsscaler-invalid-file' => 'Invalid file: could not process requested file (does it exist on this wiki?)', |
15 | 15 | 'vipsscaler-invalid-width' => 'You must specify a width (integer > 0)', |
16 | 16 | 'vipsscaler-thumb-error' => 'VIPS could not generate a thumbnail with given parameters', |
| 17 | + |
| 18 | + # Vipscaler test form: |
| 19 | + 'vipsscaler-form-legend' => 'VIPS scaling', |
| 20 | + 'vipsscaler-form-width' => 'Thumbnail width: ', |
| 21 | + 'vipsscaler-form-file' => 'File on this wiki: ', |
| 22 | + 'vipsscaler-form-params' => 'VIPS parameters: ', |
| 23 | + 'vipsscaler-form-submit' => 'Generate thumbnail', |
17 | 24 | ); |
18 | 25 | |
19 | 26 | /** Message documentation (Message documentation) |
— | — | @@ -23,6 +30,13 @@ |
24 | 31 | 'vipsscaler-invalid-file' => 'Error message when SpecialVipsTest was given a non existent or invalid file name', |
25 | 32 | 'vipsscaler-invalid-width' => 'Error message when SpecialVipsTest did not get a valid width parameter', |
26 | 33 | 'vipsscaler-thumb-error' => 'Error message when VIPS did not manage to generate a thumbnail', |
| 34 | + |
| 35 | + # Vipscaler test form: |
| 36 | + 'vipsscaler-form-legend' => 'Special:VipsTest form: legend at top of the form', |
| 37 | + 'vipsscaler-form-width' => 'Special:VipsTest form: label for the width input box', |
| 38 | + 'vipsscaler-form-file' => 'Special:VipsTest form: label for the file input box', |
| 39 | + 'vipsscaler-form-params' => 'Special:VipsTest form: label for the VIPS parameters box', |
| 40 | + 'vipsscaler-form-submit' => 'Special:VipsTest form: submit button text. The page will then attempt to generate a thumbnail with the given parameters.', |
27 | 41 | ); |
28 | 42 | |
29 | 43 | /** Afrikaans (Afrikaans) |
Index: trunk/extensions/VipsScaler/SpecialVipsTest.php |
— | — | @@ -79,18 +79,79 @@ |
80 | 80 | $this->getOutput()->addWikiMsg( 'vipsscaler-thumb-error' ); |
81 | 81 | } |
82 | 82 | |
83 | | - $vipsThumbUrl = $this->makeUrl( $file, $width ); |
84 | | - |
| 83 | + $this->makeUrl( $file, $width ); |
85 | 84 | } |
86 | 85 | |
87 | 86 | /** |
88 | 87 | * TODO |
89 | 88 | */ |
90 | 89 | protected function showForm() { |
| 90 | + $form = new HTMLForm( $this->getFormFields(), $this->getContext() ); |
| 91 | + $form->setWrapperLegend( wfMsg( 'vipsscaler-form-legend' ) ); |
| 92 | + $form->setSubmitText( wfMsg( 'vipsscaler-form-submit' ) ); |
| 93 | + $form->setSubmitCallback( array( __CLASS__, 'processForm' ) ); |
91 | 94 | |
| 95 | + // Looks like HTMLForm does not actually show the form if submission |
| 96 | + // was correct. So we have to show it again. |
| 97 | + // See HTMLForm::show() |
| 98 | + $result = $form->show(); |
| 99 | + if( $result === true or $result instanceof Status && $result->isGood() ) { |
| 100 | + $form->displayForm( $result ); |
| 101 | + } |
92 | 102 | } |
93 | 103 | |
94 | 104 | /** |
| 105 | + * [[Special:VipsTest]] form structure for HTMLForm |
| 106 | + * @return Array A form structure using the HTMLForm system |
| 107 | + */ |
| 108 | + protected function getFormFields() { |
| 109 | + $fields = array( |
| 110 | + 'Width' => array( |
| 111 | + 'name' => 'width', |
| 112 | + 'class' => 'HTMLIntField', |
| 113 | + 'default' => '640', |
| 114 | + 'size' => '5', |
| 115 | + 'required' => true, |
| 116 | + 'label-message' => 'vipsscaler-form-width', |
| 117 | + ), |
| 118 | + 'File' => array( |
| 119 | + 'name' => 'file', |
| 120 | + 'class' => 'HTMLTextField', |
| 121 | + 'required' => true, |
| 122 | + 'label-message' => 'vipsscaler-form-file', |
| 123 | + 'validation-callback' => array( __CLASS__, 'validateFileInput' ), |
| 124 | + ), |
| 125 | + 'Params' => array( |
| 126 | + 'name' => 'params', |
| 127 | + 'class' => 'HTMLTextField', |
| 128 | + 'label-message' => 'vipsscaler-form-params', |
| 129 | + ), |
| 130 | + ); |
| 131 | + return $fields; |
| 132 | + } |
| 133 | + |
| 134 | + public static function validateFileInput( $input, $alldata ) { |
| 135 | + $title = Title::makeTitleSafe( NS_FILE, $input ); |
| 136 | + if( is_null( $title ) ) { |
| 137 | + return wfMsg( 'vipsscaler-invalid-file' ); |
| 138 | + } |
| 139 | + $file = wfFindFile( $title ); # TODO what does it do? |
| 140 | + if ( !$file || !$file->exists() ) { |
| 141 | + return wfMsg( 'vipsscaler-invalid-file' ); |
| 142 | + } |
| 143 | + |
| 144 | + // Looks sane enough. |
| 145 | + return true; |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Process data submitted by the form. |
| 150 | + */ |
| 151 | + public static function processForm( array $data ) { |
| 152 | + return Status::newGood(); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
95 | 156 | * |
96 | 157 | */ |
97 | 158 | protected function streamThumbnail() { |