public function execute()
 {
     global $wgUser;
     $username = $this->getOption('username', false);
     if ($username === false) {
         $user = User::newSystemUser('ScriptImporter', ['steal' => true]);
     } else {
         $user = User::newFromName($username);
     }
     $wgUser = $user;
     $baseUrl = $this->getArg(1);
     $pageList = $this->fetchScriptList();
     $this->output('Importing ' . count($pageList) . " pages\n");
     foreach ($pageList as $page) {
         $title = Title::makeTitleSafe(NS_MEDIAWIKI, $page);
         if (!$title) {
             $this->error("{$page} is an invalid title; it will not be imported\n");
             continue;
         }
         $this->output("Importing {$page}\n");
         $url = wfAppendQuery($baseUrl, ['action' => 'raw', 'title' => "MediaWiki:{$page}"]);
         $text = Http::get($url, [], __METHOD__);
         $wikiPage = WikiPage::factory($title);
         $content = ContentHandler::makeContent($text, $wikiPage->getTitle());
         $wikiPage->doEditContent($content, "Importing from {$url}", 0, false, $user);
     }
 }
Example #2
0
 public function execute()
 {
     global $wgCapitalLinks;
     if ($wgCapitalLinks) {
         $this->error("\$wgCapitalLinks is on -- no need for caps links cleanup.", true);
     }
     $this->user = User::newSystemUser('Conversion script', ['steal' => true]);
     $this->namespace = intval($this->getOption('namespace', 0));
     $this->dryrun = $this->hasOption('dry-run');
     $this->runTable(['table' => 'page', 'conds' => ['page_namespace' => $this->namespace], 'index' => 'page_id', 'callback' => 'processRow']);
 }
Example #3
0
 public function execute()
 {
     $this->user = User::newSystemUser('Conversion script', ['steal' => true]);
     $this->namespace = intval($this->getOption('namespace', 0));
     if (MWNamespace::isCapitalized($this->namespace)) {
         $this->output("Will be moving pages to first letter capitalized titles");
         $callback = 'processRowToUppercase';
     } else {
         $this->output("Will be moving pages to first letter lowercase titles");
         $callback = 'processRowToLowercase';
     }
     $this->dryrun = $this->hasOption('dry-run');
     $this->runTable(['table' => 'page', 'conds' => ['page_namespace' => $this->namespace], 'index' => 'page_id', 'callback' => $callback]);
 }
Example #4
0
 public function execute()
 {
     global $IP, $wgLocalDatabases, $wgUser;
     $username = wfMessage('spambot_username')->text();
     $wgUser = User::newSystemUser($username);
     if (!$wgUser) {
         $this->error("Invalid username specified in 'spambot_username' message: {$username}", true);
     }
     // Create the user if necessary
     if (!$wgUser->getId()) {
         $wgUser->addToDatabase();
     }
     $spec = $this->getArg();
     $like = LinkFilter::makeLikeArray($spec);
     if (!$like) {
         $this->error("Not a valid hostname specification: {$spec}", true);
     }
     if ($this->hasOption('all')) {
         // Clean up spam on all wikis
         $this->output("Finding spam on " . count($wgLocalDatabases) . " wikis\n");
         $found = false;
         foreach ($wgLocalDatabases as $wikiID) {
             $dbr = wfGetDB(DB_SLAVE, array(), $wikiID);
             $count = $dbr->selectField('externallinks', 'COUNT(*)', array('el_index' . $dbr->buildLike($like)), __METHOD__);
             if ($count) {
                 $found = true;
                 $cmd = wfShellWikiCmd("{$IP}/maintenance/cleanupSpam.php", array('--wiki', $wikiID, $spec));
                 passthru("{$cmd} | sed 's/^/{$wikiID}:  /'");
             }
         }
         if ($found) {
             $this->output("All done\n");
         } else {
             $this->output("None found\n");
         }
     } else {
         // Clean up spam on this wiki
         $dbr = wfGetDB(DB_SLAVE);
         $res = $dbr->select('externallinks', array('DISTINCT el_from'), array('el_index' . $dbr->buildLike($like)), __METHOD__);
         $count = $dbr->numRows($res);
         $this->output("Found {$count} articles containing {$spec}\n");
         foreach ($res as $row) {
             $this->cleanupArticle($row->el_from, $spec);
         }
         if ($count) {
             $this->output("Done\n");
         }
     }
 }
