Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SEO tweaks #491

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Add SEO tweaks #491

wants to merge 13 commits into from

Conversation

colleirose
Copy link

@colleirose colleirose commented May 19, 2024

Google has indexed some really useless pages on miraheze.org, hopefully this can help reduce that.

  • New Features
    • Make some pages noindex and some links nofollow for SEO reasons

Copy link

coderabbitai bot commented May 19, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates introduce new functionality to the Hooks class in the MediaWiki extension. Specifically, handlers for the HtmlPageLinkRendererEnd and BeforePageDisplay hooks have been added to manage link attributes and page indexing. Additionally, the changes include removing and adding several class declarations for better code organization and functionality.

Changes

File Change Summary
extension.json Added new handlers for HtmlPageLinkRendererEnd and BeforePageDisplay hooks.
includes/Hooks.php Added imports and methods for managing nofollow attributes and page indexing.
includes/Hooks.php Removed obsolete declarations (Article, DeferredUpdates, ExtensionRegistry).

Poem

In the realm of wiki's might,
New hooks bring much delight! 🌐
Links with 'nofollow' now,
Pages indexed right, we'll vow.
Clean code, pure and bright,
Coding changes out of sight! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 87e4875 and 140ad99.
Files selected for processing (2)
  • extension.json (1 hunks)
  • includes/Hooks.php (7 hunks)
Additional Context Used
Path-based Instructions (1)
includes/Hooks.php (1)

