MediaWiki REL1_40
MissingExtensionException.php
Go to the documentation of this file.
1<?php
13
14class MissingExtensionException extends Exception {
16 private $isSkin;
18 private $extName = 'unknown';
20 private $path;
22 private $error;
23
28 public function __construct( $path, $error ) {
29 $this->isSkin = substr( $path, -10 ) === "/skin.json";
30 $m = [];
31 preg_match( "!/([^/]*)/[^/]*.json$!", $path, $m );
32 if ( $m ) {
33 $this->extName = $m[1];
34 }
35 $this->path = $path;
36 $this->error = $error;
37
38 parent::__construct( "Error Loading extension. Unable to open file $path: $error" );
39 }
40
48 private function renderHtml() {
49 if ( !headers_sent() ) {
50 HttpStatus::header( 500 );
51 header( 'Content-Type: text/html; charset=UTF-8' );
52 }
53
55
56 try {
57 echo $templateParser->processTemplate(
58 'ExtensionConfigError',
59 [
60 'version' => MW_VERSION,
61 'path' => $this->path,
62 'type' => $this->isSkin ? 'skin' : 'extension',
63 'error' => $this->error,
64 'extName' => $this->extName,
65 'trace' => $this->getTraceAsString(),
66 'mwLogo' => $this->getMWLogo(),
67 ]
68 );
69 } catch ( Exception $e ) {
70 echo 'Error: ' . htmlspecialchars( $e->getMessage() );
71 }
72 }
73
77 private function renderText() {
78 $type = $this->isSkin ? 'skin' : 'extension';
79 echo "Error: The $this->extName $type cannot be loaded. "
80 . "Check that all of its files are installed properly.\n\n";
81 echo $this->getTraceAsString();
82 echo "\n";
83 }
84
90 public function render() {
91 if ( wfIsCli() ) {
92 $this->renderText();
93 } else {
94 $this->renderHtml();
95 }
96 // Make sure that the error gets into logs.
97 // This will also stop execution.
98 trigger_error( $this->getMessage(), E_USER_ERROR );
99 }
100
106 private function getMWLogo() {
107 global $wgResourceBasePath;
108 $suffix = "/resources/assets/mediawiki.png";
109 if ( $wgResourceBasePath !== null ) {
110 // We are early in setup, so we can't rely on this.
111 return $wgResourceBasePath . $suffix;
112 }
113 $path = '/';
114 foreach ( array_filter( explode( '/', $_SERVER['PHP_SELF'] ) ) as $part ) {
115 if ( !preg_match( '/\.php$/', $part ) ) {
116 $path .= "$part/";
117 } else {
118 break;
119 }
120 }
121
122 return $path . $suffix;
123 }
124}
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:36
$templateParser
A BagOStuff object with no objects in it.
render()
Output an error response and exit.
$wgResourceBasePath
Config variable stub for the ResourceBasePath setting, for use by phpdoc and IDEs.