Merge "Don't modify $wgHooks on language object construction"
[lhc/web/wiklou.git] / includes / specials / SpecialUndelete.php
index b36860f..5e08e51 100644 (file)
@@ -51,6 +51,10 @@ class PageArchive {
                $this->config = $config;
        }
 
+       public function doesWrites() {
+               return true;
+       }
+
        /**
         * List all deleted pages recorded in the archive table. Returns result
         * wrapper with (ar_namespace, ar_title, count) fields, ordered by page
@@ -569,6 +573,10 @@ class PageArchive {
                        }
                        // Safe to insert now...
                        $newid = $article->insertOn( $dbw, $row->ar_page_id );
+                       if ( $newid === false ) {
+                               // The old ID is reserved; let's pick another
+                               $newid = $article->insertOn( $dbw );
+                       }
                        $pageId = $newid;
                } else {
                        // Check if a deleted revision will become the current revision...
@@ -667,13 +675,14 @@ class PageArchive {
  * @ingroup SpecialPage
  */
 class SpecialUndelete extends SpecialPage {
-       private $mAction;
+       private $mAction;
        private $mTarget;
        private $mTimestamp;
        private $mRestore;
+       private $mRevdel;
        private $mInvert;
        private $mFilename;
-       private $mTargetTimestamp;
+       private $mTargetTimestamp;
        private $mAllowed;
        private $mCanView;
        private $mComment;
@@ -711,6 +720,7 @@ class SpecialUndelete extends SpecialPage {
                $posted = $request->wasPosted() &&
                        $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
                $this->mRestore = $request->getCheck( 'restore' ) && $posted;
+               $this->mRevdel = $request->getCheck( 'revdel' ) && $posted;
                $this->mInvert = $request->getCheck( 'invert' ) && $posted;
                $this->mPreview = $request->getCheck( 'preview' ) && $posted;
                $this->mDiff = $request->getCheck( 'diff' );
@@ -823,13 +833,42 @@ class SpecialUndelete extends SpecialPage {
                        } else {
                                $this->showFile( $this->mFilename );
                        }
-               } elseif ( $this->mRestore && $this->mAction == 'submit' ) {
-                       $this->undelete();
+               } elseif ( $this->mAction === "submit" ) {
+                       if ( $this->mRestore ) {
+                               $this->undelete();
+                       } elseif ( $this->mRevdel ) {
+                               $this->redirectToRevDel();
+                       }
+
                } else {
                        $this->showHistory();
                }
        }
 
+       /**
+        * Convert submitted form data to format expected by RevisionDelete and
+        * redirect the request
+        */
+       private function redirectToRevDel() {
+               $archive = new PageArchive( $this->mTargetObj );
+
+               $revisions = array();
+
+               foreach ( $this->getRequest()->getValues() as $key => $val ) {
+                       $matches = array();
+                       if ( preg_match( "/^ts(\d{14})$/", $key, $matches ) ) {
+                               $revisions[ $archive->getRevision( $matches[1] )->getId() ] = 1;
+                       }
+               }
+               $query = array(
+                       "type" => "revision",
+                       "ids" => $revisions,
+                       "target" => wfUrlencode( $this->mTargetObj->getPrefixedText() )
+               );
+               $url = SpecialPage::getTitleFor( "RevisionDelete" )->getFullURL( $query );
+               $this->getOutput()->redirect( $url );
+       }
+
        function showSearchForm() {
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
@@ -1348,7 +1387,20 @@ class SpecialUndelete extends SpecialPage {
                $out->addHTML( Xml::element( 'h2', null, $this->msg( 'history' )->text() ) . "\n" );
 
                if ( $haveRevisions ) {
-                       # The page's stored (deleted) history:
+                       # Show the page's stored (deleted) history
+
+                       if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
+                               $out->addHTML( Html::element(
+                                       'button',
+                                       array(
+                                               'name' => 'revdel',
+                                               'type' => 'submit',
+                                               'class' => 'deleterevision-log-submit mw-log-deleterevision-button'
+                                       ),
+                                       $this->msg( 'showhideselectedversions' )->text()
+                               ) . "\n" );
+                       }
+
                        $out->addHTML( '<ul>' );
                        $remaining = $revisions->numRows();
                        $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
@@ -1458,13 +1510,9 @@ class SpecialUndelete extends SpecialPage {
                        $attribs['class'] = implode( ' ', $classes );
                }
 
-               // Revision delete links
-               $revdlink = Linker::getRevDeleteLink( $user, $rev, $this->mTargetObj );
-
-               $revisionRow = $this->msg( 'undelete-revision-row' )
+               $revisionRow = $this->msg( 'undelete-revision-row2' )
                        ->rawParams(
                                $checkBox,
-                               $revdlink,
                                $last,
                                $pageLink,
                                $userLink,
@@ -1701,15 +1749,7 @@ class SpecialUndelete extends SpecialPage {
         * @return string[] Matching subpages
         */
        public function prefixSearchSubpages( $search, $limit, $offset ) {
-               $title = Title::newFromText( $search );
-               if ( !$title || !$title->canExist() ) {
-                       // No prefix suggestion in special and media namespace
-                       return array();
-               }
-               // Autocomplete subpage the same as a normal search
-               $prefixSearcher = new StringPrefixSearch;
-               $result = $prefixSearcher->search( $search, $limit, array(), $offset );
-               return $result;
+               return $this->prefixSearchString( $search, $limit, $offset );
        }
 
        protected function getGroupName() {