54 public function add( $name ) {
55 $this->names[] =
$name;
56 $this->hash = $this->baseRegex = $this->regex =
null;
65 $this->names = array_merge( $this->names, array_values(
$names ) );
66 $this->hash = $this->baseRegex = $this->regex =
null;
74 if ( is_null( $this->hash ) ) {
76 $this->hash = [ 0 => [], 1 => [] ];
77 foreach ( $this->names as $name ) {
79 $case = intval( $magic->isCaseSensitive() );
80 foreach ( $magic->getSynonyms() as $syn ) {
84 $this->hash[$case][$syn] =
$name;
96 if ( is_null( $this->baseRegex ) ) {
97 $this->baseRegex = [ 0 =>
'', 1 =>
'' ];
99 foreach ( $this->names as $name ) {
101 $case = intval( $magic->isCaseSensitive() );
102 foreach ( $magic->getSynonyms() as $i => $syn ) {
104 $it = strtr( $i,
'0123456789',
'abcdefghij' );
105 $groupName = $it .
'_' .
$name;
106 $group =
'(?P<' . $groupName .
'>' . preg_quote( $syn,
'/' ) .
')';
108 if ( isset( $allGroups[$groupName] ) ) {
110 __METHOD__ .
': duplicate internal name in magic word array: ' . $name
113 $allGroups[$groupName] =
true;
114 if ( $this->baseRegex[$case] ===
'' ) {
115 $this->baseRegex[$case] = $group;
117 $this->baseRegex[$case] .=
'|' . $group;
130 if ( is_null( $this->regex ) ) {
132 $this->regex = [
'',
'' ];
133 if ( $this->baseRegex[0] !==
'' ) {
134 $this->regex[0] =
"/{$base[0]}/iuS";
136 if ( $this->baseRegex[1] !==
'' ) {
137 $this->regex[1] =
"/{$base[1]}/S";
149 return str_replace(
"\\$1",
"(.*?)", $this->
getRegex() );
159 $newRegex = [
'',
'' ];
160 if (
$base[0] !==
'' ) {
161 $newRegex[0] =
"/^(?:{$base[0]})/iuS";
163 if (
$base[1] !==
'' ) {
164 $newRegex[1] =
"/^(?:{$base[1]})/S";
176 $newRegex = [
'',
'' ];
177 if (
$base[0] !==
'' ) {
178 $newRegex[0] = str_replace(
"\\$1",
"(.*?)",
"/^(?:{$base[0]})$/iuS" );
180 if (
$base[1] !==
'' ) {
181 $newRegex[1] = str_replace(
"\\$1",
"(.*?)",
"/^(?:{$base[1]})$/S" );
206 while ( ( $key =
key( $m ) ) !==
null ) {
209 if ( $key === 0 ||
$value ===
'' ) {
212 $parts = explode(
'_', $key, 2 );
213 if ( count( $parts ) != 2 ) {
216 throw new MWException( __METHOD__ .
': bad parameter name' );
218 list( , $magicName ) = $parts;
219 $paramValue = next( $m );
220 return [ $magicName, $paramValue ];
223 throw new MWException( __METHOD__ .
': parameter not found' );
238 foreach ( $regexes as
$regex ) {
241 if ( preg_match(
$regex, $text, $m ) ) {
246 return [
false,
false ];
259 if ( isset(
$hash[1][$text] ) ) {
260 return $hash[1][$text];
264 if ( isset(
$hash[0][$lc] ) ) {
265 return $hash[0][$lc];
281 foreach ( $regexes as
$regex ) {
287 if (
$res ===
false ) {
288 LoggerFactory::getInstance(
'parser' )->warning(
'preg_match_all returned false', [
289 'code' => preg_last_error(),
296 $found[
$name] = $param;
300 if (
$res ===
null ) {
301 LoggerFactory::getInstance(
'parser' )->warning(
'preg_replace returned null', [
302 'code' => preg_last_error(),
324 foreach ( $regexes as
$regex ) {
328 if ( preg_match(
$regex, $text, $m ) ) {
330 if ( strlen( $m[0] ) >= strlen( $text ) ) {
333 $text = substr( $text, strlen( $m[0] ) );
Class for handling an array of magic words.
matchVariableStartToEnd( $text)
Match some text, with parameter capture Returns an array with the magic word name in the first elemen...
add( $name)
Add a magic word by name.
getVariableRegex()
Get a regex for matching variables with parameters.
parseMatch( $m)
Parse a match array from preg_match Returns array(magic word ID, parameter value) If there is no para...
matchStartToEnd( $text)
Match some text, without parameter capture Returns the magic word name, or false if there was no capt...
getRegexStart()
Get a regex anchored to the start of the string that does not match parameters.
getBaseRegex()
Get the base regex.
matchStartAndRemove(&$text)
Return the ID of the magic word at the start of $text, and remove the prefix from $text.
getRegex()
Get an unanchored regex that does not match parameters.
getVariableStartToEndRegex()
Get an anchored regex for matching variables with parameters.
getHash()
Get a 2-d hashtable for this array.
matchAndRemove(&$text)
Returns an associative array, ID => param value, for all items that match Removes the matched items f...
addArray( $names)
Add a number of magic words by name.
static & get( $id)
Factory: creates an object representing an ID.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Allows to change the fields on the form that will be generated $name
processing should stop and the error should be shown to the user * false