r96470 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96469‎ | r96470 | r96471 >
Date:19:07, 7 September 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Modified paths:
  • /branches/REL1_18/phase3/includes/Block.php (modified) (history)
  • /branches/REL1_18/phase3/includes/GlobalFunctions.php (modified) (history)
  • /branches/REL1_18/phase3/includes/SpecialPage.php (modified) (history)
  • /branches/REL1_18/phase3/includes/Title.php (modified) (history)
  • /branches/REL1_18/phase3/includes/WikiPage.php (modified) (history)
  • /branches/REL1_18/phase3/includes/api/ApiFormatBase.php (modified) (history)
  • /branches/REL1_18/phase3/includes/api/ApiParamInfo.php (modified) (history)
  • /branches/REL1_18/phase3/includes/parser/Parser.php (modified) (history)
  • /branches/REL1_18/phase3/includes/specials/SpecialEditWatchlist.php (modified) (history)
  • /branches/REL1_18/phase3/skins/common/shared.css (modified) (history)
  • /branches/REL1_18/phase3/tests/parser/parserTests.txt (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/includes/ArticleTest.php (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/skins/common/shared.css
@@ -181,12 +181,13 @@
182182 /**
183183 * Categories
184184 */
185 -#catlinks ul, #catlinks li {
 185+#catlinks ul {
186186 display:inline;
187187 margin: 0px;
188188 list-style:none;
189189 list-style-type:none;
190190 list-style-image:none;
 191+ vertical-align: middle !ie;
191192 }
192193
193194 #catlinks li {
@@ -195,13 +196,14 @@
196197 padding: 0 .7em;
197198 border-left: 1px solid #AAA;
198199 margin: 0.3em 0;
 200+ zoom: 1;
 201+ display:inline !ie;
199202 }
200203
201204 #catlinks li:first-child {
202205 padding-left: .4em;
203206 border-left: none;
204207 }
205 -
206208 /**
207209 * Hidden categories
208210 */
Index: branches/REL1_18/phase3/tests/phpunit/includes/ArticleTest.php
@@ -50,14 +50,17 @@
5151 "Article get/set magic on update to new field" );
5252 }
5353
 54+ /**
 55+ * Checks for the existence of the backwards compatibility static functions (forwarders to WikiPage class)
 56+ */
