VitaliyFilippov has uploaded a new change for review.

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


Change subject: Allow to duplicate subpages
......................................................................

Allow to duplicate subpages

Change-Id: I950ec49fc91f7a99c0722771f8498b15033e86d5
---
M Duplicator.i18n.php
M Duplicator.page.php
2 files changed, 47 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Duplicator 
refs/changes/79/65979/1

diff --git a/Duplicator.i18n.php b/Duplicator.i18n.php
index 68a55c4..44090c0 100644
--- a/Duplicator.i18n.php
+++ b/Duplicator.i18n.php
@@ -22,6 +22,7 @@
        'duplicator-source'                => 'Source:',
        'duplicator-dest'                  => 'Destination:',
        'duplicator-dotalk'                => 'Duplicate discussion page (if 
applicable)',
+       'duplicator-dosubpages'            => 'Duplicate subpages (if any)',
        'duplicator-dohistory'             => 'Duplicate full page history',
        'duplicator-submit'                => 'Duplicate',
        'duplicator-summary'               => 'Copied from [[$1]], revision 
[[$2]]',
@@ -1480,6 +1481,7 @@
        'duplicator-source' => 'Откуда:',
        'duplicator-dest' => 'Куда:',
        'duplicator-dotalk' => 'Клонировать страницу обсуждения (если 
возможно)',
+       'duplicator-dosubpages' => 'Клонировать подстраницы (если есть)',
        'duplicator-dohistory' => 'Клонировать историю изменений',
        'duplicator-submit' => 'Клонировать',
        'duplicator-summary' => 'Копия ревизии [[$2]] статьи [[$1]]',
diff --git a/Duplicator.page.php b/Duplicator.page.php
index 1439e26..50d1145 100644
--- a/Duplicator.page.php
+++ b/Duplicator.page.php
@@ -23,9 +23,10 @@
        protected $destTitle = null;
 
        /**
-        * Whether or not we're duplicating the talk page and the history
+        * Whether or not we're duplicating the talk page, subpages, and the 
history
         */
        protected $talk = true;
+       protected $subpages = true;
        protected $history = true;
 
        /**
@@ -98,6 +99,10 @@
                if( $num ) {
                        $success = '* ' . wfMsgNoTrans( 'duplicator-success', 
$this->sourceTitle->getPrefixedText(), $this->destTitle->getPrefixedText() );
                        $success .= ' ' . wfMsgNoTrans( 
'duplicator-success-revisions', $wgLang->formatNum( $num ) ) . "\n";
+                       # If there are subpages and we've been asked to 
duplicate them, do so
+                       if ( $this->subpages ) {
+                               $success .= $this->duplicateSubpages( 
$this->sourceTitle, $this->destTitle, $this->history );
+                       }
                        # If there is a talk page and we've been asked to 
duplicate it, do so
                        if( $this->talk && $this->dealWithTalk() ) {
                                $st = $this->sourceTitle->getTalkPage();
@@ -106,6 +111,9 @@
                                if ( $num ) {
                                        $success .= '* ' . wfMsgNoTrans( 
'duplicator-success', $st->getPrefixedText(), $dt->getPrefixedText() );
                                        $success .= ' ' . wfMsgNoTrans( 
'duplicator-success-revisions', $wgLang->formatNum( $num ) ) . "\n";
+                                       if ( $this->subpages ) {
+                                               $success .= 
$this->duplicateSubpages( $st, $dt, $this->history );
+                                       }
                                } else {
                                        $success .= '* ' . wfMsgNoTrans( 
'duplicator-success-talknotcopied' ) . "\n";
                                }
@@ -133,6 +141,7 @@
                $this->dest = $request->getText( 'dest', '' );
                $this->destTitle = Title::newFromText( $this->dest );
                $this->talk = $request->getCheck( 'talk' );
+               $this->subpages = $request->getCheck( 'subpages' );
                $this->history = $request->getCheck( 'history' );
        }
 
@@ -179,6 +188,9 @@
                $form .= '<td>' . Xml::checkLabel( wfMsg( 'duplicator-dotalk' 
), 'talk', 'talk', $this->talk ) . '</td>';
                $form .= '</tr><tr>';
                $form .= '<td>&#160;</td>';
+               $form .= '<td>' . Xml::checkLabel( wfMsg( 
'duplicator-dosubpages' ), 'subpages', 'subpages', $this->subpages ) . '</td>';
+               $form .= '</tr><tr>';
+               $form .= '<td>&#160;</td>';
                $form .= '<td>' . Xml::checkLabel( wfMsg( 
'duplicator-dohistory' ), 'history', 'history', $this->history ) . '</td>';
                $form .= '</tr><tr>';
                $form .= '<td>&#160;</td>';
@@ -191,6 +203,38 @@
        }
 
        /**
+        * Duplicate subpages of $source to $dest
+        *
+        * @param $source Title to duplicate subpages for
+        * @param $dest Title to save subpages to
+        * @return bool
+        */
+       protected function duplicateSubpages( $source, $dest, $includeHistory ) 
{
+               global $wgLang;
+               $subpages = $source->getSubpages();
+               $len = strlen( $source->getText() );
+               $ns = $dest->getNamespace();
+               $dest = $dest->getText();
+               $success = '';
+               foreach ( $subpages as $sub ) {
+                       $destSub = Title::makeTitleSafe( $ns, $dest . substr( 
$sub->getText(), $len ) );
+                       if ( $destSub ) {
+                               if ( $destSub->exists() ) {
+                                       $success .= '* ' . wfMsgNoTrans( 
'duplicator-failed-dest-exists', $sub->getPrefixedText(), 
$destSub->getPrefixedText() ) . "\n";
+                               } else {
+                                       $num = $this->duplicate( $sub, 
$destSub, $this->history );
+                                       $success .= '* ' . wfMsgNoTrans( 
'duplicator-success', $sub->getPrefixedText(), $destSub->getPrefixedText() );
+                                       $success .= ' ' . wfMsgNoTrans( 
'duplicator-success-revisions', $wgLang->formatNum( $num ) ) . "\n";
+                               }
+                       } else {
+                               # Bad title error can only occur here because 
of the destination title being too long
+                               $success .= '* ' . wfMsgNoTrans( 
'duplicator-failed-toolong', $sub->getPrefixedText() ) . "\n";
+                       }
+               }
+               return $success;
+       }
+
+       /**
         * Duplicate one page to another, including full histories
         * Does some basic error-catching, but not as much as the code above 
[should]
         *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I950ec49fc91f7a99c0722771f8498b15033e86d5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Duplicator
Gerrit-Branch: master
Gerrit-Owner: VitaliyFilippov <vita...@yourcmc.ru>

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

Reply via email to