MediaWiki  REL1_31
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 = [];
36  protected $L = null;
37 
38  protected $results = [];
39 
40  private $includeExif = false;
41 
45  public function __construct( array $options ) {
46  if ( isset( $options['help'] ) ) {
47  echo $this->help();
48  exit( 1 );
49  }
50 
51  if ( isset( $options['lang'] ) ) {
52  $this->code = $options['lang'];
53  } else {
55  $this->code = $wgLanguageCode;
56  }
57 
58  if ( isset( $options['level'] ) ) {
59  $this->level = $options['level'];
60  }
61 
62  $this->doLinks = isset( $options['links'] );
63  $this->includeExif = !isset( $options['noexif'] );
64  $this->checkAll = isset( $options['all'] );
65 
66  if ( isset( $options['prefix'] ) ) {
67  $this->linksPrefix = $options['prefix'];
68  }
69 
70  if ( isset( $options['wikilang'] ) ) {
71  $this->wikiCode = $options['wikilang'];
72  }
73 
74  if ( isset( $options['whitelist'] ) ) {
75  $this->checks = explode( ',', $options['whitelist'] );
76  } elseif ( isset( $options['blacklist'] ) ) {
77  $this->checks = array_diff(
78  isset( $options['easy'] ) ? $this->easyChecks() : $this->defaultChecks(),
79  explode( ',', $options['blacklist'] )
80  );
81  } elseif ( isset( $options['easy'] ) ) {
82  $this->checks = $this->easyChecks();
83  } else {
84  $this->checks = $this->defaultChecks();
85  }
86 
87  if ( isset( $options['output'] ) ) {
88  $this->output = $options['output'];
89  }
90 
91  $this->L = new Languages( $this->includeExif );
92  }
93 
98  protected function defaultChecks() {
99  return [
100  'untranslated', 'duplicate', 'obsolete', 'variables', 'empty', 'plural',
101  'whitespace', 'xhtml', 'chars', 'links', 'unbalanced', 'namespace',
102  'projecttalk', 'magic', 'magic-old', 'magic-over', 'magic-case',
103  'special', 'special-old',
104  ];
105  }
106 
111  protected function nonMessageChecks() {
112  return [
113  'namespace', 'projecttalk', 'magic', 'magic-old', 'magic-over',
114  'magic-case', 'special', 'special-old',
115  ];
116  }
117 
122  protected function easyChecks() {
123  return [
124  'duplicate', 'obsolete', 'empty', 'whitespace', 'xhtml', 'chars', 'magic-old',
125  'magic-over', 'magic-case', 'special-old',
126  ];
127  }
128 
133  protected function getChecks() {
134  return [
135  'untranslated' => 'getUntranslatedMessages',
136  'duplicate' => 'getDuplicateMessages',
137  'obsolete' => 'getObsoleteMessages',
138  'variables' => 'getMessagesWithMismatchVariables',
139  'plural' => 'getMessagesWithoutPlural',
140  'empty' => 'getEmptyMessages',
141  'whitespace' => 'getMessagesWithWhitespace',
142  'xhtml' => 'getNonXHTMLMessages',
143  'chars' => 'getMessagesWithWrongChars',
144  'links' => 'getMessagesWithDubiousLinks',
145  'unbalanced' => 'getMessagesWithUnbalanced',
146  'namespace' => 'getUntranslatedNamespaces',
147  'projecttalk' => 'getProblematicProjectTalks',
148  'magic' => 'getUntranslatedMagicWords',
149  'magic-old' => 'getObsoleteMagicWords',
150  'magic-over' => 'getOverridingMagicWords',
151  'magic-case' => 'getCaseMismatchMagicWords',
152  'special' => 'getUntraslatedSpecialPages',
153  'special-old' => 'getObsoleteSpecialPages',
154  ];
155  }
156 
163  protected function getTotalCount() {
164  return [
165  'namespace' => [ 'getNamespaceNames', 'en' ],
166  'projecttalk' => null,
167  'magic' => [ 'getMagicWords', 'en' ],
168  'magic-old' => [ 'getMagicWords', null ],
169  'magic-over' => [ 'getMagicWords', null ],
170  'magic-case' => [ 'getMagicWords', null ],
171  'special' => [ 'getSpecialPageAliases', 'en' ],
172  'special-old' => [ 'getSpecialPageAliases', null ],
173  ];
174  }
175 
180  protected function getDescriptions() {
181  return [
182  'untranslated' => '$1 message(s) of $2 are not translated to $3, but exist in en:',
183  'duplicate' => '$1 message(s) of $2 are translated the same in en and $3:',
184  'obsolete' =>
185  '$1 message(s) of $2 do not exist in en or are in the ignore list, but exist in $3:',
186  'variables' => '$1 message(s) of $2 in $3 don\'t match the variables used in en:',
187  'plural' => '$1 message(s) of $2 in $3 don\'t use {{plural}} while en uses:',
188  'empty' => '$1 message(s) of $2 in $3 are empty or -:',
189  'whitespace' => '$1 message(s) of $2 in $3 have trailing whitespace:',
190  'xhtml' => '$1 message(s) of $2 in $3 contain illegal XHTML:',
191  'chars' =>
192  '$1 message(s) of $2 in $3 include hidden chars which should not be used in the messages:',
193  'links' => '$1 message(s) of $2 in $3 have problematic link(s):',
194  'unbalanced' => '$1 message(s) of $2 in $3 have unbalanced {[]}:',
195  'namespace' => '$1 namespace name(s) of $2 are not translated to $3, but exist in en:',
196  'projecttalk' =>
197  '$1 namespace name(s) and alias(es) in $3 are project talk namespaces without the parameter:',
198  'magic' => '$1 magic word(s) of $2 are not translated to $3, but exist in en:',
199  'magic-old' => '$1 magic word(s) of $2 do not exist in en, but exist in $3:',
200  'magic-over' => '$1 magic word(s) of $2 in $3 do not contain the original en word(s):',
201  'magic-case' =>
202  '$1 magic word(s) of $2 in $3 change the case-sensitivity of the original en word:',
203  'special' => '$1 special page alias(es) of $2 are not translated to $3, but exist in en:',
204  'special-old' => '$1 special page alias(es) of $2 do not exist in en, but exist in $3:',
205  ];
206  }
207 
212  protected function help() {
213  return <<<ENDS
214 Run this script to check a specific language file, or all of them.
215 Command line settings are in form --parameter[=value].
216 Parameters:
217  --help: Show this help.
218  --lang: Language code (default: the installation default language).
219  --all: Check all customized languages.
220  --level: Show the following display level (default: 2):
221  * 0: Skip the checks (useful for checking syntax).
222  * 1: Show only the stub headers and number of wrong messages, without
223  list of messages.
224  * 2: Show only the headers and the message keys, without the message
225  values.
226  * 3: Show both the headers and the complete messages, with both keys and
227  values.
228  --links: Link the message values (default off).
229  --prefix: prefix to add to links.
230  --wikilang: For the links, what is the content language of the wiki to
231  display the output in (default en).
232  --noexif: Do not check for Exif messages (a bit hard and boring to
233  translate), if you know what they are currently not translated and want
234  to focus on other problems (default off).
235  --whitelist: Do only the following checks (form: code,code).
236  --blacklist: Do not do the following checks (form: code,code).
237  --easy: Do only the easy checks, which can be treated by non-speakers of
238  the language.
239 
240 Check codes (ideally, all of them should result 0; all the checks are executed
241 by default (except language-specific check blacklists in checkLanguage.inc):
242  * untranslated: Messages which are required to translate, but are not
243  translated.
244  * duplicate: Messages which translation equal to fallback.
245  * obsolete: Messages which are untranslatable or do not exist, but are
246  translated.
247  * variables: Messages without variables which should be used, or with
248  variables which should not be used.
249  * empty: Empty messages and messages that contain only -.
250  * whitespace: Messages which have trailing whitespace.
251  * xhtml: Messages which are not well-formed XHTML (checks only few common
252  errors).
253  * chars: Messages with hidden characters.
254  * links: Messages which contains broken links to pages (does not find all).
255  * unbalanced: Messages which contains unequal numbers of opening {[ and
256  closing ]}.
257  * namespace: Namespace names that were not translated.
258  * projecttalk: Namespace names and aliases where the project talk does not
259  contain $1.
260  * magic: Magic words that were not translated.
261  * magic-old: Magic words which do not exist.
262  * magic-over: Magic words that override the original English word.
263  * magic-case: Magic words whose translation changes the case-sensitivity of
264  the original English word.
265  * special: Special page names that were not translated.
266  * special-old: Special page names which do not exist.
267 
268 ENDS;
269  }
270 
274  public function execute() {
275  $this->doChecks();
276  if ( $this->level > 0 ) {
277  switch ( $this->output ) {
278  case 'plain':
279  $this->outputText();
280  break;
281  case 'wiki':
282  $this->outputWiki();
283  break;
284  default:
285  throw new MWException( "Invalid output type $this->output" );
286  }
287  }
288  }
289 
293  protected function doChecks() {
294  $ignoredCodes = [ 'en', 'enRTL' ];
295 
296  $this->results = [];
297  # Check the language
298  if ( $this->checkAll ) {
299  foreach ( $this->L->getLanguages() as $language ) {
300  if ( !in_array( $language, $ignoredCodes ) ) {
301  $this->results[$language] = $this->checkLanguage( $language );
302  }
303  }
304  } else {
305  if ( in_array( $this->code, $ignoredCodes ) ) {
306  throw new MWException( "Cannot check code $this->code." );
307  } else {
308  $this->results[$this->code] = $this->checkLanguage( $this->code );
309  }
310  }
311 
313  foreach ( $results as $code => $checks ) {
314  foreach ( $checks as $check => $messages ) {
315  foreach ( $messages as $key => $details ) {
316  if ( $this->isCheckBlacklisted( $check, $code, $key ) ) {
317  unset( $this->results[$code][$check][$key] );
318  }
319  }
320  }
321  }
322  }
323 
328  protected function getCheckBlacklist() {
329  static $blacklist = null;
330 
331  if ( $blacklist !== null ) {
332  return $blacklist;
333  }
334 
335  // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
337 
338  $blacklist = $checkBlacklist;
339 
340  Hooks::run( 'LocalisationChecksBlacklist', [ &$blacklist ] );
341 
342  return $blacklist;
343  }
344 
353  protected function isCheckBlacklisted( $check, $code, $message ) {
354  $blacklist = $this->getCheckBlacklist();
355 
356  foreach ( $blacklist as $item ) {
357  if ( isset( $item['check'] ) && $check !== $item['check'] ) {
358  continue;
359  }
360 
361  if ( isset( $item['code'] ) && !in_array( $code, $item['code'] ) ) {
362  continue;
363  }
364 
365  if ( isset( $item['message'] ) &&
366  ( $message === false || !in_array( $message, $item['message'] ) )
367  ) {
368  continue;
369  }
370 
371  return true;
372  }
373 
374  return false;
375  }
376 
383  protected function checkLanguage( $code ) {
384  # Syntax check only
385  $results = [];
386  if ( $this->level === 0 ) {
387  $this->L->getMessages( $code );
388 
389  return $results;
390  }
391 
392  $checkFunctions = $this->getChecks();
393  foreach ( $this->checks as $check ) {
394  if ( $this->isCheckBlacklisted( $check, $code, false ) ) {
395  $results[$check] = [];
396  continue;
397  }
398 
399  $callback = [ $this->L, $checkFunctions[$check] ];
400  if ( !is_callable( $callback ) ) {
401  throw new MWException( "Unkown check $check." );
402  }
403  $results[$check] = call_user_func( $callback, $code );
404  }
405 
406  return $results;
407  }
408 
415  protected function formatKey( $key, $code ) {
416  if ( $this->doLinks ) {
417  $displayKey = ucfirst( $key );
418  if ( $code == $this->wikiCode ) {
419  return "[[{$this->linksPrefix}MediaWiki:$displayKey|$key]]";
420  } else {
421  return "[[{$this->linksPrefix}MediaWiki:$displayKey/$code|$key]]";
422  }
423  } else {
424  return $key;
425  }
426  }
427 
431  protected function outputText() {
432  foreach ( $this->results as $code => $results ) {
433  $translated = $this->L->getMessages( $code );
434  $translated = count( $translated['translated'] );
435  foreach ( $results as $check => $messages ) {
436  $count = count( $messages );
437  if ( $count ) {
438  if ( $check == 'untranslated' ) {
439  $translatable = $this->L->getGeneralMessages();
440  $total = count( $translatable['translatable'] );
441  } elseif ( in_array( $check, $this->nonMessageChecks() ) ) {
442  $totalCount = $this->getTotalCount();
443  $totalCount = $totalCount[$check];
444  $callback = [ $this->L, $totalCount[0] ];
445  $callCode = $totalCount[1] ? $totalCount[1] : $code;
446  $total = count( call_user_func( $callback, $callCode ) );
447  } else {
448  $total = $translated;
449  }
450  $search = [ '$1', '$2', '$3' ];
451  $replace = [ $count, $total, $code ];
452  $descriptions = $this->getDescriptions();
453  echo "\n" . str_replace( $search, $replace, $descriptions[$check] ) . "\n";
454  if ( $this->level == 1 ) {
455  echo "[messages are hidden]\n";
456  } else {
457  foreach ( $messages as $key => $value ) {
458  if ( !in_array( $check, $this->nonMessageChecks() ) ) {
459  $key = $this->formatKey( $key, $code );
460  }
461  if ( $this->level == 2 || empty( $value ) ) {
462  echo "* $key\n";
463  } else {
464  echo "* $key: '$value'\n";
465  }
466  }
467  }
468  }
469  }
470  }
471  }
472 
476  function outputWiki() {
477  $detailText = '';
478  $rows[] = '! Language !! Code !! Total !! ' .
479  implode( ' !! ', array_diff( $this->checks, $this->nonMessageChecks() ) );
480  foreach ( $this->results as $code => $results ) {
481  $detailTextForLang = "==$code==\n";
482  $numbers = [];
483  $problems = 0;
484  $detailTextForLangChecks = [];
485  foreach ( $results as $check => $messages ) {
486  if ( in_array( $check, $this->nonMessageChecks() ) ) {
487  continue;
488  }
489  $count = count( $messages );
490  if ( $count ) {
491  $problems += $count;
492  $messageDetails = [];
493  foreach ( $messages as $key => $details ) {
494  $displayKey = $this->formatKey( $key, $code );
495  $messageDetails[] = $displayKey;
496  }
497  $detailTextForLangChecks[] = "=== $code-$check ===\n* " . implode( ', ', $messageDetails );
498  $numbers[] = "'''[[#$code-$check|$count]]'''";
499  } else {
500  $numbers[] = $count;
501  }
502  }
503 
504  if ( count( $detailTextForLangChecks ) ) {
505  $detailText .= $detailTextForLang . implode( "\n", $detailTextForLangChecks ) . "\n";
506  }
507 
508  if ( !$problems ) {
509  # Don't list languages without problems
510  continue;
511  }
512  $language = Language::fetchLanguageName( $code );
513  $rows[] = "| $language || $code || $problems || " . implode( ' || ', $numbers );
514  }
515 
516  $tableRows = implode( "\n|-\n", $rows );
517 
518  $version = SpecialVersion::getVersion( 'nodb' );
519  // phpcs:disable Generic.Files.LineLength
520  echo <<<EOL
521 '''Check results are for:''' <code>$version</code>
522 
523 
524 {| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear: both;"
525 $tableRows
526 |}
527 
528 $detailText
529 
530 EOL;
531  // phpcs:enable
532  }
533 
538  protected function isEmpty() {
539  foreach ( $this->results as $results ) {
540  foreach ( $results as $messages ) {
541  if ( !empty( $messages ) ) {
542  return false;
543  }
544  }
545  }
546 
547  return true;
548  }
549 }
550 
555  private $extensions;
556 
561  public function __construct( array $options, $extension ) {
562  if ( isset( $options['help'] ) ) {
563  echo $this->help();
564  exit( 1 );
565  }
566 
567  if ( isset( $options['lang'] ) ) {
568  $this->code = $options['lang'];
569  } else {
571  $this->code = $wgLanguageCode;
572  }
573 
574  if ( isset( $options['level'] ) ) {
575  $this->level = $options['level'];
576  }
577 
578  $this->doLinks = isset( $options['links'] );
579 
580  if ( isset( $options['wikilang'] ) ) {
581  $this->wikiCode = $options['wikilang'];
582  }
583 
584  if ( isset( $options['whitelist'] ) ) {
585  $this->checks = explode( ',', $options['whitelist'] );
586  } elseif ( isset( $options['blacklist'] ) ) {
587  $this->checks = array_diff(
588  isset( $options['easy'] ) ? $this->easyChecks() : $this->defaultChecks(),
589  explode( ',', $options['blacklist'] )
590  );
591  } elseif ( isset( $options['easy'] ) ) {
592  $this->checks = $this->easyChecks();
593  } else {
594  $this->checks = $this->defaultChecks();
595  }
596 
597  if ( isset( $options['output'] ) ) {
598  $this->output = $options['output'];
599  }
600 
601  # Some additional checks not enabled by default
602  if ( isset( $options['duplicate'] ) ) {
603  $this->checks[] = 'duplicate';
604  }
605 
606  $this->extensions = [];
607  $extensions = new PremadeMediawikiExtensionGroups();
608  $extensions->addAll();
609  if ( $extension == 'all' ) {
610  foreach ( MessageGroups::singleton()->getGroups() as $group ) {
611  if ( strpos( $group->getId(), 'ext-' ) === 0 && !$group->isMeta() ) {
612  $this->extensions[] = new ExtensionLanguages( $group );
613  }
614  }
615  } elseif ( $extension == 'wikimedia' ) {
616  $wikimedia = MessageGroups::getGroup( 'ext-0-wikimedia' );
617  foreach ( $wikimedia->wmfextensions() as $extension ) {
618  $group = MessageGroups::getGroup( $extension );
619  $this->extensions[] = new ExtensionLanguages( $group );
620  }
621  } elseif ( $extension == 'flaggedrevs' ) {
622  foreach ( MessageGroups::singleton()->getGroups() as $group ) {
623  if ( strpos( $group->getId(), 'ext-flaggedrevs-' ) === 0 && !$group->isMeta() ) {
624  $this->extensions[] = new ExtensionLanguages( $group );
625  }
626  }
627  } else {
628  $extensions = explode( ',', $extension );
629  foreach ( $extensions as $extension ) {
630  $group = MessageGroups::getGroup( 'ext-' . $extension );
631  if ( $group ) {
632  $extension = new ExtensionLanguages( $group );
633  $this->extensions[] = $extension;
634  } else {
635  print "No such extension $extension.\n";
636  }
637  }
638  }
639  }
640 
645  protected function defaultChecks() {
646  return [
647  'untranslated', 'duplicate', 'obsolete', 'variables', 'empty', 'plural',
648  'whitespace', 'xhtml', 'chars', 'links', 'unbalanced',
649  ];
650  }
651 
656  protected function nonMessageChecks() {
657  return [];
658  }
659 
664  protected function easyChecks() {
665  return [
666  'duplicate', 'obsolete', 'empty', 'whitespace', 'xhtml', 'chars',
667  ];
668  }
669 
674  protected function help() {
675  return <<<ENDS
676 Run this script to check the status of a specific language in extensions, or
677 all of them. Command line settings are in form --parameter[=value], except for
678 the first one.
679 Parameters:
680  * First parameter (mandatory): Extension name, multiple extension names
681  (separated by commas), "all" for all the extensions, "wikimedia" for
682  extensions used by Wikimedia or "flaggedrevs" for all FLaggedRevs
683  extension messages.
684  * lang: Language code (default: the installation default language).
685  * help: Show this help.
686  * level: Show the following display level (default: 2).
687  * links: Link the message values (default off).
688  * wikilang: For the links, what is the content language of the wiki to
689  display the output in (default en).
690  * whitelist: Do only the following checks (form: code,code).
691  * blacklist: Do not perform the following checks (form: code,code).
692  * easy: Do only the easy checks, which can be treated by non-speakers of
693  the language.
694 
695 Check codes (ideally, all of them should result 0; all the checks are executed
696 by default (except language-specific check blacklists in checkLanguage.inc):
697  * untranslated: Messages which are required to translate, but are not
698  translated.
699  * duplicate: Messages which translation equal to fallback.
700  * obsolete: Messages which are untranslatable, but translated.
701  * variables: Messages without variables which should be used, or with
702  variables which should not be used.
703  * empty: Empty messages.
704  * whitespace: Messages which have trailing whitespace.
705  * xhtml: Messages which are not well-formed XHTML (checks only few common
706  errors).
707  * chars: Messages with hidden characters.
708  * links: Messages which contains broken links to pages (does not find all).
709  * unbalanced: Messages which contains unequal numbers of opening {[ and
710  closing ]}.
711 
712 Display levels (default: 2):
713  * 0: Skip the checks (useful for checking syntax).
714  * 1: Show only the stub headers and number of wrong messages, without list
715  of messages.
716  * 2: Show only the headers and the message keys, without the message
717  values.
718  * 3: Show both the headers and the complete messages, with both keys and
719  values.
720 
721 ENDS;
722  }
723 
727  public function execute() {
728  $this->doChecks();
729  }
730 
736  protected function checkLanguage( $code ) {
737  foreach ( $this->extensions as $extension ) {
738  $this->L = $extension;
739  $this->results = [];
740  $this->results[$code] = parent::checkLanguage( $code );
741 
742  if ( !$this->isEmpty() ) {
743  echo $extension->name() . ":\n";
744 
745  if ( $this->level > 0 ) {
746  switch ( $this->output ) {
747  case 'plain':
748  $this->outputText();
749  break;
750  case 'wiki':
751  $this->outputWiki();
752  break;
753  default:
754  throw new MWException( "Invalid output type $this->output" );
755  }
756  }
757 
758  echo "\n";
759  }
760  }
761  }
762 }
763 
764 // Blacklist some checks for some languages or some messages
765 // Possible keys of the sub arrays are: 'check', 'code' and 'message'.
767  [
768  'check' => 'plural',
769  'code' => [ 'az', 'bo', 'cdo', 'dz', 'id', 'fa', 'gan', 'gan-hans',
770  'gan-hant', 'gn', 'hak', 'hu', 'ja', 'jv', 'ka', 'kk-arab',
771  'kk-cyrl', 'kk-latn', 'km', 'kn', 'ko', 'lzh', 'mn', 'ms',
772  'my', 'sah', 'sq', 'tet', 'th', 'to', 'tr', 'vi', 'wuu', 'xmf',
773  'yo', 'yue', 'zh', 'zh-classical', 'zh-cn', 'zh-hans',
774  'zh-hant', 'zh-hk', 'zh-sg', 'zh-tw', 'zh-yue'
775  ],
776  ],
777  [
778  'check' => 'chars',
779  'code' => [ 'my' ],
780  ],
781 ];
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:28
CheckLanguageCLI\$L
$L
Definition: checkLanguage.inc:36
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
$rows
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition: hooks.txt:2783
names
within a display generated by the Derivative if and wherever such third party notices normally appear The contents of the NOTICE file are for informational purposes only and do not modify the License You may add Your own attribution notices within Derivative Works that You alongside or as an addendum to the NOTICE text from the provided that such additional attribution notices cannot be construed as modifying the License You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for or distribution of Your or for any such Derivative Works as a provided Your and distribution of the Work otherwise complies with the conditions stated in this License Submission of Contributions Unless You explicitly state any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this without any additional terms or conditions Notwithstanding the nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions Trademarks This License does not grant permission to use the trade names
Definition: APACHE-LICENSE-2.0.txt:140
CheckLanguageCLI\easyChecks
easyChecks()
Get the checks that can easily be treated by non-speakers of the language.
Definition: checkLanguage.inc:122
array
the array() calling protocol came about after MediaWiki 1.4rc1.
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:27
well
page as well
Definition: All_system_messages.txt:2725
CheckLanguageCLI\help
help()
Get help.
Definition: checkLanguage.inc:212
used
you don t have to do a grep find to see where the $wgReverseTitle variable is used
Definition: hooks.txt:115
page
target page
Definition: All_system_messages.txt:1267
message
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation 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:2163
perform
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed or on behalf the Licensor for the purpose of discussing and improving the but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as Not a Contribution Contributor shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work Grant of Copyright License Subject to the terms and conditions of this each Contributor hereby grants to You a non no royalty irrevocable copyright license to prepare Derivative Works publicly publicly perform
Definition: APACHE-LICENSE-2.0.txt:71
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
php
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
Definition: injection.txt:37
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:736
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:106
CheckExtensionsCLI\execute
execute()
Execute the script.
Definition: checkLanguage.inc:727
CheckLanguageCLI\__construct
__construct(array $options)
Definition: checkLanguage.inc:45
CheckLanguageCLI\outputText
outputText()
Output the checks results as plain text.
Definition: checkLanguage.inc:431
MWException
MediaWiki exception.
Definition: MWException.php:26
messages
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error messages
Definition: hooks.txt:1275
CheckExtensionsCLI\nonMessageChecks
nonMessageChecks()
Get the checks which check other things than messages.
Definition: checkLanguage.inc:656
CheckLanguageCLI\getChecks
getChecks()
Get all checks.
Definition: checkLanguage.inc:133
CheckLanguageCLI\outputWiki
outputWiki()
Output the checks results as wiki text.
Definition: checkLanguage.inc:476
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:72
were
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had 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:25
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:56
CheckLanguageCLI\defaultChecks
defaultChecks()
Get the default checks.
Definition: checkLanguage.inc:98
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
CheckLanguageCLI\getCheckBlacklist
getCheckBlacklist()
Get the check blacklist.
Definition: checkLanguage.inc:328
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:37
by
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed by
Definition: APACHE-LICENSE-2.0.txt:58
CheckExtensionsCLI\help
help()
Get help.
Definition: checkLanguage.inc:674
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:645
them
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing them
Definition: hooks.txt:1018
CheckLanguageCLI\getDescriptions
getDescriptions()
Get all check descriptions.
Definition: checkLanguage.inc:180
errors
the value of this variable comes from LanguageConverter 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:1748
$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:2001
links
This document describes the XML format used to represent information about external sites known to a MediaWiki installation This information about external sites is used to allow inter wiki links
in the order they appear.
Definition: sitelist.txt:3
CheckLanguageCLI\doChecks
doChecks()
Execute the checks.
Definition: checkLanguage.inc:293
SpecialVersion\getVersion
static getVersion( $flags='', $lang=null)
Return a string of the MediaWiki version with Git revision if available.
Definition: SpecialVersion.php:271
ExtensionLanguages
Definition: languages.inc:788
CheckExtensionsCLI
Definition: checkLanguage.inc:554
style
Bar style
Definition: parserTests.txt:192
$value
$value
Definition: styleTest.css.php:45
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 or overridable Default is either copyrightwarning or copyrightwarning2 overridable Default is editpage tos summary such as anonymity and the real check
Definition: hooks.txt:1481
CheckLanguageCLI
Definition: checkLanguage.inc:27
CheckLanguageCLI\$includeExif
$includeExif
Definition: checkLanguage.inc:40
extensions
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 as usual *javascript user provided javascript code *json simple implementation for use by extensions
Definition: contenthandler.txt:11
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:2887
First
The First
Definition: primes.txt:1
Languages
Definition: languages.inc:27
CheckLanguageCLI\checkLanguage
checkLanguage( $code)
Check a language.
Definition: checkLanguage.inc:383
and
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
display
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed or on behalf the Licensor for the purpose of discussing and improving the but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as Not a Contribution Contributor shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work Grant of Copyright License Subject to the terms and conditions of this each Contributor hereby grants to You a non no royalty irrevocable copyright license to prepare Derivative Works publicly display
Definition: APACHE-LICENSE-2.0.txt:71
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:37
Language\fetchLanguageName
static fetchLanguageName( $code, $inLanguage=null, $include='all')
Definition: Language.php:896
CheckLanguageCLI\isEmpty
isEmpty()
Check if there are any results for the checks, in any language.
Definition: checkLanguage.inc:538
CheckLanguageCLI\formatKey
formatKey( $key, $code)
Format a message key.
Definition: checkLanguage.inc:415
Special
wiki Special
Definition: All_system_messages.txt:2667
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:2001
print
print
Definition: opensearch_desc.php:46
CheckLanguageCLI\$checks
$checks
Definition: checkLanguage.inc:35
other
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 which defines all default service and specifies how they depend on each other("wiring"). When a new service is added to MediaWiki core
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:235
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:9
or
or
Definition: APACHE-LICENSE-2.0.txt:114
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:22
CheckLanguageCLI\nonMessageChecks
nonMessageChecks()
Get the checks which check other things than messages.
Definition: checkLanguage.inc:111
Wikimedia
CheckLanguageCLI\isCheckBlacklisted
isCheckBlacklisted( $check, $code, $message)
Verify whether a check is blacklisted.
Definition: checkLanguage.inc:353
in
null for the wiki Added in
Definition: hooks.txt:1591
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:179
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
database rows
Definition: globals.txt:10
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:13
complete
Returning false makes less sense for events where the action is complete
Definition: hooks.txt:197
CheckLanguageCLI\$checkAll
$checkAll
Definition: checkLanguage.inc:33
CheckLanguageCLI\execute
execute()
Execute the script.
Definition: checkLanguage.inc:274
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
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:18
CheckExtensionsCLI\easyChecks
easyChecks()
Get the checks that can easily be treated by non-speakers of the language.
Definition: checkLanguage.inc:664
CheckLanguageCLI\$results
$results
Definition: checkLanguage.inc:38
$checkBlacklist
$checkBlacklist
Definition: checkLanguage.inc:766
Language
Internationalisation code.
Definition: Language.php:35
$messages
$messages
Definition: LogTests.i18n.php:8
CheckLanguageCLI\$level
$level
Definition: checkLanguage.inc:29
CheckExtensionsCLI\$extensions
$extensions
Definition: checkLanguage.inc:555
CheckExtensionsCLI\__construct
__construct(array $options, $extension)
Definition: checkLanguage.inc:561
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:80
CheckLanguageCLI\getTotalCount
getTotalCount()
Get total count for each check non-messages check.
Definition: checkLanguage.inc:163
form
null means default in associative array form
Definition: hooks.txt:1996