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
;
29 use MediaWiki\Storage\RevisionRecord
;
31 require_once __DIR__
. '/dumpIterator.php';
34 * Maintenance script that takes page text out of an XML dump file and
35 * preprocesses it to obj.
37 * @ingroup Maintenance
39 class PreprocessDump
extends DumpIterator
{
41 /* Variables for dressing up as a parser */
42 public $mTitle = 'PreprocessDump';
43 public $mPPNodeCount = 0;
45 public function getStripList() {
46 $parser = MediaWikiServices
::getInstance()->getParser();
48 return $parser->getStripList();
51 public function __construct() {
52 parent
::__construct();
53 $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
54 $this->addOption( 'preprocessor', 'Preprocessor to use.', false, false );
57 public function getDbType() {
58 return Maintenance
::DB_NONE
;
61 public function checkOptions() {
62 global $wgParserConf, $wgPreprocessorCacheThreshold;
64 if ( !$this->hasOption( 'cache' ) ) {
65 $wgPreprocessorCacheThreshold = false;
68 if ( $this->hasOption( 'preprocessor' ) ) {
69 $name = $this->getOption( 'preprocessor' );
70 } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) {
71 $name = $wgParserConf['preprocessorClass'];
73 $name = Preprocessor_DOM
::class;
76 MediaWikiServices
::getInstance()->getParser()->firstCallInit();
77 $this->mPreprocessor
= new $name( $this );
81 * Callback function for each revision, preprocessToObj()
82 * @param Revision $rev
84 public function processRevision( $rev ) {
85 $content = $rev->getContent( RevisionRecord
::RAW
);
87 if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT
) {
92 $this->mPreprocessor
->preprocessToObj( strval( $content->getText() ), 0 );
93 } catch ( Exception
$e ) {
94 $this->error( "Caught exception " . $e->getMessage() . " in "
95 . $rev->getTitle()->getPrefixedText() );
100 $maintClass = PreprocessDump
::class;
101 require_once RUN_MAINTENANCE_IF_MAIN
;