Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php |
— | — | @@ -59,85 +59,75 @@ |
60 | 60 | * - identify-warnings |
61 | 61 | * - check for running-identify-service |
62 | 62 | */ |
63 | | - function verifyFileHook( $upload, $mime, &$error ) { |
| 63 | + function verifyUpload( $fileName ) { |
64 | 64 | global $wgTiffMaxEmbedFiles, $wgTiffMaxMetaSize, $wgMaxUploadSize, |
65 | 65 | $wgTiffRejectOnError, $wgTiffRejectOnWarning, $wgTiffUseTiffReader, |
66 | 66 | $wgTiffReaderPath, $wgTiffReaderCheckEofForJS; |
67 | 67 | |
68 | | - $tempName = $upload->getTempPath(); |
69 | | - $saveName = $upload->getLocalFile()->getName(); |
70 | | - |
71 | | - if ( $mime != "image/tiff" ) { |
72 | | - # not a tiff file, do not check |
73 | | - wfDebug( __METHOD__ . ": not a tiff file\n" ); |
74 | | - return true; |
75 | | - } |
76 | | - |
77 | 68 | wfLoadExtensionMessages( 'PagedTiffHandler' ); |
| 69 | + $status = Status::newGood(); |
78 | 70 | if ( $wgTiffUseTiffReader ) { |
79 | | - $tr = new TiffReader( $tempName ); |
| 71 | + $tr = new TiffReader( $fileName ); |
80 | 72 | $tr->check(); |
81 | 73 | if ( !$tr->isValidTiff() ) { |
82 | | - $error = array( 'tiff_bad_file' ); |
83 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" ); |
84 | | - return false; |
| 74 | + wfDebug( __METHOD__ . ": bad file\n" ); |
| 75 | + $status->fatal( 'tiff_bad_file' ); |
| 76 | + } else { |
| 77 | + if ( $tr->checkScriptAtEnd( $wgTiffReaderCheckEofForJS ) ) { |
| 78 | + wfDebug( __METHOD__ . ": script detected\n" ); |
| 79 | + $status->fatal( 'tiff_script_detected' ); |
| 80 | + } |
| 81 | + if ( !$tr->checkSize() ) { |
| 82 | + wfDebug( __METHOD__ . ": size error\n" ); |
| 83 | + $status->fatal( 'tiff_size_error' ); |
| 84 | + } |
85 | 85 | } |
86 | | - if ( $tr->checkScriptAtEnd( $wgTiffReaderCheckEofForJS ) ) { |
87 | | - $error = array( 'tiff_script_detected' ); |
88 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" ); |
89 | | - return false; |
90 | | - } |
91 | | - if ( !$tr->checkSize() ) { |
92 | | - $error = array( 'tiff_size_error' ); |
93 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" ); |
94 | | - return false; |
95 | | - } |
96 | 86 | } |
97 | | - $meta = self::getTiffImage( false, $tempName )->retrieveMetaData(); |
| 87 | + $meta = self::getTiffImage( false, $fileName )->retrieveMetaData(); |
98 | 88 | if ( !$meta ) { |
99 | | - $error = array( 'tiff_out_of_service' ); |
100 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" ); |
101 | | - return false; |
102 | | - } |
| 89 | + wfDebug( __METHOD__ . ": unable to retreive metadata\n" ); |
| 90 | + $status->fatal( 'tiff_out_of_service' ); |
| 91 | + } else { |
| 92 | + $error = false; |
| 93 | + $ok = self::verifyMetaData( $meta, $error ); |
103 | 94 | |
104 | | - $ok = self::verifyMetaData( $meta, $error, $saveName ); |
105 | | - |
106 | | - if ( !$ok ) { |
107 | | - wfDebug( __METHOD__ . ": file is ok ($saveName)\n" ); |
| 95 | + if ( !$ok ) { |
| 96 | + call_user_func_array( array( $status, 'fatal' ), $error ); |
| 97 | + } |
108 | 98 | } |
109 | 99 | |
110 | | - return $ok; |
| 100 | + return $status; |
111 | 101 | } |
112 | 102 | |
113 | | - static function verifyMetaData( $meta, &$error, $saveName = '' ) { |
| 103 | + static function verifyMetaData( $meta, &$error ) { |
114 | 104 | global $wgTiffMaxEmbedFiles, $wgTiffMaxMetaSize; |
115 | 105 | |
116 | 106 | $errors = PagedTiffHandler::getMetadataErrors( $meta ); |
117 | 107 | if ( $errors ) { |
118 | 108 | $error = array( 'tiff_bad_file', PagedTiffHandler::joinMessages( $errors ) ); |
119 | 109 | |
120 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName) " . PagedTiffHandler::joinMessages( $errors, false ) . "\n" ); |
| 110 | + wfDebug( __METHOD__ . ": {$error[0]} " . PagedTiffHandler::joinMessages( $errors, false ) . "\n" ); |
121 | 111 | return false; |
122 | 112 | } |
123 | 113 | |
124 | 114 | if ( $meta['page_amount'] <= 0 || empty( $meta['page_data'] ) ) { |
125 | 115 | $error = array( 'tiff_page_error', $meta['page_amount'] ); |
126 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" ); |
| 116 | + wfDebug( __METHOD__ . ": {$error[0]}\n" ); |
127 | 117 | return false; |
128 | 118 | } |
129 | 119 | if ( $wgTiffMaxEmbedFiles && $meta['page_amount'] > $wgTiffMaxEmbedFiles ) { |
130 | 120 | $error = array( 'tiff_too_much_embed_files', $meta['page_amount'], $wgTiffMaxEmbedFiles ); |
131 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" ); |
| 121 | + wfDebug( __METHOD__ . ": {$error[0]}\n" ); |
132 | 122 | return false; |
133 | 123 | } |
134 | 124 | $len = strlen( serialize( $meta ) ); |
135 | 125 | if ( ( $len + 1 ) > $wgTiffMaxMetaSize ) { |
136 | 126 | $error = array( 'tiff_too_much_meta', $len, $wgTiffMaxMetaSize ); |
137 | | - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" ); |
| 127 | + wfDebug( __METHOD__ . ": {$error[0]}\n" ); |
138 | 128 | return false; |
139 | 129 | } |
140 | 130 | |
141 | | - wfDebug( __METHOD__ . ": metadata is ok ($saveName)\n" ); |
| 131 | + wfDebug( __METHOD__ . ": metadata is ok\n" ); |
142 | 132 | return true; |
143 | 133 | } |
144 | 134 | |