MediaWiki  1.23.0
HtmlTest.php
Go to the documentation of this file.
1 <?php
4 class HtmlTest extends MediaWikiTestCase {
5 
6  protected function setUp() {
7  parent::setUp();
8 
9  $langCode = 'en';
10  $langObj = Language::factory( $langCode );
11 
12  // Hardcode namespaces during test runs,
13  // so that html output based on existing namespaces
14  // can be properly evaluated.
15  $langObj->setNamespaces( array(
16  -2 => 'Media',
17  -1 => 'Special',
18  0 => '',
19  1 => 'Talk',
20  2 => 'User',
21  3 => 'User_talk',
22  4 => 'MyWiki',
23  5 => 'MyWiki_Talk',
24  6 => 'File',
25  7 => 'File_talk',
26  8 => 'MediaWiki',
27  9 => 'MediaWiki_talk',
28  10 => 'Template',
29  11 => 'Template_talk',
30  14 => 'Category',
31  15 => 'Category_talk',
32  100 => 'Custom',
33  101 => 'Custom_talk',
34  ) );
35 
36  $this->setMwGlobals( array(
37  'wgLanguageCode' => $langCode,
38  'wgContLang' => $langObj,
39  'wgLang' => $langObj,
40  'wgWellFormedXml' => false,
41  ) );
42  }
43 
47  public function testElementBasics() {
48  $this->assertEquals(
49  '<img>',
50  Html::element( 'img', null, '' ),
51  'No close tag for short-tag elements'
52  );
53 
54  $this->assertEquals(
55  '<element></element>',
56  Html::element( 'element', null, null ),
57  'Close tag for empty element (null, null)'
58  );
59 
60  $this->assertEquals(
61  '<element></element>',
62  Html::element( 'element', array(), '' ),
63  'Close tag for empty element (array, string)'
64  );
65 
66  $this->setMwGlobals( 'wgWellFormedXml', true );
67 
68  $this->assertEquals(
69  '<img />',
70  Html::element( 'img', null, '' ),
71  'Self-closing tag for short-tag elements (wgWellFormedXml = true)'
72  );
73  }
74 
75  public function dataXmlMimeType() {
76  return array(
77  // ( $mimetype, $isXmlMimeType )
78  # HTML is not an XML MimeType
79  array( 'text/html', false ),
80  # XML is an XML MimeType
81  array( 'text/xml', true ),
82  array( 'application/xml', true ),
83  # XHTML is an XML MimeType
84  array( 'application/xhtml+xml', true ),
85  # Make sure other +xml MimeTypes are supported
86  # SVG is another random MimeType even though we don't use it
87  array( 'image/svg+xml', true ),
88  # Complete random other MimeTypes are not XML
89  array( 'text/plain', false ),
90  );
91  }
92 
97  public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
98  $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
99  }
100 
104  public function testExpandAttributesSkipsNullAndFalse() {
105 
106  ### EMPTY ########
107  $this->assertEmpty(
108  Html::expandAttributes( array( 'foo' => null ) ),
109  'skip keys with null value'
110  );
111  $this->assertEmpty(
112  Html::expandAttributes( array( 'foo' => false ) ),
113  'skip keys with false value'
114  );
115  $this->assertNotEmpty(
116  Html::expandAttributes( array( 'foo' => '' ) ),
117  'keep keys with an empty string'
118  );
119  }
120 
124  public function testExpandAttributesForBooleans() {
125  $this->assertEquals(
126  '',
127  Html::expandAttributes( array( 'selected' => false ) ),
128  'Boolean attributes do not generates output when value is false'
129  );
130  $this->assertEquals(
131  '',
132  Html::expandAttributes( array( 'selected' => null ) ),
133  'Boolean attributes do not generates output when value is null'
134  );
135 
136  $this->assertEquals(
137  ' selected',
138  Html::expandAttributes( array( 'selected' => true ) ),
139  'Boolean attributes have no value when value is true'
140  );
141  $this->assertEquals(
142  ' selected',
143  Html::expandAttributes( array( 'selected' ) ),
144  'Boolean attributes have no value when value is true (passed as numerical array)'
145  );
146 
147  $this->setMwGlobals( 'wgWellFormedXml', true );
148 
149  $this->assertEquals(
150  ' selected=""',
151  Html::expandAttributes( array( 'selected' => true ) ),
152  'Boolean attributes have empty string value when value is true (wgWellFormedXml)'
153  );
154  }
155 
161  public function testExpandAttributesVariousExpansions() {
162  ### NOT EMPTY ####
163  $this->assertEquals(
164  ' empty_string=""',
165  Html::expandAttributes( array( 'empty_string' => '' ) ),
166  'Empty string is always quoted'
167  );
168  $this->assertEquals(
169  ' key=value',
170  Html::expandAttributes( array( 'key' => 'value' ) ),
171  'Simple string value needs no quotes'
172  );
173  $this->assertEquals(
174  ' one=1',
175  Html::expandAttributes( array( 'one' => 1 ) ),
176  'Number 1 value needs no quotes'
177  );
178  $this->assertEquals(
179  ' zero=0',
180  Html::expandAttributes( array( 'zero' => 0 ) ),
181  'Number 0 value needs no quotes'
182  );
183 
184  $this->setMwGlobals( 'wgWellFormedXml', true );
185 
186  $this->assertEquals(
187  ' empty_string=""',
188  Html::expandAttributes( array( 'empty_string' => '' ) ),
189  'Attribute values are always quoted (wgWellFormedXml): Empty string'
190  );
191  $this->assertEquals(
192  ' key="value"',
193  Html::expandAttributes( array( 'key' => 'value' ) ),
194  'Attribute values are always quoted (wgWellFormedXml): Simple string'
195  );
196  $this->assertEquals(
197  ' one="1"',
198  Html::expandAttributes( array( 'one' => 1 ) ),
199  'Attribute values are always quoted (wgWellFormedXml): Number 1'
200  );
201  $this->assertEquals(
202  ' zero="0"',
203  Html::expandAttributes( array( 'zero' => 0 ) ),
204  'Attribute values are always quoted (wgWellFormedXml): Number 0'
205  );
206  }
207 
214  public function testExpandAttributesListValueAttributes() {
215  ### STRING VALUES
216  $this->assertEquals(
217  ' class="redundant spaces here"',
218  Html::expandAttributes( array( 'class' => ' redundant spaces here ' ) ),
219  'Normalization should strip redundant spaces'
220  );
221  $this->assertEquals(
222  ' class="foo bar"',
223  Html::expandAttributes( array( 'class' => 'foo bar foo bar bar' ) ),
224  'Normalization should remove duplicates in string-lists'
225  );
226  ### "EMPTY" ARRAY VALUES
227  $this->assertEquals(
228  ' class=""',
229  Html::expandAttributes( array( 'class' => array() ) ),
230  'Value with an empty array'
231  );
232  $this->assertEquals(
233  ' class=""',
234  Html::expandAttributes( array( 'class' => array( null, '', ' ', ' ' ) ) ),
235  'Array with null, empty string and spaces'
236  );
237  ### NON-EMPTY ARRAY VALUES
238  $this->assertEquals(
239  ' class="foo bar"',
240  Html::expandAttributes( array( 'class' => array(
241  'foo',
242  'bar',
243  'foo',
244  'bar',
245  'bar',
246  ) ) ),
247  'Normalization should remove duplicates in the array'
248  );
249  $this->assertEquals(
250  ' class="foo bar"',
251  Html::expandAttributes( array( 'class' => array(
252  'foo bar',
253  'bar foo',
254  'foo',
255  'bar bar',
256  ) ) ),
257  'Normalization should remove duplicates in string-lists in the array'
258  );
259  }
260 
266  public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
267  $this->assertEquals(
268  ' class="booltrue one"',
269  Html::expandAttributes( array( 'class' => array(
270  'booltrue' => true,
271  'one' => 1,
272 
273  # Method use isset() internally, make sure we do discard
274  # attributes values which have been assigned well known values
275  'emptystring' => '',
276  'boolfalse' => false,
277  'zero' => 0,
278  'null' => null,
279  ) ) )
280  );
281  }
282 
291  public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
292  $this->assertEquals(
293  ' class=""',
294  Html::expandAttributes( array( 'class' => array(
295  'GREEN',
296  'GREEN' => false,
297  'GREEN',
298  ) ) )
299  );
300  }
301 
305  public function testNamespaceSelector() {
306  $this->assertEquals(
307  '<select id=namespace name=namespace>' . "\n" .
308  '<option value=0>(Main)</option>' . "\n" .
309  '<option value=1>Talk</option>' . "\n" .
310  '<option value=2>User</option>' . "\n" .
311  '<option value=3>User talk</option>' . "\n" .
312  '<option value=4>MyWiki</option>' . "\n" .
313  '<option value=5>MyWiki Talk</option>' . "\n" .
314  '<option value=6>File</option>' . "\n" .
315  '<option value=7>File talk</option>' . "\n" .
316  '<option value=8>MediaWiki</option>' . "\n" .
317  '<option value=9>MediaWiki talk</option>' . "\n" .
318  '<option value=10>Template</option>' . "\n" .
319  '<option value=11>Template talk</option>' . "\n" .
320  '<option value=14>Category</option>' . "\n" .
321  '<option value=15>Category talk</option>' . "\n" .
322  '<option value=100>Custom</option>' . "\n" .
323  '<option value=101>Custom talk</option>' . "\n" .
324  '</select>',
325  Html::namespaceSelector(),
326  'Basic namespace selector without custom options'
327  );
328 
329  $this->assertEquals(
330  '<label for=mw-test-namespace>Select a namespace:</label>&#160;' .
331  '<select id=mw-test-namespace name=wpNamespace>' . "\n" .
332  '<option value=all>all</option>' . "\n" .
333  '<option value=0>(Main)</option>' . "\n" .
334  '<option value=1>Talk</option>' . "\n" .
335  '<option value=2 selected>User</option>' . "\n" .
336  '<option value=3>User talk</option>' . "\n" .
337  '<option value=4>MyWiki</option>' . "\n" .
338  '<option value=5>MyWiki Talk</option>' . "\n" .
339  '<option value=6>File</option>' . "\n" .
340  '<option value=7>File talk</option>' . "\n" .
341  '<option value=8>MediaWiki</option>' . "\n" .
342  '<option value=9>MediaWiki talk</option>' . "\n" .
343  '<option value=10>Template</option>' . "\n" .
344  '<option value=11>Template talk</option>' . "\n" .
345  '<option value=14>Category</option>' . "\n" .
346  '<option value=15>Category talk</option>' . "\n" .
347  '<option value=100>Custom</option>' . "\n" .
348  '<option value=101>Custom talk</option>' . "\n" .
349  '</select>',
350  Html::namespaceSelector(
351  array( 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ),
352  array( 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' )
353  ),
354  'Basic namespace selector with custom values'
355  );
356 
357  $this->assertEquals(
358  '<label for=namespace>Select a namespace:</label>&#160;' .
359  '<select id=namespace name=namespace>' . "\n" .
360  '<option value=0>(Main)</option>' . "\n" .
361  '<option value=1>Talk</option>' . "\n" .
362  '<option value=2>User</option>' . "\n" .
363  '<option value=3>User talk</option>' . "\n" .
364  '<option value=4>MyWiki</option>' . "\n" .
365  '<option value=5>MyWiki Talk</option>' . "\n" .
366  '<option value=6>File</option>' . "\n" .
367  '<option value=7>File talk</option>' . "\n" .
368  '<option value=8>MediaWiki</option>' . "\n" .
369  '<option value=9>MediaWiki talk</option>' . "\n" .
370  '<option value=10>Template</option>' . "\n" .
371  '<option value=11>Template talk</option>' . "\n" .
372  '<option value=14>Category</option>' . "\n" .
373  '<option value=15>Category talk</option>' . "\n" .
374  '<option value=100>Custom</option>' . "\n" .
375  '<option value=101>Custom talk</option>' . "\n" .
376  '</select>',
377  Html::namespaceSelector(
378  array( 'label' => 'Select a namespace:' )
379  ),
380  'Basic namespace selector with a custom label but no id attribtue for the <select>'
381  );
382  }
383 
384  public function testCanFilterOutNamespaces() {
385  $this->assertEquals(
386  '<select id=namespace name=namespace>' . "\n" .
387  '<option value=2>User</option>' . "\n" .
388  '<option value=4>MyWiki</option>' . "\n" .
389  '<option value=5>MyWiki Talk</option>' . "\n" .
390  '<option value=6>File</option>' . "\n" .
391  '<option value=7>File talk</option>' . "\n" .
392  '<option value=8>MediaWiki</option>' . "\n" .
393  '<option value=9>MediaWiki talk</option>' . "\n" .
394  '<option value=10>Template</option>' . "\n" .
395  '<option value=11>Template talk</option>' . "\n" .
396  '<option value=14>Category</option>' . "\n" .
397  '<option value=15>Category talk</option>' . "\n" .
398  '</select>',
399  Html::namespaceSelector(
400  array( 'exclude' => array( 0, 1, 3, 100, 101 ) )
401  ),
402  'Namespace selector namespace filtering.'
403  );
404  }
405 
406  public function testCanDisableANamespaces() {
407  $this->assertEquals(
408  '<select id=namespace name=namespace>' . "\n" .
409  '<option disabled value=0>(Main)</option>' . "\n" .
410  '<option disabled value=1>Talk</option>' . "\n" .
411  '<option disabled value=2>User</option>' . "\n" .
412  '<option disabled value=3>User talk</option>' . "\n" .
413  '<option disabled value=4>MyWiki</option>' . "\n" .
414  '<option value=5>MyWiki Talk</option>' . "\n" .
415  '<option value=6>File</option>' . "\n" .
416  '<option value=7>File talk</option>' . "\n" .
417  '<option value=8>MediaWiki</option>' . "\n" .
418  '<option value=9>MediaWiki talk</option>' . "\n" .
419  '<option value=10>Template</option>' . "\n" .
420  '<option value=11>Template talk</option>' . "\n" .
421  '<option value=14>Category</option>' . "\n" .
422  '<option value=15>Category talk</option>' . "\n" .
423  '<option value=100>Custom</option>' . "\n" .
424  '<option value=101>Custom talk</option>' . "\n" .
425  '</select>',
426  Html::namespaceSelector( array(
427  'disable' => array( 0, 1, 2, 3, 4 )
428  ) ),
429  'Namespace selector namespace disabling'
430  );
431  }
432 
437  public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
438  $this->assertEquals(
439  '<input type=' . $HTML5InputType . '>',
440  Html::element( 'input', array( 'type' => $HTML5InputType ) ),
441  'In HTML5, HTML::element() should accept type="' . $HTML5InputType . '"'
442  );
443  }
444 
449  public static function provideHtml5InputTypes() {
450  $types = array(
451  'datetime',
452  'datetime-local',
453  'date',
454  'month',
455  'time',
456  'week',
457  'number',
458  'range',
459  'email',
460  'url',
461  'search',
462  'tel',
463  'color',
464  );
465  $cases = array();
466  foreach ( $types as $type ) {
467  $cases[] = array( $type );
468  }
469 
470  return $cases;
471  }
472 
478  public function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
479  $this->assertEquals( $expected, Html::element( $element, $attribs ), $message );
480  }
481 
482  public static function provideElementsWithAttributesHavingDefaultValues() {
483  # Use cases in a concise format:
484  # <expected>, <element name>, <array of attributes> [, <message>]
485  # Will be mapped to Html::element()
486  $cases = array();
487 
488  ### Generic cases, match $attribDefault static array
489  $cases[] = array( '<area>',
490  'area', array( 'shape' => 'rect' )
491  );
492 
493  $cases[] = array( '<button type=submit></button>',
494  'button', array( 'formaction' => 'GET' )
495  );
496  $cases[] = array( '<button type=submit></button>',
497  'button', array( 'formenctype' => 'application/x-www-form-urlencoded' )
498  );
499 
500  $cases[] = array( '<canvas></canvas>',
501  'canvas', array( 'height' => '150' )
502  );
503  $cases[] = array( '<canvas></canvas>',
504  'canvas', array( 'width' => '300' )
505  );
506  # Also check with numeric values
507  $cases[] = array( '<canvas></canvas>',
508  'canvas', array( 'height' => 150 )
509  );
510  $cases[] = array( '<canvas></canvas>',
511  'canvas', array( 'width' => 300 )
512  );
513 
514  $cases[] = array( '<command>',
515  'command', array( 'type' => 'command' )
516  );
517 
518  $cases[] = array( '<form></form>',
519  'form', array( 'action' => 'GET' )
520  );
521  $cases[] = array( '<form></form>',
522  'form', array( 'autocomplete' => 'on' )
523  );
524  $cases[] = array( '<form></form>',
525  'form', array( 'enctype' => 'application/x-www-form-urlencoded' )
526  );
527 
528  $cases[] = array( '<input>',
529  'input', array( 'formaction' => 'GET' )
530  );
531  $cases[] = array( '<input>',
532  'input', array( 'type' => 'text' )
533  );
534 
535  $cases[] = array( '<keygen>',
536  'keygen', array( 'keytype' => 'rsa' )
537  );
538 
539  $cases[] = array( '<link>',
540  'link', array( 'media' => 'all' )
541  );
542 
543  $cases[] = array( '<menu></menu>',
544  'menu', array( 'type' => 'list' )
545  );
546 
547  $cases[] = array( '<script></script>',
548  'script', array( 'type' => 'text/javascript' )
549  );
550 
551  $cases[] = array( '<style></style>',
552  'style', array( 'media' => 'all' )
553  );
554  $cases[] = array( '<style></style>',
555  'style', array( 'type' => 'text/css' )
556  );
557 
558  $cases[] = array( '<textarea></textarea>',
559  'textarea', array( 'wrap' => 'soft' )
560  );
561 
562  ### SPECIFIC CASES
563 
564  # <link type="text/css">
565  $cases[] = array( '<link>',
566  'link', array( 'type' => 'text/css' )
567  );
568 
569  # <input> specific handling
570  $cases[] = array( '<input type=checkbox>',
571  'input', array( 'type' => 'checkbox', 'value' => 'on' ),
572  'Default value "on" is stripped of checkboxes',
573  );
574  $cases[] = array( '<input type=radio>',
575  'input', array( 'type' => 'radio', 'value' => 'on' ),
576  'Default value "on" is stripped of radio buttons',
577  );
578  $cases[] = array( '<input type=submit value=Submit>',
579  'input', array( 'type' => 'submit', 'value' => 'Submit' ),
580  'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
581  );
582  $cases[] = array( '<input type=color>',
583  'input', array( 'type' => 'color', 'value' => '' ),
584  );
585  $cases[] = array( '<input type=range>',
586  'input', array( 'type' => 'range', 'value' => '' ),
587  );
588 
589  # <button> specific handling
590  # see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
591  $cases[] = array( '<button type=submit></button>',
592  'button', array( 'type' => 'submit' ),
593  'According to standard the default type is "submit". Depending on compatibility mode IE might use "button", instead.',
594  );
595 
596  # <select> specifc handling
597  $cases[] = array( '<select multiple></select>',
598  'select', array( 'size' => '4', 'multiple' => true ),
599  );
600  # .. with numeric value
601  $cases[] = array( '<select multiple></select>',
602  'select', array( 'size' => 4, 'multiple' => true ),
603  );
604  $cases[] = array( '<select></select>',
605  'select', array( 'size' => '1', 'multiple' => false ),
606  );
607  # .. with numeric value
608  $cases[] = array( '<select></select>',
609  'select', array( 'size' => 1, 'multiple' => false ),
610  );
611 
612  # Passing an array as value
613  $cases[] = array( '<a class="css-class-one css-class-two"></a>',
614  'a', array( 'class' => array( 'css-class-one', 'css-class-two' ) ),
615  "dropDefaults accepts values given as an array"
616  );
617 
618  # FIXME: doDropDefault should remove defaults given in an array
619  # Expected should be '<a></a>'
620  $cases[] = array( '<a class=""></a>',
621  'a', array( 'class' => array( '', '' ) ),
622  "dropDefaults accepts values given as an array"
623  );
624 
625  # Craft the Html elements
626  $ret = array();
627  foreach ( $cases as $case ) {
628  $ret[] = array(
629  $case[0],
630  $case[1], $case[2],
631  isset( $case[3] ) ? $case[3] : ''
632  );
633  }
634 
635  return $ret;
636  }
637 
641  public function testFormValidationBlacklist() {
642  $this->assertEmpty(
643  Html::expandAttributes( array( 'min' => 1, 'max' => 100, 'pattern' => 'abc', 'required' => true, 'step' => 2 ) ),
644  'Blacklist form validation attributes.'
645  );
646  $this->assertEquals(
647  ' step=any',
648  Html::expandAttributes( array( 'min' => 1, 'max' => 100, 'pattern' => 'abc', 'required' => true, 'step' => 'any' ) ),
649  'Allow special case "step=any".'
650  );
651  }
652 }
php
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
Definition: skin.txt:62
Template
! article Main Page ! text blah blah ! endarticle !article Template
Definition: parserTests.txt:209
is
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
text
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
Definition: design.txt:12
Category
Category objects are immutable, strictly speaking.
Definition: Category.php:31
$ret
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 & $ret
Definition: hooks.txt:1530
Html\expandAttributes
static expandAttributes( $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
Definition: Html.php:419
key
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
Definition: design.txt:25
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:148
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
MediaWiki
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
options
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing options(say) and put it in one place. Instead of having little title-reversing if-blocks spread all over the codebase in showAnArticle
MediaWikiTestCase\setUp
setUp()
Definition: MediaWikiTestCase.php:187
output
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
in
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning in
Definition: maintenance.txt:1
are
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of and so on Built in content types are
Definition: contenthandler.txt:5
as
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
Definition: distributors.txt:9
though
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being though
Definition: globals.txt:25
values
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition: hooks.txt:177
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
name
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 name
Definition: design.txt:12
select
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 select() and insert() are usually more convenient. They take care of things like table prefixes and escaping for you. If you really need to make your own SQL
$attribs
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 & $attribs
Definition: hooks.txt:1530
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
MediaWiki
The MediaWiki class is the helper class for the index.php entry point.
Definition: Wiki.php:28
$type
$type
Definition: testCompression.php:46