Example #5
0
 public function execute()
 {
     global $wgUser;
     $userName = $this->getOption('user', false);
     $summary = $this->getOption('summary', '');
     $minor = $this->hasOption('minor');
     $bot = $this->hasOption('bot');
     $autoSummary = $this->hasOption('autosummary');
     $noRC = $this->hasOption('no-rc');
     if ($userName === false) {
         $wgUser = User::newSystemUser('Maintenance script', array('steal' => true));
     } else {
         $wgUser = User::newFromName($userName);
     }
     if (!$wgUser) {
         $this->error("Invalid username", true);
     }
     if ($wgUser->isAnon()) {
         $wgUser->addToDatabase();
     }
     $title = Title::newFromText($this->getArg());
     if (!$title) {
         $this->error("Invalid title", true);
     }
     if ($this->hasOption('nocreate') && !$title->exists()) {
         $this->error("Page does not exist", true);
     } elseif ($this->hasOption('createonly') && $title->exists()) {
         $this->error("Page already exists", true);
     }
     $page = WikiPage::factory($title);
     # Read the text
     $text = $this->getStdin(Maintenance::STDIN_ALL);
     $content = ContentHandler::makeContent($text, $title);
     # Do the edit
     $this->output("Saving... ");
     $status = $page->doEditContent($content, $summary, ($minor ? EDIT_MINOR : 0) | ($bot ? EDIT_FORCE_BOT : 0) | ($autoSummary ? EDIT_AUTOSUMMARY : 0) | ($noRC ? EDIT_SUPPRESS_RC : 0));
     if ($status->isOK()) {
         $this->output("done\n");
         $exit = 0;
     } else {
         $this->output("failed\n");
         $exit = 1;
     }
     if (!$status->isGood()) {
         $this->output($status->getWikiText() . "\n");
     }
     exit($exit);
 }
Example #6
0
 public function execute()
 {
     $userName = $this->getOption('u', false);
     $reason = $this->getOption('r', '');
     $cascade = $this->hasOption('cascade');
     $protection = "sysop";
     if ($this->hasOption('semiprotect')) {
         $protection = "autoconfirmed";
     } elseif ($this->hasOption('unprotect')) {
         $protection = "";
     }
     if ($userName === false) {
         $user = User::newSystemUser('Maintenance script', array('steal' => true));
     } else {
         $user = User::newFromName($userName);
     }
     if (!$user) {
         $this->error("Invalid username", true);
     }
     // @todo FIXME: This is reset 7 lines down.
     $restrictions = array('edit' => $protection, 'move' => $protection);
     $t = Title::newFromText($this->getArg());
     if (!$t) {
         $this->error("Invalid title", true);
     }
     $restrictions = array();
     foreach ($t->getRestrictionTypes() as $type) {
         $restrictions[$type] = $protection;
     }
     # un/protect the article
     $this->output("Updating protection status... ");
     $page = WikiPage::factory($t);
     $status = $page->doUpdateRestrictions($restrictions, array(), $cascade, $reason, $user);
     if ($status->isOK()) {
         $this->output("done\n");
     } else {
         $this->output("failed\n");
     }
 }
Example #7
0
 public function execute()
 {
     $user = $this->getOption('user');
     $username = User::isIP($user) ? $user : User::getCanonicalName($user);
     if (!$username) {
         $this->error('Invalid username', true);
     }
     $bot = $this->hasOption('bot');
     $summary = $this->getOption('summary', $this->mSelf . ' mass rollback');
     $titles = array();
     $results = array();
     if ($this->hasOption('titles')) {
         foreach (explode('|', $this->getOption('titles')) as $title) {
             $t = Title::newFromText($title);
             if (!$t) {
                 $this->error('Invalid title, ' . $title);
             } else {
                 $titles[] = $t;
             }
         }
     } else {
         $titles = $this->getRollbackTitles($user);
     }
     if (!$titles) {
         $this->output('No suitable titles to be rolled back');
         return;
     }
     $doer = User::newSystemUser('Maintenance script', array('steal' => true));
     foreach ($titles as $t) {
         $page = WikiPage::factory($t);
         $this->output('Processing ' . $t->getPrefixedText() . '... ');
         if (!$page->commitRollback($user, $summary, $bot, $results, $doer)) {
             $this->output("done\n");
         } else {
             $this->output("failed\n");
         }
     }
 }
