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