Merge branch 'c0nnex-namespaces' into develop

This commit is contained in:
Daniel Kraus
2016-08-25 14:48:57 +02:00
4 changed files with 70 additions and 11 deletions

4
.gitignore vendored
View File

@ -5,3 +5,7 @@
gpl-2.0.txt gpl-2.0.txt
Maintenance.php Maintenance.php
doxygen_sqlite3.db doxygen_sqlite3.db
/LinkTitles.phpproj
/LinkTitles.phpproj.user
/LinkTitles.sln
/LinkTitles.v12.suo

View File

@ -65,6 +65,26 @@ class Cli extends \Maintenance {
true, // requires argument true, // requires argument
"s" "s"
); );
$this->addOption(
"page",
"page to process",
false, // not required
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
);
} }
/// Main function of the maintenance script. /// Main function of the maintenance script.
@ -72,20 +92,43 @@ class Cli extends \Maintenance {
/// if the `--start` option is given) and call LinkTitles::processPage() for /// if the `--start` option is given) and call LinkTitles::processPage() for
/// each page. /// each page.
public function execute() { public function execute() {
global $wgLinkTitlesNamespaces;
$index = intval($this->getOption('start', 0)); $index = intval($this->getOption('start', 0));
if ( $index < 0 ) { if ( $index < 0 ) {
$this->error('FATAL: Start index must be 0 or greater.', 1); $this->error('FATAL: Start index must be 0 or greater.', 1);
}; };
if ($this->hasOption('log'))
{
LinkTitles::$ltConsoleOutput = true;
}
if ($this->hasOption('debug'))
{
LinkTitles::$ltConsoleOutputDebug = true;
}
$pagename = strval($this->getOption('page'));
if ($pagename != null)
{
$curTitle = Title::newFromDBkey( $pagename );
LinkTitles::processPage($curTitle,RequestContext::getMain() );
$this->output("\nFinished parsing.\n");
return;
}
// get our Namespaces
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' );
// Connect to the database // Connect to the database
$dbr = $this->getDB( DB_SLAVE ); $dbr = $this->getDB( DB_SLAVE );
// Retrieve page names from the database. // Retrieve page names from the database.
$res = $dbr->select( $res = $dbr->select(
'page', 'page',
'page_title', array('page_title', 'page_namespace'),
array( array(
'page_namespace = 0', 'page_namespace IN ' . $namespacesClause,
), ),
__METHOD__, __METHOD__,
array( array(
@ -100,7 +143,7 @@ class Cli extends \Maintenance {
// Iterate through the pages; break if a time limit is exceeded. // Iterate through the pages; break if a time limit is exceeded.
foreach ( $res as $row ) { foreach ( $res as $row ) {
$index += 1; $index += 1;
$curTitle = $row->page_title; $curTitle = Title::makeTitleSafe( $row->page_namespace, $row->page_title);
$this->output( $this->output(
sprintf("\rPage #%d (%02.0f%%)", $index, $index / $numPages * 100) sprintf("\rPage #%d (%02.0f%%)", $index, $index / $numPages * 100)
); );

View File

@ -24,6 +24,9 @@
"LinkTitlesWordStartOnly": true, "LinkTitlesWordStartOnly": true,
"LinkTitlesWordEndOnly": true, "LinkTitlesWordEndOnly": true,
"LinkTitlesBatchTimeLimit": 1 "LinkTitlesBatchTimeLimit": 1
"LinkTitlesNamespaces": [
2
]
}, },
"AutoloadClasses": { "AutoloadClasses": {
"LinkTitles\\Extension": "includes/LinkTitles_Extension.php", "LinkTitles\\Extension": "includes/LinkTitles_Extension.php",

View File

@ -84,6 +84,10 @@ class Special extends \SpecialPage {
/// @param OutputPage $output Output page for the special page. /// @param OutputPage $output Output page for the special page.
private function process( \WebRequest &$request, \OutputPage &$output) { private function process( \WebRequest &$request, \OutputPage &$output) {
global $wgLinkTitlesTimeLimit; global $wgLinkTitlesTimeLimit;
global $wgLinkTitlesNamespaces;
// get our Namespaces
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' );
// Start the stopwatch // Start the stopwatch
$startTime = microtime(true); $startTime = microtime(true);
@ -106,7 +110,7 @@ class Special extends \SpecialPage {
else else
{ {
// No end index was given. Therefore, count pages now. // No end index was given. Therefore, count pages now.
$end = $this->countPages($dbr); $end = $this->countPages($dbr, $namespacesClause );
}; };
array_key_exists('r', $postValues) ? array_key_exists('r', $postValues) ?
@ -116,9 +120,9 @@ class Special extends \SpecialPage {
// Retrieve page names from the database. // Retrieve page names from the database.
$res = $dbr->select( $res = $dbr->select(
'page', 'page',
'page_title', array('page_title', 'page_namespace'),
array( array(
'page_namespace = 0', 'page_namespace IN ' . $namespacesClause,
), ),
__METHOD__, __METHOD__,
array( array(
@ -129,7 +133,7 @@ class Special extends \SpecialPage {
// Iterate through the pages; break if a time limit is exceeded. // Iterate through the pages; break if a time limit is exceeded.
foreach ( $res as $row ) { foreach ( $res as $row ) {
$curTitle = $row->page_title; $curTitle = Title::makeTitleSafe( $row->page_namespace, $row->page_title);
Extension::processPage($curTitle, $this->getContext()); Extension::processPage($curTitle, $this->getContext());
$start += 1; $start += 1;
@ -280,16 +284,21 @@ EOF
/// Counts the number of pages in a read-access wiki database ($dbr). /// Counts the number of pages in a read-access wiki database ($dbr).
/// @param $dbr Read-only `Database` object. /// @param $dbr Read-only `Database` object.
/// @returns Number of pages in the default namespace (0) of the wiki. /// @returns Number of pages in the default namespace (0) of the wiki.
<<<<<<< HEAD:includes/LinkTitles_Special.php
private function countPages( &$dbr ) { private function countPages( &$dbr ) {
=======
private function countPages(&$dbr, $namespacesClause) {
>>>>>>> 085a4032f07ef9200370e7561b5b22b4c05e287c:SpecialLinkTitles.php
$res = $dbr->select( $res = $dbr->select(
'page', 'page',
'page_id', array('pagecount' => "COUNT(page_id)"),
array( array(
'page_namespace = 0', 'page_namespace IN ' . $namespacesClause,
), ),
__METHOD__ __METHOD__
); );
return $res->numRows();
return $res->current()->pagecount;
} }
} }