32require_once __DIR__ .
'/Maintenance.php';
43 parent::__construct();
45 $this->
addArg(
'api',
'API base url' );
46 $this->
addArg(
'index',
'index.php base url' );
47 $this->
addOption(
'username',
'User name of the script importer' );
52 $username = $this->
getOption(
'username',
false );
53 if ( $username ===
false ) {
54 $user = User::newSystemUser(
'ScriptImporter', [
'steal' =>
true ] );
56 $user = User::newFromName( $username );
58 '@phan-var User $user';
59 StubGlobalUser::setUser( $user );
61 $baseUrl = $this->
getArg( 1 );
63 $this->
output(
'Importing ' . count( $pageList ) .
" pages\n" );
65 $wikiPageFactory = $services->getWikiPageFactory();
66 $httpRequestFactory = $services->getHttpRequestFactory();
71 foreach ( $pageBatches as $pageBatch ) {
73 foreach ( $pageBatch as $page ) {
76 $this->
error(
"$page is an invalid title; it will not be imported\n" );
80 $this->
output(
"Importing $page\n" );
83 'title' =>
"MediaWiki:{$page}" ] );
84 $text = $httpRequestFactory->get(
$url, [], __METHOD__ );
86 $wikiPage = $wikiPageFactory->newFromTitle( $title );
87 $content = ContentHandler::makeContent( $text, $wikiPage->getTitle() );
89 $wikiPage->doUserEditContent( $content, $user,
"Importing from $url" );
100 'apnamespace' =>
'8',
104 $baseUrl = $this->
getArg( 0 );
110 get(
$url, [], __METHOD__ );
111 $result = FormatJson::decode( $strResult,
true );
114 foreach ( $result[
'query'][
'allpages'] as $page ) {
115 if ( str_ends_with( $page[
'title'],
'.js' ) ) {
116 strtok( $page[
'title'],
':' );
117 $pages[] = strtok(
'' );
121 if ( $page !==
null ) {
122 $this->
output(
"Fetched list up to {$page['title']}\n" );
125 if ( isset( $result[
'continue'] ) ) {
126 $data = array_replace( $data, $result[
'continue'] );
127 } elseif ( isset( $result[
'query-continue'][
'allpages'] ) ) {
128 $data = array_replace( $data, $result[
'query-continue'][
'allpages'] );
140require_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.
A content handler knows how do deal with a specific type of content on a wiki page.
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.