18require_once __DIR__ .
'/Maintenance.php';
29 parent::__construct();
31 $this->
addArg(
'api',
'API base url' );
32 $this->
addArg(
'index',
'index.php base url' );
33 $this->
addOption(
'username',
'User name of the script importer' );
38 $username = $this->
getOption(
'username',
false );
39 if ( $username ===
false ) {
40 $user = User::newSystemUser(
'ScriptImporter', [
'steal' =>
true ] );
42 $user = User::newFromName( $username );
44 '@phan-var User $user';
45 StubGlobalUser::setUser( $user );
47 $baseUrl = $this->
getArg( 1 );
49 $this->
output(
'Importing ' . count( $pageList ) .
" pages\n" );
51 $wikiPageFactory = $services->getWikiPageFactory();
52 $httpRequestFactory = $services->getHttpRequestFactory();
57 foreach ( $pageBatches as $pageBatch ) {
59 foreach ( $pageBatch as $page ) {
62 $this->
error(
"$page is an invalid title; it will not be imported\n" );
66 $this->
output(
"Importing $page\n" );
69 'title' =>
"MediaWiki:{$page}" ] );
70 $text = $httpRequestFactory->get(
$url, [], __METHOD__ );
72 $wikiPage = $wikiPageFactory->newFromTitle( $title );
73 $content = ContentHandler::makeContent( $text, $wikiPage->getTitle() );
75 $wikiPage->doUserEditContent( $content, $user,
"Importing from $url" );
90 $baseUrl = $this->
getArg( 0 );
96 get(
$url, [], __METHOD__ );
97 $result = FormatJson::decode( $strResult,
true );
100 foreach ( $result[
'query'][
'allpages'] as $page ) {
101 if ( str_ends_with( $page[
'title'],
'.js' ) ) {
102 strtok( $page[
'title'],
':' );
103 $pages[] = strtok(
'' );
107 if ( $page !==
null ) {
108 $this->
output(
"Fetched list up to {$page['title']}\n" );
111 if ( isset( $result[
'continue'] ) ) {
112 $data = array_replace( $data, $result[
'continue'] );
113 } elseif ( isset( $result[
'query-continue'][
'allpages'] ) ) {
114 $data = array_replace( $data, $result[
'query-continue'][
'allpages'] );
126require_once RUN_MAINTENANCE_IF_MAIN;
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Maintenance script to import all scripts in the MediaWiki namespace from a local site.
execute()
Do the actual work.
__construct()
Default constructor.
Base class for content handling.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
newBatchIterator( $source)
Wrap an entry iterator into a generator that returns batches of said entries.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.