[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> preprocessDump.php (source)

   1  <?php
   2  /**
   3   * Take page text out of an XML dump file and preprocess it to obj.
   4   * It may be useful for getting preprocessor statistics or filling the
   5   * preprocessor cache.
   6   *
   7   * Copyright © 2011 Platonides - https://www.mediawiki.org/
   8   *
   9   * This program is free software; you can redistribute it and/or modify
  10   * it under the terms of the GNU General Public License as published by
  11   * the Free Software Foundation; either version 2 of the License, or
  12   * (at your option) any later version.
  13   *
  14   * This program is distributed in the hope that it will be useful,
  15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17   * GNU General Public License for more details.
  18   *
  19   * You should have received a copy of the GNU General Public License along
  20   * with this program; if not, write to the Free Software Foundation, Inc.,
  21   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22   * http://www.gnu.org/copyleft/gpl.html
  23   *
  24   * @file
  25   * @ingroup Maintenance
  26   */
  27  
  28  require_once  __DIR__ . '/dumpIterator.php';
  29  
  30  /**
  31   * Maintenance script that takes page text out of an XML dump file and
  32   * preprocesses it to obj.
  33   *
  34   * @ingroup Maintenance
  35   */
  36  class PreprocessDump extends DumpIterator {
  37  
  38      /* Variables for dressing up as a parser */
  39      public $mTitle = 'PreprocessDump';
  40      public $mPPNodeCount = 0;
  41  
  42  	public function getStripList() {
  43          global $wgParser;
  44  
  45          return $wgParser->getStripList();
  46      }
  47  
  48  	public function __construct() {
  49          parent::__construct();
  50          $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
  51          $this->addOption( 'preprocessor', 'Preprocessor to use.', false, false );
  52      }
  53  
  54  	public function getDbType() {
  55          return Maintenance::DB_NONE;
  56      }
  57  
  58  	public function checkOptions() {
  59          global $wgParser, $wgParserConf, $wgPreprocessorCacheThreshold;
  60  
  61          if ( !$this->hasOption( 'cache' ) ) {
  62              $wgPreprocessorCacheThreshold = false;
  63          }
  64  
  65          if ( $this->hasOption( 'preprocessor' ) ) {
  66              $name = $this->getOption( 'preprocessor' );
  67          } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) {
  68              $name = $wgParserConf['preprocessorClass'];
  69          } else {
  70              $name = 'Preprocessor_DOM';
  71          }
  72  
  73          $wgParser->firstCallInit();
  74          $this->mPreprocessor = new $name( $this );
  75      }
  76  
  77      /**
  78       * Callback function for each revision, preprocessToObj()
  79       * @param Revision $rev
  80       */
  81  	public function processRevision( $rev ) {
  82          $content = $rev->getContent( Revision::RAW );
  83  
  84          if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
  85              return;
  86          }
  87  
  88          try {
  89              $this->mPreprocessor->preprocessToObj( strval( $content->getNativeData() ), 0 );
  90          } catch ( Exception $e ) {
  91              $this->error( "Caught exception " . $e->getMessage() . " in "
  92                  . $rev->getTitle()->getPrefixedText() );
  93          }
  94      }
  95  }
  96  
  97  $maintClass = "PreprocessDump";
  98  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1