User:Leucosticte/IWSandbox

populate
 * @copyright GPL

require_once( dirname( __FILE__ ) . "/../../maintenance/Maintenance.php" );

class PopulateInterwikiExistencePageTable extends Maintenance { public function execute { global $wgInterwikiExistenceRemoteWikiUrl, $wgInterwikiExistenceApiAllPagesArgs, $wgInterwikiExistenceUserAgent; require_once 'setInterwikiExistenceTimestamp.php'; SetInterwikiExistenceTimestamp::setTimestamp ( 'new', 'now' ); SetInterwikiExistenceTimestamp::setTimestamp ( 'delete', 'now' ); InterwikiExistenceHooks::interwikiExistenceUpdate ( INTERWIKIEXISTENCE_CHECKMINIMUMSECONDS,		'interwikiexistencedeletetimestamp',			'interwikiexistencedeleteconttimestamp',			true, $wgInterwikiExistenceRemoteWikiUrl, $wgInterwikiExistenceApiDeleteArgs,			'logevents', 'iwe_page_deleted', 'lecontinue',			$wgInterwikiExistenceSeconds, $wgInterwikiExistenceMinimumSeconds,			$wgInterwikiExistenceUserAgent );

$dbw = wfGetDB( DB_MASTER ); $result = $dbw->selectrow( 'user_properties', 'up_value', array ( 'up_user' => '1', 'up_property' => 'interwikiexistenceallpagescont', ) );       if ( $result ) { $apiStart = $result->up_value; if ( !$apiStart ) { $apiStart = '!'; }       } else { $apiStart = '!'; }       echo "Starting with $apiStart ...\n"; while ( $apiStart != null ) { $apiUrl = $wgInterwikiExistenceRemoteWikiUrl. str_replace (               '$1', $apiStart, $wgInterwikiExistenceApiAllPagesArgs ); $apiPull = InterwikiExistenceHooks::InterwikiExistenceApiPull ( $apiUrl,               $wgInterwikiExistenceUserAgent ); if ( isset ( $apiPull['status'] ) ) { echo "There was a problem polling the API. URL = $apiUrl\n"; die; }           // See what titles are in the database $firstElement = true; $cond = ''; $titles = array; foreach ( $apiPull['query']['allpages'] as $apiPullElement ) { $cleanTitle = $dbw->strencode ( $apiPullElement['title'] ); if ( !$firstElement ) { $cond .= " OR "; }                           $cond .= "iwe_page_title=". $dbw->addquotes ( $cleanTitle ); $firstElement = false; $titles[$cleanTitle] = wfTimestampNow; }                   $result = $dbw->select( 'iwe_page', array ( 'iwe_page_title', 'iwe_page_created' ),                            $cond ); if ( $result ) { foreach ( $result as $row ) { $timestamp = $titles[$row->iwe_page_title]; unset ( $titles[ $row->iwe_page_title ] ); if ( $timestamp > $row->iwe_page_created ) { $dbw->update ( 'iwe_page', array ( 'iwe_page_created' => $timestamp ),                                               array ( 'iwe_page_title' => $row->iwe_page_title )                                        ); }                           }                    }                    // Insert rows $insertArray = array; foreach ( $titles as $title => $timestamp ) { if ( $title != 'updated' ) { $insertArray[] = array (                                           'iwe_page_title' => $title,                                            'iwe_page_created' => $timestamp                                    ); }                   }                    $dbw->insert( 'iwe_page', $insertArray ); // Update interwikiexistenceallpagescont timestamp if we've reached the end of the queries if ( !isset ( $apiPull['query-continue'] ) ) { echo "Population complete!\n"; $apiStart = null; } else { $apiStart = $apiPull['query-continue']['allpages']['apcontinue']; $upsert = array (                                   'up_user' => '1',                                    'up_property' => 'interwikiexistenceallpagescont',                                    'up_value' => $apiStart                            ); $dbw->upsert(                                   'user_properties',                                    $upsert,                                    array ( 'up_user', 'up_property' ),                                    $upsert                            ); echo "Continuing with $apiStart ...\n"; }       }    } }

$maintClass = 'PopulateInterwikiExistencePageTable'; if( defined('RUN_MAINTENANCE_IF_MAIN') ) { require_once( RUN_MAINTENANCE_IF_MAIN ); } else { require_once( DO_MAINTENANCE ); # Make this work on versions before 1.17 }

special
 * @copyright GPL

if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension. It is not a valid entry point' ); }

class SpecialInterwikiExistence extends SpecialPage { function __construct { parent::__construct( 'InterwikiExistence', 'interwikiexistence' ); }

public function userCanExecute( User $user ) { return true; }

function execute( $par ) { global $wgInterwikiExistenceNewSeconds, $wgInterwikiExistenceDeleteSeconds, $wgInterwikiExistenceNewOdds, $wgInterwikiExistenceDeleteOdds, $wgInterwikiExistenceRemoteWikiUrl, $wgInterwikiExistenceApiNewArgs, $wgInterwikiExistenceApiDeleteArgs, $wgInterwikiExistenceUserAgent, $wgInterwikiExistenceMinimumNewSeconds, $wgInterwikiExistenceMinimumDeleteSeconds; $user = $this->getUser; if ( !$user->isAllowed( 'interwikiexistence' ) ) { throw new PermissionsError( null, array( array(                               'interwikiexistence-notallowed' ) ) ); }		$this->setHeaders; $output = $this->getOutput; $context = $this->getContext; $isNotExempt = !$user->isAllowed( 'interwikiexistencenoratelimit' ); // Don't roll dice or check time SpecialInterwikiExistence::reaction (			InterwikiExistenceHooks::interwikiExistenceUpdate ( INTERWIKIEXISTENCE_ROLLDICE | INTERWIKIEXISTENCE_CHECKMINIMUMTIME, $wgInterwikiExistenceNewOdds, 'interwikiexistencenewtimestamp', 'interwikiexistencenewconttimestamp', $wgInterwikiExistenceRemoteWikiUrl, $wgInterwikiExistenceApiNewArgs, 'recentchanges', 'iwe_page_created', 'rccontinue', $wgInterwikiExistenceNewSeconds, $wgInterwikiExistenceMinimumNewSeconds, $wgInterwikiExistenceUserAgent ), $output,				'interwikiexistence-creation',				$wgInterwikiExistenceMinimumNewSeconds ); SpecialInterwikiExistence::reaction (			InterwikiExistenceHooks::interwikiExistenceUpdate ( INTERWIKIEXISTENCE_ROLLDICE | INTERWIKIEXISTENCE_CHECKMINIMUMTIME, $wgInterwikiExistenceDeleteOdds, 'interwikiexistencedeletetimestamp', 'interwikiexistencedeleteconttimestamp', false, $wgInterwikiExistenceRemoteWikiUrl, $wgInterwikiExistenceApiDeleteArgs, 'logevents', 'iwe_page_deleted', 'lecontinue', $wgInterwikiExistenceDeleteSeconds, $wgInterwikiExistenceMinimumDeleteSeconds, true, $wgInterwikiExistenceUserAgent ), $output,				'interwikiexistence-deletion',				$wgInterwikiExistenceMinimumDeleteSeconds ); }

public static function reaction ( $input, $output, $action, $seconds ) { if ( is_array ( $input ) ) { if ( $input['status'] == INTERWIKIEXISTENCE_NORETRIEVE ) { $output->addWikiMsg ( 'interwikiexistence-trigger-noretrieve',                                       $result['url']); }                       if ( $input['status'] == INTERWIKIEXISTENCE_NODECODE ) { $output->addWikiMsg ( 'interwikiexistence-trigger-nodecode',                                       $result['url'] ); }               } else switch ( $input ) { case INTERWIKIEXISTENCE_SUCCESS: $output->addWikiMsg ( 'interwikiexistence-trigger-success',					wfMessage ( $action ) ); break; case INTERWIKIEXISTENCE_CONTINUING: $output->addWikiMsg ( 'interwikiexistence-trigger-continuing',					wfMessage ( $action ) ); break; case INTERWIKIEXISTENCE_THROTTLED: $output->addWikiMsg ( 'interwikiexistence-trigger-throttled',					$seconds, wfMessage ( $action ) ); break; case INTERWIKIEXISTENCE_NOTIMESTAMP: $output->addWikiMsg ( 'interwikiexistence-trigger-notimestamp',					wfMessage ( $action ) ); break; }		return; } }