### Running the examples Source: https://github.com/archlinux/archwiki/blob/master/resources/lib/vuex/README.md Commands to install dependencies and run the example applications. ```bash $ npm install $ npm run dev # serve examples at localhost:8080 ``` -------------------------------- ### Standalone Installation Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/less.php/README.md Example of how to include the Less.php library when installed standalone. ```php require_once '[path to]/less.php/lib/Less/Autoloader.php'; Less_Autoloader::register(); ``` -------------------------------- ### Development Setup Source: https://github.com/archlinux/archwiki/blob/master/resources/lib/vue-test-utils/README.md Install dependencies and run tests for development. ```bash pnpm install pnpm test ``` -------------------------------- ### Installation Source: https://github.com/archlinux/archwiki/blob/master/vendor/endroid/qr-code/README.md Install the library using Composer. ```bash composer require endroid/qr-code ``` -------------------------------- ### Installation with Composer Source: https://github.com/archlinux/archwiki/blob/master/vendor/christian-riesen/base32/README.md Installs the base32 package using Composer. ```bash composer require christian-riesen/base32 ``` -------------------------------- ### Composer Installation Source: https://github.com/archlinux/archwiki/blob/master/vendor/zordius/lightncandy/README.md Install LightnCandy using Composer. ```bash composer require zordius/lightncandy:dev-master ``` -------------------------------- ### Install IDLeDOM Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/idle-dom/README.md Install the IDLeDOM package using Composer. ```bash $ composer require wikimedia/idle-dom ``` -------------------------------- ### Install and test Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/at-ease/README.md Commands to install the library dependencies and run the tests. ```bash composer install --prefer-dist composer test ``` -------------------------------- ### Inline style with more spaces example Source: https://github.com/archlinux/archwiki/blob/master/extensions/TemplateData/Specification.md Example of inline style with more spaces, requiring the template to be at the start of a line. ```wikitext {{Foo | bar = baz | qux = quux}} {{Bar }} ``` -------------------------------- ### Installation with npm Source: https://github.com/archlinux/archwiki/blob/master/resources/lib/fetch-polyfill/README.md Install the whatwg-fetch package using npm. ```bash npm install whatwg-fetch --save ``` -------------------------------- ### Install dependencies and run tests Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/parsoid/tests/README.md This snippet shows the basic commands to navigate to the project directory and run the tests using npm. ```bash $ cd .. # if you are in this README file's directory $ npm test ``` -------------------------------- ### Intervals: get example Source: https://github.com/archlinux/archwiki/blob/master/vendor/composer/semver/README.md Example of using the Intervals class to create an array of numeric intervals and branch constraints. ```php use Composer\Semver\Intervals; // Creates an array of numeric intervals and branch constraints representing a given constraint Intervals::get(ConstraintInterface $constraint); ``` -------------------------------- ### Getting a node at a specific index Source: https://github.com/archlinux/archwiki/blob/master/vendor/mck89/peast/doc/querying-by-selector.md This example demonstrates how to get the node at the given index, specifically the first matching node. ```php //Returns the first matching node $ast->query("FunctionDeclaration")->get(0); ``` -------------------------------- ### Start a local web server Source: https://github.com/archlinux/archwiki/blob/master/extensions/VisualEditor/lib/ve/lib/oojs-ui/README.md Command to start a local PHP web server in the root directory. ```bash php -S localhost:80 ``` -------------------------------- ### GuzzleHttp\Psr7\Message::toString Example Source: https://github.com/archlinux/archwiki/blob/master/vendor/guzzlehttp/psr7/README.md Shows how to get the string representation of an HTTP message. ```php $request = new GuzzleHttp\Psr7\Request('GET', 'http://example.com'); echo GuzzleHttp\Psr7\Message::toString($request); ``` -------------------------------- ### Tag release commit Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/codex/CONTRIBUTING.md Example of a commit title for tagging a release. ```git commit Tag: v1.2.3 ``` -------------------------------- ### Run demo with Python 2 Source: https://github.com/archlinux/archwiki/blob/master/resources/lib/jquery.i18n/README.md Starts a local HTTP server using Python 2 to serve the demo. ```bash # If you're using python2, use this command instead ``` -------------------------------- ### RelPath Usage Examples Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/relpath/README.md Demonstrates how to use the RelPath library to get a relative path and join paths. ```php $relPath = \Wikimedia\RelPath::getRelativePath( '/srv/mediawiki/resources/src/startup.js', '/srv/mediawiki' ); // Result: "resources/src/startup.js" $fullPath = \Wikimedia\RelPath::joinPath( '/srv/mediawiki', 'resources/src/startup.js' ); // Result: "/srv/mediawiki/resources/src/startup.js" $fullPath = \Wikimedia\RelPath::joinPath( '/srv/mediawiki', '/var/startup/startup.js' ); // Result: "/var/startup/startup.js" ``` -------------------------------- ### Compile Options Example Source: https://github.com/archlinux/archwiki/blob/master/vendor/zordius/lightncandy/README.md Example of compiling a template with specific flags for error logging and standalone PHP output. ```php LightnCandy::compile($template, array( 'flags' => LightnCandy::FLAG_ERROR_LOG | LightnCandy::FLAG_STANDALONEPHP )); ``` -------------------------------- ### Usage Examples Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/timestamp/README.md Demonstrates how to instantiate ConvertibleTimestamp, get formatted timestamps, and use shorthand conversion. ```php $ts = new ConvertibleTimestamp( '2012-07-31T19:01:08Z' ); $formatted = $ts->getTimestamp( TS_UNIX ); // Shorthand $formatted = ConvertibleTimestamp::convert( TS_UNIX, '2012-07-31T19:01:08Z' ); // Format using PHP date formatting codes $formatted = $ts->format( 'Y-m-d H:i:s O' ); ``` -------------------------------- ### PAGESIZE Magic Word Example Source: https://github.com/archlinux/archwiki/blob/master/tests/parser/magicWords.txt Demonstrates the usage of the {{PAGESIZE}} magic word to get the size of a page. ```wikitext {{PAGESIZE:{{PAGENAME}}}} ``` -------------------------------- ### Lookup Helper Example Source: https://github.com/archlinux/archwiki/blob/master/vendor/zordius/lightncandy/README.md Demonstrates the 'lookup' helper for accessing values by key. ```php use LightnCandy\LightnCandy; // {{lookup foo bar}} : lookup foo by value of bar as key. $template = '{{lookup data key}}'; $renderer = new LightnCandy(); $rendered = $renderer->render($template, ['data' => ['a' => 1, 'b' => 2], 'key' => 'a']); echo $rendered; // Output: 1 ``` -------------------------------- ### Basic Usage Example Source: https://github.com/archlinux/archwiki/blob/master/includes/libs/ParamValidator/README.md Demonstrates how to initialize and use the ParamValidator to get and validate an integer parameter. ```php use Wikimedia\ParamValidator\ParamValidator; use Wikimedia\ParamValidator\TypeDef\IntegerDef; use Wikimedia\ParamValidator\SimpleCallbacks as ParamValidatorCallbacks; use Wikimedia\ParamValidator\ValidationException; // We assume these are available from your environment in some manner. /** @var Wikimedia\ObjectFactory\ObjectFactory $objectFactory */ $objectFactory = ...; /** @var Wikimedia\Message\MessageFormatterFactory $messageFormatterFactory */ $messageFormatterFactory = ...; $validator = new ParamValidator( new ParamValidatorCallbacks( $_POST + $_GET, $_FILES ), $objectFactory ); try { $intValue = $validator->getValue( 'intParam', [ ParamValidator::PARAM_TYPE => 'integer', ParamValidator::PARAM_DEFAULT => 0, IntegerDef::PARAM_MIN => 0, IntegerDef::PARAM_MAX => 5, ] ); } catch ( ValidationException $ex ) { $error = $messageFormatterFactory->getTextFormatter( 'en' )->format( $ex->getFailureMessage() ); echo "Validation error: $error\n"; } ``` -------------------------------- ### Rule Parameter Syntax Examples Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/wikipeg/README.md Demonstrates various ways to use parameters with rules in WikiPEG, including assertions, assignments, and reference parameters. ```wikipeg rule rule rule rule rule rule <& parameter = 1> ``` -------------------------------- ### Unit Test Dependencies and Watch Source: https://github.com/archlinux/archwiki/blob/master/extensions/VisualEditor/lib/ve/lib/jquery/README.md Commands to install dependencies and start the watch process for auto-building jQuery during development. ```bash npm install ``` ```bash grunt watch ``` -------------------------------- ### Write Query Example Source: https://github.com/archlinux/archwiki/blob/master/docs/database.md Example of how to make a write query using the MediaWiki API. ```php $dbw = $dbProvider->getPrimaryDatabase(); $dbw->newInsertQueryBuilder() ->insertInto( /* ...see docs... */ ) // ...see docs for other methods... ->execute(); ``` -------------------------------- ### TinyVE Initialization and Transaction Example Source: https://github.com/archlinux/archwiki/blob/master/extensions/VisualEditor/lib/ve/tinyve/tinyve.html Demonstrates initializing TinyVE, making a transaction to replace text, and inserting a new paragraph. ```javascript const $container = $( '.tinyve-demo' ); const html = $container.html(); tinyve.init( $container, html ); const dmDoc = tinyve.init.target.surface.model.documentModel; console.log( 'Original:', dmDoc.data ); const tx1 = new tinyve.dm.Transaction( [ { type: 'retain', length: 3 }, { type: 'replace', remove: [ ...'This' ], insert: [ ...'THIS' ] } ] ); dmDoc.commit( tx1 ); console.log( 'After tx1:', dmDoc.data ); const tx2 = new tinyve.dm.Transaction( [ { type: 'retain', length: 2 }, { type: 'replace', remove: [], insert: [ { type: 'p' }, ...'foo', { type: '/p' } ] } ] ); dmDoc.commit( tx2 ); console.log( 'After tx2:', dmDoc.data ); ``` -------------------------------- ### Relativize Example Source: https://github.com/archlinux/archwiki/blob/master/vendor/guzzlehttp/psr7/README.md Demonstrates how to use UriResolver::relativize to get the target URI as a relative reference from a base URI. ```php (string) $target === (string) UriResolver::resolve($base, UriResolver::relativize($base, $target)) ``` ```php $base = new Uri('http://example.com/a/b/'); echo UriResolver::relativize($base, new Uri('http://example.com/a/b/c')); // prints 'c'. echo UriResolver::relativize($base, new Uri('http://example.com/a/x/y')); // prints '../x/y'. echo UriResolver::relativize($base, new Uri('http://example.com/a/b/?q')); // prints '?q'. echo UriResolver::relativize($base, new Uri('http://example.org/a/b/')); // prints '//example.org/a/b/'. ``` -------------------------------- ### Run demo with Python 3 Source: https://github.com/archlinux/archwiki/blob/master/resources/lib/jquery.i18n/README.md Starts a local HTTP server on port 8000 using Python 3 to serve the demo. ```bash python -m http.server ``` -------------------------------- ### Templated tags, no content (4) Source: https://github.com/archlinux/archwiki/blob/master/tests/parser/parserTests.txt Example of using templates for table start and end tags without any content in between. ```wikitext {{tbl-start}} {{tbl-end}} ``` ```html/php
``` ```html/parsoid
``` -------------------------------- ### Injecting a custom CurlMulti object Source: https://github.com/archlinux/archwiki/blob/master/vendor/guzzlehttp/guzzle/UPGRADING.md Example of how to inject a custom CurlMulti object into each client when reusing the same CurlMulti object with each client. ```php $multi = new Guzzle\Http\Curl\CurlMulti(); $builder = Guzzle\Service\Builder\ServiceBuilder::factory('/path/to/config.json'); $builder->addListener('service_builder.create_client', function ($event) use ($multi) { $event['client']->setCurlMulti($multi); }); ``` -------------------------------- ### Raw Output Example Source: https://github.com/archlinux/archwiki/blob/master/vendor/zordius/lightncandy/README.md Demonstrates using triple curly braces for unescaped output. ```php use LightnCandy\LightnCandy; $php_code = <<<"EOF" use LightnCandy\LightnCandy; // use {{{val}}} when you do not require HTML escaped output on the value. // It is better performance, too. $template = 'Hello {{{name}}}!'; $renderer = new LightnCandy(); $rendered = $renderer->render($template, ['name' => 'World']); echo $rendered; // Output: Hello World! // You can also use {{&val}} for raw output. $template = 'Hello {{&name}}!'; $rendered = $renderer->render($template, ['name' => 'World']); echo $rendered; // Output: Hello World! // Example with HTML content that should not be escaped $template = '
{{{html_content}}}
'; $renderer = new LightnCandy(); $rendered = $renderer->render($template, ['html_content' => '']); echo $rendered; // Output:
// Example with a value that needs to be escaped by default $template = '

