Index: trunk/tools/mwmultiversion/multiversion/MWMultiVersion.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | */ |
43 | 43 | private static function createInstance() { |
44 | 44 | if ( isset( self::$instance ) ) { |
45 | | - die( "MWMultiVersion instance already set!\n" ); |
| 45 | + self::error( "MWMultiVersion instance already set!\n" ); |
46 | 46 | } |
47 | 47 | self::$instance = new self; |
48 | 48 | return self::$instance; |
— | — | @@ -101,7 +101,7 @@ |
102 | 102 | $matches = array(); |
103 | 103 | if ( $secure ) { |
104 | 104 | if ( !preg_match('/^([^.]+)\.([^.]+)\./', $secure, $matches ) ) { |
105 | | - die( "Invalid hostname.\n" ); |
| 105 | + self::error( "Invalid hostname.\n" ); |
106 | 106 | } |
107 | 107 | $lang = $matches[1]; |
108 | 108 | $site = $matches[2]; |
— | — | @@ -126,13 +126,13 @@ |
127 | 127 | } else if ( preg_match( '/^(.*)\.prototype\.wikimedia\.org$/', $serverName, $matches ) ) { |
128 | 128 | $lang = $matches[1]; |
129 | 129 | } else { |
130 | | - die( "Invalid host name ($serverName), can't determine language.\n" ); |
| 130 | + self::error( "Invalid host name ($serverName), can't determine language.\n" ); |
131 | 131 | } |
132 | 132 | } elseif ( preg_match( "/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/", $docRoot, $matches ) ) { |
133 | 133 | $site = "wikipedia"; |
134 | 134 | $lang = $matches[1]; |
135 | 135 | } else { |
136 | | - die( "Invalid host name (docroot=" . $docRoot . "), can't determine language.\n" ); |
| 136 | + self::error( "Invalid host name (docroot=" . $docRoot . "), can't determine language.\n" ); |
137 | 137 | } |
138 | 138 | } |
139 | 139 | $this->loadDBFromSite( $site, $lang ); |
— | — | @@ -145,7 +145,7 @@ |
146 | 146 | private function setSiteInfoForUploadWiki( $pathInfo ) { |
147 | 147 | $pathBits = explode( '/', $pathInfo ); |
148 | 148 | if ( count( $pathBits ) < 3 ) { |
149 | | - die( "Invalid file path info (pathinfo=" . $pathInfo . "), can't determine language.\n" ); |
| 149 | + self::error( "Invalid file path info (pathinfo=" . $pathInfo . "), can't determine language.\n" ); |
150 | 150 | } |
151 | 151 | $site = $pathBits[1]; |
152 | 152 | $lang = $pathBits[2]; |
— | — | @@ -171,7 +171,7 @@ |
172 | 172 | } |
173 | 173 | |
174 | 174 | if ( $dbname === '' ) { |
175 | | - die( "--wiki must be the first parameter.\n" ); |
| 175 | + self::error( "--wiki must be the first parameter.\n" ); |
176 | 176 | } |
177 | 177 | |
178 | 178 | $this->db = $dbname; |
— | — | @@ -217,11 +217,11 @@ |
218 | 218 | $extraVersion = false; |
219 | 219 | } else { |
220 | 220 | if ( strpos( $version, 'php-' ) !== 0 ) { |
221 | | - die( "wikiversions.cdb version entry does not start with `php-` (got `$version`).\n" ); |
| 221 | + self::error( "wikiversions.cdb version entry does not start with `php-` (got `$version`).\n" ); |
222 | 222 | } |
223 | 223 | $extraVersion = dba_fetch( "ext:{$this->db}", $db ); |
224 | 224 | if ( $extraVersion === false ) { |
225 | | - die( "wikiversions.cdb has no extra version entry for `$db`.\n" ); |
| 225 | + self::error( "wikiversions.cdb has no extra version entry for `$db`.\n" ); |
226 | 226 | } |
227 | 227 | } |
228 | 228 | dba_close( $db ); |
— | — | @@ -241,7 +241,7 @@ |
242 | 242 | */ |
243 | 243 | private function assertNotMissing() { |
244 | 244 | if ( $this->isMissing() ) { |
245 | | - die( "wikiversions.cdb has no version entry for `{$this->db}`.\n" ); |
| 245 | + self::error( "wikiversions.cdb has no version entry for `{$this->db}`.\n" ); |
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
— | — | @@ -295,4 +295,17 @@ |
296 | 296 | } |
297 | 297 | return $ver; |
298 | 298 | } |
| 299 | + |
| 300 | + /** |
| 301 | + * Error out with a die() message |
| 302 | + * @param $msg String |
| 303 | + * @return void |
| 304 | + */ |
| 305 | + private static function error( $msg ) { |
| 306 | + $msg = (string)$msg; |
| 307 | + if ( php_sapi_name() !== 'cli' ) { |
| 308 | + $msg = htmlspecialchars( $msg ); |
| 309 | + } |
| 310 | + die( $msg ); |
| 311 | + } |
299 | 312 | } |