Skip to content

Commit

Permalink
Implemented MwDump::touchModified() to touch timestamp for altered re…
Browse files Browse the repository at this point in the history
…vision texts via their base36sha1.
  • Loading branch information
root committed Aug 11, 2014
1 parent 7759f43 commit 079cc19
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
15 changes: 14 additions & 1 deletion MwDumpProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,27 @@ public function filterFiles( PageModel $pageModel ) {
return $pageModel->getSubProp( 'pageProps', 'ns' ) === PageModel::NS_FILE;
}

public function touchModified( PageModel $pageModel ) {
if ( $pageModel->getSubProp( 'revProps', 'base36sha1' ) !==
$pageModel->getSubProp( 'textProps', 'base36sha1' ) ) {
$pageModel->setTimestamp( time() );
$pageModel->setRevBase36Sha1( $pageModel->getSubProp( 'textProps', 'base36sha1' ) );
# Q\Dbg\log('modifiedPage',$pageModel);
return true;
} else {
return false;
}
}

public function process( $inFileName, $outFileName ) {
$dumpParser = MwDumpParser::newFromUri( $inFileName );
$dumpParser->setOutputFileName( $outFileName );
# $dumpParser->addPageHook( array( $this, 'noopHook' ) );
# $dumpParser->addPageHook( array( $this, 'addArchiveCategory' ) );
# $dumpParser->addPageHook( array( $this, 'renameCategory' ) );
# $dumpParser->addPageHook( array( $this, 'forceRenameCategory' ) );
$dumpParser->addPageHook( array( $this, 'filterFiles' ) );
# $dumpParser->addPageHook( array( $this, 'filterFiles' ) );
$dumpParser->addPageHook( array( $this, 'touchModified' ) );
$dumpParser->parse();
}

Expand Down
31 changes: 24 additions & 7 deletions model/PageModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class PageModel extends Q\FeaturesObject {

protected $pageProps;
protected $revProps;
protected $textProps;

function __construct() {
$this->pageProps = new \stdClass();
$this->revProps = new \stdClass();
$this->textProps = new \stdClass();
}

public function setTitle( $title ) {
Expand Down Expand Up @@ -43,13 +45,17 @@ public function setParentId( $parentId ) {
}

public function setTimestamp( $ts ) {
$ts = Q\Gl::timeStamp( Q\Gl::TS_UNIX, $ts );
$ts = is_numeric( $ts ) ? $ts : Q\Gl::timeStamp( Q\Gl::TS_UNIX, $ts );
if ( $ts === false ) {
SdvException::throwRecoverable( 'Invalid timestamp of revision', __METHOD__, $ts );
}
$this->revProps->ts = $ts;
}

public function setUserIP( $userIP ) {
$this->revProps->userIP = $userIP;
}

public function setUserName( $userName ) {
$this->revProps->userName = $userName;
}
Expand All @@ -72,8 +78,8 @@ public function setTextAttrs( $textAttrs ) {

public function setText( $text ) {
$this->revProps->text = $text;
$this->revProps->base36sha1 = Q\Gl::baseConvert( sha1( $text ), 16, 36, 31 );
$this->revProps->textAttrs->bytes = strlen( $text );
$this->textProps->base36sha1 = Q\Gl::baseConvert( sha1( $text ), 16, 36, 31 );
$this->textProps->bytes = strlen( $text );
}

public function setRevBase36Sha1( $base36sha1 ) {
Expand Down Expand Up @@ -104,17 +110,28 @@ public function getTagArray() {
if ( property_exists( $this->revProps, 'parentId' ) ) {
$revision[] = array( '@tag' => 'parentid', $this->revProps->parentId );
}
if ( !property_exists( $this->revProps, 'textAttrs' ) ) {
Q\SdvException::throwError( 'Revision property textAttrs does not exists', __METHOD__, $this->revProps );
}
$textTagArray = (array) $this->revProps->textAttrs;
$textTagArray['@tag'] = 'text';
if ( $this->revProps->text !== '' ) {
$textTagArray[] = $this->revProps->text;
}
$contributor = array( '@tag' => 'contributor' );
if ( property_exists( $this->revProps, 'userIP' ) ) {
array_push( $contributor,
array( '@tag' => 'ip', $this->revProps->userIP )
);
} else {
array_push( $contributor,
array( '@tag' => 'username', $this->revProps->userName ),
array( '@tag' => 'id', $this->revProps->uid )
);
}
array_push( $revision,
array( '@tag' => 'timestamp', Q\Gl::timeStamp( Q\Gl::TS_ISO_8601, $this->revProps->ts ) ),
array( '@tag' => 'contributor',
array( '@tag' => 'username', $this->revProps->userName ),
array( '@tag' => 'id', $this->revProps->uid ),
)
$contributor
);
if ( property_exists( $this->revProps, 'isMinor' ) &&
$this->revProps->isMinor ) {
Expand Down
5 changes: 3 additions & 2 deletions parser/PageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class PageParser extends Q\XmlOneLevelParser {
'revision/id' => array( self::TAG_MANDATORY, 'setRevisionId' ),
'revision/parentid' => array( self::TAG_OPTIONAL, 'setParentId' ),
'revision/timestamp' => array( self::TAG_MANDATORY, 'setTimestamp' ),
'revision/contributor/username' => array( self::TAG_MANDATORY, 'setUserName' ),
'revision/contributor/id' => array( self::TAG_MANDATORY, 'setUserId' ),
'revision/contributor/ip' => array( self::TAG_OPTIONAL, 'setUserIP' ),
'revision/contributor/username' => array( self::TAG_OPTIONAL, 'setUserName' ),
'revision/contributor/id' => array( self::TAG_OPTIONAL, 'setUserId' ),
'revision/comment' => array( self::TAG_OPTIONAL, 'setRevComment' ),
'revision/minor' => array( self::TAG_OPTIONAL, 'setRevMinor' ),
'revision/text' => array( self::TAG_MANDATORY, array( 'parsetag_text' ), 'logNameAttrVal' ),
Expand Down
2 changes: 1 addition & 1 deletion sdv_engine.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e:\www\questpc
/var/www/questpc

0 comments on commit 079cc19

Please sign in to comment.