r23213 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23212‎ | r23213 | r23214 >
Date:12:41, 22 June 2007
Author:greg
Status:old
Tags:
Comment:
Add Postgres support. Refactor touchpages concept.
Modified paths:
  • /trunk/extensions/DidYouMean/DidYouMean.php (modified) (history)
  • /trunk/extensions/DidYouMean/didyoumean.pg.sql (added) (history)
  • /trunk/extensions/DidYouMean/install.php (modified) (history)

Diff [purge]

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
115 + native
Index: trunk/extensions/DidYouMean/DidYouMean.php
@@ -70,10 +70,10 @@
7171 #wfDebug( 'HIPP: ' . __METHOD__ . "\n" );
7272
7373 # 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'))
7575 return true;
7676
77 - $parser->mDymFirstChunk = 'no';
 77+ $parser->mDymFirstChunk = 'done';
7878
7979 $title = $parser->getTitle();
8080 $parser->mDymSees = wfDymLookup( $title->getArticleID(), $title->getText() );
@@ -318,16 +318,29 @@
319319 $dbw->insert( 'dympage', array( 'dp_pageid' => $pageid, 'dp_normid' => $normid ) );
320320
321321 # 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+
330324 }
331325
 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+
332345 function wfDoDelete( $pageid ) {
333346 wfDebug( 'HIPP: ' . __METHOD__ . " DELETE\n" );
334347 $dbw = wfGetDB( DB_MASTER );
@@ -341,15 +354,8 @@
342355 if ($count == 0)
343356 $dbw->delete( 'dymnorm', array('dn_normid' => $normid) );
344357
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" );
354360 }
355361
356362 function wfDoUpdate( $pageid, $title ) {
@@ -379,20 +385,8 @@
380386 $dbw->delete( 'dymnorm', array('dn_normid' => $oldnormid) );
381387
382388 # 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+
397391 }
398392 }
399393
Index: trunk/extensions/DidYouMean/install.php
@@ -51,7 +51,11 @@
5252 }
5353
5454 # 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';
5660 echo( "Sourcing: $sql\n" );
5761 $res = $dba->sourceFile( $sql );
5862 echo( "Result: $res\n" );
@@ -88,10 +92,7 @@
8993 }
9094 $dba->freeResult( $result );
9195 }
92 -} else {
93 - echo( "The tables already exist. No action was taken.\n" );
9496 }
95 -
9697 # Close the connection
9798 $dba->close();
9899 echo( "\n" );

Status & tagging log