r24873 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24872‎ | r24873 | r24874 >
Date:14:22, 17 August 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
New query pages for properties (will replace the old pages for relations/attributes)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages (added) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMWQueryPage.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMWQueryPage.php
@@ -0,0 +1,102 @@
 2+<?php
 3+/**
 4+ * @author Markus Krötzsch
 5+ *
 6+ * An abstract query page base class that supports array-based
 7+ * data retrieval instead of the SQL-based access used by MW.
 8+ */
 9+
 10+if (!defined('MEDIAWIKI')) die();
 11+
 12+global $IP;
 13+require_once( "$IP/includes/SpecialPage.php" );
 14+require_once( "$IP/includes/Title.php" );
 15+require_once( "$IP/includes/QueryPage.php");
 16+
 17+/**
 18+ * Abstract base class for SMW's variant of the MW QueryPage.
 19+ * Subclasses must implement getResults() and formatResult(), as
 20+ * well as some other standard functions of QueryPage.
 21+ */
 22+abstract class SMWQueryPage extends QueryPage {
 23+
 24+ /**
 25+ * Implemented by subclasses to provide concrete functions.
 26+ */
 27+ abstract function getResults($requestoptions);
 28+
 29+ /**
 30+ * Clear the cache and save new results
 31+ */
 32+ function recache( $limit, $ignoreErrors = true ) {
 33+ ///TODO
 34+ }
 35+
 36+ /**
 37+ * This is the actual workhorse. It does everything needed to make a
 38+ * real, honest-to-gosh query page.
 39+ * Alas, we need to overwrite the whole beast since we do not assume
 40+ * an SQL-based storage backend.
 41+ *
 42+ * @param $offset database query offset
 43+ * @param $limit database query limit
 44+ * @param $shownavigation show navigation like "next 200"?
 45+ */
 46+ function doQuery( $offset, $limit, $shownavigation=true ) {
 47+ global $wgUser, $wgOut, $wgLang, $wgContLang;
 48+
 49+ $options = new SMWRequestOptions();
 50+ $options->limit = $limit;
 51+ $options->offset = $offset;
 52+ $options->sort = true;
 53+ $res = $this->getResults($options);
 54+ $num = count($res);
 55+
 56+ $sk = $wgUser->getSkin();
 57+ $sname = $this->getName();
 58+
 59+ if($shownavigation) {
 60+ $wgOut->addHTML( $this->getPageHeader() );
 61+
 62+ // if list is empty, show it
 63+ if( $num == 0 ) {
 64+ $wgOut->addHTML( '<p>' . wfMsgHTML('specialpage-empty') . '</p>' );
 65+ return;
 66+ }
 67+
 68+ $top = wfShowingResults( $offset, $num);
 69+ $wgOut->addHTML( "<p>{$top}\n" );
 70+
 71+ // often disable 'next' link when we reach the end
 72+ $atend = $num < $limit;
 73+
 74+ $sl = wfViewPrevNext( $offset, $limit ,
 75+ $wgContLang->specialPage( $sname ),
 76+ wfArrayToCGI( $this->linkParameters() ), $atend );
 77+ $wgOut->addHTML( "<br />{$sl}</p>\n" );
 78+ }
 79+ if ( $num > 0 ) {
 80+ $s = array();
 81+ if ( ! $this->listoutput )
 82+ $s[] = $this->openList( $offset );
 83+
 84+ foreach ($res as $r) {
 85+ $format = $this->formatResult( $sk, $r );
 86+ if ( $format ) {
 87+ $s[] = $this->listoutput ? $format : "<li>{$format}</li>\n";
 88+ }
 89+ }
 90+
 91+ if ( ! $this->listoutput )
 92+ $s[] = $this->closeList();
 93+ $str = $this->listoutput ? $wgContLang->listToText( $s ) : implode( '', $s );
 94+ $wgOut->addHTML( $str );
 95+ }
 96+ if($shownavigation) {
 97+ $wgOut->addHTML( "<p>{$sl}</p>\n" );
 98+ }
 99+ return $num;
 100+ }
 101+
 102+}
 103+
Property changes on: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMWQueryPage.php
___________________________________________________________________
Added: svn:eol-style
1104 + native
Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
@@ -0,0 +1,62 @@
 2+<?php
 3+/**
 4+ * @author Markus Krötzsch
 5+ *
 6+ * This page shows all used attributes.
 7+ */
 8+
 9+if (!defined('MEDIAWIKI')) die();
 10+
 11+global $smwgIP;
 12+include_once( "$smwgIP/specials/QueryPages/SMWQueryPage.php" );
 13+
 14+class PropertiesPage extends SMWQueryPage {
 15+
 16+ function getName() {
 17+ /// TODO: should probably use SMW prefix
 18+ return "Properties";
 19+ }
 20+
 21+ function isExpensive() {
 22+ return false; /// disables caching for now
 23+ }
 24+
 25+ function isSyndicated() {
 26+ return false; ///TODO: why not?
 27+ }
 28+
 29+ function getPageHeader() {
 30+ return '<p>' . wfMsg('smw_properties_docu') . "</p><br />\n";
 31+ }
 32+
 33+ function formatResult( $skin, $result ) {
 34+ global $wgLang, $wgExtraNamespaces;
 35+ $proplink = $skin->makeLinkObj( $result[0], $result[0]->getText() );
 36+ $typestring = '';
 37+ $errors = array();
 38+ if ($result[1]<=5) {
 39+ $errors[] = wfMsg('smw_propertyhardlyused');
 40+ }
 41+ if ($result[0]->exists()) {
 42+ $types = smwfGetStore()->getSpecialValues($result[0], SMW_SP_HAS_TYPE);
 43+ if (count($types) >= 1) {
 44+ $typestring = $types[0]->getLongHTMLText($skin);
 45+ }
 46+ } else {
 47+ $errors[] = wfMsg('smw_propertylackspage');
 48+ }
 49+ if ($typestring == '') {
 50+ $type = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE);
 51+ $type->setXSDValue('_wpg');
 52+ $typestring = $type->getLongHTMLText($skin);
 53+ $errors[] = wfMsg('smw_propertylackstype', $type->getLongHTMLText($skin));
 54+ }
 55+ return wfMsg('smw_property_template', $proplink, $typestring, $result[1]) . ' ' . smwfEncodeMessages($errors);
 56+ }
 57+
 58+ function getResults($requestoptions) {
 59+ return smwfGetStore()->getPropertiesSpecial($requestoptions);
 60+ }
 61+
 62+}
 63+
Property changes on: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
___________________________________________________________________
Added: svn:eol-style
164 + native

Status & tagging log