MediaWiki REL1_33
generateJqueryMsgData.php
Go to the documentation of this file.
1<?php
16/*
17 * @example QUnit
18 * <code>
19 QUnit.test( 'Output matches PHP parser', function ( assert ) {
20 mw.messages.set( mw.libs.phpParserData.messages );
21 $.each( mw.libs.phpParserData.tests, function ( i, test ) {
22 QUnit.stop();
23 getMwLanguage( test.lang, function ( langClass ) {
24 var parser = new mw.jqueryMsg.Parser( { language: langClass } );
25 assert.strictEqual(
26 parser.parse( test.key, test.args ).html(),
27 test.result,
28 test.name
29 );
30 QUnit.start();
31 } );
32 } );
33 });
34 * </code>
35 *
36 * @example Jasmine
37 * <code>
38 describe( 'match output to output from PHP parser', function () {
39 mw.messages.set( mw.libs.phpParserData.messages );
40 $.each( mw.libs.phpParserData.tests, function ( i, test ) {
41 it( 'should parse ' + test.name, function () {
42 var langClass;
43 runs( function () {
44 getMwLanguage( test.lang, function ( gotIt ) {
45 langClass = gotIt;
46 });
47 });
48 waitsFor( function () {
49 return langClass !== undefined;
50 }, 'Language class should be loaded', 1000 );
51 runs( function () {
52 console.log( test.lang, 'running tests' );
53 var parser = new mw.jqueryMsg.Parser( { language: langClass } );
54 expect(
55 parser.parse( test.key, test.args ).html()
56 ).toEqual( test.result );
57 } );
58 } );
59 } );
60 } );
61 * </code>
62 */
63
64require __DIR__ . '/../../../maintenance/Maintenance.php';
65
67
68 public static $keyToTestArgs = [
69 'undelete_short' => [
70 [ 0 ],
71 [ 1 ],
72 [ 2 ],
73 [ 5 ],
74 [ 21 ],
75 [ 101 ]
76 ],
77 'category-subcat-count' => [
78 [ 0, 10 ],
79 [ 1, 1 ],
80 [ 1, 2 ],
81 [ 3, 30 ]
82 ]
83 ];
84
85 public function __construct() {
86 parent::__construct();
87 $this->mDescription = 'Create a specification for message parsing ini JSON format';
88 // add any other options here
89 }
90
91 public function execute() {
92 list( $messages, $tests ) = $this->getMessagesAndTests();
93 $this->writeJavascriptFile( $messages, $tests, __DIR__ . '/mediawiki.jqueryMsg.data.js' );
94 }
95
96 private function getMessagesAndTests() {
97 $messages = [];
98 $tests = [];
99 foreach ( [ 'en', 'fr', 'ar', 'jp', 'zh' ] as $languageCode ) {
100 foreach ( self::$keyToTestArgs as $key => $testArgs ) {
101 foreach ( $testArgs as $args ) {
102 // Get the raw message, without any transformations.
103 $template = wfMessage( $key )->inLanguage( $languageCode )->plain();
104
105 // Get the magic-parsed version with args.
106 $result = wfMessage( $key, $args )->inLanguage( $languageCode )->text();
107
108 // Record the template, args, language, and expected result
109 // fake multiple languages by flattening them together.
110 $langKey = $languageCode . '_' . $key;
112 $tests[] = [
113 'name' => $languageCode . ' ' . $key . ' ' . implode( ',', $args ),
114 'key' => $langKey,
115 'args' => $args,
116 'result' => $result,
117 'lang' => $languageCode
118 ];
119 }
120 }
121 }
122 return [ $messages, $tests ];
123 }
124
125 private function writeJavascriptFile( $messages, $tests, $dataSpecFile ) {
126 $phpParserData = [
127 'messages' => $messages,
128 'tests' => $tests,
129 ];
130
131 $output =
132 "// This file stores the output from the PHP parser for various messages, arguments,\n"
133 . "// languages, and parser modes. Intended for use by a unit test framework by looping\n"
134 . "// through the object and comparing its parser return value with the 'result' property.\n"
135 . '// Last generated with ' . basename( __FILE__ ) . ' at ' . gmdate( 'r' ) . "\n"
136 . "/* eslint-disable */\n"
137 . "\n"
138 . 'mediaWiki.libs.phpParserData = ' . FormatJson::encode( $phpParserData, true ) . ";\n";
139
140 $fp = file_put_contents( $dataSpecFile, $output );
141 if ( $fp === false ) {
142 die( "Couldn't write to $dataSpecFile." );
143 }
144 }
145}
146
147$maintClass = "GenerateJqueryMsgData";
148require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$messages
if( $line===false) $args
Definition cdb.php:64
This PHP script defines the spec that the mediawiki.jqueryMsg module should conform to.
__construct()
Default constructor.
execute()
Do the actual work.
writeJavascriptFile( $messages, $tests, $dataSpecFile)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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
namespace being checked & $result
Definition hooks.txt:2340
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping $template
Definition hooks.txt:822
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 use $formDescriptor instead 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 set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2272
require_once RUN_MAINTENANCE_IF_MAIN