Cicalese has submitted this change and it was merged.

Change subject: initial commit
......................................................................


initial commit

Change-Id: I642fbc6df42f0e64b599f85818ddaba3d31b1707
---
A SafeDelete.alias.php
A SafeDelete.class.php
A SafeDelete.php
A i18n/en.json
A i18n/qqq.json
5 files changed, 273 insertions(+), 0 deletions(-)

Approvals:
  Cicalese: Verified; Looks good to me, approved



diff --git a/SafeDelete.alias.php b/SafeDelete.alias.php
new file mode 100644
index 0000000..a3e6e68
--- /dev/null
+++ b/SafeDelete.alias.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * Copyright (c) 2015 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+$specialPageAliases = array();
+
+/** English */
+$specialPageAliases['en'] = array(
+       'SafeDelete' => array(
+               'SafeDelete', 'Safe Delete'
+       )
+);
diff --git a/SafeDelete.class.php b/SafeDelete.class.php
new file mode 100644
index 0000000..fc4bb3b
--- /dev/null
+++ b/SafeDelete.class.php
@@ -0,0 +1,171 @@
+<?php
+
+/*
+ * Copyright (c) 2015 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+class SafeDelete extends UnlistedSpecialPage {
+
+       public function __construct() {
+               parent::__construct( 'SafeDelete' );
+       }
+
+       function execute( $par ) {
+
+               $this->setHeaders();
+               $this->outputHeader();
+
+               if ( !$this->getUser()->isAllowed( 'delete' ) ) {
+                       $this->displayRestrictionError();
+                       return;
+               }
+
+               if ( $par === null ) {
+                       $this->getOutput()->addHTML(
+                               $this->msg( 'safedelete-missingpagename' ) );
+                       return;
+               }
+
+               if ( !isset( $GLOBALS['SafeDeleteNamespaces'] ) ) {
+                       $this->getOutput()->addHTML(
+                               $this->msg( 'safedelete-missingnamespaces' ) );
+                       return;
+               }
+
+               $title = Title::newFromURL( $par );
+               $this->getSkin()->setRelevantTitle( $title );
+
+               if ( class_exists ("SemanticTitle" ) ) {
+                       $displaytitle = SemanticTitle::getText( $title );
+               } else {
+                       $displaytitle = $title->getPrefixedText();
+               }
+               $this->getOutput()->setPageTitle( $this->msg( 
'safedelete-title',
+                       $displaytitle ) );
+
+               $this->getOutput()->addBacklinkSubtitle( $title );
+
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $queryLimit = 1000;
+
+               $sql1 = $dbr->selectSQLText(
+                       array(
+                               'pagelinks',
+                               'page'
+                       ),
+                       array(
+                               'page_namespace',
+                               'page_title'
+                       ),
+                       array(
+                               'pl_namespace' => $title->getNamespace(),
+                               'pl_title' => $title->getText(),
+                               'page_namespace' => 
$GLOBALS['SafeDeleteNamespaces'],
+                               'pl_from=page_id'
+                       ),
+                       __METHOD__,
+                       array(
+                               'DISTINCT',
+                               'LIMIT' => $queryLimit
+                       )
+               );
+
+               $sql2 = $dbr->selectSQLText(
+                       array(
+                               'redirect',
+                               'page'
+                       ),
+                       array(
+                               'page_namespace',
+                               'page_title'
+                       ),
+                       array(
+                               'rd_namespace' => $title->getNamespace(),
+                               'rd_title' => $title->getText(),
+                               'page_namespace' => 
$GLOBALS['SafeDeleteNamespaces'],
+                               'rd_from=page_id'
+                       ),
+                       __METHOD__,
+                       array(
+                               'DISTINCT',
+                               'LIMIT' => $queryLimit
+                       )
+               );
+
+               $sql = $dbr->unionQueries( array( $sql1, $sql2 ), false );
+
+               $rows = $dbr->query( $sql );
+
+               if ( $rows->numRows() > 0 ) {
+
+                       $this->getOutput()->addHTML(
+                               $this->msg( 'safedelete-cannotdelete', 
$displaytitle ) );
+
+                       $this->getOutput()->addHTML( Html::element( 'br' ) );
+                       $this->getOutput()->addHTML( Html::openElement( 'ul' ) 
);
+                       foreach ( $rows as $row ) {
+                               $nt = Title::makeTitle( $row->page_namespace,
+                                       $row->page_title );
+                               $link = Linker::linkKnown( $nt );
+                               $element = Xml::tags( 'li', null, "$link" );
+                               $this->getOutput()->addHTML( $element );
+                       }
+
+                       $this->getOutput()->addHTML( Html::closeElement( 'ul' ) 
);
+
+               } else {
+
+                       $this->getOutput()->redirect(
+                               $title->getLocalURL( 'action=delete' ) );
+
+               }
+
+       }
+
+       public static function checkLink( SkinTemplate &$sktemplate,
+               array &$links ) {
+
+               if ( isset( $GLOBALS['SafeDeleteNamespaces'] ) &&
+                       isset( $links['actions']['delete'] ) ) {
+
+                       $title = $sktemplate->getTitle();
+                       $pagename = $title->getPrefixedText();
+
+                       $sd = "Special:SafeDelete/";
+                       if ( substr( $pagename, 0, strlen( $sd ) ) === $sd ) {
+
+                               unset( $links['actions']['delete'] );
+
+                       } elseif
+                               ( $title->inNamespaces( 
$GLOBALS['SafeDeleteNamespaces'] ) ) {
+
+                               $links['actions']['delete']['href'] =
+                                       SpecialPage::getTitleFor( 'SafeDelete', 
$pagename )->
+                                       getLocalURL();
+                       }
+
+               }
+
+               return true;
+
+       }
+}
diff --git a/SafeDelete.php b/SafeDelete.php
new file mode 100644
index 0000000..fcb91d3
--- /dev/null
+++ b/SafeDelete.php
@@ -0,0 +1,44 @@
+<?php
+
+/*
+ * Copyright (c) 2015 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki
+       package and cannot be run standalone." );
+
+$wgExtensionCredits['special'][] = array (
+       'name' => 'Safe Delete',
+       'version' => '1.0',
+       'author' => '[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy 
Cicalese]',
+       'descriptionmsg' => 'safedelete-desc',
+       'path' => __FILE__,
+       'url' => 'https://www.mediawiki.org/wiki/Extension:Safe_Delete',
+);
+
+$wgAutoloadClasses['SafeDelete'] = __DIR__ . '/SafeDelete.class.php';
+
+$wgMessagesDirs['SafeDelete'] = __DIR__ . '/i18n';
+$wgExtensionMessagesFiles['SafeDeleteAlias'] =
+       __DIR__ . '/SafeDelete.alias.php';
+
+$wgSpecialPages['SafeDelete'] = 'SafeDelete';
+$wgHooks['SkinTemplateNavigation'][] = 'SafeDelete::checkLink';
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..c2a7988
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,13 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Cindy Cicalese"
+               ]
+       },
+       "safedelete": "Safe Delete",
+       "safedelete-desc": "Delete page only if there are no pages in the 
specified namespaces linking to it",
+       "safedelete-title": "Delete \"$1\"",
+       "safedelete-missingpagename": "Page name is missing.",
+       "safedelete-missingnamespaces": "List of Special Delete namespaces is 
not set.",
+       "safedelete-cannotdelete": "Page \"$1\" cannot be deleted since there 
are links or redirects to it from the following pages:"
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..2ec6e0a
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,13 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Cindy Cicalese"
+               ]
+       },
+       "safedelete": "The name of the Special Page for this extension",
+       "safedelete-desc": "{{desc|name=Safe 
Delete|url=https://www.mediawiki.org/wiki/Extension:Safe_Delete}}";,
+       "safedelete-title": "Page title to be displayed on special page; $1 is 
the name of the page to be deleted",
+       "safedelete-missingpagename": "Displayed when the special page is 
invoked without the name of the page to be deleted passed as a subpage",
+       "safedelete-missingnamespaces": "Displayed when global 
$SpecialDeleteNamespaces is not set",
+       "safedelete-cannotdelete": "Displayed before the list of 
links/redirects preventing deletion; $1 is the name of the page to be deleted",
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I642fbc6df42f0e64b599f85818ddaba3d31b1707
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SafeDelete
Gerrit-Branch: master
Gerrit-Owner: Cicalese <cical...@mitre.org>
Gerrit-Reviewer: Cicalese <cical...@mitre.org>

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

Reply via email to