Isarra has submitted this change and it was merged.
Change subject: Coding style nitpicking and other such stuff that I'm famous for
......................................................................
Coding style nitpicking and other such stuff that I'm famous for
* dirname( __FILE__ ) --> __DIR__, because MW these days requires PHP 5.3 (or
5.4/5.5 in master/1.27) and older versions aren't supported
* spacing tweaks
* NULL --> null
* comment tweaks
* ACTUAL (POSSIBLE) BUGFIX: in grabDeletedText.php, function storeText(), added
support for using a non-$wgDBname database via the --db option (all other
functions in this file already supported that feature)
* print --> $this->output() for consistency
* else if --> elseif
Change-Id: Iaf1cacfe00becda793b4c3439b9b008622ec453e
---
M grabDeletedFiles.php
M grabDeletedText.php
M grabFiles.php
M grabImages.php
M grabInterwikiMap.php
M grabLogs.php
M grabNamespaceInfo.php
M grabNewText.php
M grabText.php
M grabUserGroups.php
10 files changed, 137 insertions(+), 140 deletions(-)
Approvals:
Isarra: Verified; Looks good to me, approved
diff --git a/grabDeletedFiles.php b/grabDeletedFiles.php
index f65a985..e692701 100755
--- a/grabDeletedFiles.php
+++ b/grabDeletedFiles.php
@@ -14,10 +14,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabDeletedFiles extends Maintenance {
public function __construct() {
@@ -33,6 +33,7 @@
public function execute() {
global $wgUploadDirectory;
+
$url = $this->getOption( 'url' );
$imagesurl = $this->getOption( 'imagesurl' );
if ( !$url || !$imagesurl ) {
@@ -55,7 +56,7 @@
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0)
Gecko/20100101 Firefox/13.0.1'
);
if ( !$bot->login() ) {
- print "Logged in as $user...\n";
+ $this->output( "Logged in as $user...\n" );
# Does the user have deletion rights?
$params = array(
@@ -165,7 +166,7 @@
'fa_user_text' => $entry['user'],
'fa_timestamp' => wfTimestamp( TS_MW,
$entry['timestamp'] ),
'fa_storage_group' => 'deleted',
- 'fa_media_type' => NULL,
+ 'fa_media_type' => null,
'fa_deleted' => 0
);
@@ -179,9 +180,9 @@
# We could get these other fields from logging, but they appear
to have no purpose so SCREW IT.
$e['fa_deleted_user'] = 0;
- $e['fa_deleted_timestamp'] = NULL;
- $e['fa_deleted_reason'] = NULL;
- $e['fa_archive_name'] = NULL; # UN:N; mediawiki figures it out
anyway.
+ $e['fa_deleted_timestamp'] = null;
+ $e['fa_deleted_reason'] = null;
+ $e['fa_archive_name'] = null; # UN:N; MediaWiki figures it out
anyway.
$dbw = wfGetDB( DB_MASTER, array(), $this->getOption( 'db',
$wgDBname ) );
@@ -191,7 +192,7 @@
# $this->output( "Changes committed to the database!\n" );
}
- # Base conversion function to make up for php's overwhelming crappiness
+ # Base conversion function to make up for PHP's overwhelming crappiness
# (base_convert doesn't work with large numbers)
# Borrowed from some guy's comments on php.net...
function str_sha1_36( $str ) {
@@ -214,4 +215,4 @@
}
$maintClass = 'GrabDeletedFiles';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabDeletedText.php b/grabDeletedText.php
index 014645c..4450ce1 100755
--- a/grabDeletedText.php
+++ b/grabDeletedText.php
@@ -15,10 +15,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabDeletedText extends Maintenance {
public function __construct() {
@@ -31,28 +31,28 @@
# $this->addOption( 'start', 'Revision at which to start',
false, true );
$this->addOption( 'startdate', 'Not yet implemented.', false,
true );
$this->addOption( 'enddate', 'End point (20121222142317,
2012-12-22T14:23:17T, etc); defaults to current timestamp.', false, true );
- $this->addOption( 'drcontinue', 'For the idiot brigade, api
continue to restart deleted revision process', false, true );
- $this->addOption( 'carlb', 'Tells the script to use lower api
limits', false, false );
+ $this->addOption( 'drcontinue', 'For the idiot brigade, API
continue to restart deleted revision process', false, true );
+ $this->addOption( 'carlb', 'Tells the script to use lower API
limits', false, false );
$this->addOption( 'lasttitle', 'Last title to get; useful for
working around content with a namespace/interwiki on top of it in mw1.19-',
false, true );
$this->addOption( 'badstart', 'Actual start point if bad
drcontinues force having to continue from earlier (mw1.19- issue)', false, true
);
$this->addOption( 'repair', 'Fill in holes in an existing
import', false, false );
-
}
public function execute() {
global $bot, $endDate, $wgDBname, $lastRevision, $endDate,
$lastTitle, $badStart, $repair;
+
$repair = $this->getOption( 'repair' );
$carlb = $this->getOption( 'carlb' );
$lastTitle = $this->getOption( 'lasttitle' );
$badStart = $this->getOption( 'badstart' );
$url = $this->getOption( 'url' );
- if( !$url ) {
+ if ( !$url ) {
$this->error( "The URL to the source wiki\'s api.php
must be specified!\n", true );
}
$user = $this->getOption( 'username' );
$password = $this->getOption( 'password' );
- if( !$user || !$password ) {
+ if ( !$user || !$password ) {
$this->error( "An admin username and password are
required.\n", true );
}
@@ -80,7 +80,7 @@
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0)
Gecko/20100101 Firefox/13.0.1'
);
if ( !$bot->login() ) {
- print "Logged in as $user...\n";
+ $this->output( "Logged in as $user...\n" );
# Does the user have deletion rights?
$params = array(
'list' => 'allusers',
@@ -95,7 +95,6 @@
} else {
$this->error( "Failed to log in as $user.", true );
}
-
$pageList = array();
$this->output( "\n" );
@@ -133,7 +132,7 @@
foreach ( $textNamespaces as $ns ) {
$more = true;
$drcontinue = $this->getOption( 'drcontinue' );
- if ( !$drcontinue ) {
+ if ( !$drcontinue ) {
$drcontinue = null;
} else {
# Parse start namespace from input string and
use
@@ -146,9 +145,9 @@
$nsStart = substr( $drcontinue, 0,
$nsStart );
}
if ( $ns < $nsStart ) {
- print "Skipping $ns\n";
+ $this->output( "Skipping $ns\n" );
continue;
- } else if ( $nsStart != $ns ) {
+ } elseif ( $nsStart != $ns ) {
$drcontinue = null;
}
}
@@ -175,7 +174,7 @@
if ( !$carlb && isset(
$params['drcontinue'] ) ) {
$oldcontinue =
$params['drcontinue'];
if ( substr( str_replace( ' ',
'_', $drcontinue ), 0, -15 ) < substr( str_replace( ' ', '_', $oldcontinue ),
0, -15 ) ) {
- $this->error( "Bad
drcontinue; " . str_replace( ' ', '_', $drcontinue ) . ' < ' . str_replace( '
', '_', $oldcontinue ), true );
+ $this->error( 'Bad
drcontinue; ' . str_replace( ' ', '_', $drcontinue ) . ' < ' . str_replace( '
', '_', $oldcontinue ), true );
}
}
$params['drcontinue'] = $drcontinue;
@@ -211,7 +210,6 @@
$this->output( "\n" );
$this->output( "Saved $revisions_processed deleted
revisions.\n" );
-
# Done.
}
@@ -219,14 +217,14 @@
function storeText( $text ) {
global $wgDBname;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER, array(), $this->getOption( 'db',
$wgDBname ) );
$old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
$dbw->insert(
'text',
array(
'old_id' => $old_id,
- 'old_text' => $text,
+ 'old_text' => $text,
'old_flags' => ''
),
__METHOD__
@@ -239,6 +237,7 @@
# Takes results in chunks because that's how the API returns pages -
with chunks of revisions.
function processDeletedRevisions( $pageChunk, $nsRevisions ) {
global $wgContLang, $wgDBname, $endDate, $lastTitle, $badStart,
$repair;
+
# Go back if we're not actually to the start point yet.
if ( $badStart && ( str_replace( ' ', '_', $badStart ) >
str_replace( ' ', '_', $pageChunk['title'] ) ) ) {
return $nsRevisions;
@@ -334,11 +333,12 @@
$nsRevisions++;
# $this->output( "Changes committed to the database!\n"
);
}
+
return $nsRevisions;
}
function sanitiseTitle( $ns, $title ) {
- if( $ns != 0 ) {
+ if ( $ns != 0 ) {
$title = preg_replace( '/^[^:]*?:/', '', $title );
}
$title = str_replace( ' ', '_', $title );
@@ -347,4 +347,4 @@
}
$maintClass = 'GrabDeletedText';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabFiles.php b/grabFiles.php
index a63b487..ae6540c 100755
--- a/grabFiles.php
+++ b/grabFiles.php
@@ -14,10 +14,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabFiles extends Maintenance {
public function __construct() {
@@ -63,9 +63,9 @@
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0)
Gecko/20100101 Firefox/13.0.1'
);
if ( !$bot->login() ) {
- print "Logged in as $user...\n";
+ $this->output( "Logged in as $user...\n" );
} else {
- print "WARNING: Failed to log in as $user.\n";
+ $this->output( "WARNING: Failed to log in as
$user.\n" );
}
} else {
$bot = new MediaWikiBot(
@@ -208,7 +208,7 @@
}
$urlparts = explode( '/', $fileurl );
- $urli = count($urlparts);
+ $urli = count( $urlparts );
$fileLocalPath = $wgUploadDirectory . '/' .
$urlparts[$urli - 3] . '/' . $urlparts[$urli - 2] . '/' . $name;
$fileLocalDir = $wgUploadDirectory . '/' .
$urlparts[$urli - 3] . '/' . $urlparts[$urli - 2] . '/';
@@ -241,4 +241,4 @@
}
$maintClass = 'GrabFiles';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabImages.php b/grabImages.php
index b363efd..08d1522 100755
--- a/grabImages.php
+++ b/grabImages.php
@@ -15,9 +15,9 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
+require_once 'Maintenance.php';
class GrabImages extends Maintenance {
public function __construct() {
@@ -51,7 +51,7 @@
$folder = $this->getWorkingDirectory();
wfMkdirParents( $folder );
- if( !file_exists( $folder ) ) {
+ if ( !file_exists( $folder ) ) {
$this->error( "Error creating temporary folder
{$folder}\n", true );
return false;
}
@@ -150,7 +150,7 @@
$more = !( $aifrom === null );
$i++;
}
- } while( $more );
+ } while ( $more );
if ( $imgGrabbed % 100 == 0 ) {
$this->output( 'grabbed: ' . $imgGrabbed . ', errors: '
. ( $imgGrabbed - $imgOK ) . "\n" );
@@ -165,7 +165,7 @@
$command = "{$wgPhpCli}
{$IP}/maintenance/importImages.php {$folder} {$fileExtensions} --conf {$conf}";
$result = wfShellExec( $command, $retval );
- if( $retval ) {
+ if ( $retval ) {
$this->output( "importImages script failed -
returned value was: $retval\n" );
return false;
} else {
@@ -181,9 +181,9 @@
* Simple wrapper for Http::get & file_put_content.
* Some basic checking is provided.
*
- * @param $url String: image URL
- * @param $path String: image local path, if null will take last part
of URL
- * @return Boolean: status
+ * @param string $url Image URL
+ * @param string $path Image local path, if null will take last part of
URL
+ * @return bool Status (true = success, false = failure)
*/
function saveFile( $url, $path = null ) {
if ( is_null( $path ) ) {
@@ -213,7 +213,7 @@
* The wiki's subdomain (e.g. "foo" in "foo.example.com/w/api.php) will
* be used as the directory name.
*
- * @return String: path to the place where the images will be stored
+ * @return string Path to the place where the images will be stored
*/
function getWorkingDirectory() {
// First remove the protocol from the URL...
@@ -224,7 +224,7 @@
$workingDirectory = $urlArray[0];
$retVal = ( wfIsWindows() ?
- dirname( __FILE__ ) . '/image-grabber/' .
$workingDirectory :
+ __DIR__ . '/image-grabber/' . $workingDirectory :
'/tmp/image-grabber/' . $workingDirectory );
return $retVal;
@@ -232,4 +232,4 @@
}
$maintClass = 'GrabImages';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabInterwikiMap.php b/grabInterwikiMap.php
index 4adeb0a..2c2f72f 100755
--- a/grabInterwikiMap.php
+++ b/grabInterwikiMap.php
@@ -24,10 +24,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabInterwikiMap extends Maintenance {
public function __construct() {
@@ -64,9 +64,9 @@
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0)
Gecko/20100101 Firefox/13.0.1'
);
if ( !$bot->login() ) {
- print "Logged in as $user...\n";
+ $this->output( "Logged in as $user...\n" );
} else {
- print "WARNING: Failed to log in as $user.\n";
+ $this->output( "WARNING: Failed to log in as
$user.\n" );
}
} else {
$bot = new MediaWikiBot(
@@ -99,7 +99,7 @@
continue;
}
# Check if prefix already exists
- else if ( $dbw->fetchObject( $dbw->query( "SELECT *
FROM `interwiki` WHERE `iw_prefix` = '{$iwEntry['prefix']}'" ) ) ) {
+ elseif ( $dbw->fetchObject( $dbw->query( "SELECT * FROM
`interwiki` WHERE `iw_prefix` = '{$iwEntry['prefix']}'" ) ) ) {
continue;
}
@@ -129,4 +129,4 @@
}
$maintClass = 'GrabInterwikiMap';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabLogs.php b/grabLogs.php
index b32443a..5a762f4 100755
--- a/grabLogs.php
+++ b/grabLogs.php
@@ -17,10 +17,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabLogs extends Maintenance {
public function __construct() {
@@ -32,7 +32,7 @@
$this->addOption( 'db', 'Database name, if we don\'t want to
write to $wgDBname', false, true );
$this->addOption( 'start', 'Start point in crazy zulu format
timestamp (2012-11-20T05:28:53Z)', false, true );
$this->addOption( 'end', 'Log time at which to stop (in crazy
zulu format timestamp)', false, true );
- $this->addOption( 'carlb', 'Tells the script to use lower api
limits', false, false );
+ $this->addOption( 'carlb', 'Tells the script to use lower API
limits', false, false );
}
public function execute() {
@@ -168,14 +168,14 @@
$title = $entry['title'];
$ns = $entry['ns'];
- if( $ns != 0 ) {
+ if ( $ns != 0 ) {
// HT hexmode & Skizzerz
$title = preg_replace( '/^[^:]*?:/', '', $title );
}
$title = str_replace( ' ', '_', $title );
$ts = wfTimestamp( TS_MW, $entry['timestamp'] );
- if( $ts < 20080000000000 && preg_match( '/^Wikia\-/',
$entry['user'], $matches ) ) {
+ if ( $ts < 20080000000000 && preg_match( '/^Wikia\-/',
$entry['user'], $matches ) ) {
# A tiny bug on Wikia in 2006-2007, affects ~10 log
entries only
if ( isset( $matches[0] ) ) {
$entry['user'] = substr( $entry['user'], 0, 6 );
@@ -202,55 +202,51 @@
# Supress warnings because if they're missing, they're missing
from the source,
# so not our problem
wfSuppressWarnings();
- if( $action == 'patrol' ) {
+ if ( $action == 'patrol' ) {
# Parameters: revision id, previous revision id,
automatic?
$e['params'] = $entry['patrol']['cur'] . "\n" .
$entry['patrol']['prev'] . "\n" .
$entry['patrol']['auto'];
- } elseif( $action == 'block' || $action == 'reblock' ) {
+ } elseif ( $action == 'block' || $action == 'reblock' ) {
# Parameters: Block expiration, options
$e['params'] = $entry['block']['duration'] . "\n" .
$entry['block']['flags'];
- } elseif( $action == 'move' || $action == 'move_redir' ) {
+ } elseif ( $action == 'move' || $action == 'move_redir' ) {
# Parameters: Target page title, redirect suppressed?
$e['params'] = $entry['move']['new_title'] . "\n";
- if( isset( $entry['move']['suppressedredirect'] ) ) {
+ if ( isset( $entry['move']['suppressedredirect'] ) ) {
# Suppressed redirect.
$e['params'] .= '1';
}
- } elseif( $entry['type'] == 'abusefilter' ) {
+ } elseif ( $entry['type'] == 'abusefilter' ) {
# [[Extension:AbuseFilter]]
# Parameters: filter revision id, filter number
- foreach( array_keys( $entry ) as $eh ){
- print "$eh: {$entry[$eh]}\n";
+ foreach ( array_keys( $entry ) as $eh ){
+ $this->output( "$eh: {$entry[$eh]}\n" );
}
$e['params'] = $entry[0] . "\n" . $entry[1];
-
- } elseif( $entry['type'] == 'interwiki' ) {
+ } elseif ( $entry['type'] == 'interwiki' ) {
# [[Extension:Interwiki]]
# Parameters: interwiki prefix, url, transcludable?,
local?
$e['params'] = $entry[0];
if ( $action == 'iw_add' || $action == 'iw_edit' ) {
$e['params'] .= "\n" . $entry[1] . "\n" .
$entry[2] . "\n" . $entry[3];
}
-
- } elseif( $action == 'renameuser' ) {
+ } elseif ( $action == 'renameuser' ) {
# [[Extension:Renameuser]]
# Parameter: new user name
$e['params'] = $entry[0];
-
- } elseif( $action == 'merge' ) {
+ } elseif ( $action == 'merge' ) {
# Parameters: target (merged into), latest revision date
$e['params'] = $entry[0] . "\n" . $entry[1];
-
- } elseif( $entry['type'] == 'protect' && ( $action == 'protect'
|| $action == 'modify' ) ) {
+ } elseif ( $entry['type'] == 'protect' && ( $action ==
'protect' || $action == 'modify' ) ) {
# Parameters: protection type and expiration, cascading
options
$e['params'] = ( isset( $entry[0] ) ? $entry[0] : '') .
( isset( $entry[1] ) ? "\n" . $entry[1] : '' );
- } elseif( $action == 'rights' ) {
+ } elseif ( $action == 'rights' ) {
# Parameters: old groups, new groups
$e['params'] = $entry['rights']['old'] . "\n" .
$entry['rights']['new'];
- } elseif( $entry['type'] == 'newusers' && ( $action == 'create'
|| $action == 'create2' ) ) {
+ } elseif ( $entry['type'] == 'newusers' && ( $action ==
'create' || $action == 'create2' ) ) {
# Parameter: new user ID (set to 0; mwauth can change
this upon login)
$e['params'] = ( isset( $entry[0]['param'] ) ?
$entry[0]['param'] : '' );
}
@@ -285,9 +281,8 @@
# $this->output( "Changes committed to the database!\n"
);
} catch ( Exception $e ) {
-
foreach ( array_values( $entry ) as $line ) {
- if ( $line == NULL ) {
+ if ( $line == null ) {
$this->output( "Exception caught;
something exploded\n" );
$line = 0;
}
@@ -301,4 +296,4 @@
}
$maintClass = 'GrabLogs';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabNamespaceInfo.php b/grabNamespaceInfo.php
index 518ed6c..ae97311 100755
--- a/grabNamespaceInfo.php
+++ b/grabNamespaceInfo.php
@@ -14,10 +14,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( "Maintenance.php" );
-require_once( "mediawikibot.class.php" );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabNamespaceInfo extends Maintenance {
public function __construct() {
@@ -27,9 +27,10 @@
}
public function execute() {
- global $bot, $wgDBname, $lastRevision;
+ global $bot;
+
$url = $this->getOption( 'url' );
- if( !$url ) {
+ if ( !$url ) {
$this->error( "The URL to the source wiki\'s api.php
must be specified!\n", true );
}
@@ -51,6 +52,7 @@
# Custom namespaces - make a list as these will need to be added to the
localsettings/whatever
function parseNamespaces() {
global $bot;
+
$params = array(
'meta' => 'siteinfo',
'siprop' => 'namespaces|namespacealiases'
@@ -64,7 +66,7 @@
$contentNamespaces = array();
$subpageNamespaces = array();
- foreach( array_keys( $namespaces ) as $ns ) {
+ foreach ( array_keys( $namespaces ) as $ns ) {
# Content?
if ( isset( $namespaces[$ns]['content'] ) ) {
$contentNamespaces[] = $ns;
@@ -78,13 +80,13 @@
}
}
$namespaceAliases = array(); # $wgNamespaceAliases['WP'] =
NS_PROJECT;
- foreach( $result['query']['namespacealiases'] as $nsa ) {
+ foreach ( $result['query']['namespacealiases'] as $nsa ) {
$namespaceAliases[$nsa['*']] = $nsa['id'];
}
# Show stuff
$this->output( "# Extra namespaces or some such\n" );
- foreach( array_keys( $customNamespaces ) as $ns ) {
+ foreach ( array_keys( $customNamespaces ) as $ns ) {
$namespaceName = str_replace( ' ', '_',
$customNamespaces[$ns] );
$this->output( '$wgExtraNamespaces[' . $ns . '] = "' .
$namespaceName . '";' . "\n" );
}
@@ -97,7 +99,7 @@
$this->output( "\t" . 'array( ' );
$this->output( $contentNamespaces[1] );
- foreach( array_keys( $contentNamespaces ) as $i ) {
+ foreach ( array_keys( $contentNamespaces ) as $i ) {
if ( $i > 1 ) {
$this->output( ",
{$contentNamespaces[$i]}" );
}
@@ -125,4 +127,4 @@
}
$maintClass = 'GrabNamespaceInfo';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabNewText.php b/grabNewText.php
index cc5d5ec..0fe2339 100755
--- a/grabNewText.php
+++ b/grabNewText.php
@@ -15,10 +15,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabNewText extends Maintenance {
public function __construct() {
@@ -34,8 +34,9 @@
public function execute() {
global $bot, $endDate, $startDate, $wgDBname, $lastRevision;
+
$url = $this->getOption( 'url' );
- if( !$url ) {
+ if ( !$url ) {
$this->error( "The URL to the source wiki\'s api.php
must be specified!\n", true );
}
@@ -69,9 +70,9 @@
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0)
Gecko/20100101 Firefox/13.0.1'
);
if ( !$bot->login() ) {
- print "Logged in as $user...\n";
+ $this->output( "Logged in as $user...\n" );
} else {
- print "Warning - failed to log in as $user.\n";
+ $this->output( "Warning - failed to log in as
$user.\n" );
}
} else {
$bot = new MediaWikiBot(
@@ -94,7 +95,6 @@
/**
* Get page edits and creations
- *
*/
function processRecentChanges() {
global $wgDBname, $endDate, $startDate, $bot;
@@ -144,11 +144,11 @@
$title = $entry['title'];
$ns = $entry['ns'];
- if( $ns != 0 ) {
+ if ( $ns != 0 ) {
$title = preg_replace( '/^[^:]*?:/',
'', $title );
}
$title = str_replace( ' ', '_', $title );
- $listKey = $ns."cowz".$title;
+ $listKey = $ns . 'cowz' . $title;
if ( in_array( $listKey, $blackList ) ) {
# Already done; continue
@@ -183,9 +183,8 @@
/**
* Get delete/move/import changes
- *
*/
- function processRecentLogs () {
+ function processRecentLogs() {
global $bot, $endDate, $wgDBname, $startDate;
$params = array(
@@ -248,13 +247,11 @@
}
$dbw->commit( __METHOD__ );
- }
- elseif ( $logEntry['action'] ==
'delete' ) {
+ } elseif ( $logEntry['action'] ==
'delete' ) {
$this->output( "$ns:$title was
deleted; updating....\n" );
# Delete our copy, move
revisions -> archive
$this->updateDeleted( $ns,
$title, $dbw );
- }
- elseif ( $logEntry['action'] ==
'restore' ) {
+ } elseif ( $logEntry['action'] ==
'restore' ) {
$this->output( "$ns:$title was
undeleted; updating....\n" );
# Remove any revisions from
archive and process as new
$page = $this->updateRestored(
$ns, $title, $dbw );
@@ -298,9 +295,9 @@
/**
* Handle an individual page.
*
- * @param $page Array: array retrieved from the API, containing pageid,
+ * @param array $page Array retrieved from the API, containing pageid,
* page title, namespace, protection status and
more...
- * @param $start Int: timestamp from which to get revisions; if this is
+ * @param int|null $start Timestamp from which to get revisions; if
this is
* defined, protection stuff is skipped.
*/
function processPage( $page, $start = null ) {
@@ -315,7 +312,7 @@
$this->output( "Processing page $pageID...\n" );
# Trim and convert displayed title to database page title
- if( $ns != 0 ) {
+ if ( $ns != 0 ) {
$title = preg_replace( '/^[^:]*?:/', '', $title );
}
$title = str_replace( ' ', '_', $title );
@@ -352,7 +349,7 @@
'page_id',
array(),
__METHOD__,
- array( 'ORDER BY' => 'page_id
desc' )
+ array( 'ORDER BY' => 'page_id
DESC' )
);
$localID = $resid + 1;
}
@@ -410,7 +407,6 @@
$rvcontinue = null;
# 'rvcontinue' in 1.20+, 'rvstartid' in 1.19-
$rvcontinuename = 'rvcontinue';
-
$params = array(
'prop' => 'revisions',
@@ -501,7 +497,6 @@
__METHOD__
);
} else {
-
$this->output( "Inserting page entry
$localID\n" );
$dbw->insert(
'page',
@@ -522,22 +517,23 @@
);
}
}
+
$dbw->commit();
}
/**
* Process an individual page revision.
*
- * @param $revision Array: array retrieved from the API, containing the
revision
+ * @param array $revision Array retrieved from the API, containing the
revision
* text, ID, timestamp, whether it was a minor edit
or
* not and much more
- * @param $page_e UNUSED
- * @param $prev_rev_id Integer: previous revision ID
(revision.rev_parent_id)
+ * @param int $page_id Page ID number
+ * @param int $prev_rev_id Previous revision ID (revision.rev_parent_id)
*/
function processRevision( $revision, $page_id, $prev_rev_id ) {
global $wgLang, $wgDBname, $lastRevision;
- if ( $revision['revid'] <= $lastRevision) {
+ if ( $revision['revid'] <= $lastRevision ) {
# Oops?
return false;
}
@@ -755,8 +751,9 @@
return false;
}
}
+
function sanitiseTitle( $ns, $title ) {
- if( $ns != 0 ) {
+ if ( $ns != 0 ) {
$title = preg_replace( '/^[^:]*?:/', '', $title );
}
$title = str_replace( ' ', '_', $title );
@@ -765,4 +762,4 @@
}
$maintClass = 'GrabNewText';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabText.php b/grabText.php
index 58639a8..6166934 100755
--- a/grabText.php
+++ b/grabText.php
@@ -12,10 +12,10 @@
*/
# Because we're not in maintenance
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabText extends Maintenance {
public function __construct() {
@@ -59,9 +59,9 @@
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0)
Gecko/20100101 Firefox/13.0.1'
);
if ( !$bot->login() ) {
- print "Logged in as $user...\n";
+ $this->output( "Logged in as $user...\n" );
} else {
- print "Warning - failed to log in as $user.\n";
+ $this->output( "Warning - failed to log in as
$user.\n" );
}
} else {
$bot = new MediaWikiBot(
@@ -150,7 +150,9 @@
if ( isset( $result['query-continue'] )
) {
if ( isset(
$result['query-continue']['allpages']['gapcontinue'] ) ) {
$gapfrom =
$result['query-continue']['allpages']['gapcontinue'];
- } else $gapfrom =
$result['query-continue']['allpages']['gapfrom'];
+ } else {
+ $gapfrom =
$result['query-continue']['allpages']['gapfrom'];
+ }
} else {
$gapfrom = null;
}
@@ -178,9 +180,9 @@
/**
* Handle an individual page.
*
- * @param $page Array: array retrieved from the API, containing pageid,
+ * @param array $page Array retrieved from the API, containing pageid,
* page title, namespace, protection status and
more...
- * @param $start Int: timestamp from which to get revisions; if this is
+ * @param int $start Timestamp from which to get revisions; if this is
* defined, protection stuff is skipped.
*/
function processPage( $page, $start = null ) {
@@ -195,7 +197,7 @@
$this->output( "Processing page $pageID: $title\n" );
# Trim and convert displayed title to database page title
- if( $ns != 0 ) {
+ if ( $ns != 0 ) {
$title = preg_replace( '/^[^:]*?:/', '', $title );
}
$title = str_replace( ' ', '_', $title );
@@ -419,7 +421,6 @@
/**
* Take the result from revision request and call processRevision
- *
*/
function processPageResult( $result, $localID, $last_rev_id ) {
$revisions = array_values( $result['query']['pages'] );
@@ -434,11 +435,11 @@
/**
* Process an individual page revision.
*
- * @param $revision Array: array retrieved from the API, containing the
revision
+ * @param array $revision Array retrieved from the API, containing the
revision
* text, ID, timestamp, whether it was a minor edit
or
* not and much more
- * @param $page_e UNUSED
- * @param $prev_rev_id Integer: previous revision ID
(revision.rev_parent_id)
+ * @param int $page_id Page ID
+ * @param int $prev_rev_id Previous revision ID (revision.rev_parent_id)
*/
function processRevision( $revision, $page_id, $prev_rev_id ) {
global $wgLang, $wgDBname, $lastRevision;
@@ -482,7 +483,7 @@
$text = $revision['*'];
$comment = $revision['comment'];
- if( $comment ) {
+ if ( $comment ) {
$comment = $wgLang->truncate( $comment, 255 );
} else {
$comment = '';
@@ -524,6 +525,7 @@
),
__METHOD__
);
+
# Insert tags, if any
if ( count( $tags ) ) {
$tagBlob = '';
@@ -603,7 +605,7 @@
}
function sanitiseTitle( $ns, $title ) {
- if( $ns != 0 ) {
+ if ( $ns != 0 ) {
$title = preg_replace( '/^[^:]*?:/', '', $title );
}
$title = str_replace( ' ', '_', $title );
@@ -613,4 +615,4 @@
}
$maintClass = 'GrabText';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/grabUserGroups.php b/grabUserGroups.php
index db8d40c..5e52f47 100755
--- a/grabUserGroups.php
+++ b/grabUserGroups.php
@@ -11,10 +11,10 @@
* Set the correct include path for PHP so that we can run this script from
* $IP/grabbers/ and we don't need to move this file to $IP/maintenance/.
*/
-ini_set( 'include_path', dirname( __FILE__ ) . '/../maintenance' );
+ini_set( 'include_path', __DIR__ . '/../maintenance' );
-require_once( 'Maintenance.php' );
-require_once( 'mediawikibot.class.php' );
+require_once 'Maintenance.php';
+require_once 'mediawikibot.class.php';
class GrabUserGroups extends Maintenance {
@@ -22,7 +22,7 @@
* Groups we don't want to import...
* @var array
*/
- var $badGroups = array( '*', 'user', 'autoconfirmed' );
+ public $badGroups = array( '*', 'user', 'autoconfirmed' );
public function __construct() {
parent::__construct();
@@ -106,7 +106,7 @@
}
/**
- * @param $bot MediaWikiBot
+ * @param MediaWikiBot $bot
* @return array
*/
public function getGroups( $bot ) {
@@ -127,7 +127,7 @@
/**
* Batch insert rows
- * @param $rows array
+ * @param array $rows
*/
public function insertRows( $rows ) {
global $wgDBname;
@@ -138,4 +138,4 @@
}
$maintClass = 'GrabUserGroups';
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;
--
To view, visit https://gerrit.wikimedia.org/r/278529
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaf1cacfe00becda793b4c3439b9b008622ec453e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/grabbers
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Isarra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits