Jump to content

query problem (relating to wiki)


m11oct

Recommended Posts

I have a site which runs using the MediaWiki software.

There is a script in the software which automatically selects a random page for the user to view.

The code (contained in the file "SpecialRandompage.php") is:
[code] $randstr = wfRandom();

$db =& wfGetDB( DB_SLAVE );
$use_index = $db->useIndexClause( 'page_random' );
$page = $db->tableName( 'page' );

$extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : '';
$sql = "SELECT page_id,page_title
FROM $page $use_index
WHERE page_namespace=$namespace AND page_is_redirect=0 $extra
AND page_random>$randstr
ORDER BY page_random";
$sql = $db->limitResult($sql, 1, 0);
$res = $db->query( $sql, $fname );[/code]

My problem is that there are certain pages which I would like to exclude from being selected when a user wants to view a random page. The pages which I don't want to be selected randomly are "disambiguation" pages. The problem is that unlike "page_is_redirect", there is no "page_is_disambiguation" field in the database.

In the wiki, all disambiguation pages are also categorised into a category called "Disambiguation". This results in them being listed in a different table of the database (tablename: categorylinks). In this table, "page_id" in the first table would match the value of "cl_from" in the categorylinks table. There may be more than one row with a matching "cl_from" value. If the page is a disambiguation, there would be a row where "cl_from" matched "page_id" and "cl_to" was equal to text string "Disambiguation".

Any ideas how I would change the SQL query in the code? I am quite experienced with PHP but just need a little guidance on the SQL code.

Thanks in advance,
Michael
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.