Skip to content

Commit

Permalink
WIP Porting DOMDataUtils.php in progress and minor related changes
Browse files Browse the repository at this point in the history
* Minor changes to other files being ported correcting errors
  and adjusting to PORT-FIXME annotation to return for additional
  porting of code requiring deeper analysis or support from php
  libraries.

Change-Id: I2aeacf2335ed39dd7b3c35b18777a6dce34f8dfb
  • Loading branch information
simmunity committed Jan 8, 2019
1 parent 1ab7525 commit 2b4deca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions php/lib/config/WikitextConstants.php
Expand Up @@ -2,6 +2,10 @@

namespace Parsoid\Lib\Config;

function object(){
return new stdClass();
}

function makeSet( $a ) {
$set = [];
foreach ( $a as $e ) {
Expand Down
20 changes: 16 additions & 4 deletions php/lib/utils/ContentUtils.php
Expand Up @@ -10,6 +10,18 @@
// WIP porting from JS to PHP, mostly incomplete but first pass through
// of variable naming complete

namespace Parsoid\Lib\Utils;

require_once __DIR__."/../config/WikitextConstants.php";
require_once __DIR__."/DOMDataUtils.php";
require_once __DIR__."/DOMUtils.php";
//require_once __DIR__."/phputils.php";

use Parsoid\Lib\Config\WikitextConstants;
use Parsoid\Lib\Utils\DOMDataUtils;
use Parsoid\Lib\Utils\DOMUtils;
//use Parsoid\Lib\PHPUtils\PHPUtil;

class ContentUtils {
/**
* XML Serializer.
Expand Down Expand Up @@ -49,7 +61,7 @@ public static function ppToXML($node, $options) {
* @return {Node}
*/
public static function ppToDOM($html, $options) {
$options = $options || {};
$options = $options || object();
$node = $options->node;
if ($node === undefined) {
$node = $DOMUtils->parseHTML($html)->body;
Expand All @@ -68,7 +80,7 @@ public static function ppToDOM($html, $options) {
* @return {string}
*/
public static function extractDpAndSerialize($node, $options) {
if (!$options) { $options = {}; }
if (!$options) { $options = object(); }
$options->captureOffsets = true;
$pb = $DOMDataUtils->extractPageBundle($DOMUtils->isBody($node) ? $node->ownerDocument : $node);
out = XMLSerializer->serialize($node, $options);
Expand Down Expand Up @@ -132,7 +144,7 @@ public static function replaceAudioWithVideo($doc) {
*/
public static function dumpDOM($rootNode, $title, $options) {
$DiffUtils = null;
$options = $options || {};
$options = $options || object();
if ($options->storeDiffMark || $options->dumpFragmentMap) { $console->assert($options->env); }

function cloneData($node, $clone) {
Expand Down Expand Up @@ -185,7 +197,7 @@ function emit($buf, $opts) {
$buf->push("");
emit($buf, $options);

$newOpts = $Object->assign({}, $options, { dumpFragmentMap: false, quiet: true });
$newOpts = $Object->assign(object(), $options, { dumpFragmentMap: false, quiet: true });
$fragment = $options->env->fragmentMap->get($k);
$ContentUtils->dumpDOM($Array->isArray($fragment) ? $fragment[0] : $fragment, '', $newOpts);
});
Expand Down
10 changes: 5 additions & 5 deletions php/lib/utils/DOMUtils.php
Expand Up @@ -12,11 +12,11 @@
require_once __DIR__."/phputils.php";
require_once __DIR__."/TokenUtils.php";

use Parsoid\Lib\PHPUtils\PHPUtil;
use Parsoid\Lib\Config\WikitextConstants;
use Parsoid\Lib\PHPUtils\PHPUtil;
use Parsoid\Lib\Utils\TokenUtils;

class DU
class DOMUtils
{
const TPL_META_TYPE_REGEXP = '/(?:^|\s)(mw:(?:Transclusion|Param)(?:\/End)?)(?=$|\s)/';
const FIRST_ENCAP_REGEXP = '/(?:^|\s)(mw:(?:Transclusion|Param|LanguageVariant|Extension(\/[^\s]+)))(?=$|\s)/';
Expand Down Expand Up @@ -384,7 +384,7 @@ public static function isDiffMarker($node, $mark) {
return self::isMarkerMeta($node, 'mw:DiffMarker/' + $mark);
} else {
assert(false, 'Not yet ported');
// NTR - must convert regex expression to php style
// PORT-FIXME - must convert regex expression to php style
// return $node->nodeName === 'META' && /\bmw:DiffMarker\/\w*\b/.test($node->getAttribute('typeof'));
}
}
Expand Down Expand Up @@ -676,9 +676,9 @@ public static function nodeEssentiallyEmpty($node, $strict) {
if (self::isElt($n) && !self::isDiffMarker($n)) {
return false;
} else if (self::isText($n) // &&
// NTR - must convert regex expression to php style
// PORT-FIXME - must convert regex expression to php style
// (strict || !/^[ \t]*$/.test($n->nodeValue))) {
{ // NTR - remove this brace when line above is restored
{ // PORT-FIXME - remove this brace when line above is restored
assert(false, 'Not yet ported');
return false;
} else if (self::isComment($n)) {
Expand Down
7 changes: 5 additions & 2 deletions php/lib/utils/phputils.php
Expand Up @@ -32,6 +32,9 @@ public static function getHRTimeDifferential($previousTime) {
public static function json_encode($o) {
return json_encode($o, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
}

?>
public static function json_decode($o) {
return json_decode($o);
}

}

0 comments on commit 2b4deca

Please sign in to comment.