Rename maintenance script.

This commit is contained in:
Daniel Kraus
2017-08-27 22:52:44 +02:00
parent 1e27f47750
commit 38284b11a1
3 changed files with 74 additions and 56 deletions

View File

@ -84,7 +84,6 @@ class Extension {
* @returns bool True if the page exists, false if the page does not exist
*/
public static function processPage( \Title $title, \RequestContext $context ) {
self::ltLog('Processing '. $title->getPrefixedText());
$page = \WikiPage::factory($title);
$content = $page->getContent();
if ( $content != null ) {
@ -138,11 +137,11 @@ class Extension {
public static function doAutolinksTag( $input, array $args, \Parser $parser, \PPFrame $frame ) {
$config = new Config();
$linker = new Linker( $config );
$withLinks = $linker->linkContent( $parser->getTitle(), $input );
$title = $parser->getTitle();
$withLinks = $linker->linkContent( $title, $input );
$output = $parser->recursiveTagParse( $withLinks, $frame );
return $output;
}
}
// vim: ts=2:sw=2:noet:comments^=\:///

View File

@ -168,7 +168,7 @@ class Target {
// (unlinked).
if ( $this->config->checkRedirect ) {
$redirectTitle = $this->getContent()->getUltimateRedirectTarget();
if ( $redirectTitle && $redirectTitle->equals( $fromtitle ) ) {
if ( $redirectTitle && $redirectTitle->equals( $fromTitle ) ) {
return false;
}
};

View File

@ -1,5 +1,7 @@
<?php
/*
/**
* LinkTitles command line interface (CLI)/maintenance script
*
* Copyright 2012-2017 Daniel Kraus <bovender@bovender.de> @bovender
*
* This program is free software; you can redistribute it and/or modify
@ -46,15 +48,19 @@ else
require_once( __DIR__ . "/includes/Extension.php" );
/// Core class of the maintanance script.
/// @note Note that the execution of maintenance scripts is prohibited for
/// an Apache web server due to a `.htaccess` file that declares `deny from
/// all`. Other webservers may exhibit different behavior. Be aware that
/// anybody who is able to execute this script may place a high load on the
/// server.
/// @ingroup batch
/**
* Core class of the maintanance script.
* @note Note that the execution of maintenance scripts is prohibited for
* an Apache web server due to a `.htaccess` file that declares `deny from
* all`. Other webservers may exhibit different behavior. Be aware that
* anybody who is able to execute this script may place a high load on the
* server.
* @ingroup batch
*/
class Cli extends \Maintenance {
/// The constructor adds a description and one option.
/**
* Constructor.
*/
public function __construct() {
parent::__construct();
$this->addDescription("Iterates over wiki pages and automatically adds links to other pages.");
@ -72,34 +78,38 @@ class Cli extends \Maintenance {
true, // requires argument
"p"
);
$this->addOption(
"log",
"enables logging to console",
false, // not required
false, // requires no argument
"l"
);
$this->addOption(
"debug",
"enables debug logging to console",
false, // not required
false // requires no argument
);
// TODO: Add back logging options.
// TODO: Add configuration options.
// $this->addOption(
// "log",
// "enables logging to console",
// false, // not required
// false, // requires no argument
// "l"
// );
// $this->addOption(
// "debug",
// "enables debug logging to console",
// false, // not required
// false // requires no argument
// );
}
/// Main function of the maintenance script.
/// Will iterate over all pages in the wiki (starting at a certain index,
/// if the `--start` option is given) and call LinkTitles::processPage() for
/// each page.
/*
* Main function of the maintenance script.
* Will iterate over all pages in the wiki (starting at a certain index,
* if the `--start` option is given) and call LinkTitles::processPage() for
* each page.
*/
public function execute() {
if ($this->hasOption('log'))
{
Extension::$ltConsoleOutput = true;
}
if ($this->hasOption('debug'))
{
Extension::$ltConsoleOutputDebug = true;
}
// if ($this->hasOption('log'))
// {
// Extension::$ltConsoleOutput = true;
// }
// if ($this->hasOption('debug'))
// {
// Extension::$ltConsoleOutputDebug = true;
// }
if ( $this->hasOption('page') ) {
if ( !$this->hasOption( 'start' ) ) {
$this->singlePage();
@ -117,6 +127,10 @@ class Cli extends \Maintenance {
}
}
/**
* Processes a single page.
* @return bool True on success, false on failure.
*/
private function singlePage() {
$pageName = strval( $this->getOption( 'page' ) );
$this->output( "Processing single page: '$pageName'\n" );
@ -131,17 +145,22 @@ class Cli extends \Maintenance {
return $success;
}
/**
* Process all pages in the Wiki.
* @param integer $index Index of the start page.
* @return bool True on success, false on failure.
*/
private function allPages( $index = 0 ) {
global $wgLinkTitlesNamespaces;
$config = new Config();
// Retrieve page names from the database.
$dbr = $this->getDB( DB_SLAVE );
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ', $wgLinkTitlesNamespaces ) . ')' );
$nameSpacesClause = str_replace( '_', ' ','(' . implode( ', ', $config->nameSpaces ) . ')' );
$res = $dbr->select(
'page',
array( 'page_title', 'page_namespace' ),
array(
'page_namespace IN ' . $namespacesClause,
'page_namespace IN ' . $nameSpacesClause,
),
__METHOD__,
array(