28 require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 $this->
addArg(
'api',
'API base url' );
41 $this->
addArg(
'index',
'index.php base url' );
42 $this->
addOption(
'username',
'User name of the script importer' );
46 $username = $this->
getOption(
'username',
false );
47 if ( $username ===
false ) {
52 '@phan-var User $user';
53 StubGlobalUser::setUser( $user );
55 $baseUrl = $this->
getArg( 1 );
57 $this->
output(
'Importing ' . count( $pageList ) .
" pages\n" );
58 $services = MediaWikiServices::getInstance();
59 $wikiPageFactory = $services->getWikiPageFactory();
60 $httpRequestFactory = $services->getHttpRequestFactory();
62 foreach ( $pageList as $page ) {
65 $this->
error(
"$page is an invalid title; it will not be imported\n" );
69 $this->
output(
"Importing $page\n" );
72 'title' =>
"MediaWiki:{$page}" ] );
73 $text = $httpRequestFactory->get( $url, [], __METHOD__ );
75 $wikiPage = $wikiPageFactory->newFromTitle(
$title );
77 $wikiPage->doUserEditContent(
$content, $user,
"Importing from $url" );
90 $baseUrl = $this->
getArg( 0 );
95 $strResult = MediaWikiServices::getInstance()->getHttpRequestFactory()->
96 get( $url, [], __METHOD__ );
100 foreach ( $result[
'query'][
'allpages'] as $page ) {
101 if ( substr( $page[
'title'], -3 ) ===
'.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'] );
125 require_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...
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Maintenance script to import all scripts in the MediaWiki namespace from a local site.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
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.
static newFromName( $name, $validate='valid')
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.