Permalink
Browse files

Use a more flexible regex approach to searching Recent additions

  • Loading branch information...
Jarry1250 committed Jan 24, 2018
1 parent 5585dd1 commit 130c52eb42e26ef1d83f0a849fdfe2c07a65a83e
Showing with 3 additions and 11 deletions.
  1. +3 −11 script.php
@@ -200,20 +200,12 @@ function getApplicableLength( $pagename, $dykname ) {
$json = getJSON( $apiBase . "action=query&prop=revisions&titles=" . urlencode( $backlink['title'] ) . "&rvprop=content&rvlimit=1" );
$page = array_shift( $json['query']['pages'] );
$text = str_replace( '_', ' ', $page['revisions'][0]['*'] );
$bits = explode( '===', $text );
for( $i = 0; $i < count( $bits ); $i++ ) {
$altPagename = str_replace( ' ', '_', $pagename );
$altPagename2 = str_replace( '_', ' ', $pagename );
if ( ( stripos( $bits[$i], "'''[[$altPagename" ) !== false || stripos( $bits[$i], "'''[[$altPagename2" ) !== false
|| stripos( $bits[$i], "'''[[$altPagename2" ) !== false )
&& preg_match( "/'''''(.*?) \(UTC\)'''''/", $bits[$i + 1], $matches ) ) {
$timestamp = date( 'YmdHis', strtotime( $matches[1] ) );
break;
}
// Wierdly we want the timestamp after and not before...
if( preg_match("/" . preg_quote( str_replace( '_', ' ', $pagename ) ) . ".*?'''''(.*?) \(UTC\)'''''/is", $text, $matches ) ) {
$timestamp = date( 'YmdHis', strtotime( $matches[1] ) );
}
}
}
if( $timestamp === false ) {
// Fall back to assumption of promotion plus 12 hours
$json = getJSON( $apiBase . "action=query&titles=$encodedDykName&prop=revisions" );

1 comment on commit 130c52e

@Jarry1250

This comment has been minimized.

Owner

Jarry1250 commented on 130c52e May 13, 2018

Use of ".*?'''''" caused a minor regression where the qunituple apostrophe was used but not followed by a UTC block. See a6e39aa5.

Please sign in to comment.