Go to the documentation of this file.
24 require __DIR__ .
'/../commandLine.inc';
43 $logging = $this->dbw->tableName(
'logging' );
44 $logging_1_10 = $this->dbw->tableName(
'logging_1_10' );
45 $logging_pre_1_10 = $this->dbw->tableName(
'logging_pre_1_10' );
47 if ( $this->dbw->tableExists(
'logging_pre_1_10' ) && !$this->dbw->tableExists(
'logging' ) ) {
48 # Fix previous aborted run
49 echo
"Cleaning up from previous aborted run\n";
50 $this->dbw->query(
"RENAME TABLE $logging_pre_1_10 TO $logging", __METHOD__ );
53 if ( $this->dbw->tableExists(
'logging_pre_1_10' ) ) {
54 echo
"This script has already been run to completion\n";
58 # Create the target table
59 if ( !$this->dbw->tableExists(
'logging_1_10' ) ) {
63 CREATE TABLE $logging_1_10 (
64 -- Log
ID,
for referring to
this specific log entry, probably
for deletion and
such.
65 log_id
int unsigned NOT NULL auto_increment,
70 log_type varbinary(10) NOT NULL
default '',
71 log_action varbinary(10) NOT NULL
default '',
74 log_timestamp binary(14) NOT NULL
default '19700101000000',
77 log_user
int unsigned NOT NULL
default 0,
79 -- Key to the
page affected. Where a
user is the target,
81 log_namespace
int NOT NULL
default 0,
82 log_title varchar(255) binary NOT NULL
default '',
84 -- Freeform
text. Interpreted
as edit history comments.
85 log_comment varchar(255) NOT NULL
default '',
87 -- LF separated
list of miscellaneous parameters
88 log_params blob NOT NULL,
90 -- rev_deleted
for logs
91 log_deleted tinyint
unsigned NOT NULL
default '0',
93 PRIMARY KEY log_id (log_id),
94 KEY type_time (log_type, log_timestamp),
95 KEY user_time (log_user, log_timestamp),
96 KEY page_time (log_namespace, log_title, log_timestamp),
97 KEY times (log_timestamp)
101 echo
"Creating table logging_1_10\n";
102 $this->dbw->query( $sql, __METHOD__ );
105 # Synchronise the tables
106 echo
"Doing initial sync...\n";
107 $this->
sync(
'logging',
'logging_1_10' );
108 echo
"Sync done\n\n";
110 # Rename the old table away
111 echo
"Renaming the old table to $logging_pre_1_10\n";
112 $this->dbw->query(
"RENAME TABLE $logging TO $logging_pre_1_10", __METHOD__ );
114 # Copy remaining old rows
115 # Done before the new table is active so that $copyPos is accurate
116 echo
"Doing final sync...\n";
117 $this->
sync(
'logging_pre_1_10',
'logging_1_10' );
119 # Move the new table in
120 echo
"Moving the new table in...\n";
121 $this->dbw->query(
"RENAME TABLE $logging_1_10 TO $logging", __METHOD__ );
128 function sync( $srcTable, $dstTable ) {
130 $minTs = $this->dbw->selectField( $srcTable,
'MIN(log_timestamp)',
false, __METHOD__ );
135 $maxTs = $this->dbw->selectField( $srcTable,
'MAX(log_timestamp)',
false, __METHOD__ );
136 $copyPos = $this->dbw->selectField( $dstTable,
'MAX(log_timestamp)',
false, __METHOD__ );
140 if ( $copyPos ===
null ) {
143 $percent = ( $copyPosUnix - $minTsUnix ) / ( $maxTsUnix - $minTsUnix ) * 100;
145 printf(
"%s %.2f%%\n", $copyPos, $percent );
147 # Handle all entries with timestamp equal to $copyPos
148 if ( $copyPos !==
null ) {
149 $numRowsCopied += $this->
copyExactMatch( $srcTable, $dstTable, $copyPos );
152 # Now copy a batch of rows
153 if ( $copyPos ===
null ) {
156 $conds =
array(
'log_timestamp > ' . $this->dbw->addQuotes( $copyPos ) );
158 $srcRes = $this->dbw->select( $srcTable,
'*', $conds, __METHOD__,
161 if ( ! $srcRes->numRows() ) {
167 foreach ( $srcRes
as $srcRow ) {
170 $this->dbw->insert( $dstTable,
$batch, __METHOD__ );
171 $numRowsCopied += count(
$batch );
175 echo
"Copied $numRowsCopied rows\n";
180 $srcRes = $this->dbw->select( $srcTable,
'*',
array(
'log_timestamp' => $copyPos ), __METHOD__ );
181 $dstRes = $this->dbw->select( $dstTable,
'*',
array(
'log_timestamp' => $copyPos ), __METHOD__ );
183 if ( $srcRes->numRows() ) {
184 $srcRow = $srcRes->fetchObject();
185 $srcFields = array_keys( (
array)$srcRow );
187 $dstRowsSeen =
array();
189 # Make a hashtable of rows that already exist in the destination
190 foreach ( $dstRes
as $dstRow ) {
191 $reducedDstRow =
array();
192 foreach ( $srcFields
as $field ) {
193 $reducedDstRow[$field] = $dstRow->$field;
195 $hash = md5( serialize( $reducedDstRow ) );
196 $dstRowsSeen[
$hash] =
true;
199 # Copy all the source rows that aren't already in the destination
200 foreach ( $srcRes
as $srcRow ) {
202 if ( !isset( $dstRowsSeen[
$hash] ) ) {
203 $this->dbw->insert( $dstTable, (
array)$srcRow, __METHOD__ );
208 return $numRowsCopied;
occurs before session is loaded can be modified ID
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
when a variable name is used in a it is silently declared as a new masking the global
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Database abstraction object.
published in in Madrid In the first edition of the Vocabolario for was published In in Rotterdam was the Dictionnaire Universel ! html< p > The first monolingual dictionary written in a Romance language was< i > Sebastián Covarrubias</i >< i > Tesoro de la lengua castellana o published in in Madrid In the first edition of the< i > Vocabolario dell< a href="/index.php?title=Accademia_della_Crusca&action=edit&redlink=1" class="new" title="Accademia della Crusca (page does not exist)"> Accademia della Crusca</a ></i > for was published In in Rotterdam was the< i > Dictionnaire Universel</i ></p > ! end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html php< p >< i > foo</i ></p > ! html parsoid< p >< i > foo</i >< b ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! options ! wikitext foo ! html< p >< b >< i > foo</i ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< i ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< b ></b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s family</b ></i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s</b > family</i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo</i ></b >< i > s family</i ></p > !end ! test Italics and ! options ! wikitext this is about foo s family ! html< p >< i > this is about</i > foo< b > s family</b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo s</i > family</b ></p > !end ! test Italicized possessive ! wikitext The s talk page ! html< p > The< i >< a href="/wiki/Main_Page" title="Main Page"> Main Page</a ></i > s talk page</p > ! end ! test Parsoid only
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks & $hash
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
sync( $srcTable, $dstTable)
Copy all rows from $srcTable to $dstTable.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
copyExactMatch( $srcTable, $dstTable, $copyPos)
if the prop value should be in the metadata multi language array format
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
it sets a lot of them automatically from query and such
Maintenance script that upgrade for log_id/log_deleted fields in a replication-safe way.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values my talk page