From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/site/MediaWikiSite.php | 44 +++++++++++---------- includes/site/Site.php | 32 ++++++++------- includes/site/SiteList.php | 88 ++++++++++++++++++++++++++++++++++------- includes/site/SiteSQLStore.php | 52 ++++++++++-------------- includes/site/SiteStore.php | 8 ++-- 5 files changed, 139 insertions(+), 85 deletions(-) (limited to 'includes/site') diff --git a/includes/site/MediaWikiSite.php b/includes/site/MediaWikiSite.php index f3b8a0c7..9711f042 100644 --- a/includes/site/MediaWikiSite.php +++ b/includes/site/MediaWikiSite.php @@ -33,15 +33,14 @@ * @ingroup Site */ class MediaWikiSite extends Site { - const PATH_FILE = 'file_path'; const PATH_PAGE = 'page_path'; /** * @since 1.21 - * @deprecated Just use the constructor or the factory Site::newForType + * @deprecated since 1.21 Just use the constructor or the factory Site::newForType * - * @param integer $globalId + * @param int $globalId * * @return MediaWikiSite */ @@ -67,23 +66,25 @@ class MediaWikiSite extends Site { * * @since 1.21 * - * @param string $title the target page's title, in normalized form. + * @param string $title The target page's title, in normalized form. * - * @return String + * @return string */ public function toDBKey( $title ) { return str_replace( ' ', '_', $title ); } /** - * Returns the normalized form of the given page title, using the normalization rules of the given site. - * If the given title is a redirect, the redirect weill be resolved and the redirect target is returned. + * Returns the normalized form of the given page title, using the + * normalization rules of the given site. If the given title is a redirect, + * the redirect weill be resolved and the redirect target is returned. * - * @note : This actually makes an API request to the remote site, so beware that this function is slow and depends - * on an external service. + * @note This actually makes an API request to the remote site, so beware + * that this function is slow and depends on an external service. * - * @note : If MW_PHPUNIT_TEST is defined, the call to the external site is skipped, and the title - * is normalized using the local normalization rules as implemented by the Title class. + * @note If MW_PHPUNIT_TEST is defined, the call to the external site is + * skipped, and the title is normalized using the local normalization + * rules as implemented by the Title class. * * @see Site::normalizePageName * @@ -103,8 +104,10 @@ class MediaWikiSite extends Site { // Go on call the external site if ( defined( 'MW_PHPUNIT_TEST' ) ) { - // If the code is under test, don't call out to other sites, just normalize locally. - // Note: this may cause results to be inconsistent with the actual normalization used by the respective remote site! + // If the code is under test, don't call out to other sites, just + // normalize locally. + // Note: this may cause results to be inconsistent with the actual + // normalization used by the respective remote site! $t = Title::newFromText( $pageName ); return $t->getPrefixedText(); @@ -152,12 +155,14 @@ class MediaWikiSite extends Site { $page = static::extractPageRecord( $data, $pageName ); if ( isset( $page['missing'] ) ) { - wfDebugLog( "MediaWikiSite", "call to <$url> returned a marker for a missing page title! " . $ret ); + wfDebugLog( "MediaWikiSite", "call to <$url> returned a marker for a missing page title! " + . $ret ); return false; } if ( isset( $page['invalid'] ) ) { - wfDebugLog( "MediaWikiSite", "call to <$url> returned a marker for an invalid page title! " . $ret ); + wfDebugLog( "MediaWikiSite", "call to <$url> returned a marker for an invalid page title! " + . $ret ); return false; } @@ -177,7 +182,7 @@ class MediaWikiSite extends Site { * @param array $externalData A reply from the API on a external server. * @param string $pageTitle Identifies the page at the external site, needing normalization. * - * @return array|boolean a 'page' structure representing the page identified by $pageTitle. + * @return array|bool A 'page' structure representing the page identified by $pageTitle. */ private static function extractPageRecord( $externalData, $pageTitle ) { // If there is a special case with only one returned page @@ -210,7 +215,7 @@ class MediaWikiSite extends Site { // Filter the substructure down to what we actually are using. $collectedHits = array_filter( array_values( $externalData['query'][$listId] ), - function( $a ) use ( $fieldId, $pageTitle ) { + function ( $a ) use ( $fieldId, $pageTitle ) { return $a[$fieldId] === $pageTitle; } ); @@ -309,7 +314,7 @@ class MediaWikiSite extends Site { * * @since 1.21 * - * @param string|boolean $pageName Page name or false (default: false) + * @param string|bool $pageName Page name or false (default: false) * * @return string */ @@ -335,7 +340,7 @@ class MediaWikiSite extends Site { * * @since 1.21 * - * @param string|boolean $path + * @param string|bool $path * * @return string */ @@ -348,5 +353,4 @@ class MediaWikiSite extends Site { return $filePath; } - } diff --git a/includes/site/Site.php b/includes/site/Site.php index 076dc88c..fafb14c7 100644 --- a/includes/site/Site.php +++ b/includes/site/Site.php @@ -27,7 +27,6 @@ * @author Jeroen De Dauw < jeroendedauw@gmail.com > */ class Site implements Serializable { - const TYPE_UNKNOWN = 'unknown'; const TYPE_MEDIAWIKI = 'mediawiki'; @@ -234,7 +233,7 @@ class Site implements Serializable { * * @since 1.21 * - * @return boolean + * @return bool */ public function shouldForward() { return $this->forward; @@ -246,7 +245,7 @@ class Site implements Serializable { * * @since 1.21 * - * @param boolean $shouldForward + * @param bool $shouldForward * * @throws MWException */ @@ -340,11 +339,12 @@ class Site implements Serializable { } /** - * Returns the main path type, that is the type of the path that should generally be used to construct links - * to the target site. + * Returns the main path type, that is the type of the path that should + * generally be used to construct links to the target site. * - * This default implementation returns Site::PATH_LINK as the default path type. Subclasses can override this - * to define a different default path type, or return false to disable site links. + * This default implementation returns Site::PATH_LINK as the default path + * type. Subclasses can override this to define a different default path + * type, or return false to disable site links. * * @since 1.21 * @@ -365,9 +365,9 @@ class Site implements Serializable { * * @since 1.21 * - * @param bool|String $pageName + * @param bool|string $pageName * - * @return string|boolean false + * @return string|bool */ public function getPageUrl( $pageName = false ) { $url = $this->getLinkPath(); @@ -541,7 +541,9 @@ class Site implements Serializable { * @return string[] */ public function getInterwikiIds() { - return array_key_exists( self::ID_INTERWIKI, $this->localIds ) ? $this->localIds[self::ID_INTERWIKI] : array(); + return array_key_exists( self::ID_INTERWIKI, $this->localIds ) + ? $this->localIds[self::ID_INTERWIKI] + : array(); } /** @@ -553,7 +555,9 @@ class Site implements Serializable { * @return string[] */ public function getNavigationIds() { - return array_key_exists( self::ID_EQUIVALENT, $this->localIds ) ? $this->localIds[self::ID_EQUIVALENT] : array(); + return array_key_exists( self::ID_EQUIVALENT, $this->localIds ) + ? $this->localIds[self::ID_EQUIVALENT] : + array(); } /** @@ -693,10 +697,10 @@ class Site implements Serializable { $this->setForward( $fields['forward'] ); $this->setInternalId( $fields['internalid'] ); } - } /** - * @deprecated + * @deprecated since 1.21 */ -class SiteObject extends Site {} +class SiteObject extends Site { +} diff --git a/includes/site/SiteList.php b/includes/site/SiteList.php index b0d1f95b..2d9f22dd 100644 --- a/includes/site/SiteList.php +++ b/includes/site/SiteList.php @@ -27,13 +27,12 @@ * @author Jeroen De Dauw < jeroendedauw@gmail.com > */ class SiteList extends GenericArrayObject { - /** * Internal site identifiers pointing to their sites offset value. * * @since 1.21 * - * @var array of integer + * @var array Array of integer */ protected $byInternalId = array(); @@ -42,10 +41,20 @@ class SiteList extends GenericArrayObject { * * @since 1.21 * - * @var array of string + * @var array Array of string */ protected $byGlobalId = array(); + /** + * Navigational site identifiers alias inter-language prefixes + * pointing to their sites offset value. + * + * @since 1.23 + * + * @var array Array of string + */ + protected $byNavigationId = array(); + /** * @see GenericArrayObject::getObjectType * @@ -65,7 +74,7 @@ class SiteList extends GenericArrayObject { * @param int|string $index * @param Site $site * - * @return boolean + * @return bool */ protected function preSetElement( $index, $site ) { if ( $this->hasSite( $site->getGlobalId() ) ) { @@ -75,6 +84,11 @@ class SiteList extends GenericArrayObject { $this->byGlobalId[$site->getGlobalId()] = $index; $this->byInternalId[$site->getInternalId()] = $index; + $ids = $site->getNavigationIds(); + foreach ( $ids as $navId ) { + $this->byNavigationId[$navId] = $index; + } + return true; } @@ -94,6 +108,11 @@ class SiteList extends GenericArrayObject { unset( $this->byGlobalId[$site->getGlobalId()] ); unset( $this->byInternalId[$site->getInternalId()] ); + + $ids = $site->getNavigationIds(); + foreach ( $ids as $navId ) { + unset( $this->byNavigationId[$navId] ); + } } parent::offsetUnset( $index ); @@ -116,7 +135,7 @@ class SiteList extends GenericArrayObject { * * @param string $globalSiteId * - * @return boolean + * @return bool */ public function hasSite( $globalSiteId ) { return array_key_exists( $globalSiteId, $this->byGlobalId ); @@ -153,7 +172,7 @@ class SiteList extends GenericArrayObject { * * @since 1.21 * - * @return boolean + * @return bool */ public function isEmpty() { return $this->byGlobalId === array(); @@ -162,9 +181,9 @@ class SiteList extends GenericArrayObject { /** * Returns if the list contains the site with the provided site id. * - * @param integer $id + * @param int $id * - * @return boolean + * @return bool */ public function hasInternalId( $id ) { return array_key_exists( $id, $this->byInternalId ); @@ -176,7 +195,7 @@ class SiteList extends GenericArrayObject { * * @since 1.21 * - * @param integer $id + * @param int $id * * @return Site */ @@ -190,12 +209,49 @@ class SiteList extends GenericArrayObject { * * @since 1.21 * - * @param integer $id + * @param int $id */ public function removeSiteByInternalId( $id ) { $this->offsetUnset( $this->byInternalId[$id] ); } + /** + * Returns if the list contains the site with the provided navigational site id. + * + * @param string $id + * + * @return bool + */ + public function hasNavigationId( $id ) { + return array_key_exists( $id, $this->byNavigationId ); + } + + /** + * Returns the Site with the provided navigational site id. + * The site needs to exist, so if not sure, call has first. + * + * @since 1.23 + * + * @param string $id + * + * @return Site + */ + public function getSiteByNavigationId( $id ) { + return $this->offsetGet( $this->byNavigationId[$id] ); + } + + /** + * Removes the site with the specified navigational site id. + * The site needs to exist, so if not sure, call has first. + * + * @since 1.23 + * + * @param string $id + */ + public function removeSiteByNavigationId( $id ) { + $this->offsetUnset( $this->byNavigationId[$id] ); + } + /** * Sets a site in the list. If the site was not there, * it will be added. If it was, it will be updated. @@ -221,7 +277,7 @@ class SiteList extends GenericArrayObject { $group = new self(); /** - * @var \Site $site + * @var Site $site */ foreach ( $this as $site ) { if ( $site->getGroup() === $groupName ) { @@ -240,7 +296,7 @@ class SiteList extends GenericArrayObject { * @var string A string uniquely identifying the version of the serialization structure, * not including any sub-structures. */ - const SERIAL_VERSION_ID = '2013-02-07'; + const SERIAL_VERSION_ID = '2014-03-17'; /** * Returns the version ID that identifies the serialization structure used by @@ -270,6 +326,7 @@ class SiteList extends GenericArrayObject { array( 'internalIds' => $this->byInternalId, 'globalIds' => $this->byGlobalId, + 'navigationIds' => $this->byNavigationId ) ); } @@ -288,13 +345,14 @@ class SiteList extends GenericArrayObject { $this->byInternalId = $serializationData['internalIds']; $this->byGlobalId = $serializationData['globalIds']; + $this->byNavigationId = $serializationData['navigationIds']; return $serializationData; } - } /** - * @deprecated + * @deprecated since 1.21 */ -class SiteArray extends SiteList {} +class SiteArray extends SiteList { +} diff --git a/includes/site/SiteSQLStore.php b/includes/site/SiteSQLStore.php index 11141e07..d1334680 100644 --- a/includes/site/SiteSQLStore.php +++ b/includes/site/SiteSQLStore.php @@ -29,7 +29,6 @@ * @author Jeroen De Dauw < jeroendedauw@gmail.com > */ class SiteSQLStore implements SiteStore { - /** * @since 1.21 * @@ -90,7 +89,7 @@ class SiteSQLStore implements SiteStore { * * @see SiteList::getSerialVersionId * - * @return String The cache key. + * @return string The cache key. */ protected function getCacheKey() { wfProfileIn( __METHOD__ ); @@ -115,7 +114,7 @@ class SiteSQLStore implements SiteStore { * * @since 1.21 * - * @param string $source either 'cache' or 'recache' + * @param string $source Either 'cache' or 'recache' * * @return SiteList */ @@ -169,7 +168,10 @@ class SiteSQLStore implements SiteStore { } if ( $siteRow->hasField( 'language' ) ) { - $site->setLanguageCode( $siteRow->getField( 'language' ) === '' ? null : $siteRow->getField( 'language' ) ); + $site->setLanguageCode( $siteRow->getField( 'language' ) === '' + ? null + : $siteRow->getField( 'language' ) + ); } if ( $siteRow->hasField( 'source' ) ) { @@ -193,7 +195,7 @@ class SiteSQLStore implements SiteStore { * * @since 1.22 * - * @param Site + * @param Site $site * * @return ORMRow */ @@ -287,7 +289,7 @@ class SiteSQLStore implements SiteStore { * * @param Site $site * - * @return boolean Success indicator + * @return bool Success indicator */ public function saveSite( Site $site ) { return $this->saveSites( array( $site ) ); @@ -300,7 +302,7 @@ class SiteSQLStore implements SiteStore { * * @param Site[] $sites * - * @return boolean Success indicator + * @return bool Success indicator */ public function saveSites( array $sites ) { wfProfileIn( __METHOD__ ); @@ -312,11 +314,7 @@ class SiteSQLStore implements SiteStore { $dbw = $this->sitesTable->getWriteDbConnection(); - $trx = $dbw->trxLevel(); - - if ( $trx == 0 ) { - $dbw->begin( __METHOD__ ); - } + $dbw->startAtomic( __METHOD__ ); $success = true; @@ -358,9 +356,7 @@ class SiteSQLStore implements SiteStore { ); } - if ( $trx == 0 ) { - $dbw->commit( __METHOD__ ); - } + $dbw->endAtomic( __METHOD__ ); // purge cache $this->reset(); @@ -390,24 +386,16 @@ class SiteSQLStore implements SiteStore { * * @see SiteStore::clear() * - * @return bool success + * @return bool Success */ public function clear() { wfProfileIn( __METHOD__ ); $dbw = $this->sitesTable->getWriteDbConnection(); - $trx = $dbw->trxLevel(); - - if ( $trx == 0 ) { - $dbw->begin( __METHOD__ ); - } - + $dbw->startAtomic( __METHOD__ ); $ok = $dbw->delete( 'sites', '*', __METHOD__ ); $ok = $dbw->delete( 'site_identifiers', '*', __METHOD__ ) && $ok; - - if ( $trx == 0 ) { - $dbw->commit( __METHOD__ ); - } + $dbw->endAtomic( __METHOD__); $this->reset(); @@ -458,7 +446,7 @@ class SiteSQLStore implements SiteStore { } /** - * @deprecated + * @deprecated since 1.21 */ class Sites extends SiteSQLStore { @@ -466,9 +454,9 @@ class Sites extends SiteSQLStore { * Factory for creating new site objects. * * @since 1.21 - * @deprecated + * @deprecated since 1.21 * - * @param string|boolean false $globalId + * @param string|bool $globalId * * @return Site */ @@ -483,7 +471,7 @@ class Sites extends SiteSQLStore { } /** - * @deprecated + * @deprecated since 1.21 * @return SiteStore */ public static function singleton() { @@ -497,11 +485,11 @@ class Sites extends SiteSQLStore { } /** - * @deprecated + * @deprecated since 1.21 + * @param string $group * @return SiteList */ public function getSiteGroup( $group ) { return $this->getSites()->getGroup( $group ); } - } diff --git a/includes/site/SiteStore.php b/includes/site/SiteStore.php index 52ba8fbf..537f1ccb 100644 --- a/includes/site/SiteStore.php +++ b/includes/site/SiteStore.php @@ -35,7 +35,7 @@ interface SiteStore { * * @param Site $site * - * @return boolean Success indicator + * @return bool Success indicator */ public function saveSite( Site $site ); @@ -46,7 +46,7 @@ interface SiteStore { * * @param Site[] $sites * - * @return boolean Success indicator + * @return bool Success indicator */ public function saveSites( array $sites ); @@ -56,7 +56,7 @@ interface SiteStore { * @since 1.21 * * @param string $globalId - * @param string $source either 'cache' or 'recache'. + * @param string $source Either 'cache' or 'recache'. * If 'cache', the values are allowed (but not obliged) to come from a cache. * * @return Site|null @@ -70,7 +70,7 @@ interface SiteStore { * * @since 1.21 * - * @param string $source either 'cache' or 'recache'. + * @param string $source Either 'cache' or 'recache'. * If 'cache', the values are allowed (but not obliged) to come from a cache. * * @return SiteList -- cgit v1.2.3-54-g00ecf