Permalink
Browse files

Refactor getCreationDate to passesCreationDateTest

Allows easy use of the last-revision-before paradigm, which itself
allows for a bytesize check on the page (thus establishing whether
it is a redirect or not).
  • Loading branch information...
Jarry1250 committed May 19, 2014
1 parent b306a91 commit 119cbec180e69883212772aec2d00c6ea0c951fb
Showing with 11 additions and 7 deletions.
  1. +11 −7 script.php
@@ -213,20 +213,25 @@ function getApplicableLength( $pagename, $dykname ) {
return mb_strlen( $prose, 'UTF-8' );
}
function getCreationDate( $pagename ) {
function passesCreationDateTest( $pagename ) {
global $apiBase;
// Find first revision
$json = getJSON( $apiBase . "action=query&titles=$pagename&prop=revisions&rvdir=newer&rvlimit=1" );
// Find first revision before cutoff, if any
$cutoff = ( intval( date( 'Y' ) ) - 5 ) . '0101000000';
$json = getJSON( $apiBase . "action=query&titles=$pagename&rvprop=size&rvstart=$cutoff&rvlimit=1" );
if( !isset( $json['query']['pages'] ) ){
// No such page?
return false;
}
$page = array_shift( $json['query']['pages'] );
if( !isset( $page['revisions'], $page['revisions'][0], $page['revisions'][0]['timestamp'] ) ){
if( !isset( $page['revisions'], $page['revisions'][0],
$page['revisions'][0]['timestamp'], $page['revisions'][0]['size'] ) ){
// No such revision
return false;
}
return strtotime( $page['revisions'][0]['timestamp'] );
return ( intval( $page['revisions'][0]['size'] ) > 100 );
}
function getApplicableMultiplier( $pageName, $section, $line ) {
@@ -276,8 +281,7 @@ function getApplicableMultiplier( $pageName, $section, $line ) {
if( getApplicableLength( $pageName, $dykNom ) > 5100 ){
$preadditive += 5;
}
$creation = getCreationDate( $pageName );
if( $creation && $creation < strtotime( '1 January ' . ( intval( date( 'Y' ) ) - 5 ) ) ){
if( passesCreationDateTest( $pageName ) ){
$postadditive += 5;
}
}

0 comments on commit 119cbec

Please sign in to comment.