Example #8
0
 public function execute()
 {
     global $wgUser;
     $user = $this->getOption('user', false);
     $reason = $this->getOption('reason', '');
     $pageName = $this->getArg();
     $title = Title::newFromText($pageName);
     if (!$title) {
         $this->error("Invalid title", true);
     }
     if ($user === false) {
         $wgUser = User::newSystemUser('Command line script', array('steal' => true));
     } else {
         $wgUser = User::newFromName($user);
     }
     if (!$wgUser) {
         $this->error("Invalid username", true);
     }
     $archive = new PageArchive($title, RequestContext::getMain()->getConfig());
     $this->output("Undeleting " . $title->getPrefixedDBkey() . '...');
     $archive->undelete(array(), $reason);
     $this->output("done\n");
 }
 public function execute()
 {
     global $wgUser;
     # Change to current working directory
     $oldCwd = getcwd();
     chdir($oldCwd);
     # Options processing
     $user = $this->getOption('u', false);
     $reason = $this->getOption('r', '');
     $interval = $this->getOption('i', 0);
     $noredirects = $this->getOption('noredirects', false);
     if ($this->hasArg()) {
         $file = fopen($this->getArg(), 'r');
     } else {
         $file = $this->getStdin();
     }
     # Setup
     if (!$file) {
         $this->error("Unable to read file, exiting", true);
     }
     if ($user === false) {
         $wgUser = User::newSystemUser('Move page script', array('steal' => true));
     } else {
         $wgUser = User::newFromName($user);
     }
     if (!$wgUser) {
         $this->error("Invalid username", true);
     }
     # Setup complete, now start
     $dbw = $this->getDB(DB_MASTER);
     // @codingStandardsIgnoreStart Ignore avoid function calls in a FOR loop test part warning
     for ($linenum = 1; !feof($file); $linenum++) {
         // @codingStandardsIgnoreEnd
         $line = fgets($file);
         if ($line === false) {
             break;
         }
         $parts = array_map('trim', explode('|', $line));
         if (count($parts) != 2) {
             $this->error("Error on line {$linenum}, no pipe character");
             continue;
         }
         $source = Title::newFromText($parts[0]);
         $dest = Title::newFromText($parts[1]);
         if (is_null($source) || is_null($dest)) {
             $this->error("Invalid title on line {$linenum}");
             continue;
         }
         $this->output($source->getPrefixedText() . ' --> ' . $dest->getPrefixedText());
         $this->beginTransaction($dbw, __METHOD__);
         $mp = new MovePage($source, $dest);
         $status = $mp->move($wgUser, $reason, !$noredirects);
         if (!$status->isOK()) {
             $this->output("\nFAILED: " . $status->getWikiText());
         }
         $this->commitTransaction($dbw, __METHOD__);
         $this->output("\n");
         if ($interval) {
             sleep($interval);
         }
         wfWaitForSlaves();
     }
 }
