Coder Social home page Coder Social logo

octfx / wiki-seo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tinymighty/wiki-seo

5.0 4.0 2.0 2.12 MB

Main development on Gerrit: https://gerrit.wikimedia.org/g/mediawiki/extensions/WikiSEO.

Home Page: https://www.mediawiki.org/wiki/Extension:WikiSEO

License: GNU General Public License v2.0

PHP 99.40% JavaScript 0.33% Lua 0.27%
mediawiki-extension seo-optimization

wiki-seo's Introduction

Package octfx/wiki-seo was updated to use the new repository.

MediaWiki WikiSEO extension

Starting from 2023-01-23, WikiSEO requires MediaWiki 1.39.0

The WikiSEO extension allows you to replace, append or prepend the html title tag content, and allows you to add common SEO meta keywords and a meta description.

Extension Page: Extension:WikiSEO

Installation

  • Download and place the file(s) in a directory called WikiSEO in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
wfLoadExtension( 'WikiSEO' );
  • Configure as required.
  • Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration

The following variables are in use by this extension.

Variable Description Usage
Site / App Keys
$wgGoogleSiteVerificationKey Setting this variable will add a <meta name="google-site-verification" content="CODE"> tag to every page. $wgGoogleSiteVerificationKey = 'CODE';
$wgBingSiteVerificationKey Setting this variable will add a <meta name="msvalidate.01" content="CODE"> tag to every page. $wgBingSiteVerificationKey= 'CODE';
$wgFacebookAppID Setting this variable will add a <meta property="fb:app_id" content="ID"> tag to every page. $wgFacebookAppID= 'App_ID';
$wgFacebookAdmins Setting this variable will add a <meta property="fb:admins" content="ID1,ID2,..."> tag to every page. $wgFacebookAdmins= 'ID1,ID2,...';
$wgYandexSiteVerificationKey Setting this variable will add a <meta name="yandex-verification" content="CODE"> tag to every page. $wgYandexSiteVerificationKey= 'CODE';
$wgAlexaSiteVerificationKey Setting this variable will add a <meta name="alexaVerifyID" content="CODE"> tag to every page. $wgAlexaSiteVerificationKey= 'CODE';
$wgPinterestSiteVerificationKey Setting this variable will add a <meta name="p:domain_verify" content="CODE"> tag to every page. $wgPinterestSiteVerificationKey= 'CODE';
$wgNortonSiteVerificationKey Setting this variable will add a <meta name="norton-safeweb-site-verification" content="CODE"> tag to every page. $wgNortonSiteVerificationKey= 'CODE';
$wgNaverSiteVerificationKey Setting this variable will add a <meta name="naver-site-verification" content="CODE"> tag to every page. $wgNaverSiteVerificationKey = 'CODE';
General Options
$wgMetadataGenerators Array containing the metadata generator classes to load. Custom generators can be added by appending the class name without the namespace to this array. $wgMetadataGenerators = ["OpenGraph", "Twitter", "SchemaOrg"]
$wgTwitterSiteHandle Only used when Twitter generator is loaded. Setting this variable will add a tag to every page. $wgTwitterSiteHandle = '@SITE_HANDLE';
$wgWikiSeoDefaultImage Set a default image to use if no image is set on the site. If this variable is not set the sites logo will be used. $wgWikiSeoDefaultImage = 'File:Localfile.jpg';
$wgTwitterCardType Defaults to summary_large_image for the twitter card type. $wgTwitterCardType = 'summary';
$wgWikiSeoDefaultLanguage A default language code with area to generate a for. $wgWikiSeoDefaultLanguage = 'de-de';
$wgWikiSeoDisableLogoFallbackImage Disables setting $wgLogo as the fallback image if no image was set.
$wgWikiSeoNoindexPageTitles An array of page titles where a 'noindex' robot tag should be added. $wgWikiSeoNoindexPageTitles = [ 'Custom_Title', 'Main_Page' ];
$wgWikiSeoEnableAutoDescription Set to true to try to request a description from textextracts, if no description was given, or the description key is set to 'textextracts' or 'auto'. This requires Extension:TextExtracts to be loaded. The description is generated when saving the page after an edit. $wgWikiSeoEnableAutoDescription = true;
$wgWikiSeoTryCleanAutoDescription Set to true, if WikiSEO should try to remove dangling sentences when using descriptions from textextracts. This will remove all characters after the last found dot. $wgWikiSeoTryCleanAutoDescription = true;
$wgWikiSeoOverwritePageImage Set to true to enable overwriting the iamge set by extension PageImages. $wgWikiSeoOverwritePageImage = true;
Social Media Images
$wgWikiSeoEnableSocialImages Generate dedicated social media icons for pages $wgWikiSeoEnableSocialImages = true;
$wgWikiSeoSocialImageIcon The icon/watermark to add to the social media image. Use a local file name $wgWikiSeoSocialImageIcon = LocalFile.jpg;
$wgWikiSeoSocialImageWidth Width of the social media image $wgWikiSeoSocialImageWidth = 1200;
$wgWikiSeoSocialImageHeight Height of the social media image $wgWikiSeoSocialImageHeight = 620;
$wgWikiSeoSocialImageTextColor Color of the text on the social image $wgWikiSeoSocialImageTextColor = #fff;
$wgWikiSeoSocialImageShowAuthor Show the author of the current page revision $wgWikiSeoSocialImageShowAuthor = true;
$wgWikiSeoSocialImageShowLogo Show the Wiki logo in the top right corner $wgWikiSeoSocialImageShowLogo = true;
$wgWikiSeoSocialImageBackgroundColor Default background color if no page image is found

