Merge "WebInstallerOutput: Restore 'global $wgResourceModules'"
[lhc/web/wiklou.git] / includes / specials / SpecialUndelete.php
index 51235ee..8acf8a2 100644 (file)
@@ -36,11 +36,19 @@ class PageArchive {
        /** @var Status */
        protected $revisionStatus;
 
-       function __construct( $title ) {
+       /** @var Config */
+       protected $config;
+
+       function __construct( $title, Config $config = null ) {
                if ( is_null( $title ) ) {
                        throw new MWException( __METHOD__ . ' given a null title.' );
                }
                $this->title = $title;
+               if ( $config === null ) {
+                       wfDebug( __METHOD__ . ' did not have a Config object passed to it' );
+                       $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+               }
+               $this->config = $config;
        }
 
        /**
@@ -115,8 +123,6 @@ class PageArchive {
         * @return ResultWrapper
         */
        function listRevisions() {
-               global $wgContentHandlerUseDB;
-
                $dbr = wfGetDB( DB_SLAVE );
 
                $tables = array( 'archive' );
@@ -126,7 +132,7 @@ class PageArchive {
                        'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1',
                );
 
-               if ( $wgContentHandlerUseDB ) {
+               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
                        $fields[] = 'ar_content_format';
                        $fields[] = 'ar_content_model';
                }
@@ -190,8 +196,6 @@ class PageArchive {
         * @return Revision|null
         */
        function getRevision( $timestamp ) {
-               global $wgContentHandlerUseDB;
-
                $dbr = wfGetDB( DB_SLAVE );
 
                $fields = array(
@@ -209,7 +213,7 @@ class PageArchive {
                        'ar_sha1',
                );
 
-               if ( $wgContentHandlerUseDB ) {
+               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
                        $fields[] = 'ar_content_format';
                        $fields[] = 'ar_content_model';
                }
@@ -442,8 +446,6 @@ class PageArchive {
         * @return Status Status object containing the number of revisions restored on success
         */
        private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
-               global $wgContentHandlerUseDB;
-
                if ( wfReadOnly() ) {
                        throw new ReadOnlyError();
                }
@@ -492,15 +494,12 @@ class PageArchive {
                        $previousTimestamp = 0;
                }
 
-               if ( $restoreAll ) {
-                       $oldones = '1 = 1'; # All revisions...
-               } else {
-                       $oldts = implode( ',',
-                               array_map( array( &$dbw, 'addQuotes' ),
-                                       array_map( array( &$dbw, 'timestamp' ),
-                                               $timestamps ) ) );
-
-                       $oldones = "ar_timestamp IN ( {$oldts} )";
+               $oldWhere = array(
+                       'ar_namespace' => $this->title->getNamespace(),
+                       'ar_title' => $this->title->getDBkey(),
+               );
+               if ( !$restoreAll ) {
+                       $oldWhere['ar_timestamp'] = array_map( array( &$dbw, 'timestamp' ), $timestamps );
                }
 
                $fields = array(
@@ -519,7 +518,7 @@ class PageArchive {
                        'ar_sha1'
                );
 
-               if ( $wgContentHandlerUseDB ) {
+               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
                        $fields[] = 'ar_content_format';
                        $fields[] = 'ar_content_model';
                }
@@ -529,10 +528,7 @@ class PageArchive {
                 */
                $result = $dbw->select( 'archive',
                        $fields,
-                       /* WHERE */ array(
-                               'ar_namespace' => $this->title->getNamespace(),
-                               'ar_title' => $this->title->getDBkey(),
-                               $oldones ),
+                       $oldWhere,
                        __METHOD__,
                        /* options */ array( 'ORDER BY' => 'ar_timestamp' )
                );
@@ -618,10 +614,7 @@ class PageArchive {
                }
                # Now that it's safely stored, take it out of the archive
                $dbw->delete( 'archive',
-                       /* WHERE */ array(
-                               'ar_namespace' => $this->title->getNamespace(),
-                               'ar_title' => $this->title->getDBkey(),
-                               $oldones ),
+                       $oldWhere,
                        __METHOD__ );
 
                // Was anything restored at all?
@@ -815,12 +808,10 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function showSearchForm() {
-               global $wgScript;
-
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
                $out->addHTML(
-                       Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
+                       Xml::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) ) .
                                Xml::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
                                Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
                                Html::rawElement(
@@ -900,7 +891,7 @@ class SpecialUndelete extends SpecialPage {
                        return;
                }
 
-               $archive = new PageArchive( $this->mTargetObj );
+               $archive = new PageArchive( $this->mTargetObj, $this->getConfig() );
                if ( !wfRunHooks( 'UndeleteForm::showRevision', array( &$archive, $this->mTargetObj ) ) ) {
                        return;
                }
@@ -919,7 +910,8 @@ class SpecialUndelete extends SpecialPage {
                        if ( !$rev->userCan( Revision::DELETED_TEXT, $user ) ) {
                                $out->wrapWikiMsg(
                                        "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
-                                       'rev-deleted-text-permission'
+                               $rev->isDeleted( Revision::DELETED_RESTRICTED ) ?
+                                       'rev-suppressed-text-permission' : 'rev-deleted-text-permission'
                                );
 
                                return;
@@ -927,7 +919,8 @@ class SpecialUndelete extends SpecialPage {
 
                        $out->wrapWikiMsg(
                                "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
-                               'rev-deleted-text-view'
+                               $rev->isDeleted( Revision::DELETED_RESTRICTED ) ?
+                                       'rev-suppressed-text-view' : 'rev-deleted-text-view'
                        );
                        $out->addHTML( '<br />' );
                        // and we are allowed to see...
@@ -1205,7 +1198,7 @@ class SpecialUndelete extends SpecialPage {
                        array( 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj->getPrefixedText() ) )
                );
 
-               $archive = new PageArchive( $this->mTargetObj );
+               $archive = new PageArchive( $this->mTargetObj, $this->getConfig() );
                wfRunHooks( 'UndeleteForm::showHistory', array( &$archive, $this->mTargetObj ) );
                /*
                $text = $archive->getLastRevisionText();
@@ -1617,9 +1610,7 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function undelete() {
-               global $wgUploadMaintenance;
-
-               if ( $wgUploadMaintenance && $this->mTargetObj->getNamespace() == NS_FILE ) {
+               if ( $this->getConfig()->get( 'UploadMaintenance' ) && $this->mTargetObj->getNamespace() == NS_FILE ) {
                        throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
                }
 
@@ -1628,7 +1619,7 @@ class SpecialUndelete extends SpecialPage {
                }
 
                $out = $this->getOutput();
-               $archive = new PageArchive( $this->mTargetObj );
+               $archive = new PageArchive( $this->mTargetObj, $this->getConfig() );
                wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) );
                $ok = $archive->undelete(
                        $this->mTargetTimestamp,