X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FimportSiteScripts.php;h=e67d07719cf9aeace4c5d6ba7744043691585b26;hb=f4f5f41194ec3e417755579b392a4c09faf3db53;hp=c498280468d8d353773421b10db71b90b38db487;hpb=c8b2ad0c98ad36908b329ca1d8f408dec86bbf31;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/importSiteScripts.php b/maintenance/importSiteScripts.php index c498280468..e67d07719c 100644 --- a/maintenance/importSiteScripts.php +++ b/maintenance/importSiteScripts.php @@ -21,7 +21,7 @@ * @ingroup Maintenance */ -require_once( __DIR__ . '/Maintenance.php' ); +require_once __DIR__ . '/Maintenance.php'; /** * Maintenance script to import all scripts in the MediaWiki namespace from a @@ -65,42 +65,47 @@ class ImportSiteScripts extends Maintenance { $content = ContentHandler::makeContent( $text, $wikiPage->getTitle() ); $wikiPage->doEditContent( $content, "Importing from $url", 0, false, $user ); } - } protected function fetchScriptList() { $data = array( 'action' => 'query', - 'format' => 'php',//'json', + 'format' => 'json', 'list' => 'allpages', 'apnamespace' => '8', 'aplimit' => '500', + 'continue' => '', ); $baseUrl = $this->getArg( 0 ); $pages = array(); - do { + while ( true ) { $url = wfAppendQuery( $baseUrl, $data ); $strResult = Http::get( $url ); - //$result = FormatJson::decode( $strResult ); // Still broken - $result = unserialize( $strResult ); + $result = FormatJson::decode( $strResult, true ); - if ( !empty( $result['query']['allpages'] ) ) { - foreach ( $result['query']['allpages'] as $page ) { - if ( substr( $page['title'], -3 ) === '.js' ) { - strtok( $page['title'], ':' ); - $pages[] = strtok( '' ); - } + $page = null; + foreach ( $result['query']['allpages'] as $page ) { + if ( substr( $page['title'], -3 ) === '.js' ) { + strtok( $page['title'], ':' ); + $pages[] = strtok( '' ); } } - if ( !empty( $result['query-continue'] ) ) { - $data['apfrom'] = $result['query-continue']['allpages']['apfrom']; - $this->output( "Fetching new batch from {$data['apfrom']}\n" ); + + if ( $page !== null ) { + $this->output( "Fetched list up to {$page['title']}\n" ); } - } while ( isset( $result['query-continue'] ) ); - return $pages; + if ( isset( $result['continue'] ) ) { // >= 1.21 + $data = array_replace( $data, $result['continue'] ); + } elseif ( isset( $result['query-continue']['allpages'] ) ) { // <= 1.20 + $data = array_replace( $data, $result['query-continue']['allpages'] ); + } else { + break; + } + } + return $pages; } }