* (bug 8136) Introduce 'ArticleUndelete' hook; see docs/hooks.txt for more info
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 * @package MediaWiki
5 */
6
7 /**
8 * This file is not a valid entry point, perform no further processing unless
9 * MEDIAWIKI is defined
10 */
11 if( !defined( 'MEDIAWIKI' ) ) {
12 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
13 exit( 1 );
14 }
15
16 # The main wiki script and things like database
17 # conversion and maintenance scripts all share a
18 # common setup of including lots of classes and
19 # setting up a few globals.
20 #
21
22 $fname = 'Setup.php';
23 wfProfileIn( $fname );
24
25 // Check to see if we are at the file scope
26 if ( !isset( $wgVersion ) ) {
27 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
28 die( 1 );
29 }
30
31 // Set various default paths sensibly...
32 if( $wgScript === false ) $wgScript = "$wgScriptPath/index.php";
33 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect.php";
34
35 if( $wgArticlePath === false ) {
36 if( $wgUsePathInfo ) {
37 $wgArticlePath = "$wgScript/$1";
38 } else {
39 $wgArticlePath = "$wgScript?title=$1";
40 }
41 }
42
43 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
44 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
45
46 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
47
48 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
49 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
50
51 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
52 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
53 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
54
55 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
56 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
57
58 require_once( "$IP/includes/AutoLoader.php" );
59
60 wfProfileIn( $fname.'-exception' );
61 require_once( "$IP/includes/Exception.php" );
62 wfInstallExceptionHandler();
63 wfProfileOut( $fname.'-exception' );
64
65 wfProfileIn( $fname.'-includes' );
66 require_once( "$IP/includes/GlobalFunctions.php" );
67 require_once( "$IP/includes/Hooks.php" );
68 require_once( "$IP/includes/Namespace.php" );
69 require_once( "$IP/includes/ProxyTools.php" );
70 require_once( "$IP/includes/ObjectCache.php" );
71 require_once( "$IP/includes/ImageFunctions.php" );
72 require_once( "$IP/includes/StubObject.php" );
73 wfProfileOut( $fname.'-includes' );
74 wfProfileIn( $fname.'-misc1' );
75
76
77 $wgIP = false; # Load on demand
78 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
79 $wgRequest = new WebRequest;
80 if ( function_exists( 'posix_uname' ) ) {
81 $wguname = posix_uname();
82 $wgNodeName = $wguname['nodename'];
83 } else {
84 $wgNodeName = '';
85 }
86
87 # Useful debug output
88 if ( $wgCommandLineMode ) {
89 wfDebug( "\n\nStart command line script $self\n" );
90 } elseif ( function_exists( 'getallheaders' ) ) {
91 wfDebug( "\n\nStart request\n" );
92 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
93 $headers = getallheaders();
94 foreach ($headers as $name => $value) {
95 wfDebug( "$name: $value\n" );
96 }
97 wfDebug( "\n" );
98 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
99 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
100 }
101
102 if ( $wgSkipSkin ) {
103 $wgSkipSkins[] = $wgSkipSkin;
104 }
105
106 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
107
108 if($wgMetaNamespace === FALSE) {
109 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
110 }
111
112 # These are now the same, always
113 # To determine the user language, use $wgLang->getCode()
114 $wgContLanguageCode = $wgLanguageCode;
115
116 wfProfileOut( $fname.'-misc1' );
117 wfProfileIn( $fname.'-memcached' );
118
119 $wgMemc =& wfGetMainCache();
120 $messageMemc =& wfGetMessageCacheStorage();
121 $parserMemc =& wfGetParserCacheStorage();
122
123 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
124 "\nMessage cache: " . get_class( $messageMemc ) .
125 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
126
127 wfProfileOut( $fname.'-memcached' );
128 wfProfileIn( $fname.'-SetupSession' );
129
130 if ( $wgDBprefix ) {
131 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
132 } elseif ( $wgSharedDB ) {
133 $wgCookiePrefix = $wgSharedDB;
134 } else {
135 $wgCookiePrefix = $wgDBname;
136 }
137
138 # If session.auto_start is there, we can't touch session name
139 #
140 if( !ini_get( 'session.auto_start' ) )
141 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
142
143 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
144 wfIncrStats( 'request_with_session' );
145 wfSetupSession();
146 $wgSessionStarted = true;
147 } else {
148 wfIncrStats( 'request_without_session' );
149 $wgSessionStarted = false;
150 }
151
152 wfProfileOut( $fname.'-SetupSession' );
153 wfProfileIn( $fname.'-globals' );
154
155 if ( !$wgDBservers ) {
156 $wgDBservers = array(array(
157 'host' => $wgDBserver,
158 'user' => $wgDBuser,
159 'password' => $wgDBpassword,
160 'dbname' => $wgDBname,
161 'type' => $wgDBtype,
162 'load' => 1,
163 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
164 ));
165 }
166
167 $wgLoadBalancer = new StubObject( 'wgLoadBalancer', 'LoadBalancer',
168 array( $wgDBservers, false, $wgMasterWaitTimeout, true ) );
169 $wgContLang = new StubContLang;
170 $wgUser = new StubUser;
171 $wgLang = new StubUserLang;
172 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
173 $wgParser = new StubObject( 'wgParser', 'Parser' );
174 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
175 array( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
176
177 wfProfileOut( $fname.'-globals' );
178 wfProfileIn( $fname.'-User' );
179
180 # Skin setup functions
181 # Entries can be added to this variable during the inclusion
182 # of the extension file. Skins can then perform any necessary initialisation.
183 #
184 foreach ( $wgSkinExtensionFunctions as $func ) {
185 call_user_func( $func );
186 }
187
188 if( !is_object( $wgAuth ) ) {
189 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
190 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
191 }
192
193 wfProfileOut( $fname.'-User' );
194
195 wfProfileIn( $fname.'-misc2' );
196
197 $wgDeferredUpdateList = array();
198 $wgPostCommitUpdateList = array();
199
200 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
201 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
202
203 wfSeedRandom();
204
205 # Placeholders in case of DB error
206 $wgTitle = null;
207 $wgArticle = null;
208
209 wfProfileOut( $fname.'-misc2' );
210 wfProfileIn( $fname.'-extensions' );
211
212 # Extension setup functions for extensions other than skins
213 # Entries should be added to this variable during the inclusion
214 # of the extension file. This allows the extension to perform
215 # any necessary initialisation in the fully initialised environment
216 foreach ( $wgExtensionFunctions as $func ) {
217 $profName = $fname.'-extensions-'.strval( $func );
218 wfProfileIn( $profName );
219 call_user_func( $func );
220 wfProfileOut( $profName );
221 }
222
223 // For compatibility
224 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
225 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
226 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
227 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
228
229
230 wfDebug( "Fully initialised\n" );
231 $wgFullyInitialised = true;
232 wfProfileOut( $fname.'-extensions' );
233 wfProfileOut( $fname );
234
235 ?>