├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .gitmodules
├── .gitreview
├── .phpcs.xml
├── .scrutinizer.yml
├── COPYING
├── DefaultSettings.php
├── Makefile
├── README.md
├── RELEASE-NOTES.md
├── SemanticMetaTags.php
├── codecov.yml
├── composer.json
├── docs
├── ISSUE_TEMPLATE.md
├── PULL_REQUEST_TEMPLATE.md
└── README.md
├── extension.json
├── i18n
├── ar.json
├── ast.json
├── be-tarask.json
├── bg.json
├── br.json
├── ca.json
├── cs.json
├── de.json
├── diq.json
├── en.json
├── es.json
├── fr.json
├── gl.json
├── he.json
├── ia.json
├── it.json
├── ko.json
├── mk.json
├── nb.json
├── nl.json
├── pl.json
├── pt-br.json
├── pt.json
├── qqq.json
├── roa-tara.json
├── ru.json
├── sl.json
├── sr-ec.json
├── sr-el.json
├── th.json
├── tr.json
├── uk.json
├── zh-hans.json
└── zh-hant.json
├── phpmd.xml
├── phpunit.xml.dist
├── src
├── HookRegistry.php
├── JsonLDSerializer.php
├── LazySemanticDataLookup.php
├── MetaTagsProcessor.php
├── Options.php
├── OutputPageHtmlTagsInserter.php
└── PropertyValuesContentAggregator.php
└── tests
├── bootstrap.php
├── phpunit
├── Integration
│ ├── I18nJsonFileIntegrityTest.php
│ └── MetaTagsContentGenerationIntegrationTest.php
└── Unit
│ ├── HookRegistryTest.php
│ ├── LazySemanticDataLookupTest.php
│ ├── MetaTagsProcessorTest.php
│ ├── OptionsTest.php
│ ├── OutputPageHtmlTagsInserterTest.php
│ └── PropertyValuesContentAggregatorTest.php
└── travis
├── install-mediawiki.sh
├── install-semantic-meta-tags.sh
├── run-tests.sh
└── upload-coverage-report.sh
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 | workflow_dispatch:
9 |
10 | jobs:
11 |
12 | test:
13 |
14 | runs-on: ubuntu-latest
15 | continue-on-error: ${{ matrix.experimental }}
16 |
17 | strategy:
18 | matrix:
19 | include:
20 | - mediawiki_version: '1.39'
21 | smw_version: dev-master
22 | php_version: 8.1
23 | database_type: mysql
24 | database_image: "mariadb:10"
25 | coverage: false
26 | experimental: false
27 | - mediawiki_version: '1.40'
28 | smw_version: dev-master
29 | php_version: 8.1
30 | database_type: mysql
31 | database_image: "mariadb:11.2"
32 | coverage: true
33 | experimental: false
34 | - mediawiki_version: '1.41'
35 | smw_version: dev-master
36 | php_version: 8.1
37 | database_type: mysql
38 | database_image: "mariadb:11.2"
39 | coverage: false
40 | experimental: false
41 | - mediawiki_version: '1.42'
42 | smw_version: dev-master
43 | php_version: 8.1
44 | database_type: mysql
45 | database_image: "mariadb:11.2"
46 | coverage: false
47 | experimental: false
48 | - mediawiki_version: '1.43'
49 | smw_version: dev-master
50 | php_version: 8.1
51 | database_type: mysql
52 | database_image: "mariadb:11.2"
53 | coverage: false
54 | experimental: false
55 |
56 | env:
57 | MW_VERSION: ${{ matrix.mediawiki_version }}
58 | SMW_VERSION: ${{ matrix.smw_version }}
59 | PHP_VERSION: ${{ matrix.php_version }}
60 | DB_TYPE: ${{ matrix.database_type }}
61 | DB_IMAGE: ${{ matrix.database_image }}
62 |
63 | steps:
64 | - name: Checkout
65 | uses: actions/checkout@v4
66 | with:
67 | submodules: recursive
68 |
69 | - name: Update submodules
70 | run: git submodule update --init --remote
71 |
72 | - name: Run tests
73 | run: make ci
74 | if: matrix.coverage == false
75 |
76 | - name: Run tests with coverage
77 | run: make ci-coverage
78 | if: matrix.coverage == true
79 |
80 | - name: Upload code coverage
81 | uses: codecov/codecov-action@v4
82 | with:
83 | token: ${{ secrets.CODECOV_TOKEN }}
84 | files: coverage/php/coverage.xml
85 | if: matrix.coverage == true
86 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.kate-swp
3 |
4 | vendor/
5 | extensions/
6 |
7 | composer.phar
8 | composer.lock
9 |
10 | !.*
11 | .idea/
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "build"]
2 | path = build
3 | url = https://github.com/gesinn-it-pub/docker-compose-ci.git
4 |
--------------------------------------------------------------------------------
/.gitreview:
--------------------------------------------------------------------------------
1 | [gerrit]
2 | host=gerrit.wikimedia.org
3 | port=29418
4 | project=mediawiki/extensions/SemanticMetaTags.git
5 | defaultbranch=master
6 |
--------------------------------------------------------------------------------
/.phpcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 0
40 |
41 | .
42 | /(vendor|conf)/
43 | extensions/*
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/.scrutinizer.yml:
--------------------------------------------------------------------------------
1 | filter:
2 | excluded_paths:
3 | - 'vendor/*'
4 |
5 | tools:
6 | php_mess_detector:
7 | config:
8 | controversial_rules: { superglobals: false }
9 | php_cpd: true
10 | php_pdepend: true
11 | php_code_coverage: false
12 | php_code_sniffer: true
13 | php_cs_fixer: true
14 | php_loc: true
15 | php_analyzer: true
16 | sensiolabs_security_checker: true
17 | external_code_coverage:
18 | timeout: '900'
19 |
20 | checks:
21 | php:
22 | code_rating: true
23 | duplication: true
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | '''[https://github.com/SemanticMediaWiki/SemanticMetaTags Semantic Meta Tags (SMT)]''' is a free, open-source extension to Semantic MediaWiki to enhance the meta tags of an article with content generated from semantic annotations.
2 |
3 | Copyright (C) 2015
4 |
5 | The license text below "====" applies to all files within this distribution, other than those that are in a directory which contains files named "LICENSE" or "COPYING", or a subdirectory thereof. For those files, the license text contained in said file overrides any license information contained in directories of smaller depth. Alternative licenses are typically used for software that is provided by external parties, and merely packaged with this extension for convenience.
6 | ----
7 | ----
8 |
9 | == GNU GENERAL PUBLIC LICENSE ==
10 | Version 2, June 1991
11 |
12 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
13 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14 |
15 | Everyone is permitted to copy and distribute verbatim copies
16 | of this license document, but changing it is not allowed.
17 |
18 | === Preamble ===
19 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software - to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
22 |
23 | To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
24 |
25 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
26 |
27 | We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
28 |
29 | Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original
30 | authors' reputations.
31 |
32 | Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
33 |
34 | The precise terms and conditions for copying, distribution and modification follow.
35 |
36 | === TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION ===
37 |
38 | '''0.''' This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
39 |
40 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
41 |
42 | '''1.''' You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
43 |
44 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
45 |
46 | '''2.''' You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
47 |
48 | : '''a)''' You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
49 |
50 | : '''b)''' You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
51 |
52 | : '''c)''' If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
53 |
54 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
55 |
56 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
57 |
58 | In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
59 |
60 | '''3.''' You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
61 |
62 | : '''a)''' Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
63 |
64 | : '''b)''' Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
65 |
66 | : '''c)''' Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
67 |
68 | The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
69 |
70 | If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
71 |
72 | '''4.''' You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
73 |
74 | '''5.''' You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
75 |
76 | '''6.''' Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
77 |
78 | '''7.''' If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
79 |
80 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
81 |
82 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing
83 | to distribute software through any other system and a licensee cannot impose that choice.
84 |
85 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
86 |
87 | '''8.''' If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
88 |
89 | '''9.''' The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
90 |
91 | Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
92 |
93 | '''10.''' If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
94 |
95 | '''NO WARRANTY'''
96 |
97 | '''11.''' BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
98 |
99 | '''12.''' IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
100 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
101 |
102 | '''END OF TERMS AND CONDITIONS'''
103 |
--------------------------------------------------------------------------------
/DefaultSettings.php:
--------------------------------------------------------------------------------
1 | array( 'Has keywords', ... )
19 | */
20 | $GLOBALS['smtgTagsProperties'] = $GLOBALS['smtgTagsProperties'] ?? [];
21 |
22 | /**
23 | * Describes static content for an assigned `` tag
24 | *
25 | * 'some:tag' => 'Content that is static'
26 | */
27 | $GLOBALS['smtgTagsStrings'] = $GLOBALS['smtgTagsStrings'] ?? [];
28 |
29 | /**
30 | * Listed tags are generally assumed to be reserved or excluded for free use
31 | */
32 | $GLOBALS['smtgTagsBlacklist'] = $GLOBALS['smtgTagsBlacklist'] ?? [
33 | 'generator',
34 | 'robots'
35 | ];
36 |
37 | /**
38 | * In case it is set `true` then the first property that returns a valid content
39 | * for an assigned tag will be used exclusively.
40 | */
41 | $GLOBALS['smtgTagsPropertyFallbackUsage'] = $GLOBALS['smtgTagsPropertyFallbackUsage'] ?? false;
42 |
43 | /**
44 | * Identifies prefixes that require `meta:property:...`
45 | */
46 | $GLOBALS['smtgMetaPropertyPrefixes'] = $GLOBALS['smtgMetaPropertyPrefixes'] ?? [ 'og:' ];
47 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | -include .env
2 | export
3 |
4 | # setup for docker-compose-ci build directory
5 | # delete "build" directory to update docker-compose-ci
6 |
7 | ifeq (,$(wildcard ./build/))
8 | $(shell git submodule update --init --remote)
9 | endif
10 |
11 | EXTENSION=SemanticMetaTags
12 |
13 | # docker images
14 | MW_VERSION?=1.39
15 | PHP_VERSION?=8.1
16 | DB_TYPE?=mysql
17 | DB_IMAGE?="mariadb:10"
18 |
19 | # extensions
20 | SMW_VERSION?=dev-master
21 |
22 | # composer
23 | # Enables "composer update" inside of extension
24 | COMPOSER_EXT?=true
25 |
26 | # nodejs
27 | # Enables node.js related tests and "npm install"
28 | # NODE_JS?=true
29 |
30 | # check for build dir and git submodule init if it does not exist
31 | include build/Makefile
32 |
33 |
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Semantic Meta Tags
2 |
3 | [](http://travis-ci.org/SemanticMediaWiki/SemanticMetaTags)
4 | [](https://codecov.io/gh/SemanticMediaWiki/SemanticMetaTags)
5 | [](https://packagist.org/packages/mediawiki/semantic-meta-tags)
6 | [](https://packagist.org/packages/mediawiki/semantic-meta-tags)
7 |
8 | Semantic Meta Tags (a.k.a. SMT) is a [Semantic Mediawiki][smw] extension to enhance
9 | the meta element of a page with content generated from semantic annotations.
10 |
11 | This extension enables to automatically extend the HTML `` elements of a page
12 | with content generated from selected properties to create:
13 |
14 | - Standard meta elements (e.g `meta name="keywords"`) as well as
15 | - [Summary card][tw] and [Open Graph][opg] protocol tags (e.g `meta property="og:title"`)
16 |
17 | ## Requirements
18 |
19 | - PHP 7.1 or later
20 | - MediaWiki 1.31 or later
21 | - [Semantic MediaWiki][smw] 3.1 or later
22 |
23 | ## Installation
24 |
25 | The recommended way to install Semantic Meta Tags is using [Composer](http://getcomposer.org) with
26 | [MediaWiki's built-in support for Composer](https://www.mediawiki.org/wiki/Composer).
27 |
28 | Note that the required extension Semantic MediaWiki must be installed first according to the installation
29 | instructions provided for it.
30 |
31 | ### Step 1
32 |
33 | Change to the base directory of your MediaWiki installation. If you do not have a "composer.local.json" file yet,
34 | create one and add the following content to it:
35 |
36 | ```
37 | {
38 | "require": {
39 | "mediawiki/semantic-meta-tags": "~3.1"
40 | }
41 | }
42 | ```
43 |
44 | If you already have a "composer.local.json" file add the following line to the end of the "require"
45 | section in your file:
46 |
47 | "mediawiki/semantic-meta-tags": "~3.1"
48 |
49 | Remember to add a comma to the end of the preceding line in this section.
50 |
51 | ### Step 2
52 |
53 | Run the following command in your shell:
54 |
55 | php composer.phar update --no-dev
56 |
57 | Note if you have Git installed on your system add the `--prefer-source` flag to the above command.
58 |
59 | ### Step 3
60 |
61 | Add the following line to the end of your "LocalSettings.php" file:
62 |
63 | wfLoadExtension( 'SemanticMetaTags' );
64 |
65 | ## Documentation
66 |
67 | This [document](docs/README.md) describes features as well as necessary settings.
68 |
69 | ## Contribution and support
70 |
71 | If you want to contribute work to the project please subscribe to the developers mailing list and
72 | have a look at the contribution guideline.
73 |
74 | * [File an issue](https://github.com/SemanticMediaWiki/SemanticMetaTags/issues)
75 | * [Submit a pull request](https://github.com/SemanticMediaWiki/SemanticMetaTags/pulls)
76 | * Ask a question on [the mailing list](https://www.semantic-mediawiki.org/wiki/Mailing_list)
77 |
78 | ## Tests
79 |
80 | This extension provides unit and integration tests that are run by a [continues integration platform][travis]
81 | but can also be executed using `composer phpunit` from the extension base directory.
82 |
83 | ## License
84 |
85 | [GNU General Public License, version 2 or later][gpl-licence].
86 |
87 | [smw]: https://github.com/SemanticMediaWiki/SemanticMediaWiki
88 | [contributors]: https://github.com/SemanticMediaWiki/SemanticMetaTags/graphs/contributors
89 | [travis]: https://travis-ci.org/SemanticMediaWiki/SemanticMetaTags
90 | [gpl-licence]: https://www.gnu.org/copyleft/gpl.html
91 | [composer]: https://getcomposer.org/
92 | [opg]: http://ogp.me/
93 | [tw]: https://dev.twitter.com/cards/types/summary
94 |
--------------------------------------------------------------------------------
/RELEASE-NOTES.md:
--------------------------------------------------------------------------------
1 | This file contains the RELEASE-NOTES of the **Semantic Meta Tags** (a.k.a. SMT) extension.
2 |
3 | ### 4.0.0
4 |
5 | Not released yet
6 |
7 | * Minimum requirement for
8 | * MediaWiki changed to version 1.39 and later
9 | * Semantic MediaWiki changed to version 4 and later
10 |
11 | ### 3.1.0
12 |
13 | Released on March 20, 2024
14 |
15 | * Allows installing this extension with Semantic MediaWiki 4.0 and later
16 | * Localization updates from https://translatewiki.net
17 |
18 |
19 | ### 3.0.0
20 |
21 | Released on September 26, 2020.
22 |
23 | * Minimum requirement for
24 | * PHP changed to version 7.1 and later
25 | * MediaWiki changed to version 1.31 and later
26 | * Semantic MediaWiki changed to version 3.1 and later
27 | * [#61](https://github.com/SemanticMediaWiki/SemanticMetaTags/issues/61) Adds support for fallback strings to be used if no annotation is present
28 | * Localization updates from https://translatewiki.net
29 |
30 | ### 2.0.0
31 |
32 | Released on January 29, 2019.
33 |
34 | * Minimum requirement for Semantic MediaWiki changed to version 3.0 and later
35 | * #39 Adds support for extension registration via "extension.json"
36 | → Now you have to use `wfLoadExtension( 'SemanticMetaTags' );` in the "LocalSettings.php" file to invoke the extension
37 | * Localization updates from https://translatewiki.net
38 |
39 | ### 1.5.0
40 |
41 | Released on October 9, 2018.
42 |
43 | * Minimum requirement for
44 | * PHP changed to version 5.6 and later
45 | * Semantic MediaWiki changed to version 2.5 and later
46 | * Minor clean-up
47 | * Localization updates from https://translatewiki.net
48 |
49 | ### 1.4.0
50 |
51 | Released on June 7, 2017.
52 |
53 | * Minimum requirement for
54 | * PHP changed to version 5.5 and later
55 | * MediaWiki changed to version 1.27 and later
56 | * Semantic MediaWiki changed to version 2.4 and later
57 | * `$smtgMetaPropertyPrefixes` to set which prefixes to meta elements should result in rendering as properties rather than names
58 | * Localization updates from https://translatewiki.net
59 |
60 | ### 1.3.0
61 |
62 | Released on July 9, 2016.
63 |
64 | * Minor clean-up
65 | * Localization updates from https://translatewiki.net
66 |
67 | ### 1.2.0
68 |
69 | Released on December 19, 2015.
70 |
71 | * Minimum requirement for Semantic MediaWiki changed to version 2.2 and later
72 | * Minor clean-up
73 | * Changed value aggregation so that DI values for the same property only appear once
74 | * Localization updates from https://translatewiki.net
75 |
76 | ### 1.1.0
77 |
78 | Released on June 2, 2015.
79 |
80 | * Minor clean-up
81 | * Localization updates from https://translatewiki.net
82 |
83 | ### 1.0.0
84 |
85 | Released on February 28, 2015.
86 |
87 | * Initial release
88 | * Requires PHP 5.3 or later
89 | * Requires MediaWiki 1.23 or later
90 | * Requires Semantic MediaWiki 2.1 or later
91 | * `$smtgTagsProperties` to set which meta elements should be enabled
92 | * `$smtgTagsPropertyFallbackUsage` to set whether the first property that returns
93 | a valid content for an assigned meta element will be used exclusively
94 | * `$smtgTagsStrings` to describe static content for an assigned meta element
95 | * `$smtgTagsBlacklist` to generally disable certain meta elements for free assignments
96 |
--------------------------------------------------------------------------------
/SemanticMetaTags.php:
--------------------------------------------------------------------------------
1 | Error: This version of SemanticMetaTags is only compatible with MediaWiki 1.27 or above. You need to upgrade MediaWiki first.' );
57 | }
58 | }
59 |
60 | /**
61 | * @since 1.0
62 | */
63 | public static function onExtensionFunction() {
64 | if ( !defined( 'SMW_VERSION' ) ) {
65 |
66 | if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
67 | die( "\nThe 'Semantic Meta Tags' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
68 | } else {
69 | die(
70 | 'Error: The Semantic Meta Tags ' .
71 | 'extension requires Semantic MediaWiki to be ' .
72 | 'installed and enabled.
'
73 | );
74 | }
75 | }
76 |
77 | $configuration = [
78 | 'metaTagsContentPropertySelector' => $GLOBALS['smtgTagsProperties'],
79 | 'metaTagsStaticContentDescriptor' => $GLOBALS['smtgTagsStrings'],
80 | 'metaTagsBlacklist' => $GLOBALS['smtgTagsBlacklist'],
81 | 'metaTagsFallbackUseForMultipleProperties' => $GLOBALS['smtgTagsPropertyFallbackUsage'],
82 | 'metaTagsMetaPropertyPrefixes' => $GLOBALS['smtgMetaPropertyPrefixes']
83 | ];
84 |
85 | $hookRegistry = new HookRegistry(
86 | ApplicationFactory::getInstance()->getStore(),
87 | new Options( $configuration )
88 | );
89 |
90 | $hookRegistry->register();
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | fixes:
2 | - "/var/www/html/extensions/SemanticMetaTags/::"
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mediawiki/semantic-meta-tags",
3 | "type": "mediawiki-extension",
4 | "description": "An extension to Semantic Mediawiki to add meta elements with content generated from semantic annotations.",
5 | "keywords": [
6 | "smw",
7 | "semantic mediawiki",
8 | "wiki",
9 | "mediawiki",
10 | "meta tags",
11 | "meta elements"
12 | ],
13 | "homepage": "https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Meta_Tags",
14 | "license": "GPL-2.0-or-later",
15 | "authors": [
16 | {
17 | "name": "James Hong Kong",
18 | "homepage": "https://www.semantic-mediawiki.org/wiki/User:MWJames",
19 | "role": "Developer"
20 | }
21 | ],
22 | "support": {
23 | "email": "semediawiki-user@lists.sourceforge.net",
24 | "issues": "https://github.com/SemanticMediaWiki/SemanticMetaTags/issues",
25 | "forum": "https://www.semantic-mediawiki.org/wiki/semantic-mediawiki.org_talk:Community_portal",
26 | "wiki": "https://www.semantic-mediawiki.org/wiki/",
27 | "source": "https://github.com/SemanticMediaWiki/SemanticMetaTags"
28 | },
29 | "require": {
30 | "php": ">=7.4",
31 | "composer/installers": ">=1.0.1",
32 | "easyrdf/easyrdf": "~1.1",
33 | "ml/json-ld": "^1.2"
34 | },
35 | "require-dev": {
36 | "mediawiki/mediawiki-codesniffer": "43.0.0",
37 | "mediawiki/minus-x": "1.1.3",
38 | "php-parallel-lint/php-console-highlighter": "1.0.0",
39 | "php-parallel-lint/php-parallel-lint": "1.4.0"
40 | },
41 | "extra": {
42 | "branch-alias": {
43 | "dev-master": "4.x-dev"
44 | }
45 | },
46 | "config": {
47 | "process-timeout": 0,
48 | "allow-plugins": {
49 | "composer/installers": true,
50 | "dealerdirect/phpcodesniffer-composer-installer": true
51 | }
52 | },
53 | "scripts":{
54 | "test": [
55 | "@analyze",
56 | "@phpunit"
57 | ],
58 | "test-coverage": [
59 | "@analyze",
60 | "@phpunit-coverage"
61 | ],
62 | "analyze": [
63 | "@lint",
64 | "@phpcs",
65 | "@minus-x"
66 | ],
67 | "phpunit": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist",
68 | "phpunit-coverage": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml",
69 | "post-test-coverage": [
70 | "sed -i 's|/var/www/html/extensions/SemanticMetaTags/||g' coverage/php/coverage.xml",
71 | "find coverage/php -type f -name '*.html' -exec sed -i 's|/var/www/html/extensions/||g' {} +"
72 | ],
73 | "phpcs": "phpcs -ps -d memory_limit=2G",
74 | "phpcs-fix": "phpcbf -p",
75 | "lint": "parallel-lint . --exclude vendor --exclude node_modules --exclude extensions",
76 | "minus-x": "minus-x check ."
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/docs/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Setup and configuration
2 |
3 | - SMW version:
4 | - SMT version:
5 | - MW version:
6 | - DB (MySQL etc.):
7 |
8 | ### Issue
9 |
10 | Produces a [stack trace](https://www.semantic-mediawiki.org/wiki/Help:Identifying_bugs) and outputs:
11 |
12 | ```
13 | ```
14 |
15 | Steps to reproduce the observation (recommendation is to use the [sandbox](https://sandbox.semantic-mediawiki.org)):
16 |
--------------------------------------------------------------------------------
/docs/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | This PR is made in reference to: #
2 |
3 | This PR addresses or contains:
4 | - ...
5 | - ...
6 | - ...
7 |
8 | This PR includes:
9 | - [ ] Tests (unit/integration)
10 | - [ ] CI build passed
11 |
12 | Fixes #
13 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | ## Usage
2 |
3 | 
4 |
5 | In order to generate customized `` tags, property assignments have
6 | to be added to `$GLOBALS['smtgTagsProperties']` (no assigments = no additional
7 | `` tags).
8 |
9 | `` tags are mapped (by name) to properties. In case you want to generate
10 | multiple values from different properties to the same `` tag then separate
11 | those property assigments by comma.
12 |
13 | If a tag contains a `og:` it is identified as an [Open Graph][opg] `` tag
14 | and annotated using the `meta property=""` description.
15 |
16 | ## Configuration
17 |
18 | * `$GLOBALS['smtgTagsProperties']` array of "tag => property" or "tag => callback"
19 | assignments. If a given property has multiple values (including subobjects)
20 | on a wiki page, the values are concatenated into a single string separated
21 | by commas.
22 | * callback is a function that ought to have the following signature:
23 | `function( OutputPage $outputPage ): string`. This is the place to assign
24 | MediaWiki system messages, page properties like its title or plain strings to tags
25 | * `$GLOBALS['smtgTagsPropertyFallbackUsage']` in case it is set `true` then the
26 | first property that returns a valid content for an assigned tag will be used
27 | exclusively.
28 | * `$GLOBALS['smtgTagsStrings']` can be used to describe static content for an
29 | assigned `` tag.
30 | * Tags specified in `$GLOBALS['smtgTagsBlacklist']` are generally disabled for
31 | free assignments.
32 | * `$GLOBALS['smtgMetaPropertyPrefixes']` to set which prefixes to meta elements
33 | should result in rendering as properties rather than names. For example, all
34 | Open Graph (Facebook) meta tags should render as properties.
35 |
36 | ### Example settings
37 |
38 | #### Simple settings
39 | Best for wikis using templates on all content pages
40 | ```php
41 | $GLOBALS['smtgTagsProperties'] = [
42 |
43 | // Standard meta tags
44 | 'keywords' => [
45 | 'Has keywords', 'Has another keyword'
46 | ],
47 | 'description' => 'Has some description',
48 | 'author' => 'Has last editor',
49 |
50 | // Summary card tag
51 | 'twitter:description' => 'Has some description',
52 |
53 | // Open Graph protocol supported tag
54 | 'og:title' => 'Has title'
55 | ];
56 |
57 | $GLOBALS['smtgTagsStrings'] = [
58 |
59 | // Static content tag
60 | 'some:tag' => 'Content that is static'
61 | ];
62 |
63 | $GLOBALS['smtgMetaPropertyPrefixes'] = [
64 |
65 | // Open Graph prefixes
66 | 'og:',
67 | 'fb:'
68 | ];
69 | ```
70 |
71 | #### Advanced settings
72 | Best for wikis not using templates on all content pages
73 | ```php
74 | $GLOBALS['smtgTagsProperties'] = [
75 |
76 | // Standard meta tags
77 | 'keywords' => [
78 | 'Has keywords',
79 | 'Has another keyword',
80 | function( OutputPage $outputPage ): string {
81 | // Redirects to the page are collected as keywords.
82 | $redirects = $outputPage->getContext()->getTitle()->getRedirectsHere();
83 | $redirect_titles = [];
84 | foreach ( $redirects as $redirect ) {
85 | $redirect_titles[] = $redirect->getText();
86 | }
87 | return implode( ', ', array_unique( $redirect_titles ));
88 | }
89 | ],
90 | 'description' => [
91 | 'Has some description',
92 | function( OutputPage $outputPage ): string {
93 | /**
94 | * This example generates a fallback description for a page:
95 | * - for the main page, the site name from the message "MediaWiki:Pagetitle-view-mainpage",
96 | * - for other pages, page title, followed by subtitle from "MediaWiki:Tagline".
97 | * The language specified, e.g. 'ru' should match the language of your wiki's language
98 | */
99 | global $wgLanguageCode;
100 | $title = $outputPage->getContext()->getTitle()->getText();
101 | $main_page = wfMessage( 'mainpage' )->inLanguage( $wgLanguageCode ?: 'ru' )->escaped();
102 | $site_name = wfMessage( 'pagetitle-view-mainpage' )->inLanguage( $wgLanguageCode ?: 'ru' )->escaped();
103 | $subtitle = $title !== $main_page ? wfMessage( 'tagline' )->inLanguage( $wgLanguageCode ?: 'ru' )->escaped() : '';
104 | return $title === $main_page ? $site_name : $title . '. ' . $subtitle;
105 | }],
106 | 'author' => 'Has last editor',
107 |
108 | // Summary card tag
109 | 'twitter:description' => 'Has some description',
110 |
111 | // Open Graph protocol supported tag
112 | 'og:title' => 'Has title'
113 | ];
114 |
115 | $GLOBALS['smtgTagsPropertyFallbackUsage'] = true;
116 |
117 | $GLOBALS['smtgTagsStrings'] = [
118 |
119 | // Static content tag
120 | 'some:tag' => 'Content that is static'
121 | ];
122 |
123 | $GLOBALS['smtgMetaPropertyPrefixes'] = [
124 |
125 | // Open Graph prefixes
126 | 'og:',
127 | 'fb:'
128 | ];
129 | ```
130 |
--------------------------------------------------------------------------------
/extension.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "SemanticMetaTags",
3 | "version": "4.0.0-beta",
4 | "author": [
5 | "James Hong Kong"
6 | ],
7 | "url": "https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Meta_Tags",
8 | "descriptionmsg": "smt-desc",
9 | "namemsg": "smt-name",
10 | "license-name": "GPL-2.0-or-later",
11 | "type": "semantic",
12 | "requires": {
13 | "MediaWiki": ">= 1.39",
14 | "extensions": {
15 | "SemanticMediaWiki": ">= 4.2.0"
16 | }
17 | },
18 | "MessagesDirs": {
19 | "SemanticMetaTags": [
20 | "i18n"
21 | ]
22 | },
23 | "callback": "SemanticMetaTags::initExtension",
24 | "ExtensionFunctions": [
25 | "SemanticMetaTags::onExtensionFunction"
26 | ],
27 | "AutoloadClasses": {
28 | "SemanticMetaTags": "SemanticMetaTags.php"
29 | },
30 | "AutoloadNamespaces": {
31 | "SMT\\": "src/"
32 | },
33 | "TestAutoloadNamespaces": {
34 | "SMT\\Tests\\": "tests/phpunit/Unit/",
35 | "SMT\\Tests\\Integration\\": "tests/phpunit/Integration/"
36 | },
37 | "load_composer_autoloader": true,
38 | "manifest_version": 2
39 | }
40 |
--------------------------------------------------------------------------------
/i18n/ar.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "ديفيد"
5 | ]
6 | },
7 | "smt-desc": "تسماح بتوفير علامات وصفية تم إنشاؤها من [https://www.semantic-mediawiki.org التعليقات التوضيحية الدلالية]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/ast.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Xuacu"
5 | ]
6 | },
7 | "smt-desc": "Permite ufrir metaetiquetes xeneraes dende [https://www.semantic-mediawiki.org anotaciones semántiques]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/be-tarask.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Red Winged Duck"
5 | ]
6 | },
7 | "smt-desc": "Дазваляе дадаць мэта-тэгі, атрыманыя з [https://www.semantic-mediawiki.org сэмантычных анатацыяў]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/bg.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "StanProg",
5 | "Vlad5250"
6 | ]
7 | },
8 | "smt-desc": "Предоставя възможност за мета тагове, генерирани от [https://www.semantic-mediawiki.org семантични анотации]"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/br.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": []
4 | },
5 | "smt-desc": "Aotren a ra pourchas metatikedennoù ganet diwar [https://www.semantic-mediawiki.org notennoù sterva]"
6 | }
7 |
--------------------------------------------------------------------------------
/i18n/ca.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Fitoschido",
5 | "Toniher"
6 | ]
7 | },
8 | "smt-desc": "Proporciona metaetiquetes generades a partir d’[https://www.semantic-mediawiki.org anotacions semàntiques]"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/cs.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Jaroslav Cerny"
5 | ]
6 | },
7 | "smt-desc": "Umožňuje poskytovat meta tagy generované ze [https://www.semantic-mediawiki.org sémantických anotací]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/de.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Metalhead64",
5 | "kghbln"
6 | ]
7 | },
8 | "smt-desc": "Ermöglicht das auf semantische Attribute gestützte Festlegen von Meta-Elementen"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/diq.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "1917 Ekim Devrimi"
5 | ]
6 | },
7 | "smt-desc": "Vıraziyaye [https://www.semantic-mediawiki.org Izahatê Semantiki ] etiketê meta rê mısade deyeno"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "mwjames",
5 | "kghbln"
6 | ]
7 | },
8 | "smt-desc": "Allows to provide meta tags generated from [https://www.semantic-mediawiki.org semantic annotations]",
9 | "smt-name": "Semantic Meta Tags"
10 | }
11 |
--------------------------------------------------------------------------------
/i18n/es.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "DannyS712",
5 | "Fitoschido",
6 | "Macofe"
7 | ]
8 | },
9 | "smt-desc": "Proporciona metaetiquetas generadas a partir de [https://www.semantic-mediawiki.org anotaciones semánticas]"
10 | }
11 |
--------------------------------------------------------------------------------
/i18n/fr.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Verdy p",
5 | "Wladek92"
6 | ]
7 | },
8 | "smt-desc": "Permet de fournir des méta-balises générées à partir des [https://semantic-mediawiki.org/ annotations sémantiques]"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/gl.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Toliño"
5 | ]
6 | },
7 | "smt-desc": "Permite proporcionar metaetiquetas xeradas a partir de [https://www.semantic-mediawiki.org anotacións semánticas]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/he.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Amire80"
5 | ]
6 | },
7 | "smt-desc": "אפשרות לספק מטא־תגים שנוצרו מ[https://www.semantic-mediawiki.org הערות סמנטיות]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/ia.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "McDutchie"
5 | ]
6 | },
7 | "smt-desc": "Permitte fornir meta-etiquettas generate a partir de [https://www.semantic-mediawiki.org annotationes semantic]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/it.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Beta16"
5 | ]
6 | },
7 | "smt-desc": "Consente di fornire i meta-tag generati da [https://www.semantic-mediawiki.org annotazioni semantiche]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/ko.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Suleiman the Magnificent Television",
5 | "Ykhwong"
6 | ]
7 | },
8 | "smt-desc": "[https://www.semantic-mediawiki.org semantic annotations]에서 생성된 메타 태그 제공을 허용합니다"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/mk.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Bjankuloski06"
5 | ]
6 | },
7 | "smt-desc": "Дава можност за метаознаки создадени од [https://www.semantic-mediawiki.org семантичките прибелешки]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/nb.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Jon Harald Søby"
5 | ]
6 | },
7 | "smt-desc": "Lar deg angi metatagger generert fra [https://www.semantic-mediawiki.org semantiske annoteringer]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/nl.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Rangekill",
5 | "Rcdeboer",
6 | "Xbaked potatox"
7 | ]
8 | },
9 | "smt-desc": "Toestaan om metatags aan te bieden die zijn gegenereerd op basis van [https://www.semantic-mediawiki.org semantische annotaties]"
10 | }
11 |
--------------------------------------------------------------------------------
/i18n/pl.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "SemanticPioneer"
5 | ]
6 | },
7 | "smt-desc": "Umożliwia dostarczenie metatagów wygenerowanych z [https://www.semantic-mediawiki.org adnotacji semantycznych]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/pt-br.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Jaideraf",
5 | "Tks4Fish"
6 | ]
7 | },
8 | "smt-desc": "Permite fornecer meta tags geradas a partir de [https://www.semantic-mediawiki.org marcações semânticas]"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/pt.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Hamilton Abreu",
5 | "Vitorvicentevalente"
6 | ]
7 | },
8 | "smt-desc": "Permite fornecer metaetiquetas geradas a partir de [https://semantic-mediawiki.org anotações semânticas]"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/qqq.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Kghbln",
5 | "Mwjames"
6 | ]
7 | },
8 | "smt-desc": "{{desc|name=Semantic Meta Tags|url=https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Meta_Tags}}\nAn extension providing HTML tags generated from semantic annotations.",
9 | "smt-name": "The name of this extension.\n{{Notranslate}}"
10 | }
11 |
--------------------------------------------------------------------------------
/i18n/roa-tara.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Joetaras"
5 | ]
6 | },
7 | "smt-desc": "Permette de pigghià le meta tag generate da [https://www.semantic-mediawiki.org annotaziune semandeche]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/ru.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Okras",
5 | "Vlad5250"
6 | ]
7 | },
8 | "smt-desc": "Позволяет предоставлять метатеги, созданные из [https://www.semantic-mediawiki.org семантических аннотаций]"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/sl.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Eleassar"
5 | ]
6 | },
7 | "smt-desc": "Omogoča uporabo metaoznak, ustvarjenih s [https://www.semantic-mediawiki.org semantičnim označevanjem]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/sr-ec.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Aca",
5 | "BadDog",
6 | "Obsuser"
7 | ]
8 | },
9 | "smt-desc": "Омогућава додељивање мета ознака генерисаних из [https://www.semantic-mediawiki.org семантичких прибелешки]"
10 | }
11 |
--------------------------------------------------------------------------------
/i18n/sr-el.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": []
4 | },
5 | "smt-desc": "Omogućava dodeljivanje meta oznaka generisanih iz [https://www.semantic-mediawiki.org semantičkih pribeleški]"
6 | }
7 |
--------------------------------------------------------------------------------
/i18n/th.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "B20180"
5 | ]
6 | },
7 | "smt-desc": "อนุญาตให้สร้างเมตาแท็กจาก [https://www.semantic-mediawiki.org คำอธิบายประกอบความหมาย]"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/tr.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "BaRaN6161 TURK"
5 | ]
6 | },
7 | "smt-desc": "[https://www.semantic-mediawiki.org Semantik ek açıklamalarından] oluşturulan meta etiketlerin sağlanmasına izin verir"
8 | }
9 |
--------------------------------------------------------------------------------
/i18n/uk.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Vlad5250",
5 | "Ата"
6 | ]
7 | },
8 | "smt-desc": "Дозволяє забезпечити мета-теґи, що генеруються з [https://www.semantic-mediawiki.org семантичних анотацій]"
9 | }
10 |
--------------------------------------------------------------------------------
/i18n/zh-hans.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "LittlePaw365",
5 | "Liuxinyu970226",
6 | "水獭很懒"
7 | ]
8 | },
9 | "smt-desc": "允许提供从[https://www.semantic-mediawiki.org 语义注释]生成的meta标记"
10 | }
11 |
--------------------------------------------------------------------------------
/i18n/zh-hant.json:
--------------------------------------------------------------------------------
1 | {
2 | "@metadata": {
3 | "authors": [
4 | "Kly"
5 | ]
6 | },
7 | "smt-desc": "允許提供來自[https://www.semantic-mediawiki.org 語意註解]所產生的元標籤"
8 | }
9 |
--------------------------------------------------------------------------------
/phpmd.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
17 | tests/phpunit/Unit
18 |
19 |
20 | tests/phpunit/Integration
21 |
22 |
23 |
24 |
25 | src
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/HookRegistry.php:
--------------------------------------------------------------------------------
1 | addCallbackHandlers( $store, $options );
30 | }
31 |
32 | /**
33 | * @since 1.0
34 | */
35 | public function register() {
36 | foreach ( $this->handlers as $name => $callback ) {
37 | MediaWikiServices::getInstance()->getHookContainer()->register( $name, $callback );
38 | }
39 | }
40 |
41 | /**
42 | * @since 1.0
43 | *
44 | * @param string $name
45 | *
46 | * @return bool
47 | */
48 | public function isRegistered( $name ) {
49 | return MediaWikiServices::getInstance()->getHookContainer()->isRegistered( $name );
50 | }
51 |
52 | /**
53 | * @since 1.1
54 | *
55 | * @param string $name
56 | *
57 | * @return callable|false
58 | */
59 | public function getHandlerFor( $name ) {
60 | return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false;
61 | }
62 |
63 | private function addCallbackHandlers( $store, $options ) {
64 | $this->handlers['BeforePageDisplay'] = static function ( $outputPage, $skin ) {
65 | if ( empty( $GLOBALS['wgSemanticMetaTagsDisableJsonLD'] ) ) {
66 | new JsonLDSerializer( $skin->getTitle(), $outputPage );
67 | }
68 | };
69 |
70 | /**
71 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageParserOutput
72 | */
73 | $this->handlers['OutputPageParserOutput'] = static function ( &$outputPage, $parserOutput ) use( $store, $options ) {
74 | $parserData = ApplicationFactory::getInstance()->newParserData(
75 | $outputPage->getTitle(),
76 | $parserOutput
77 | );
78 |
79 | $lazySemanticDataLookup = new LazySemanticDataLookup(
80 | $parserData,
81 | $store
82 | );
83 |
84 | $outputPageHtmlTagsInserter = new OutputPageHtmlTagsInserter(
85 | $outputPage
86 | );
87 |
88 | $outputPageHtmlTagsInserter->setMetaTagsBlacklist(
89 | $options->get( 'metaTagsBlacklist' )
90 | );
91 |
92 | $outputPageHtmlTagsInserter->setMetaPropertyPrefixes(
93 | $options->get( 'metaTagsMetaPropertyPrefixes' )
94 | );
95 |
96 | $outputPageHtmlTagsInserter->setActionName(
97 | \Action::getActionName( $outputPage->getContext() )
98 | );
99 |
100 | $propertyValuesContentAggregator = new PropertyValuesContentAggregator(
101 | $lazySemanticDataLookup,
102 | $outputPage
103 | );
104 |
105 | $propertyValuesContentAggregator->useFallbackChainForMultipleProperties(
106 | $options->get( 'metaTagsFallbackUseForMultipleProperties' )
107 | );
108 |
109 | $metaTagsProcessor = new MetaTagsProcessor(
110 | $propertyValuesContentAggregator
111 | );
112 |
113 | $metaTagsProcessor->setMetaTagsContentPropertySelector(
114 | $options->get( 'metaTagsContentPropertySelector' )
115 | );
116 |
117 | $metaTagsProcessor->setMetaTagsStaticContentDescriptor(
118 | $options->get( 'metaTagsStaticContentDescriptor' )
119 | );
120 |
121 | $metaTagsProcessor->addMetaTags( $outputPageHtmlTagsInserter );
122 |
123 | return true;
124 | };
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/JsonLDSerializer.php:
--------------------------------------------------------------------------------
1 | isKnownArticle( $title ) ) {
22 | $this->setJsonLD( $title, $outputPage );
23 | }
24 | }
25 |
26 | /**
27 | * @see https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/PageProperties/+/548d30609c512a79e202dfa7c02a298c66ca34fa/includes/PageProperties.php
28 | * @param Title $title
29 | * @return bool
30 | */
31 | private function isKnownArticle( $title ) {
32 | return ( $title && $title->canExist() && $title->getArticleID() > 0
33 | && $title->isKnown() );
34 | }
35 |
36 | /**
37 | * @see https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/PageProperties/+/548d30609c512a79e202dfa7c02a298c66ca34fa/includes/PageProperties.php
38 | * @param Title $title
39 | * @param OutputPage $outputPage
40 | * @return void
41 | */
42 | public static function setJsonLD( $title, $outputPage ) {
43 | if ( !class_exists( '\EasyRdf\Graph' ) || !class_exists( '\ML\JsonLD\JsonLD' ) ) {
44 | return;
45 | }
46 |
47 | // @TODO use directly the function makeExportDataForSubject
48 | // SemanticMediawiki/includes/export/SMW_Exporter.php
49 | $export_rdf = SpecialPage::getTitleFor( 'ExportRDF' );
50 | if ( $export_rdf->isKnown() ) {
51 | $export_url = $export_rdf->getFullURL( [
52 | 'page' => $title->getFullText(),
53 | 'recursive' => '1',
54 | 'backlinks' => 0
55 | ] );
56 |
57 | try {
58 | $foaf = new \EasyRdf\Graph( $export_url );
59 | $foaf->load();
60 |
61 | $format = \EasyRdf\Format::getFormat( 'jsonld' );
62 | $output = $foaf->serialise( $format, [
63 | 'compact' => true,
64 | ] );
65 |
66 | } catch ( Exception $e ) {
67 | self::$Logger->error( 'EasyRdf error: ' . $export_url );
68 | return;
69 | }
70 |
71 | // https://hotexamples.com/examples/-/EasyRdf_Graph/serialise/php-easyrdf_graph-serialise-method-examples.html
72 | if ( is_scalar( $output ) ) {
73 | $outputPage->addHeadItem( 'json-ld', Html::Element(
74 | 'script', [ 'type' => 'application/ld+json' ], $output
75 | )
76 | );
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/LazySemanticDataLookup.php:
--------------------------------------------------------------------------------
1 | parserData = $parserData;
45 | $this->store = $store;
46 | }
47 |
48 | /**
49 | * @since 1.0
50 | *
51 | * @return SemanticData
52 | */
53 | public function getSemanticData() {
54 | if ( $this->semanticData === null ) {
55 | $this->semanticData = $this->fetchSemanticData();
56 | }
57 |
58 | return $this->semanticData;
59 | }
60 |
61 | private function fetchSemanticData() {
62 | // First try the ParserOuput
63 | $semanticData = $this->parserData->getSemanticData();
64 |
65 | if ( !$semanticData->isEmpty() ) {
66 | return $semanticData;
67 | }
68 |
69 | $requestOptions = new RequestOptions();
70 | $requestOptions->setCaller( __METHOD__ );
71 |
72 | $subject = $this->parserData->getSemanticData()->getSubject();
73 |
74 | // Final method is the Store
75 | return $this->store->getSemanticData(
76 | $subject,
77 | $requestOptions
78 | );
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/MetaTagsProcessor.php:
--------------------------------------------------------------------------------
1 | propertyValuesContentAggregator = $propertyValuesContentAggregator;
40 | }
41 |
42 | /**
43 | * @since 1.0
44 | *
45 | * @param array $metaTagsContentPropertySelector
46 | */
47 | public function setMetaTagsContentPropertySelector( array $metaTagsContentPropertySelector ) {
48 | $this->metaTagsContentPropertySelector = $metaTagsContentPropertySelector;
49 | }
50 |
51 | /**
52 | * @since 1.0
53 | *
54 | * @param array $metaTagsStaticContentDescriptor
55 | */
56 | public function setMetaTagsStaticContentDescriptor( array $metaTagsStaticContentDescriptor ) {
57 | $this->metaTagsStaticContentDescriptor = $metaTagsStaticContentDescriptor;
58 | }
59 |
60 | /**
61 | * @since 1.0
62 | *
63 | * @param OutputPageHtmlTagsInserter $outputPageHtmlTagsInserter
64 | */
65 | public function addMetaTags( OutputPageHtmlTagsInserter $outputPageHtmlTagsInserter ) {
66 | if ( !$outputPageHtmlTagsInserter->canUseOutputPage() ) {
67 | return;
68 | }
69 |
70 | $this->outputPageHtmlTagsInserter = $outputPageHtmlTagsInserter;
71 |
72 | $this->addMetaTagsForProperties();
73 | $this->addMetaTagsForStaticContent();
74 | }
75 |
76 | private function addMetaTagsForProperties() {
77 | foreach ( $this->metaTagsContentPropertySelector as $tag => $properties ) {
78 |
79 | if ( $properties === '' || $properties === [] ) {
80 | continue;
81 | }
82 |
83 | $this->addMetaTagsForAggregatedProperties( $tag, $properties );
84 | }
85 | }
86 |
87 | private function addMetaTagsForAggregatedProperties( $tag, $properties ) {
88 | if ( is_string( $properties ) ) {
89 | $properties = explode( ',', $properties );
90 | } elseif ( is_callable( $properties ) ) {
91 | $properties = [ $properties ];
92 | }
93 |
94 | $content = $this->propertyValuesContentAggregator->doAggregateFor(
95 | $properties
96 | );
97 |
98 | if ( $content === '' ) {
99 | return;
100 | }
101 |
102 | $this->outputPageHtmlTagsInserter->addTagContentToOutputPage(
103 | $tag,
104 | $content
105 | );
106 | }
107 |
108 | private function addMetaTagsForStaticContent() {
109 | foreach ( $this->metaTagsStaticContentDescriptor as $tag => $content ) {
110 |
111 | if ( $content === '' ) {
112 | continue;
113 | }
114 |
115 | $this->outputPageHtmlTagsInserter->addTagContentToOutputPage(
116 | $tag,
117 | $content
118 | );
119 | }
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/src/Options.php:
--------------------------------------------------------------------------------
1 | options = $options;
25 | }
26 |
27 | /**
28 | * @since 1.0
29 | *
30 | * @param string $key
31 | * @param mixed $value
32 | */
33 | public function set( $key, $value ) {
34 | $this->options[$key] = $value;
35 | }
36 |
37 | /**
38 | * @since 1.0
39 | *
40 | * @param string $key
41 | *
42 | * @return bool
43 | */
44 | public function has( $key ) {
45 | return isset( $this->options[$key] ) || array_key_exists( $key, $this->options );
46 | }
47 |
48 | /**
49 | * @since 1.0
50 | *
51 | * @param string $key
52 | *
53 | * @return string
54 | * @throws InvalidArgumentException
55 | */
56 | public function get( $key ) {
57 | if ( $this->has( $key ) ) {
58 | return $this->options[$key];
59 | }
60 |
61 | throw new InvalidArgumentException( "{$key} is an unregistered option" );
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/OutputPageHtmlTagsInserter.php:
--------------------------------------------------------------------------------
1 | outputPage = $outputPage;
47 | }
48 |
49 | /**
50 | * @since 1.0
51 | *
52 | * @param array $metaTagsBlacklist
53 | */
54 | public function setMetaTagsBlacklist( array $metaTagsBlacklist ) {
55 | $this->metaTagsBlacklist = array_flip( $metaTagsBlacklist );
56 | }
57 |
58 | /**
59 | * @since 1.4
60 | *
61 | * @param array $metaPropertyPrefixes
62 | */
63 | public function setMetaPropertyPrefixes( array $metaPropertyPrefixes ) {
64 | $this->metaPropertyPrefixes = $metaPropertyPrefixes;
65 | }
66 |
67 | /**
68 | * @since 1.0
69 | *
70 | * @param string $actionName
71 | */
72 | public function setActionName( $actionName ) {
73 | $this->actionName = $actionName;
74 | }
75 |
76 | /**
77 | * @since 1.0
78 | *
79 | * @return bool
80 | */
81 | public function canUseOutputPage() {
82 | if ( $this->outputPage->getTitle() === null || $this->outputPage->getTitle()->isSpecialPage() || $this->actionName !== 'view' ) {
83 | return false;
84 | }
85 |
86 | return true;
87 | }
88 |
89 | /**
90 | * @since 1.0
91 | *
92 | * @param string $tag
93 | * @param string $content
94 | */
95 | public function addTagContentToOutputPage( $tag, $content ) {
96 | $tag = strtolower( htmlspecialchars( trim( $tag ) ) );
97 | $content = htmlspecialchars( $content );
98 |
99 | if ( isset( $this->metaTagsBlacklist[$tag] ) ) {
100 | return;
101 | }
102 |
103 | if ( $this->reqMetaPropertyMarkup( $tag ) ) {
104 | return $this->addMetaPropertyMarkup( $tag, $content );
105 | }
106 |
107 | $this->outputPage->addMeta( $tag, $content );
108 | }
109 |
110 | private function addMetaPropertyMarkup( $tag, $content ) {
111 | $comment = '';
112 |
113 | if ( !$this->metaPropertyMarkup ) {
114 | $comment .= '' . "\n";
115 | $this->metaPropertyMarkup = true;
116 | }
117 |
118 | $content = $comment . \Html::element( 'meta', [
119 | 'property' => $tag,
120 | 'content' => $content
121 | ] );
122 |
123 | $this->outputPage->addHeadItem( "meta:property:$tag", $content );
124 | }
125 |
126 | private function reqMetaPropertyMarkup( $tag ) {
127 | // If a tag contains a `og:` such as `og:title` it is expected to be a
128 | // OpenGraph protocol tag along with other prefixes maintained in
129 | // $GLOBALS['smtgMetaPropertyPrefixes']
130 | foreach ( $this->metaPropertyPrefixes as $prefix ) {
131 | if ( strpos( $tag, $prefix ) !== false ) {
132 | return true;
133 | }
134 | }
135 |
136 | return false;
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/src/PropertyValuesContentAggregator.php:
--------------------------------------------------------------------------------
1 | lazySemanticDataLookup = $lazySemanticDataLookup;
45 | $this->mOutputPage = $outputPage;
46 | }
47 |
48 | /**
49 | * @since 1.0
50 | *
51 | * @param bool $useFallbackChainForMultipleProperties
52 | */
53 | public function useFallbackChainForMultipleProperties( $useFallbackChainForMultipleProperties ) {
54 | $this->useFallbackChainForMultipleProperties = $useFallbackChainForMultipleProperties;
55 | }
56 |
57 | /**
58 | * @since 1.0
59 | *
60 | * @param string[] $propertyNames
61 | *
62 | * @return string
63 | */
64 | public function doAggregateFor( array $propertyNames ) {
65 | $values = [];
66 |
67 | foreach ( $propertyNames as $property ) {
68 |
69 | // If content is already present and the fallback mode is enabled
70 | // stop requesting additional content
71 | if ( $this->useFallbackChainForMultipleProperties && $values !== [] ) {
72 | break;
73 | }
74 |
75 | if ( is_string( $property ) ) {
76 | $property = trim( $property );
77 | }
78 | $this->fetchContentForProperty( $property, $values );
79 | }
80 |
81 | return implode( ',', $values );
82 | }
83 |
84 | private function fetchContentForProperty( $property, array &$values ) {
85 | if ( is_callable( $property ) ) {
86 | // This is actually a callback function.
87 | $result = $property( $this->mOutputPage );
88 | if ( $result ) {
89 | foreach ( (array)$result as $value ) {
90 | $values[$value] = (string)$value;
91 | }
92 | }
93 | } else {
94 | // This is a real property.
95 | $property = DIProperty::newFromUserLabel( $property );
96 | $semanticData = $this->lazySemanticDataLookup->getSemanticData();
97 |
98 | $this->iterateToCollectPropertyValues(
99 | $semanticData->getPropertyValues( $property ),
100 | $values
101 | );
102 |
103 | foreach ( $semanticData->getSubSemanticData() as $subSemanticData ) {
104 | $this->iterateToCollectPropertyValues(
105 | $subSemanticData->getPropertyValues( $property ),
106 | $values
107 | );
108 | }
109 | }
110 | }
111 |
112 | private function iterateToCollectPropertyValues( array $propertyValues, &$values ) {
113 | foreach ( $propertyValues as $value ) {
114 |
115 | // Content escaping (htmlspecialchars) is being carried out
116 | // by the instance that adds the content
117 | if ( $value instanceof DIBlob ) {
118 | $values[$value->getHash()] = $value->getString();
119 | } elseif ( $value instanceof DIWikiPage || $value instanceof DIUri ) {
120 | $values[$value->getHash()] = $value->getSortKey();
121 | }
122 | }
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | addPsr4( 'SMT\\Tests\\', __DIR__ . '/phpunit/Unit' );
29 | $autoloader->addPsr4( 'SMT\\Tests\\Integration\\', __DIR__ . '/phpunit/Integration' );
30 |
31 | unset( $autoloader );
32 |
--------------------------------------------------------------------------------
/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php:
--------------------------------------------------------------------------------
1 | newJsonFileReader( $file );
25 |
26 | $this->assertIsInt(
27 |
28 | $jsonFileReader->getModificationTime()
29 | );
30 |
31 | $this->assertIsArray(
32 |
33 | $jsonFileReader->read()
34 | );
35 | }
36 |
37 | public function i18nFileProvider() {
38 | $provider = [];
39 | $location = $GLOBALS['wgMessagesDirs']['SemanticMetaTags'];
40 |
41 | $bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location );
42 | $bulkFileProvider->searchByFileExtension( 'json' );
43 |
44 | foreach ( $bulkFileProvider->getFiles() as $file ) {
45 | $provider[] = [ $file ];
46 | }
47 |
48 | return $provider;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/tests/phpunit/Integration/MetaTagsContentGenerationIntegrationTest.php:
--------------------------------------------------------------------------------
1 | pageCreator = UtilityFactory::getInstance()->newpageCreator();
31 | $this->pageDeleter = UtilityFactory::getInstance()->newPageDeleter();
32 |
33 | // @see LinksUpdateTest
34 | $this->mwHooksHandler = $this->testEnvironment->getUtilityFactory()->newMwHooksHandler();
35 | $this->mwHooksHandler->deregisterListedHooks();
36 | $this->mwHooksHandler->invokeHooksFromRegistry();
37 |
38 | $metaTagsBlacklist = [
39 | 'robots'
40 | ];
41 |
42 | $metaTagsContentPropertySelector = [
43 | 'KEYwoRDS' => [ 'SMT keywords', 'SMT other keywords' ],
44 | 'robots' => 'SMT keywords, SMT other keywords',
45 | 'description' => '',
46 | 'twitter:description' => 'SMT description',
47 | 'og:title' => 'SMT title'
48 | ];
49 |
50 | $metaTagsStaticContentDescriptor = [
51 | 'static:TAG' => 'withStatic'
52 | ];
53 |
54 | $configuration = [
55 | 'metaTagsContentPropertySelector' => $metaTagsContentPropertySelector,
56 | 'metaTagsStaticContentDescriptor' => $metaTagsStaticContentDescriptor,
57 | 'metaTagsBlacklist' => $metaTagsBlacklist,
58 | 'metaTagsFallbackUseForMultipleProperties' => false,
59 | 'metaTagsMetaPropertyPrefixes' => [ 'og:' ]
60 | ];
61 |
62 | $hookRegistry = new HookRegistry(
63 | $this->getStore(),
64 | new Options( $configuration )
65 | );
66 |
67 | $hookRegistry->register();
68 | }
69 |
70 | protected function tearDown(): void {
71 | $this->pageDeleter->doDeletePoolOfPages(
72 | $this->subjects
73 | );
74 |
75 | parent::tearDown();
76 | }
77 |
78 | public function testAddStandardMetaTag() {
79 | $requestContext = new \RequestContext();
80 | $outputPage = $requestContext->getOutput();
81 |
82 | if ( !method_exists( $outputPage, 'getMetaTags' ) ) {
83 | $this->markTestSkipped( 'OutputPage::getMetaTags does not exist for this MW version' );
84 | }
85 |
86 | $subject = new DIWikiPage( __METHOD__, NS_MAIN );
87 | $requestContext->setTitle( $subject->getTitle() );
88 |
89 | $this->pageCreator
90 | ->createPage( $subject->getTitle() )
91 | ->doEdit(
92 | '[[SMT keywords::KeywordMetaTag]]' .
93 | '[[SMT other keywords::AnotherKeywordMetaTag]]' .
94 | '[[SMT description::Example description]]' );
95 |
96 | $parserOutput = $this->pageCreator->getEditInfo()->getOutput();
97 |
98 | $outputPage->addParserOutputMetadata( $parserOutput );
99 |
100 | $expected = [
101 | [ 'keywords', 'KeywordMetaTag,AnotherKeywordMetaTag' ],
102 | [ 'twitter:description', 'Example description' ],
103 | [ 'static:tag', 'withStatic<Content>' ]
104 | ];
105 |
106 | $this->assertEquals(
107 | $expected,
108 | $outputPage->getMetaTags()
109 | );
110 |
111 | $this->assertFalse(
112 | $outputPage->hasHeadItem( 'meta:property:og:title' )
113 | );
114 |
115 | $this->subjects[] = $subject;
116 | }
117 |
118 | public function testAddOpenGraphMetaTag() {
119 | $requestContext = new \RequestContext();
120 | $outputPage = $requestContext->getOutput();
121 |
122 | if ( !method_exists( $outputPage, 'addParserOutputMetadata' ) ) {
123 | $this->markTestSkipped( 'OutputPage::addParserOutputMetadata does not exist for this MW version' );
124 | }
125 |
126 | $subject = new DIWikiPage( __METHOD__, NS_MAIN );
127 | $requestContext->setTitle( $subject->getTitle() );
128 |
129 | $this->pageCreator
130 | ->createPage( $subject->getTitle() )
131 | ->doEdit( '[[SMT title::OGTitleMetaTags]]' );
132 |
133 | // Force the FallbackSemanticDataFetcher to indirectly use the Store
134 | $outputPage->addParserOutputMetadata( new \ParserOutput() );
135 |
136 | $this->assertTrue(
137 | $outputPage->hasHeadItem( 'meta:property:og:title' )
138 | );
139 |
140 | $this->subjects[] = $subject;
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/tests/phpunit/Unit/HookRegistryTest.php:
--------------------------------------------------------------------------------
1 | getMockBuilder( '\SMW\Store' )
22 | ->disableOriginalConstructor()
23 | ->getMockForAbstractClass();
24 |
25 | $options = $this->getMockBuilder( '\SMT\Options' )
26 | ->disableOriginalConstructor()
27 | ->getMock();
28 |
29 | $this->assertInstanceOf(
30 | '\SMT\HookRegistry',
31 | new HookRegistry( $store, $options )
32 | );
33 | }
34 |
35 | public function testRegister() {
36 | $store = $this->getMockBuilder( '\SMW\Store' )
37 | ->disableOriginalConstructor()
38 | ->getMockForAbstractClass();
39 |
40 | $configuration = [
41 | 'metaTagsContentPropertySelector' => [],
42 | 'metaTagsStaticContentDescriptor' => [],
43 | 'metaTagsBlacklist' => [],
44 | 'metaTagsFallbackUseForMultipleProperties' => false,
45 | 'metaTagsMetaPropertyPrefixes' => []
46 | ];
47 |
48 | $instance = new HookRegistry(
49 | $store,
50 | new Options( $configuration )
51 | );
52 |
53 | $this->doTestRegisteredOutputPageParserOutputHandler( $instance );
54 | }
55 |
56 | public function doTestRegisteredOutputPageParserOutputHandler( $instance ) {
57 | $handler = 'OutputPageParserOutput';
58 |
59 | $title = Title::newFromText( __METHOD__ );
60 |
61 | $context = $this->getMockBuilder( '\IContextSource' )
62 | ->disableOriginalConstructor()
63 | ->getMock();
64 |
65 | $context->expects( $this->any() )
66 | ->method( 'getActionName' )
67 | ->willReturn( 'view' );
68 |
69 | $outputPage = $this->getMockBuilder( '\OutputPage' )
70 | ->disableOriginalConstructor()
71 | ->getMock();
72 |
73 | $outputPage->expects( $this->atLeastOnce() )
74 | ->method( 'getTitle' )
75 | ->willReturn( $title );
76 |
77 | $outputPage->expects( $this->atLeastOnce() )
78 | ->method( 'getContext' )
79 | ->willReturn( $context );
80 |
81 | $parserOutput = $this->getMockBuilder( '\ParserOutput' )
82 | ->disableOriginalConstructor()
83 | ->getMock();
84 |
85 | $this->assertTrue(
86 | $instance->isRegistered( $handler )
87 | );
88 |
89 | $this->assertThatHookIsExcutable(
90 | $instance->getHandlerFor( $handler ),
91 | [ &$outputPage, $parserOutput ]
92 | );
93 | }
94 |
95 | private function assertThatHookIsExcutable( \Closure $handler, $arguments ) {
96 | $this->assertIsBool(
97 |
98 | call_user_func_array( $handler, $arguments )
99 | );
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/tests/phpunit/Unit/LazySemanticDataLookupTest.php:
--------------------------------------------------------------------------------
1 | getMockBuilder( '\SMW\ParserData' )
21 | ->disableOriginalConstructor()
22 | ->getMock();
23 |
24 | $store = $this->getMockBuilder( '\SMW\Store' )
25 | ->disableOriginalConstructor()
26 | ->getMockForAbstractClass();
27 |
28 | $this->assertInstanceOf(
29 | '\SMT\LazySemanticDataLookup',
30 | new LazySemanticDataLookup( $parserData, $store )
31 | );
32 | }
33 |
34 | public function testGetSemanticDataFromParserOutput() {
35 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
36 | ->disableOriginalConstructor()
37 | ->getMock();
38 |
39 | $semanticData->expects( $this->once() )
40 | ->method( 'isEmpty' )
41 | ->willReturn( false );
42 |
43 | $parserData = $this->getMockBuilder( '\SMW\ParserData' )
44 | ->disableOriginalConstructor()
45 | ->getMock();
46 |
47 | $parserData->expects( $this->once() )
48 | ->method( 'getSemanticData' )
49 | ->willReturn( $semanticData );
50 |
51 | $store = $this->getMockBuilder( '\SMW\Store' )
52 | ->disableOriginalConstructor()
53 | ->getMockForAbstractClass();
54 |
55 | $store->expects( $this->never() )
56 | ->method( 'getSemanticData' );
57 |
58 | $instance = new LazySemanticDataLookup( $parserData, $store );
59 | $instance->getSemanticData();
60 |
61 | // Internally cached
62 | $instance->getSemanticData();
63 | }
64 |
65 | public function testGetSemanticDataFromStore() {
66 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
67 | ->disableOriginalConstructor()
68 | ->getMock();
69 |
70 | $semanticData->expects( $this->at( 0 ) )
71 | ->method( 'isEmpty' )
72 | ->willReturn( true );
73 |
74 | $semanticData->expects( $this->at( 1 ) )
75 | ->method( 'isEmpty' )
76 | ->willReturn( false );
77 |
78 | $semanticData->expects( $this->once() )
79 | ->method( 'getSubject' )
80 | ->willReturn( new DIWikiPage( 'Foo', NS_MAIN ) );
81 |
82 | $parserData = $this->getMockBuilder( '\SMW\ParserData' )
83 | ->disableOriginalConstructor()
84 | ->getMock();
85 |
86 | $parserData->expects( $this->atLeastOnce() )
87 | ->method( 'getSemanticData' )
88 | ->willReturn( $semanticData );
89 |
90 | $store = $this->getMockBuilder( '\SMW\Store' )
91 | ->disableOriginalConstructor()
92 | ->getMockForAbstractClass();
93 |
94 | $store->expects( $this->once() )
95 | ->method( 'getSemanticData' );
96 |
97 | $instance = new LazySemanticDataLookup( $parserData, $store );
98 | $instance->getSemanticData();
99 |
100 | // Internally cached
101 | $instance->getSemanticData();
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/tests/phpunit/Unit/MetaTagsProcessorTest.php:
--------------------------------------------------------------------------------
1 | getMockBuilder( '\SMT\PropertyValuesContentAggregator' )
20 | ->disableOriginalConstructor()
21 | ->getMock();
22 |
23 | $this->assertInstanceOf(
24 | '\SMT\MetaTagsProcessor',
25 | new MetaTagsProcessor( $propertyValuesContentAggregator )
26 | );
27 | }
28 |
29 | public function testTryToAddTags() {
30 | $propertyValuesContentAggregator = $this->getMockBuilder( '\SMT\PropertyValuesContentAggregator' )
31 | ->disableOriginalConstructor()
32 | ->getMock();
33 |
34 | $propertyValuesContentAggregator->expects( $this->never() )
35 | ->method( 'doAggregateFor' );
36 |
37 | $OutputPageHtmlTagsInserter = $this->getMockBuilder( '\SMT\OutputPageHtmlTagsInserter' )
38 | ->disableOriginalConstructor()
39 | ->getMock();
40 |
41 | $OutputPageHtmlTagsInserter->expects( $this->once() )
42 | ->method( 'canUseOutputPage' )
43 | ->willReturn( false );
44 |
45 | $instance = new MetaTagsProcessor(
46 | $propertyValuesContentAggregator
47 | );
48 |
49 | $instance->setMetaTagsContentPropertySelector( [ 'foo' ] );
50 | $instance->addMetaTags( $OutputPageHtmlTagsInserter );
51 | }
52 |
53 | /**
54 | * @dataProvider invalidPropertySelectorProvider
55 | */
56 | public function testTryToModifyOutputPageForInvalidPropertySelector( $propertySelector ) {
57 | $propertyValuesContentAggregator = $this->getMockBuilder( '\SMT\PropertyValuesContentAggregator' )
58 | ->disableOriginalConstructor()
59 | ->getMock();
60 |
61 | $propertyValuesContentAggregator->expects( $this->never() )
62 | ->method( 'doAggregateFor' );
63 |
64 | $outputPage = $this->getMockBuilder( '\OutputPage' )
65 | ->disableOriginalConstructor()
66 | ->getMock();
67 |
68 | $outputPage->expects( $this->never() )
69 | ->method( 'addMeta' );
70 |
71 | $outputPage->expects( $this->never() )
72 | ->method( 'addHeadItem' );
73 |
74 | $OutputPageHtmlTagsInserter = $this->getMockBuilder( '\SMT\OutputPageHtmlTagsInserter' )
75 | ->setConstructorArgs( [ $outputPage ] )
76 | ->onlyMethods( [ 'canUseOutputPage' ] )
77 | ->getMock();
78 |
79 | $OutputPageHtmlTagsInserter->expects( $this->once() )
80 | ->method( 'canUseOutputPage' )
81 | ->willReturn( true );
82 |
83 | $instance = new MetaTagsProcessor(
84 | $propertyValuesContentAggregator
85 | );
86 |
87 | $instance->setMetaTagsContentPropertySelector( $propertySelector );
88 | $instance->addMetaTags( $OutputPageHtmlTagsInserter );
89 | }
90 |
91 | /**
92 | * @dataProvider validPropertySelectorProvider
93 | */
94 | public function testModifyOutputPageForValidPropertySelector( $propertySelector, $properties, $expected ) {
95 | $propertyValuesContentAggregator = $this->getMockBuilder( '\SMT\PropertyValuesContentAggregator' )
96 | ->disableOriginalConstructor()
97 | ->getMock();
98 |
99 | $propertyValuesContentAggregator->expects( $this->once() )
100 | ->method( 'doAggregateFor' )
101 | ->with( $properties )
102 | ->willReturn( $expected['content'] );
103 |
104 | $outputPage = $this->getMockBuilder( '\OutputPage' )
105 | ->disableOriginalConstructor()
106 | ->getMock();
107 |
108 | $outputPage->expects( $this->once() )
109 | ->method( 'addMeta' )
110 | ->with(
111 | $expected['tag'],
112 | $expected['content'] );
113 |
114 | $OutputPageHtmlTagsInserter = $this->getMockBuilder( '\SMT\OutputPageHtmlTagsInserter' )
115 | ->setConstructorArgs( [ $outputPage ] )
116 | ->onlyMethods( [ 'canUseOutputPage' ] )
117 | ->getMock();
118 |
119 | $OutputPageHtmlTagsInserter->expects( $this->once() )
120 | ->method( 'canUseOutputPage' )
121 | ->willReturn( true );
122 |
123 | $instance = new MetaTagsProcessor(
124 | $propertyValuesContentAggregator
125 | );
126 |
127 | $instance->setMetaTagsContentPropertySelector( $propertySelector );
128 | $instance->addMetaTags( $OutputPageHtmlTagsInserter );
129 | }
130 |
131 | public function testTryToModifyOutputPageForEmptyStaticContent() {
132 | $propertyValuesContentAggregator = $this->getMockBuilder( '\SMT\PropertyValuesContentAggregator' )
133 | ->disableOriginalConstructor()
134 | ->getMock();
135 |
136 | $outputPageHtmlTagsInserter = $this->getMockBuilder( '\SMT\OutputPageHtmlTagsInserter' )
137 | ->disableOriginalConstructor()
138 | ->onlyMethods( [ 'canUseOutputPage', 'addTagContentToOutputPage' ] )
139 | ->getMock();
140 |
141 | $outputPageHtmlTagsInserter->expects( $this->once() )
142 | ->method( 'canUseOutputPage' )
143 | ->willReturn( true );
144 |
145 | $outputPageHtmlTagsInserter->expects( $this->never() )
146 | ->method( 'addTagContentToOutputPage' );
147 |
148 | $instance = new MetaTagsProcessor(
149 | $propertyValuesContentAggregator
150 | );
151 |
152 | $instance->setMetaTagsStaticContentDescriptor( [ 'foo' => '' ] );
153 | $instance->addMetaTags( $outputPageHtmlTagsInserter );
154 | }
155 |
156 | /**
157 | * @dataProvider staticContentProvider
158 | */
159 | public function testModifyOutputPageForStaticContentDescriptor( $contentDescriptor, $expected ) {
160 | $propertyValuesContentAggregator = $this->getMockBuilder( '\SMT\PropertyValuesContentAggregator' )
161 | ->disableOriginalConstructor()
162 | ->getMock();
163 |
164 | $outputPage = $this->getMockBuilder( '\OutputPage' )
165 | ->disableOriginalConstructor()
166 | ->getMock();
167 |
168 | $outputPage->expects( $this->once() )
169 | ->method( 'addMeta' )
170 | ->with(
171 | $expected['tag'],
172 | $expected['content'] );
173 |
174 | $OutputPageHtmlTagsInserter = $this->getMockBuilder( '\SMT\OutputPageHtmlTagsInserter' )
175 | ->setConstructorArgs( [ $outputPage ] )
176 | ->onlyMethods( [ 'canUseOutputPage' ] )
177 | ->getMock();
178 |
179 | $OutputPageHtmlTagsInserter->expects( $this->once() )
180 | ->method( 'canUseOutputPage' )
181 | ->willReturn( true );
182 |
183 | $instance = new MetaTagsProcessor(
184 | $propertyValuesContentAggregator
185 | );
186 |
187 | $instance->setMetaTagsStaticContentDescriptor( $contentDescriptor );
188 | $instance->addMetaTags( $OutputPageHtmlTagsInserter );
189 | }
190 |
191 | public function invalidPropertySelectorProvider() {
192 | $provider = [];
193 |
194 | $provider[] = [
195 | []
196 | ];
197 |
198 | $provider[] = [
199 | [ 'foo' => '' ]
200 | ];
201 |
202 | $provider[] = [
203 | [ 'foo' => [] ]
204 | ];
205 |
206 | $provider[] = [
207 | [ 'foo:bar' => '' ]
208 | ];
209 |
210 | return $provider;
211 | }
212 |
213 | public function validPropertySelectorProvider() {
214 | $provider = [];
215 |
216 | $provider[] = [
217 | [ 'foo' => 'foobar' ],
218 | [ 'foobar' ],
219 | [ 'tag' => 'foo', 'content' => 'Mo,fo' ]
220 | ];
221 |
222 | $provider[] = [
223 | [ 'foo' => [ 'foobar', 'quin' ] ],
224 | [ 'foobar', 'quin' ],
225 | [ 'tag' => 'foo', 'content' => 'Mo,fo' ]
226 | ];
227 |
228 | $provider[] = [
229 | [ 'foo' => ' foobar, quin ' ],
230 | [ ' foobar', ' quin ' ],
231 | [ 'tag' => 'foo', 'content' => 'Mo,fo' ]
232 | ];
233 |
234 | $provider[] = [
235 | [ 'FOO' => 'foobar,quin' ],
236 | [ 'foobar', 'quin' ],
237 | [ 'tag' => 'foo', 'content' => 'Mo,fo' ]
238 | ];
239 |
240 | $provider[] = [
241 | [ 'FO"O' => 'foobar,quin' ],
242 | [ 'foobar', 'quin' ],
243 | [ 'tag' => 'fo"o', 'content' => 'Mo,fo' ]
244 | ];
245 |
246 | return $provider;
247 | }
248 |
249 | public function staticContentProvider() {
250 | $provider = [];
251 |
252 | $provider[] = [
253 | [ 'foo' => 'staticDescriptionOfContent' ],
254 | [ 'tag' => 'foo', 'content' => 'staticDescriptionOfContent' ]
255 | ];
256 |
257 | $provider[] = [
258 | [ 'FOO' => 'static"Description"OfContent' ],
259 | [ 'tag' => 'foo', 'content' => 'static"Description"OfContent' ]
260 | ];
261 |
262 | $provider[] = [
263 | [ 'bar' => '', 'FOO' => 'bar' ],
264 | [
265 | 'tag' => 'foo', 'content' => 'bar'
266 | ]
267 | ];
268 |
269 | return $provider;
270 | }
271 |
272 | }
273 |
--------------------------------------------------------------------------------
/tests/phpunit/Unit/OptionsTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
20 | '\SMT\Options',
21 | new Options()
22 | );
23 | }
24 |
25 | public function testAddOption() {
26 | $instance = new Options();
27 |
28 | $this->assertFalse(
29 | $instance->has( 'Foo' )
30 | );
31 |
32 | $instance->set( 'Foo', 42 );
33 |
34 | $this->assertEquals(
35 | 42,
36 | $instance->get( 'Foo' )
37 | );
38 | }
39 |
40 | public function testUnregisteredKeyThrowsException() {
41 | $instance = new Options();
42 |
43 | $this->expectException( 'InvalidArgumentException' );
44 | $instance->get( 'Foo' );
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/tests/phpunit/Unit/OutputPageHtmlTagsInserterTest.php:
--------------------------------------------------------------------------------
1 | getMockBuilder( '\OutputPage' )
20 | ->disableOriginalConstructor()
21 | ->getMock();
22 |
23 | $this->assertInstanceOf(
24 | '\SMT\OutputPageHtmlTagsInserter',
25 | new OutputPageHtmlTagsInserter( $outputPage )
26 | );
27 | }
28 |
29 | public function testTryToUseOutputPageForSpecialPage() {
30 | $title = $this->getMockBuilder( '\Title' )
31 | ->disableOriginalConstructor()
32 | ->getMock();
33 |
34 | $title->expects( $this->any() )
35 | ->method( 'isSpecialPage' )
36 | ->willReturn( true );
37 |
38 | $outputPage = $this->getMockBuilder( '\OutputPage' )
39 | ->disableOriginalConstructor()
40 | ->getMock();
41 |
42 | $outputPage->expects( $this->never() )
43 | ->method( 'addMeta' );
44 |
45 | $outputPage->expects( $this->atLeastOnce() )
46 | ->method( 'getTitle' )
47 | ->willReturn( $title );
48 |
49 | $instance = new OutputPageHtmlTagsInserter( $outputPage );
50 |
51 | $this->assertFalse(
52 | $instance->canUseOutputPage()
53 | );
54 | }
55 |
56 | public function testTryToUseOutputPageForNonViewAction() {
57 | $title = $this->getMockBuilder( '\Title' )
58 | ->disableOriginalConstructor()
59 | ->getMock();
60 |
61 | $title->expects( $this->any() )
62 | ->method( 'isSpecialPage' )
63 | ->willReturn( false );
64 |
65 | $outputPage = $this->getMockBuilder( '\OutputPage' )
66 | ->disableOriginalConstructor()
67 | ->getMock();
68 |
69 | $outputPage->expects( $this->never() )
70 | ->method( 'addMeta' );
71 |
72 | $outputPage->expects( $this->atLeastOnce() )
73 | ->method( 'getTitle' )
74 | ->willReturn( $title );
75 |
76 | $instance = new OutputPageHtmlTagsInserter( $outputPage );
77 | $instance->setActionName( 'foo' );
78 |
79 | $this->assertFalse(
80 | $instance->canUseOutputPage()
81 | );
82 | }
83 |
84 | public function testTryToAddContentForBlacklistedTag() {
85 | $outputPage = $this->getMockBuilder( '\OutputPage' )
86 | ->disableOriginalConstructor()
87 | ->getMock();
88 |
89 | $outputPage->expects( $this->never() )
90 | ->method( 'addMeta' );
91 |
92 | $instance = new OutputPageHtmlTagsInserter( $outputPage );
93 | $instance->setMetaTagsBlacklist( [ 'foo' ] );
94 |
95 | $instance->addTagContentToOutputPage( 'FOO', 'bar' );
96 | }
97 |
98 | /**
99 | * @dataProvider nonOgTagProvider
100 | */
101 | public function testAddTagForNonOgContent( $tag, $content, $expected ) {
102 | $outputPage = $this->getMockBuilder( '\OutputPage' )
103 | ->disableOriginalConstructor()
104 | ->getMock();
105 |
106 | $outputPage->expects( $this->once() )
107 | ->method( 'addMeta' )
108 | ->with(
109 | $expected['tag'],
110 | $expected['content'] );
111 |
112 | $instance = new OutputPageHtmlTagsInserter( $outputPage );
113 | $instance->addTagContentToOutputPage( $tag, $content );
114 | }
115 |
116 | /**
117 | * @dataProvider propertyTagProvider
118 | */
119 | public function testAddTagOnMetaPropertyPrefixContent( $prefixes, $tag, $content, $expected ) {
120 | $outputPage = $this->getMockBuilder( '\OutputPage' )
121 | ->disableOriginalConstructor()
122 | ->getMock();
123 |
124 | $outputPage->expects( $this->once() )
125 | ->method( 'addHeadItem' )
126 | ->with(
127 | $expected['tag'],
128 | $this->stringContains( $expected['item'] ) );
129 |
130 | $instance = new OutputPageHtmlTagsInserter( $outputPage );
131 |
132 | $instance->setMetaPropertyPrefixes(
133 | $prefixes
134 | );
135 |
136 | $instance->addTagContentToOutputPage( $tag, $content );
137 | }
138 |
139 | public function nonOgTagProvider() {
140 | $provider = [];
141 |
142 | $provider[] = [
143 | 'foo',
144 | 'foobar',
145 | [ 'tag' => 'foo', 'content' => 'foobar' ]
146 | ];
147 |
148 | $provider[] = [
149 | 'FOO',
150 | '"foobar"',
151 | [ 'tag' => 'foo', 'content' => '"foobar"' ]
152 | ];
153 |
154 | $provider[] = [
155 | ' foo ',
156 | ' foobar ',
157 | [ 'tag' => 'foo', 'content' => ' foobar ' ]
158 | ];
159 |
160 | $provider[] = [
161 | 'FO"O',
162 | 'foobar',
163 | [ 'tag' => 'fo"o', 'content' => 'foobar' ]
164 | ];
165 |
166 | $provider[] = [
167 | 'twitter:card',
168 | 'FOO',
169 | [ 'tag' => 'twitter:card', 'content' => 'FOO' ]
170 | ];
171 |
172 | return $provider;
173 | }
174 |
175 | public function propertyTagProvider() {
176 | $provider = [];
177 |
178 | $provider[] = [
179 | [
180 | 'og:'
181 | ],
182 | 'og:bar',
183 | 'foobar',
184 | [
185 | 'tag' => 'meta:property:og:bar',
186 | 'item' => '' . "\n" . 'getMockBuilder( '\SMT\LazySemanticDataLookup' )
24 | ->disableOriginalConstructor()
25 | ->getMock();
26 |
27 | $outputPage = $this->getMockBuilder( 'OutputPage' )
28 | ->disableOriginalConstructor()
29 | ->getMock();
30 |
31 | $this->assertInstanceOf(
32 | '\SMT\PropertyValuesContentAggregator',
33 | new PropertyValuesContentAggregator( $lazySemanticDataLookup, $outputPage )
34 | );
35 | }
36 |
37 | public function testFindContentForProperty() {
38 | $properties = [ 'foobar' ];
39 |
40 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
41 | ->disableOriginalConstructor()
42 | ->getMock();
43 |
44 | $semanticData->expects( $this->once() )
45 | ->method( 'getSubSemanticData' )
46 | ->willReturn( [] );
47 |
48 | $semanticData->expects( $this->once() )
49 | ->method( 'getPropertyValues' )
50 | ->with( DIProperty::newFromUserLabel( 'foobar' ) )
51 | ->willReturn( [ new DIWikiPage( 'Foo', NS_MAIN ) ] );
52 |
53 | $lazySemanticDataLookup = $this->getMockBuilder( '\SMT\LazySemanticDataLookup' )
54 | ->disableOriginalConstructor()
55 | ->getMock();
56 |
57 | $lazySemanticDataLookup->expects( $this->once() )
58 | ->method( 'getSemanticData' )
59 | ->willReturn( $semanticData );
60 |
61 | $outputPage = $this->getMockBuilder( 'OutputPage' )
62 | ->disableOriginalConstructor()
63 | ->getMock();
64 |
65 | $instance = new PropertyValuesContentAggregator( $lazySemanticDataLookup, $outputPage );
66 |
67 | $this->assertSame(
68 | 'Foo',
69 | $instance->doAggregateFor( $properties )
70 | );
71 | }
72 |
73 | public function testAggregatePropertyValueContentWithSameHash() {
74 | $properties = [ 'foobar' ];
75 |
76 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
77 | ->disableOriginalConstructor()
78 | ->getMock();
79 |
80 | $semanticData->expects( $this->once() )
81 | ->method( 'getSubSemanticData' )
82 | ->willReturn( [] );
83 |
84 | $semanticData->expects( $this->once() )
85 | ->method( 'getPropertyValues' )
86 | ->with( DIProperty::newFromUserLabel( 'foobar' ) )
87 | ->willReturn( [
88 | DIUri::doUnserialize( 'http://username@example.org/foo' ),
89 | DIUri::doUnserialize( 'http://username@example.org/foo' ),
90 | new DIWikiPage( 'Foo', NS_MAIN ),
91 | new DIWikiPage( 'Foo', NS_MAIN ) ] );
92 |
93 | $lazySemanticDataLookup = $this->getMockBuilder( '\SMT\LazySemanticDataLookup' )
94 | ->disableOriginalConstructor()
95 | ->getMock();
96 |
97 | $lazySemanticDataLookup->expects( $this->once() )
98 | ->method( 'getSemanticData' )
99 | ->willReturn( $semanticData );
100 |
101 | $outputPage = $this->getMockBuilder( 'OutputPage' )
102 | ->disableOriginalConstructor()
103 | ->getMock();
104 |
105 | $instance = new PropertyValuesContentAggregator( $lazySemanticDataLookup, $outputPage );
106 |
107 | $this->assertSame(
108 | 'http://username@example.org/foo,Foo',
109 | $instance->doAggregateFor( $properties )
110 | );
111 | }
112 |
113 | public function testFindContentForSubobjectProperty() {
114 | $properties = [ 'bar' ];
115 |
116 | $subSemanticData = $this->getMockBuilder( '\SMW\SemanticData' )
117 | ->disableOriginalConstructor()
118 | ->getMock();
119 |
120 | $subSemanticData->expects( $this->once() )
121 | ->method( 'getPropertyValues' )
122 | ->with( DIProperty::newFromUserLabel( 'bar' ) )
123 | ->willReturn( [ new DIBlob( 'Foo-with-html-"<>"-escaping-to-happen-somewhere-else' ) ] );
124 |
125 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
126 | ->disableOriginalConstructor()
127 | ->getMock();
128 |
129 | $semanticData->expects( $this->once() )
130 | ->method( 'getPropertyValues' )
131 | ->willReturn( [] );
132 |
133 | $semanticData->expects( $this->once() )
134 | ->method( 'getSubSemanticData' )
135 | ->willReturn( [ $subSemanticData ] );
136 |
137 | $lazySemanticDataLookup = $this->getMockBuilder( '\SMT\LazySemanticDataLookup' )
138 | ->disableOriginalConstructor()
139 | ->getMock();
140 |
141 | $lazySemanticDataLookup->expects( $this->once() )
142 | ->method( 'getSemanticData' )
143 | ->willReturn( $semanticData );
144 |
145 | $outputPage = $this->getMockBuilder( 'OutputPage' )
146 | ->disableOriginalConstructor()
147 | ->getMock();
148 |
149 | $instance = new PropertyValuesContentAggregator( $lazySemanticDataLookup, $outputPage );
150 |
151 | $this->assertSame(
152 | 'Foo-with-html-"<>"-escaping-to-happen-somewhere-else',
153 | $instance->doAggregateFor( $properties )
154 | );
155 | }
156 |
157 | public function testFindContentForMultiplePropertiesToUseFullContentAggregation() {
158 | $properties = [ ' foo ', 'bar' ];
159 |
160 | $propertyValues = [
161 | 0 => [
162 | DIUri::doUnserialize( 'http://username@example.org/foo' ),
163 | new DIWikiPage( '"Foo"', NS_MAIN )
164 | ],
165 | 2 => [
166 | new DIBlob( 'Mo' ),
167 | new DIBlob( 'Mo' ),
168 | new DIBlob( 'fo' )
169 | ]
170 | ];
171 |
172 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
173 | ->disableOriginalConstructor()
174 | ->getMock();
175 |
176 | $semanticData->expects( $this->at( 0 ) )
177 | ->method( 'getPropertyValues' )
178 | ->with( DIProperty::newFromUserLabel( 'foo' ) )
179 | ->willReturn( $propertyValues[0] );
180 |
181 | $semanticData->expects( $this->at( 2 ) )
182 | ->method( 'getPropertyValues' )
183 | ->with( DIProperty::newFromUserLabel( 'bar' ) )
184 | ->willReturn( $propertyValues[2] );
185 |
186 | $semanticData->expects( $this->any() )
187 | ->method( 'getSubSemanticData' )
188 | ->willReturn( [] );
189 |
190 | $this->doAssertContentForMultipleProperties(
191 | false,
192 | $semanticData,
193 | $properties,
194 | 'http://username@example.org/foo,"Foo",Mo,fo'
195 | );
196 | }
197 |
198 | public function testFindContentForMultiplePropertiesToUseFallbackChain() {
199 | $properties = [ ' foo ', 'bar' ];
200 |
201 | $propertyValues = [
202 | [
203 | DIUri::doUnserialize( 'http://username@example.org/foo' ),
204 | new DIWikiPage( '"Foo"', NS_MAIN )
205 | ],
206 | [
207 | new DIBlob( 'Mo' ),
208 | new DIBlob( 'fo' )
209 | ]
210 | ];
211 |
212 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
213 | ->disableOriginalConstructor()
214 | ->getMock();
215 |
216 | $semanticData->expects( $this->once() )
217 | ->method( 'getPropertyValues' )
218 | ->with( DIProperty::newFromUserLabel( 'foo' ) )
219 | ->willReturnOnConsecutiveCalls( $propertyValues[0], $propertyValues[1] );
220 |
221 | $semanticData->expects( $this->any() )
222 | ->method( 'getSubSemanticData' )
223 | ->willReturn( [] );
224 |
225 | $this->doAssertContentForMultipleProperties(
226 | true,
227 | $semanticData,
228 | $properties,
229 | 'http://username@example.org/foo,"Foo"'
230 | );
231 | }
232 |
233 | private function doAssertContentForMultipleProperties( $fallbackChainUsageState, $semanticData, $properties, $expected ) {
234 | $lazySemanticDataLookup = $this->getMockBuilder( '\SMT\LazySemanticDataLookup' )
235 | ->disableOriginalConstructor()
236 | ->getMock();
237 |
238 | $lazySemanticDataLookup->expects( $this->atLeastOnce() )
239 | ->method( 'getSemanticData' )
240 | ->willReturn( $semanticData );
241 |
242 | $outputPage = $this->getMockBuilder( 'OutputPage' )
243 | ->disableOriginalConstructor()
244 | ->getMock();
245 |
246 | $instance = new PropertyValuesContentAggregator( $lazySemanticDataLookup, $outputPage );
247 | $instance->useFallbackChainForMultipleProperties( $fallbackChainUsageState );
248 |
249 | $this->assertSame(
250 | $expected,
251 | $instance->doAggregateFor( $properties )
252 | );
253 | }
254 |
255 | }
256 |
--------------------------------------------------------------------------------
/tests/travis/install-mediawiki.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -ex
3 |
4 | cd ..
5 |
6 | ## Use sha (master@5cc1f1d) to download a particular commit to avoid breakages
7 | ## introduced by MediaWiki core
8 | if [[ "$MW" == *@* ]]
9 | then
10 | arrMw=(${MW//@/ })
11 | MW=${arrMw[0]}
12 | SOURCE=${arrMw[1]}
13 | else
14 | MW=$MW
15 | SOURCE=$MW
16 | fi
17 |
18 | wget https://github.com/wikimedia/mediawiki/archive/$SOURCE.tar.gz -O $MW.tar.gz
19 |
20 | tar -zxf $MW.tar.gz
21 | mv mediawiki-* mw
22 |
23 | cd mw
24 |
25 | ## MW 1.25+ requires Psr\Logger
26 | if [ -f composer.json ]
27 | then
28 | composer self-update
29 | composer install --prefer-source
30 | fi
31 |
32 | if [ "$DB" == "postgres" ]
33 | then
34 | # See #458
35 | sudo /etc/init.d/postgresql stop
36 | sudo /etc/init.d/postgresql start
37 |
38 | psql -c 'create database its_a_mw;' -U postgres
39 | php maintenance/install.php --dbtype $DB --dbuser postgres --dbname its_a_mw --pass AdminPassword TravisWiki admin --scriptpath /TravisWiki
40 | else
41 | mysql -e 'create database its_a_mw;'
42 | php maintenance/install.php --dbtype $DB --dbuser root --dbname its_a_mw --dbpath $(pwd) --pass AdminPassword TravisWiki admin --scriptpath /TravisWiki
43 | fi
44 |
--------------------------------------------------------------------------------
/tests/travis/install-semantic-meta-tags.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -ex
3 |
4 | BASE_PATH=$(pwd)
5 | MW_INSTALL_PATH=$BASE_PATH/../mw
6 |
7 | # Run Composer installation from the MW root directory
8 | function installToMediaWikiRoot {
9 | echo -e "Running MW root composer install build on $TRAVIS_BRANCH \n"
10 |
11 | cd $MW_INSTALL_PATH
12 |
13 | if [ "$PHPUNIT" != "" ]
14 | then
15 | composer require 'phpunit/phpunit='$PHPUNIT --update-with-dependencies
16 | else
17 | composer require 'phpunit/phpunit=6.5.*' --update-with-dependencies
18 | fi
19 |
20 | if [ "$SMT" != "" ]
21 | then
22 | composer require 'mediawiki/semantic-meta-tags='$SMT --update-with-dependencies
23 | else
24 | composer init --stability dev
25 | composer require mediawiki/semantic-meta-tags "dev-master" --dev --update-with-dependencies
26 |
27 | cd extensions
28 | cd SemanticMetaTags
29 |
30 | # Pull request number, "false" if it's not a pull request
31 | # After the install via composer an additional get fetch is carried out to
32 | # update th repository to make sure that the latests code changes are
33 | # deployed for testing
34 | if [ "$TRAVIS_PULL_REQUEST" != "false" ]
35 | then
36 | git fetch origin +refs/pull/"$TRAVIS_PULL_REQUEST"/merge:
37 | git checkout -qf FETCH_HEAD
38 | else
39 | git fetch origin "$TRAVIS_BRANCH"
40 | git checkout -qf FETCH_HEAD
41 | fi
42 |
43 | cd ../..
44 | fi
45 |
46 | # Rebuild the class map for added classes during git fetch
47 | composer dump-autoload
48 | }
49 |
50 | function updateConfiguration {
51 |
52 | cd $MW_INSTALL_PATH
53 |
54 | # SMW#1732
55 | echo 'wfLoadExtension( "SemanticMediaWiki" );' >> LocalSettings.php
56 |
57 | echo 'wfLoadExtension( "SemanticMetaTags" );' >> LocalSettings.php
58 |
59 | # Site language
60 | if [ "$SITELANG" != "" ]
61 | then
62 | echo '$wgLanguageCode = "'$SITELANG'";' >> LocalSettings.php
63 | fi
64 |
65 | echo 'define("SMW_PHPUNIT_PULL_VERSION_FROM_GITHUB", true);' >> LocalSettings.php
66 |
67 | echo 'error_reporting(E_ALL| E_STRICT);' >> LocalSettings.php
68 | echo 'ini_set("display_errors", 1);' >> LocalSettings.php
69 | echo '$wgShowExceptionDetails = true;' >> LocalSettings.php
70 | echo '$wgDevelopmentWarnings = true;' >> LocalSettings.php
71 | echo "putenv( 'MW_INSTALL_PATH=$(pwd)' );" >> LocalSettings.php
72 |
73 | php maintenance/update.php --quick
74 | }
75 |
76 | installToMediaWikiRoot
77 | updateConfiguration
78 |
--------------------------------------------------------------------------------
/tests/travis/run-tests.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | set -ex
3 |
4 | BASE_PATH=$(pwd)
5 | MW_INSTALL_PATH=$BASE_PATH/../mw
6 |
7 | cd $MW_INSTALL_PATH/extensions/SemanticMetaTags
8 |
9 | if [ "$TYPE" == "coverage" ]
10 | then
11 | composer phpunit -- --coverage-clover $BASE_PATH/build/coverage.clover
12 | else
13 | composer phpunit
14 | fi
15 |
--------------------------------------------------------------------------------
/tests/travis/upload-coverage-report.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | set -ex
3 |
4 | BASE_PATH=$(pwd)
5 |
6 | if [ "$TYPE" == "coverage" ]
7 | then
8 | wget https://scrutinizer-ci.com/ocular.phar
9 | php ocular.phar code-coverage:upload --format=php-clover $BASE_PATH/build/coverage.clover
10 | fi
--------------------------------------------------------------------------------