Merge "Add passing ''italic'''s case to 'Unclosed and unmatched quotes' test"
[lhc/web/wiklou.git] / maintenance / preprocessDump.php
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 (C) 2011 Platonides - http://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( dirname( __FILE__ ) . '/dumpIterator.php' );
29
30 class PreprocessDump extends DumpIterator {
31
32 /* Variables for dressing up as a parser */
33 public $mTitle = 'PreprocessDump';
34 public $mPPNodeCount = 0;
35
36 public function getStripList() {
37 global $wgParser;
38 return $wgParser->getStripList();
39 }
40
41 public function __construct() {
42 parent::__construct();
43 $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
44 $this->addOption( 'preprocessor', 'Preprocessor to use.', false, false );
45 }
46
47 public function getDbType() {
48 return Maintenance::DB_NONE;
49 }
50
51 public function checkOptions() {
52 global $wgParser, $wgParserConf, $wgPreprocessorCacheThreshold;
53
54 if ( !$this->hasOption( 'cache' ) ) {
55 $wgPreprocessorCacheThreshold = false;
56 }
57
58 if ( $this->hasOption( 'preprocessor' ) ) {
59 $name = $this->getOption( 'preprocessor' );
60 } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) {
61 $name = $wgParserConf['preprocessorClass'];
62 } else {
63 $name = 'Preprocessor_DOM';
64 }
65
66 $wgParser->firstCallInit();
67 $this->mPreprocessor = new $name( $this );
68 }
69
70 /**
71 * Callback function for each revision, preprocessToObj()
72 * @param $rev Revision
73 */
74 public function processRevision( $rev ) {
75 try {
76 $this->mPreprocessor->preprocessToObj( $rev->getText(), 0 );
77 }
78 catch(Exception $e) {
79 $this->error("Caught exception " . $e->getMessage() . " in " . $rev->getTitle()->getPrefixedText() );
80 }
81 }
82 }
83
84 $maintClass = "PreprocessDump";
85 require_once( RUN_MAINTENANCE_IF_MAIN );
86