All analysis instructions are written in light red, small size 4 italics.
Index.php
//mediawiki program entry
This is the main web entry point for MediaWiki.
Now start to look at the first line of code of the program to determine whether the PHP version is It is 5.3.2 and above. If not, an error message will be reported on the page.
Php code
Next is the more critical code, introduce a PHP file Webstart.php.
Php code
* It does some security checks, starts the profiler and loads the
* configuration, and optionally loads Setup.php depending on whether
* MW_NO_SETUP is defined.
* Setup.php (if loaded) then sets up GlobalFunctions, the AutoLoader,
* and the configuration globals (though not $wgTitle).
WebStart.php
The annotation part of the file is as above, Roughly speaking, the operation performed by this file is to initialize settings for a Web request: perform security checks, enable debugging, and load global variables and constants in the configuration file. Finally, if mediawiki has not been installed, call setup.php to install mediawiki. This file calls Defines.php (constants), LocalSettings.php (configuration file, global variables), and also opens the character buffer here according to the configuration. The callback method is the wfOutputHandler method of OutputHandler.php.Php code
(
ini_get
('register_globals'# points and when $wgOut gets disabled or overridden.
Php code
header(
'X-Content-Type-Options: nosniff');
For IE8 Turn off content sniffing, everyone should ignore this
Php code
function returns the current Unix timestamp and microtime Number of seconds. Php code
define(
'MEDIAWIKI' , true );# Full path to working directory.
apc
.realpath() returns false
# if we don't have permissions on parent directories.
Php code
$IP = getenv('MW_INSTALL_PATH');
if($IP === false ) {
$IPrealpath
(
' .' ) ?: dirname( __DIR__ );$wgRUstart = wfGetRusage() ?:
array();
...
# Start the profiler
if(
file_exists( "$IP/StartProfiler.php" ) ) {
require
"$IP/StartProfiler.php"
;
Mediawiki.php
The MediaWiki class is defined in mediawiki.php. It includes many methods of wiki objects. Then open up memory space for the $mediaWiki object.
Php code
Obtain the request request object and configuration information through the construction method.
Php code
Determine whether AJAX requests are enabled, and if the $action value in the request is ajax, then send the Ajax request to the Ajax dispather processor.
If the user has forceHTTPS set to true, or if the user
// is in a group requiring HTTPS, or if they have the HTTPS
// preference set, redirect them to HTTPS.
// Note: Do this after $wgTitle is setup, otherwise the hooks run from
// isLoggedIn() will do all sorts of weird stuff.
Php code
If forcehttps is set to true and https access is used, redirection processing
Php code
Namespace value
Namespace value meaning | -1 |
Special: |
1 |
Talk: |
2 |
5
|
|
7
|
|
8
|
|
10 |
|
11 |
|
Help: Help_talk: |
14 |
Category: |
15 |
Category_talk: |
16 |
ONLINEPAY |
// Actually do the work of the request and build up any output
Php code
Processing Request job and build output. This method will generate an output object $output. This object has corresponding methods to set different output results.
Php code
The first sentence of the method, I found that the basic method entry in mediawiki has this sentence, and wfProfileOut( __ME appears after it THOD__ ) tracking It is found that after starting the DEBUG mode, print the corresponding data. Enable the printing method and set the $wgDebugLogFile=d:a.txt value in LocationSettings.php. Note: wfProfileIn and wfProfileOut need to appear in pairs, otherwise an error will occur. Moreover, the output sequence of debugging information is: first output the debugging information of the matched pair of wfProfileIn and wfProfileOut, that is, only output the debugging information when wfProfileOut is encountered, not wfProfileIn. .
Php code
Determine whether the request has a print request. If so, mark it in the output object.
Php code
performs checks before initialization through the request object. This is a system hook program and should require a plug-in to implement the BeforeInitialize method. My full-text search found no specific practical examples of this method.
// Check user's permissions to read this page.
// We have to check here to catch special pages etc.
// We will check again in Article::view().
Php code
Determine whether the user has read permission to access the page based on the title. If the permissions are insufficient, construct the item page and return.
// Either all DB and deferred updates should happen or none.
// The later should not be canceled due to client disconnect .
Php code
Function provided by PHP, if set to true, ignores disconnection from the user. PHP will not detect if the user has disconnected until trying to send information to the client.
//Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction
Php code
Things are submitted and rolled back if there is an error.
//Output everything!
Php code
Page output Go to the front page. All data before this sentence does not carry styles. Word code execution will add different skins according to the return data type.
Php code
The above introduces the mediawiki1.24 source code analysis (1), including the content. I hope it will be helpful to friends who are interested in PHP tutorials.