Merge "(bug 36908) Language::isValidBuiltInCode passed an object"
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 18 May 2012 21:50:35 +0000 (21:50 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 18 May 2012 21:50:35 +0000 (21:50 +0000)
includes/WikiPage.php
languages/Language.php
tests/phpunit/includes/WikiPageTest.php

index b326eb4..fffd5f6 100644 (file)
@@ -2225,21 +2225,7 @@ class WikiPage extends Page {
                        return WikiPage::DELETE_NO_REVISIONS;
                }
 
-               # update site status
-               DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 ) );
-
-               # remove secondary indexes, etc
-               $updates = $this->getDeletionUpdates( );
-               DataUpdate::runUpdates( $updates );
-
-               # Clear caches
-               WikiPage::onArticleDelete( $this->mTitle );
-
-               # Reset this object
-               $this->clear();
-
-               # Clear the cached article id so the interface doesn't act like we exist
-               $this->mTitle->resetArticleID( 0 );
+               $this->doDeleteUpdates( $id );
 
                # Log the deletion, if the page was suppressed, log it at Oversight instead
                $logtype = $suppress ? 'suppress' : 'delete';
@@ -2259,6 +2245,29 @@ class WikiPage extends Page {
                return WikiPage::DELETE_SUCCESS;
        }
 
+       /**
+        * Do some database updates after deletion
+        *
+        * @param $id Int: page_id value of the page being deleted (B/C, currently unused)
+        */
+       public function doDeleteUpdates( $id ) {
+               # update site status
+               DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 ) );
+
+               # remove secondary indexes, etc
+               $updates = $this->getDeletionUpdates( );
+               DataUpdate::runUpdates( $updates );
+
+               # Clear caches
+               WikiPage::onArticleDelete( $this->mTitle );
+
+               # Reset this object
+               $this->clear();
+
+               # Clear the cached article id so the interface doesn't act like we exist
+               $this->mTitle->resetArticleID( 0 );
+       }
+
        /**
         * Roll back the most recent consecutive set of edits to a page
         * from the same user; fails if there are no eligible edits to
index 877ccfe..240b0d3 100644 (file)
@@ -709,9 +709,9 @@ class Language {
         *              Use null for autonyms (native names)
         * @param $include string:
         *              'all' all available languages
-        *              'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames
+        *              'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames (default)
         *              'mwfile' only if the language is in 'mw' *and* has a message file
-        * @return array|bool: language code => language name, false if $include is wrong
+        * @return array: language code => language name
         * @since 1.20
         */
        public static function fetchLanguageNames( $inLanguage = null, $include = 'mw' ) {
@@ -749,9 +749,7 @@ class Language {
                        $returnMw[$coreCode] = $names[$coreCode];
                }
 
-               if( $include === 'mw' ) {
-                       return $returnMw;
-               } elseif( $include === 'mwfile' ) {
+               if( $include === 'mwfile' ) {
                        $namesMwFile = array();
                        # We do this using a foreach over the codes instead of a directory
                        # loop so that messages files in extensions will work correctly.
@@ -762,7 +760,8 @@ class Language {
                        }
                        return $namesMwFile;
                }
-               return false;
+               # 'mw' option; default if it's not one of the other two options (all/mwfile)
+               return $returnMw;
        }
 
        /**
index 88c26ef..65abdab 100644 (file)
@@ -142,6 +142,21 @@ class WikiPageTest extends MediaWikiTestCase {
                $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
        }
 
+       public function testDoDeleteUpdates() {
+               $page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo" );
+               $id = $page->getId();
+
+               $page->doDeleteUpdates( $id );
+
+               # ------------------------
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
+               $n = $res->numRows();
+               $res->free();
+
+               $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
+       }
+
        public function testGetRevision() {
                $page = $this->newPage( "WikiPageTest_testGetRevision" );