Pattern **/*.php: Follow MediaWiki PHP Coding Standards:

Indentation:

  • Use tabs for indentation, not spaces.

Spaces:

  • Use spaces on either side of binary operators.
    Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect)
  • Add spaces inside parentheses, except where they are empty.
    Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect)
  • Do not add a space after a function name.
    Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)

Function Return Type Hint:

  • Add a space after the colon in the function return type hint.
    Example: function square( int $x ): int { return $x * $x; }

Arrays:

  • Use spaces in brackets when declaring an array, except where the array is empty.
    Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect)
  • Do not put spaces in brackets when accessing array elements.
    Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)

Control Structures:

  • Add a space after control structure keywords.
    Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)

Type Casting:

  • Do not use a space within or after the cast operator.
    Example: (int)$foo; (Correct) (int) $bar; (Incorrect)

Comments:

  • In comments, there should be one space between the # or // and the comment text.
    Example: // This is a comment. (Correct) //This is a comment. (Incorrect)

Ternary Operator:

  • Keep ternary operator expressions short and obvious.
  • For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.

File Formatting:
- Avoid trailing whitespace on lines.

Additional comments not posted (2)
extension.json (1)

133-137: The addition of the HtmlPageLinkRendererEnd and BeforePageDisplay hooks aligns with the PR's objective to improve SEO. Ensure that these hooks are correctly implemented and tested.

Verification successful

The implementations for the onHtmlPageLinkRendererEnd and onBeforePageDisplay functions have been successfully extracted and reviewed. Both functions appear to be correctly handling their respective hooks to improve SEO by adding nofollow attributes and setting noindex policies for certain pages.

  • onHtmlPageLinkRendererEnd: Adds a nofollow attribute to links that are not known or are external.
  • onBeforePageDisplay: Sets a noindex,nofollow policy for specific namespaces and based on certain URL parameters.

These implementations align with the intended functionality to improve SEO.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of new hooks in the PHP files.

# Test: Search for the implementation of the new hooks. Expect: Proper implementation and usage.
rg --type php --files-with-matches $'public function onHtmlPageLinkRendererEnd|public function onBeforePageDisplay' ./includes

Length of output: 148



Script:

#!/bin/bash
# Description: Extract the implementation of the new hooks in the PHP files.

# Extract the implementation of the onHtmlPageLinkRendererEnd function.
ast-grep --lang php --pattern $'function onHtmlPageLinkRendererEnd($_) {
  $$$
}' ./includes/Hooks.php

# Extract the implementation of the onBeforePageDisplay function.
ast-grep --lang php --pattern $'function onBeforePageDisplay($_) {
  $$$
}' ./includes/Hooks.php

Length of output: 415



Script:

#!/bin/bash
# Description: Extract the implementation of the new hooks in the PHP files using rg.

# Extract the implementation of the onHtmlPageLinkRendererEnd function.
rg --type php -A 20 'function onHtmlPageLinkRendererEnd' ./includes/Hooks.php

# Extract the implementation of the onBeforePageDisplay function.
rg --type php -A 20 'function onBeforePageDisplay' ./includes/Hooks.php

Length of output: 1231

includes/Hooks.php (1)

30-31: The addition of BeforePageDisplayHook and HtmlPageLinkRendererEndHook declarations is appropriate for the SEO improvements. Ensure that these hooks are correctly implemented in their respective methods.

Verification successful

The hooks onHtmlPageLinkRendererEnd and onBeforePageDisplay are correctly implemented in includes/Hooks.php. The methods contain logic to add nofollow attributes to links and set noindex,nofollow robot policies for certain pages, aligning with the SEO improvements.

  • onHtmlPageLinkRendererEnd: Adds rel="nofollow" to links that are not known or external.
  • onBeforePageDisplay: Sets noindex,nofollow for specific namespaces and blacklisted URL parameters.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of new hooks in the PHP files.

# Test: Search for the implementation of the new hooks. Expect: Proper implementation and usage.
rg --type php --files-with-matches $'public function onHtmlPageLinkRendererEnd|public function onBeforePageDisplay' ./includes

Length of output: 148



Script:

#!/bin/bash
# Extract the implementation of the hooks from includes/Hooks.php

# Extract the method onHtmlPageLinkRendererEnd
ast-grep --lang php --pattern $'public function onHtmlPageLinkRendererEnd($_, $_, $_) {
  $$$
}' includes/Hooks.php

# Extract the method onBeforePageDisplay
ast-grep --lang php --pattern $'public function onBeforePageDisplay($_) {
  $$$
}' includes/Hooks.php

Length of output: 433



Script:

#!/bin/bash
# Extract the implementation of the hooks from includes/Hooks.php using rg

# Search for the method onHtmlPageLinkRendererEnd
rg --type php 'public function onHtmlPageLinkRendererEnd' includes/Hooks.php -A 20

# Search for the method onBeforePageDisplay
rg --type php 'public function onBeforePageDisplay' includes/Hooks.php -A 20

Length of output: 1241

includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
@colleirose

This comment has been minimized.

Copy link

coderabbitai bot commented May 19, 2024

Oops, something went wrong! Please try again later. 🐰 💔

@colleirose

This comment has been minimized.

Copy link

coderabbitai bot commented May 19, 2024

Tip

For best results, initiate chat on the files or code changes.

@colleirose, I apologize for the confusion earlier. Upon reviewing the changes in the includes/Hooks.php file, it appears that the declarations for Article, DeferredUpdates, and ExtensionRegistry were not removed but were instead reorganized within the file. Additionally, new hooks BeforePageDisplayHook and HtmlPageLinkRendererEndHook were added.

Thank you for pointing out the discrepancy. If you have any further questions or need additional assistance, please let me know!

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check the diff of the includes/Hooks.php file in the PR to verify the changes.
git diff origin/main...HEAD -- includes/Hooks.php

Length of output: 92



Script:

#!/bin/bash
# Fetch the correct branch names
MAIN_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
PR_BRANCH=$(git branch --show-current)

# Check the diff of the includes/Hooks.php file in the PR to verify the changes.
git diff $MAIN_BRANCH...$PR_BRANCH -- includes/Hooks.php

Length of output: 5246


New Learnings Added
User: colleirose
URL: https://github.com/miraheze/MirahezeMagic/pull/491

Timestamp: 2024-05-19T22:36:56.255Z
Learning: In the `includes/Hooks.php` file, the declarations for `Article`, `DeferredUpdates`, and `ExtensionRegistry` were reorganized rather than removed.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure review instructions.

includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
extension.json Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
@colleirose
Copy link
Author

@Universal-Omega Done, can you check again?

@colleirose colleirose changed the title Add SEO tweaks and slight formatting enhancements Add SEO tweaks May 20, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Out of diff range and nitpick comments (1)
includes/Hooks.php (1)

Line range hint 17-27: Ensure proper spacing around operators and within array declarations as per MediaWiki PHP coding standards.

- use MediaWiki\Hook\BeforePageDisplayHook;
- use MediaWiki\Hook\BlockIpCompleteHook;
- use MediaWiki\Hook\ContributionsToolLinksHook;
- use MediaWiki\Hook\GetLocalURL__InternalHook;
- use MediaWiki\Hook\MimeMagicInitHook;
- use MediaWiki\Hook\RecentChange_saveHook;
- use MediaWiki\Hook\SiteNoticeAfterHook;
- use MediaWiki\Hook\SkinAddFooterLinksHook;
+ use MediaWiki\Hook\BeforePageDisplayHook;
+ use MediaWiki\Hook\BlockIpCompleteHook;
+ use MediaWiki\Hook\ContributionsToolLinksHook;
+ use MediaWiki\Hook\GetLocalURL__InternalHook;
+ use MediaWiki\Hook\MimeMagicInitHook;
+ use MediaWiki\Hook\RecentChange_saveHook;
+ use MediaWiki\Hook\SiteNoticeAfterHook;
+ use MediaWiki\Hook\SkinAddFooterLinksHook;
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 140ad99 and 9c1a31c.
Files selected for processing (2)
  • extension.json (2 hunks)
  • includes/Hooks.php (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • extension.json
Additional Context Used
Path-based Instructions (1)
includes/Hooks.php (1)

Pattern **/*.php: Follow MediaWiki PHP Coding Standards:

Indentation:

  • Use tabs for indentation, not spaces.

Spaces:

  • Use spaces on either side of binary operators.
    Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect)
  • Add spaces inside parentheses, except where they are empty.
    Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect)
  • Do not add a space after a function name.
    Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)

Function Return Type Hint:

  • Add a space after the colon in the function return type hint.
    Example: function square( int $x ): int { return $x * $x; }

