jenkins-bot has submitted this change and it was merged. ( 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. Removed whitespace. Improved SQL-Queries. Removed whitespace. Change-Id: I826aabaeea9f15d6a8a6ce71d908545e1b19df5d --- A maintenance/fixNS.php 1 file changed, 75 insertions(+), 0 deletions(-) Approvals: Robert Vogel: Looks good to me, approved jenkins-bot: Verified diff --git a/maintenance/fixNS.php b/maintenance/fixNS.php new file mode 100644 index 0000000..7e03aaf --- /dev/null +++ b/maintenance/fixNS.php @@ -0,0 +1,75 @@ +<?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() { + $dbr = wfGetDB( DB_MASTER ); + $res = $dbr->select( + "page", + array( "page_id", "page_title", "page_namespace" ), + "page_namespace = 0", + "page_namespace ".$dbr->buildLike( "%:%", $dbr->anyString() ) + ); + + if($res!=null){ + foreach( $res as $row ) { + $fields = get_object_vars( $row ); + $pageId = $fields[ "page_id" ]; + $pageTitle = $fields[ "page_title" ]; + $arr = explode( ":", $pageTitle, 2 ); + $pageNS = $arr[ 0 ]; + $pageName = $arr[ 1 ]; + $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 ) { + $dbr->update( + "page", + array( + "page_title = '".$pageName."'", + "page_namespace = ".$nsKey + ), + array( + "page_title = '".$nsData.":".$pageName."'", + "page_id = ".$pageId, + "page_namespace = 0" + ) + ); + $done = true; + } + } + + if( $done == true ) { + $this->output( " ... done\n" ); + } else { + $this->output( " ... query failed \n" ); + } + } + else { + $this->output( "No page in need of change found. \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: merged Gerrit-Change-Id: I826aabaeea9f15d6a8a6ce71d908545e1b19df5d Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation Gerrit-Branch: master Gerrit-Owner: Pmiguelpirzer <schmir...@gmail.com> Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com> Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz> Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz> Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits