Расширение:WikiSEO

This page is a translated version of the page Extension:WikiSEO and the translation is 49% complete.
Справка по расширениям MediaWiki
WikiSEO
Статус релиза: стабильно
Реализация Функция парсера
Описание Позволяет добавлять общие мета-элементы как часть поисковой оптимизации (SEO)
Автор(ы) Octfxобсуждение
Поддерживающий(ие) Octfx
Последняя версия 2.7.0 (2023-06-29)
MediaWiki 1.39+
PHP 7.4+
Composer octfx/wiki-seo
Лицензия GNU General Public License 2.0 или позднее
Скачать
  • $wgWikiSeoSocialImageShowAuthor
  • $wgFacebookAdmins
  • $wgWikiSeoSocialImageShowLogo
  • $wgPinterestSiteVerificationKey
  • $wgMetadataGenerators
  • $wgGoogleSiteVerificationKey
  • $wgFacebookAppId
  • $wgWikiSeoSocialImageHeight
  • $wgBingSiteVerificationKey
  • $wgTwitterCardType
  • $wgYandexSiteVerificationKey
  • $wgWikiSeoEnableSocialImages
  • $wgWikiSeoTryCleanAutoDescription
  • $wgWikiSeoDefaultImage
  • $wgNortonSiteVerificationKey
  • $wgTwitterSiteHandle
  • $wgWikiSeoSocialImageBackgroundColor
  • $wgWikiSeoDefaultLanguage
  • $wgWikiSeoSocialImageWidth
  • $wgWikiSeoOverwritePageImage
  • $wgNaverSiteVerificationKey
  • $wgWikiSeoSocialImageIcon
  • $wgWikiSeoEnableAutoDescription
  • $wgWikiSeoDisableLogoFallbackImage
  • $wgWikiSeoNoindexPageTitles
  • $wgWikiSeoSocialImageTextColor
Ежеквартальные загрузки 112 (Ranked 47th)
Переведите расширение WikiSEO, если оно доступно на translatewiki.net
Проблемы Открытые задачи · Сообщить об ошибке

The WikiSEO extension allows you to replace, append or prepend the HTML title tag content. It also allows you to add common SEO (Search Engine Optimisation) meta elements such as "keywords" and "description".

A working job queue is absolutely required for this extension to function.

Установка

  • Скачайте и распакуйте файл(ы) в папку с названием WikiSEO в вашей папке extensions/.
    Вместо этого разработчикам и соавторам кода следует установить расширение из Git, используя:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiSEO
  • Добавьте следующий код в конце вашего файла LocalSettings.php :
    wfLoadExtension( 'WikiSEO' );
    
  • Configure as required.
  •   Готово – Перейдите на страницу Special:Version на своей вики, чтобы удостовериться в том, что расширение успешно установлено.

Использование

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

Параметры, поддерживаемые всеми генераторами

Имя По умолчанию Описание Пример
title (empty) The title you want to appear in the html title tag. Will also be used for OpenGraph, Schema.org and Twitter metadata.
{{#seo:|title=This is the title of the page}}
title_mode replace Set to append, prepend, or replace (default) to define how the title will be amended. Further examples can be found here.
{{#seo:|title=This replaces the Title of the Page|title_mode=replace}}
title_separator - The separator in case title_mode was set to append or prepend.
{{#seo:|title=This gets prepended to the page name separated by the separator|title_mode=prepend|title_separator=<<}}
keywords (empty) Разделённый запятыми список ключевых слов, описывающих содержимое страницы. Также будет использоваться для метаданных OpenGraph, Schema.org и Twitter.
{{#seo:|keywords=Apple, Pears, Oranges}}
description (empty) Краткий текст, описывающий тему страницы. Также будет использоваться для метаданных OpenGraph, Schema.org и Twitter.
{{#seo:|description=This page contains information about...}}

Параметры, поддерживаемые генератором мета-тегов

Имя По умолчанию Описание Пример
robots (empty) Controls the behaviour of search engine crawling and indexing
{{#seo:|robots=noindex, nofollow}}
googlebot (empty) Controls the behaviour of the google crawler
{{#seo:|googlebot=noindex, nofollow}}
hreflang_xx-xx (empty) Добавляет элементы <link rel="alternate" href="url" hreflang="xx-xx">
{{#seo:|hreflang_de-de=https://example.com}}

Parameters supported by OpenGraph / Twitter generator

Имя По умолчанию Описание Пример
type (empty) Тип вашего объекта, например, "video.movie". Depending on the type you specify, other properties may also be required.
{{#seo:|type=website}}
image (empty) 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.
{{#seo:|image=Local_File.png}}
image_width (empty) Ширина изображения в px. (Automatically set if an image name is set in image)
{{#seo:|image_width=420}}
image_height (empty) The image height in px. (Automatically set if an image name is set in image)
{{#seo:|image_height=69}}
image_alt (empty) Краткое предложение, описывающее изображение
{{#seo:|image_alt=A picture showing an orange cat.}}
locale (empty) The locale these tags are marked up in. Of the format language_TERRITORY.
{{#seo:|locale=en-US}}
site_name (empty) If your object is part of a larger web site, the name which should be displayed for the overall site. e.g., "IMDb".
{{#seo:|site_name=WMF}}

Parameters with type=article supported by OpenGraph generator

См. type=article.[1]

Имя По умолчанию Описание Пример
author (empty) Writers of the article.
{{#seo:|author=Jon Doe}}
section (empty) A high-level section name. E.g. Technology
{{#seo:|section=Technology}}
published_time (empty) When the article was first published. ISO 8601 Format.
{{#seo:|published_time=2012-01-25}}

Параметры, поддерживаемые генератором Twitter

See OpenGraph Tags.[2]

Имя По умолчанию Описание Пример
twitter_site (empty) 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.
{{#seo:|twitter_site=MediaWiki}}

Parameters supported by Citation generator

См. Schema.org.[3]

Имя По умолчанию Описание Пример
citation_type ScholarlyArticle Used in @graph @type
{{#seo:|citation_type=MedicalScholarlyArticle}}
citation_name (empty) Name of the Publication
{{#seo:|citation_name=Cataloging & Classification Quarterly}}
citation_headline (empty) Headline of the article.
{{#seo:|citation_headline=Works in Cataloging}}
citation_date_published (empty) Date of first broadcast/publication.
{{#seo:|citation_date_published=2012-01-01}}
citation_date_created (empty) The date on which the CreativeWork was created or the item was added to a DataFeed.
{{#seo:|citation_date_created=2012-01-01}}
citation_page_start (empty) The page on which the work starts; for example "135" or "xiii".
{{#seo:|citation_page_start=135}}
citation_doi (empty) URL of a reference Web page that unambiguously indicates the item's identity. E.g. the URL of the item's Wikipedia page, Wikidata entry, or official website.
{{#seo:|citation_doi=http://dx.doi.org/10.1038/nphys1170}}
citation_author (empty) One or more authors separated by ';'
{{#seo:|citation_author=Doe, John; Bar, Foo}}
citation_publisher (empty) Name of the publisher
{{#seo:|citation_journal_title=Elsevir}}
citation_license (empty) A license document that applies to this content, typically indicated by URL.
{{#seo:|citation_license=link}}
citation_volume (empty) Volume number
{{#seo:|citation_volume=50}}
keywords (empty) Article Keywords (*)
{{#seo:|citation_keywords=Keyword a; Keyword b; ...}}
description (empty) A description of the item (*)
{{#seo:|description=An article about cataloging}}

(*) these parameters are supported by all generators.

Do note that the Citation generator is not activated by default! To activate the generator add the following snippet to LocalSettings.php:

$wgMetadataGenerators[] = "Citation";

Примеры

Добавление статических значений

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

Добавление динамических значений

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}}
 |title_mode={{{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
}}

Использование в модулях Lua

-- 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|set|title=ExampleTitle|keywords=WikiSEO, SEO, MediaWiki}} or {{#invoke:SEO|setStatic}}.

Атрибуты hreflang

{{#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

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 (изменён разделитель)

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

HTML Title result: Prepended Title >> Example Page

Replace (по умолчанию)

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

HTML Title result: Replaced Title

Скрипт обслуживания

WikiSEO provides a maintenance script to generate descriptions for specified pages. This script requires Расширение:TextExtracts to be installed and active. The script will only generate descriptions for pages that don't have a description property set in the page properties table.

You can force the generation using the --force flag, this will overwrite any description already present.

A list of namespace ids needs to be given in order for the script to work:

# Запустить только в основном пространстве имён
php maintenance/GenerateDescription.php 0

# Запустить только в основном пространстве имён и перезаписать существующие описания
php maintenance/GenerateDescription.php --force 0

# Run in namespace 1234, overwrite descriptions and remove dangling sentences
php maintenance/GenerateDescription.php --force --cleanSentence 1234

Настройка

В этом расширении используются следующие переменные.

Site / App Keys
Переменная Описание Использование
$wgGoogleSiteVerificationKey Установка этой переменной добавит тег <meta name="google-site-verification" content="CODE"> на каждую страницу. $wgGoogleSiteVerificationKey = 'CODE';
$wgBingSiteVerificationKey Установка этой переменной добавит тег <meta name="msvalidate.01" content="CODE"> на каждую страницу. $wgBingSiteVerificationKey= 'CODE';
$wgFacebookAppID Установка этой переменной добавит тег <meta property="fb:app_id" content="ID"> на каждую страницу. $wgFacebookAppID= 'App_ID';
$wgFacebookAdmins Установка этой переменной добавит тег <meta property="fb:admins" content="ID1,ID2,..."> на каждую страницу. $wgFacebookAdmins= 'ID1,ID2,...';
$wgYandexSiteVerificationKey Установка этой переменной добавит тег <meta name="yandex-verification" content="CODE"> на каждую страницу. $wgYandexSiteVerificationKey= 'CODE';
$wgAlexaSiteVerificationKey Установка этой переменной добавит тег <meta name="alexaVerifyID" content="CODE"> на каждую страницу. $wgAlexaSiteVerificationKey= 'CODE';
$wgPinterestSiteVerificationKey Установка этой переменной добавит тег <meta name="p:domain_verify" content="CODE"> на каждую страницу. $wgPinterestSiteVerificationKey= 'CODE';
$wgNortonSiteVerificationKey Установка этой переменной добавит тег <meta name="norton-safeweb-site-verification" content="CODE"> на каждую страницу. $wgNortonSiteVerificationKey= 'CODE';
$wgNaverSiteVerificationKey Установка этой переменной добавит тег <meta name="naver-site-verification" content="CODE"> на каждую страницу. $wgNaverSiteVerificationKey = 'CODE';

$wgWikiSeoDefaultImage

Set a default image to use if no image is set on the site. If this variable is not set the site's logo will be used.

Использование: $wgWikiSeoDefaultImage= 'Localfile.jpg';

$wgMetadataGenerators

Array containing the metadata generator names to load.

По умолчанию: ["OpenGraph", "Twitter", "SchemaOrg"]

If you only want to change the page title and add 'description', 'keywords', 'robots' tags set $wgMetadataGenerators = [];

$wgWikiSeoDisableLogoFallbackImage

Disable setting $wgLogo as a fallback image if no image for a page was set.

$wgTwitterCardType

Defaults to `summary_large_image` for the twitter card type.

Использование: $wgTwitterCardType = 'summary';

$wgWikiSeoNoindexPageTitles

An array of page titles where a 'noindex' robot tag should be added. Использование: $wgWikiSeoNoindexPageTitles = [ 'Custom_Title', 'Main_Page' ];

$wgWikiSeoDefaultLanguage

A default language code with area to generate a <link rel="alternate" href="current Url" hreflang="xx-xx"> for.

Использование: $wgWikiSeoDefaultLanguage = 'de-de';

$wgWikiSeoEnableAutoDescription

If no description was given in the parser function, a short description from Расширение:TextExtracts will be requested. A description will only be set, if the page is edited and saved. Alternatively the maintenance script GenerateDescription can be run from the extension folder.

$wgWikiSeoTryCleanAutoDescription

Tries to remove dangling sentences from the description provided by TextExtracts. This will remove the last sentence not ending in a '.', and will result in descriptions shorter than 160 characters.

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 Цвет фона по умолчанию, если изображение страницы не найдено $wgWikiSeoSocialImageBackgroundColor = '#ff00ff';

Migrating from v1.2.2 to to v2.x

Удалённые теги

  • 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

Изменённые названия аргументов

  • 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

Известные проблемы

Расширение:PageImages will add an og:image tag if an image is found on the page. If another image was set using WikiSEO, both og:image will be added to the page.

Дополнительная информация:

Setting $wgPageImagesOpenGraph = false; disables PageImages setting any og:image* meta tags.

Additionally you can set $wgWikiSeoOverwritePageImage = true; to overwrite the image set by PageImages with the one specified by WikiSEO.

Further details

This extension is not a drop-in replacement for the previous version of this extension from tinymighty/wiki-seo.

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 Руководство:$wgAllowDisplayTitle and Руководство:$wgRestrictDisplayTitle settings.

Note that this extension stores relevant properties in the page_props table. Its parser hook persists previous properties when invoked since commit 78245b3 (released in v2.6.6). This enables administrators to set these properties manually with other tools like Extension:PageProperties . On the other hand removed parameters from parser function call will persist in the page. These outdated properties can be purged by temporarily removing the magic words or disabling the extension, then reparsing the page.

schema.org

The SchemaOrg generator will set a SearchAction property based on Special:Search.[4]

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.

Интеграция

WikiSEO will use descriptions provided by Расширение:Description2 .

Примечания

См. также