Follow-up 5cbb64f56: Remove unused preprocessor classes
Merge the PPD* classes that were used by the DOM preprocessor with the hash preprocessor classes that extend them. This resolves many issues with types/phpcs and it removes unused code left over from the DOM preprocessor. Bug: T278069 Bug: T204945 Change-Id: I4b160b4610e5c7ba47e9e31db252cc00d2e345df
This commit is contained in:
parent
695db68020
commit
ff9b220f89
8 changed files with 176 additions and 317 deletions
|
|
@ -718,6 +718,11 @@ because of Phabricator reports.
|
|||
- loadRestrictions()
|
||||
* User::isAllowUsertalk was hard deprecated. Use User::getBlock and
|
||||
AbstractBlock::isUsertalkEditAllowed instead.
|
||||
* Classes used by Preprocessor_DOM have been merged with classes used by
|
||||
Preprocessor_Hash, as Preprocessor_DOM was removed in 1.35.
|
||||
- PPDPart has been merged into PPDPart_Hash
|
||||
- PPDStack has been merged into PPDStack_Hash
|
||||
- PPDStackElement has been merged into PPDStackElement_Hash
|
||||
* Collation::singleton and ::factory were deprecated, obtain an CollationFactory
|
||||
instance from MediaWikiServices instead.
|
||||
* …
|
||||
|
|
|
|||
|
|
@ -1185,10 +1185,7 @@ $wgAutoloadLocalClasses = [
|
|||
'PNGHandler' => __DIR__ . '/includes/media/PNGHandler.php',
|
||||
'PNGMetadataExtractor' => __DIR__ . '/includes/media/PNGMetadataExtractor.php',
|
||||
'PPCustomFrame_Hash' => __DIR__ . '/includes/parser/PPCustomFrame_Hash.php',
|
||||
'PPDPart' => __DIR__ . '/includes/parser/PPDPart.php',
|
||||
'PPDPart_Hash' => __DIR__ . '/includes/parser/PPDPart_Hash.php',
|
||||
'PPDStack' => __DIR__ . '/includes/parser/PPDStack.php',
|
||||
'PPDStackElement' => __DIR__ . '/includes/parser/PPDStackElement.php',
|
||||
'PPDStackElement_Hash' => __DIR__ . '/includes/parser/PPDStackElement_Hash.php',
|
||||
'PPDStack_Hash' => __DIR__ . '/includes/parser/PPDStack_Hash.php',
|
||||
'PPFrame' => __DIR__ . '/includes/parser/PPFrame.php',
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
* @ingroup Parser
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*
|
||||
* @property int $eqpos
|
||||
* @property int $commentEnd
|
||||
* @property int $visualEnd
|
||||
*/
|
||||
class PPDPart {
|
||||
/**
|
||||
* @var string Output accumulator string
|
||||
*/
|
||||
public $out;
|
||||
|
||||
// Optional member variables:
|
||||
// eqpos Position of equals sign in output accumulator
|
||||
// commentEnd Past-the-end input pointer for the last comment encountered
|
||||
// visualEnd Past-the-end input pointer for the end of the accumulator minus comments
|
||||
|
||||
/**
|
||||
* @param string $out
|
||||
*/
|
||||
public function __construct( $out = '' ) {
|
||||
$this->out = $out;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,21 +21,24 @@
|
|||
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*
|
||||
* @property int $eqpos
|
||||
* @property int $commentEnd
|
||||
* @property int $visualEnd
|
||||
* @property string[] $out
|
||||
*/
|
||||
// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
class PPDPart_Hash extends PPDPart {
|
||||
|
||||
class PPDPart_Hash {
|
||||
/**
|
||||
* @param string $out
|
||||
* @var string[] Output accumulator
|
||||
*/
|
||||
public $out;
|
||||
|
||||
public function __construct( $out = '' ) {
|
||||
$this->out = [];
|
||||
|
||||
if ( $out !== '' ) {
|
||||
$accum = [ $out ];
|
||||
} else {
|
||||
$accum = [];
|
||||
$this->out[] = $out;
|
||||
}
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal
|
||||
parent::__construct( $accum );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
* @ingroup Parser
|
||||
*/
|
||||
|
||||
/**
|
||||
* Stack class to help Preprocessor::preprocessToObj()
|
||||
* @ingroup Parser
|
||||
*/
|
||||
class PPDStack {
|
||||
/** @var PPDStackElement[] */
|
||||
public $stack;
|
||||
/** @var string|array */
|
||||
public $rootAccum;
|
||||
/** @var string|array */
|
||||
public $accum;
|
||||
|
||||
/**
|
||||
* @var PPDStackElement|false
|
||||
*/
|
||||
public $top;
|
||||
public $out;
|
||||
public $elementClass = PPDStackElement::class;
|
||||
|
||||
public static $false = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->stack = [];
|
||||
$this->top = false;
|
||||
$this->rootAccum = '';
|
||||
$this->accum =& $this->rootAccum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count( $this->stack );
|
||||
}
|
||||
|
||||
public function &getAccum() {
|
||||
return $this->accum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|PPDPart
|
||||
*/
|
||||
public function getCurrentPart() {
|
||||
if ( $this->top === false ) {
|
||||
return false;
|
||||
} else {
|
||||
return $this->top->getCurrentPart();
|
||||
}
|
||||
}
|
||||
|
||||
public function push( $data ) {
|
||||
if ( $data instanceof $this->elementClass ) {
|
||||
$this->stack[] = $data;
|
||||
} else {
|
||||
$class = $this->elementClass;
|
||||
$this->stack[] = new $class( $data );
|
||||
}
|
||||
$this->top = $this->stack[count( $this->stack ) - 1];
|
||||
$this->accum =& $this->top->getAccum();
|
||||
}
|
||||
|
||||
public function pop() {
|
||||
if ( $this->stack === [] ) {
|
||||
throw new MWException( __METHOD__ . ': no elements remaining' );
|
||||
}
|
||||
$temp = array_pop( $this->stack );
|
||||
|
||||
if ( count( $this->stack ) ) {
|
||||
$this->top = $this->stack[count( $this->stack ) - 1];
|
||||
$this->accum =& $this->top->getAccum();
|
||||
} else {
|
||||
$this->top = self::$false;
|
||||
$this->accum =& $this->rootAccum;
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
|
||||
public function addPart( $s = '' ) {
|
||||
$this->top->addPart( $s );
|
||||
$this->accum =& $this->top->getAccum();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFlags() {
|
||||
if ( $this->stack === [] ) {
|
||||
return [
|
||||
'findEquals' => false,
|
||||
'findPipe' => false,
|
||||
'inHeading' => false,
|
||||
];
|
||||
} else {
|
||||
return $this->top->getFlags();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
* @ingroup Parser
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*
|
||||
* @property int $startPos
|
||||
*/
|
||||
class PPDStackElement {
|
||||
/**
|
||||
* @var string Opening character (\n for heading)
|
||||
*/
|
||||
public $open;
|
||||
|
||||
/**
|
||||
* @var string Matching closing character
|
||||
*/
|
||||
public $close;
|
||||
|
||||
/**
|
||||
* @var string Saved prefix that may affect later processing,
|
||||
* e.g. to differentiate `-{{{{` and `{{{{` after later seeing `}}}`.
|
||||
*/
|
||||
public $savedPrefix = '';
|
||||
|
||||
/**
|
||||
* @var int Number of opening characters found (number of "=" for heading)
|
||||
*/
|
||||
public $count;
|
||||
|
||||
/**
|
||||
* @var PPDPart[] Array of PPDPart objects describing pipe-separated parts.
|
||||
*/
|
||||
public $parts;
|
||||
|
||||
/**
|
||||
* @var bool True if the open char appeared at the start of the input line.
|
||||
* Not set for headings.
|
||||
*/
|
||||
public $lineStart;
|
||||
|
||||
/** @var string */
|
||||
public $partClass = PPDPart::class;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct( $data = [] ) {
|
||||
$class = $this->partClass;
|
||||
$this->parts = [ new $class ];
|
||||
|
||||
foreach ( $data as $name => $value ) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function &getAccum() {
|
||||
return $this->parts[count( $this->parts ) - 1]->out;
|
||||
}
|
||||
|
||||
public function addPart( $s = '' ) {
|
||||
$class = $this->partClass;
|
||||
$this->parts[] = new $class( $s );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PPDPart
|
||||
*/
|
||||
public function getCurrentPart() {
|
||||
return $this->parts[count( $this->parts ) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFlags() {
|
||||
$partCount = count( $this->parts );
|
||||
$findPipe = $this->open != "\n" && $this->open != '[';
|
||||
return [
|
||||
'findPipe' => $findPipe,
|
||||
'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
|
||||
'inHeading' => $this->open == "\n",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output string that would result if the close is not found.
|
||||
*
|
||||
* @param bool|int $openingCount
|
||||
* @return string
|
||||
*/
|
||||
public function breakSyntax( $openingCount = false ) {
|
||||
if ( $this->open == "\n" ) {
|
||||
$s = $this->savedPrefix . $this->parts[0]->out;
|
||||
} else {
|
||||
if ( $openingCount === false ) {
|
||||
$openingCount = $this->count;
|
||||
}
|
||||
$s = substr( $this->open, 0, -1 );
|
||||
$s .= str_repeat(
|
||||
substr( $this->open, -1 ),
|
||||
$openingCount - strlen( $s )
|
||||
);
|
||||
$s = $this->savedPrefix . $s;
|
||||
$first = true;
|
||||
foreach ( $this->parts as $part ) {
|
||||
if ( $first ) {
|
||||
$first = false;
|
||||
} else {
|
||||
$s .= '|';
|
||||
}
|
||||
$s .= $part->out;
|
||||
}
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,14 +21,83 @@
|
|||
|
||||
/**
|
||||
* @ingroup Parser
|
||||
*
|
||||
* @property PPDPart_Hash[] $parts
|
||||
* @property int $startPos
|
||||
*/
|
||||
// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
class PPDStackElement_Hash extends PPDStackElement {
|
||||
class PPDStackElement_Hash {
|
||||
/**
|
||||
* @var string Opening character (\n for heading)
|
||||
*/
|
||||
public $open;
|
||||
|
||||
/**
|
||||
* @var string Matching closing character
|
||||
*/
|
||||
public $close;
|
||||
|
||||
/**
|
||||
* @var string Saved prefix that may affect later processing,
|
||||
* e.g. to differentiate `-{{{{` and `{{{{` after later seeing `}}}`.
|
||||
*/
|
||||
public $savedPrefix = '';
|
||||
|
||||
/**
|
||||
* @var int Number of opening characters found (number of "=" for heading)
|
||||
*/
|
||||
public $count;
|
||||
|
||||
/**
|
||||
* @var PPDPart_Hash[] Array of PPDPart objects describing pipe-separated parts.
|
||||
*/
|
||||
public $parts;
|
||||
|
||||
/**
|
||||
* @var bool True if the open char appeared at the start of the input line.
|
||||
* Not set for headings.
|
||||
*/
|
||||
public $lineStart;
|
||||
|
||||
/** @var string */
|
||||
public $partClass = PPDPart_Hash::class;
|
||||
|
||||
public function __construct( $data = [] ) {
|
||||
$this->partClass = PPDPart_Hash::class;
|
||||
parent::__construct( $data );
|
||||
$class = $this->partClass;
|
||||
$this->parts = [ new $class ];
|
||||
|
||||
foreach ( $data as $name => $value ) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function &getAccum() {
|
||||
return $this->parts[count( $this->parts ) - 1]->out;
|
||||
}
|
||||
|
||||
public function addPart( $s = '' ) {
|
||||
$class = $this->partClass;
|
||||
$this->parts[] = new $class( $s );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PPDPart_Hash
|
||||
*/
|
||||
public function getCurrentPart() {
|
||||
return $this->parts[count( $this->parts ) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFlags() {
|
||||
$partCount = count( $this->parts );
|
||||
$findPipe = $this->open != "\n" && $this->open != '[';
|
||||
return [
|
||||
'findPipe' => $findPipe,
|
||||
'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
|
||||
'inHeading' => $this->open == "\n",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +105,6 @@ class PPDStackElement_Hash extends PPDStackElement {
|
|||
*
|
||||
* @param int|bool $openingCount
|
||||
* @return array
|
||||
* @suppress PhanParamSignatureMismatch
|
||||
*/
|
||||
public function breakSyntax( $openingCount = false ) {
|
||||
if ( $this->open == "\n" ) {
|
||||
|
|
|
|||
|
|
@ -24,11 +24,96 @@
|
|||
* @ingroup Parser
|
||||
*/
|
||||
// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
class PPDStack_Hash extends PPDStack {
|
||||
class PPDStack_Hash {
|
||||
/** @var PPDStackElement_Hash[] */
|
||||
public $stack;
|
||||
/** @var string[] */
|
||||
public $rootAccum;
|
||||
/** @var string[] */
|
||||
public $accum;
|
||||
|
||||
/**
|
||||
* @var PPDStackElement_Hash|false
|
||||
*/
|
||||
public $top;
|
||||
public $out;
|
||||
public $elementClass = PPDStackElement_Hash::class;
|
||||
|
||||
public static $false = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->elementClass = PPDStackElement_Hash::class;
|
||||
parent::__construct();
|
||||
$this->stack = [];
|
||||
$this->top = false;
|
||||
$this->rootAccum = [];
|
||||
$this->accum =& $this->rootAccum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count( $this->stack );
|
||||
}
|
||||
|
||||
public function &getAccum() {
|
||||
return $this->accum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|PPDPart_Hash
|
||||
*/
|
||||
public function getCurrentPart() {
|
||||
if ( $this->top === false ) {
|
||||
return false;
|
||||
} else {
|
||||
return $this->top->getCurrentPart();
|
||||
}
|
||||
}
|
||||
|
||||
public function push( $data ) {
|
||||
if ( $data instanceof $this->elementClass ) {
|
||||
$this->stack[] = $data;
|
||||
} else {
|
||||
$class = $this->elementClass;
|
||||
$this->stack[] = new $class( $data );
|
||||
}
|
||||
$this->top = $this->stack[count( $this->stack ) - 1];
|
||||
$this->accum =& $this->top->getAccum();
|
||||
}
|
||||
|
||||
public function pop() {
|
||||
if ( $this->stack === [] ) {
|
||||
throw new MWException( __METHOD__ . ': no elements remaining' );
|
||||
}
|
||||
$temp = array_pop( $this->stack );
|
||||
|
||||
if ( count( $this->stack ) ) {
|
||||
$this->top = $this->stack[count( $this->stack ) - 1];
|
||||
$this->accum =& $this->top->getAccum();
|
||||
} else {
|
||||
$this->top = self::$false;
|
||||
$this->accum =& $this->rootAccum;
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
|
||||
public function addPart( $s = '' ) {
|
||||
$this->top->addPart( $s );
|
||||
$this->accum =& $this->top->getAccum();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFlags() {
|
||||
if ( $this->stack === [] ) {
|
||||
return [
|
||||
'findEquals' => false,
|
||||
'findPipe' => false,
|
||||
'inHeading' => false,
|
||||
];
|
||||
} else {
|
||||
return $this->top->getFlags();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue