r94562 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94561‎ | r94562 | r94563 >
Date:20:30, 15 August 2011
Author:catrope
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/ArticleFeedback/api/ApiArticleFeedback.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/ArticleFeedback/populateAFRevisions.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/CodeReview/backend/CodeCommentLinker.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/Collection/Collection.body.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/Collection/Collection.templates.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/Narayam/Narayam.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/SiteMatrix/SiteMatrixApi.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/GlobalFunctions.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiFormatBase.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/Narayam/Narayam.php
@@ -204,13 +204,14 @@
205205 'messages' => array( 'narayam-si-wijesekara' ),
206206 'dependencies' => 'ext.narayam.core',
207207 );
208 -$wgResourceModules['ext.narayam.rules.ta99'] = $narayamTpl + array(
209 - 'scripts' => 'ext.narayam.rules.ta99.js',
210 - 'messages' => array( 'narayam-ta99' ),
211 - 'dependencies' => 'ext.narayam.core',
212 -);
213208 $wgResourceModules['ext.narayam.rules.ta'] = $narayamTpl + array(
214209 'scripts' => 'ext.narayam.rules.ta.js',
215210 'messages' => array( 'narayam-ta' ),
216211 'dependencies' => 'ext.narayam.core',
217212 );
 213+$wgResourceModules['ext.narayam.rules.ta99'] = $narayamTpl + array(
 214+ 'scripts' => 'ext.narayam.rules.ta99.js',
 215+ 'messages' => array( 'narayam-ta99' ),
 216+ 'dependencies' => 'ext.narayam.rules.ta', // make sure ta99 loads after ta
 217+);
 218+
