Add new parser function {{apiurl}}. Also, add new global $wgApiScript because manuall...
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 */
5
6 /**
7 * This file is not a valid entry point, perform no further processing unless
8 * MEDIAWIKI is defined
9 */
10 if( !defined( 'MEDIAWIKI' ) ) {
11 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
12 exit( 1 );
13 }
14
15 # The main wiki script and things like database
16 # conversion and maintenance scripts all share a
17 # common setup of including lots of classes and
18 # setting up a few globals.
19 #
20
21 $fname = 'Setup.php';
22 wfProfileIn( $fname );
23
24 // Check to see if we are at the file scope
25 if ( !isset( $wgVersion ) ) {
26 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
27 die( 1 );
28 }
29
30 // Set various default paths sensibly...
31 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
32 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
33
34 if( $wgArticlePath === false ) {
35 if( $wgUsePathInfo ) {
36 $wgArticlePath = "$wgScript/$1";
37 } else {
38 $wgArticlePath = "$wgScript?title=$1";
39 }
40 }
41
42 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
43 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
44
45 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
46
47 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
48 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
49
50 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
51 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
52 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
53
54 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
55 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
56 if( $wgApiScript == false ) $wgApiScript = "$wgScriptPath/api$wgScriptExtension";
57
58 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
59 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
60 }
61
62 /**
63 * Initialise $wgLocalFileRepo from backwards-compatible settings
64 */
65 if ( !$wgLocalFileRepo ) {
66 $wgLocalFileRepo = array(
67 'class' => 'LocalRepo',
68 'name' => 'local',
69 'directory' => $wgUploadDirectory,
70 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
71 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
72 'thumbScriptUrl' => $wgThumbnailScriptPath,
73 'transformVia404' => !$wgGenerateThumbnailOnParse,
74 'initialCapital' => $wgCapitalLinks,
75 'deletedDir' => $wgFileStore['deleted']['directory'],
76 'deletedHashLevels' => $wgFileStore['deleted']['hash']
77 );
78 }
79 /**
80 * Initialise shared repo from backwards-compatible settings
81 */
82 if ( $wgUseSharedUploads ) {
83 if ( $wgSharedUploadDBname ) {
84 $wgForeignFileRepos[] = array(
85 'class' => 'ForeignDBRepo',
86 'name' => 'shared',
87 'directory' => $wgSharedUploadDirectory,
88 'url' => $wgSharedUploadPath,
89 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
90 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
91 'transformVia404' => !$wgGenerateThumbnailOnParse,
92 'dbType' => $wgDBtype,
93 'dbServer' => $wgDBserver,
94 'dbUser' => $wgDBuser,
95 'dbPassword' => $wgDBpassword,
96 'dbName' => $wgSharedUploadDBname,
97 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
98 'tablePrefix' => $wgSharedUploadDBprefix,
99 'hasSharedCache' => $wgCacheSharedUploads,
100 'descBaseUrl' => $wgRepositoryBaseUrl,
101 'fetchDescription' => $wgFetchCommonsDescriptions,
102 );
103 } else {
104 $wgForeignFileRepos[] = array(
105 'class' => 'FSRepo',
106 'name' => 'shared',
107 'directory' => $wgSharedUploadDirectory,
108 'url' => $wgSharedUploadPath,
109 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
110 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
111 'transformVia404' => !$wgGenerateThumbnailOnParse,
112 'descBaseUrl' => $wgRepositoryBaseUrl,
113 'fetchDescription' => $wgFetchCommonsDescriptions,
114 );
115 }
116 }
117
118 if ( !class_exists( 'AutoLoader' ) ) {
119 require_once( "$IP/includes/AutoLoader.php" );
120 }
121
122 wfProfileIn( $fname.'-exception' );
123 require_once( "$IP/includes/Exception.php" );
124 wfInstallExceptionHandler();
125 wfProfileOut( $fname.'-exception' );
126
127 wfProfileIn( $fname.'-includes' );
128 require_once( "$IP/includes/GlobalFunctions.php" );
129 require_once( "$IP/includes/Hooks.php" );
130 require_once( "$IP/includes/Namespace.php" );
131 require_once( "$IP/includes/ProxyTools.php" );
132 require_once( "$IP/includes/ObjectCache.php" );
133 require_once( "$IP/includes/ImageFunctions.php" );
134 require_once( "$IP/includes/StubObject.php" );
135 wfProfileOut( $fname.'-includes' );
136 wfProfileIn( $fname.'-misc1' );
137
138
139 $wgIP = false; # Load on demand
140 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
141 $wgRequest = new WebRequest;
142 if ( function_exists( 'posix_uname' ) ) {
143 $wguname = posix_uname();
144 $wgNodeName = $wguname['nodename'];
145 } else {
146 $wgNodeName = '';
147 }
148
149 # Useful debug output
150 if ( $wgCommandLineMode ) {
151 wfDebug( "\n\nStart command line script $self\n" );
152 } elseif ( function_exists( 'getallheaders' ) ) {
153 wfDebug( "\n\nStart request\n" );
154 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
155 $headers = getallheaders();
156 foreach ($headers as $name => $value) {
157 wfDebug( "$name: $value\n" );
158 }
159 wfDebug( "\n" );
160 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
161 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
162 }
163
164 if( $wgRCFilterByAge ) {
165 ## Trim down $wgRCLinkDays so that it only lists links which are valid
166 ## as determined by $wgRCMaxAge.
167 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
168 sort($wgRCLinkDays);
169 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
170 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
171 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
172 break;
173 }
174 }
175 }
176
177 if ( $wgSkipSkin ) {
178 $wgSkipSkins[] = $wgSkipSkin;
179 }
180
181 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
182
183 if($wgMetaNamespace === FALSE) {
184 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
185 }
186
187 # These are now the same, always
188 # To determine the user language, use $wgLang->getCode()
189 $wgContLanguageCode = $wgLanguageCode;
190
191 wfProfileOut( $fname.'-misc1' );
192 wfProfileIn( $fname.'-memcached' );
193
194 $wgMemc =& wfGetMainCache();
195 $messageMemc =& wfGetMessageCacheStorage();
196 $parserMemc =& wfGetParserCacheStorage();
197
198 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
199 "\nMessage cache: " . get_class( $messageMemc ) .
200 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
201
202 wfProfileOut( $fname.'-memcached' );
203 wfProfileIn( $fname.'-SetupSession' );
204
205 # Set default shared prefix
206 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
207
208 if( !$wgCookiePrefix ) {
209 if ( in_array('user', $wgSharedTables) && $wgSharedDB && $wgSharedPrefix ) {
210 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
211 } elseif ( in_array('user', $wgSharedTables) && $wgSharedDB ) {
212 $wgCookiePrefix = $wgSharedDB;
213 } elseif ( $wgDBprefix ) {
214 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
215 } else {
216 $wgCookiePrefix = $wgDBname;
217 }
218 }
219 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
220
221 # If session.auto_start is there, we can't touch session name
222 #
223 if( !wfIniGetBool( 'session.auto_start' ) )
224 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
225
226 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
227 wfIncrStats( 'request_with_session' );
228 wfSetupSession();
229 $wgSessionStarted = true;
230 } else {
231 wfIncrStats( 'request_without_session' );
232 $wgSessionStarted = false;
233 }
234
235 wfProfileOut( $fname.'-SetupSession' );
236 wfProfileIn( $fname.'-globals' );
237
238 $wgContLang = new StubContLang;
239
240 // Now that variant lists may be available...
241 $wgRequest->interpolateTitle();
242
243 $wgUser = new StubUser;
244 $wgLang = new StubUserLang;
245 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
246 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
247
248 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
249 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
250
251 wfProfileOut( $fname.'-globals' );
252 wfProfileIn( $fname.'-User' );
253
254 # Skin setup functions
255 # Entries can be added to this variable during the inclusion
256 # of the extension file. Skins can then perform any necessary initialisation.
257 #
258 foreach ( $wgSkinExtensionFunctions as $func ) {
259 call_user_func( $func );
260 }
261
262 if( !is_object( $wgAuth ) ) {
263 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
264 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
265 }
266
267 wfProfileOut( $fname.'-User' );
268
269 wfProfileIn( $fname.'-misc2' );
270
271 $wgDeferredUpdateList = array();
272 $wgPostCommitUpdateList = array();
273
274 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
275 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
276 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
277 if( $wgAjaxLicensePreview )
278 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
279
280 # Placeholders in case of DB error
281 $wgTitle = null;
282 $wgArticle = null;
283
284 wfProfileOut( $fname.'-misc2' );
285 wfProfileIn( $fname.'-extensions' );
286
287 # Extension setup functions for extensions other than skins
288 # Entries should be added to this variable during the inclusion
289 # of the extension file. This allows the extension to perform
290 # any necessary initialisation in the fully initialised environment
291 foreach ( $wgExtensionFunctions as $func ) {
292 $profName = $fname.'-extensions-'.strval( $func );
293 wfProfileIn( $profName );
294 call_user_func( $func );
295 wfProfileOut( $profName );
296 }
297
298 // For compatibility
299 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
300 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
301 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
302 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
303
304
305 wfDebug( "Fully initialised\n" );
306 $wgFullyInitialised = true;
307 wfProfileOut( $fname.'-extensions' );
308 wfProfileOut( $fname );