Example #10
0
# Check Protection
if (isset($options['protect']) && isset($options['unprotect'])) {
    die("Cannot specify both protect and unprotect.  Only 1 is allowed.\n");
}
if (isset($options['protect']) && $options['protect'] == 1) {
    die("You must specify a protection option.\n");
}
# Prepare the list of allowed extensions
global $wgFileExtensions;
$extensions = isset($options['extensions']) ? explode(',', strtolower($options['extensions'])) : $wgFileExtensions;
# Search the path provided for candidates for import
$files = findFiles($dir, $extensions, isset($options['search-recursively']));
# Initialise the user for this operation
$user = isset($options['user']) ? User::newFromName($options['user']) : User::newSystemUser('Maintenance script', ['steal' => true]);
if (!$user instanceof User) {
    $user = User::newSystemUser('Maintenance script', ['steal' => true]);
}
$wgUser = $user;
# Get block check. If a value is given, this specified how often the check is performed
if (isset($options['check-userblock'])) {
    if (!$options['check-userblock']) {
        $checkUserBlock = 1;
    } else {
        $checkUserBlock = (int) $options['check-userblock'];
    }
} else {
    $checkUserBlock = false;
}
# Get --from
MediaWiki\suppressWarnings();
$from = $options['from'];
Example #11
0
 public function execute()
 {
     $userName = $this->getOption('user', false);
     $summary = $this->getOption('summary', 'Imported from text file');
     $useTimestamp = $this->hasOption('use-timestamp');
     $rc = $this->hasOption('rc');
     $bot = $this->hasOption('bot');
     $overwrite = $this->hasOption('overwrite');
     $prefix = $this->getOption('prefix', '');
     // Get all the arguments. A loop is required since Maintenance doesn't
     // support an arbitrary number of arguments.
     $files = [];
     $i = 0;
     while ($arg = $this->getArg($i++)) {
         if (file_exists($arg)) {
             $files[$arg] = file_get_contents($arg);
         } else {
             // use glob to support the Windows shell, which doesn't automatically
             // expand wildcards
             $found = false;
             foreach (glob($arg) as $filename) {
                 $found = true;
                 $files[$filename] = file_get_contents($filename);
             }
             if (!$found) {
                 $this->error("Fatal error: The file '{$arg}' does not exist!", 1);
             }
         }
     }
     $count = count($files);
     $this->output("Importing {$count} pages...\n");
     if ($userName === false) {
         $user = User::newSystemUser('Maintenance script', ['steal' => true]);
     } else {
         $user = User::newFromName($userName);
     }
     if (!$user) {
         $this->error("Invalid username\n", true);
     }
     if ($user->isAnon()) {
         $user->addToDatabase();
     }
     $exit = 0;
     $successCount = 0;
     $failCount = 0;
     $skipCount = 0;
     foreach ($files as $file => $text) {
         $pageName = $prefix . pathinfo($file, PATHINFO_FILENAME);
         $timestamp = $useTimestamp ? wfTimestamp(TS_UNIX, filemtime($file)) : wfTimestampNow();
         $title = Title::newFromText($pageName);
         // Have to check for # manually, since it gets interpreted as a fragment
         if (!$title || $title->hasFragment()) {
             $this->error("Invalid title {$pageName}. Skipping.\n");
             $skipCount++;
             continue;
         }
         $exists = $title->exists();
         $oldRevID = $title->getLatestRevID();
         $oldRev = $oldRevID ? Revision::newFromId($oldRevID) : null;
         $actualTitle = $title->getPrefixedText();
         if ($exists) {
             $touched = wfTimestamp(TS_UNIX, $title->getTouched());
             if (!$overwrite) {
                 $this->output("Title {$actualTitle} already exists. Skipping.\n");
                 $skipCount++;
                 continue;
             } elseif ($useTimestamp && intval($touched) >= intval($timestamp)) {
                 $this->output("File for title {$actualTitle} has not been modified since the " . "destination page was touched. Skipping.\n");
                 $skipCount++;
                 continue;
             }
         }
         $rev = new WikiRevision(ConfigFactory::getDefaultInstance()->makeConfig('main'));
         $rev->setText(rtrim($text));
         $rev->setTitle($title);
         $rev->setUserObj($user);
         $rev->setComment($summary);
         $rev->setTimestamp($timestamp);
         if ($exists && $overwrite && $rev->getContent()->equals($oldRev->getContent())) {
             $this->output("File for title {$actualTitle} contains no changes from the current " . "revision. Skipping.\n");
             $skipCount++;
             continue;
         }
         $status = $rev->importOldRevision();
         $newId = $title->getLatestRevID();
         if ($status) {
             $action = $exists ? 'updated' : 'created';
             $this->output("Successfully {$action} {$actualTitle}\n");
             $successCount++;
         } else {
             $action = $exists ? 'update' : 'create';
             $this->output("Failed to {$action} {$actualTitle}\n");
             $failCount++;
             $exit = 1;
         }
         // Create the RecentChanges entry if necessary
         if ($rc && $status) {
             if ($exists) {
                 if (is_object($oldRev)) {
                     $oldContent = $oldRev->getContent();
                     RecentChange::notifyEdit($timestamp, $title, $rev->getMinor(), $user, $summary, $oldRevID, $oldRev->getTimestamp(), $bot, '', $oldContent ? $oldContent->getSize() : 0, $rev->getContent()->getSize(), $newId, 1);
                 }
             } else {
                 RecentChange::notifyNew($timestamp, $title, $rev->getMinor(), $user, $summary, $bot, '', $rev->getContent()->getSize(), $newId, 1);
             }
         }
     }
     $this->output("Done! {$successCount} succeeded, {$skipCount} skipped.\n");
     if ($exit) {
         $this->error("Import failed with {$failCount} failed pages.\n", $exit);
     }
 }
 public function execute()
 {
     global $wgUser;
     # Change to current working directory
     $oldCwd = getcwd();
     chdir($oldCwd);
     # Options processing
     $username = $this->getOption('u', false);
     $reason = $this->getOption('r', '');
     $interval = $this->getOption('i', 0);
     if ($username === false) {
         $user = User::newSystemUser('Delete page script', array('steal' => true));
     } else {
         $user = User::newFromName($username);
     }
     if (!$user) {
         $this->error("Invalid username", true);
     }
     $wgUser = $user;
     if ($this->hasArg()) {
         $file = fopen($this->getArg(), 'r');
     } else {
         $file = $this->getStdin();
     }
     # Setup
     if (!$file) {
         $this->error("Unable to read file, exiting", true);
     }
     $dbw = $this->getDB(DB_MASTER);
     # Handle each entry
     // @codingStandardsIgnoreStart Ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
     for ($linenum = 1; !feof($file); $linenum++) {
         // @codingStandardsIgnoreEnd
         $line = trim(fgets($file));
         if ($line == '') {
             continue;
         }
         $title = Title::newFromText($line);
         if (is_null($title)) {
             $this->output("Invalid title '{$line}' on line {$linenum}\n");
             continue;
         }
         if (!$title->exists()) {
             $this->output("Skipping nonexistent page '{$line}'\n");
             continue;
         }
         $this->output($title->getPrefixedText());
         if ($title->getNamespace() == NS_FILE) {
             $img = wfFindFile($title, array('ignoreRedirect' => true));
             if ($img && $img->isLocal() && !$img->delete($reason)) {
                 $this->output(" FAILED to delete associated file... ");
             }
         }
         $page = WikiPage::factory($title);
         $error = '';
         $success = $page->doDeleteArticle($reason, false, 0, true, $error, $user);
         if ($success) {
             $this->output(" Deleted!\n");
         } else {
             $this->output(" FAILED to delete article\n");
         }
         if ($interval) {
             sleep($interval);
         }
         wfWaitForSlaves();
     }
 }
 public function execute()
 {
     $doDelete = $this->hasOption('delete');
     $doDeleteTalk = $this->hasOption('delete-talk');
     $langCode = $this->getOption('lang-code');
     $messageInfo = array('relevantPages' => 0, 'equalPages' => 0, 'equalPagesTalks' => 0, 'results' => array());
     $this->output('Checking for pages with default message...');
     // Load message information
     if ($langCode) {
         $langCodes = Language::fetchLanguageNames(null, 'mwfile');
         if ($langCode === '*') {
             // All valid lang-code subpages in NS_MEDIAWIKI that
             // override the messsages in that language
             foreach ($langCodes as $key => $value) {
                 $this->fetchMessageInfo($key, $messageInfo);
             }
             // Lastly, the base pages in NS_MEDIAWIKI that override
             // messages in content language
             $this->fetchMessageInfo(false, $messageInfo);
         } else {
             if (!isset($langCodes[$langCode])) {
                 $this->error('Invalid language code: ' . $langCode, 1);
             }
             $this->fetchMessageInfo($langCode, $messageInfo);
         }
     } else {
         $this->fetchMessageInfo(false, $messageInfo);
     }
     if ($messageInfo['equalPages'] === 0) {
         // No more equal messages left
         $this->output("\ndone.\n");
         return;
     }
     $this->output("\n{$messageInfo['relevantPages']} pages in the MediaWiki namespace " . "override messages.");
     $this->output("\n{$messageInfo['equalPages']} pages are equal to the default message " . "(+ {$messageInfo['equalPagesTalks']} talk pages).\n");
     if (!$doDelete) {
         $list = '';
         foreach ($messageInfo['results'] as $result) {
             $title = Title::makeTitle(NS_MEDIAWIKI, $result['title']);
             $list .= "* [[{$title}]]\n";
             if ($result['hasTalk']) {
                 $title = Title::makeTitle(NS_MEDIAWIKI_TALK, $result['title']);
                 $list .= "* [[{$title}]]\n";
             }
         }
         $this->output("\nList:\n{$list}\nRun the script again with --delete to delete these pages");
         if ($messageInfo['equalPagesTalks'] !== 0) {
             $this->output(" (include --delete-talk to also delete the talk pages)");
         }
         $this->output("\n");
         return;
     }
     $user = User::newSystemUser('MediaWiki default', array('steal' => true));
     if (!$user) {
         $this->error("Invalid username", true);
     }
     global $wgUser;
     $wgUser = $user;
     // Hide deletions from RecentChanges
     $user->addGroup('bot');
     // Handle deletion
     $this->output("\n...deleting equal messages (this may take a long time!)...");
     $dbw = $this->getDB(DB_MASTER);
     foreach ($messageInfo['results'] as $result) {
         wfWaitForSlaves();
         $dbw->ping();
         $title = Title::makeTitle(NS_MEDIAWIKI, $result['title']);
         $this->output("\n* [[{$title}]]");
         $page = WikiPage::factory($title);
         $error = '';
         // Passed by ref
         $success = $page->doDeleteArticle('No longer required', false, 0, true, $error, $user);
         if (!$success) {
             $this->output(" (Failed!)");
         }
         if ($result['hasTalk'] && $doDeleteTalk) {
             $title = Title::makeTitle(NS_MEDIAWIKI_TALK, $result['title']);
             $this->output("\n* [[{$title}]]");
             $page = WikiPage::factory($title);
             $error = '';
             // Passed by ref
             $success = $page->doDeleteArticle('Orphaned talk page of no longer required message', false, 0, true, $error, $user);
             if (!$success) {
                 $this->output(" (Failed!)");
             }
         }
     }
     $this->output("\n\ndone!\n");
 }
Example #14
0
# Check Protection
if (isset($options['protect']) && isset($options['unprotect'])) {
    die("Cannot specify both protect and unprotect.  Only 1 is allowed.\n");
}
if (isset($options['protect']) && $options['protect'] == 1) {
    die("You must specify a protection option.\n");
}
# Prepare the list of allowed extensions
global $wgFileExtensions;
$extensions = isset($options['extensions']) ? explode(',', strtolower($options['extensions'])) : $wgFileExtensions;
# Search the path provided for candidates for import
$files = findFiles($dir, $extensions, isset($options['search-recursively']));
# Initialise the user for this operation
$user = isset($options['user']) ? User::newFromName($options['user']) : User::newSystemUser('Maintenance script', array('steal' => true));
if (!$user instanceof User) {
    $user = User::newSystemUser('Maintenance script', array('steal' => true));
}
$wgUser = $user;
# Get block check. If a value is given, this specified how often the check is performed
if (isset($options['check-userblock'])) {
    if (!$options['check-userblock']) {
        $checkUserBlock = 1;
    } else {
        $checkUserBlock = (int) $options['check-userblock'];
    }
} else {
    $checkUserBlock = false;
}
# Get --from
MediaWiki\suppressWarnings();
$from = $options['from'];