Arrays:

  • Use spaces in brackets when declaring an array, except where the array is empty.
    Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect)
  • Do not put spaces in brackets when accessing array elements.
    Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)

Control Structures:

  • Add a space after control structure keywords.
    Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)

Type Casting:

  • Do not use a space within or after the cast operator.
    Example: (int)$foo; (Correct) (int) $bar; (Incorrect)

Comments:

  • In comments, there should be one space between the # or // and the comment text.
    Example: // This is a comment. (Correct) //This is a comment. (Incorrect)

Ternary Operator:

  • Keep ternary operator expressions short and obvious.
  • For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.

File Formatting:
- Avoid trailing whitespace on lines.

Additional comments not posted (1)
includes/Hooks.php (1)

Line range hint 63-73: Added interfaces are aligned with the PR's objective to handle new hooks. Ensure that these interfaces are implemented correctly in the methods below.

includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
Looks weird in GitHub diffs but not on my machine for some reason (this is why I prefer spaces over tabs, tab sizes...)
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9c1a31c and 01a3855.
Files selected for processing (1)
  • includes/Hooks.php (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • includes/Hooks.php

No idea why I didn't realize this, the extension was actually running fine on my local install, very odd
Copy link
Member

@Universal-Omega Universal-Omega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a lot better. Still a few things though. Sorry if I am a bit particular here, I just like clean formatting meeting most standards. For the most part this PR looks pretty good though.

includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved

$blockedURLParamKeyValuePairs = [
'feed' => ['rss'],
'limit' => ['500'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be a string or an int?

Copy link
Author

@colleirose colleirose May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe not. This is fetching the request parameter values, which are passed to the server as strings, not ints, and they aren't converted to an int by PHP unless you explicitly cast them. Also, the code I based this on (linked to in the code comments) had them as strings and not ints. I also tested this on my local machine and confirm that ?limit=500 adds noindex,nofollow to the meta robots tag.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 01a3855 and bdb6cca.
Files selected for processing (1)
  • includes/Hooks.php (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • includes/Hooks.php

@colleirose
Copy link
Author

colleirose commented Jun 16, 2024

@pixDeVl Please make a PR to set up ManageWiki so that by default (i.e. user can change it) these namespaces and all talk pages (regardless of whether they relate to the namespaces listed here) default to noindex nofollow:

User
MediaWiki
Template
Module
File (won't prevent indexing of images, just their File: pages which rarely contain helpful information)

Thanks

@colleirose

This comment has been minimized.

Copy link

coderabbitai bot commented Jun 23, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Ideally, this will be done in ManageWiki later, as has been described previously
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdb6cca and 5ad45f2.

Files selected for processing (1)
  • includes/Hooks.php (5 hunks)
Additional context used
Path-based instructions (1)
includes/Hooks.php (1)

Pattern **/*.php: Follow MediaWiki PHP Coding Standards:

Indentation:

  • Use tabs for indentation, not spaces.

Spaces:

  • Use spaces on either side of binary operators.
    Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect)
  • Add spaces inside parentheses, except where they are empty.
    Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect)
  • Do not add a space after a function name.
    Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)

Function Return Type Hint:

  • Add a space after the colon in the function return type hint.
    Example: function square( int $x ): int { return $x * $x; }

Arrays:

  • Use spaces in brackets when declaring an array, except where the array is empty.
    Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect)
  • Do not put spaces in brackets when accessing array elements.
    Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)

Control Structures:

  • Add a space after control structure keywords.
    Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)

Type Casting:

  • Do not use a space within or after the cast operator.
    Example: (int)$foo; (Correct) (int) $bar; (Incorrect)

Comments:

  • In comments, there should be one space between the # or // and the comment text.
    Example: // This is a comment. (Correct) //This is a comment. (Incorrect)

Ternary Operator:

  • Keep ternary operator expressions short and obvious.
  • For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.

File Formatting:
- Avoid trailing whitespace on lines.

Additional comments not posted (1)
includes/Hooks.php (1)

Line range hint 17-27: Verify the correct implementation of newly added interfaces and hooks.

The class Hooks now implements several new interfaces, including BeforePageDisplayHook and HtmlPageLinkRendererEndHook. Ensure that these interfaces are correctly used in the methods onHtmlPageLinkRendererEnd and onBeforePagePageDisplay, and that all necessary conditions are met for these hooks to function as expected.

Also applies to: 63-73

includes/Hooks.php Outdated Show resolved Hide resolved
includes/Hooks.php Outdated Show resolved Hide resolved
Copy link

coderabbitai bot commented Jun 23, 2024

Tip

For best results, initiate chat on the files or code changes.

@colleirose, I appreciate your patience and your humor! 🐰 While I strive for perfection, sometimes things don't go as planned. If there's anything specific you need help with right now, please let me know, and I'll do my best to assist. Let's make the future a bit brighter together!

@colleirose

This comment has been minimized.

includes/Hooks.php Outdated Show resolved Hide resolved
@Universal-Omega
Copy link
Member

Looks okay, just needs testing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants