Coder Social home page Coder Social logo

semanticmediawiki / semanticmetatags Goto Github PK

View Code? Open in Web Editor NEW
12.0 8.0 6.0 186 KB

Allows to generate HTML <meta> elements from semantic annotations

Home Page: https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Meta_Tags

License: Other

PHP 93.04% Shell 6.96%
meta-tags mediawiki smw semantic-mediawiki smt mw semantic meta-elements

semanticmetatags's Introduction

Semantic Meta Tags

Build Status codecov Latest Stable Version Packagist download count

Semantic Meta Tags (a.k.a. SMT) is a Semantic Mediawiki extension to enhance the meta element of a page with content generated from semantic annotations.

This extension enables to automatically extend the HTML <meta> elements of a page with content generated from selected properties to create:

  • Standard meta elements (e.g meta name="keywords") as well as
  • Summary card and Open Graph protocol tags (e.g meta property="og:title")

Requirements

Installation

The recommended way to install Semantic Meta Tags is using Composer with MediaWiki's built-in support for Composer.

Note that the required extension Semantic MediaWiki must be installed first according to the installation instructions provided for it.

Step 1

Change to the base directory of your MediaWiki installation. If you do not have a "composer.local.json" file yet, create one and add the following content to it:

{
	"require": {
		"mediawiki/semantic-meta-tags": "~3.1"
	}
}

If you already have a "composer.local.json" file add the following line to the end of the "require" section in your file:

"mediawiki/semantic-meta-tags": "~3.1"

Remember to add a comma to the end of the preceding line in this section.

Step 2

Run the following command in your shell:

php composer.phar update --no-dev

Note if you have Git installed on your system add the --prefer-source flag to the above command.

Step 3

Add the following line to the end of your "LocalSettings.php" file:

wfLoadExtension( 'SemanticMetaTags' );

Documentation

This document describes features as well as necessary settings.

Contribution and support

If you want to contribute work to the project please subscribe to the developers mailing list and have a look at the contribution guideline.

Tests

This extension provides unit and integration tests that are run by a continues integration platform but can also be executed using composer phpunit from the extension base directory.

License

GNU General Public License, version 2 or later.

semanticmetatags's People

Contributors

alex-mashin avatar gesinn-it-gea avatar gesinn-it-wam avatar jeroendedauw avatar jhoeffler avatar kghbln avatar kizule avatar legoktm avatar mwjames avatar nikerabbit avatar protonotarios avatar siebrand avatar translatewiki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

semanticmetatags's Issues

Feature request: Allow callable fallbacks for $smtgTagsProperties

Proposal: if $smtgTagsProperties['tag name'] or $smtgTagsProperties['tag name'][some index] is callable, call it, passing OutputPage &$out and perhaps ParserOutput $parserOutput to it, and assign the return, if it does not evaluate to false, to the meta tag.

Reason: property values are not always set, but a non-semantic fallback can often be found. However, this fallback value should usually depend on the current page and localised messages, and trying to access both from LocalSettings.php gives horrible results, to the point of effectively breaking MediaWiki.

This feature can totally replace $smtgTagsStrings, also resolving #60.

Allow fallback properties?

When I first saw the example given in README.md of

 'keywords' => 'Has keywords, Has another keyword',

I thought that meant it would use Property:Has keywords, and if empty fallback to Property:Has another keyword. Actually the behavior is more like concatenating the two properties, and even leaves the comma in the concatenated output (which seems a little odd, but intentional).

It would be really nice to be able to provide a proper array instead.

 'keywords' => ['Has keywords', 'Has another keyword'],

And have it use the first item in the array that returns non-null output.

This may be feature creep and considered beyond scope, but I immediately wanted to use this on WikiApiary for

 'keywords' => 'Has description, Has tagline',

To use a description if provided and if not a tagline.

Meta tags not showing up consistently

I’m trying to test the meta tags and am seeing that they are not consistently being rendered on the page. I’m using the Twitter Card Validator and am getting

INFO:  Page fetched successfully
INFO:  8 metatags were found
INFO:  twitter:card = summary tag found
WARN:  Not whitelisted
ERROR: Required meta tag missing (twitter:description)
ERROR: Required meta tag missing (twitter:title)

My config is:

    # Set Semantic Tags configuration
    $GLOBALS['egSMTMetaTagsContentPropertySelector'] = array(
        // Standard meta tags
        'keywords' => 'Has tag',
        'description' => 'Has description',
        'author' => 'Page author',

        // Twitter Cards
        'twitter:title' => 'Has name',
        'twitter:image' => 'Has image URL',
        'twitter:description' => 'Has description',

        // Open Graph protocol supported tags
        'og:title' => 'Has name',
        'og:image' => 'Has image URL',
        'og:description' => 'Has description'
    );

    $GLOBALS['egSMTMetaTagsStaticContentDescriptor'] = array(
        // Static tags
        'twitter:card' => 'summary',
        'twitter:site' => '@WikiApiary',
        'og:site_name' => 'WikiApiary'
    );

When I test with curl though, it confirms that only the static meta tags are showing up!

➜  w  curl --silent -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30" 'https://wikiapiary.com/wiki/WikiApiary' | grep twitter
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@WikiApiary" />

I can also confirm this using Show source in my browser.

This is what I’m seeing using https://wikiapiary.com/wiki/WikiApiary

  1. Hit refresh in page tools and I see all 5 tags, looks perfect!
  2. Trigger refresh in browser (browser refresh, not mediawiki) and all 5 meta tags are still there. Great!
  3. Hit browser refresh again and only the static ones are present.

If I go to a browser that is not logged in, I can never see the meta tags (except for the static ones).

Wondering if this is somehow related to #9 and the PageOutput thing mentioned there.

Make 1.5.0 release

Tracking issue for the 1.5.0 release.

  • Finalize RELEASE NOTES
  • Update "README.md"
  • Update "/docs/"
  • Update "composer.json"
  • Update version number "SemanticMetaTags.php"
  • Create tag
  • Add release to Wikidata
  • Update homepage
  • Announce via mail
  • Do a release tweet on Twitter
  • Run composer update on smw.o
  • Update "LocalSettings.php"
  • Start development of new version
    • Update "composer.json" (update dev alias)
    • Update "SemanticMetaTags.php" (new alpha version)

name vs. property

Setup and configuration

  • SMW version: 2.4.6
  • SMT version: 1.3.0
  • MW version: 1.28.0
  • MySQL: 5.6.36-82.0

Issue

Facebook debugger returns:

Share App ID Missing
The 'fb:app_id' property should be explicitly provided, Specify the app ID so that stories shared to Facebook will be properly attributed to the app. Alternatively, app_id can be set in url when open the share dialog.

even though fb:app_id is declared in my configuration:

$GLOBALS['smtgTagsProperties'] = array(

	// Standard meta tags
	'keywords'            => array('Has meta tag keywords', 'Has another keyword'),
	'description'         => 'Has meta tag description',
	'author'              => 'Has meta tag author',

	// Summary card tag
	'twitter:title'       => 'Has meta tag title',
	'twitter:description' => 'Has meta tag description',
	'twitter:image'       => 'Has meta tag image',

	// Open Graph protocol supported tag
	'og:title'            => 'Has meta tag title',
	'og:description'      => 'Has meta tag description',
	'og:type'             => 'Has meta tag type',
	'og:image'            => 'Has meta tag image'
);
$GLOBALS['smtgTagsStrings'] = array(

	// Static content tag
	'fb:app_id' => '1234567890'
);

but it renders as:

<meta charset="UTF-8" />
<meta name="ResourceLoaderDynamicStyles" content="" />
<meta name="generator" content="MediaWiki 1.28.0" />
<meta name="description" content="XXXXXXXX" />
<meta name="twitter:title" content="XXXXXXXX" />
<meta name="twitter:description" content="XXXXXXXX" />
<meta name="twitter:image" content="http://XXXXXXXX.jpg" />
<meta name="fb:app_id" content="1234567890" />
<meta property="og:title" content="XXXXXXXX" />
<meta property="og:description" content="XXXXXXXX" />
<meta property="og:type" content="XXXXXXXX" />
<meta property="og:image" content="http://XXXXXXXX.jpg" />

So it seems that fb:app_id renders as name="fb:app_id" when it should be property="fb:app_id".

Why do some tags render as names and others as properties? For example, my Twitter and Facebook tags are assigned to the exact same semantic properties so I can't understand why they render differently. Is there a way to control whether they render as names or properties?

Thanks! This extension is awesome!!!!

Image in the docs

I suggest to have an image like

[screenshot of semantic data in wiki] [arrow to the right] [screenshot of the html with the tags]

That allows people to see at a glance what it is about.

Make 1.4.0 release

  • Finalize release notes
  • Update "README"
  • Update "composer.json" (remove SMW 3.0 dev)
  • Update "SemanticMetaTags.php" (version 1.4.0)
  • Create tag
  • Start development of new version
    • Update "SemanticMetaTags.php" (version 1.5.0-alpha)
    • Update "composer.json" (add SMW 3.0 dev)
  • Announce via mail
  • Do a release tweet on Twitter

Make 3.0.0 release

Tracking issue for the 2.1.0 release.

  • Finalize RELEASE NOTES
  • Update "README.md"
  • Update "/docs/"
  • Update "composer.json"
  • Update version number "extension.json"
  • Create tag
  • Add release to Wikidata
  • Update homepage
  • Announce via mail
  • Do a release tweet on Twitter
  • Run composer update on smw.o
  • Update "LocalSettings.php"
  • Start development of new version
    • Update "composer.json" (update dev alias)
    • Update "extension.json" (new alpha version)

Add Schema.org support via JSON-LD

Feature request

This has been discussed here.
SMT would probably a good place to implement something like this. Instead of "only" meta-tags, a JSON-LD representation that can be customized/populated from semantic properties would be a very valuable addition to any SMW instance.

Make `$smtgTagsProperties` take precedence over `$smtgTagsStrings`

Issue

Currently settings for $smtgTagsProperties and $smtgTagsStrings are both considered and added to the head for the same meta element, e.g. setting

$smtgTagsProperties = [
	'description' => 'Meta-Element description'
];

together with an annotation set on a page and

$smtgTagsStrings = [
	'description' => 'My awesome wiki'
];

will result into two meta elements for "description" in the head on the same page.

However there are many wikis out there which do not use templates on all their content pages. Thus they need to set $smtgTagsStrings to get e.g. a description out to the head of every page. This however removes the possibility to add page specific and more tailored descriptions via templates were possible.

Thus it will be great if a value passed via $smtgTagsProperties takes precedence over values set via $smtgTagsStrings for the very same meta element.

This file is part of the SemanticMetaTags extension, it is not a valid entry point.

Setup and configuration

MediaWiki 1.39.4 (c06e1c5)00:11, 2 July 2023
PHP 7.4.33 (apache2handler)
MariaDB 10.5.19-MariaDB-0+deb11u2
Semantic Meta Tags 3.1.0-alpha

Issue

MediaWiki 1.39.x, Compser 2.x and SMT no longer play nicely. If you install this extension via Composer, it works, however, if you would like to run composer update --no-dev at some later point, you will get the following error message:

This file is part of the SemanticMetaTags extension, it is not a valid entry point.

The error is preventing Composer from being executed. To mitigate, you must delete the /vendor/ directory and run composer update --no-dev again to get the software in. Just removing the inclusion of the extension from "LocalSettings.php" and from "composer.local.json" does not mitigate the issue.

Suspicion is that autoloading files via "composer.json" is causing the issue: https://github.com/SemanticMediaWiki/SemanticMetaTags/blob/3.0.0/composer.json#L44 I do not know for sure if this is the cause.

Make 2.0.0 release

Tracking issue for the 2.0.0 release.

  • Finalize RELEASE NOTES
  • Update "README.md"
  • Update "/docs/"
  • Update "composer.json"
  • Update version number "extension.json"
  • Create tag
  • Add release to Wikidata
  • Update homepage
  • Announce via mail
  • Do a release tweet on Twitter
  • Run composer update on smw.o
  • Update "LocalSettings.php"
  • Start development of new version
    • Update "composer.json" (update dev alias)
    • Update "extension.json" (new alpha version)

Ask for a example page that is using Semantic Meta Tags

Setup and configuration

  • SMW version:3.2.3
  • SMT version:3.0.0
  • MW version:1.35.4
  • DB (MySQL etc.):MySQL

Issue

I'm trying to create a page of Semantic Meta Tags, I recognize that there was an example on Semantic MediaWiki Sandbox. However, this site is unavailable right now which says:

"sandbox.semantic-mediawiki.org" is currently not available and should be back in the first quarter of 2022.

I would be appreciate it if you can provide an example for me. Here is my email: [email protected]
Thank you all the same.

How do I set `og:image` (OpenGraph Image) etc. dynamically?

This isn't really an issue: it's just a plea for help. I'm mostly trying to implement this to get a correct og:image to appear when pages are shared on Facebook. I've managed to follow the instructions and have a static image but I'm somewhat lost as to how to do variable meta properties.

If I could get some personalised help, I'm pretty sure I could help updated the documentation to provide a much better experience of trying to use what I can see is a very powerful addition to SMW.

Setup and configuration

  • SMW version: 2.5.4
  • SMT version: 1.4.0
  • MW version: 1.29.1
  • DB (MySQL etc.):

Update Semantic Meta Tags at packagist

Hi! Today I tried to install this extension with SMW 4.1 and got the following error:

Problem 1
    - Root composer.json requires mediawiki/semantic-meta-tags ~3.0 -> satisfiable by mediawiki/semantic-meta-tags[3.0.0].
    - mediawiki/semantic-meta-tags 3.0.0 requires mediawiki/semantic-media-wiki ~3.1 -> found mediawiki/semantic-media-wiki[3.1.0, ..., 3.2.3] but it conflicts with your root composer.json require (~4.0).

Looking at https://packagist.org/packages/mediawiki/semantic-meta-tags I noticed that the uploaded version still requires SMW 3.0, but the dev version was up-to-date, so I changed my composer.local.json to the following in order to complete the installation:

"mediawiki/semantic-meta-tags": "dev-master"

However, this shouldn't be necessary, right? Kind regards,

SMT interferes with rebuldData.php und setupStore.php

Setup and configuration

  • SMW version: 4.1.2
  • SMT version: 3.1.0 alpha
  • MW version: 1.39.5
  • DB (MySQL etc.): mySQL 8.0.28

Issue

rebuildData.php runs without any special errors (it runs somewhat faster), but the wiki seems not to store any data.
Effects I encountered:

  • Special:Browse always does not show any properties
  • touching LocalSettings, null-edit or regular edit of a page or purging a page does not help
  • the only exception being a edit in the User namespace
  • __SHOWFACTBOX__ interestingly shows the properties, still Special:Browse does not show anything and queries do not work
  • I did a rebuldData --delete and an ran update.php again, nothing changes

Then I realized that if I comment out SMT, rebuildData is working again.

It seems that there is a general, mayor problem with SMW probably not being compatible with SMW 4.1.2 and/or MW 1.39.

On another, working wiki, enabling SMT and running update.php resulted in the following error:

Checking table smw_object_ids ...
   Table already exists, checking structure ...
   ... changing type of field smw_id from 'INT UNSIGNED NOT NULL AUTO_INCREMENT' to 'INT(11) UNSIGNED NOT NULL KEY AUTO_INCREMENT' ... Wikimedia\Rdbms\DBQueryError from line 1618 of includes/libs/rdbms/database/Database.php: Error 1091: Can't DROP 'PRIMARY'; check that column/key exists
Function: SMW\SQLStore\TableBuilder\MySQLTableBuilder::doUpdateFieldType
Query: ALTER TABLE `smw_object_ids` DROP PRIMARY KEY

#0 includes/libs/rdbms/database/Database.php(1602): Wikimedia\Rdbms\Database->getQueryException()
#1 includes/libs/rdbms/database/Database.php(1576): Wikimedia\Rdbms\Database->getQueryExceptionAndLog()
#2 includes/libs/rdbms/database/Database.php(952): Wikimedia\Rdbms\Database->reportQueryError()
#3 includes/libs/rdbms/database/DBConnRef.php(103): Wikimedia\Rdbms\Database->query()
#4 includes/libs/rdbms/database/DBConnRef.php(293): Wikimedia\Rdbms\DBConnRef->__call()
#5 extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/MySQLTableBuilder.php(231): Wikimedia\Rdbms\DBConnRef->query()
#6 extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/MySQLTableBuilder.php(201): SMW\SQLStore\TableBuilder\MySQLTableBuilder->doUpdateFieldType()
#7 extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/MySQLTableBuilder.php(131): SMW\SQLStore\TableBuilder\MySQLTableBuilder->doUpdateField()
#8 extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/TableBuilder.php(159): SMW\SQLStore\TableBuilder\MySQLTableBuilder->doUpdateTable()
#9 extensions/SemanticMediaWiki/src/SQLStore/Installer.php(229): SMW\SQLStore\TableBuilder\TableBuilder->create()
#10 extensions/SemanticMediaWiki/src/SQLStore/SQLStore.php(456): SMW\SQLStore\Installer->install()
#11 extensions/SemanticMediaWiki/src/Store.php(490): SMW\SQLStore\SQLStore->setup()
#12 includes/installer/DatabaseUpdater.php(547): SMW\Store::setupStore()
#13 includes/installer/DatabaseUpdater.php(515): DatabaseUpdater->runUpdates()
#14 maintenance/update.php(209): DatabaseUpdater->doUpdates()
#15 maintenance/includes/MaintenanceRunner.php(309): UpdateMediaWiki->execute()
#16 maintenance/doMaintenance.php(85): MediaWiki\Maintenance\MaintenanceRunner->run()
#17 maintenance/update.php(319): require_once('/srv/ma01/wiki/...')
#18 {main}

This error remains, even if you disable SMT and run it again. The only thing that helps is to delete the SMW store and start over again!

Requires Semantic MediaWiki 3.x

Hi! When I tried installing this extension via composer in a wiki running Semantic MediaWiki 4.0, I get the following error:

Problem 1
- Root composer.json requires mediawiki/semantic-meta-tags ~3.0 -> satisfiable by mediawiki/semantic-meta-tags[3.0.0].
- mediawiki/semantic-meta-tags 3.0.0 requires mediawiki/semantic-media-wiki ~3.1 -> found mediawiki/semantic-media-wiki[3.1.0, ..., 3.2.3] but it conflicts with your root composer.json require (~4.0).

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Adding the option --with-all-dependencies (or -W) does nothing, I get the exact same error.

Is this extension compatible with Semantic MediaWiki 4.x ? Is it just a matter of updating dependencies?

Support for Twitter cards

Not sure if I could just add additional twitter:card meta tags, but I see OpenGraph has a special section so thought I would highlight the potential of adding Twitter Card section as well.

SESP not working?

I’m using 'author' => 'Page author' set by SESP and I cannot get the property to show up in the meta tags. Possibly because this is a fixed property?

URLs not working in metadata?

I set some OpenGraph tags of URL type and cannot get them to show up.

        // Open Graph protocol supported tags
        'og:title' => 'Has name',
        'og:image' => 'Has image URL',
        'og:url' => 'Has URL',
        'og:description' => 'Has description, Has tagline'

On https://wikiapiary.com/wiki/WikiApiary

<!-- Open Graph protocol markup -->
<meta property="og:title" content="WikiApiary" />
<meta property="og:description" content="WikiApiary is a wiki that collects, displays and analyzes information about the usage and performance of MediaWiki websites.,Monitoring the MediaWiki universe" />

the two URL types do not appear.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.