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
https://forums.phpfreaks.com/topic/28482-query-problem-relating-to-wiki/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.