A few weeks ago, I discovered that searches with a few subqueries were dreadfully slow and found the cause to be making annotated redirects equivalent to their targets. I suggested making redirect equivalency a SMW option--but when I went scanning for how to implement it, I gleefully found that it was already included! The setting is:

$smwgQEqualitySupport = true; // Should #redirects be evaluated as equality between page names?

(It should probably include a note about efficiency for its comment, just like the one for $smwgQDefaultNamespaces--taking out redirect equality support can make a HUGE difference for more complex queries. HUGE being the difference between a three subquery search taking 34 minutes with redirect equivalency and .3 seconds without.)

In any case, my semantic wiki has been happily humming and searching along since I set $smwgQEqualitySupport to false. But I also need a way to tell where annotations in the wiki are pointing to redirected pages, so they can be fixed.

So I've made a special page for redirected annotations that extends SMWQueryPage. This will make it easy for people to find where annotations are pointing to redirected pages and fix them to point at the right ones.

Messages that would are added for this page:

        // Messages for Redirected Annotations Special
        'redirectedannotations' => 'Redirected annotations',
'smw_redirectedannotations_docu' => 'The object of these annotations points to a redirected page.', 'smw_redirectedannotations_template' => 'On page $1, the annotation $2::$3 redirects to $4.',

It required one additional function to SMW_SQLStore in the "Special page functions" section:

function getRedirectedAnnotationsSpecial($requestoptions = NULL) {
                wfProfileIn("SMWSQLStore::getRedirectedAnnotationsSpecial 
(SMW)");
                $db =& wfGetDB( DB_SLAVE );
                $options = ' ORDER BY subject_title';
                
                if ($requestoptions->limit > 0) {
                        $options .= ' LIMIT ' . $requestoptions->limit;
                }
                if ($requestoptions->offset > 0) {
                        $options .= ' OFFSET ' . $requestoptions->offset;
                }
                
                extract( $db->tableNames('smw_relations', 'redirect') );

$res = $db->query("SELECT subject_title, subject_namespace, relation_title, object_title, object_namespace, rd_title, rd_namespace FROM $smw_relations " . "INNER JOIN $redirect ON $smw_relations.object_id = $redirect.rd_from"
                        . $options, 'SMW::getRedirectedAnnotationsSpecial');
                $result = array();
                
                while($row = $db->fetchObject($res)) {
$subject_page = Title::newFromText($row->subject_title, $row- >subject_namespace); $relation_page = Title::newFromText($row->relation_title, SMW_NS_PROPERTY); $object_page = Title::newFromText($row->object_title, $row- >object_namespace);
                        $rd_page = Title::newFromText($row->rd_title, 
$row->rd_namespace);
$result[] = array($subject_page, $relation_page, $object_page, $rd_page);
                }
                
                wfProfileOut("SMWSQLStore::getRedirectedAnnotationsSpecial 
(SMW)");
                return $result;
        }

And it needs to be added in the enableSemantics() function in SMW_GlobalFunctions.php:

$wgSpecialPages['RedirectedAnnotations'] = array ('SMWSpecialPage','RedirectedAnnotations', 'smwfDoSpecialRedirectedAnnotations', $smwgIP . '/specials/QueryPages/ SMW_SpecialRedirectedAnnotations.php');

I've attached the PHP code for the page itself.

Am looking for input on:

* Whether the special page should be initialized and included only if $smwgQEqualitySupport = false
* Whether the page name RedirectedAnnotations is an adequate name
* Other wording that should be changed or tweaked. For example, in the smw_redirctedannotations_temp: * Message text: "the annotation Similar to::X redirects to Y." or "the relation Similar to::X redirects to Y.", since this only happens to relation annotations? "The object of these annotations points to a redirected page." or "The object of these relations points to a redirected page." ?
* Coding style


<?php
/**
 * @author Audra Johnson
 *
 * This page shows all annotations with a redirected object.
 */

if (!defined('MEDIAWIKI')) die();

global $smwgIP;
include_once( "$smwgIP/specials/QueryPages/SMW_QueryPage.php" );

function smwfDoSpecialRedirectedAnnotations() {
	wfProfileIn('smwfDoSpecialRedirectedAnnotations (SMW)');
	list( $limit, $offset ) = wfCheckLimits();
	$rep = new SMWRedirectedAnnotationsPage();
	$result = $rep->doQuery( $offset, $limit );
	wfProfileOut('smwfDoSpecialRedirectedAnnotations (SMW)');
	return $result;
}

class SMWRedirectedAnnotationsPage extends SMWQueryPage {

	function getName() {
		/// TODO: should probably use SMW prefix
		return "RedirectedAnnotations";
	}

	function isExpensive() {
		return false; /// disables caching for now
	}

	function isSyndicated() { 
		return false; ///TODO: why not?
	}

	function getPageHeader() {
		return '<p>' . wfMsg('smw_redirectedannotations_docu') . "</p><br />\n";
	}

	function formatResult( $skin, $result ) {
		global $wgLang, $wgExtraNamespaces;
		
		// Make links for the pages
		$subject_page = $skin->makeLinkObj($result[0], $result[0]->getText(), 'action=view');
		$relation_page = $skin->makeLinkObj($result[1], $result[1]->getText(), 'action=view');
		$object_page = $skin->makeLinkObj($result[2], $result[2]->getText(), 'action=view');
		$rd_page = $skin->makeLinkObj($result[3], $result[3]->getText(), 'action=view');
		
		$types = smwfGetStore()->getSpecialValues($result[1], SMW_SP_HAS_TYPE);
		if (count($types) >= 1) {
			$typestring = $types[0]->getLongHTMLText($skin);
		} else {
			$type = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE);
			$type->setXSDValue('_wpg');
			$typestring = $type->getLongHTMLText($skin);
			$errors[] = wfMsg('smw_propertylackstype', $type->getLongHTMLText());
		}
		
		return wfMsg('smw_redirectedannotations_template', $subject_page, $relation_page, $object_page, $rd_page ) . ' ' . smwfEncodeMessages($errors);
	}
	
	function getResults($requestoptions) {
		return smwfGetStore()->getRedirectedAnnotationsSpecial($requestoptions);
	}

}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Semediawiki-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

Reply via email to