Index: branches/wmf/1.17wmf1/extensions/Collection/Collection.body.php
@@ -948,11 +948,7 @@
949949 }
950950
951951 function renderCollection( $collection, $referrer, $writer ) {
952 - global $wgOut;
953 - global $wgContLang;
954 - global $wgServer;
955 - global $wgScriptPath;
956 - global $wgScriptExtension;
 952+ global $wgOut, $wgContLang, $wgScriptPath, $wgScriptExtension;
957953
958954 if ( !$writer ) {
959955 $writer = 'rl';
@@ -960,7 +956,7 @@
961957
962958 $response = self::mwServeCommand( 'render', array(
963959 'metabook' => $this->buildJSONCollection( $collection ),
964 - 'base_url' => $wgServer . $wgScriptPath,
 960+ 'base_url' => wfExpandUrl( $wgScriptPath ),
965961 'script_extension' => $wgScriptExtension,
966962 'template_blacklist' => wfMsgForContent( 'coll-template_blacklist_title' ),
967963 'template_exclusion_category' => wfMsgForContent( 'coll-exclusion_category_title' ),
@@ -986,19 +982,14 @@
987983 }
988984
989985 function forceRenderCollection() {
990 - global $wgOut;
991 - global $wgContLang;
992 - global $wgRequest;
993 - global $wgServer;
994 - global $wgScriptPath;
995 - global $wgScriptExtension;
 986+ global $wgOut, $wgContLang, $wgRequest, $wgScriptPath, $wgScriptExtension;
996987
997988 $collectionID = $wgRequest->getVal( 'collection_id', '' );
998989 $writer = $wgRequest->getVal( 'writer', 'rl' );
999990
1000991 $response = self::mwServeCommand( 'render', array(
1001992 'collection_id' => $collectionID,
1002 - 'base_url' => $wgServer . $wgScriptPath,
 993+ 'base_url' => wfExpandUrl( $wgScriptPath ),
1003994 'script_extension' => $wgScriptExtension,
1004995 'template_blacklist' => wfMsgForContent( 'coll-template_blacklist_title' ),
1005996 'template_exclusion_category' => wfMsgForContent( 'coll-exclusion_category_title' ),
@@ -1080,7 +1071,7 @@
10811072 $wgOut->setPageTitle( wfMsg( 'coll-rendering_finished_title' ) );
10821073
10831074 $template = new CollectionFinishedTemplate();
1084 - $template->set( 'download_url', $wgServer . SkinTemplate::makeSpecialUrl( 'Book', 'bookcmd=download&' . $query ) );
 1075+ $template->set( 'download_url', wfExpandUrl( SkinTemplate::makeSpecialUrl( 'Book', 'bookcmd=download&' . $query ) ) );
10851076 $template->set( 'is_cached', $wgRequest->getVal( 'is_cached' ) );
10861077 $template->set( 'query', $query );
10871078 $template->set( 'return_to', $return_to );
@@ -1161,10 +1152,7 @@
11621153 }
11631154
11641155 function postZIP( $collection, $partner ) {
1165 - global $wgServer;
1166 - global $wgScriptPath;
1167 - global $wgScriptExtension;
1168 - global $wgOut;
 1156+ global $wgScriptPath, $wgScriptExtension, $wgOut;
11691157
11701158 if ( !isset( $this->mPODPartners[$partner] ) ) {
11711159 $wgOut->showErrorPage( 'coll-invalid_podpartner_title', 'coll-invalid_podpartner_msg' );
@@ -1173,7 +1161,7 @@
11741162
11751163 $response = self::mwServeCommand( 'zip_post', array(
11761164 'metabook' => $this->buildJSONCollection( $collection ),
1177 - 'base_url' => $wgServer . $wgScriptPath,
 1165+ 'base_url' => wfExpandUrl( $wgScriptPath ),
11781166 'script_extension' => $wgScriptExtension,
11791167 'template_blacklist' => wfMsgForContent( 'coll-template_blacklist_title' ),
11801168 'template_exclusion_category' => wfMsgForContent( 'coll-exclusion_category_title' ),
Index: branches/wmf/1.17wmf1/extensions/Collection/Collection.templates.php
@@ -482,11 +482,10 @@
483483
484484 // needed for Ajax functions
485485 function getProposalList () {
486 - global $wgServer;
487 - global $wgScript;
 486+ global $wgScript, $wgScriptPath;
488487
489 - $mediapath = $GLOBALS['wgScriptPath'] . '/extensions/Collection/images/';
490 - $baseUrl = $wgServer . $wgScript . "/";
 488+ $mediapath = $wgScriptPath . '/extensions/Collection/images/';
 489+ $baseUrl = $wgScript . "/";
491490
492491 $prop = $this->data['proposals'];
493492 $out = '';
Index: branches/wmf/1.17wmf1/extensions/ArticleFeedback/populateAFRevisions.php
@@ -40,12 +40,11 @@
4141
4242 $lastRevID = 0;
4343 $i = 0;
44 - $dbr = wfGetDB( DB_SLAVE );
4544 $dbw = wfGetDB( DB_MASTER );
4645 $this->output( "Reading data from article_feedback ...\n" );
4746 while ( true ) {
4847 // Get the next revision ID
49 - $row = $dbr->selectRow( 'article_feedback', array( 'aa_revision', 'aa_page_id' ),
 48+ $row = $dbw->selectRow( 'article_feedback', array( 'aa_revision', 'aa_page_id' ),
5049 "aa_revision > $lastRevID", __METHOD__,
5150 array( 'ORDER BY' => 'aa_revision', 'LIMIT' => 1 )
5251 );
@@ -57,7 +56,7 @@
5857 $pageid = intval( $row->aa_page_id );
5958
6059 // Get all article_feedback rows for this revision
61 - $res = $dbr->select( 'article_feedback',
 60+ $res = $dbw->select( 'article_feedback',
6261 array( 'aa_rating_id', 'aa_rating_value', 'aa_user_id', 'aa_user_anon_token' ),
6362 array( 'aa_revision' => $revid ),
6463 __METHOD__
Index: branches/wmf/1.17wmf1/extensions/ArticleFeedback/api/ApiArticleFeedback.php
@@ -37,11 +37,12 @@
3838 $this->dieUsage( 'ArticleFeedback is not enabled on this page', 'invalidpage' );
3939 }
4040
41 - $dbr = wfGetDB( DB_SLAVE );
 41+ $dbw = wfGetDB( DB_MASTER );
4242
4343 // Query the latest ratings by this user for this page,
4444 // possibly for an older revision
45 - $res = $dbr->select(
 45+ // Select from the master to prevent replag-induced bugs
 46+ $res = $dbw->select(
4647 'article_feedback',
4748 array( 'aa_rating_id', 'aa_rating_value', 'aa_revision' ),
4849 array(
@@ -454,4 +455,4 @@
455456 public function getVersion() {
456457 return __CLASS__ . ': $Id$';
457458 }
458 -}
\ No newline at end of file
 459+}
Property changes on: branches/wmf/1.17wmf1/extensions/ArticleFeedback/api/ApiArticleFeedback.php
___________________________________________________________________
Modified: svn:mergeinfo
459460 Merged /trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php:r93711,94376,94404,94502,94509
460461 Merged /trunk/phase3/extensions/ArticleFeedback/api/ApiArticleFeedback.php:r94346
Index: branches/wmf/1.17wmf1/extensions/SiteMatrix/SiteMatrixApi.php
@@ -46,7 +46,7 @@
4747 if ( $matrix->exist( $lang, $site ) ) {
4848 $url = $matrix->getUrl( $lang, $site );
4949 $site_out = array(
50 - 'url' => $url,
 50+ 'url' => wfExpandUrl( $url ),
5151 'code' => $site,
5252 );
5353 if( $matrix->isClosed( $lang, $site ) ) {
@@ -68,7 +68,7 @@
6969 $url = $matrix->getUrl( $lang, $site );
7070
7171 $wiki = array();
72 - $wiki['url'] = $url;
 72+ $wiki['url'] = wfExpandUrl( $url );
7373 $wiki['code'] = str_replace( '_', '-', $lang ) . ( $site != 'wiki' ? $site : '' );
7474
7575 if( $matrix->isPrivate( $lang . $site ) ) {
Index: branches/wmf/1.17wmf1/extensions/CodeReview/backend/CodeCommentLinker.php
@@ -28,7 +28,7 @@
2929 function link( $text ) {
3030 # Catch links like http://www.mediawiki.org/wiki/Special:Code/MediaWiki/44245#c829
3131 # Ended by space or brackets (like those pesky <br /> tags)
32 - $text = preg_replace_callback( '/(^|[^\w[])(' . wfUrlProtocols() . ')(' . Parser::EXT_LINK_URL_CLASS . '+)/',
 32+ $text = preg_replace_callback( '/(^|[^\w[])(' . wfUrlProtocolsWithoutProtRel() . ')(' . Parser::EXT_LINK_URL_CLASS . '+)/',
3333 array( $this, 'generalLink' ), $text );
3434 $text = preg_replace_callback( '/\br(\d+)\b/',
3535 array( $this, 'messageRevLink' ), $text );
Index: branches/wmf/1.17wmf1/includes/GlobalFunctions.php
@@ -2458,14 +2458,18 @@
24592459 /**
24602460 * Returns a regular expression of url protocols
24612461 *
 2462+ * @param $includeProtocolRelative bool If false, remove '//' from the returned protocol list.
 2463+ * DO NOT USE this directy, use wfUrlProtocolsWithoutProtRel() instead
24622464 * @return String
24632465 */
2464 -function wfUrlProtocols() {
 2466+function wfUrlProtocols( $includeProtocolRelative = true ) {
24652467 global $wgUrlProtocols;
24662468
2467 - static $retval = null;
2468 - if ( !is_null( $retval ) ) {
2469 - return $retval;
 2469+ // Cache return values separately based on $includeProtocolRelative
 2470+ static $withProtRel = null, $withoutProtRel = null;
 2471+ $cachedValue = $includeProtocolRelative ? $withProtRel : $withoutProtRel;
 2472+ if ( !is_null( $cachedValue ) ) {
 2473+ return $cachedValue;
24702474 }
24712475
24722476 // Support old-style $wgUrlProtocols strings, for backwards compatibility
@@ -2473,17 +2477,40 @@
24742478 if ( is_array( $wgUrlProtocols ) ) {
24752479 $protocols = array();
24762480 foreach ( $wgUrlProtocols as $protocol ) {
2477 - $protocols[] = preg_quote( $protocol, '/' );
 2481+ // Filter out '//' if !$includeProtocolRelative
 2482+ if ( $includeProtocolRelative || $protocol !== '//' ) {
 2483+ $protocols[] = preg_quote( $protocol, '/' );
 2484+ }
24782485 }
24792486
24802487 $retval = implode( '|', $protocols );
24812488 } else {
 2489+ // Ignore $includeProtocolRelative in this case
 2490+ // This case exists for pre-1.6 compatibility, and we can safely assume
 2491+ // that '//' won't appear in a pre-1.6 config because protocol-relative
 2492+ // URLs weren't supported until 1.18
24822493 $retval = $wgUrlProtocols;
24832494 }
 2495+
 2496+ // Cache return value
 2497+ if ( $includeProtocolRelative ) {
 2498+ $withProtRel = $retval;
 2499+ } else {
 2500+ $withoutProtRel = $retval;
 2501+ }
24842502 return $retval;
24852503 }
24862504
24872505 /**
 2506+ * Like wfUrlProtocols(), but excludes '//' from the protocol list. Use this if
 2507+ * you need a regex that matches all URL protocols but does not match protocol-
 2508+ * relative URLs
 2509+ */
 2510+function wfUrlProtocolsWithoutProtRel() {
 2511+ return wfUrlProtocols( false );
 2512+}
 2513+
 2514+/**
24882515 * Safety wrapper around ini_get() for boolean settings.
24892516 * The values returned from ini_get() are pre-normalized for settings
24902517 * set via php.ini or php_flag/php_admin_flag... but *not*
Property changes on: branches/wmf/1.17wmf1/includes/GlobalFunctions.php
___________________________________________________________________
Modified: svn:mergeinfo
24912518 Merged /trunk/phase3/includes/GlobalFunctions.php:r94502,94511
Index: branches/wmf/1.17wmf1/includes/parser/Parser.php
@@ -1045,7 +1045,7 @@
10461046 */
10471047 function doMagicLinks( $text ) {
10481048 wfProfileIn( __METHOD__ );
1049 - $prots = $this->mUrlProtocols;
 1049+ $prots = wfUrlProtocolsWithoutProtRel();
10501050 $urlChar = self::EXT_LINK_URL_CLASS;
10511051 $text = preg_replace_callback(
10521052 '!(?: # Start cases
@@ -1701,7 +1701,7 @@
17021702 # Don't allow internal links to pages containing
17031703 # PROTO: where PROTO is a valid URL protocol; these
17041704 # should be external links.
1705 - if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
 1705+ if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
17061706 $s .= $prefix . '[[' . $line ;
17071707 wfProfileOut( __METHOD__."-misc" );
17081708 continue;
Property changes on: branches/wmf/1.17wmf1/includes/parser/Parser.php
___________________________________________________________________
Modified: svn:mergeinfo
17091709 Merged /trunk/phase3/includes/parser/Parser.php:r94346,94502
Index: branches/wmf/1.17wmf1/includes/api/ApiFormatBase.php
@@ -265,7 +265,7 @@
266266 // encode all comments or tags as safe blue strings
267267 $text = preg_replace( '/\&lt;(!--.*?--|.*?)\&gt;/', '<span style="color:blue;">&lt;\1&gt;</span>', $text );
268268 // identify URLs
269 - $protos = wfUrlProtocols();
 269+ $protos = wfUrlProtocolsWithoutProtRel();
270270 // This regex hacks around bug 13218 (&quot; included in the URL)
271271 $text = preg_replace( "#(($protos).*?)(&quot;)?([ \\'\"<>\n]|&lt;|&gt;|&quot;)#", '<a href="\\1">\\1</a>\\3\\4', $text );
272272 // identify requests to api.php
Property changes on: branches/wmf/1.17wmf1/includes/api/ApiFormatBase.php
___________________________________________________________________
Added: svn:mergeinfo
273273 Merged /branches/REL1_15/phase3/includes/api/ApiFormatBase.php:r51646
274274 Merged /branches/REL1_16/phase3/includes/api/ApiFormatBase.php:r63621-63636,69357
275275 Merged /branches/wmf/1.16wmf4/includes/api/ApiFormatBase.php:r67177,69199,69521,76243,77266
276276 Merged /branches/sqlite/includes/api/ApiFormatBase.php:r58211-58321
277277 Merged /trunk/phase3/includes/api/ApiFormatBase.php:r89512-89513,89549,89574,94502
278278 Merged /branches/wmf-deployment/includes/api/ApiFormatBase.php:r53381,59952,60970

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93711* (bug 30178) Narayam input manager: switch 'ta' as default before 'ta99' for...brion08:35, 2 August 2011
r94346(bug 30236) Links like [[//example.com Link text]] were parsed as an internal...catrope13:32, 12 August 2011
r94369Expand URLs in the SiteMatrix API. This should fix bug 30171catrope19:09, 12 August 2011
r94376Collection: Use wfExpandUrl() instead of prepending $wgServer everywhere. In ...catrope20:00, 12 August 2011
r94404Hopefully prevent race conditions in ArticleFeedback by reading from the mast...catrope10:46, 13 August 2011
r94502(bug 30269) Strings like foobar//barfoo are linked to become foobar[//barfoo]...catrope12:20, 15 August 2011
r94509Followup r94404: remove LOCK IN SHARE MODE because locking reads are evil, pe...catrope13:06, 15 August 2011
r94511Followup r94502: per CR, use two caching variables instead of an array indexe...catrope13:16, 15 August 2011

Status & tagging log