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
7 * Copyright © 2011 Platonides - https://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
25 * @ingroup Maintenance
28 use MediaWiki\MediaWikiServices
;
30 require_once __DIR__
. '/dumpIterator.php';
33 * Maintenance script that takes page text out of an XML dump file and
34 * preprocesses it to obj.
36 * @ingroup Maintenance
38 class PreprocessDump
extends DumpIterator
{
40 /* Variables for dressing up as a parser */
41 public $mTitle = 'PreprocessDump';
42 public $mPPNodeCount = 0;
44 public function getStripList() {
45 $parser = MediaWikiServices
::getInstance()->getParser();
47 return $parser->getStripList();
50 public function __construct() {
51 parent
::__construct();
52 $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
53 $this->addOption( 'preprocessor', 'Preprocessor to use.', false, false );
56 public function getDbType() {
57 return Maintenance
::DB_NONE
;
60 public function checkOptions() {
61 global $wgParser, $wgParserConf, $wgPreprocessorCacheThreshold;
63 if ( !$this->hasOption( 'cache' ) ) {
64 $wgPreprocessorCacheThreshold = false;
67 if ( $this->hasOption( 'preprocessor' ) ) {
68 $name = $this->getOption( 'preprocessor' );
69 } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) {
70 $name = $wgParserConf['preprocessorClass'];
72 $name = Preprocessor_DOM
::class;
75 $wgParser->firstCallInit();
76 $this->mPreprocessor
= new $name( $this );
80 * Callback function for each revision, preprocessToObj()
81 * @param Revision $rev
83 public function processRevision( $rev ) {
84 $content = $rev->getContent( Revision
::RAW
);
86 if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT
) {
91 $this->mPreprocessor
->preprocessToObj( strval( $content->getText() ), 0 );
92 } catch ( Exception
$e ) {
93 $this->error( "Caught exception " . $e->getMessage() . " in "
94 . $rev->getTitle()->getPrefixedText() );
99 $maintClass = PreprocessDump
::class;
100 require_once RUN_MAINTENANCE_IF_MAIN
;