Merge "Prefix new ContentHandler hooks in WikiPage with Page instead of Article"
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 11 Oct 2012 17:12:50 +0000 (17:12 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 11 Oct 2012 17:12:50 +0000 (17:12 +0000)
docs/hooks.txt
includes/Defines.php
includes/EditPage.php
includes/Title.php
includes/actions/InfoAction.php
includes/db/IORMTable.php
includes/db/ORMTable.php

index 7957c84..10a341d 100644 (file)
@@ -1223,6 +1223,10 @@ $reader: XMLReader object
 $revisionInfo: Array of information
 Return false to stop further processing of the tag
 
+'InfoAction': When building information to display on the action=info page
+$context: IContextSource object
+&$pageInfo: Array of information
+
 'InitializeArticleMaybeRedirect': MediaWiki check to see if title is a redirect
 $title: Title object ($wgTitle)
 $request: WebRequest
index 1bcb058..2ddd053 100644 (file)
@@ -213,6 +213,7 @@ require_once __DIR__.'/normal/UtfNormalDefines.php';
 define( 'MW_SUPPORTS_EDITFILTERMERGED', 1 );
 define( 'MW_SUPPORTS_PARSERFIRSTCALLINIT', 1 );
 define( 'MW_SUPPORTS_LOCALISATIONCACHE', 1 );
+define( 'MW_SUPPORTS_CONTENTHANDLER', 1 );
 /**@}*/
 
 /** Support for $wgResourceModules */
index f7d9e3f..f2bab7d 100644 (file)
@@ -1007,7 +1007,7 @@ class EditPage {
         * @since 1.21
         */
        public function setPreloadedContent( Content $content ) {
-               $this->mPreloadedContent = $content;
+               $this->mPreloadContent = $content;
        }
 
        /**
index 3212f54..cb0a13f 100644 (file)
@@ -2916,10 +2916,10 @@ class Title {
 
                $linkCache = LinkCache::singleton();
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
-               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
-                       # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
-                       #      as a stop gap, perhaps log this, but don't throw an exception?
-                       throw new MWException( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
+               if ( $cached === null ) { 
+                       // TODO: check the assumption that the cache actually knows about this title
+                       // and handle this, such as get the title from the database.
+                       // See https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
                }
 
                $this->mRedirect = (bool)$cached;
index a4b0cb7..b573b1a 100644 (file)
@@ -75,7 +75,7 @@ class InfoAction extends FormlessAction {
                $pageInfo = $this->pageInfo();
 
                // Allow extensions to add additional information
-               wfRunHooks( 'InfoAction', array( &$pageInfo ) );
+               wfRunHooks( 'InfoAction', array( $this->getContext(), &$pageInfo ) );
 
                // Render page information
                foreach ( $pageInfo as $header => $infoTable ) {
@@ -149,7 +149,7 @@ class InfoAction extends FormlessAction {
         * @return array
         */
        protected function pageInfo() {
-               global $wgContLang, $wgDisableCounters, $wgRCMaxAge;
+               global $wgContLang, $wgRCMaxAge;
 
                $user = $this->getUser();
                $lang = $this->getLanguage();
@@ -157,8 +157,7 @@ class InfoAction extends FormlessAction {
                $id = $title->getArticleID();
 
                // Get page information that would be too "expensive" to retrieve by normal means
-               $userCanViewUnwatchedPages = $user->isAllowed( 'unwatchedpages' );
-               $pageCounts = self::pageCounts( $title, $userCanViewUnwatchedPages, $wgDisableCounters );
+               $pageCounts = self::pageCounts( $title, $user );
 
                // Get page properties
                $dbr = wfGetDB( DB_SLAVE );
@@ -216,14 +215,14 @@ class InfoAction extends FormlessAction {
                        $this->msg( 'pageinfo-robot-policy' ), $this->msg( "pageinfo-robot-${policy['index']}" )
                );
 
-               if ( !$wgDisableCounters ) {
+               if ( isset( $pageCounts['views'] ) ) {
                        // Number of views
                        $pageInfo['header-basic'][] = array(
                                $this->msg( 'pageinfo-views' ), $lang->formatNum( $pageCounts['views'] )
                        );
                }
 
-               if ( $userCanViewUnwatchedPages ) {
+               if ( isset( $pageCounts['watchers'] ) ) {
                        // Number of page watchers
                        $pageInfo['header-basic'][] = array(
                                $this->msg( 'pageinfo-watchers' ), $lang->formatNum( $pageCounts['watchers'] )
@@ -402,12 +401,11 @@ class InfoAction extends FormlessAction {
         * Returns page counts that would be too "expensive" to retrieve by normal means.
         *
         * @param $title Title object
-        * @param $canViewUnwatched bool
-        * @param $disableCounter bool
+        * @param $user User object
         * @return array
         */
-       protected static function pageCounts( $title, $canViewUnwatched, $disableCounter ) {
-               global $wgRCMaxAge;
+       protected static function pageCounts( $title, $user ) {
+               global $wgRCMaxAge, $wgDisableCounters;
 
                wfProfileIn( __METHOD__ );
                $id = $title->getArticleID();
@@ -415,7 +413,7 @@ class InfoAction extends FormlessAction {
                $dbr = wfGetDB( DB_SLAVE );
                $result = array();
 
-               if ( !$disableCounter ) {
+               if ( !$wgDisableCounters ) {
                        // Number of views
                        $views = (int) $dbr->selectField(
                                'page',
@@ -426,7 +424,7 @@ class InfoAction extends FormlessAction {
                        $result['views'] = $views;
                }
 
-               if ( $canViewUnwatched ) {
+               if ( $user->isAllowed( 'unwatchedpages' ) ) {
                        // Number of page watchers
                        $watchers = (int) $dbr->selectField(
                                'watchlist',
index 99413f9..9693789 100644 (file)
@@ -298,6 +298,72 @@ interface IORMTable {
         */
        public function setReadDb( $db );
 
+
+       /**
+        * Get the ID of the any foreign wiki to use as a target for database operations
+        *
+        * @since 1.20
+        *
+        * @return String|bool The target wiki, in a form that  LBFactory understands (or false if the local wiki is used)
+        */
+       public function getTargetWiki();
+
+       /**
+        * Set the ID of the any foreign wiki to use as a target for database operations
+        *
+        * @param String|bool $wiki The target wiki, in a form that  LBFactory understands (or false if the local wiki shall be used)
+        *
+        * @since 1.20
+        */
+       public function setTargetWiki( $wiki );
+
+       /**
+        * Get the database type used for read operations.
+        * This is to be used instead of wfGetDB.
+        *
+        * @see LoadBalancer::getConnection
+        *
+        * @since 1.20
+        *
+        * @return DatabaseBase The database object
+        */
+       public function getReadDbConnection();
+
+       /**
+        * Get the database type used for read operations.
+        * This is to be used instead of wfGetDB.
+        *
+        * @see LoadBalancer::getConnection
+        *
+        * @since 1.20
+        *
+        * @return DatabaseBase The database object
+        */
+       public function getWriteDbConnection();
+
+       /**
+        * Get the database type used for read operations.
+        *
+        * @see wfGetLB
+        *
+        * @since 1.20
+        *
+        * @return LoadBalancer The database load balancer object
+        */
+       public function getLoadBalancer();
+
+       /**
+        * Releases the lease on the given database connection. This is useful mainly
+        * for connections to a foreign wiki. It does nothing for connections to the local wiki.
+        *
+        * @see LoadBalancer::reuseConnection
+        *
+        * @param DatabaseBase $db the database
+        *
+        * @since 1.20
+        */
+       public function releaseConnection( DatabaseBase $db );
+
        /**
         * Update the records matching the provided conditions by
         * setting the fields that are keys in the $values param to
index a77074f..bcbf17f 100644 (file)
@@ -47,7 +47,7 @@ abstract class ORMTable implements IORMTable {
        protected static $instanceCache = array();
 
        /**
-        * The database connection to use for read operations.
+        * ID of the database connection to use for read operations.
         * Can be changed via @see setReadDb.
         *
         * @since 1.20
@@ -55,6 +55,15 @@ abstract class ORMTable implements IORMTable {
         */
        protected $readDb = DB_SLAVE;
 
+       /**
+        * The ID of any foreign wiki to use as a target for database operations,
+        * or false to use the local wiki.
+        *
+        * @since 1.20
+        * @var String|bool
+        */
+       protected $wiki = false;
+
        /**
         * Returns a list of default field values.
         * field name => field value
@@ -145,13 +154,17 @@ abstract class ORMTable implements IORMTable {
                        $fields = (array)$fields;
                }
 
-               return wfGetDB( $this->getReadDb() )->select(
+               $dbr = $this->getReadDbConnection();
+               $result = $dbr->select(
                        $this->getName(),
                        $this->getPrefixedFields( $fields ),
                        $this->getPrefixedValues( $conditions ),
                        is_null( $functionName ) ? __METHOD__ : $functionName,
                        $options
                );
+
+               $this->releaseConnection( $dbr );
+               return $result;
        }
 
        /**
@@ -241,15 +254,18 @@ abstract class ORMTable implements IORMTable {
         */
        public function rawSelectRow( array $fields, array $conditions = array(),
                                                                  array $options = array(), $functionName = null ) {
-               $dbr = wfGetDB( $this->getReadDb() );
+               $dbr = $this->getReadDbConnection();
 
-               return $dbr->selectRow(
+               $result = $dbr->selectRow(
                        $this->getName(),
                        $fields,
                        $conditions,
                        is_null( $functionName ) ? __METHOD__ : $functionName,
                        $options
                );
+
+               $this->releaseConnection( $dbr );
+               return $result;
        }
 
        /**
@@ -327,11 +343,16 @@ abstract class ORMTable implements IORMTable {
         * @return boolean Success indicator
         */
        public function delete( array $conditions, $functionName = null ) {
-               return wfGetDB( DB_MASTER )->delete(
+               $dbw = $this->getWriteDbConnection();
+
+               $result = $dbw->delete(
                        $this->getName(),
                        $conditions === array() ? '*' : $this->getPrefixedValues( $conditions ),
                        $functionName
                ) !== false; // DatabaseBase::delete does not always return true for success as documented...
+
+               $this->releaseConnection( $dbw );
+               return $result;
        }
        
        /**
@@ -397,7 +418,7 @@ abstract class ORMTable implements IORMTable {
        }
 
        /**
-        * Get the database type used for read operations.
+        * Get the database ID used for read operations.
         *
         * @since 1.20
         *
@@ -408,7 +429,7 @@ abstract class ORMTable implements IORMTable {
        }
 
        /**
-        * Set the database type to use for read operations.
+        * Set the database ID to use for read operations, use DB_XXX constants or an index to the load balancer setup.
         *
         * @param integer $db
         *
@@ -418,6 +439,86 @@ abstract class ORMTable implements IORMTable {
                $this->readDb = $db;
        }
 
+       /**
+        * Get the ID of the any foreign wiki to use as a target for database operations
+        *
+        * @since 1.20
+        *
+        * @return String|bool The target wiki, in a form that  LBFactory understands (or false if the local wiki is used)
+        */
+       public function getTargetWiki() {
+               return $this->wiki;
+       }
+
+       /**
+        * Set the ID of the any foreign wiki to use as a target for database operations
+        *
+        * @param String|bool $wiki The target wiki, in a form that  LBFactory understands (or false if the local wiki shall be used)
+        *
+        * @since 1.20
+        */
+       public function setTargetWiki( $wiki ) {
+               $this->wiki = $wiki;
+       }
+
+       /**
+        * Get the database type used for read operations.
+        * This is to be used instead of wfGetDB.
+        *
+        * @see LoadBalancer::getConnection
+        *
+        * @since 1.20
+        *
+        * @return DatabaseBase The database object
+        */
+       public function getReadDbConnection() {
+               return $this->getLoadBalancer()->getConnection( $this->getReadDb(), array(), $this->getTargetWiki() );
+       }
+
+       /**
+        * Get the database type used for read operations.
+        * This is to be used instead of wfGetDB.
+        *
+        * @see LoadBalancer::getConnection
+        *
+        * @since 1.20
+        *
+        * @return DatabaseBase The database object
+        */
+       public function getWriteDbConnection() {
+               return $this->getLoadBalancer()->getConnection( DB_MASTER, array(), $this->getTargetWiki() );
+       }
+
+       /**
+        * Get the database type used for read operations.
+        *
+        * @see wfGetLB
+        *
+        * @since 1.20
+        *
+        * @return LoadBalancer The database load balancer object
+        */
+       public function getLoadBalancer() {
+               return wfGetLB( $this->getTargetWiki() );
+       }
+
+       /**
+        * Releases the lease on the given database connection. This is useful mainly
+        * for connections to a foreign wiki. It does nothing for connections to the local wiki.
+        *
+        * @see LoadBalancer::reuseConnection
+        *
+        * @param DatabaseBase $db the database
+        *
+        * @since 1.20
+        */
+       public function releaseConnection( DatabaseBase $db ) {
+               if ( $this->wiki !== false ) {
+                       // recycle connection to foreign wiki
+                       $this->getLoadBalancer()->reuseConnection( $db );
+               }
+       }
+
        /**
         * Update the records matching the provided conditions by
         * setting the fields that are keys in the $values param to
@@ -431,14 +532,17 @@ abstract class ORMTable implements IORMTable {
         * @return boolean Success indicator
         */
        public function update( array $values, array $conditions = array() ) {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getWriteDbConnection();
 
-               return $dbw->update(
+               $result = $dbw->update(
                        $this->getName(),
                        $this->getPrefixedValues( $values ),
                        $this->getPrefixedValues( $conditions ),
                        __METHOD__
                ) !== false; // DatabaseBase::update does not always return true for success as documented...
+
+               $this->releaseConnection( $dbw );
+               return $result;
        }
 
        /**
@@ -450,6 +554,7 @@ abstract class ORMTable implements IORMTable {
         * @param array $conditions
         */
        public function updateSummaryFields( $summaryFields = null, array $conditions = array() ) {
+               $slave = $this->getReadDb();
                $this->setReadDb( DB_MASTER );
 
                /**
@@ -461,7 +566,7 @@ abstract class ORMTable implements IORMTable {
                        $item->save();
                }
 
-               $this->setReadDb( DB_SLAVE );
+               $this->setReadDb( $slave );
        }
 
        /**