Extension talk:Attribute

Latest comment: 13 years ago by Mickeyf in topic 1.16.1
The following discussion has been transferred from Meta-Wiki.
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).

I'm using MediaWiki: 1.7.1, PHP: 5.1.5 (apache2handler) and MySQL: 5.0.24-community-nt

I had to change

// Add special page
  if (  version_compare( $wgVersion, '1.7.1', '<' )) {
    require_once(dirname(__FILE__) . '/xyAttributeQuery.php');
    SpecialPage::addPage(new XyAttributeQuery() );
    }
  else {
    if ( !function_exists( 'extAddSpecialPage' ) ) {
      require( dirname(__FILE__) . '/../ExtensionFunctions.php' );
      }
    extAddSpecialPage( dirname(__FILE__) . '/xyAttributeQuery.php', 'XyAttributeQuery', 'XyAttributeQuery' );
    }

to

// Add special page
  if (  version_compare( $wgVersion, '1.7.1', '<=' )) {
    require_once(dirname(__FILE__) . '/xyAttributeQuery.php');
    SpecialPage::addPage(new XyAttributeQuery() );
    }
  else {

    if ( !function_exists( 'extAddSpecialPage' ) ) {
      require( dirname(__FILE__) . '/../' );
      }
    extAddSpecialPage( dirname(__FILE__) . '/xyAttributeQuery.php', 'XyAttributeQuery', 'XyAttributeQuery' );


    }

in xyAttribute.php

There's no ExtensionFunctions.php in 1.7.1, and I couldn't find much about the file. Seems to work fine after the change.

Icon issue: Using MW 1.7.1, had to comment out the $xyAttributePng line in LocalSettings.php in order for the button to display properly in the editor. --Jtautry 21:31, 16 October 2006 (UTC)Reply

Props

edit

Just wanted to leave some props. Very cool extension. --131.158.72.67 22:12, 15 December 2006 (UTC)Reply

MW Versions

edit

Is it possible to have it on MW 1.6.7? Any changes to code are needed?

Regards, Aretai 14:43, 2 February 2007 (UTC)Reply


Having problems in 1.9.2 version

edit
  • I am getting

"Fatal error: Call to undefined function wfInsertArray() in /opt/lampp/mediawiki/extensions/xyAttribute/xyAttribute.php on line 170"

--129.46.173.14 02:10, 17 February 2007 (UTC)Reply


  • I had the same problem using version 1.9.3

Solved including the following statement right before line 170:

 require_once("./includes/DatabaseFunctions.php");

201.49.16.43 17:30, 10 May 2007 (UTC)Reply

missing specialpage

edit

I simply don't have the page for querying the data. I had some minor issues installinng the extension (like missing ExtensionFunctions.php that I didn't have in the extensions directory and a missing localization file plus I had to paste the SQL thing in phpMyAdmin) that I fixed. But I don't have the special page, I usually nuke everything that doesn't work, but this is a neat extension and anyway the data is being gathered even if I don't have any specialpage for querying it.

Any suggestions on manually creating the specialpage? 354d 18:11, 20 August 2007 (UTC)Reply

More recent versions?

edit

Just wondering if there are any plans to update this extension for the more recent versions of MediaWiki, specifically 1.12?

Working with 1.11.2

edit
  • Installing ExtensionFunctions.php and activating DatabaseFunctions.php as described above
  • Adding return values for some functions in xyAttribute.php

Here is the whole patch for xyAttribute.php

79a80
>   return true;
86c87
<   if ($action != 'xyAttributes') return;
---
>   if ($action != 'xyAttributes') return false;
89c90
<   $myAction = wfMsg('xyattributes');
---
>   $myAction = wfMsg('xyAttributes');
106c107
<     return;
---
>     return false;
158c159
<   if (!$ret) return;  
---
>   if (!$ret) return false;  
169a171
>   require_once("./includes/DatabaseFunctions.php");
170a173
>   return true;

