For r91123:
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 7 Sep 2011 17:55:37 +0000 (17:55 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 7 Sep 2011 17:55:37 +0000 (17:55 +0000)
* Moved generateReason() to WikiPage. This fixes the PureWikiDeletion ext too.
* Make Checkpoint ext call getRawText() as doEdit() does. Aalso, WikiPage doesn't have fetchContent().
* Call getAutosummary() statically in doEdit().
* Fixed outdated code comment.
* Fixed title used in unit test.

includes/Article.php
includes/WikiPage.php
tests/phpunit/includes/ArticleTest.php

index 1d71bad..49beeb8 100644 (file)
@@ -1266,101 +1266,6 @@ class Article extends Page {
                $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
        }
 
-       /**
-        * Auto-generates a deletion reason
-        *
-        * @param &$hasHistory Boolean: whether the page has a history
-        * @return mixed String containing deletion reason or empty string, or boolean false
-        *    if no revision occurred
-        */
-       public function generateReason( &$hasHistory ) {
-               global $wgContLang;
-
-               $dbw = wfGetDB( DB_MASTER );
-               // Get the last revision
-               $rev = Revision::newFromTitle( $this->getTitle() );
-
-               if ( is_null( $rev ) ) {
-                       return false;
-               }
-
-               // Get the article's contents
-               $contents = $rev->getText();
-               $blank = false;
-
-               // If the page is blank, use the text from the previous revision,
-               // which can only be blank if there's a move/import/protect dummy revision involved
-               if ( $contents == '' ) {
-                       $prev = $rev->getPrevious();
-
-                       if ( $prev )    {
-                               $contents = $prev->getText();
-                               $blank = true;
-                       }
-               }
-
-               // Find out if there was only one contributor
-               // Only scan the last 20 revisions
-               $res = $dbw->select( 'revision', 'rev_user_text',
-                       array( 'rev_page' => $this->mPage->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
-                       __METHOD__,
-                       array( 'LIMIT' => 20 )
-               );
-
-               if ( $res === false ) {
-                       // This page has no revisions, which is very weird
-                       return false;
-               }
-
-               $hasHistory = ( $res->numRows() > 1 );
-               $row = $dbw->fetchObject( $res );
-
-               if ( $row ) { // $row is false if the only contributor is hidden
-                       $onlyAuthor = $row->rev_user_text;
-                       // Try to find a second contributor
-                       foreach ( $res as $row ) {
-                               if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
-                                       $onlyAuthor = false;
-                                       break;
-                               }
-                       }
-               } else {
-                       $onlyAuthor = false;
-               }
-
-               // Generate the summary with a '$1' placeholder
-               if ( $blank ) {
-                       // The current revision is blank and the one before is also
-                       // blank. It's just not our lucky day
-                       $reason = wfMsgForContent( 'exbeforeblank', '$1' );
-               } else {
-                       if ( $onlyAuthor ) {
-                               $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
-                       } else {
-                               $reason = wfMsgForContent( 'excontent', '$1' );
-                       }
-               }
-
-               if ( $reason == '-' ) {
-                       // Allow these UI messages to be blanked out cleanly
-                       return '';
-               }
-
-               // Replace newlines with spaces to prevent uglyness
-               $contents = preg_replace( "/[\n\r]/", ' ', $contents );
-               // Calculate the maximum amount of chars to get
-               // Max content length = max comment length - length of the comment (excl. $1)
-               $maxLength = 255 - ( strlen( $reason ) - 2 );
-               $contents = $wgContLang->truncate( $contents, $maxLength );
-               // Remove possible unfinished links
-               $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
-               // Now replace the '$1' placeholder
-               $reason = str_replace( '$1', $contents, $reason );
-
-               return $reason;
-       }
-
-
        /**
         * UI entry point for page deletion
         */
@@ -2042,6 +1947,10 @@ class Article extends Page {
                return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
        }
 
+       public function generateReason( &$hasHistory ) {
+               return $this->mPage->getAutoDeleteReason( $hasHistory );
+       }
+
        // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
        public static function selectFields() {
                return WikiPage::selectFields();
index 0483eeb..aca2b0c 100644 (file)
@@ -574,7 +574,7 @@ class WikiPage extends Page {
         * @return string MW timestamp of last article revision
         */
        public function getTimestamp() {
-               // Check if the field has been filled by ParserCache::get()
+               // Check if the field has been filled by WikiPage::setTimestamp()
                if ( !$this->mTimestamp ) {
                        $this->loadLastEdit();
                }
@@ -1094,7 +1094,7 @@ class WikiPage extends Page {
 
                # Provide autosummaries if one is not provided and autosummaries are enabled.
                if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) {
-                       $summary = $this->getAutosummary( $oldtext, $text, $flags );
+                       $summary = self::getAutosummary( $oldtext, $text, $flags );
                }
 
                $editInfo = $this->prepareTextForEdit( $text, null, $user );
@@ -2464,6 +2464,100 @@ class WikiPage extends Page {
                return '';
        }
 
+       /**
+        * Auto-generates a deletion reason
+        *
+        * @param &$hasHistory Boolean: whether the page has a history
+        * @return mixed String containing deletion reason or empty string, or boolean false
+        *    if no revision occurred
+        */
+       public function getAutoDeleteReason( &$hasHistory ) {
+               global $wgContLang;
+
+               $dbw = wfGetDB( DB_MASTER );
+               // Get the last revision
+               $rev = Revision::newFromTitle( $this->getTitle() );
+
+               if ( is_null( $rev ) ) {
+                       return false;
+               }
+
+               // Get the article's contents
+               $contents = $rev->getText();
+               $blank = false;
+
+               // If the page is blank, use the text from the previous revision,
+               // which can only be blank if there's a move/import/protect dummy revision involved
+               if ( $contents == '' ) {
+                       $prev = $rev->getPrevious();
+
+                       if ( $prev )    {
+                               $contents = $prev->getText();
+                               $blank = true;
+                       }
+               }
+
+               // Find out if there was only one contributor
+               // Only scan the last 20 revisions
+               $res = $dbw->select( 'revision', 'rev_user_text',
+                       array( 'rev_page' => $this->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
+                       __METHOD__,
+                       array( 'LIMIT' => 20 )
+               );
+
+               if ( $res === false ) {
+                       // This page has no revisions, which is very weird
+                       return false;
+               }
+
+               $hasHistory = ( $res->numRows() > 1 );
+               $row = $dbw->fetchObject( $res );
+
+               if ( $row ) { // $row is false if the only contributor is hidden
+                       $onlyAuthor = $row->rev_user_text;
+                       // Try to find a second contributor
+                       foreach ( $res as $row ) {
+                               if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
+                                       $onlyAuthor = false;
+                                       break;
+                               }
+                       }
+               } else {
+                       $onlyAuthor = false;
+               }
+
+               // Generate the summary with a '$1' placeholder
+               if ( $blank ) {
+                       // The current revision is blank and the one before is also
+                       // blank. It's just not our lucky day
+                       $reason = wfMsgForContent( 'exbeforeblank', '$1' );
+               } else {
+                       if ( $onlyAuthor ) {
+                               $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
+                       } else {
+                               $reason = wfMsgForContent( 'excontent', '$1' );
+                       }
+               }
+
+               if ( $reason == '-' ) {
+                       // Allow these UI messages to be blanked out cleanly
+                       return '';
+               }
+
+               // Replace newlines with spaces to prevent uglyness
+               $contents = preg_replace( "/[\n\r]/", ' ', $contents );
+               // Calculate the maximum amount of chars to get
+               // Max content length = max comment length - length of the comment (excl. $1)
+               $maxLength = 255 - ( strlen( $reason ) - 2 );
+               $contents = $wgContLang->truncate( $contents, $maxLength );
+               // Remove possible unfinished links
+               $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
+               // Now replace the '$1' placeholder
+               $reason = str_replace( '$1', $contents, $reason );
+
+               return $reason;
+       }
+
        /**
         * Get parser options suitable for rendering the primary article wikitext
         * @param $canonical boolean Determines that the generated options must not depend on user preferences (see bug 14404)
index 56384cf..285efee 100644 (file)
@@ -7,7 +7,7 @@ class ArticleTest extends MediaWikiTestCase {
 
        /** creates a title object and its article object */
        function setUp() {
-               $this->title   = Title::makeTitle( NS_MAIN, 'somePage' );
+               $this->title   = Title::makeTitle( NS_MAIN, 'SomePage' );
                $this->article = new Article( $this->title );
 
        }