Pmiguelpirzer has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404272 )

Change subject: fixNS.php: Added maintenance-script
......................................................................

fixNS.php: Added maintenance-script

Added maintenance-script for adding
pages with wrong entry of namespace
retrospectively to a namespace.

Needs merge into master.

Change-Id: I826aabaeea9f15d6a8a6ce71d908545e1b19df5d
---
A maintenance/fixNS.php
1 file changed, 56 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation 
refs/changes/72/404272/1

diff --git a/maintenance/fixNS.php b/maintenance/fixNS.php
new file mode 100644
index 0000000..c43b2ca
--- /dev/null
+++ b/maintenance/fixNS.php
@@ -0,0 +1,56 @@
+<?php
+
+require_once __DIR__ . '/Maintenance.php';
+
+/**
+ * Base class for adding pages with retrospectively to a namespace
+ *
+ * @ingroup Maintenance
+ */
+class FixNS extends Maintenance {
+
+    public function __construct() {
+        parent::__construct();
+        $this->addDescription( '' );
+    }
+
+    public function execute() {
+        $dbw = $this->getDB( DB_MASTER );
+        $res = $dbw->query( "SELECT * FROM page WHERE page_namespace = 0 AND 
page_title LIKE '%:%'" );
+
+        foreach( $res as $row ) {
+            $fields = get_object_vars( $row );
+            $pageId = $fields[ "page_id" ];
+            $pageTitle = $fields[ "page_title" ];
+            $arr = explode( ":", $pageTitle, 2 );
+            $pageNS = $arr[ 0 ];
+            $arrNS = $GLOBALS[ 'wgExtraNamespaces' ];
+            
+            if( in_array( $pageNS, $arrNS ) ) {
+                $this->output( "Found " . $pageNS . " as namespace. \n" );
+                $this->output( "Adding " . $pageTitle . " to the namespace " . 
$pageNS . ". \n" );
+                foreach( $arrNS as $nsKey => $nsData ) {
+                    if( $nsData == $pageNS ) {
+                        $dbw->query( "
+                            UPDATE page SET
+                            page_title = REPLACE(page_title, '$nsData:', ''),
+                            page_namespace = $nsKey
+                            WHERE page_title LIKE '$nsData:%' AND 
page_id=$pageId AND page_namespace=0"
+                        );
+                        $done = true;
+                    }
+                }
+                
+                if( $done == true ) {
+                    $this->output( " ... done\n" );
+                } else {
+                    $this->output( " ... query failed \n" );
+                }
+            }
+        }
+    }
+
+}
+
+$maintClass = "FixNS";
+require_once RUN_MAINTENANCE_IF_MAIN;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I826aabaeea9f15d6a8a6ce71d908545e1b19df5d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Pmiguelpirzer <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to