Working with 1.13.3

edit
  • Using this modified xyAttribute.php and adding to the extension folder ExtensionFunctions.php and activating DatabaseFunctions.php as described above will get things working with 1.13.3. (Based on the post above)
<?php
/* Attribute extension for mediawiki
 *
 * @author   xypron
 * @version  0.4
 * filename: xyAttribute.php 
 *
 * Version history
 * 0.4 Attribute Query added
 * 0.3 Installer added
 * 0.2 Tuple IDs added to attributes table
 * 0.1 First version
 *
 * Adds:
 *   - attribute tag with attributes name and value
 *   - attribute icon for editor
 *   - attribute tab to see attribute values
 *   - database table with attributes for evaluations
 */
 
if(!defined('MEDIAWIKI')) {
   header("HTTP/1.1 404 Not Found");
   die('<H1>404 Not found</H1>');
   }

// Our variables
$xyAttributePng = $wgScriptPath."/extensions/xyAttribute/attribute.png";

//install extension hooks
$wgHooks['SkinTemplateTabs'][] = 'xyAttributesTabHook';
$wgHooks['UnknownAction'][] = 'xyAttributesActionHook';
$wgHooks['ArticleSaveComplete'][] = 'xyAttributesCompleteHook';
$wgHooks['EditPage::showEditForm:initial'][] = 'xyAttributesEditorButton';

// Add the initialization routine as extension function.
$wgExtensionFunctions[] = 'xyAttributesInit';

// Intialize 
function xyAttributesInit() {
  global $wgMessageCache, $wgParser, $wgUser, $wgVersion;
  global $xyAttributes;

// Add special page
  if (  version_compare( $wgVersion, '1.7.1', '<' )) {
    require_once(dirname(__FILE__) . '/xyAttributeQuery.php');
    SpecialPage::addPage(new XyAttributeQuery() );
    }
  else {
    if ( !function_exists( 'extAddSpecialPage' ) ) {
      require( dirname(__FILE__) . '/../ExtensionFunctions.php' );
      }
    extAddSpecialPage( dirname(__FILE__) . '/xyAttributeQuery.php', 'XyAttributeQuery', 'XyAttributeQuery' );
    }

  // During parsing $xyAttributes will be filled
  $xyAttributes= Array();
  // Add a parser hook for the attribute tag
  $wgParser->setHook( "attribute", "xyAttributeParse" );
  $lang = $wgUser->getOption('language');
  $langInclude=dirname(__FILE__)."/xyAttributeMessages.";
  //en = default
  include($langInclude."en");
  if ($lang != "en") {
    include($langInclude.$lang);
    }
  }

// add a tab on the article page
function xyAttributesTabHook(&$skin , &$content_actions ) {
  global $wgRequest, $wgTitle;

  $myAction = wfMsg('xyAttributes');
  $action   = $wgRequest->getText( 'action' );

  $content_actions['xyAttributes'] = array(
    'class' => ($action == 'xyAttributes')? 'selected' : '',
    'text'  => wfMsg('xyattributes'),
    'href'  => $wgTitle->getLocalUrl('action=xyAttributes')
    );
  return true;
  }

// Show the attributes
function xyAttributesActionHook( &$action, &$article ) {
  global $wgTitle, $wgOut, $wgUser, $wgDBprefix;
  // Is this our action?
  if ($action != 'xyAttributes') return false;
  
  
  $myAction = wfMsg('xyAttributes');
  $tblname = $wgDBprefix."xyAttributes";
  $id = $article->getID();

  // read database table
  $sql = "SELECT * FROM $tblname WHERE page_id = $id ORDER BY page_id, tuple_id, name";
//  $dbr =& wfGetDB( DB_SLAVE );
//  $ret = $dbr->query ( $sql ) ;
  $dbr =& wfGetDB( DB_SLAVE );
  if ( $dbr !== false ) {
    $ret = $dbr->query( $sql, '', true );
    }
  else {
    $ret = false;
    }
  if (!$ret) {
    require_once(dirname(__FILE__) . '/xyAttributeInstall.php');
    return false;
    }
  // output as wiki table
  $output = 
      "{|\n"
    . "| '''" . wfMsg('xytuple') . "'''\n"
    . "| '''" . wfMsg('xyname') . "'''\n"
    . "|\n| '''" . wfMsg('xyvalue') . "'''\n"
    . "|-\n";

  $tuple_id = -1;
  while( $row = $dbr->fetchObject( $ret ) ){
    $output .= "| ";
    if ($row->tuple_id != $tuple_id) {
      $tuple_id = $row->tuple_id;
      $output.= $tuple_id;
      };
    $output .= "\n| ".$row->name."\n| =\n| ".$row->value."\n|-\n";
    }
    $output .= "|}";
  $dbr->freeResult( $ret );
  $wgOut->clearHTML();
  $wgOut->addWikiText($output);
  return false;
  }
  
function xyAttributeParse($content, $params, $parser ) {
  global $xyAttributes;
  // remember attributes
  $tuple_id = xyAttribute::nextTupleID();  
  $xyAttributes[$tuple_id] = $params;
  return $content;
  }

// When article is saved, insert collected attributes into database table
function xyAttributesCompleteHook(&$article, &$user, $text, $summary ) {
  global $wgDBprefix, $wgDBtype, $wgOut;
  global $xyAttributes;
  
  $id = $article->getID();
  $tblname = $wgDBprefix."xyAttributes";

  // delete existing entries
  $sql = "DELETE from $tblname WHERE page_id = '$id'";
  $db =& wfGetDB( DB_MASTER );
  if ( $db !== false ) {
    $ret = $db->query( $sql, '', true );
    }
  else {
    $ret = false;
    }
  // we cannot delete, probably table is missing  
  if (!$ret) return false;  
  $tab = Array();
  foreach( $xyAttributes as $tuple_id => $arr ) {
    foreach( $arr as $opt => $val ) {
      $row = Array(
        'page_id'  => $id,
        'tuple_id' => $tuple_id,
        'name'     => $opt,
        'value'    => $val);
      $tab[]=$row;
      }
    }
  require_once("./includes/DatabaseFunctions.php");
  $ret = wfInsertArray( "xyAttributes", $tab);
  return true;
  }

// Add a button to the internal editor
function xyAttributesEditorButton ($editPage) { 
  global $wgOut, $wgScriptPath, $xyAttributePng;
  
  $ico = $xyAttributePng;
  $alt = wfMsg('xyattribute');
  // Insert javascript script that hooks up to create button.
  $wgOut->addScript("<script type=\"text/javascript\">\n".
       "function xyAttributesAddButton(){\n".
       "  addButton('$ico','$alt','<'+'attribute name=\"','\" />','value');".
       "  }\n".
       "addOnloadHook(xyAttributesAddButton);\n".
       "</script>");
        return true;
  }
  
class xyAttribute {
  var $error = 0;
  
/*
 * Counter for tuples
 * Tested with PHP 4.3.6 Win32
 * Tested with PHP 5.1.1 Win32 
 */ 
  function nextTupleId() {
    static $tuple_id;
    if (!isset($tuple_id)) $tuple_id = 0;
    return ++$tuple_id;
    }
    
  function installErrorHandler() {
    $this->error = 1;
    }
  }
  
  
?>


1.16.1

edit

In xyAttributeQuery.php there is an apparent typo. Around line 235, the query button creation line should look like:

<TD><INPUT name="ok" type="submit" value="$Query" /></TD>

The unbalanced <TD </TD tags in the downloaded file cause Chrome and EI8 and EI9 to choke and fail to display the button. Firefox is more forgiving and never had this problem.

Mickeyf 16:00, 12 July 2011 (UTC)Reply

Return to "Attribute" page.