Merge "Allow reset of global services (redux)."
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index f8f078f..537bdef 100644 (file)
@@ -501,12 +501,26 @@ function wfAppendQuery( $url, $query ) {
                $query = wfArrayToCgi( $query );
        }
        if ( $query != '' ) {
+               // Remove the fragment, if there is one
+               $fragment = false;
+               $hashPos = strpos( $url, '#' );
+               if ( $hashPos !== false ) {
+                       $fragment = substr( $url, $hashPos );
+                       $url = substr( $url, 0, $hashPos );
+               }
+
+               // Add parameter
                if ( false === strpos( $url, '?' ) ) {
                        $url .= '?';
                } else {
                        $url .= '&';
                }
                $url .= $query;
+
+               // Put the fragment back
+               if ( $fragment !== false ) {
+                       $url .= $fragment;
+               }
        }
        return $url;
 }
@@ -2937,7 +2951,7 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1,
 
 /**
  * @deprecated since 1.27, PHP's session generation isn't used with
- *  MediaWiki\\Session\\SessionManager
+ *  MediaWiki\Session\SessionManager
  */
 function wfFixSessionID() {
        wfDeprecated( __FUNCTION__, '1.27' );
@@ -2946,7 +2960,7 @@ function wfFixSessionID() {
 /**
  * Reset the session id
  *
- * @deprecated since 1.27, use MediaWiki\\Session\\SessionManager instead
+ * @deprecated since 1.27, use MediaWiki\Session\SessionManager instead
  * @since 1.22
  */
 function wfResetSessionID() {
@@ -2968,7 +2982,7 @@ function wfResetSessionID() {
 /**
  * Initialise php session
  *
- * @deprecated since 1.27, use MediaWiki\\Session\\SessionManager instead.
+ * @deprecated since 1.27, use MediaWiki\Session\SessionManager instead.
  *  Generally, "using" SessionManager will be calling ->getSessionById() or
  *  ::getGlobalSession() (depending on whether you were passing $sessionId
  *  here), then calling $session->persist().
@@ -3109,6 +3123,9 @@ function wfSplitWikiID( $wiki ) {
  * Note 2: use $this->getDB() in maintenance scripts that may be invoked by
  * updater to ensure that a proper database is being updated.
  *
+ * @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection()
+ *       on an injected instance of LoadBalancer.
+ *
  * @return DatabaseBase
  */
 function wfGetDB( $db, $groups = [], $wiki = false ) {
@@ -3118,20 +3135,30 @@ function wfGetDB( $db, $groups = [], $wiki = false ) {
 /**
  * Get a load balancer object.
  *
+ * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancer()
+ *              or MediaWikiServices::getDBLoadBalancerFactory() instead.
+ *
  * @param string|bool $wiki Wiki ID, or false for the current wiki
  * @return LoadBalancer
  */
 function wfGetLB( $wiki = false ) {
-       return wfGetLBFactory()->getMainLB( $wiki );
+       if ( $wiki === false ) {
+               return \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancer();
+       } else {
+               $factory = \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               return $factory->getMainLB( $wiki );
+       }
 }
 
 /**
  * Get the load balancer factory object
  *
+ * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancerFactory() instead.
+ *
  * @return LBFactory
  */
 function wfGetLBFactory() {
-       return LBFactory::singleton();
+       return \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
 }
 
 /**