{{user_input}}

'; $renderer = new LightnCandy(); $rendered = $renderer->render($template, ['user_input' => '']); echo $rendered; // Output:

<script>alert('XSS')</script>

EOF; // For demonstration purposes, we'll just show the template and data. // In a real scenario, you would compile and render this. $template = 'Hello {{{name}}}!'; $data = ['name' => 'World']; // To show the actual PHP code that would be generated: // echo $php_code; ``` -------------------------------- ### Interactive Program Notice Source: https://github.com/archlinux/archwiki/blob/master/extensions/Cite/COPYING.txt An example of a short notice that an interactive program should display upon starting, including version, copyright, warranty, and redistribution information. ```text Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Isomorphic Testing Setup (Example 2) Source: https://github.com/archlinux/archwiki/blob/master/resources/lib/vue-demi/README.md Alternative configuration for isomorphic testing using npm aliases, specifying different Vue versions. ```json { "scripts": { "test:2": "vue-demi-switch 2 && jest", "test:3": "vue-demi-switch 3 vue3 && jest", }, "devDependencies": { "vue": "^2.6.0", "vue3": "npm:vue@3" }, } ``` -------------------------------- ### Custom Build Examples Source: https://github.com/archlinux/archwiki/blob/master/extensions/VisualEditor/lib/ve/lib/jquery/README.md Commands for creating custom jQuery builds by excluding specific modules. ```bash git pull; git checkout VERSION ``` ```bash npm install ``` ```bash grunt custom:-ajax ``` ```bash grunt custom:-css ``` ```bash grunt custom:-ajax/jsonp,-css,-deprecated,-dimensions,-effects,-offset,-wrap ``` ```bash grunt custom:slim ``` -------------------------------- ### Looping and Context Variables Source: https://github.com/archlinux/archwiki/blob/master/vendor/zordius/lightncandy/README.md Examples showing how to reference loop index, key, root context, and first/last item status within loops. ```handlebars {{@index}} ``` ```handlebars {{@key}} ``` ```handlebars {{@root}} ``` ```handlebars {{@first}} ``` ```handlebars {{@last}} ``` ```handlebars {{@root.path.to.value}} ``` ```handlebars {{@../index}} ``` ```handlebars {{@../key}} ``` -------------------------------- ### Templated tags, no content (Example 4) Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/parsoid/tests/parser/parserTests.txt Demonstrates the use of templates to define table start and end tags when there is no content within the table. ```wikitext {{tbl-start}} {{tbl-end}} ``` ```html/php
``` ```html/parsoid
``` -------------------------------- ### Isomorphic Testing Setup (Example 1) Source: https://github.com/archlinux/archwiki/blob/master/resources/lib/vue-demi/README.md Configuration for supporting isomorphic testing for both Vue 2 and Vue 3 using npm aliases in devDependencies. ```json { "scripts": { "test:2": "vue-demi-switch 2 vue2 && jest", "test:3": "vue-demi-switch 3 && jest", }, "devDependencies": { "vue": "^3.0.0", "vue2": "npm:vue@2" }, } ``` -------------------------------- ### Wikitext Example for Gallery with Language Variants Source: https://github.com/archlinux/archwiki/blob/master/vendor/wikimedia/parsoid/tests/parser/media.txt Demonstrates how to use wikitext to create a gallery with images, including specifying language variants for the images. ```wikitext [[Datei:Foobar.svg]] [[Datei:Foobar.svg|sprache=ru]] Datei:Foobar.svg Datei:Foobar.svg|sprache=ru ``` -------------------------------- ### Guzzle v5 Event System Source: https://github.com/archlinux/archwiki/blob/master/vendor/guzzlehttp/guzzle/UPGRADING.md Example of using the event system in Guzzle v5 to listen for the 'before' event and modify the request headers. ```php use GuzzleHttp\Event\BeforeEvent; $client = new GuzzleHttp\Client(); // Get the emitter and listen to the before event. $client->getEmitter()->on('before', function (BeforeEvent $e) { // Guzzle v5 events relied on mutation $e->getRequest()->setHeader('X-Foo', 'Bar'); }); ``` -------------------------------- ### Test Suite Convenience Method `q` Source: https://github.com/archlinux/archwiki/blob/master/extensions/VisualEditor/lib/ve/lib/jquery/README.md Example usage of the `q` convenience method for selecting elements by ID. ```javascript q( "main", "foo", "bar" ); => [ div#main, span#foo, input#bar ] ```