Merge "Make line breaks in <blockquote> behave like <div> (bug 6200)."
[mediawiki.git] / maintenance / preprocessDump.php
blob0dc19e2865cd3d9f3f641209ee1cb446efb8a629
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.
7 * Copyright © 2011 Platonides - http://www.mediawiki.org/
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.
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.
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
24 * @file
25 * @ingroup Maintenance
28 require_once __DIR__ . '/dumpIterator.php';
30 /**
31 * Maintenance script that takes page text out of an XML dump file and
32 * preprocesses it to obj.
34 * @ingroup Maintenance
36 class PreprocessDump extends DumpIterator {
38 /* Variables for dressing up as a parser */
39 public $mTitle = 'PreprocessDump';
40 public $mPPNodeCount = 0;
42 public function getStripList() {
43 global $wgParser;
44 return $wgParser->getStripList();
47 public function __construct() {
48 parent::__construct();
49 $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
50 $this->addOption( 'preprocessor', 'Preprocessor to use.', false, false );
53 public function getDbType() {
54 return Maintenance::DB_NONE;
57 public function checkOptions() {
58 global $wgParser, $wgParserConf, $wgPreprocessorCacheThreshold;
60 if ( !$this->hasOption( 'cache' ) ) {
61 $wgPreprocessorCacheThreshold = false;
64 if ( $this->hasOption( 'preprocessor' ) ) {
65 $name = $this->getOption( 'preprocessor' );
66 } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) {
67 $name = $wgParserConf['preprocessorClass'];
68 } else {
69 $name = 'Preprocessor_DOM';
72 $wgParser->firstCallInit();
73 $this->mPreprocessor = new $name( $this );
76 /**
77 * Callback function for each revision, preprocessToObj()
78 * @param $rev Revision
80 public function processRevision( $rev ) {
81 $content = $rev->getContent( Revision::RAW );
83 if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
84 return;
87 try {
88 $this->mPreprocessor->preprocessToObj( strval( $content->getNativeData() ), 0 );
89 } catch ( Exception $e ) {
90 $this->error( "Caught exception " . $e->getMessage() . " in " . $rev->getTitle()->getPrefixedText() );
95 $maintClass = "PreprocessDump";
96 require_once RUN_MAINTENANCE_IF_MAIN;