r34542 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34541‎ | r34542 | r34543 >
Date:23:52, 9 May 2008
Author:brion
Status:old
Tags:
Comment:
Revert r34541 for the moment pending further review & discussion...
There's some kind of crazy magic_quotes stuff in here which screams RED ALERT, something's weird going on! :)
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -461,53 +461,6 @@
462462 }
463463 }
464464
465 -function setupRightClickEdit() {
466 - if (document.getElementsByTagName) {
467 - var spans = document.getElementsByTagName('span');
468 - for (var i = 0; i < spans.length; i++) {
469 - var el = spans[i];
470 - if(el.className == 'editsection') {
471 - addRightClickEditHandler(el);
472 - }
473 - }
474 - }
475 -}
476 -
477 -function addRightClickEditHandler(el) {
478 - for (var i = 0; i < el.childNodes.length; i++) {
479 - var link = el.childNodes[i];
480 - if (link.nodeType == 1 && link.nodeName.toLowerCase() == 'a') {
481 - var editHref = link.getAttribute('href');
482 - // find the enclosing (parent) header
483 - var prev = el.parentNode;
484 - if (prev && prev.nodeType == 1 &&
485 - prev.nodeName.match(/^[Hh][1-6]$/)) {
486 - prev.oncontextmenu = function(e) {
487 - if (!e) { e = window.event; }
488 - // e is now the event in all browsers
489 - var targ;
490 - if (e.target) { targ = e.target; }
491 - else if (e.srcElement) { targ = e.srcElement; }
492 - if (targ.nodeType == 3) { // defeat Safari bug
493 - targ = targ.parentNode;
494 - }
495 - // targ is now the target element
496 -
497 - // We don't want to deprive the noble reader of a context menu
498 - // for the section edit link, do we? (Might want to extend this
499 - // to all <a>'s?)
500 - if (targ.nodeName.toLowerCase() != 'a'
501 - || targ.parentNode.className != 'editsection') {
502 - document.location = editHref;
503 - return false;
504 - }
505 - return true;
506 - };
507 - }
508 - }
509 - }
510 -}
511 -
512465 var checkboxes;
513466 var lastCheckbox;
514467
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -983,40 +983,25 @@
984984 }
985985
986986 /**
987 - * This function takes one or two arrays, objects, or strings as input, and returns a CGI-style string, e.g.
 987+ * This function takes two arrays as input, and returns a CGI-style string, e.g.
988988 * "days=7&limit=100". Options in the first array override options in the second.
989989 * Options set to "" will not be output.
990 - * @depreciated
991990 */
992 -function wfArrayToCGI( $query1, $query2 = null ) {
993 - if( is_null($query2) ) wfBuildQuery( $query1 );
994 - else wfBuildQuery( $query2, $query1 );
995 -}
996 -/**
997 - * wfBuildQuery is a improved wrapper for http_build_query.
998 - * We support a defaults array which the query may be merged with. As well we also support
999 - * arrays, objects, and strings as input.
1000 - */
1001 -function wfBuildQuery( $query, $defaults = null ) {
1002 - if( !is_null($defaults) ) {
1003 - ## If either array is a string, then parse it and make sure to fix magic quotes.
1004 - foreach( array( 'query', 'defaults' ) as $var ) {
1005 - if( is_string($$var) ) {
1006 - $arr = array();
1007 - parse_str($$var, &$arr);
1008 - if( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
1009 - global $wgRequest;
1010 - $wgRequest->fix_magic_quotes( $arr );
1011 - }
1012 - $$var = $arr;
 991+function wfArrayToCGI( $array1, $array2 = NULL )
 992+{
 993+ if ( !is_null( $array2 ) ) {
 994+ $array1 = $array1 + $array2;
 995+ }
 996+
 997+ $cgi = '';
 998+ foreach ( $array1 as $key => $value ) {
 999+ if ( '' !== $value ) {
 1000+ if ( '' != $cgi ) {
 1001+ $cgi .= '&';
10131002 }
 1003+ $cgi .= urlencode( $key ) . '=' . urlencode( $value );
10141004 }
1015 - # Merge, make sure they are arrays, not objects.
1016 - $query = ((array)$defaults) + ((array)$query);
10171005 }
1018 -
1019 - # Note that we must specify & because the default is sometimes &amp;
1020 - $cgi = is_string($query) ? $query : http_build_query( $query, null, '&' );
10211006 return $cgi;
10221007 }
10231008
@@ -2352,8 +2337,13 @@
23532338 * Get a cache key
23542339 */
23552340 function wfMemcKey( /*... */ ) {
 2341+ global $wgDBprefix, $wgDBname;
23562342 $args = func_get_args();
2357 - $key = wfWikiID() . ':' . implode( ':', $args );
 2343+ if ( $wgDBprefix ) {
 2344+ $key = "$wgDBname-$wgDBprefix:" . implode( ':', $args );
 2345+ } else {
 2346+ $key = $wgDBname . ':' . implode( ':', $args );
 2347+ }
23582348 return $key;
23592349 }
23602350
@@ -2362,7 +2352,11 @@
23632353 */
23642354 function wfForeignMemcKey( $db, $prefix /*, ... */ ) {
23652355 $args = array_slice( func_get_args(), 2 );
2366 - wfForeignWikiID($db,$prefix) . ':' . implode( ':', $args );
 2356+ if ( $prefix ) {
 2357+ $key = "$db-$prefix:" . implode( ':', $args );
 2358+ } else {
 2359+ $key = $db . ':' . implode( ':', $args );
 2360+ }
23672361 return $key;
23682362 }
23692363
@@ -2371,7 +2365,7 @@
23722366 * This is used as a prefix in memcached keys
23732367 */
23742368 function wfWikiID() {
2375 - global $wgDBname, wgDBprefix;
 2369+ global $wgDBprefix, $wgDBname;
23762370 if ( $wgDBprefix ) {
23772371 return "$wgDBname-$wgDBprefix";
23782372 } else {
@@ -2380,22 +2374,6 @@
23812375 }
23822376
23832377 /**
2384 - * Get an ASCII string identifying a foreign wiki or shared db
2385 - * This is used as a prefix in foreign memcached keys
2386 - */
2387 -function wfForeignWikiID( $db = null, $prefix = null ) {
2388 - global $wgSharedDB, $wgSharedPrefix, $wgDBname, $wgDBprefix;
2389 - if( !isset($db) ) $db = (isset($wgSharedDB) ? $wgSharedDB, $wgDBname);
2390 - if( !isset($prefix) ) $prefix = ($wgSharedPrefix ? $wgSharedPrefix, $wgDBprefix);
2391 -
2392 - if ( $prefix ) {
2393 - return "$db-$prefix";
2394 - } else {
2395 - return $db;
2396 - }
2397 -}
2398 -
2399 -/**
24002378 * Split a wiki ID into DB name and table prefix
24012379 */
24022380 function wfSplitWikiID( $wiki ) {
Index: trunk/phase3/includes/Title.php
@@ -761,12 +761,10 @@
762762 */
763763 public function getFullURL( $query = '', $variant = false ) {
764764 global $wgContLang, $wgServer, $wgRequest;
765 -
766 - $query = wfBuildQuery( $query ); # Support query input other than strings.
767 -
 765+
768766 if ( '' == $this->mInterwiki ) {
769767 $url = $this->getLocalUrl( $query, $variant );
770 -
 768+
771769 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
772770 // Correct fix would be to move the prepending elsewhere.
773771 if ($wgRequest->getVal('action') != 'render') {
@@ -774,7 +772,7 @@
775773 }
776774 } else {
777775 $baseUrl = $this->getInterwikiLink( $this->mInterwiki );
778 -
 776+
779777 $namespace = wfUrlencode( $this->getNsText() );
780778 if ( '' != $namespace ) {
781779 # Can this actually happen? Interwikis shouldn't be parsed.
@@ -803,16 +801,14 @@
804802 public function getLocalURL( $query = '', $variant = false ) {
805803 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
806804 global $wgVariantArticlePath, $wgContLang, $wgUser;
807 -
808 - $query = wfBuildQuery( $query ); # Support query input other than strings.
809 -
 805+
810806 // internal links should point to same variant as current page (only anonymous users)
811807 if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
812808 $pref = $wgContLang->getPreferredVariant(false);
813809 if($pref != $wgContLang->getCode())
814810 $variant = $pref;
815811 }
816 -
 812+
817813 if ( $this->isExternal() ) {
818814 $url = $this->getFullURL();
819815 if ( $query ) {
@@ -848,7 +844,7 @@
849845 $query = $matches[1];
850846 if( isset( $matches[4] ) ) $query .= $matches[4];
851847 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
852 - $url = wfAppendQuery( $url, $query );
 848+ if( $query != '' ) $url .= '?' . $query;
853849 }
854850 }
855851 if ( $url === false ) {
@@ -858,7 +854,7 @@
859855 $url = "{$wgScript}?title={$dbkey}&{$query}";
860856 }
861857 }
862 -
 858+
863859 // FIXME: this causes breakage in various places when we
864860 // actually expected a local URL and end up with dupe prefixes.
865861 if ($wgRequest->getVal('action') == 'render') {

Follow-up revisions

RevisionCommit summaryAuthorDate
r34697Revert r34559 and fix r34542 -- include rightclickedit.js for 'edit on right ...brion23:37, 12 May 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r34541Fixing up a variety of GlobalFunctions and also improving queries in Titke.php....dantman23:36, 9 May 2008

Status & tagging log