mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 01:30:15 +00:00
Hygiene: Convert value to constant and clarify outlier use case
Change-Id: I7a82fa99b41362368a9f58cfb84241cca97bfb15
This commit is contained in:
parent
4aa508b6a8
commit
0f36db727e
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
abstract class EchoDiscussionParser {
|
abstract class EchoDiscussionParser {
|
||||||
|
const HEADER_REGEX = '^(==+)\s*([^=].*)\s*\1$';
|
||||||
|
|
||||||
static protected $timestampRegex;
|
static protected $timestampRegex;
|
||||||
static protected $headerRegex = '^(==+)\s*([^=].*)\s*\1$';
|
|
||||||
static protected $revisionInterpretationCache = array();
|
static protected $revisionInterpretationCache = array();
|
||||||
static protected $diffParser;
|
static protected $diffParser;
|
||||||
|
|
||||||
|
@ -340,7 +341,10 @@ abstract class EchoDiscussionParser {
|
||||||
|
|
||||||
if ( $change['action'] == 'add' ) {
|
if ( $change['action'] == 'add' ) {
|
||||||
$content = trim( $change['content'] );
|
$content = trim( $change['content'] );
|
||||||
$startSection = preg_match( "/\A" . self::$headerRegex . '/um', $content );
|
// The \A means the regex must match at the begining of the string.
|
||||||
|
// This is slightly different than ^ which matches begining of each
|
||||||
|
// line in multiline mode.
|
||||||
|
$startSection = preg_match( "/\A" . self::HEADER_REGEX . '/um', $content );
|
||||||
$sectionCount = self::getSectionCount( $content );
|
$sectionCount = self::getSectionCount( $content );
|
||||||
$signedUsers = array_keys( self::extractSignatures( $content ) );
|
$signedUsers = array_keys( self::extractSignatures( $content ) );
|
||||||
|
|
||||||
|
@ -411,7 +415,7 @@ abstract class EchoDiscussionParser {
|
||||||
*/
|
*/
|
||||||
static function getFullSection( $lines, $offset ) {
|
static function getFullSection( $lines, $offset ) {
|
||||||
$content = $lines[$offset - 1];
|
$content = $lines[$offset - 1];
|
||||||
$headerRegex = '/' . self::$headerRegex . '/um';
|
$headerRegex = '/' . self::HEADER_REGEX . '/um';
|
||||||
|
|
||||||
// Expand backwards...
|
// Expand backwards...
|
||||||
$continue = !preg_match( $headerRegex, $lines[$offset - 1] );
|
$continue = !preg_match( $headerRegex, $lines[$offset - 1] );
|
||||||
|
@ -452,7 +456,7 @@ abstract class EchoDiscussionParser {
|
||||||
$text = trim( $text );
|
$text = trim( $text );
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
preg_match_all( '/' . self::$headerRegex . '/um', $text, $matches );
|
preg_match_all( '/' . self::HEADER_REGEX . '/um', $text, $matches );
|
||||||
|
|
||||||
return count( $matches[0] );
|
return count( $matches[0] );
|
||||||
}
|
}
|
||||||
|
@ -468,7 +472,7 @@ abstract class EchoDiscussionParser {
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
|
|
||||||
if ( !preg_match_all( '/' . self::$headerRegex . '/um', $text, $matches ) ) {
|
if ( !preg_match_all( '/' . self::HEADER_REGEX . '/um', $text, $matches ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,7 +534,7 @@ abstract class EchoDiscussionParser {
|
||||||
* @return string: The same text, with the section header stripped out.
|
* @return string: The same text, with the section header stripped out.
|
||||||
*/
|
*/
|
||||||
static function stripHeader( $text ) {
|
static function stripHeader( $text ) {
|
||||||
$text = preg_replace( '/' . self::$headerRegex . '/um', '', $text );
|
$text = preg_replace( '/' . self::HEADER_REGEX . '/um', '', $text );
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue