MediaWiki  1.23.1
checkLanguage.inc
Go to the documentation of this file.
1 <?php
28  protected $code = null;
29  protected $level = 2;
30  protected $doLinks = false;
31  protected $linksPrefix = '';
32  protected $wikiCode = 'en';
33  protected $checkAll = false;
34  protected $output = 'plain';
35  protected $checks = array();
36  protected $L = null;
37 
38  protected $results = array();
39 
40  private $includeExif = false;
41 
46  public function __construct( array $options ) {
47  if ( isset( $options['help'] ) ) {
48  echo $this->help();
49  exit( 1 );
50  }
51 
52  if ( isset( $options['lang'] ) ) {
53  $this->code = $options['lang'];
54  } else {
55  global $wgLanguageCode;
56  $this->code = $wgLanguageCode;
57  }
58 
59  if ( isset( $options['level'] ) ) {
60  $this->level = $options['level'];
61  }
62 
63  $this->doLinks = isset( $options['links'] );
64  $this->includeExif = !isset( $options['noexif'] );
65  $this->checkAll = isset( $options['all'] );
66 
67  if ( isset( $options['prefix'] ) ) {
68  $this->linksPrefix = $options['prefix'];
69  }
70 
71  if ( isset( $options['wikilang'] ) ) {
72  $this->wikiCode = $options['wikilang'];
73  }
74 
75  if ( isset( $options['whitelist'] ) ) {
76  $this->checks = explode( ',', $options['whitelist'] );
77  } elseif ( isset( $options['blacklist'] ) ) {
78  $this->checks = array_diff(
79  isset( $options['easy'] ) ? $this->easyChecks() : $this->defaultChecks(),
80  explode( ',', $options['blacklist'] )
81  );
82  } elseif ( isset( $options['easy'] ) ) {
83  $this->checks = $this->easyChecks();
84  } else {
85  $this->checks = $this->defaultChecks();
86  }
87 
88  if ( isset( $options['output'] ) ) {
89  $this->output = $options['output'];
90  }
91 
92  $this->L = new Languages( $this->includeExif );
93  }
94 
99  protected function defaultChecks() {
100  return array(
101  'untranslated', 'duplicate', 'obsolete', 'variables', 'empty', 'plural',
102  'whitespace', 'xhtml', 'chars', 'links', 'unbalanced', 'namespace',
103  'projecttalk', 'magic', 'magic-old', 'magic-over', 'magic-case',
104  'special', 'special-old',
105  );
106  }
107 
112  protected function nonMessageChecks() {
113  return array(
114  'namespace', 'projecttalk', 'magic', 'magic-old', 'magic-over',
115  'magic-case', 'special', 'special-old',
116  );
117  }
118 
123  protected function easyChecks() {
124  return array(
125  'duplicate', 'obsolete', 'empty', 'whitespace', 'xhtml', 'chars', 'magic-old',
126  'magic-over', 'magic-case', 'special-old',
127  );
128  }
129 
134  protected function getChecks() {
135  return array(
136  'untranslated' => 'getUntranslatedMessages',
137  'duplicate' => 'getDuplicateMessages',
138  'obsolete' => 'getObsoleteMessages',
139  'variables' => 'getMessagesWithMismatchVariables',
140  'plural' => 'getMessagesWithoutPlural',
141  'empty' => 'getEmptyMessages',
142  'whitespace' => 'getMessagesWithWhitespace',
143  'xhtml' => 'getNonXHTMLMessages',
144  'chars' => 'getMessagesWithWrongChars',
145  'links' => 'getMessagesWithDubiousLinks',
146  'unbalanced' => 'getMessagesWithUnbalanced',
147  'namespace' => 'getUntranslatedNamespaces',
148  'projecttalk' => 'getProblematicProjectTalks',
149  'magic' => 'getUntranslatedMagicWords',
150  'magic-old' => 'getObsoleteMagicWords',
151  'magic-over' => 'getOverridingMagicWords',
152  'magic-case' => 'getCaseMismatchMagicWords',
153  'special' => 'getUntraslatedSpecialPages',
154  'special-old' => 'getObsoleteSpecialPages',
155  );
156  }
157 
164  protected function getTotalCount() {
165  return array(
166  'namespace' => array( 'getNamespaceNames', 'en' ),
167  'projecttalk' => null,
168  'magic' => array( 'getMagicWords', 'en' ),
169  'magic-old' => array( 'getMagicWords', null ),
170  'magic-over' => array( 'getMagicWords', null ),
171  'magic-case' => array( 'getMagicWords', null ),
172  'special' => array( 'getSpecialPageAliases', 'en' ),
173  'special-old' => array( 'getSpecialPageAliases', null ),
174  );
175  }
176 
181  protected function getDescriptions() {
182  return array(
183  'untranslated' => '$1 message(s) of $2 are not translated to $3, but exist in en:',
184  'duplicate' => '$1 message(s) of $2 are translated the same in en and $3:',
185  'obsolete' =>
186  '$1 message(s) of $2 do not exist in en or are in the ignore list, but exist in $3:',
187  'variables' => '$1 message(s) of $2 in $3 don\'t match the variables used in en:',
188  'plural' => '$1 message(s) of $2 in $3 don\'t use {{plural}} while en uses:',
189  'empty' => '$1 message(s) of $2 in $3 are empty or -:',
190  'whitespace' => '$1 message(s) of $2 in $3 have trailing whitespace:',
191  'xhtml' => '$1 message(s) of $2 in $3 contain illegal XHTML:',
192  'chars' =>
193  '$1 message(s) of $2 in $3 include hidden chars which should not be used in the messages:',
194  'links' => '$1 message(s) of $2 in $3 have problematic link(s):',
195  'unbalanced' => '$1 message(s) of $2 in $3 have unbalanced {[]}:',
196  'namespace' => '$1 namespace name(s) of $2 are not translated to $3, but exist in en:',
197  'projecttalk' =>
198  '$1 namespace name(s) and alias(es) in $3 are project talk namespaces without the parameter:',
199  'magic' => '$1 magic word(s) of $2 are not translated to $3, but exist in en:',
200  'magic-old' => '$1 magic word(s) of $2 do not exist in en, but exist in $3:',
201  'magic-over' => '$1 magic word(s) of $2 in $3 do not contain the original en word(s):',
202  'magic-case' =>
203  '$1 magic word(s) of $2 in $3 change the case-sensitivity of the original en word:',
204  'special' => '$1 special page alias(es) of $2 are not translated to $3, but exist in en:',
205  'special-old' => '$1 special page alias(es) of $2 do not exist in en, but exist in $3:',
206  );
207  }
208 
213  protected function help() {
214  return <<<ENDS
215 Run this script to check a specific language file, or all of them.
216 Command line settings are in form --parameter[=value].
217 Parameters:
218  --help: Show this help.
219  --lang: Language code (default: the installation default language).
220  --all: Check all customized languages.
221  --level: Show the following display level (default: 2):
222  * 0: Skip the checks (useful for checking syntax).
223  * 1: Show only the stub headers and number of wrong messages, without
224  list of messages.
225  * 2: Show only the headers and the message keys, without the message
226  values.
227  * 3: Show both the headers and the complete messages, with both keys and
228  values.
229  --links: Link the message values (default off).
230  --prefix: prefix to add to links.
231  --wikilang: For the links, what is the content language of the wiki to
232  display the output in (default en).
233  --noexif: Do not check for Exif messages (a bit hard and boring to
234  translate), if you know what they are currently not translated and want
235  to focus on other problems (default off).
236  --whitelist: Do only the following checks (form: code,code).
237  --blacklist: Do not do the following checks (form: code,code).
238  --easy: Do only the easy checks, which can be treated by non-speakers of
239  the language.
240 
241 Check codes (ideally, all of them should result 0; all the checks are executed
242 by default (except language-specific check blacklists in checkLanguage.inc):
243  * untranslated: Messages which are required to translate, but are not
244  translated.
245  * duplicate: Messages which translation equal to fallback.
246  * obsolete: Messages which are untranslatable or do not exist, but are
247  translated.
248  * variables: Messages without variables which should be used, or with
249  variables which should not be used.
250  * empty: Empty messages and messages that contain only -.
251  * whitespace: Messages which have trailing whitespace.
252  * xhtml: Messages which are not well-formed XHTML (checks only few common
253  errors).
254  * chars: Messages with hidden characters.
255  * links: Messages which contains broken links to pages (does not find all).
256  * unbalanced: Messages which contains unequal numbers of opening {[ and
257  closing ]}.
258  * namespace: Namespace names that were not translated.
259  * projecttalk: Namespace names and aliases where the project talk does not
260  contain $1.
261  * magic: Magic words that were not translated.
262  * magic-old: Magic words which do not exist.
263  * magic-over: Magic words that override the original English word.
264  * magic-case: Magic words whose translation changes the case-sensitivity of
265  the original English word.
266  * special: Special page names that were not translated.
267  * special-old: Special page names which do not exist.
268 
269 ENDS;
270  }
271 
275  public function execute() {
276  $this->doChecks();
277  if ( $this->level > 0 ) {
278  switch ( $this->output ) {
279  case 'plain':
280  $this->outputText();
281  break;
282  case 'wiki':
283  $this->outputWiki();
284  break;
285  default:
286  throw new MWException( "Invalid output type $this->output" );
287  }
288  }
289  }
290 
294  protected function doChecks() {
295  $ignoredCodes = array( 'en', 'enRTL' );
296 
297  $this->results = array();
298  # Check the language
299  if ( $this->checkAll ) {
300  foreach ( $this->L->getLanguages() as $language ) {
301  if ( !in_array( $language, $ignoredCodes ) ) {
302  $this->results[$language] = $this->checkLanguage( $language );
303  }
304  }
305  } else {
306  if ( in_array( $this->code, $ignoredCodes ) ) {
307  throw new MWException( "Cannot check code $this->code." );
308  } else {
309  $this->results[$this->code] = $this->checkLanguage( $this->code );
310  }
311  }
312 
314  foreach ( $results as $code => $checks ) {
315  foreach ( $checks as $check => $messages ) {
316  foreach ( $messages as $key => $details ) {
317  if ( $this->isCheckBlacklisted( $check, $code, $key ) ) {
318  unset( $this->results[$code][$check][$key] );
319  }
320  }
321  }
322  }
323  }
324 
329  protected function getCheckBlacklist() {
330  static $blacklist = null;
331 
332  if ( $blacklist !== null ) {
333  return $blacklist;
334  }
335 
336  // @codingStandardsIgnoreStart Ignore that globals should have a "wg" prefix.
338  // @codingStandardsIgnoreEnd
339 
340  $blacklist = $checkBlacklist;
341 
342  wfRunHooks( 'LocalisationChecksBlacklist', array( &$blacklist ) );
343 
344  return $blacklist;
345  }
346 
355  protected function isCheckBlacklisted( $check, $code, $message ) {
356  $blacklist = $this->getCheckBlacklist();
357 
358  foreach ( $blacklist as $item ) {
359  if ( isset( $item['check'] ) && $check !== $item['check'] ) {
360  continue;
361  }
362 
363  if ( isset( $item['code'] ) && !in_array( $code, $item['code'] ) ) {
364  continue;
365  }
366 
367  if ( isset( $item['message'] ) &&
368  ( $message === false || !in_array( $message, $item['message'] ) )
369  ) {
370  continue;
371  }
372 
373  return true;
374  }
375 
376  return false;
377  }
378 
385  protected function checkLanguage( $code ) {
386  # Syntax check only
387  $results = array();
388  if ( $this->level === 0 ) {
389  $this->L->getMessages( $code );
390 
391  return $results;
392  }
393 
394  $checkFunctions = $this->getChecks();
395  foreach ( $this->checks as $check ) {
396  if ( $this->isCheckBlacklisted( $check, $code, false ) ) {
397  $results[$check] = array();
398  continue;
399  }
400 
401  $callback = array( $this->L, $checkFunctions[$check] );
402  if ( !is_callable( $callback ) ) {
403  throw new MWException( "Unkown check $check." );
404  }
405  $results[$check] = call_user_func( $callback, $code );
406  }
407 
408  return $results;
409  }
410 
417  protected function formatKey( $key, $code ) {
418  if ( $this->doLinks ) {
419  $displayKey = ucfirst( $key );
420  if ( $code == $this->wikiCode ) {
421  return "[[{$this->linksPrefix}MediaWiki:$displayKey|$key]]";
422  } else {
423  return "[[{$this->linksPrefix}MediaWiki:$displayKey/$code|$key]]";
424  }
425  } else {
426  return $key;
427  }
428  }
429 
433  protected function outputText() {
434  foreach ( $this->results as $code => $results ) {
435  $translated = $this->L->getMessages( $code );
436  $translated = count( $translated['translated'] );
437  foreach ( $results as $check => $messages ) {
438  $count = count( $messages );
439  if ( $count ) {
440  if ( $check == 'untranslated' ) {
441  $translatable = $this->L->getGeneralMessages();
442  $total = count( $translatable['translatable'] );
443  } elseif ( in_array( $check, $this->nonMessageChecks() ) ) {
444  $totalCount = $this->getTotalCount();
445  $totalCount = $totalCount[$check];
446  $callback = array( $this->L, $totalCount[0] );
447  $callCode = $totalCount[1] ? $totalCount[1] : $code;
448  $total = count( call_user_func( $callback, $callCode ) );
449  } else {
450  $total = $translated;
451  }
452  $search = array( '$1', '$2', '$3' );
453  $replace = array( $count, $total, $code );
454  $descriptions = $this->getDescriptions();
455  echo "\n" . str_replace( $search, $replace, $descriptions[$check] ) . "\n";
456  if ( $this->level == 1 ) {
457  echo "[messages are hidden]\n";
458  } else {
459  foreach ( $messages as $key => $value ) {
460  if ( !in_array( $check, $this->nonMessageChecks() ) ) {
461  $key = $this->formatKey( $key, $code );
462  }
463  if ( $this->level == 2 || empty( $value ) ) {
464  echo "* $key\n";
465  } else {
466  echo "* $key: '$value'\n";
467  }
468  }
469  }
470  }
471  }
472  }
473  }
474 
478  function outputWiki() {
479  $detailText = '';
480  $rows[] = '! Language !! Code !! Total !! ' .
481  implode( ' !! ', array_diff( $this->checks, $this->nonMessageChecks() ) );
482  foreach ( $this->results as $code => $results ) {
483  $detailTextForLang = "==$code==\n";
484  $numbers = array();
485  $problems = 0;
486  $detailTextForLangChecks = array();
487  foreach ( $results as $check => $messages ) {
488  if ( in_array( $check, $this->nonMessageChecks() ) ) {
489  continue;
490  }
491  $count = count( $messages );
492  if ( $count ) {
493  $problems += $count;
494  $messageDetails = array();
495  foreach ( $messages as $key => $details ) {
496  $displayKey = $this->formatKey( $key, $code );
497  $messageDetails[] = $displayKey;
498  }
499  $detailTextForLangChecks[] = "=== $code-$check ===\n* " . implode( ', ', $messageDetails );
500  $numbers[] = "'''[[#$code-$check|$count]]'''";
501  } else {
502  $numbers[] = $count;
503  }
504  }
505 
506  if ( count( $detailTextForLangChecks ) ) {
507  $detailText .= $detailTextForLang . implode( "\n", $detailTextForLangChecks ) . "\n";
508  }
509 
510  if ( !$problems ) {
511  # Don't list languages without problems
512  continue;
513  }
514  $language = Language::fetchLanguageName( $code );
515  $rows[] = "| $language || $code || $problems || " . implode( ' || ', $numbers );
516  }
517 
518  $tableRows = implode( "\n|-\n", $rows );
519 
521  // @codingStandardsIgnoreStart Long line.
522  echo <<<EOL
523 '''Check results are for:''' <code>$version</code>
524 
525 
526 {| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear: both;"
527 $tableRows
528 |}
529 
530 $detailText
531 
532 EOL;
533  // @codingStandardsIgnoreEnd
534  }
535 
540  protected function isEmpty() {
541  foreach ( $this->results as $results ) {
542  foreach ( $results as $messages ) {
543  if ( !empty( $messages ) ) {
544  return false;
545  }
546  }
547  }
548 
549  return true;
550  }
551 }
552 
556 class CheckExtensionsCLI extends CheckLanguageCLI {
557  private $extensions;
558 
564  public function __construct( array $options, $extension ) {
565  if ( isset( $options['help'] ) ) {
566  echo $this->help();
567  exit( 1 );
568  }
569 
570  if ( isset( $options['lang'] ) ) {
571  $this->code = $options['lang'];
572  } else {
573  global $wgLanguageCode;
574  $this->code = $wgLanguageCode;
575  }
576 
577  if ( isset( $options['level'] ) ) {
578  $this->level = $options['level'];
579  }
580 
581  $this->doLinks = isset( $options['links'] );
582 
583  if ( isset( $options['wikilang'] ) ) {
584  $this->wikiCode = $options['wikilang'];
585  }
586 
587  if ( isset( $options['whitelist'] ) ) {
588  $this->checks = explode( ',', $options['whitelist'] );
589  } elseif ( isset( $options['blacklist'] ) ) {
590  $this->checks = array_diff(
591  isset( $options['easy'] ) ? $this->easyChecks() : $this->defaultChecks(),
592  explode( ',', $options['blacklist'] )
593  );
594  } elseif ( isset( $options['easy'] ) ) {
595  $this->checks = $this->easyChecks();
596  } else {
597  $this->checks = $this->defaultChecks();
598  }
599 
600  if ( isset( $options['output'] ) ) {
601  $this->output = $options['output'];
602  }
603 
604  # Some additional checks not enabled by default
605  if ( isset( $options['duplicate'] ) ) {
606  $this->checks[] = 'duplicate';
607  }
608 
609  $this->extensions = array();
610  $extensions = new PremadeMediawikiExtensionGroups();
611  $extensions->addAll();
612  if ( $extension == 'all' ) {
613  foreach ( MessageGroups::singleton()->getGroups() as $group ) {
614  if ( strpos( $group->getId(), 'ext-' ) === 0 && !$group->isMeta() ) {
615  $this->extensions[] = new ExtensionLanguages( $group );
616  }
617  }
618  } elseif ( $extension == 'wikimedia' ) {
619  $wikimedia = MessageGroups::getGroup( 'ext-0-wikimedia' );
620  foreach ( $wikimedia->wmfextensions() as $extension ) {
621  $group = MessageGroups::getGroup( $extension );
622  $this->extensions[] = new ExtensionLanguages( $group );
623  }
624  } elseif ( $extension == 'flaggedrevs' ) {
625  foreach ( MessageGroups::singleton()->getGroups() as $group ) {
626  if ( strpos( $group->getId(), 'ext-flaggedrevs-' ) === 0 && !$group->isMeta() ) {
627  $this->extensions[] = new ExtensionLanguages( $group );
628  }
629  }
630  } else {
631  $extensions = explode( ',', $extension );
632  foreach ( $extensions as $extension ) {
633  $group = MessageGroups::getGroup( 'ext-' . $extension );
634  if ( $group ) {
635  $extension = new ExtensionLanguages( $group );
636  $this->extensions[] = $extension;
637  } else {
638  print "No such extension $extension.\n";
639  }
640  }
641  }
642  }
643 
648  protected function defaultChecks() {
649  return array(
650  'untranslated', 'duplicate', 'obsolete', 'variables', 'empty', 'plural',
651  'whitespace', 'xhtml', 'chars', 'links', 'unbalanced',
652  );
653  }
654 
659  protected function nonMessageChecks() {
660  return array();
661  }
662 
667  protected function easyChecks() {
668  return array(
669  'duplicate', 'obsolete', 'empty', 'whitespace', 'xhtml', 'chars',
670  );
671  }
672 
677  protected function help() {
678  return <<<ENDS
679 Run this script to check the status of a specific language in extensions, or
680 all of them. Command line settings are in form --parameter[=value], except for
681 the first one.
682 Parameters:
683  * First parameter (mandatory): Extension name, multiple extension names
684  (separated by commas), "all" for all the extensions, "wikimedia" for
685  extensions used by Wikimedia or "flaggedrevs" for all FLaggedRevs
686  extension messages.
687  * lang: Language code (default: the installation default language).
688  * help: Show this help.
689  * level: Show the following display level (default: 2).
690  * links: Link the message values (default off).
691  * wikilang: For the links, what is the content language of the wiki to
692  display the output in (default en).
693  * whitelist: Do only the following checks (form: code,code).
694  * blacklist: Do not perform the following checks (form: code,code).
695  * easy: Do only the easy checks, which can be treated by non-speakers of
696  the language.
697 
698 Check codes (ideally, all of them should result 0; all the checks are executed
699 by default (except language-specific check blacklists in checkLanguage.inc):
700  * untranslated: Messages which are required to translate, but are not
701  translated.
702  * duplicate: Messages which translation equal to fallback.
703  * obsolete: Messages which are untranslatable, but translated.
704  * variables: Messages without variables which should be used, or with
705  variables which should not be used.
706  * empty: Empty messages.
707  * whitespace: Messages which have trailing whitespace.
708  * xhtml: Messages which are not well-formed XHTML (checks only few common
709  errors).
710  * chars: Messages with hidden characters.
711  * links: Messages which contains broken links to pages (does not find all).
712  * unbalanced: Messages which contains unequal numbers of opening {[ and
713  closing ]}.
714 
715 Display levels (default: 2):
716  * 0: Skip the checks (useful for checking syntax).
717  * 1: Show only the stub headers and number of wrong messages, without list
718  of messages.
719  * 2: Show only the headers and the message keys, without the message
720  values.
721  * 3: Show both the headers and the complete messages, with both keys and
722  values.
723 
724 ENDS;
725  }
726 
730  public function execute() {
731  $this->doChecks();
732  }
733 
739  protected function checkLanguage( $code ) {
740  foreach ( $this->extensions as $extension ) {
741  $this->L = $extension;
742  $this->results = array();
743  $this->results[$code] = parent::checkLanguage( $code );
744 
745  if ( !$this->isEmpty() ) {
746  echo $extension->name() . ":\n";
747 
748  if ( $this->level > 0 ) {
749  switch ( $this->output ) {
750  case 'plain':
751  $this->outputText();
752  break;
753  case 'wiki':
754  $this->outputWiki();
755  break;
756  default:
757  throw new MWException( "Invalid output type $this->output" );
758  }
759  }
760 
761  echo "\n";
762  }
763  }
764  }
765 }
766 
767 // Blacklist some checks for some languages or some messages
768 // Possible keys of the sub arrays are: 'check', 'code' and 'message'.
770  array(
771  'check' => 'plural',
772  'code' => array( 'az', 'bo', 'cdo', 'dz', 'id', 'fa', 'gan', 'gan-hans',
773  'gan-hant', 'gn', 'hak', 'hu', 'ja', 'jv', 'ka', 'kk-arab',
774  'kk-cyrl', 'kk-latn', 'km', 'kn', 'ko', 'lzh', 'mn', 'ms',
775  'my', 'sah', 'sq', 'tet', 'th', 'to', 'tr', 'vi', 'wuu', 'xmf',
776  'yo', 'yue', 'zh', 'zh-classical', 'zh-cn', 'zh-hans',
777  'zh-hant', 'zh-hk', 'zh-sg', 'zh-tw', 'zh-yue'
778  ),
779  ),
780  array(
781  'check' => 'chars',
782  'code' => array( 'my' ),
783  ),
784 );
check
in this case you re responsible for computing and outputting the entire conflict i the difference between revisions and your text headers and sections and Diff overridable Default is either copyrightwarning or copyrightwarning2 overridable Default is editpage tos summary such as anonymity and the real check
Definition: hooks.txt:1038
CheckLanguageCLI\$L
$L
Definition: checkLanguage.inc:36
of
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
Definition: globals.txt:10
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
content
per default it will return the text for text based content
Definition: contenthandler.txt:107
CheckLanguageCLI\easyChecks
easyChecks()
Get the checks that can easily be treated by non-speakers of the language.
Definition: checkLanguage.inc:123
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
CheckLanguageCLI\$doLinks
$doLinks
Definition: checkLanguage.inc:30
CheckLanguageCLI\$linksPrefix
$linksPrefix
Definition: checkLanguage.inc:31
wiki
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
Definition: maintenance.txt:1
well
page as well
Definition: All_system_messages.txt:2732
CheckLanguageCLI\help
help()
Get help.
Definition: checkLanguage.inc:213
messages
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. Handler functions that modify $result should generally return false to further attempts at conversion. 'ContribsPager you ll need to handle error messages
Definition: hooks.txt:896
default
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 so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break but it is *strongly *advised not to try any more intrusive changes to get MediaWiki to conform more closely to your filesystem hierarchy Any such attempt will almost certainly result in unnecessary bugs The standard recommended location to install relative to the web is it should be possible to enable the appropriate rewrite rules by default
Definition: distributors.txt:53
$messages
$messages
Definition: LogTests.i18n.php:8
Exif
Class to extract and validate Exif data from jpeg (and possibly tiff) files.
Definition: Exif.php:32
CheckLanguageCLI\$wikiCode
$wikiCode
Definition: checkLanguage.inc:32
CheckLanguageCLI\$code
$code
Definition: checkLanguage.inc:28
CheckLanguageCLI\$output
$output
Definition: checkLanguage.inc:34
pages
The ContentHandler facility adds support for arbitrary content types on wiki pages
Definition: contenthandler.txt:1
CheckExtensionsCLI\checkLanguage
checkLanguage( $code)
Check a language and show the results.
Definition: checkLanguage.inc:674
file
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 we can concentrate it all in an extension file
Definition: hooks.txt:93
CheckExtensionsCLI\execute
execute()
Execute the script.
Definition: checkLanguage.inc:665
CheckLanguageCLI\__construct
__construct(array $options)
Constructor.
Definition: checkLanguage.inc:46
CheckLanguageCLI\outputText
outputText()
Output the checks results as plain text.
Definition: checkLanguage.inc:433
$total
$total
Definition: Utf8Test.php:92
MWException
MediaWiki exception.
Definition: MWException.php:26
CheckExtensionsCLI\nonMessageChecks
nonMessageChecks()
Get the checks which check other things than messages.
Definition: checkLanguage.inc:594
CheckLanguageCLI\getChecks
getChecks()
Get all checks.
Definition: checkLanguage.inc:134
CheckLanguageCLI\outputWiki
outputWiki()
Output the checks results as wiki text.
Definition: checkLanguage.inc:478
project
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the project
Definition: design.txt:70
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
add
An extension or a will often add custom code to the function with or without a global variable For someone wanting email notification when an article is shown may add
Definition: hooks.txt:51
CheckLanguageCLI\defaultChecks
defaultChecks()
Get the default checks.
Definition: checkLanguage.inc:99
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
form
null means default in associative array form
Definition: hooks.txt:1530
CheckLanguageCLI\getCheckBlacklist
getCheckBlacklist()
Get the check blacklist.
Definition: checkLanguage.inc:329
settings
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 MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration settings
Definition: globals.txt:25
CheckExtensionsCLI\help
help()
Get help.
Definition: checkLanguage.inc:612
list
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
Definition: deferred.txt:11
CheckExtensionsCLI\defaultChecks
defaultChecks()
Get the default checks.
Definition: checkLanguage.inc:583
CheckLanguageCLI\getDescriptions
getDescriptions()
Get all check descriptions.
Definition: checkLanguage.inc:181
errors
if the prop value should be in the metadata multi language array can modify can modify indexed by page_id indexed by prefixed DB keys can modify can modify can modify this should be populated with an alert message to that effect to be fed to an HTMLForm object and populate $result with the reason in the form of error messages should be plain text with no special etc to show that they re errors
Definition: hooks.txt:1318
$options
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 & $options
Definition: hooks.txt:1530
CheckLanguageCLI\doChecks
doChecks()
Execute the checks.
Definition: checkLanguage.inc:294
CheckExtensionsCLI
Definition: checkLanguage.inc:491
$value
$value
Definition: styleTest.css.php:45
CheckLanguageCLI
Definition: checkLanguage.inc:27
CheckLanguageCLI\$includeExif
$includeExif
Definition: checkLanguage.inc:40
CheckLanguageCLI\checkLanguage
checkLanguage( $code)
Check a language.
Definition: checkLanguage.inc:385
$version
$version
Definition: parserTests.php:86
following
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default do this many per batch HOW TO WRITE YOUR OWN Make a file in the maintenance directory called myScript php or something In write the following
Definition: maintenance.txt:1
Language\fetchLanguageName
static fetchLanguageName( $code, $inLanguage=null, $include='all')
Definition: Language.php:936
CheckLanguageCLI\isEmpty
isEmpty()
Check if there are any results for the checks, in any language.
Definition: checkLanguage.inc:540
off
Use of locking define a new flag for $wgAntiLockFlags which allows them to be turned off
Definition: database.txt:164
CheckLanguageCLI\formatKey
formatKey( $key, $code)
Format a message key.
Definition: checkLanguage.inc:417
only
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&amp;action=edit&amp;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
Definition: parserTests.txt:396
Special
wiki Special
Definition: All_system_messages.txt:2674
$count
$count
Definition: UtfNormalTest2.php:96
broken
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 broken
Definition: hooks.txt:1530
CheckLanguageCLI\$checks
$checks
Definition: checkLanguage.inc:35
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
Makefile.translate
def translate(text, conv_table)
Definition: Makefile.py:216
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
on
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 on
Definition: hooks.txt:86
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
used
you don t have to do a grep find to see where the $wgReverseTitle variable is used
Definition: hooks.txt:117
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
CheckLanguageCLI\nonMessageChecks
nonMessageChecks()
Get the checks which check other things than messages.
Definition: checkLanguage.inc:112
CheckLanguageCLI\isCheckBlacklisted
isCheckBlacklisted( $check, $code, $message)
Verify whether a check is blacklisted.
Definition: checkLanguage.inc:355
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
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
that
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 then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if that
Definition: deferred.txt:11
code
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a third party developers and administrators to define code that will be run at certain points in the mainline code
Definition: hooks.txt:23
complete
Returning false makes less sense for events where the action is complete
Definition: hooks.txt:198
CheckLanguageCLI\$checkAll
$checkAll
Definition: checkLanguage.inc:33
CheckLanguageCLI\execute
execute()
Execute the script.
Definition: checkLanguage.inc:275
message
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 in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a message
Definition: hooks.txt:1624
were
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 were
Definition: skin.txt:10
headers
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 headers
Definition: design.txt:12
CheckExtensionsCLI\easyChecks
easyChecks()
Get the checks that can easily be treated by non-speakers of the language.
Definition: checkLanguage.inc:602
CheckLanguageCLI\$results
$results
Definition: checkLanguage.inc:38
$checkBlacklist
$checkBlacklist
Definition: checkLanguage.inc:658
Language
Internationalisation code.
Definition: Language.php:74
CheckLanguageCLI\$level
$level
Definition: checkLanguage.inc:29
CheckExtensionsCLI\$extensions
$extensions
Definition: checkLanguage.inc:492
CheckExtensionsCLI\__construct
__construct(array $options, $extension)
Constructor.
Definition: checkLanguage.inc:499
line
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do which work well I also use K &R brace matching style I know that s a religious issue for so if you want to use a style that puts opening braces on the next line
Definition: design.txt:79
SpecialVersion\getVersion
static getVersion( $flags='')
Return a string of the MediaWiki version with SVN revision if available.
Definition: SpecialVersion.php:246
CheckLanguageCLI\getTotalCount
getTotalCount()
Get total count for each check non-messages check.
Definition: checkLanguage.inc:164
page
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
Definition: hooks.txt:1956