Usage

The extension can be used via the {{#seo}} parser function or in Lua modules by using mw.ext.seo. It accepts the following named parameters in any order.

  • title
    • The title you want to appear in the html title tag
  • title_mode
    • Set to append, prepend, or replace (default) to define how the title will be amended.
  • title_separator
    • The separator in case titlemode was set to append or prepend; " - " (default)
  • keywords
    • A comma separated list of keywords for the meta keywords tag
  • description
    • A text description for the meta description tag
  • robots
    • Controls the behavior of search engine crawling and indexing
    • Assumes the following order: index policy, follow policy
    • Example: robots=index,nofollow / noindex,follow / index,follow / etc.
    • Invalid: robots=follow,index
  • googlebot
    • Controls the behavior of the google crawler
  • hreflang_xx-xx[]
    • Adds <link rel="alternate" href="url" hreflang="xx-xx"> elements

Tags related to the Open Graph protocol

  • type
    • The type of your object, e.g., "video.movie". Depending on the type you specify, other properties may also be required.
  • image
    • An image URL which should represent your object within the graph. The extension will automatically add the right image url, width and height if an image name is set as the parameter. Example image = Local_file_to_use.png. Alternatively a full url to an image can be used, image_width and image_height will then have to be set manually. If no parameter is set, the extension will use $wgLogo as a fallback or the local file set through $wgWikiSeoDefaultImage.
  • image_width
    • The image width in px. (Automatically set if an image name is set in image)
  • image_height
    • The image height in px. (Automatically set if an image name is set in image)
  • image_alt
    • Alternative description for the image.
  • locale
    • The locale these tags are marked up in. Of the format language_TERRITORY.
  • site_name
    • If your object is part of a larger web site, the name which should be displayed for the overall site. e.g., "IMDb".

Tags related to Open Graph type "article"

  • author
    • Writers of the article.
  • keywords
    • Translates into article:tag
  • section
    • A high-level section name. E.g. Technology
  • published_time
    • When the article was first published. ISO 8601 Format.

Tags related to Twitter Cards (see OpenGraph Tags)

  • twitter_site
    • If you did not set a global site name through $wgTwitterSiteHandle, you can set a site handle per page. If a global site handle is set this key will be ignored.
  • twitter_card
    • Allows per page overriding of $wgWikiSEOTwitterCardType

Tags related to the Citation generator

  • description
  • keywords
  • citation_type
  • citation_name
  • citation_headline
  • citation_date_published
  • citation_date_created
  • citation_page_start
  • citation_doi
  • citation_author
  • citation_publisher
  • citation_license
  • citation_volume

** Tags related to the Dublin Core generator**

  • description
  • title
  • author
  • locale
  • site_name
  • dc.identifier.wikidata

Examples

Adding static values

{{#seo:
 |title=Your page title
 |titlemode=append
 |keywords=these,are,your,keywords
 |description=Your meta description
 |image=Uploaded_file.png
 |image_alt=Wiki Logo
}}

Adding dynamic values

If you need to include variables or templates you should use the parser function to ensure they are properly parsed. This allows you to use Cargo or Semantic MediaWiki, with Page Forms, for data entry, or for programmatic creation of a page title from existing variables or content...

{{#seo:
 |title={{#if: {{{page_title|}}} | {{{page_title}}} | Welcome to WikiSEO}}
 |titlemode={{{title_mode|}}}
 |keywords={{{keywords|}}}
 |description={{{description|}}}
 |published_time={{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}
}}
{{#seo:
|title_mode=append
|title=Example SEO Wiki
|keywords=WikiSEO, SEO, MediaWiki
|description=An example description for this wiki
|image=Wiki_Logo.png
|image_alt=Wiki Logo
|site_name=Example SEO Wiki
|locale=en_EN
|type=website
|modified_time={{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}
|published_time=2020-11-01
}}

Using the lua module

WikiSEO exposes a lua method as mw.ext.seo.set

Example module:

-- Module:SEO
local seo = {}

--[[
argTable format:
{
  title_mode = 'append',
  title = 'Example Seo Wiki',
  keywords = 'WikiSEO, SEO, MediaWiki',
  -- ...
}
]]--
function seo.set( argTable )
  mw.ext.seo.set( argTable )
end

function seo.setStatic()
  mw.ext.seo.set{
    title_mode = 'append',
    title = 'Example Seo Wiki',
    keywords = 'WikiSEO, SEO, MediaWiki',  
  }
end

return seo

The module would now be callable as {{#invoke:SEO|add|title=ExampleTitle|keywords=WikiSEO, SEO, MediaWiki}} or {{#invoke:SEO|addStatic}}.

Hreflang Attributes

{{#seo:
 |hreflang_de-de=https://example.de/page
 |hreflang_nl-nl=https://example.nl/page-nl
 |hreflang_en-us=https://website.com/
}}

Will generate the following <link> elements:

<link rel="alternate" href="https://example.de/page" hreflang="de-de">
<link rel="alternate" href="https://example.nl/page-nl" hreflang="nl-nl">
<link rel="alternate" href="https://website.com/" hreflang="en-us">

Title Modes

Example: Page with title Example Page

Append

{{#seo:
 |title_mode=append
 |title=Appended Title
}}

HTML Title result: Example Page - Appended Title

Prepend

{{#seo:
 |title_mode=prepend
 |title=Prepended Title
}}

HTML Title result: Prepended Title - Example Page

Prepend (changed separator)

{{#seo:
 |title_mode=prepend
 |title=Prepended Title
 |title_separator=<nowiki>&nbsp;>>&nbsp;</nowiki>
}}

HTML Title result: Prepended Title >> Example Page

Replace (default)

{{#seo:
 |title_mode=replace
 |title=Replaced Title
}}

HTML Title result: Replaced Title

Hooks

WikiSEO exposes Hooks that allow to customize the metadata that gets added to the page and saved in page props.

  • WikiSEOPreAddMedatada
    • onWikiSEOPreAddMedatada( &$metadata )
    • An array of key-value pairs validated through Validator::validateParams
    • Run right before the instantiation of the metadata generators
  • WikiSEOPreAddPageProps
    • onWikiSEOPreAddPageProps( &$metadata )
    • An array of key-value pairs validated through Validator::validateParams
    • Run right before setting the page props
  • WikiSEOLuaPreAddPageProps
    • onWikiSEOLuaPreAddPageProps( &$metadata )
    • An array of key-value pairs validated through Validator::validateParams
    • Run right before setting the page props
    • Only run when the lua module is called | $wgWikiSeoSocialImageBackgroundColor = #14181f; |

Migrating to v2

Removed tags

  • DC.date.created
  • DC.date.issued
  • google
  • name
  • og:title (automatically set)
  • og:url (automatically set)
  • twitter:card (automatically set)
  • twitter:creator
  • twitter:domain
  • article:modified_time / og:updated_time (automatically set)

Removed aliases

  • metakeywords / metak
    • use keywords instead
  • metadescription / metad
    • use description instead
  • titlemode / title mode
    • use title_mode instead

Changed argument names

  • article:author -> author
  • article:section -> section
  • article:tag -> keywords
  • article:published_time -> published_time
  • og:image / twitter:image:src -> image
  • og:image:width -> image_width
  • og:image:height -> image_height
  • og:locale -> locale
  • og:site_name -> site_name
  • og:title -> title
  • og:type -> type
  • twitter:description -> description

Known Issues

Extension:PageImages will add an og:image tag if an image is found on the page. This overwrites any og:image tag set using this extension.
There is currently no way to disable PageImages setting the meta tag.

Notes

If you only want to override the display title on pages (not append words to it), you might also look at the DISPLAYTITLE tag in combination with the Manual:$wgAllowDisplayTitle and Manual:$wgRestrictDisplayTitle settings.

schema.org

The SchemaOrg generator will set a SearchAction property based on Special:Search.
The properties publisher and author will be set to Organization with the name set to the content of $wgSitename.
dateModified will be automatically set by fetching the latest revision timestamp. If no published_time is set, datePublished will be set to the latest revision timestamp.

OpenGraph

article:modified_time will be automatically set by fetching the latest revision timestamp. If no published_time is set, article:published_time will be set to the latest revision timestamp.
This can be disabled on a per-page basis by setting modified_time=- through the parser.

Extending this extension

Metadata generators live in the includes/Generator/Plugins directory.
A generator has to implement the GeneratorInterface.
To load the generator simply add its name to $wgMetadataGenerators.

wiki-seo's People

Contributors

andru avatar bawolff avatar cougrimes avatar cscott avatar develle avatar kghbln avatar kizule avatar marcoaureliowm avatar mary-kate avatar octfx avatar paladox avatar porplemontage avatar raymondde avatar reedy avatar rhinosf1 avatar samwilson avatar subbuss avatar tosfos avatar translatewiki avatar umherirrender avatar universal-omega avatar vedmaka avatar zabemath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wiki-seo's Issues

Auto description doesn't work on page save unless parser function is present

If you set $wgWikiSeoEnableAutoDescription=true without setting $wgWikiSeoSaveAutoDescriptionOnView to true, the auto description is not set on page save unless the seo parser function/tag is on the page. I think the auto description should be added to pages without the tag, using a save page hook (?)

Maintenance script fails with Errors in 1.37

Hi i tried to run the generateDescriptions script but it fails with some errors:

root@miki-en-mediawiki-678847567b-q2pnv:/var/www/html/extensions/WikiSEO# php maintenance/GenerateDescription.php 0
PHP Deprecated:  Use of Maintenance::getArg without an $argId was deprecated in MediaWiki 1.33. [Called from GenerateDescription::execute in /var/www/html/extensions/WikiSEO/maintenance/GenerateDescription.php at line 36] in /var/www/html/includes/debug/MWDebug.php on line 375
Deprecated: Use of Maintenance::getArg without an $argId was deprecated in MediaWiki 1.33. [Called from GenerateDescription::execute in /var/www/html/extensions/WikiSEO/maintenance/GenerateDescription.php at line 36] in /var/www/html/includes/debug/MWDebug.php on line 375
Generating description for 'Fluffychat'
[ec62bc12e624e3e9a26317fb] [no req]   TypeError: Argument 2 passed to MediaWiki\Extension\WikiSEO\DeferredDescriptionUpdate::__construct() must be of the type string or null, bool given, called in /var/www/html/extensions/WikiSEO/maintenance/GenerateDescription.php on line 84
Backtrace:
from /var/www/html/extensions/WikiSEO/includes/DeferredDescriptionUpdate.php(66)
#0 /var/www/html/extensions/WikiSEO/maintenance/GenerateDescription.php(84): MediaWiki\Extension\WikiSEO\DeferredDescriptionUpdate->__construct(Title, boolean)
#1 /var/www/html/maintenance/doMaintenance.php(108): GenerateDescription->execute()
#2 /var/www/html/extensions/WikiSEO/maintenance/GenerateDescription.php(93): require_once(string)
#3 {main}

Setting meta tags

Hello, good evening

My team has been working on a wiki that we created https://wiki.lodgecompliance.com/Lodge_Compliance We downloaded and installed the wikiSEO extension version 2.5.0 and it seemed to be working fine. But for a few days now I have been trying to edit the title, meta descriptions and keywords but the changes are not reflecting on google SERP.

Although I can see the title change from the tabs of my web browser, but when I search on google, I see that neither the title or description has changed.

Kindly assist with any tips on how to fix this.

Thank you

Auto descriptions don't update once generated

If I change the opening content of the page, the auto description doesn't update. On page save, it should check if auto descriptions are enabled and update the description if so.

$wgMetadataGenerators (and probably more config) is not working

Hi,
I recognize that setting $wgMetadataGenerators has no result at all in my environments (a working wiki as well as local development). The only way to change metadata generators is to modify extension.json.

My configuration in LocalSettings.php looks like:

wfLoadExtension( 'WikiSEO' );
$wgMetadataGenerators = ["MyCustomPlugin"];

(or any other change)

After some research, I found the https://www.mediawiki.org/wiki/Manual:Configuration_for_developers manual. It recommends a bit different usage of configuration. I tried it:

  1. in extension.json, I added:
"ConfigRegistry": {
	"WikiSEO": "GlobalVarConfig::newInstance"
},
  1. In WikiSEO.php, on line 182, I replaced existing getMainConfig with:
MediaWikiServices::getInstance()->getConfigFactory()->makeConfig('WikiSEO')->get( 'MetadataGenerators' );

...and now it works. I'm unsure if there is something wrong with what I do, or something wrong with the usage of getMainConfig

Support Naver Site Verification

Somewhat similar to Yandex, Naver has won the Search Engine battle in South Korea, and takes care of (approximately) 75% of search traffic in Korea.

It has following syntax for meta tag verification: <meta name="naver-site-verification" content="$TAG" /> (Sorry, docs are only available in Korean)

Can you add it? Thanks!

WikiSEO adds extraneous newline (`<br />`)

Normally in MediaWiki one can write various magic words, templates, widgets, etc. into new lines in the MediaWiki markup without these generating newlines. However, WikiSEO seems to inject extraneous newlines.

Example...

Broken, extraneous newline (<br />):

{{Header}}
{{#seo:
|description=test
}}

OK, no extraneous newline (<br />):

{{Header}} {{#seo:
|description=test
}}

Is there some way to tell the MediaWiki parser "do not add any newline (<br />) after invocation of {{#seo}}?

wgWikiSeoTryCleanAutoDescription should be language-agonistic

wgWikiSeoTryCleanAutoDescription should take consideration of different punctuation in different languages.
For example, the period in Chinese is not the same in English.

In the current setup, the English period . is used. When trying to clean auto description from Chinese, the description returns no string but a period.

cannot set og:title

I cannot set og:title. It is always set to the name of the wiki page.

For example wiki page wiki/NameOfWikiPage will result in:

{{#seo:
|title=Test-Title2
|description=Description is functional.
}}

It properly sets the HTML title though:

<title>Test-Title2</title>

The following does not help either:

{{#seo:
|title=Test-Title2
|og:title=Test-Title2
|description=Description is functional.
}}

Using {{DISPLAYTITLE:Test-Title2}} above or below the {{#seo: code block ​results in the bold title on top of the wiki page to show Test-Title2 as expected but og:title is ​still wrong, i.e. still <meta property=og:title content=NameOfWikiPage />.


Using:

  • mediawiki 1.35.2
  • WikSEO 2.6.5 (202fdb8)
$wgAllowDisplayTitle = true;
$wgRestrictDisplayTitle = false;

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.