mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 20:09:44 +00:00
0a4c3cad17
CE-2367 change description
43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
namespace Wikia\PortableInfobox\Helpers;
|
|
|
|
class PortableInfoboxClassification {
|
|
|
|
/**
|
|
* Checks if a page contains non-portable infoboxes based on its title and content.
|
|
* The first check is if the title includes a word "infobox":
|
|
* - if yes, check for a new markup (<infobox>) in the content. If it is missing - it indicates that
|
|
* the template contains a non-portable infobox
|
|
* - if no, check for an occurrence of a word "infobox" inside all class HTML attributes
|
|
*
|
|
* Returns true if a page may consist a non-portable infobox
|
|
*
|
|
* @param string $titleText
|
|
* @param string $contentText
|
|
* @return bool
|
|
*/
|
|
public static function isTitleWithNonportableInfobox( $titleText, $contentText ) {
|
|
// ignore docs pages
|
|
if ( stripos( $titleText, '/doc' ) ) {
|
|
return false;
|
|
}
|
|
|
|
$titleNeedle = 'infobox';
|
|
if ( strripos( $titleText, $titleNeedle ) !== false ) {
|
|
$portableInfoboxNeedle = '<infobox';
|
|
|
|
// if a portable infobox was not found
|
|
// it means that the template has a non-portable one
|
|
return strpos( $contentText, $portableInfoboxNeedle ) === false;
|
|
} else {
|
|
$nonportableInfoboxRegEx = '/class=\"[^\"]*infobox[^\"]*\"/i';
|
|
$nonportableInfoboxRegExMatch = preg_match( $nonportableInfoboxRegEx, $contentText );
|
|
|
|
// If a non-portable infobox markup was found
|
|
// the $nonportableInfoboxRegExMatch is not empty
|
|
return !empty( $nonportableInfoboxRegExMatch );
|
|
}
|
|
}
|
|
}
|
|
|