r98746 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98745‎ | r98746 | r98747 >
Date:10:42, 3 October 2011
Author:catrope
Status:ok
Tags:
Comment:
1.18wmf1: MFT r98744, r98745
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/CentralAuth/CentralAuthHooks.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ExtensionDistributor/ExtensionDistributor_body.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/WikiMap.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/ExtensionDistributor_body.php
@@ -249,7 +249,7 @@
250250 }
251251 }
252252
253 - $url = "$wgExtDistTarUrl/$tarName";
 253+ $url = wfExpandUrl( "$wgExtDistTarUrl/$tarName", PROTO_CURRENT );
254254
255255 // Show a message
256256 $wgOut->addWikiMsg( 'extdist-created', $extension, "r$rev",
Index: branches/wmf/1.18wmf1/extensions/CentralAuth/CentralAuthHooks.php
@@ -163,7 +163,8 @@
164164 $wgMemc->set( CentralAuthUser::memcKey( 'login-token', $loginToken ), $data, 600 );
165165
166166 $wiki = WikiMap::getWiki( $wiki );
167 - $url = wfAppendQuery( $wiki->getUrl( 'Special:AutoLogin' ), "token=$loginToken" );
 167+ // Use WikiReference::getFullUrl(), returns a protocol-relative URL if needed
 168+ $url = wfAppendQuery( $wiki->getFullUrl( 'Special:AutoLogin' ), "token=$loginToken" );
168169
169170 $inject_html .= Xml::element( 'img',
170171 array(
Index: branches/wmf/1.18wmf1/includes/WikiMap.php
@@ -18,11 +18,13 @@
1919
2020 list( $major, $minor ) = $wgConf->siteFromDB( $wikiID );
2121 if( isset( $major ) ) {
22 - $server = $wgConf->get( 'wgCanonicalServer', $wikiID, $major,
 22+ $canonicalServer = $wgConf->get( 'wgCanonicalServer', $wikiID, $major,
2323 array( 'lang' => $minor, 'site' => $major ) );
 24+ $server = $wgConf->get( 'wgServer', $wikiID, $major,
 25+ array( 'lang' => $minor, 'site' => $major ) );
2426 $path = $wgConf->get( 'wgArticlePath', $wikiID, $major,
2527 array( 'lang' => $minor, 'site' => $major ) );
26 - return new WikiReference( $major, $minor, $server, $path );
 28+ return new WikiReference( $major, $minor, $canonicalServer, $path, $server );
2729 } else {
2830 return null;
2931 }
@@ -101,21 +103,23 @@
102104 class WikiReference {
103105 private $mMinor; ///< 'en', 'meta', 'mediawiki', etc
104106 private $mMajor; ///< 'wiki', 'wiktionary', etc
105 - private $mServer; ///< server override, 'www.mediawiki.org'
106 - private $mPath; ///< path override, '/wiki/$1'
 107+ private $mCanonicalServer; ///< canonical server URL, e.g. 'http://www.mediawiki.org'
 108+ private $mServer; ///< server URL, may be protocol-relative, e.g. '//www.mediawiki.org'
 109+ private $mPath; ///< path, '/wiki/$1'
107110
108 - public function __construct( $major, $minor, $server, $path ) {
 111+ public function __construct( $major, $minor, $canonicalServer, $path, $server = null ) {
109112 $this->mMajor = $major;
110113 $this->mMinor = $minor;
111 - $this->mServer = $server;
 114+ $this->mCanonicalServer = $canonicalServer;
112115 $this->mPath = $path;
 116+ $this->mServer = $server === null ? $canonicalServer : $server;
113117 }
114118
115119 public function getHostname() {
116120 $prefixes = array( 'http://', 'https://' );
117121 foreach ( $prefixes as $prefix ) {
118 - if ( substr( $this->mServer, 0, strlen( $prefix ) ) ) {
119 - return substr( $this->mServer, strlen( $prefix ) );
 122+ if ( substr( $this->mCanonicalServer, 0, strlen( $prefix ) ) ) {
 123+ return substr( $this->mCanonicalServer, strlen( $prefix ) );
120124 }
121125 }
122126 throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" );
@@ -150,12 +154,32 @@
151155 }
152156
153157 /**
154 - * Get a URL to a page on this foreign wiki
 158+ * Get a canonical (i.e. based on $wgCanonicalServer) URL to a page on this foreign wiki
155159 *
156160 * @param $page String: page name (must be normalised before calling this function!)
157161 * @return String: Url
158162 */
 163+ public function getCanonicalUrl( $page ) {
 164+ return
 165+ $this->mCanonicalServer .
 166+ $this->getLocalUrl( $page );
 167+ }
 168+
 169+ /**
 170+ * Alias for getCanonicalUrl(), for backwards compatibility.
 171+ */
159172 public function getUrl( $page ) {
 173+ return $this->getCanonicalUrl( $page );
 174+ }
 175+
 176+ /**
 177+ * Get a URL based on $wgServer, like Title::getFullUrl() would produce
 178+ * when called locally on the wiki.
 179+ *
 180+ * @param $page String: page name (must be normalized before calling this function!)
 181+ * @return String: URL
 182+ */
 183+ public function getFullUrl( $page ) {
160184 return
161185 $this->mServer .
162186 $this->getLocalUrl( $page );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98744ExtensionDistributor: Don't display a protocol-relative URL in plain text (or...catrope10:24, 3 October 2011
r98745(bug 31320) CentralAuth uses http URLs for autologin images when logging in o...catrope10:27, 3 October 2011

Status & tagging log