MediaWiki  REL1_22
preprocessDump.php
Go to the documentation of this file.
00001 <?php
00028 require_once __DIR__ . '/dumpIterator.php';
00029 
00036 class PreprocessDump extends DumpIterator {
00037 
00038     /* Variables for dressing up as a parser */
00039     public $mTitle = 'PreprocessDump';
00040     public $mPPNodeCount = 0;
00041 
00042     public function getStripList() {
00043         global $wgParser;
00044         return $wgParser->getStripList();
00045     }
00046 
00047     public function __construct() {
00048         parent::__construct();
00049         $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
00050         $this->addOption( 'preprocessor', 'Preprocessor to use.', false, false );
00051     }
00052 
00053     public function getDbType() {
00054         return Maintenance::DB_NONE;
00055     }
00056 
00057     public function checkOptions() {
00058         global $wgParser, $wgParserConf, $wgPreprocessorCacheThreshold;
00059 
00060         if ( !$this->hasOption( 'cache' ) ) {
00061             $wgPreprocessorCacheThreshold = false;
00062         }
00063 
00064         if ( $this->hasOption( 'preprocessor' ) ) {
00065             $name = $this->getOption( 'preprocessor' );
00066         } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) {
00067             $name = $wgParserConf['preprocessorClass'];
00068         } else {
00069             $name = 'Preprocessor_DOM';
00070         }
00071 
00072         $wgParser->firstCallInit();
00073         $this->mPreprocessor = new $name( $this );
00074     }
00075 
00080     public function processRevision( $rev ) {
00081         $content = $rev->getContent( Revision::RAW );
00082 
00083         if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
00084             return;
00085         }
00086 
00087         try {
00088             $this->mPreprocessor->preprocessToObj( strval( $content->getNativeData() ), 0 );
00089         } catch ( Exception $e ) {
00090             $this->error( "Caught exception " . $e->getMessage() . " in " . $rev->getTitle()->getPrefixedText() );
00091         }
00092     }
00093 }
00094 
00095 $maintClass = "PreprocessDump";
00096 require_once RUN_MAINTENANCE_IF_MAIN;