X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=56e9b44cc59c3e91e9ce0b44708931f726a06ec0;hb=99c92a87fc32fb897da320dd12b391a0d9be12c7;hp=734e009e8a44bb2923103621570d9b57d8b366eb;hpb=75da5baa3f353a326edaf9ee4e0bbaed097f725a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 734e009e8a..56e9b44cc5 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -491,6 +491,108 @@ class Title { return $rxTc; } + /** + * Utility method for converting a character sequence from bytes to Unicode. + * + * Primary usecase being converting $wgLegalTitleChars to a sequence usable in + * javascript, as PHP uses UTF-8 bytes where javascript uses Unicode code units. + * + * @param string $byteClass + * @return string + */ + public static function convertByteClassToUnicodeClass( $byteClass ) { + $length = strlen( $byteClass ); + // Input token queue + $x0 = $x1 = $x2 = ''; + // Decoded queue + $d0 = $d1 = $d2 = ''; + // Decoded integer codepoints + $ord0 = $ord1 = $ord2 = 0; + // Re-encoded queue + $r0 = $r1 = $r2 = ''; + // Output + $out = ''; + // Flags + $allowUnicode = false; + for ( $pos = 0; $pos < $length; $pos++ ) { + // Shift the queues down + $x2 = $x1; + $x1 = $x0; + $d2 = $d1; + $d1 = $d0; + $ord2 = $ord1; + $ord1 = $ord0; + $r2 = $r1; + $r1 = $r0; + // Load the current input token and decoded values + $inChar = $byteClass[$pos]; + if ( $inChar == '\\' ) { + if ( preg_match( '/x([0-9a-fA-F]{2})/A', $byteClass, $m, 0, $pos + 1 ) ) { + $x0 = $inChar . $m[0]; + $d0 = chr( hexdec( $m[1] ) ); + $pos += strlen( $m[0] ); + } elseif ( preg_match( '/[0-7]{3}/A', $byteClass, $m, 0, $pos + 1 ) ) { + $x0 = $inChar . $m[0]; + $d0 = chr( octdec( $m[0] ) ); + $pos += strlen( $m[0] ); + } elseif ( $pos + 1 >= $length ) { + $x0 = $d0 = '\\'; + } else { + $d0 = $byteClass[$pos + 1]; + $x0 = $inChar . $d0; + $pos += 1; + } + } else { + $x0 = $d0 = $inChar; + } + $ord0 = ord( $d0 ); + // Load the current re-encoded value + if ( $ord0 < 32 || $ord0 == 0x7f ) { + $r0 = sprintf( '\x%02x', $ord0 ); + } elseif ( $ord0 >= 0x80 ) { + // Allow unicode if a single high-bit character appears + $r0 = sprintf( '\x%02x', $ord0 ); + $allowUnicode = true; + } elseif ( strpos( '-\\[]^', $d0 ) !== false ) { + $r0 = '\\' . $d0; + } else { + $r0 = $d0; + } + // Do the output + if ( $x0 !== '' && $x1 === '-' && $x2 !== '' ) { + // Range + if ( $ord2 > $ord0 ) { + // Empty range + } elseif ( $ord0 >= 0x80 ) { + // Unicode range + $allowUnicode = true; + if ( $ord2 < 0x80 ) { + // Keep the non-unicode section of the range + $out .= "$r2-\\x7F"; + } + } else { + // Normal range + $out .= "$r2-$r0"; + } + // Reset state to the initial value + $x0 = $x1 = $d0 = $d1 = $r0 = $r1 = ''; + } elseif ( $ord2 < 0x80 ) { + // ASCII character + $out .= $r2; + } + } + if ( $ord1 < 0x80 ) { + $out .= $r1; + } + if ( $ord0 < 0x80 ) { + $out .= $r0; + } + if ( $allowUnicode ) { + $out .= '\u0080-\uFFFF'; + } + return $out; + } + /** * Get a string representation of a title suitable for * including in a search index @@ -3063,7 +3165,7 @@ class Title { return false; } - if ( false !== strpos( $dbkey, UTF8_REPLACEMENT ) ) { + if ( strpos( $dbkey, UTF8_REPLACEMENT ) !== false ) { # Contained illegal UTF-8 sequences or forbidden Unicode chars. return false; } @@ -3200,6 +3302,7 @@ class Title { # Can't make a link to a namespace alone... "empty" local links can only be # self-links with a fragment identifier. + # TODO: Why do we exclude NS_MAIN (bug 54044) if ( $dbkey == '' && $this->mInterwiki == '' && $this->mNamespace != NS_MAIN ) { return false; } @@ -3620,6 +3723,8 @@ class Title { $createRedirect = true; } + wfRunHooks( 'TitleMove', array( $this, $nt, $wgUser ) ); + // If it is a file, move it first. // It is done before all other moving stuff is done because it's hard to revert. $dbw = wfGetDB( DB_MASTER ); @@ -3694,7 +3799,7 @@ class Title { $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason; } // @todo FIXME: $params? - $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ) ); + $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ), $wgUser ); } # Update watchlists @@ -3736,7 +3841,8 @@ class Title { if ( $createRedirect ) { $contentHandler = ContentHandler::getForTitle( $this ); - $redirectContent = $contentHandler->makeRedirectContent( $nt ); + $redirectContent = $contentHandler->makeRedirectContent( $nt, + wfMessage( 'move-redirect-text' )->inContentLanguage()->plain() ); // NOTE: If this page's content model does not support redirects, $redirectContent will be null. } else {