Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310184

Change subject: refreshLinks: Add --namespace option
......................................................................

refreshLinks: Add --namespace option

This allows limiting refreshing data to pages in a single namespace.

Change-Id: I309058df98b638beb32adb1d663455a0c4aa1cec
---
M maintenance/refreshLinks.php
1 file changed, 24 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/310184/1

diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php
index 24c8c11..6c009a1 100644
--- a/maintenance/refreshLinks.php
+++ b/maintenance/refreshLinks.php
@@ -29,6 +29,12 @@
  * @ingroup Maintenance
  */
 class RefreshLinks extends Maintenance {
+
+       /**
+        * @var int|bool
+        */
+       protected $namespace = false;
+
        public function __construct() {
                parent::__construct();
                $this->addDescription( 'Refresh link tables' );
@@ -39,6 +45,7 @@
                $this->addOption( 'e', 'Last page id to refresh', false, true );
                $this->addOption( 'dfn-chunk-size', 'Maximum number of existent 
IDs to check per ' .
                        'query, default 100000', false, true );
+               $this->addOption( 'namespace', 'Only fix pages in this 
namespace', false );
                $this->addArg( 'start', 'Page_id to start from, default 1', 
false );
                $this->setBatchSize( 100 );
        }
@@ -51,6 +58,12 @@
                $start = (int)$this->getArg( 0 ) ?: null;
                $end = (int)$this->getOption( 'e' ) ?: null;
                $dfnChunkSize = (int)$this->getOption( 'dfn-chunk-size', 100000 
);
+               $ns = $this->getOption( 'namespace' );
+               if ( $ns === null ) {
+                       $this->namespace = false;
+               } else {
+                       $this->namespace = (int)$ns;
+               }
                if ( !$this->hasOption( 'dfn-only' ) ) {
                        $new = $this->getOption( 'new-only', false );
                        $redir = $this->getOption( 'redirects-only', false );
@@ -60,6 +73,12 @@
                } else {
                        $this->deleteLinksFromNonexistent( $start, $end, 
$this->mBatchSize, $dfnChunkSize );
                }
+       }
+
+       private function namespaceCond() {
+               return $this->namespace !== false
+                       ? [ 'page_namespace' => $this->namespace ]
+                       : [];
        }
 
        /**
@@ -92,7 +111,7 @@
                                "page_is_redirect=1",
                                "rd_from IS NULL",
                                self::intervalCond( $dbr, 'page_id', $start, 
$end ),
-                       ];
+                       ] + $this->namespaceCond();
 
                        $res = $dbr->select(
                                [ 'page', 'redirect' ],
@@ -121,7 +140,7 @@
                                [
                                        'page_is_new' => 1,
                                        self::intervalCond( $dbr, 'page_id', 
$start, $end ),
-                               ],
+                               ] + $this->namespaceCond(),
                                __METHOD__
                        );
                        $num = $res->numRows();
@@ -141,7 +160,7 @@
                        }
                } else {
                        if ( !$end ) {
-                               $maxPage = $dbr->selectField( 'page', 
'max(page_id)', false );
+                               $maxPage = $dbr->selectField( 'page', 
'max(page_id)', $this->namespaceCond() );
                                $maxRD = $dbr->selectField( 'redirect', 
'max(rd_from)', false );
                                $end = max( $maxPage, $maxRD );
                        }
@@ -265,7 +284,8 @@
                        $nextStart = $dbr->selectField(
                                'page',
                                'page_id',
-                               self::intervalCond( $dbr, 'page_id', $start, 
$end ),
+                               [ self::intervalCond( $dbr, 'page_id', $start, 
$end ) ]
+                               + $this->namespaceCond(),
                                __METHOD__,
                                [ 'ORDER BY' => 'page_id', 'OFFSET' => 
$chunkSize ]
                        );

-- 
To view, visit https://gerrit.wikimedia.org/r/310184
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I309058df98b638beb32adb1d663455a0c4aa1cec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to