Smuggli has uploaded a new change for review. https://gerrit.wikimedia.org/r/168299
Change subject: Rewrite of NamespaceNuker ...................................................................... Rewrite of NamespaceNuker All options of NamespaceNuker did not work or not correctly. I Rewrote the code of it because it is much easier to use MediaWiki. The benefit is that many steps are done by MediaWiki and there is no need that we do them. * Fixed bug with not correctly shown message in remove dialog Change-Id: I65c5a3ec7440563a3373fa1f572b33f312befa50 --- M NamespaceManager/NamespaceManager.class.php M NamespaceManager/NamespaceManager.setup.php D NamespaceManager/NamespaceNuker.php M NamespaceManager/i18n/de.json M NamespaceManager/i18n/en.json M NamespaceManager/i18n/qqq.json M NamespaceManager/includes/NamespaceNuker.php M NamespaceManager/resources/BS.NamespaceManager/NamespaceRemoveDialog.js M NamespaceManager/resources/BS.NamespaceManager/Panel.js 9 files changed, 147 insertions(+), 517 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions refs/changes/99/168299/1 diff --git a/NamespaceManager/NamespaceManager.class.php b/NamespaceManager/NamespaceManager.class.php index a942d35..af120a3 100644 --- a/NamespaceManager/NamespaceManager.class.php +++ b/NamespaceManager/NamespaceManager.class.php @@ -29,11 +29,11 @@ 'searched' => false ); - public static $aSortConditions = array( + public static $aSortConditions = array( 'sort' => '', 'dir' => '' ); - + public $aSortHelper = array( 'negative' => 0, 'positive' => 0 @@ -55,7 +55,7 @@ EXTINFO::STATUS => 'default', EXTINFO::PACKAGE => 'default', EXTINFO::URL => 'http://www.hallowelt.biz', - EXTINFO::DEPS => array( + EXTINFO::DEPS => array( 'bluespice' => '2.22.0', 'WikiAdmin' => '2.22.0', 'Preferences' => '2.22.0' @@ -85,19 +85,19 @@ $this->setHook( 'NamespaceManager::writeNamespaceConfiguration', 'onWriteNamespaceConfiguration', true ); //CR, RBV: This is suposed to return all constants! Not just system NS. - //At the moment the implementation relies on an hardcoded mapping, + //At the moment the implementation relies on an hardcoded mapping, //which is bad. We need to change this and make it more generic! $GLOBALS['bsSystemNamespaces'] = BsNamespaceHelper::getMwNamespaceConstants(); wfProfileOut( 'BS::'.__METHOD__ ); } - + /** * Add the sql file to database by executing the update.php * @global type $wgDBtype * @global array $wgExtNewTables * @param DatabaseUpdater $du - * @return boolean + * @return boolean */ public static function getSchemaUpdates( $updater ) { global $wgExtPGNewFields, $wgDBtype; @@ -150,7 +150,7 @@ } else { $updater->addExtensionField( 'bs_namespacemanager_backup_page', - 'page_content_model', + 'page_content_model', $dir . 'bs_namespacemanager_backup_page.patch.sql' ); $updater->addExtensionField( @@ -171,7 +171,7 @@ /** * returns if NS is empty or not * @param type $iNamespaceId - * @return boolean + * @return boolean */ public function isNamespaceEmpty( $iNamespaceId ) { if ( BsCore::checkAccessAdmission( 'wikiadmin' ) === false ) return true; @@ -195,10 +195,10 @@ $this->getOutput()->addModules( 'ext.bluespice.namespaceManager' ); BsExtensionManager::setContext( 'MW::NamespaceManagerShow' ); $aMetaFields = array( - array( - 'name' => 'id', - 'type' => 'int', - 'sortable' => true, + array( + 'name' => 'id', + 'type' => 'int', + 'sortable' => true, 'label' => wfMessage( 'bs-namespacemanager-label-id' )->plain() ), array( @@ -210,7 +210,7 @@ wfRunHooks( 'NamespaceManager::getMetaFields', array( &$aMetaFields ) ); $this->getOutput()->addJsConfigVars('bsNamespaceManagerMetaFields', $aMetaFields); - + return '<div id="bs-namespacemanager-grid"></div>'; } @@ -290,24 +290,24 @@ } public function onGetMetaFields( &$aMetaFields ) { - $aMetaFields[] = array( - 'name' => 'editable', - 'type' => 'boolean', + $aMetaFields[] = array( + 'name' => 'editable', + 'type' => 'boolean', 'label' => wfMessage( 'bs-namespacemanager-label-editable' )->plain() ); - $aMetaFields[] = array( - 'name' => 'subpages', - 'type' => 'boolean', + $aMetaFields[] = array( + 'name' => 'subpages', + 'type' => 'boolean', 'label' => wfMessage( 'bs-namespacemanager-label-subpages' )->plain() ); - $aMetaFields[] = array( - 'name' => 'searchable', - 'type' => 'boolean', + $aMetaFields[] = array( + 'name' => 'searchable', + 'type' => 'boolean', 'label' => wfMessage( 'bs-namespacemanager-label-searchable' )->plain() ); - $aMetaFields[] = array( - 'name' => 'content', - 'type' => 'boolean', + $aMetaFields[] = array( + 'name' => 'content', + 'type' => 'boolean', 'label' => wfMessage( 'bs-namespacemanager-label-content' )->plain() ); @@ -315,7 +315,7 @@ } public function onGetNamespaceData( &$aResults ) { - global $wgNamespacesWithSubpages, $wgContentNamespaces, + global $wgNamespacesWithSubpages, $wgContentNamespaces, $wgNamespacesToBeSearchedDefault, $bsSystemNamespaces; wfRunHooks( 'BSNamespaceManagerBeforeSetUsernamespaces', array( $this, &$bsSystemNamespaces ) ); $aUserNamespaces = self::getUserNamespaces(); @@ -342,7 +342,7 @@ public function onEditNamespace( &$aNamespaceDefinition, &$iNs, $aAdditionalSettings, $bUseInternalDefaults ) { if ( !$bUseInternalDefaults ) { if ( empty( $aNamespaceDefinition[$iNs] ) ) $aNamespaceDefinition[$iNs] = array(); - $aNamespaceDefinition[$iNs] += array( + $aNamespaceDefinition[$iNs] += array( 'content' => $aAdditionalSettings['content'], 'subpages' => $aAdditionalSettings['subpages'], 'searched' => $aAdditionalSettings['searchable'] ); @@ -427,7 +427,7 @@ return FormatJson::encode( self::setUserNamespaces( $aUserNamespaces ) ); } } else { - // TODO SU (04.07.11 12:13): Aus Gründen der Lesbarkeit würde ich + // TODO SU (04.07.11 12:13): Aus Gründen der Lesbarkeit würde ich // das direkt in die obige foreach-Schleife packen und den else- // Zweig hier weglassen. return FormatJson::encode( array( @@ -529,7 +529,7 @@ if ( !strstr( $sNamespace, '_'.$wgContLang->getNsText( NS_TALK ) ) ) { if ( isset( $aUserNamespaces[ ($iNS + 1) ] ) && strstr( $aUserNamespaces[ ($iNS + 1) ][ 'name' ], '_'.$wgContLang->getNsText( NS_TALK ) ) ) { - $aNamespacesToRemove[ ] = array( ($iNS + 1), 1 ); + $aNamespacesToRemove[] = array( ($iNS + 1), 1 ); $sNamespace = $aUserNamespaces[ ($iNS + 1) ][ 'name' ]; } } @@ -540,7 +540,8 @@ switch ( $iDoArticle ) { case 0: foreach ( $aNamespacesToRemove as $aNamespace ) { - if ( !NamespaceNuker::nukeNamespaceWithAllPages( $aNamespace[ 0 ] ) ) { + $iNs = $aNamespace[0]; + if ( !NamespaceNuker::removeAllNamespacePages( $iNs, $aUserNamespaces[$iNs]['name'] ) ) { $bErrors = true; } else { $aUserNamespaces[ $aNamespace[ 0 ] ] = false; @@ -549,7 +550,8 @@ break; case 1: foreach ( $aNamespacesToRemove as $aNamespace ) { - if ( !NamespaceNuker::removeAllPages( $aNamespace[ 0 ], $sNamespace, $aNamespace[ 1 ] ) ) { + $iNs = $aNamespace[0]; + if ( !NamespaceNuker::moveAllPagesIntoMain( $iNs, $aUserNamespaces[$iNs]['name'] ) ) { $bErrors = true; } else { $aUserNamespaces[ $aNamespace[ 0 ] ] = false; @@ -559,7 +561,8 @@ case 2: default: foreach ( $aNamespacesToRemove as $aNamespace ) { - if ( !NamespaceNuker::removeAllPagesWithSuffix( $aNamespace[ 0 ], $sNamespace, $aNamespace[ 1 ] ) ) { + $iNs = $aNamespace[0]; + if ( !NamespaceNuker::moveAllPagesIntoMain( $iNs, $aUserNamespaces[$iNs]['name'], true ) ) { $bErrors = true; } else { $aUserNamespaces[ $aNamespace[ 0 ] ] = false; @@ -583,7 +586,7 @@ /** * Get all namespaces, which are created with the NamespaceManager. * @param boolean $bFullDetails should the complete configuration of the namespaces be loaded - * @return array the namespace data + * @return array the namespace data */ protected static function getUserNamespaces( $bFullDetails = false ) { global $wgExtraNamespaces, $wgNamespacesWithSubpages, @@ -622,7 +625,7 @@ * @param array $aUserNamespaceDefinition the namespace configuration */ protected static function setUserNamespaces( $aUserNamespaceDefinition ) { - global $wgNamespacesWithSubpages, $wgContentNamespaces, + global $wgNamespacesWithSubpages, $wgContentNamespaces, $wgNamespacesToBeSearchedDefault, $bsSystemNamespaces; $oNamespaceManager = BsExtensionManager::getExtension( 'NamespaceManager' ); diff --git a/NamespaceManager/NamespaceManager.setup.php b/NamespaceManager/NamespaceManager.setup.php index 46712e2..f44db8c 100644 --- a/NamespaceManager/NamespaceManager.setup.php +++ b/NamespaceManager/NamespaceManager.setup.php @@ -21,7 +21,9 @@ 'bs-namespacemanager-willmovesuffix', 'bs-namespacemanager-deletewarning', 'bs-namespacemanager-pagepresent', - 'bs-namespacemanager-label-editable' + 'bs-namespacemanager-label-editable', + 'bs-ns_main', + 'bs-from-something' ), 'localBasePath' => $IP, 'remoteBasePath' => &$GLOBALS['wgScriptPath'] diff --git a/NamespaceManager/NamespaceNuker.php b/NamespaceManager/NamespaceNuker.php deleted file mode 100644 index 4fb21cd..0000000 --- a/NamespaceManager/NamespaceNuker.php +++ /dev/null @@ -1,236 +0,0 @@ -<?php - -/** - * NamespacerNuker - * @author Sebastian Ulbricht - */ -// Last review MRG (01.07.11 01:47) -class NamespaceNuker { - - protected static function PurgeRedundantText() { - global $wgDBtype; - $dbw = wfGetDB(DB_MASTER); - $dbw->begin(); - - $tbl_arc = $dbw->tableName('archive'); - $tbl_rev = $dbw->tableName('revision'); - $tbl_txt = $dbw->tableName('text'); - - # Get "active" text records from the revisions table - $res = $dbw->query("SELECT DISTINCT rev_text_id FROM $tbl_rev"); - while ($row = $dbw->fetchObject($res)) { - $cur[] = $row->rev_text_id; - } - - # Get "active" text records from the archive table - $res = $dbw->query("SELECT DISTINCT ar_text_id FROM $tbl_arc"); - while ($row = $dbw->fetchObject($res)) { - $cur[] = $row->ar_text_id; - } - - # Get the IDs of all text records not in these sets - $set = implode(', ', $cur); - $res = $dbw->query("SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )"); - $old = array(); - while ($row = $dbw->fetchObject($res)) { - $old[] = $row->old_id; - } - if (count($old)) { - $set = implode(', ', $old); - - $tbl_txt_bck = $wgDBtype == 'oracle' ? $dbw->tableName('bs_ns_bak_text') : $dbw->tableName('bs_namespacemanager_backup_text'); - $dbw->query("INSERT INTO $tbl_txt_bck SELECT * FROM $tbl_txt WHERE old_id IN ($set)"); - $dbw->query("DELETE FROM $tbl_txt WHERE old_id IN ( $set )"); - } - - $dbw->commit(); - } - - protected static function DeleteRevisions($revs) { - global $wgDBtype; - $dbw = wfGetDB(DB_MASTER); - $dbw->begin(); - $tbl_rev = $dbw->tableName('revision'); - if (count($revs)) { - $set = implode(', ', $revs); - $tbl_rev_bck = $wgDBtype == 'oracle' ? $dbw->tableName('bs_ns_bak_revision') : $dbw->tableName('bs_namespacemanager_backup_revision'); - $dbw->query("INSERT INTO $tbl_rev_bck SELECT * FROM $tbl_rev WHERE rev_id IN ( $set )"); - $dbw->query("DELETE FROM $tbl_rev WHERE rev_id IN ( $set )"); - } - $dbw->commit(); - } - - public static function removeAllPages($idNS, $nameNS, $toNS = 0) { - global $wgDBtype; - if (!$idNS) - return false; - $bnUser = RequestContext::getMain()->getUser(); - $idUser = $bnUser->getId(); - $nameUser = $bnUser->getName(); - - $dbw = wfgetDB(DB_MASTER); - $dbw->begin(); - $tbl_pag = $dbw->tableName('page'); - $tbl_rec_chg = $dbw->tableName('recentchanges'); - $idNS = $dbw->addQuotes($idNS); - $pages = array(); - $info = array(); - $renamed = 0; - - $res = $dbw->query("SELECT page_id, page_title, page_len, page_latest " . - "FROM $tbl_pag " . - "WHERE page_namespace = $idNS"); - while ($row = $dbw->fetchObject($res)) { - $pages[] = $row->page_title; - $info[$row->page_title] = array('page_title' => $row->page_title, - 'page_id' => $row->page_id, - 'last_id' => $row->page_latest, - 'page_len' => $row->page_len); - } - if (count($pages)) { - $set = implode('\', \'', $pages); - $res = $dbw->query("SELECT page_title " . - "FROM $tbl_pag " . - "WHERE page_namespace = 0 " . - " AND page_title IN ('$set')"); - $pages = array(); - while ($row = $dbw->fetchObject($res)) { - $pages[] = $row->page_title; - $info[$row->page_title]['page_title'] = $row->page_title . "_(from_$nameNS)"; - } - if (count($pages)) { - $set = implode('\', \'', $pages); - $dbw->query("UPDATE $tbl_pag " . - "SET page_title = CONCAT(page_title, '_(from_$nameNS)') " . - "WHERE page_namespace = $idNS " . - " AND page_title IN ('$set')"); - $renamed = $set; - } - if ($wgDBtype == 'postgres') { - $time = wfTimestamp(TS_POSTGRES, time()); - } else { - $time = date("YmdHis", time()); - } - foreach ($info as $page) { - $dbw->query("INSERT INTO $tbl_rec_chg " . - "(rc_timestamp, rc_cur_time, rc_user, rc_user_text, rc_namespace, rc_title, rc_comment, rc_minor ,rc_bot, rc_new, rc_cur_id, rc_this_oldid, " . - "rc_last_oldid, rc_type, rc_moved_to_ns, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted, rc_logid, rc_log_type) VALUES " . - "('$time', '$time', '$idUser', '$nameUser', $idNS, '" . $page['page_title'] . "', " . - // TODO SU (04.07.11 12:05): i18n - "'Diese Seite wurde vom Namespace \"$nameNS\" in den Mainspace verschoben, da der Namespace \"$nameNS\" gelöscht wurde.', " . - "0, 0, 0, " . $page['page_id'] . ", " . $page['last_id'] . ", 0, 3, 0, 0, '" . $_SERVER['REMOTE_ADDR'] . "', " . $page['page_len'] . ", " . - $page['page_len'] . ", 0, 0, 'move')"); - } - } - $dbw->query("UPDATE $tbl_pag " . - "SET page_namespace = $toNS " . - "WHERE page_namespace = $idNS"); - $dbw->query("UPDATE $tbl_rec_chg " . - "SET rc_namespace = $toNS " . - "WHERE rc_namespace = $idNS"); - $dbw->commit(); - - if ($renamed != 0) { - return $renamed; - } - return true; - } - - public static function removeAllPagesWithSuffix($idNS, $nameNS, $toNS = 0) { - if (!$idNS) { - return false; - } - - $dbw = wfgetDB(DB_MASTER); - $dbw->begin(); - $tbl_pag = $dbw->tableName('page'); - $tbl_rec_chg = $dbw->tableName('recentchanges'); - - $res = $dbw->query("SELECT page_id, page_title, page_len, page_latest " . - "FROM $tbl_pag " . - "WHERE page_namespace = $idNS"); - $info = array(); - while ($row = $dbw->fetchObject($res)) { - $info[$row_ > page_title] = array('page_title' => $row->page_title . "_(from_$nameNS)", - 'page_id' => $row->page_id, - 'last_id' => $row->page_latest, - 'page_len' => $row->page_len); - } - if ($wgDBtype == 'postgres') { - $time = wfTimestamp(TS_POSTGRES, time()); - } else { - $time = date("YmdHis", time()); - } - foreach ($info as $page) { - $dbw->query("INSERT INTO $tbl_rec_chg " . - "(rc_timestamp, rc_cur_time, rc_user, rc_user_text, rc_namespace, rc_title, rc_comment, rc_minor ,rc_bot, rc_new, rc_cur_id, rc_this_oldid, " . - "rc_last_oldid, rc_type, rc_moved_to_ns, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted, rc_logid, rc_log_type) VALUES " . - "('$time', '$time', '$idUser', '$nameUser', $idNS, '" . $page['page_title'] . "', " . - // TODO SU (04.07.11 12:05): i18n - "'Diese Seite wurde vom Namespace \"$nameNS\" in den Mainspace verschoben, da der Namespace \"$nameNS\" gelöscht wurde.', " . - "0, 0, 0, " . $page['page_id'] . ", " . $page['last_id'] . ", 0, 3, 0, 0, '" . $_SERVER['REMOTE_ADDR'] . "', " . $page['page_len'] . ", " . - $page['page_len'] . ", 0, 0, 'move')"); - } - - $dbw->query("UPDATE $tbl_pag " . - "SET page_title = CONCAT(page_title, '_(from_$nameNS)'), " . - " page_namespace = $toNS " . - "WHERE page_namespace = $idNS"); - $dbw->query("UPDATE $tbl_rec_chg " . - "SET rc_namespace = $toNS " . - "WHERE rc_namespace = $idNS"); - - $dbw->commit(); - return true; - } - - public static function nukeNamespaceWithAllPages($idNS) { - global $wgDBtype; - if (!$idNS) { - return false; - } - $dbw = wfgetDB(DB_MASTER); - $dbw->begin(); - - $tbl_pag = $dbw->tableName('page'); - $tbl_rev = $dbw->tableName('revision'); - $tbl_pag_bck = $wgDBtype == 'oracle' ? $dbw->tableName('bs_ns_bak_page') : $dbw->tableName('bs_namespacemanager_backup_page'); - $tbl_rec_chg = $dbw->tableName('recentchanges'); - $tbl_src_idx = $dbw->tableName('searchindex'); - $res = $dbw->query("SELECT page_title FROM $tbl_pag WHERE page_namespace = $idNS"); - $i_deleted = 0; - - while ($row = $dbw->fetchObject($res)) { - $title = Title::newFromText($row->page_title, $idNS); - $id = $title->getArticleID(); - - // Get corresponding revisions - $res2 = $dbw->query("SELECT rev_id FROM $tbl_rev WHERE rev_page = $id"); - $revs = array(); - while ($row2 = $dbw->fetchObject($res2)) { - $revs[] = $row2->rev_id; - } - $dbw->query("INSERT INTO $tbl_pag_bck SELECT * FROM $tbl_pag WHERE page_id = $id"); - // Delete revisions as appropriate - self::DeleteRevisions($revs); - $dbw->query("DELETE FROM $tbl_pag WHERE page_id = $id"); - $dbw->query("DELETE FROM $tbl_src_idx WHERE si_page = $id"); - - $i_deleted++; - } - self::PurgeRedundantText(true); - $dbw->query("DELETE FROM $tbl_rec_chg WHERE rc_namespace = $idNS"); - $dbw->commit(); - if ($i_deleted > 0) { - $res = $dbw->query("SELECT COUNT(*) AS pages FROM $tbl_pag"); - $row = $dbw->fetchObject($res); - $pages = $row->pages; - $dbw->update( - 'site_stats', array('ss_total_pages' => $pages), array('ss_row_id' => 1), __METHOD__ - ); - } - - return true; - } - -} \ No newline at end of file diff --git a/NamespaceManager/i18n/de.json b/NamespaceManager/i18n/de.json index e2b40b3..4ebca40 100644 --- a/NamespaceManager/i18n/de.json +++ b/NamespaceManager/i18n/de.json @@ -27,7 +27,9 @@ "bs-namespacemanager-labelnsname": "Namensraum-Name", "bs-namespacemanager-willdelete": "Werden gelöscht", "bs-namespacemanager-willmove": "Werden in \"{{int:bs-ns_main}}\" verschoben*", - "bs-namespacemanager-willmovesuffix": "Werden mit dem Suffix \"{{int:bs-from-something}}\" in \"{{int:bs-ns_main}}\" verschoben", + "bs-namespacemanager-willmovesuffix": "Werden mit dem Suffix \"$1\" in \"{{int:bs-ns_main}}\" verschoben", "bs-namespacemanager-deletewarning": "Bist du dir sicher, dass du den Namensraum löschen willst? Das Löschen eines Namensraums kann nicht rückgängig gemacht werden.", - "bs-namespacemanager-pagepresent": "Seiten in diesem Namensraum:" + "bs-namespacemanager-pagepresent": "Seiten in diesem Namensraum:", + "bs-namespacemanager-deletens-movepages": "Diese Seite wurde vom dem \"$1\" Namesraum in den \"{{int:bs-ns_main}}\" Namesraum verschoben, da der \"$1\" Namesraum gelöscht wurde.", + "bs-namespacemanager-deletens-deletepages": "Diese Seite wurde gelöscht, da ihr Namensraum \"$1\" gelöscht wurde." } diff --git a/NamespaceManager/i18n/en.json b/NamespaceManager/i18n/en.json index 4303421..e1aca6b 100644 --- a/NamespaceManager/i18n/en.json +++ b/NamespaceManager/i18n/en.json @@ -26,7 +26,9 @@ "bs-namespacemanager-labelnsname": "Namespace name", "bs-namespacemanager-willdelete": "Will be deleted", "bs-namespacemanager-willmove": "Will be moved into \"{{int:bs-ns_main}}\"", - "bs-namespacemanager-willmovesuffix": "Will be moved into \"{{int:bs-ns_main}}\" with the suffix \"{{int:bs-from-something}}\"", + "bs-namespacemanager-willmovesuffix": "Will be moved into \"{{int:bs-ns_main}}\" with the suffix \"$1\"", "bs-namespacemanager-deletewarning": "Are you sure that you want to delete this namespace? Deleting a namespace cannot be undone.", - "bs-namespacemanager-pagepresent": "Pages in this namespace:" + "bs-namespacemanager-pagepresent": "Pages in this namespace:", + "bs-namespacemanager-deletens-movepages": "This page has been moved from namespace \"$1\" to namespace \"{{int:bs-ns_main}}\", because namespace \"$1\" was deleted.", + "bs-namespacemanager-deletens-deletepages": "This page has been deleted, because namespace \"$1\" was deleted." } diff --git a/NamespaceManager/i18n/qqq.json b/NamespaceManager/i18n/qqq.json index bb653e2..efd6148 100644 --- a/NamespaceManager/i18n/qqq.json +++ b/NamespaceManager/i18n/qqq.json @@ -28,7 +28,9 @@ "bs-namespacemanager-labelnsname": "Label for name.\n{{Identical|Namespace name}}", "bs-namespacemanager-willdelete": "Checkbox label for will be deleted", "bs-namespacemanager-willmove": "Checkbox label for will be moved into the namespace NS_MAIN.\n\nRefers to {{msg-mw|Bs-ns main}}.", - "bs-namespacemanager-willmovesuffix": "Checkbox label for will be moved into the namespace NS_MAIN with the suffix \"{{int:bs-from-something}}\".\n\nParameters:\n* $1 - the name of the namespace which will be deleted\nRefers to:\n* {{msg-mw|Bs-ns main}}\n* {{msg-mw|Bs-from-something}}", + "bs-namespacemanager-willmovesuffix": "Checkbox label for will be moved into the namespace NS_MAIN with the suffix \"$1\".\n\nParameters:\n* $1 - is the BlueSpice message \"bs-from-something\" which includes the name of the namespace which will be deleted\nRefers to:\n* {{msg-mw|Bs-ns main}}", "bs-namespacemanager-deletewarning": "Text for are you sure that you want to delete this namespace? Deleting a namespace cannot be undone.", - "bs-namespacemanager-pagepresent": "Headline for pages in this namespace:\nHeadline for checkbox section" + "bs-namespacemanager-pagepresent": "Headline for pages in this namespace:\nHeadline for checkbox section", + "bs-namespacemanager-deletens-movepages": "Text for why a page was moved into NS_MAIN. Used as reason for moving a page. \n*$1 is the name of the namespace which was deleted. \n*Refers to {{msg-mw|Bs-ns main}}", + "bs-namespacemanager-deletens-deletepages": "Text for why a page was deleted. Used as reason for deleting a page.\n*$1 is the name of the namespace which was deleted." } diff --git a/NamespaceManager/includes/NamespaceNuker.php b/NamespaceManager/includes/NamespaceNuker.php index 4fb21cd..5d87c55 100644 --- a/NamespaceManager/includes/NamespaceNuker.php +++ b/NamespaceManager/includes/NamespaceNuker.php @@ -2,234 +2,90 @@ /** * NamespacerNuker + * @author Stephan Muggli <mug...@hallowelt.biz> * @author Sebastian Ulbricht */ -// Last review MRG (01.07.11 01:47) class NamespaceNuker { - protected static function PurgeRedundantText() { - global $wgDBtype; - $dbw = wfGetDB(DB_MASTER); - $dbw->begin(); - - $tbl_arc = $dbw->tableName('archive'); - $tbl_rev = $dbw->tableName('revision'); - $tbl_txt = $dbw->tableName('text'); - - # Get "active" text records from the revisions table - $res = $dbw->query("SELECT DISTINCT rev_text_id FROM $tbl_rev"); - while ($row = $dbw->fetchObject($res)) { - $cur[] = $row->rev_text_id; - } - - # Get "active" text records from the archive table - $res = $dbw->query("SELECT DISTINCT ar_text_id FROM $tbl_arc"); - while ($row = $dbw->fetchObject($res)) { - $cur[] = $row->ar_text_id; - } - - # Get the IDs of all text records not in these sets - $set = implode(', ', $cur); - $res = $dbw->query("SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )"); - $old = array(); - while ($row = $dbw->fetchObject($res)) { - $old[] = $row->old_id; - } - if (count($old)) { - $set = implode(', ', $old); - - $tbl_txt_bck = $wgDBtype == 'oracle' ? $dbw->tableName('bs_ns_bak_text') : $dbw->tableName('bs_namespacemanager_backup_text'); - $dbw->query("INSERT INTO $tbl_txt_bck SELECT * FROM $tbl_txt WHERE old_id IN ($set)"); - $dbw->query("DELETE FROM $tbl_txt WHERE old_id IN ( $set )"); - } - - $dbw->commit(); - } - - protected static function DeleteRevisions($revs) { - global $wgDBtype; - $dbw = wfGetDB(DB_MASTER); - $dbw->begin(); - $tbl_rev = $dbw->tableName('revision'); - if (count($revs)) { - $set = implode(', ', $revs); - $tbl_rev_bck = $wgDBtype == 'oracle' ? $dbw->tableName('bs_ns_bak_revision') : $dbw->tableName('bs_namespacemanager_backup_revision'); - $dbw->query("INSERT INTO $tbl_rev_bck SELECT * FROM $tbl_rev WHERE rev_id IN ( $set )"); - $dbw->query("DELETE FROM $tbl_rev WHERE rev_id IN ( $set )"); - } - $dbw->commit(); - } - - public static function removeAllPages($idNS, $nameNS, $toNS = 0) { - global $wgDBtype; - if (!$idNS) - return false; - $bnUser = RequestContext::getMain()->getUser(); - $idUser = $bnUser->getId(); - $nameUser = $bnUser->getName(); - - $dbw = wfgetDB(DB_MASTER); - $dbw->begin(); - $tbl_pag = $dbw->tableName('page'); - $tbl_rec_chg = $dbw->tableName('recentchanges'); - $idNS = $dbw->addQuotes($idNS); - $pages = array(); - $info = array(); - $renamed = 0; - - $res = $dbw->query("SELECT page_id, page_title, page_len, page_latest " . - "FROM $tbl_pag " . - "WHERE page_namespace = $idNS"); - while ($row = $dbw->fetchObject($res)) { - $pages[] = $row->page_title; - $info[$row->page_title] = array('page_title' => $row->page_title, - 'page_id' => $row->page_id, - 'last_id' => $row->page_latest, - 'page_len' => $row->page_len); - } - if (count($pages)) { - $set = implode('\', \'', $pages); - $res = $dbw->query("SELECT page_title " . - "FROM $tbl_pag " . - "WHERE page_namespace = 0 " . - " AND page_title IN ('$set')"); - $pages = array(); - while ($row = $dbw->fetchObject($res)) { - $pages[] = $row->page_title; - $info[$row->page_title]['page_title'] = $row->page_title . "_(from_$nameNS)"; - } - if (count($pages)) { - $set = implode('\', \'', $pages); - $dbw->query("UPDATE $tbl_pag " . - "SET page_title = CONCAT(page_title, '_(from_$nameNS)') " . - "WHERE page_namespace = $idNS " . - " AND page_title IN ('$set')"); - $renamed = $set; - } - if ($wgDBtype == 'postgres') { - $time = wfTimestamp(TS_POSTGRES, time()); - } else { - $time = date("YmdHis", time()); - } - foreach ($info as $page) { - $dbw->query("INSERT INTO $tbl_rec_chg " . - "(rc_timestamp, rc_cur_time, rc_user, rc_user_text, rc_namespace, rc_title, rc_comment, rc_minor ,rc_bot, rc_new, rc_cur_id, rc_this_oldid, " . - "rc_last_oldid, rc_type, rc_moved_to_ns, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted, rc_logid, rc_log_type) VALUES " . - "('$time', '$time', '$idUser', '$nameUser', $idNS, '" . $page['page_title'] . "', " . - // TODO SU (04.07.11 12:05): i18n - "'Diese Seite wurde vom Namespace \"$nameNS\" in den Mainspace verschoben, da der Namespace \"$nameNS\" gelöscht wurde.', " . - "0, 0, 0, " . $page['page_id'] . ", " . $page['last_id'] . ", 0, 3, 0, 0, '" . $_SERVER['REMOTE_ADDR'] . "', " . $page['page_len'] . ", " . - $page['page_len'] . ", 0, 0, 'move')"); - } - } - $dbw->query("UPDATE $tbl_pag " . - "SET page_namespace = $toNS " . - "WHERE page_namespace = $idNS"); - $dbw->query("UPDATE $tbl_rec_chg " . - "SET rc_namespace = $toNS " . - "WHERE rc_namespace = $idNS"); - $dbw->commit(); - - if ($renamed != 0) { - return $renamed; - } - return true; - } - - public static function removeAllPagesWithSuffix($idNS, $nameNS, $toNS = 0) { - if (!$idNS) { + public static function moveAllPagesIntoMain( $idNS, $nameNS, $bWithSuffix = false ) { + if ( !$idNS ) { return false; } - $dbw = wfgetDB(DB_MASTER); - $dbw->begin(); - $tbl_pag = $dbw->tableName('page'); - $tbl_rec_chg = $dbw->tableName('recentchanges'); + $dbw = wfgetDB( DB_MASTER ); + $res = $dbw->select( + 'page', + array( + 'page_id', + 'page_title', + 'page_len', + 'page_latest' + ), + array( + 'page_namespace' => $idNS + ) + ); - $res = $dbw->query("SELECT page_id, page_title, page_len, page_latest " . - "FROM $tbl_pag " . - "WHERE page_namespace = $idNS"); - $info = array(); - while ($row = $dbw->fetchObject($res)) { - $info[$row_ > page_title] = array('page_title' => $row->page_title . "_(from_$nameNS)", - 'page_id' => $row->page_id, - 'last_id' => $row->page_latest, - 'page_len' => $row->page_len); - } - if ($wgDBtype == 'postgres') { - $time = wfTimestamp(TS_POSTGRES, time()); - } else { - $time = date("YmdHis", time()); - } - foreach ($info as $page) { - $dbw->query("INSERT INTO $tbl_rec_chg " . - "(rc_timestamp, rc_cur_time, rc_user, rc_user_text, rc_namespace, rc_title, rc_comment, rc_minor ,rc_bot, rc_new, rc_cur_id, rc_this_oldid, " . - "rc_last_oldid, rc_type, rc_moved_to_ns, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted, rc_logid, rc_log_type) VALUES " . - "('$time', '$time', '$idUser', '$nameUser', $idNS, '" . $page['page_title'] . "', " . - // TODO SU (04.07.11 12:05): i18n - "'Diese Seite wurde vom Namespace \"$nameNS\" in den Mainspace verschoben, da der Namespace \"$nameNS\" gelöscht wurde.', " . - "0, 0, 0, " . $page['page_id'] . ", " . $page['last_id'] . ", 0, 3, 0, 0, '" . $_SERVER['REMOTE_ADDR'] . "', " . $page['page_len'] . ", " . - $page['page_len'] . ", 0, 0, 'move')"); - } + $sToken = RequestContext::getMain()->getUser()->getEditToken(); + foreach ( $res as $row ) { + $sTitle = ( $bWithSuffix ) + ? $row->page_title . ' ' . wfMessage( 'bs-from-something', $nameNS )->text() + : $row->page_title; - $dbw->query("UPDATE $tbl_pag " . - "SET page_title = CONCAT(page_title, '_(from_$nameNS)'), " . - " page_namespace = $toNS " . - "WHERE page_namespace = $idNS"); - $dbw->query("UPDATE $tbl_rec_chg " . - "SET rc_namespace = $toNS " . - "WHERE rc_namespace = $idNS"); - - $dbw->commit(); - return true; - } - - public static function nukeNamespaceWithAllPages($idNS) { - global $wgDBtype; - if (!$idNS) { - return false; - } - $dbw = wfgetDB(DB_MASTER); - $dbw->begin(); - - $tbl_pag = $dbw->tableName('page'); - $tbl_rev = $dbw->tableName('revision'); - $tbl_pag_bck = $wgDBtype == 'oracle' ? $dbw->tableName('bs_ns_bak_page') : $dbw->tableName('bs_namespacemanager_backup_page'); - $tbl_rec_chg = $dbw->tableName('recentchanges'); - $tbl_src_idx = $dbw->tableName('searchindex'); - $res = $dbw->query("SELECT page_title FROM $tbl_pag WHERE page_namespace = $idNS"); - $i_deleted = 0; - - while ($row = $dbw->fetchObject($res)) { - $title = Title::newFromText($row->page_title, $idNS); - $id = $title->getArticleID(); - - // Get corresponding revisions - $res2 = $dbw->query("SELECT rev_id FROM $tbl_rev WHERE rev_page = $id"); - $revs = array(); - while ($row2 = $dbw->fetchObject($res2)) { - $revs[] = $row2->rev_id; - } - $dbw->query("INSERT INTO $tbl_pag_bck SELECT * FROM $tbl_pag WHERE page_id = $id"); - // Delete revisions as appropriate - self::DeleteRevisions($revs); - $dbw->query("DELETE FROM $tbl_pag WHERE page_id = $id"); - $dbw->query("DELETE FROM $tbl_src_idx WHERE si_page = $id"); - - $i_deleted++; - } - self::PurgeRedundantText(true); - $dbw->query("DELETE FROM $tbl_rec_chg WHERE rc_namespace = $idNS"); - $dbw->commit(); - if ($i_deleted > 0) { - $res = $dbw->query("SELECT COUNT(*) AS pages FROM $tbl_pag"); - $row = $dbw->fetchObject($res); - $pages = $row->pages; - $dbw->update( - 'site_stats', array('ss_total_pages' => $pages), array('ss_row_id' => 1), __METHOD__ + $oParams = new DerivativeRequest( + RequestContext::getMain()->getRequest(), + array( + 'action' => 'move', + 'fromid' => $row->page_id, + 'to' => $sTitle, + 'reason' => wfMessage( 'bs-namespacemanager-deletens-movepages', $nameNS )->text(), + 'movetalk' => 1, + 'movesubpages' => 1, + 'noredirect' => 1, + 'token' => $sToken + ), + true ); + + $api = new ApiMain( $oParams, true ); + $api->execute(); } - + + return true; + } + + public static function removeAllNamespacePages( $idNS, $nameNS ) { + $dbw = wfgetDB( DB_MASTER ); + $res = $dbw->select( + 'page', + array( + 'page_id', + 'page_title', + 'page_len', + 'page_latest' + ), + array( + 'page_namespace' => $idNS + ) + ); + + $sToken = RequestContext::getMain()->getUser()->getEditToken(); + foreach ( $res as $row ) { + $oParams = new DerivativeRequest( + RequestContext::getMain()->getRequest(), + array( + 'action' => 'delete', + 'pageid' => $row->page_id, + 'reason' => wfMessage( 'bs-namespacemanager-deletens-deletepages', $nameNS )->text(), + 'token' => $sToken + ), + true + ); + + $api = new ApiMain( $oParams, true ); + $api->execute(); + } + return true; } diff --git a/NamespaceManager/resources/BS.NamespaceManager/NamespaceRemoveDialog.js b/NamespaceManager/resources/BS.NamespaceManager/NamespaceRemoveDialog.js index 5daf670..f35edfe 100644 --- a/NamespaceManager/resources/BS.NamespaceManager/NamespaceRemoveDialog.js +++ b/NamespaceManager/resources/BS.NamespaceManager/NamespaceRemoveDialog.js @@ -17,22 +17,21 @@ currentData: {}, selectedData: {}, afterInitComponent: function() { - + var msg = mw.message( 'bs-from-something', this.nsName ).text(); this.rgNamespacenuker = Ext.create('Ext.form.RadioGroup', { // Arrange radio buttons into two columns, distributed vertically columns: 1, vertical: true, items: [ - { boxLabel: mw.message('bs-namespacemanager-willdelete').text(), name: 'rb', inputValue: '0' }, - { boxLabel: mw.message('bs-namespacemanager-willmove').parse(), name: 'rb', inputValue: '1' }, - { boxLabel: mw.message('bs-namespacemanager-willmovesuffix', this.nsName).parse(), name: 'rb', inputValue: '2' } + { boxLabel: mw.message( 'bs-namespacemanager-willdelete' ).text(), name: 'rb', inputValue: '0' }, + { boxLabel: mw.message( 'bs-namespacemanager-willmove' ).text(), name: 'rb', inputValue: '1' }, + { boxLabel: mw.message( 'bs-namespacemanager-willmovesuffix', msg ).text(), name: 'rb', inputValue: '2' } ] }); - this.items = [{ - html: mw.message( 'bs-namespacemanager-deletewarning' ).plain() + html: mw.message( 'bs-namespacemanager-deletewarning' ).text() }, { - html: mw.message( 'bs-namespacemanager-pagepresent' ).plain() + html: mw.message( 'bs-namespacemanager-pagepresent' ).text() }, this.rgNamespacenuker ]; diff --git a/NamespaceManager/resources/BS.NamespaceManager/Panel.js b/NamespaceManager/resources/BS.NamespaceManager/Panel.js index 28387f6..5e30d17 100644 --- a/NamespaceManager/resources/BS.NamespaceManager/Panel.js +++ b/NamespaceManager/resources/BS.NamespaceManager/Panel.js @@ -19,8 +19,8 @@ var fieldDefs = mw.config.get('bsNamespaceManagerMetaFields'); var fields = []; var columns = []; - - //TODO: the "fieldDefs" should contain a "config" property that allows + + //TODO: the "fieldDefs" should contain a "config" property that allows //for more settings than just the few ones we process here for( var i = 0; i < fieldDefs.length; i++ ) { var fieldDef = fieldDefs[i]; @@ -43,7 +43,7 @@ } $(document).trigger('BSNamespaceManagerInitCompontent', [this, fields, columns]); - + this.strMain = Ext.create( 'Ext.data.JsonStore', { proxy: { type: 'ajax', @@ -81,7 +81,7 @@ this.dlgNamespaceAdd.on( 'ok', this.onDlgNamespaceAddOk, this ); } - //TODO: not nice. Decision on wether is "add" or "edit" shold be made + //TODO: not nice. Decision on wether is "add" or "edit" shold be made //by the dialog depending on the provided ID. I.e. -1 for "add" this.active = 'add'; this.dlgNamespaceAdd.setTitle( mw.message( 'bs-namespacemanager-tipadd' ).plain() ); @@ -105,9 +105,9 @@ var selectedRow = this.grdMain.getSelectionModel().getSelection(); var editable = selectedRow[0].get( 'editable' ); if ( editable === false ) { - bs.util.alert( + bs.util.alert( 'NMfail', - { + { textMsg: 'bs-namespacemanager-msgnoteditabledelete', titleMsg: 'bs-extjs-title-warning' } @@ -118,7 +118,7 @@ this.dlgNamespaceRemove = Ext.create( 'BS.NamespaceManager.NamespaceRemoveDialog', { - id:"bs-namespacemanager-remove-dlg", + id: "bs-namespacemanager-remove-dlg", nsName: selectedRow[0].get( 'name' ) } ); @@ -131,7 +131,7 @@ this.callParent( arguments ); }, onDlgNamespaceAddOk: function( sender, namespace ) { - var additionalSettings = this.getAdditionalSettings( namespace ); + var additionalSettings = this.getAdditionalSettings( namespace ); Ext.Ajax.request( { url: bs.util.getAjaxDispatcherUrl( 'NamespaceManager::addNamespace', @@ -223,13 +223,13 @@ }, renderMsgSuccess: function( responseObj ) { if ( responseObj.message.length ) { - bs.util.alert( + bs.util.alert( 'UMsuc', { text: responseObj.message, titleMsg: 'bs-extjs-title-success' - }, - { + }, + { ok: this.reloadStore, scope: this } @@ -245,24 +245,24 @@ } bs.util.alert( 'UMfail', - { + { text: message, titleMsg: 'bs-extjs-title-warning' }, - { + { ok: this.showDlgAgain, scope: this } ); return; } else if ( responseObj.message.length ) { - bs.util.alert( + bs.util.alert( 'UMfail', - { + { text: responseObj.message, titleMsg: 'bs-extjs-title-warning' }, - { + { ok: this.showDlgAgain, scope: this } -- To view, visit https://gerrit.wikimedia.org/r/168299 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I65c5a3ec7440563a3373fa1f572b33f312befa50 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions Gerrit-Branch: master Gerrit-Owner: Smuggli <mug...@hallowelt.biz> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits