Go to the documentation of this file.
73 MediaWikiServices::getInstance()->getInterwikiLookup();
86 if ( $this->
language->needsGenderDistinction() &&
90 $gender = $this->genderCache->getGenderOf( $text, __METHOD__ );
91 $name = $this->
language->getGenderNsText( $namespace, $gender );
96 if (
$name ===
false ) {
97 throw new InvalidArgumentException(
'Unknown namespace ID: ' . $namespace );
115 public function formatTitle( $namespace, $text, $fragment =
'', $interwiki =
'' ) {
116 if ( $namespace !==
false ) {
121 }
catch ( InvalidArgumentException
$e ) {
125 if ( $namespace !== 0 ) {
126 $text = $nsName .
':' . $text;
130 if ( $fragment !==
'' ) {
131 $text = $text .
'#' . $fragment;
134 if ( $interwiki !==
'' ) {
135 $text = $interwiki .
':' . $text;
138 $text = str_replace(
'_',
' ', $text );
160 if ( $parts[
'dbkey'] ===
'' ) {
217 }
catch ( InvalidArgumentException
$e ) {
222 $key .= $nsName .
':';
227 return strtr( $key,
' ',
'_' );
267 $dbkey = str_replace(
' ',
'_', $text );
272 'local_interwiki' =>
false,
274 'namespace' => $defaultNamespace,
276 'user_case_dbkey' => $dbkey,
279 # Strip Unicode bidi override characters.
280 # Sometimes they slip into cut-n-pasted page titles, where the
281 # override chars get included in list displays.
282 $dbkey = preg_replace(
'/\xE2\x80[\x8E\x8F\xAA-\xAE]/S',
'', $dbkey );
284 # Clean up whitespace
285 # Note: use of the /u option on preg_replace here will cause
286 # input with invalid UTF-8 sequences to be nullified out in PHP 5.2.x,
287 # conveniently disabling them.
288 $dbkey = preg_replace(
289 '/[ _\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u',
293 $dbkey = trim( $dbkey,
'_' );
296 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
300 $parts[
'dbkey'] = $dbkey;
302 # Initial colon indicates main namespace rather than specified default
303 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
304 if ( $dbkey !==
'' && $dbkey[0] ==
':' ) {
306 $dbkey = substr( $dbkey, 1 ); #
remove the colon but
continue processing
307 $dbkey = trim( $dbkey,
'_' ); #
remove any subsequent whitespace
310 if ( $dbkey ==
'' ) {
314 # Namespace or interwiki prefix
315 $prefixRegexp =
"/^(.+?)_*:_*(.*)$/S";
318 if ( preg_match( $prefixRegexp, $dbkey, $m ) ) {
320 $ns = $this->
language->getNsIndex( $p );
321 if ( $ns !==
false ) {
324 $parts[
'namespace'] = $ns;
325 # For Talk:X pages, check if X has a "namespace" prefix
326 if ( $ns ==
NS_TALK && preg_match( $prefixRegexp, $dbkey, $x ) ) {
327 if ( $this->
language->getNsIndex( $x[1] ) ) {
328 # Disallow Talk:File:x type titles...
330 } elseif ( $this->interwikiLookup->isValidInterwiki( $x[1] ) ) {
331 # Disallow Talk:Interwiki:x type titles...
335 } elseif ( $this->interwikiLookup->isValidInterwiki( $p ) ) {
338 $parts[
'interwiki'] = $this->
language->lc( $p );
340 # Redundant interwiki prefix to the local wiki
341 foreach ( $this->localInterwikis
as $localIW ) {
342 if ( 0 == strcasecmp( $parts[
'interwiki'], $localIW ) ) {
343 if ( $dbkey ==
'' ) {
344 # Empty self-links should point to the Main Page, to ensure
345 # compatibility with cross-wiki transclusions and the like.
348 'interwiki' => $mainPage->getInterwiki(),
349 'local_interwiki' =>
true,
350 'fragment' => $mainPage->getFragment(),
351 'namespace' => $mainPage->getNamespace(),
352 'dbkey' => $mainPage->getDBkey(),
353 'user_case_dbkey' => $mainPage->getUserCaseDBKey()
356 $parts[
'interwiki'] =
'';
357 # local interwikis should behave like initial-colon links
358 $parts[
'local_interwiki'] =
true;
360 # Do another namespace split...
365 # If there's an initial colon after the interwiki, that also
366 # resets the default namespace
367 if ( $dbkey !==
'' && $dbkey[0] ==
':' ) {
369 $dbkey = substr( $dbkey, 1 );
370 $dbkey = trim( $dbkey,
'_' );
373 # If there's no recognized interwiki or namespace,
374 # then let the colon expression be part of the title.
379 $fragment = strstr( $dbkey,
'#' );
380 if (
false !== $fragment ) {
381 $parts[
'fragment'] = str_replace(
'_',
' ', substr( $fragment, 1 ) );
382 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
383 # remove whitespace again: prevents "Foo_bar_#"
384 # becoming "Foo_bar_"
385 $dbkey = preg_replace(
'/_*$/',
'', $dbkey );
388 # Reject illegal characters.
391 if ( preg_match( $rxTc, $dbkey,
$matches ) ) {
395 # Pages with "/./" or "/../" appearing in the URLs will often be un-
396 # reachable due to the way web browsers deal with 'relative' URLs.
397 # Also, they conflict with subpage syntax. Forbid them explicitly.
399 strpos( $dbkey,
'.' ) !==
false &&
401 $dbkey ===
'.' || $dbkey ===
'..' ||
402 strpos( $dbkey,
'./' ) === 0 ||
403 strpos( $dbkey,
'../' ) === 0 ||
404 strpos( $dbkey,
'/./' ) !==
false ||
405 strpos( $dbkey,
'/../' ) !==
false ||
406 substr( $dbkey, -2 ) ==
'/.' ||
407 substr( $dbkey, -3 ) ==
'/..'
413 # Magic tilde sequences? Nu-uh!
414 if ( strpos( $dbkey,
'~~~' ) !==
false ) {
418 # Limit the size of titles to 255 bytes. This is typically the size of the
419 # underlying database field. We make an exception for special pages, which
420 # don't need to be stored in the database, and may edge over 255 bytes due
421 # to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
422 $maxLength = ( $parts[
'namespace'] !=
NS_SPECIAL ) ? 255 : 512;
423 if ( strlen( $dbkey ) > $maxLength ) {
425 [ Message::numParam( $maxLength ) ] );
428 # Normally, all wiki links are forced to have an initial capital letter so [[foo]]
429 # and [[Foo]] point to the same place. Don't force it for interwikis, since the
430 # other site might be case-sensitive.
431 $parts[
'user_case_dbkey'] = $dbkey;
432 if ( $parts[
'interwiki'] ===
'' ) {
436 # Can't make a link to a namespace alone... "empty" local links can only be
437 # self-links with a fragment identifier.
438 if ( $dbkey ==
'' && $parts[
'interwiki'] ===
'' ) {
439 if ( $parts[
'namespace'] !=
NS_MAIN ) {
455 if ( $dbkey !==
'' &&
':' == $dbkey[0] ) {
460 $parts[
'dbkey'] = $dbkey;
475 static $rxTc =
false;
477 # Matching titles will be held as illegal.
479 # Any character
not allowed
is forbidden...
481 #
URL percent encoding sequences interfere with the ability
482 # to round-trip titles -- you can't link to them consistently.
484 # XML/HTML character references produce similar issues.
485 '|&[A-Za-z0-9\x80-\xff]+;' .
487 '|&#x[0-9A-Fa-f]+;' .
static hasGenderDistinction( $index)
Does the namespace (potentially) have different aliases for different genders.
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
static newMainPage()
Create a new Title for the Main Page.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Caches user genders when needed to use correct namespace aliases.
Allows to change the fields on the form that will be generated $name
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after processing
namespace and then decline to actually register it file or subcat img or subcat $title
Unicode normalization routines for working with UTF-8 strings.
A title parser service for MediaWiki.
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 URL
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of either verbatim or with modifications and or translated into another language(Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
static capitalize( $text, $ns=NS_MAIN)
Capitalize a text string for a title if it belongs to a namespace that capitalizes.
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
static legalChars()
Get a regex character class describing the legal characters in a link.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Internationalisation code.
the array() calling protocol came about after MediaWiki 1.4rc1.
Represents a page (or page fragment) title within MediaWiki.