merging latest master
[lhc/web/wiklou.git] / includes / specials / SpecialUndelete.php
index 79c051a..1fcba12 100644 (file)
@@ -92,7 +92,7 @@ class PageArchive {
                                array(
                                        'ar_namespace',
                                        'ar_title',
-                                       'COUNT(*) AS count'
+                                       'count' => 'COUNT(*)'
                                ),
                                $condition,
                                __METHOD__,
@@ -112,12 +112,22 @@ class PageArchive {
         * @return ResultWrapper
         */
        function listRevisions() {
+               global $wgContentHandlerNoDB;
+
                $dbr = wfGetDB( DB_SLAVE );
+
+               $fields = array(
+                       'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
+                       'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1',
+               );
+
+               if ( !$wgContentHandlerNoDB ) {
+                       $fields[] = 'ar_content_format';
+                       $fields[] = 'ar_content_model';
+               }
+
                $res = $dbr->select( 'archive',
-                       array(
-                               'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
-                               'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1'
-                       ),
+                       $fields,
                        array( 'ar_namespace' => $this->title->getNamespace(),
                                   'ar_title' => $this->title->getDBkey() ),
                        'PageArchive::listRevisions',
@@ -174,22 +184,32 @@ class PageArchive {
         * @return Revision
         */
        function getRevision( $timestamp ) {
+               global $wgContentHandlerNoDB;
+
                $dbr = wfGetDB( DB_SLAVE );
+
+               $fields = array(
+                       'ar_rev_id',
+                       'ar_text',
+                       'ar_comment',
+                       'ar_user',
+                       'ar_user_text',
+                       'ar_timestamp',
+                       'ar_minor_edit',
+                       'ar_flags',
+                       'ar_text_id',
+                       'ar_deleted',
+                       'ar_len',
+                       'ar_sha1',
+               );
+
+               if ( !$wgContentHandlerNoDB ) {
+                       $fields[] = 'ar_content_format';
+                       $fields[] = 'ar_content_model';
+               }
+
                $row = $dbr->selectRow( 'archive',
-                       array(
-                               'ar_rev_id',
-                               'ar_text',
-                               'ar_comment',
-                               'ar_user',
-                               'ar_user_text',
-                               'ar_timestamp',
-                               'ar_minor_edit',
-                               'ar_flags',
-                               'ar_text_id',
-                               'ar_deleted',
-                               'ar_len',
-                               'ar_sha1',
-                       ),
+                       $fields,
                        array( 'ar_namespace' => $this->title->getNamespace(),
                                        'ar_title' => $this->title->getDBkey(),
                                        'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
@@ -321,11 +341,14 @@ class PageArchive {
         * @param $comment String
         * @param $fileVersions Array
         * @param $unsuppress Boolean
+        * @param $user User doing the action, or null to use $wgUser
         *
         * @return array(number of file revisions restored, number of image revisions restored, log message)
         * on success, false on failure
         */
-       function undelete( $timestamps, $comment = '', $fileVersions = array(), $unsuppress = false ) {
+       function undelete( $timestamps, $comment = '', $fileVersions = array(), $unsuppress = false, User $user = null ) {
+               global $wgContLang, $wgUser;
+
                // If both the set of text revisions and file revisions are empty,
                // restore everything. Otherwise, just restore the requested items.
                $restoreAll = empty( $timestamps ) && empty( $fileVersions );
@@ -354,28 +377,35 @@ class PageArchive {
                }
 
                // Touch the log!
-               global $wgContLang;
-               $log = new LogPage( 'delete' );
 
                if( $textRestored && $filesRestored ) {
-                       $reason = wfMsgExt( 'undeletedrevisions-files', array( 'content', 'parsemag' ),
-                               $wgContLang->formatNum( $textRestored ),
-                               $wgContLang->formatNum( $filesRestored ) );
+                       $reason = wfMessage( 'undeletedrevisions-files' )
+                               ->numParams( $textRestored, $filesRestored )->inContentLanguage()->text();
                } elseif( $textRestored ) {
-                       $reason = wfMsgExt( 'undeletedrevisions', array( 'content', 'parsemag' ),
-                               $wgContLang->formatNum( $textRestored ) );
+                       $reason = wfMessage( 'undeletedrevisions' )->numParams( $textRestored )
+                               ->inContentLanguage()->text();
                } elseif( $filesRestored ) {
-                       $reason = wfMsgExt( 'undeletedfiles', array( 'content', 'parsemag' ),
-                               $wgContLang->formatNum( $filesRestored ) );
+                       $reason = wfMessage( 'undeletedfiles' )->numParams( $filesRestored )
+                               ->inContentLanguage()->text();
                } else {
                        wfDebug( "Undelete: nothing undeleted...\n" );
                        return false;
                }
 
                if( trim( $comment ) != '' ) {
-                       $reason .= wfMsgForContent( 'colon-separator' ) . $comment;
+                       $reason .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
+               }
+
+               if ( $user === null ) {
+                       $user = $wgUser;
                }
-               $log->addEntry( 'restore', $this->title, $reason );
+
+               $logEntry = new ManualLogEntry( 'delete', 'restore' );
+               $logEntry->setPerformer( $user );
+               $logEntry->setTarget( $this->title );
+               $logEntry->setComment( $reason );
+               $logid = $logEntry->insert();
+               $logEntry->publish( $logid );
 
                return array( $textRestored, $filesRestored, $reason );
        }
@@ -392,6 +422,8 @@ class PageArchive {
         * @return Mixed: number of revisions restored or false on failure
         */
        private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
+               global $wgContentHandlerNoDB;
+
                if ( wfReadOnly() ) {
                        return false;
                }
@@ -445,24 +477,31 @@ class PageArchive {
                        $oldones = "ar_timestamp IN ( {$oldts} )";
                }
 
+               $fields = array(
+                       'ar_rev_id',
+                       'ar_text',
+                       'ar_comment',
+                       'ar_user',
+                       'ar_user_text',
+                       'ar_timestamp',
+                       'ar_minor_edit',
+                       'ar_flags',
+                       'ar_text_id',
+                       'ar_deleted',
+                       'ar_page_id',
+                       'ar_len',
+                       'ar_sha1');
+
+               if ( !$wgContentHandlerNoDB ) {
+                       $fields[] = 'ar_content_format';
+                       $fields[] = 'ar_content_model';
+               }
+
                /**
                 * Select each archived revision...
                 */
                $result = $dbw->select( 'archive',
-                       /* fields */ array(
-                               'ar_rev_id',
-                               'ar_text',
-                               'ar_comment',
-                               'ar_user',
-                               'ar_user_text',
-                               'ar_timestamp',
-                               'ar_minor_edit',
-                               'ar_flags',
-                               'ar_text_id',
-                               'ar_deleted',
-                               'ar_page_id',
-                               'ar_len',
-                               'ar_sha1' ),
+                       $fields,
                        /* WHERE */ array(
                                'ar_namespace' => $this->title->getNamespace(),
                                'ar_title'     => $this->title->getDBkey(),
@@ -754,8 +793,8 @@ class SpecialUndelete extends SpecialPage {
                                );
                        } else {
                                // The title is no longer valid, show as text
-                               $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
-                               $item = htmlspecialchars( $title->getPrefixedText() );
+                               $item = Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
+                                       Linker::getInvalidTitleDescription( $this->getContext(), $row->ar_namespace, $row->ar_title ) );
                        }
                        $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count )->parse();
                        $out->addHTML( "<li>{$item} ({$revs})</li>\n" );
@@ -843,6 +882,7 @@ class SpecialUndelete extends SpecialPage {
 
                if( $this->mPreview ) {
                        // Hide [edit]s
+                       //FIXME: ContentHandler will have to provide some specialized magic to do this
                        $popts = $out->parserOptions();
                        $popts->setEditSection( false );
                        $out->parserOptions( $popts );
@@ -854,7 +894,7 @@ class SpecialUndelete extends SpecialPage {
                                        'readonly' => 'readonly',
                                        'cols' => intval( $user->getOption( 'cols' ) ),
                                        'rows' => intval( $user->getOption( 'rows' ) ) ),
-                               $rev->getText( Revision::FOR_THIS_USER, $user ) . "\n" ) .
+                               $rev->getText( Revision::FOR_THIS_USER, $user ) . "\n" ) . //FIXME: ContentHandler will have to provide some specialized magic to do this
                        Xml::openElement( 'div' ) .
                        Xml::openElement( 'form', array(
                                'method' => 'post',
@@ -892,7 +932,8 @@ class SpecialUndelete extends SpecialPage {
         * @return String: HTML
         */
        function showDiff( $previousRev, $currentRev ) {
-               $diffEngine = new DifferenceEngine( $this->getContext() );
+               $contentHandler = ContentHandler::getForTitle( $this->getTitle() );
+               $diffEngine = $contentHandler->createDifferenceEngine( $this->getContext() );
                $diffEngine->showDiffStyle();
                $this->getOutput()->addHTML(
                        "<div>" .
@@ -909,8 +950,9 @@ class SpecialUndelete extends SpecialPage {
                                $this->diffHeader( $currentRev, 'n' ) .
                                "</td>\n" .
                        "</tr>" .
-                       $diffEngine->generateDiffBody(
-                               $previousRev->getText(), $currentRev->getText() ) .
+                       $diffEngine->generateContentDiffBody(
+                               $previousRev->getContent( Revision::FOR_THIS_USER, $this->getUser() ),
+                               $currentRev->getContent( Revision::FOR_THIS_USER, $this->getUser() ) ) .
                        "</table>" .
                        "</div>\n"
                );
@@ -1071,11 +1113,13 @@ class SpecialUndelete extends SpecialPage {
                }
 
                # Show relevant lines from the deletion log:
-               $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
+               $deleteLogPage = new LogPage( 'delete' );
+               $out->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) . "\n" );
                LogEventsList::showLogExtract( $out, 'delete', $this->mTargetObj );
                # Show relevant lines from the suppression log:
+               $suppressLogPage = new LogPage( 'suppress' );
                if( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
-                       $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
+                       $out->addHTML( Xml::element( 'h2', null, $suppressLogPage->getName()->text() ) . "\n" );
                        LogEventsList::showLogExtract( $out, 'suppress', $this->mTargetObj );
                }
 
@@ -1387,7 +1431,9 @@ class SpecialUndelete extends SpecialPage {
                        $this->mTargetTimestamp,
                        $this->mComment,
                        $this->mFileVersions,
-                       $this->mUnsuppress );
+                       $this->mUnsuppress,
+                       $this->getUser()
+               );
 
                if( is_array( $ok ) ) {
                        if ( $ok[1] ) { // Undeleted file count