5457 function testStaticFunctions() {
5558 $this->assertEquals( WikiPage::selectFields(), Article::selectFields(),
5659 "Article static functions" );
57 - $this->assertEquals( null, Article::onArticleCreate( $this->title ),
 60+ $this->assertEquals( true, is_callable( "Article::onArticleCreate" ),
5861 "Article static functions" );
59 - $this->assertEquals( null, Article::onArticleDelete( $this->title ),
 62+ $this->assertEquals( true, is_callable( "Article::onArticleDelete" ),
6063 "Article static functions" );
61 - $this->assertEquals( null, ImagePage::onArticleEdit( $this->title ),
 64+ $this->assertEquals( true, is_callable( "ImagePage::onArticleEdit" ),
6265 "Article static functions" );
6366 $this->assertTrue( is_string( CategoryPage::getAutosummary( '', '', 0 ) ),
6467 "Article static functions" );
Index: branches/REL1_18/phase3/tests/parser/parserTests.txt
@@ -742,6 +742,15 @@
743743 !!end
744744
745745 !! test
 746+External links: protocol-relative URL in the middle of a word is left alone (bug 30269)
 747+!! input
 748+foo//example.com/Foo
 749+!! result
 750+<p>foo//example.com/Foo
 751+</p>
 752+!! end
 753+
 754+!! test
746755 External image
747756 !! input
748757 External image: http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png
Index: branches/REL1_18/phase3/includes/GlobalFunctions.php
@@ -464,14 +464,18 @@
465465 /**
466466 * Returns a regular expression of url protocols
467467 *
 468+ * @param $includeProtocolRelative bool If false, remove '//' from the returned protocol list.
 469+ * DO NOT USE this directy, use wfUrlProtocolsWithoutProtRel() instead
468470 * @return String
469471 */
470 -function wfUrlProtocols() {
 472+function wfUrlProtocols( $includeProtocolRelative = true ) {
471473 global $wgUrlProtocols;
472474
473 - static $retval = null;
474 - if ( !is_null( $retval ) ) {
475 - return $retval;
 475+ // Cache return values separately based on $includeProtocolRelative
 476+ static $withProtRel = null, $withoutProtRel = null;
 477+ $cachedValue = $includeProtocolRelative ? $withProtRel : $withoutProtRel;
 478+ if ( !is_null( $cachedValue ) ) {
 479+ return $cachedValue;
476480 }
477481
478482 // Support old-style $wgUrlProtocols strings, for backwards compatibility
@@ -479,17 +483,40 @@
480484 if ( is_array( $wgUrlProtocols ) ) {
481485 $protocols = array();
482486 foreach ( $wgUrlProtocols as $protocol ) {
483 - $protocols[] = preg_quote( $protocol, '/' );
 487+ // Filter out '//' if !$includeProtocolRelative
 488+ if ( $includeProtocolRelative || $protocol !== '//' ) {
 489+ $protocols[] = preg_quote( $protocol, '/' );
 490+ }
484491 }
485492
486493 $retval = implode( '|', $protocols );
487494 } else {
 495+ // Ignore $includeProtocolRelative in this case
 496+ // This case exists for pre-1.6 compatibility, and we can safely assume
 497+ // that '//' won't appear in a pre-1.6 config because protocol-relative
 498+ // URLs weren't supported until 1.18
488499 $retval = $wgUrlProtocols;
489500 }
 501+
 502+ // Cache return value
 503+ if ( $includeProtocolRelative ) {
 504+ $withProtRel = $retval;
 505+ } else {
 506+ $withoutProtRel = $retval;
 507+ }
490508 return $retval;
491509 }
492510
493511 /**
 512+ * Like wfUrlProtocols(), but excludes '//' from the protocol list. Use this if
 513+ * you need a regex that matches all URL protocols but does not match protocol-
 514+ * relative URLs
 515+ */
 516+function wfUrlProtocolsWithoutProtRel() {
 517+ return wfUrlProtocols( false );
 518+}
 519+
 520+/**
494521 * parse_url() work-alike, but non-broken. Differences:
495522 *
496523 * 1) Does not raise warnings on bad URLs (just returns false)
Property changes on: branches/REL1_18/phase3/includes/GlobalFunctions.php
___________________________________________________________________
Modified: svn:mergeinfo
497524 Merged /trunk/phase3/includes/GlobalFunctions.php:r92962,93062,93093,93385,93468,93473,94350,94502,94504,94511,94548
Index: branches/REL1_18/phase3/includes/parser/Parser.php
@@ -1184,7 +1184,7 @@
11851185 */
11861186 function doMagicLinks( $text ) {
11871187 wfProfileIn( __METHOD__ );
1188 - $prots = $this->mUrlProtocols;
 1188+ $prots = wfUrlProtocolsWithoutProtRel();
11891189 $urlChar = self::EXT_LINK_URL_CLASS;
11901190 $text = preg_replace_callback(
11911191 '!(?: # Start cases
Index: branches/REL1_18/phase3/includes/api/ApiFormatBase.php
@@ -263,7 +263,7 @@
264264 // encode all comments or tags as safe blue strings
265265 $text = preg_replace( '/\&lt;(!--.*?--|.*?)\&gt;/', '<span style="color:blue;">&lt;\1&gt;</span>', $text );
266266 // identify URLs
267 - $protos = wfUrlProtocols();
 267+ $protos = wfUrlProtocolsWithoutProtRel();
268268 // This regex hacks around bug 13218 (&quot; included in the URL)
269269 $text = preg_replace( "#(($protos).*?)(&quot;)?([ \\'\"<>\n]|&lt;|&gt;|&quot;)#", '<a href="\\1">\\1</a>\\3\\4', $text );
270270 // identify requests to api.php
Index: branches/REL1_18/phase3/includes/api/ApiParamInfo.php
@@ -123,6 +123,9 @@
124124 $result->setIndexedTagName( $retval['helpurls'], 'helpurl' );
125125
126126 $retval['allexamples'] = $examples;
 127+ if ( isset( $retval['allexamples'][0] ) && $retval['allexamples'][0] === false ) {
 128+ $retval['allexamples'] = array();
 129+ }
127130 $result->setIndexedTagName( $retval['allexamples'], 'example' );
128131
129132 $retval['parameters'] = array();
Index: branches/REL1_18/phase3/includes/Title.php
@@ -3259,6 +3259,7 @@
32603260 if ( $u ) {
32613261 $u->doUpdate();
32623262 }
 3263+
32633264 # Update message cache for interface messages
32643265 if ( $this->getNamespace() == NS_MEDIAWIKI ) {
32653266 # @bug 17860: old article can be deleted, if this the case,
@@ -3348,10 +3349,11 @@
33493350 }
33503351 $nullRevId = $nullRevision->insertOn( $dbw );
33513352
 3353+ $now = wfTimestampNow();
33523354 # Change the name of the target page:
33533355 $dbw->update( 'page',
33543356 /* SET */ array(
3355 - 'page_touched' => $dbw->timestamp(),
 3357+ 'page_touched' => $dbw->timestamp( $now ),
33563358 'page_namespace' => $nt->getNamespace(),
33573359 'page_title' => $nt->getDBkey(),
33583360 'page_latest' => $nullRevId,
@@ -3363,6 +3365,7 @@
33643366
33653367 $article = new Article( $nt );
33663368 wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
 3369+ $article->setCachedLastEditTime( $now );
33673370
33683371 # Recreate the redirect, this time in the other direction.
33693372 if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {
Property changes on: branches/REL1_18/phase3/includes/Title.php
___________________________________________________________________
Modified: svn:mergeinfo
33703373 Merged /trunk/phase3/includes/Title.php:r92962,93062,93093,93385,93468,93473,94350,94502,94504,94511,94548
Index: branches/REL1_18/phase3/includes/WikiPage.php
@@ -350,19 +350,28 @@
351351 * A DB query result object or...
352352 * "fromdb" to get from a slave DB or...
353353 * "fromdbmaster" to get from the master DB
 354+ * @return void
354355 */
355356 public function loadPageData( $data = 'fromdb' ) {
356 - if ( $data === 'fromdb' || $data === 'fromdbmaster' ) {
357 - $db = ( $data == 'fromdbmaster' )
358 - ? wfGetDB( DB_MASTER )
359 - : wfGetDB( DB_SLAVE );
360 - $data = $this->pageDataFromTitle( $db, $this->mTitle );
 357+ if ( $data === 'fromdbmaster' ) {
 358+ $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
 359+ } elseif ( $data === 'fromdb' ) { // slave
 360+ $data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle );
 361+ # Use a "last rev inserted" timestamp key to dimish the issue of slave lag.
 362+ # Note that DB also stores the master position in the session and checks it.
 363+ $touched = $this->getCachedLastEditTime();
 364+ if ( $touched ) { // key set
 365+ if ( !$data || $touched > wfTimestamp( TS_MW, $data->page_touched ) ) {
 366+ $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
 367+ }
 368+ }
361369 }
362370
363371 $lc = LinkCache::singleton();
364372
365373 if ( $data ) {
366 - $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect, $data->page_latest );
 374+ $lc->addGoodLinkObj( $data->page_id, $this->mTitle,
 375+ $data->page_len, $data->page_is_redirect, $data->page_latest );
367376
368377 $this->mTitle->loadFromRow( $data );
369378
@@ -814,10 +823,11 @@
815824 $conditions['page_latest'] = $lastRevision;
816825 }
817826
 827+ $now = wfTimestampNow();
818828 $dbw->update( 'page',
819829 array( /* SET */
820830 'page_latest' => $revision->getId(),
821 - 'page_touched' => $dbw->timestamp(),
 831+ 'page_touched' => $dbw->timestamp( $now ),
822832 'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
823833 'page_is_redirect' => $rt !== null ? 1 : 0,
824834 'page_len' => strlen( $text ),
@@ -828,6 +838,7 @@
829839 $result = $dbw->affectedRows() != 0;
830840 if ( $result ) {
831841 $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
 842+ $this->setCachedLastEditTime( $now );
832843 }
833844
834845 wfProfileOut( __METHOD__ );
@@ -835,6 +846,29 @@
836847 }
837848
838849 /**
 850+ * Get the cached timestamp for the last time the page changed.
 851+ * This is only used to help handle slave lag by comparing to page_touched.
 852+ * @return string MW timestamp
 853+ */
 854+ protected function getCachedLastEditTime() {
 855+ global $wgMemc;
 856+ $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
 857+ return $wgMemc->get( $key );
 858+ }
 859+
 860+ /**
 861+ * Set the cached timestamp for the last time the page changed.
 862+ * This is only used to help handle slave lag by comparing to page_touched.
 863+ * @param $timestamp string
 864+ * @return void
 865+ */
 866+ public function setCachedLastEditTime( $timestamp ) {
 867+ global $wgMemc;
 868+ $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
 869+ $wgMemc->set( $key, wfTimestamp( TS_MW, $timestamp ), 60*15 );
 870+ }
 871+
 872+ /**
839873 * Add row to the redirect table if this is a redirect, remove otherwise.
840874 *
841875 * @param $dbw DatabaseBase
Index: branches/REL1_18/phase3/includes/specials/SpecialEditWatchlist.php
@@ -43,7 +43,7 @@
4444 array(),
4545 array( 'returnto' => $this->getTitle()->getPrefixedText() )
4646 );
47 - $out->addHTML( wfMessage( 'watchlistanontext' )->rawParam( $llink )->parse() );
 47+ $out->addHTML( wfMessage( 'watchlistanontext' )->rawParams( $llink )->parse() );
4848 return;
4949 }
5050
Index: branches/REL1_18/phase3/includes/Block.php
@@ -1057,6 +1057,19 @@
10581058 return array( null, null );
10591059 }
10601060
 1061+ if ( IP::isValid( $target ) ) {
 1062+ # We can still create a User if it's an IP address, but we need to turn
 1063+ # off validation checking (which would exclude IP addresses)
 1064+ return array(
 1065+ User::newFromName( IP::sanitizeIP( $target ), false ),
 1066+ Block::TYPE_IP
 1067+ );
 1068+
 1069+ } elseif ( IP::isValidBlock( $target ) ) {
 1070+ # Can't create a User from an IP range
 1071+ return array( IP::sanitizeRange( $target ), Block::TYPE_RANGE );
 1072+ }
 1073+
10611074 # Consider the possibility that this is not a username at all
10621075 # but actually an old subpage (bug #29797)
10631076 if( strpos( $target, '/' ) !== false ){
@@ -1072,18 +1085,6 @@
10731086 # since hash characters are not valid in usernames or titles generally.
10741087 return array( $userObj, Block::TYPE_USER );
10751088
1076 - } elseif ( IP::isValid( $target ) ) {
1077 - # We can still create a User if it's an IP address, but we need to turn
1078 - # off validation checking (which would exclude IP addresses)
1079 - return array(
1080 - User::newFromName( IP::sanitizeIP( $target ), false ),
1081 - Block::TYPE_IP
1082 - );
1083 -
1084 - } elseif ( IP::isValidBlock( $target ) ) {
1085 - # Can't create a User from an IP range
1086 - return array( IP::sanitizeRange( $target ), Block::TYPE_RANGE );
1087 -
10881089 } elseif ( preg_match( '/^#\d+$/', $target ) ) {
10891090 # Autoblock reference in the form "#12345"
10901091 return array( substr( $target, 1 ), Block::TYPE_AUTO );
Index: branches/REL1_18/phase3/includes/SpecialPage.php
@@ -545,7 +545,7 @@
546546 if ( $this->userCanExecute( $this->getUser() ) ) {
547547 $func = $this->mFunction;
548548 // only load file if the function does not exist
549 - if(!is_callable($func) and $this->mFile) {
 549+ if( !is_callable($func) && $this->mFile ) {
550550 require_once( $this->mFile );
551551 }
552552 $this->outputHeader();
Property changes on: branches/REL1_18/phase3/includes/SpecialPage.php
___________________________________________________________________
Modified: svn:mergeinfo
553553 Merged /trunk/phase3/includes/SpecialPage.php:r92962,93062,93093,93385,93468,93473,94350,94502,94504,94511,94548

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92962It is stupid to test that a void method returns null. Add a comment explainin...platonides20:23, 23 July 2011
r93062r92054: Some IE fixesdiebuche16:51, 25 July 2011
r93093Follow-up r79518: added getCachedLastEditTime/getCachedLastEditTime methods t...aaron19:24, 25 July 2011
r93385Fu r92231: PHP Fatal error: Call to a member function parse() on a non-objec...nikerabbit12:13, 28 July 2011
r93468* Follow-up r93093: set the touch key for page moves too...aaron16:44, 29 July 2011
r93473Fixed r93468, made setCachedLastEditTime() publicaaron17:56, 29 July 2011
r94350Fix r91886 thanks to johnduhart: check if it is an IP *before* stripping subp...robin14:32, 12 August 2011
r94502(bug 30269) Strings like foobar//barfoo are linked to become foobar[//barfoo]...catrope12:20, 15 August 2011
r94504Add parser test for r94502catrope12:25, 15 August 2011
r94511Followup r94502: per CR, use two caching variables instead of an array indexe...catrope13:16, 15 August 2011
r94548Followup r92430 per CR, like r94448reedy18:56, 15 August 2011

Comments

#Comment by Catrope (talk | contribs)   19:09, 7 September 2011

I meant 1.18 instead of 1.17wmf1 of course.

Status & tagging log