'math_input' , 'mathlatexml' => 'math_inputtex'); public function __construct() { parent::__construct(); $this->mDescription = 'Exports a json file that consists of the input hashes and the texvc input from the database cache.'; $this->addArg( 'table', "The math table to be used (mathoid or latexml).", false ); $this->addOption( 'offset', "If set the first n equations on the table are skipped", false, true, "o" ); $this->addOption( 'length', "If set the only n equations are exported processed", false, true, "l" ); $this->addOption( 'sort' , 'If set the result is sorted according to the input', false, false, 's' ); } /** * @param $table * @param $offset * @param $length * @return bool|ResultWrapper */ private static function getMathTagsFromDatabase( $table , $offset , $length , $sort ) { $out = array(); $dbr = wfGetDB( DB_SLAVE ); $inputColumn = self::$inputColumns[ $table ]; $options = array( 'OFFSET' => $offset, 'LIMIT' => $length ); if ( $sort === true ) { $options['ORDER BY'] = $inputColumn; } $res = $dbr->select( $table, array( 'math_inputhash', $inputColumn ), '' , __METHOD__ , $options ); if ( $res === false ) return false; // Convert result wrapper to array foreach ( $res as $row ){ $out[] = array( // the binary encoded input-hash is no valid json output 'inputhash' => MathRenderer::dbHash2md5($row->math_inputhash) , 'input' => $row->$inputColumn ); } return $out; } public function execute() { $table = $this->getArg( 0, self::DEFAULT_TABLE ); if( !in_array( $table, self::$allowedTables ) ){ echo "Error: '$table' is not allowed.\n"; return; } $offset = $this->getOption( 'offset', 0 ); $length = $this->getOption( 'length', PHP_INT_MAX ); $sort = $this->hasOption( 'sort' ); $allEquations = self::getMathTagsFromDatabase( $table, $offset, $length, $sort ); if ( !is_array( $allEquations ) ) { echo "Could not get equations from table '$table'\n"; return; } $out = json_encode( $allEquations, JSON_PRETTY_PRINT ); if( $out === false){ echo "Could not encode result als json string '$table'\n"; } else { echo $out; } } } $maintClass = "ExportMathCache"; require_once( RUN_MAINTENANCE_IF_MAIN );