mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Rename maintenance script.
This commit is contained in:
@ -84,7 +84,6 @@ class Extension {
|
|||||||
* @returns bool True if the page exists, false if the page does not exist
|
* @returns bool True if the page exists, false if the page does not exist
|
||||||
*/
|
*/
|
||||||
public static function processPage( \Title $title, \RequestContext $context ) {
|
public static function processPage( \Title $title, \RequestContext $context ) {
|
||||||
self::ltLog('Processing '. $title->getPrefixedText());
|
|
||||||
$page = \WikiPage::factory($title);
|
$page = \WikiPage::factory($title);
|
||||||
$content = $page->getContent();
|
$content = $page->getContent();
|
||||||
if ( $content != null ) {
|
if ( $content != null ) {
|
||||||
@ -138,11 +137,11 @@ class Extension {
|
|||||||
public static function doAutolinksTag( $input, array $args, \Parser $parser, \PPFrame $frame ) {
|
public static function doAutolinksTag( $input, array $args, \Parser $parser, \PPFrame $frame ) {
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
$linker = new Linker( $config );
|
$linker = new Linker( $config );
|
||||||
$withLinks = $linker->linkContent( $parser->getTitle(), $input );
|
$title = $parser->getTitle();
|
||||||
|
$withLinks = $linker->linkContent( $title, $input );
|
||||||
$output = $parser->recursiveTagParse( $withLinks, $frame );
|
$output = $parser->recursiveTagParse( $withLinks, $frame );
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: ts=2:sw=2:noet:comments^=\:///
|
// vim: ts=2:sw=2:noet:comments^=\:///
|
||||||
|
@ -168,7 +168,7 @@ class Target {
|
|||||||
// (unlinked).
|
// (unlinked).
|
||||||
if ( $this->config->checkRedirect ) {
|
if ( $this->config->checkRedirect ) {
|
||||||
$redirectTitle = $this->getContent()->getUltimateRedirectTarget();
|
$redirectTitle = $this->getContent()->getUltimateRedirectTarget();
|
||||||
if ( $redirectTitle && $redirectTitle->equals( $fromtitle ) ) {
|
if ( $redirectTitle && $redirectTitle->equals( $fromTitle ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/**
|
||||||
* Copyright 2012-2017 Daniel Kraus <bovender@bovender.de> @bovender
|
* LinkTitles command line interface (CLI)/maintenance script
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Copyright 2012-2017 Daniel Kraus <bovender@bovender.de> @bovender
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* it under the terms of the GNU General Public License as published by
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* GNU General Public License for more details.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* This program is distributed in the hope that it will be useful,
|
||||||
* along with this program; if not, write to the Free Software
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* MA 02110-1301, USA.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
namespace LinkTitles;
|
namespace LinkTitles;
|
||||||
|
|
||||||
@ -46,15 +48,19 @@ else
|
|||||||
|
|
||||||
require_once( __DIR__ . "/includes/Extension.php" );
|
require_once( __DIR__ . "/includes/Extension.php" );
|
||||||
|
|
||||||
/// Core class of the maintanance script.
|
/**
|
||||||
/// @note Note that the execution of maintenance scripts is prohibited for
|
* Core class of the maintanance script.
|
||||||
/// an Apache web server due to a `.htaccess` file that declares `deny from
|
* @note Note that the execution of maintenance scripts is prohibited for
|
||||||
/// all`. Other webservers may exhibit different behavior. Be aware that
|
* an Apache web server due to a `.htaccess` file that declares `deny from
|
||||||
/// anybody who is able to execute this script may place a high load on the
|
* all`. Other webservers may exhibit different behavior. Be aware that
|
||||||
/// server.
|
* anybody who is able to execute this script may place a high load on the
|
||||||
/// @ingroup batch
|
* server.
|
||||||
|
* @ingroup batch
|
||||||
|
*/
|
||||||
class Cli extends \Maintenance {
|
class Cli extends \Maintenance {
|
||||||
/// The constructor adds a description and one option.
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->addDescription("Iterates over wiki pages and automatically adds links to other pages.");
|
$this->addDescription("Iterates over wiki pages and automatically adds links to other pages.");
|
||||||
@ -65,41 +71,45 @@ class Cli extends \Maintenance {
|
|||||||
true, // requires argument
|
true, // requires argument
|
||||||
"s"
|
"s"
|
||||||
);
|
);
|
||||||
$this->addOption(
|
$this->addOption(
|
||||||
"page",
|
"page",
|
||||||
"page name to process",
|
"page name to process",
|
||||||
false, // not required
|
false, // not required
|
||||||
true, // requires argument
|
true, // requires argument
|
||||||
"p"
|
"p"
|
||||||
);
|
);
|
||||||
$this->addOption(
|
// TODO: Add back logging options.
|
||||||
"log",
|
// TODO: Add configuration options.
|
||||||
"enables logging to console",
|
// $this->addOption(
|
||||||
false, // not required
|
// "log",
|
||||||
false, // requires no argument
|
// "enables logging to console",
|
||||||
"l"
|
// false, // not required
|
||||||
);
|
// false, // requires no argument
|
||||||
$this->addOption(
|
// "l"
|
||||||
"debug",
|
// );
|
||||||
"enables debug logging to console",
|
// $this->addOption(
|
||||||
false, // not required
|
// "debug",
|
||||||
false // requires no argument
|
// "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,
|
* Main function of the maintenance script.
|
||||||
/// if the `--start` option is given) and call LinkTitles::processPage() for
|
* Will iterate over all pages in the wiki (starting at a certain index,
|
||||||
/// each page.
|
* if the `--start` option is given) and call LinkTitles::processPage() for
|
||||||
|
* each page.
|
||||||
|
*/
|
||||||
public function execute() {
|
public function execute() {
|
||||||
if ($this->hasOption('log'))
|
// if ($this->hasOption('log'))
|
||||||
{
|
// {
|
||||||
Extension::$ltConsoleOutput = true;
|
// Extension::$ltConsoleOutput = true;
|
||||||
}
|
// }
|
||||||
if ($this->hasOption('debug'))
|
// if ($this->hasOption('debug'))
|
||||||
{
|
// {
|
||||||
Extension::$ltConsoleOutputDebug = true;
|
// Extension::$ltConsoleOutputDebug = true;
|
||||||
}
|
// }
|
||||||
if ( $this->hasOption('page') ) {
|
if ( $this->hasOption('page') ) {
|
||||||
if ( !$this->hasOption( 'start' ) ) {
|
if ( !$this->hasOption( 'start' ) ) {
|
||||||
$this->singlePage();
|
$this->singlePage();
|
||||||
@ -113,10 +123,14 @@ class Cli extends \Maintenance {
|
|||||||
if ( $startIndex < 0 ) {
|
if ( $startIndex < 0 ) {
|
||||||
$this->error( 'FATAL: Start index must be 0 or greater.', 1 );
|
$this->error( 'FATAL: Start index must be 0 or greater.', 1 );
|
||||||
};
|
};
|
||||||
$this->allPages( $startIndex);
|
$this->allPages( $startIndex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes a single page.
|
||||||
|
* @return bool True on success, false on failure.
|
||||||
|
*/
|
||||||
private function singlePage() {
|
private function singlePage() {
|
||||||
$pageName = strval( $this->getOption( 'page' ) );
|
$pageName = strval( $this->getOption( 'page' ) );
|
||||||
$this->output( "Processing single page: '$pageName'\n" );
|
$this->output( "Processing single page: '$pageName'\n" );
|
||||||
@ -131,17 +145,22 @@ class Cli extends \Maintenance {
|
|||||||
return $success;
|
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 ) {
|
private function allPages( $index = 0 ) {
|
||||||
global $wgLinkTitlesNamespaces;
|
$config = new Config();
|
||||||
|
|
||||||
// Retrieve page names from the database.
|
// Retrieve page names from the database.
|
||||||
$dbr = $this->getDB( DB_SLAVE );
|
$dbr = $this->getDB( DB_SLAVE );
|
||||||
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ', $wgLinkTitlesNamespaces ) . ')' );
|
$nameSpacesClause = str_replace( '_', ' ','(' . implode( ', ', $config->nameSpaces ) . ')' );
|
||||||
$res = $dbr->select(
|
$res = $dbr->select(
|
||||||
'page',
|
'page',
|
||||||
array( 'page_title', 'page_namespace' ),
|
array( 'page_title', 'page_namespace' ),
|
||||||
array(
|
array(
|
||||||
'page_namespace IN ' . $namespacesClause,
|
'page_namespace IN ' . $nameSpacesClause,
|
||||||
),
|
),
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
array(
|
Reference in New Issue
Block a user