diff options
Diffstat (limited to 'includes/site')
-rw-r--r-- | includes/site/MediaWikiSite.php | 8 | ||||
-rw-r--r-- | includes/site/SiteSQLStore.php | 52 |
2 files changed, 38 insertions, 22 deletions
diff --git a/includes/site/MediaWikiSite.php b/includes/site/MediaWikiSite.php index 05092723..f3b8a0c7 100644 --- a/includes/site/MediaWikiSite.php +++ b/includes/site/MediaWikiSite.php @@ -123,17 +123,17 @@ class MediaWikiSite extends Site { 'converttitles' => true, 'format' => 'json', 'titles' => $pageName, - //@todo: options for maxlag and maxage + // @todo options for maxlag and maxage // Note that maxlag will lead to a long delay before a reply is made, // but that maxage can avoid the extreme delay. On the other hand // maxage could be nice to use anyhow as it stops unnecessary requests. // Also consider smaxage if maxage is used. ); - $url = $this->getFileUrl( 'api.php' ) . '?' . wfArrayToCgi( $args ); + $url = wfAppendQuery( $this->getFileUrl( 'api.php' ), $args ); // Go on call the external site - //@todo: we need a good way to specify a timeout here. + // @todo we need a good way to specify a timeout here. $ret = Http::get( $url ); } @@ -185,7 +185,7 @@ class MediaWikiSite extends Site { // the single page in the "pages" substructure. if ( isset( $externalData['query']['pages'] ) ) { $pages = array_values( $externalData['query']['pages'] ); - if ( count( $pages) === 1 ) { + if ( count( $pages ) === 1 ) { return $pages[0]; } } diff --git a/includes/site/SiteSQLStore.php b/includes/site/SiteSQLStore.php index 41238055..11141e07 100644 --- a/includes/site/SiteSQLStore.php +++ b/includes/site/SiteSQLStore.php @@ -189,6 +189,39 @@ class SiteSQLStore implements SiteStore { } /** + * Get a new ORMRow from a Site object + * + * @since 1.22 + * + * @param Site + * + * @return ORMRow + */ + protected function getRowFromSite( Site $site ) { + $fields = array( + // Site data + 'global_key' => $site->getGlobalId(), // TODO: check not null + 'type' => $site->getType(), + 'group' => $site->getGroup(), + 'source' => $site->getSource(), + 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(), + 'protocol' => $site->getProtocol(), + 'domain' => strrev( $site->getDomain() ) . '.', + 'data' => $site->getExtraData(), + + // Site config + 'forward' => $site->shouldForward(), + 'config' => $site->getExtraConfig(), + ); + + if ( $site->getInternalId() !== null ) { + $fields['id'] = $site->getInternalId(); + } + + return new ORMRow( $this->sitesTable, $fields ); + } + + /** * Fetches the site from the database and loads them into the sites field. * * @since 1.21 @@ -291,28 +324,11 @@ class SiteSQLStore implements SiteStore { $localIds = array(); foreach ( $sites as $site ) { - $fields = array( - // Site data - 'global_key' => $site->getGlobalId(), // TODO: check not null - 'type' => $site->getType(), - 'group' => $site->getGroup(), - 'source' => $site->getSource(), - 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(), - 'protocol' => $site->getProtocol(), - 'domain' => strrev( $site->getDomain() ) . '.', - 'data' => $site->getExtraData(), - - // Site config - 'forward' => $site->shouldForward(), - 'config' => $site->getExtraConfig(), - ); - if ( $site->getInternalId() !== null ) { - $fields['id'] = $site->getInternalId(); $internalIds[] = $site->getInternalId(); } - $siteRow = new ORMRow( $this->sitesTable, $fields ); + $siteRow = $this->getRowFromSite( $site ); $success = $siteRow->save( __METHOD__ ) && $success; foreach ( $site->getLocalIds() as $idType => $ids ) { |