public function execute() { global $wgUser; $params = $this->extractRequestParams(); if (is_null($params['page'])) { $this->dieUsage('Must specify page title', 0); } if (is_null($params['tpl'])) { $this->dieUsage('Must specify template name', 1); } if (is_null($params['param'])) { $this->dieUsage('Must specify parameter name', 2); } if (is_null($params['value'])) { $this->dieUsage('Must specify value', 3); } if (is_null($params['summary'])) { $this->dieUsage('Must specify edit summary', 4); } $page = $params['page']; $template = $params['tpl']; $instance = $params['tplinstance']; $parameter = $params['param']; $value = $params['value']; $summary = $params['summary']; $articleTitle = Title::newFromText($page); if (!$articleTitle) { $this->dieUsage("Can't create title object ({$page})", 5); } $errors = $articleTitle->getUserPermissionsErrors('edit', $wgUser); if (!empty($errors)) { $this->dieUsage(wfMsg($errors[0][0], $errors[0][1]), 8); } $article = new Article($articleTitle); if (!$article->exists()) { $this->dieUsage("Article doesn't exist ({$page})", 6); } $pom = new POMPage($article->getContent()); if (array_key_exists($template, $pom->templates) && array_key_exists($instance, $pom->templates[$template])) { $pom->templates[$template][$instance]->setParameter($parameter, $value); } else { $this->dieUsage("This template ({$template}, instance #{$instance}) with this parameter ({$parameter}) doesn't exist within this page ({$page})", 7); } $success = $article->doEdit($pom->asString(), $summary); $result = array(); $result['result'] = $success ? 'Success' : 'Failure'; $this->getResult()->addValue(null, 'pomsettplparam', $result); }
<?php require_once( 'POM.php' ); # Get document from MediaWiki server $pom = new POMPage( join( file( 'http://www.mediawiki.org/w/index.php?title=Extension:Page_Object_Model&action=raw' ) ) ); # Check current version $ver = $pom->templates['Extension'][0]->getParameter( 'version' ); echo "Current version: $ver\n"; # Increase version number by fraction $pom->templates['Extension'][0]->setParameter( 'version', $ver + 0.1 ); # Do whatever you want with result (we'll just display it) echo "Document with increased version:\n" . $pom->asString();
/** * @dataProvider pageProvider */ public function testInputIsTheSameAsOutput( $pagetext ) { $page = new POMPage( $pagetext ); $this->assertEquals( $pagetext, $page->asString() ); }