Index: trunk/extensions/DidYouMean/didyoumean.pg.sql |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +CREATE TABLE dympage ( |
| 3 | + dp_pageid INTEGER NOT NULL, |
| 4 | + dp_normid INTEGER NOT NULL, |
| 5 | + PRIMARY KEY (dp_pageid) |
| 6 | +); |
| 7 | + |
| 8 | +CREATE SEQUENCE dymnorm_dn_normid_seq; |
| 9 | +CREATE TABLE dymnorm ( |
| 10 | + dn_normid INTEGER NOT NULL DEFAULT nextval('dymnorm_dn_normid_seq'), |
| 11 | + dn_normtitle TEXT NOT NULL, |
| 12 | + PRIMARY KEY (dn_normid) |
| 13 | +); |
| 14 | +CREATE INDEX dymnorm_title ON dymnorm(dn_normtitle); |
Property changes on: trunk/extensions/DidYouMean/didyoumean.pg.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 15 | + native |
Index: trunk/extensions/DidYouMean/DidYouMean.php |
— | — | @@ -70,10 +70,10 @@ |
71 | 71 | #wfDebug( 'HIPP: ' . __METHOD__ . "\n" ); |
72 | 72 | |
73 | 73 | # if revisionid is 0 this is not an article chunk |
74 | | - if ($parser->mDymFirstChunk == 'no' || !$parser->getVariableValue('revisionid') || $parser->getVariableValue('namespace')) |
| 74 | + if( isset( $parser->mDymFirstChunk ) || !$parser->getVariableValue('revisionid') || $parser->getVariableValue('namespace')) |
75 | 75 | return true; |
76 | 76 | |
77 | | - $parser->mDymFirstChunk = 'no'; |
| 77 | + $parser->mDymFirstChunk = 'done'; |
78 | 78 | |
79 | 79 | $title = $parser->getTitle(); |
80 | 80 | $parser->mDymSees = wfDymLookup( $title->getArticleID(), $title->getText() ); |
— | — | @@ -318,16 +318,29 @@ |
319 | 319 | $dbw->insert( 'dympage', array( 'dp_pageid' => $pageid, 'dp_normid' => $normid ) ); |
320 | 320 | |
321 | 321 | # touch all pages which will now link here |
322 | | - $dbw->query( 'UPDATE ' . $dbw->tableName('page') . ',' . $dbw->tableName('dympage') . ' SET page_touched=' . $dbw->addQuotes($dbw->timestamp()) . |
323 | | - " WHERE page_id=dp_pageid AND dp_normid=$normid" ); |
324 | | - #$dbw->update( |
325 | | - # array('page', 'dympage'), |
326 | | - # array('page_touched' => $dbw->timestamp()), |
327 | | - # array('page_id=dp_pageid', 'dp_normid' => $normid), |
328 | | - # __METHOD__ |
329 | | - #); |
| 322 | + wfTouchPages( "dp_normid=$normid" ); |
| 323 | + |
330 | 324 | } |
331 | 325 | |
| 326 | + |
| 327 | +function wfTouchPages( $condition ) { |
| 328 | + global $wgDBtype; |
| 329 | + |
| 330 | + $dbw = wfGetDB( DB_MASTER ); |
| 331 | + $page = $dbw->tableName('page'); |
| 332 | + $dpage = $dbw->tableName('dympage'); |
| 333 | + |
| 334 | + $whereclause = "WHERE page_id = dp_pageid AND $condition"; |
| 335 | + if ($wgDBtype == 'postgres') { |
| 336 | + $sql = "UPDATE $page SET page_touched=now() FROM $dpage $whereclause"; |
| 337 | + } else { |
| 338 | + $sql = "UPDATE $page, $dpage SET page_touched = " . $dbw->addQuotes( $dbw->timestamp() ) . $whereclause; |
| 339 | + } |
| 340 | + |
| 341 | + $dbw->query( $sql, __METHOD__ ); |
| 342 | + |
| 343 | +} |
| 344 | + |
332 | 345 | function wfDoDelete( $pageid ) { |
333 | 346 | wfDebug( 'HIPP: ' . __METHOD__ . " DELETE\n" ); |
334 | 347 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -341,15 +354,8 @@ |
342 | 355 | if ($count == 0) |
343 | 356 | $dbw->delete( 'dymnorm', array('dn_normid' => $normid) ); |
344 | 357 | |
345 | | - # touch all pages which used to link here |
346 | | - $dbw->query( 'UPDATE ' . $dbw->tableName('page') . ',' . $dbw->tableName('dympage') . ' SET page_touched=' . $dbw->addQuotes($dbw->timestamp()) . |
347 | | - " WHERE page_id=dp_pageid AND dp_normid=$normid" ); |
348 | | - #$dbw->update( |
349 | | - # array('page', 'dympage'), |
350 | | - # array('page_touched' => $dbw->timestamp()), |
351 | | - # array('page_id=dp_pageid', 'dp_normid' => $normid), |
352 | | - # __METHOD__ |
353 | | - #); |
| 358 | + # touch all pages which will now link here |
| 359 | + wfTouchPages( "dp_normid=$normid" ); |
354 | 360 | } |
355 | 361 | |
356 | 362 | function wfDoUpdate( $pageid, $title ) { |
— | — | @@ -379,20 +385,8 @@ |
380 | 386 | $dbw->delete( 'dymnorm', array('dn_normid' => $oldnormid) ); |
381 | 387 | |
382 | 388 | # touch all pages which linked to the old name or will link to the new one |
383 | | - $dbw->query( 'UPDATE ' . $dbw->tableName('page') . ',' . $dbw->tableName('dympage') . ' SET page_touched=' . $dbw->addQuotes($dbw->timestamp()) . |
384 | | - " WHERE page_id=dp_pageid AND (dp_normid=$normid OR dp_normid=$oldnormid)" ); |
385 | | - #$dbw->update( |
386 | | - # array('page', 'dympage'), |
387 | | - # array('page_touched' => $dbw->timestamp()), |
388 | | - # array('page_id=dp_pageid', 'dp_normid' => $normid), |
389 | | - # __METHOD__ |
390 | | - #); |
391 | | - #$dbw->update( |
392 | | - # array('page', 'dympage'), |
393 | | - # array('page_touched' => $dbw->timestamp()), |
394 | | - # array('page_id=dp_pageid', 'dp_normid' => $oldnormid), |
395 | | - # __METHOD__ |
396 | | - #); |
| 389 | + wfTouchPages( "(dp_normid=$normid OR dp_normid=$oldnormid)" ); |
| 390 | + |
397 | 391 | } |
398 | 392 | } |
399 | 393 | |
Index: trunk/extensions/DidYouMean/install.php |
— | — | @@ -51,7 +51,11 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | # Do nothing if the tables exist |
55 | | -if( !$dba->tableExists( 'dympage' ) || !$dba->tableExists( 'dymnorm' ) ) { |
| 55 | +if( $dba->tableExists( 'dympage' ) || $dba->tableExists( 'dymnorm' ) ) { |
| 56 | + echo( "The tables already exist. No action was taken.\n" ); |
| 57 | +} else { |
| 58 | + if( $wgDBtype == 'postgres' ) |
| 59 | + $sql = dirname( __FILE__ ) . '/didyoumean.pg.sql'; |
56 | 60 | echo( "Sourcing: $sql\n" ); |
57 | 61 | $res = $dba->sourceFile( $sql ); |
58 | 62 | echo( "Result: $res\n" ); |
— | — | @@ -88,10 +92,7 @@ |
89 | 93 | } |
90 | 94 | $dba->freeResult( $result ); |
91 | 95 | } |
92 | | -} else { |
93 | | - echo( "The tables already exist. No action was taken.\n" ); |
94 | 96 | } |
95 | | - |
96 | 97 | # Close the connection |
97 | 98 | $dba->close(); |
98 | 99 | echo( "\n" ); |