PHP code example of wikimedia / codex

1. Go to this page and download the library: Download wikimedia/codex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wikimedia / codex example snippets


$accordion = $codex
			->accordion()
			->setTitle( "Accordion Example" )
			->setDescription( "This is an example of an accordion." )
			->setContentHtml(
				$codex
					->htmlSnippet()
					->setContent( "<p>This is the content of the accordion.</p>" )
					->build()
			)
			->setOpen( false )
			->setAttributes( [
				"class" => "foo",
				"bar" => "baz",
			] )
			->build()
			->getHtml();

echo $accordion;



kimedia\Codex\Utility\Codex

$codex = new Codex();

$accordion = $codex
			->accordion()
			->setTitle( "Accordion Example" )
			->setDescription( "This is an example of an accordion." )
			->setContentHtml(
				$codex
					->htmlSnippet()
					->setContent( "<p>This is the content of the accordion.</p>" )
					->build()
			)
			->setOpen( false )
			->setAttributes( [
				"class" => "foo",
				"bar" => "baz",
			] )
			->build()
			->getHtml();

echo $accordion;



use MediaWiki\SpecialPage\SpecialPage;
use Wikimedia\Codex\Adapter\WebRequestAdapter;
use Wikimedia\Codex\Utility\Codex;
use Wikimedia\Codex\Utility\WebRequestCallbacks;

class SomeSpecial extends SpecialPage {

	public function __construct() {
		parent::__construct( "SomeSpecial" );
	}

	public function execute( $subPage ) {
		$codex = new Codex();
		$requestAdapter = new WebRequestAdapter( $this->getRequest() );
		$callbacks = new WebRequestCallbacks( $requestAdapter );

		$tab1 = $codex
				->Tab()
				->setName( "tab1" )
				->setLabel( "Tab 1" )
				->setContentHtml(
					$codex
					->htmlSnippet()
					->setContent( "<p>Content 1.</p>" )
					->build()
				)
				->setSelected( true )
				->build();

		$tab2 = $codex
				->Tab()
				->setName( "tab2" )
				->setLabel( "Tab 2" )
				->setContentHtml(
					$codex
					->htmlSnippet()
					->setContent( "<p>Content 2.</p>" )
					->build()
				)
				->build();

		$tab3 = $codex
				->Tab()
				->setName( "tab3" )
				->setLabel( "Tab 3" )
				->setContentHtml(
					$codex
					->htmlSnippet()
					->setContent( "<p>Content 3.</p>" )
					->build()
				)
				->build();

		$tabs = $codex
				->Tabs()
				->setCallbacks( $callbacks )
				->setTab( [ $tab1, $tab2, $tab3 ] )
				->build()
				->getHtml();

		$this->getOutput()->addHTML( $tabs );
	}
}

use Wikimedia\Codex\Contract\IWebRequest;

class SimpleWebRequest implements IWebRequest {
protected array $data;

    public function __construct( array $data ) {
        $this->data = $data;
    }

    public function getVal( string $name, $default = null ) {
        return $this->data[$name] ?? $default;
    }
}

use Wikimedia\Codex\Adapter\WebRequestAdapter;

// Initialize the request with $_GET parameters
$request = new SimpleWebRequest( $_GET );

// Adapt the SimpleWebRequest to work with Codex
$requestAdapter = new WebRequestAdapter( $request );

use Wikimedia\Codex\Utility\WebRequestCallbacks;

// Initialize WebRequestCallbacks
$callbacks = new WebRequestCallbacks( $requestAdapter );