From c484323a70417eae3163f058bb7d6abf8ca5817d Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 05:34:54 +0200 Subject: [PATCH 01/16] First working test. --- extension.json | 3 ++- includes/LinkTitles_Extension.php | 18 ++++++++++++------ tests/phpunit/ParseOnEditTest.php | 17 +++++++++++++++++ tests/phpunit/TestCase.php | 19 +++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 tests/phpunit/ParseOnEditTest.php create mode 100644 tests/phpunit/TestCase.php diff --git a/extension.json b/extension.json index fe3ee4a..c62d595 100644 --- a/extension.json +++ b/extension.json @@ -34,7 +34,8 @@ }, "AutoloadClasses": { "LinkTitles\\Extension": "includes/LinkTitles_Extension.php", - "LinkTitles\\Special": "includes/LinkTitles_Special.php" + "LinkTitles\\Special": "includes/LinkTitles_Special.php", + "LinkTitles\\TestCase": "tests/phpunit/TestCase.php" }, "SpecialPages": { "LinkTitles": "LinkTitles\\Special" diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index 31e4c72..8258518 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -73,6 +73,12 @@ class Extension { self::BuildDelimiters(); } + /// Helper method to be used in unit testing, were everything takes place + /// in one request. + public static function invalidateCache() { + self::fetchPageTitles(); + } + /// Event handler that is hooked to the PageContentSave event. public static function onPageContentSave( &$wikiPage, &$user, &$content, &$summary, $isMinor, $isWatch, $section, &$flags, &$status ) { @@ -135,7 +141,7 @@ class Extension { if ( !isset( self::$pageTitles ) || ( $currentNamespace != self::$currentNamespace ) ) { self::$currentNamespace = $currentNamespace; - self::$pageTitles = self::fetchPageTitles( $currentNamespace ); + self::fetchPageTitles(); } // Iterate through the page titles @@ -269,8 +275,7 @@ class Extension { } // Fetches the page titles from the database. - // @param $currentNamespace String holding the namespace of the page currently being processed. - private static function fetchPageTitles( $currentNamespace ) { + private static function fetchPageTitles() { global $wgLinkTitlesPreferShortTitles; global $wgLinkTitlesMinimumTitleLength; global $wgLinkTitlesBlackList; @@ -282,8 +287,8 @@ class Extension { $blackList = str_replace( ' ', '_', '("' . implode( '","',$wgLinkTitlesBlackList ) . '")' ); // Build our weight list. Make sure current namespace is first element - $namespaces = array_diff( $wgLinkTitlesNamespaces, [ $currentNamespace ] ); - array_unshift( $namespaces, $currentNamespace ); + $namespaces = array_diff( $wgLinkTitlesNamespaces, [ self::$currentNamespace ] ); + array_unshift( $namespaces, self::$currentNamespace ); // No need for sanitiy check. we are sure that we have at least one element in the array $weightSelect = "CASE page_namespace "; @@ -326,7 +331,8 @@ class Extension { ); } - return $res; + self::$pageTitles = $res; + return true; } // Build an anonymous callback function to be used in simple mode. diff --git a/tests/phpunit/ParseOnEditTest.php b/tests/phpunit/ParseOnEditTest.php new file mode 100644 index 0000000..0d5f36c --- /dev/null +++ b/tests/phpunit/ParseOnEditTest.php @@ -0,0 +1,17 @@ +setMwGlobals( [ + 'wgLinkTitlesParseOnEdit' => true, + 'wgLinkTitlesParseOnRender' => true + ] ); + $pageId = $this->insertPage( 'test page', 'This page should link to the link target' )['id']; + $page = WikiPage::newFromId( $pageId ); + $this->assertSame( 'This page should link to the [[link target]]', self::getPageText( $page ) ); + } +} diff --git a/tests/phpunit/TestCase.php b/tests/phpunit/TestCase.php new file mode 100644 index 0000000..5c4929c --- /dev/null +++ b/tests/phpunit/TestCase.php @@ -0,0 +1,19 @@ +insertPage( 'link target', 'This page serves as a link target' ); + Extension::invalidateCache(); + } + + protected function tearDown() { + parent::tearDown(); + } + + protected function getPageText( \WikiPage $page ) { + $content = $page->getContent(); + return $page->getContentHandler()->serializeContent( $content ); + } +} From a7bd7d19ef125ef129426bed5d96b60ffbb899d7 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 05:55:49 +0200 Subject: [PATCH 02/16] Add testing instructions to README.md. --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/README.md b/README.md index bc4847a..5ed74ff 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,66 @@ Contributors - Daniel Kraus (@bovender), main developer - Ulrich Strauss (@c0nnex), namespaces - Brent Laabs (@labster), code review and bug fixes + + +Testing +------- + +Starting from version 4.2.0, LinkTitles finally comes with phpunit tests. + +Here's how I set up the testing environment. This may not be the canonical way +to do it. Basic information on testing MediaWiki can be found [here](https://www.mediawiki.org/wiki/Manual:PHP_unit_testing). + +The following assumes that you have an instance of MediaWiki running locally +on your development machine. This assumes that you are running Linux (I personally +use Ubuntu). + +1. Pull the MediaWiki repository: + + cd ~/Code + git clone --depth 1 https://phabricator.wikimedia.org/source/mediawiki.git + +2. Install [composer](https://getcomposer.org) locally and fetch the + dependencies (including development dependencies): + + Follow the instructions on the [composer download page](https://getcomposer.org/download), + but instead of running `php composer-setup.php`, run: + + php composer-setup.php --install-dir=bin --filename=composer + bin/composer install + +3. Install phpunit (it was already installed on my Ubuntu system when I began + testing LinkTitles, so I leave it up to you to figure out how to do it). + +4. Copy your `LocalSettings.php` over from your local MediaWiki installation + and remove (or comment out) any lines that reference extensions or skins that + you are not going to install to your test environment. For the purposes of + testing the LinkTitles extension, leave the following line in place: + + wfLoadExtensions( array( 'LinkTitles' )); + + And ensure the settings file contains the following: + + $wgShowDBErrorBacktrace = true; + +5. Create a symbolic link to your copy of the LinkTitles repository: + + cd ~/Code/mediawiki/extensions + ln -s ~/Code/LinkTitles + +6. Make sure your local MediaWiki instance is up to date. Otherwise phpunit may + fail and tell you about database problems. + + This is because the local database is used as a template for the unit tests. + For example, I initially had MW 1.26 installed on my laptop, but the cloned + repository was MW 1.29.1. It's probably also possible to clone the repository + with a specific version tag which matches your local installation. + +7. Run the tests: + + cd ~/Code/mediawiki/tests/phpunit + php phpunit.php --group bovender + + This will run all tests from the 'bovender' group, i.e. tests for my extensions. + If you linked just the LinkTitles extension in step 5, only this extension + will be tested. From 3f320778849f5b9e71d37a41f55de3e33e52ecc4 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 20:35:25 +0200 Subject: [PATCH 03/16] Refactor, add Targets class. --- Doxyfile | 445 +++++++++++++++++++----------- extension.json | 2 + includes/Config.php | 126 +++++++++ includes/LinkTitles_Extension.php | 129 ++------- includes/Targets.php | 142 ++++++++++ tests/phpunit/ConfigTest.php | 20 ++ tests/phpunit/ParseOnEditTest.php | 12 +- tests/phpunit/TestCase.php | 2 +- 8 files changed, 615 insertions(+), 263 deletions(-) create mode 100644 includes/Config.php create mode 100644 includes/Targets.php create mode 100644 tests/phpunit/ConfigTest.php diff --git a/Doxyfile b/Doxyfile index 2b4da09..330868a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1,4 +1,4 @@ -# Doxyfile 1.8.6 +# Doxyfile 1.8.13 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. @@ -46,10 +46,10 @@ PROJECT_NUMBER = PROJECT_BRIEF = "Automatically add links to existing pages." -# With the PROJECT_LOGO tag one can specify an logo or icon that is included in -# the documentation. The maximum height of the logo should not exceed 55 pixels -# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo -# to the output directory. +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. PROJECT_LOGO = @@ -60,7 +60,7 @@ PROJECT_LOGO = OUTPUT_DIRECTORY = -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and # will distribute the generated files over these directories. Enabling this # option can be useful when feeding doxygen a huge amount of source files, where @@ -70,6 +70,14 @@ OUTPUT_DIRECTORY = CREATE_SUBDIRS = NO +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. @@ -85,14 +93,14 @@ CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English -# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member # descriptions after the members that are listed in the file and class # documentation (similar to Javadoc). Set to NO to disable this. # The default value is: YES. BRIEF_MEMBER_DESC = YES -# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief # description of a member or function before the detailed description # # Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the @@ -127,7 +135,7 @@ ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO -# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the # shortest path that makes the file name unique will be used # The default value is: YES. @@ -197,9 +205,9 @@ MULTILINE_CPP_IS_BRIEF = NO INHERIT_DOCS = YES -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a -# new page for each member. If set to NO, the documentation of a member will be -# part of the file/class/namespace that contains it. +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. # The default value is: NO. SEPARATE_MEMBER_PAGES = NO @@ -261,11 +269,14 @@ OPTIMIZE_OUTPUT_VHDL = NO # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, and # language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. # -# Note For files without extension you can use no_extension as a placeholder. +# Note: For files without extension you can use no_extension as a placeholder. # # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. @@ -282,10 +293,19 @@ EXTENSION_MAPPING = MARKDOWN_SUPPORT = YES +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 0. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 0 + # When enabled doxygen tries to link words that correspond to documented # classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by by putting a % sign in front of the word -# or globally by setting AUTOLINK_SUPPORT to NO. +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. # The default value is: YES. AUTOLINK_SUPPORT = YES @@ -325,13 +345,20 @@ SIP_SUPPORT = NO IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first +# tag is set to YES then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. # The default value is: NO. DISTRIBUTE_GROUP_DOC = NO +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that # type (e.g. under the Public Functions section). Set it to NO to prevent @@ -390,7 +417,7 @@ LOOKUP_CACHE_SIZE = 0 # Build related configuration options #--------------------------------------------------------------------------- -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in # documentation are documented, even if no documentation was available. Private # class members and static file members will be hidden unless the # EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. @@ -400,35 +427,35 @@ LOOKUP_CACHE_SIZE = 0 EXTRACT_ALL = NO -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. # The default value is: NO. EXTRACT_PRIVATE = NO -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal # scope will be included in the documentation. # The default value is: NO. EXTRACT_PACKAGE = NO -# If the EXTRACT_STATIC tag is set to YES all static members of a file will be +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be # included in the documentation. # The default value is: NO. EXTRACT_STATIC = NO -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, # only classes defined in header files are included. Does not have any effect # for Java sources. # The default value is: YES. EXTRACT_LOCAL_CLASSES = YES -# This flag is only useful for Objective-C code. When set to YES local methods, +# This flag is only useful for Objective-C code. If set to YES, local methods, # which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO only methods in the interface are +# included in the documentation. If set to NO, only methods in the interface are # included. # The default value is: NO. @@ -453,21 +480,21 @@ HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set -# to NO these classes will be included in the various overviews. This option has -# no effect if EXTRACT_ALL is enabled. +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO these declarations will be +# (class|struct|union) declarations. If set to NO, these declarations will be # included in the documentation. # The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO these +# documentation blocks found inside the body of a function. If set to NO, these # blocks will be appended to the function's detailed documentation block. # The default value is: NO. @@ -481,7 +508,7 @@ HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES upper-case letters are also +# names in lower-case letters. If set to YES, upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. @@ -490,12 +517,19 @@ INTERNAL_DOCS = NO CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES the +# their full class and namespace scopes in the documentation. If set to YES, the # scope will be hidden. # The default value is: NO. HIDE_SCOPE_NAMES = NO +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. # The default value is: YES. @@ -523,14 +557,14 @@ INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the # (detailed) documentation of file and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. +# name. If set to NO, the members will appear in declaration order. # The default value is: YES. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief # descriptions of file, namespace and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. Note that +# name. If set to NO, the members will appear in declaration order. Note that # this will also influence the order of the classes in the class list. # The default value is: NO. @@ -575,27 +609,25 @@ SORT_BY_SCOPE_NAME = NO STRICT_PROTO_MATCHING = NO -# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the -# todo list. This list is created by putting \todo commands in the -# documentation. +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. # The default value is: YES. GENERATE_TODOLIST = YES -# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the -# test list. This list is created by putting \test commands in the -# documentation. +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. # The default value is: YES. GENERATE_TESTLIST = YES -# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug # list. This list is created by putting \bug commands in the documentation. # The default value is: YES. GENERATE_BUGLIST = YES -# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) # the deprecated list. This list is created by putting \deprecated commands in # the documentation. # The default value is: YES. @@ -620,8 +652,8 @@ ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES the list -# will mention the files that were used to generate the documentation. +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. # The default value is: YES. SHOW_USED_FILES = YES @@ -669,8 +701,7 @@ LAYOUT_FILE = # to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. Do not use file names with spaces, bibtex cannot handle them. See -# also \cite for info how to create references. +# search path. See also \cite for info how to create references. CITE_BIB_FILES = @@ -686,7 +717,7 @@ CITE_BIB_FILES = QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES # this implies that the warnings are on. # # Tip: Turn warnings on while writing the documentation. @@ -694,7 +725,7 @@ QUIET = NO WARNINGS = YES -# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate # warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag # will automatically be disabled. # The default value is: YES. @@ -711,12 +742,18 @@ WARN_IF_DOC_ERROR = YES # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return -# value. If set to NO doxygen will only warn about wrong or incomplete parameter -# documentation, but not about the absence of documentation. +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. # The default value is: NO. WARN_NO_PARAMDOC = NO +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. +# The default value is: NO. + +WARN_AS_ERROR = NO + # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which # will be replaced by the file and line number from which the warning originated @@ -740,10 +777,10 @@ WARN_LOGFILE = # The INPUT tag is used to specify the files and/or directories that contain # documented source files. You may enter file names like myfile.cpp or # directories like /usr/src/myproject. Separate the files or directories with -# spaces. +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = +INPUT = # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -756,12 +793,17 @@ INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank the -# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, -# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, -# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, -# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, -# *.qsf, *.as and *.js. +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, +# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf. FILE_PATTERNS = @@ -769,7 +811,7 @@ FILE_PATTERNS = # be searched for input files as well. # The default value is: NO. -RECURSIVE = NO +RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a @@ -778,7 +820,8 @@ RECURSIVE = NO # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = README.md Maintenance.php +EXCLUDE = README.md \ + Maintenance.php # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -847,6 +890,10 @@ IMAGE_PATH = # Note that the filter must not add or remove lines; it is applied before the # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. INPUT_FILTER = @@ -856,11 +903,15 @@ INPUT_FILTER = # (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how # filters are used. If the FILTER_PATTERNS tag is empty or if none of the # patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER ) will also be used to filter the input files that are used for +# INPUT_FILTER) will also be used to filter the input files that are used for # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # The default value is: NO. @@ -920,7 +971,7 @@ REFERENCED_BY_RELATION = NO REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES, then the hyperlinks from functions in REFERENCES_RELATION and +# to YES then the hyperlinks from functions in REFERENCES_RELATION and # REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will # link to the documentation. # The default value is: YES. @@ -967,6 +1018,25 @@ USE_HTAGS = NO VERBATIM_HEADERS = YES +# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the +# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# cost of reduced performance. This can be particularly helpful with template +# rich C++ code for which doxygen's built-in parser lacks the necessary type +# information. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse-libclang=ON option for CMake. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- @@ -997,7 +1067,7 @@ IGNORE_PREFIX = # Configuration options related to the HTML output #--------------------------------------------------------------------------- -# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output # The default value is: YES. GENERATE_HTML = YES @@ -1059,13 +1129,15 @@ HTML_FOOTER = HTML_STYLESHEET = -# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- -# defined cascading style sheet that is included after the standard style sheets +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. -# Doxygen will copy the style sheet file to the output directory. For an example -# see the documentation. +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_STYLESHEET = @@ -1081,7 +1153,7 @@ HTML_EXTRA_STYLESHEET = HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the stylesheet and background images according to +# will adjust the colors in the style sheet and background images according to # this color. Hue is specified as an angle on a colorwheel, see # http://en.wikipedia.org/wiki/Hue for more information. For instance the value # 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 @@ -1112,8 +1184,9 @@ HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: YES. +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = YES @@ -1209,28 +1282,29 @@ GENERATE_HTMLHELP = NO CHM_FILE = # The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler ( hhc.exe). If non-empty +# including file name) of the HTML help compiler (hhc.exe). If non-empty, # doxygen will try to run the HTML help compiler on the generated index.hhp. # The file has to be specified with full path. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. HHC_LOCATION = -# The GENERATE_CHI flag controls if a separate .chi index file is generated ( -# YES) or that it should be included in the master .chm file ( NO). +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) # and project file content. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_INDEX_ENCODING = -# The BINARY_TOC flag controls whether a binary table of contents is generated ( -# YES) or a normal table of contents ( NO) in the .chm file. +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. @@ -1343,7 +1417,7 @@ DISABLE_INDEX = YES # index structure (just like the one that is generated for HTML Help). For this # to work a browser that supports JavaScript, DHTML, CSS and frames is required # (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can # further fine-tune the look of the index. As an example, the default style # sheet generated by doxygen has an example that shows how to put an image at # the root of the tree instead of the PROJECT_NAME. Since the tree basically has @@ -1371,7 +1445,7 @@ ENUM_VALUES_PER_LINE = 4 TREEVIEW_WIDTH = 250 -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to # external symbols imported via tag files in a separate window. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. @@ -1400,7 +1474,7 @@ FORMULA_TRANSPARENT = YES # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see # http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using prerendered bitmaps. Use this if you do not have LaTeX +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path # to it using the MATHJAX_RELPATH option. @@ -1470,11 +1544,11 @@ SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be # implemented using a web server instead of a web client using Javascript. There -# are two flavours of web server based searching depending on the -# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for -# searching and an index file used by the script. When EXTERNAL_SEARCH is -# enabled the indexing and searching needs to be provided by external tools. See -# the section "External Indexing and Searching" for details. +# are two flavors of web server based searching depending on the EXTERNAL_SEARCH +# setting. When disabled, doxygen will generate a PHP script for searching and +# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing +# and searching needs to be provided by external tools. See the section +# "External Indexing and Searching" for details. # The default value is: NO. # This tag requires that the tag SEARCHENGINE is set to YES. @@ -1486,7 +1560,7 @@ SERVER_BASED_SEARCH = NO # external search engine pointed to by the SEARCHENGINE_URL option to obtain the # search results. # -# Doxygen ships with an example indexer ( doxyindexer) and search engine +# Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library # Xapian (see: http://xapian.org/). # @@ -1499,7 +1573,7 @@ EXTERNAL_SEARCH = NO # The SEARCHENGINE_URL should point to a search engine hosted by a web server # which will return the search results when EXTERNAL_SEARCH is enabled. # -# Doxygen ships with an example indexer ( doxyindexer) and search engine +# Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library # Xapian (see: http://xapian.org/). See the section "External Indexing and # Searching" for details. @@ -1537,7 +1611,7 @@ EXTRA_SEARCH_MAPPINGS = # Configuration options related to the LaTeX output #--------------------------------------------------------------------------- -# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output. +# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. # The default value is: YES. GENERATE_LATEX = NO @@ -1568,7 +1642,7 @@ LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex -# If the COMPACT_LATEX tag is set to YES doxygen generates more compact LaTeX +# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. @@ -1586,9 +1660,12 @@ COMPACT_LATEX = NO PAPER_TYPE = a4 # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names -# that should be included in the LaTeX output. To get the times font for -# instance you can specify -# EXTRA_PACKAGES=times +# that should be included in the LaTeX output. The package can be specified just +# by its name or with the correct syntax as to be used with the LaTeX +# \usepackage command. To get the times font for instance you can specify : +# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times} +# To use the option intlimits with the amsmath package you can specify: +# EXTRA_PACKAGES=[intlimits]{amsmath} # If left blank no extra packages will be included. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1602,23 +1679,36 @@ EXTRA_PACKAGES = # # Note: Only use a user-defined header if you know what you are doing! The # following commands have a special meaning inside the header: $title, -# $datetime, $date, $doxygenversion, $projectname, $projectnumber. Doxygen will -# replace them by respectively the title of the page, the current date and time, -# only the current date, the version number of doxygen, the project name (see -# PROJECT_NAME), or the project number (see PROJECT_NUMBER). +# $datetime, $date, $doxygenversion, $projectname, $projectnumber, +# $projectbrief, $projectlogo. Doxygen will replace $title with the empty +# string, for the replacement values of the other commands the user is referred +# to HTML_HEADER. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_HEADER = # The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the # generated LaTeX document. The footer should contain everything after the last -# chapter. If it is left blank doxygen will generate a standard footer. +# chapter. If it is left blank doxygen will generate a standard footer. See +# LATEX_HEADER for more information on how to generate a default footer and what +# special commands can be used inside the footer. # # Note: Only use a user-defined footer if you know what you are doing! # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_FOOTER = +# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# LaTeX style sheets that are included after the standard style sheets created +# by doxygen. Using this option one can overrule certain style aspects. Doxygen +# will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EXTRA_STYLESHEET = + # The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the LATEX_OUTPUT output # directory. Note that the files will be copied as-is; there are no commands or @@ -1636,8 +1726,8 @@ LATEX_EXTRA_FILES = PDF_HYPERLINKS = YES -# If the LATEX_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate -# the PDF file directly from the LaTeX files. Set this option to YES to get a +# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate +# the PDF file directly from the LaTeX files. Set this option to YES, to get a # higher quality PDF documentation. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1678,11 +1768,19 @@ LATEX_SOURCE_CODE = NO LATEX_BIB_STYLE = plain +# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_TIMESTAMP = NO + #--------------------------------------------------------------------------- # Configuration options related to the RTF output #--------------------------------------------------------------------------- -# If the GENERATE_RTF tag is set to YES doxygen will generate RTF output. The +# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The # RTF output is optimized for Word 97 and may not look too pretty with other RTF # readers/editors. # The default value is: NO. @@ -1697,7 +1795,7 @@ GENERATE_RTF = NO RTF_OUTPUT = rtf -# If the COMPACT_RTF tag is set to YES doxygen generates more compact RTF +# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. @@ -1734,11 +1832,21 @@ RTF_STYLESHEET_FILE = RTF_EXTENSIONS_FILE = +# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code +# with syntax highlighting in the RTF output. +# +# Note that which sources are shown also depends on other settings such as +# SOURCE_BROWSER. +# The default value is: NO. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_SOURCE_CODE = NO + #--------------------------------------------------------------------------- # Configuration options related to the man page output #--------------------------------------------------------------------------- -# If the GENERATE_MAN tag is set to YES doxygen will generate man pages for +# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for # classes and files. # The default value is: NO. @@ -1762,6 +1870,13 @@ MAN_OUTPUT = man MAN_EXTENSION = .3 +# The MAN_SUBDIR tag determines the name of the directory created within +# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by +# MAN_EXTENSION with the initial . removed. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_SUBDIR = + # If the MAN_LINKS tag is set to YES and doxygen generates man output, then it # will generate one additional man file for each entity documented in the real # man page(s). These additional files only source the real man page, but without @@ -1775,7 +1890,7 @@ MAN_LINKS = NO # Configuration options related to the XML output #--------------------------------------------------------------------------- -# If the GENERATE_XML tag is set to YES doxygen will generate an XML file that +# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that # captures the structure of the code including all documentation. # The default value is: NO. @@ -1789,19 +1904,7 @@ GENERATE_XML = NO XML_OUTPUT = xml -# The XML_SCHEMA tag can be used to specify a XML schema, which can be used by a -# validating XML parser to check the syntax of the XML files. -# This tag requires that the tag GENERATE_XML is set to YES. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify a XML DTD, which can be used by a -# validating XML parser to check the syntax of the XML files. -# This tag requires that the tag GENERATE_XML is set to YES. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program +# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program # listings (including syntax highlighting and cross-referencing information) to # the XML output. Note that enabling this will significantly increase the size # of the XML output. @@ -1814,7 +1917,7 @@ XML_PROGRAMLISTING = YES # Configuration options related to the DOCBOOK output #--------------------------------------------------------------------------- -# If the GENERATE_DOCBOOK tag is set to YES doxygen will generate Docbook files +# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files # that can be used to generate PDF. # The default value is: NO. @@ -1828,14 +1931,23 @@ GENERATE_DOCBOOK = NO DOCBOOK_OUTPUT = docbook +# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the +# program listings (including syntax highlighting and cross-referencing +# information) to the DOCBOOK output. Note that enabling this will significantly +# increase the size of the DOCBOOK output. +# The default value is: NO. +# This tag requires that the tag GENERATE_DOCBOOK is set to YES. + +DOCBOOK_PROGRAMLISTING = NO + #--------------------------------------------------------------------------- # Configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- -# If the GENERATE_AUTOGEN_DEF tag is set to YES doxygen will generate an AutoGen -# Definitions (see http://autogen.sf.net) file that captures the structure of -# the code including all documentation. Note that this feature is still -# experimental and incomplete at the moment. +# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an +# AutoGen Definitions (see http://autogen.sf.net) file that captures the +# structure of the code including all documentation. Note that this feature is +# still experimental and incomplete at the moment. # The default value is: NO. GENERATE_AUTOGEN_DEF = NO @@ -1844,7 +1956,7 @@ GENERATE_AUTOGEN_DEF = NO # Configuration options related to the Perl module output #--------------------------------------------------------------------------- -# If the GENERATE_PERLMOD tag is set to YES doxygen will generate a Perl module +# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module # file that captures the structure of the code including all documentation. # # Note that this feature is still experimental and incomplete at the moment. @@ -1852,7 +1964,7 @@ GENERATE_AUTOGEN_DEF = NO GENERATE_PERLMOD = NO -# If the PERLMOD_LATEX tag is set to YES doxygen will generate the necessary +# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary # Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI # output from the Perl module output. # The default value is: NO. @@ -1860,9 +1972,9 @@ GENERATE_PERLMOD = NO PERLMOD_LATEX = NO -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be nicely +# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely # formatted so it can be parsed by a human reader. This is useful if you want to -# understand what is going on. On the other hand, if this tag is set to NO the +# understand what is going on. On the other hand, if this tag is set to NO, the # size of the Perl module output will be much smaller and Perl will parse it # just the same. # The default value is: YES. @@ -1882,14 +1994,14 @@ PERLMOD_MAKEVAR_PREFIX = # Configuration options related to the preprocessor #--------------------------------------------------------------------------- -# If the ENABLE_PREPROCESSING tag is set to YES doxygen will evaluate all +# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all # C-preprocessor directives found in the sources and include files. # The default value is: YES. ENABLE_PREPROCESSING = YES -# If the MACRO_EXPANSION tag is set to YES doxygen will expand all macro names -# in the source code. If set to NO only conditional compilation will be +# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names +# in the source code. If set to NO, only conditional compilation will be # performed. Macro expansion can be done in a controlled way by setting # EXPAND_ONLY_PREDEF to YES. # The default value is: NO. @@ -1905,7 +2017,7 @@ MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO -# If the SEARCH_INCLUDES tag is set to YES the includes files in the +# If the SEARCH_INCLUDES tag is set to YES, the include files in the # INCLUDE_PATH will be searched if a #include is found. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. @@ -1947,9 +2059,9 @@ PREDEFINED = EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will -# remove all refrences to function-like macros that are alone on a line, have an -# all uppercase name, and do not end with a semicolon. Such function macros are -# typically used for boiler-plate code, and will confuse the parser if not +# remove all references to function-like macros that are alone on a line, have +# an all uppercase name, and do not end with a semicolon. Such function macros +# are typically used for boiler-plate code, and will confuse the parser if not # removed. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. @@ -1969,15 +2081,11 @@ SKIP_FUNCTION_MACROS = YES # where loc1 and loc2 can be relative or absolute paths or URLs. See the # section "Linking to external documentation" for more information about the use # of tag files. -# Note: Each tag file must have an unique name (where the name does NOT include +# Note: Each tag file must have a unique name (where the name does NOT include # the path). If a tag file is not located in the directory in which doxygen is # run, you must also specify the path to the tagfile here. -# Documentation was cluttered when all MediaWiki content was included. It's -# too bad for the missing links to the two parent classes (Maintenance and -# SpecialPage), but if users want to look up these, they can just head over -# to mediawiki.org. -# TAGFILES = "Doxygen_mwtags.xml = https://doc.wikimedia.org/mediawiki-core/REL1_23/php/html" +TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create a # tag file that is based on the input files it reads. See section "Linking to @@ -1985,20 +2093,21 @@ SKIP_FUNCTION_MACROS = YES GENERATE_TAGFILE = -# If the ALLEXTERNALS tag is set to YES all external class will be listed in the -# class index. If set to NO only the inherited external classes will be listed. +# If the ALLEXTERNALS tag is set to YES, all external class will be listed in +# the class index. If set to NO, only the inherited external classes will be +# listed. # The default value is: NO. ALLEXTERNALS = NO -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed in -# the modules index. If set to NO, only the current project's groups will be +# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will be # listed. # The default value is: YES. EXTERNAL_GROUPS = YES -# If the EXTERNAL_PAGES tag is set to YES all external pages will be listed in +# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in # the related pages index. If set to NO, only the current project's pages will # be listed. # The default value is: YES. @@ -2015,7 +2124,7 @@ PERL_PATH = /usr/bin/perl # Configuration options related to the dot tool #--------------------------------------------------------------------------- -# If the CLASS_DIAGRAMS tag is set to YES doxygen will generate a class diagram +# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram # (in HTML and LaTeX) for classes with base or super classes. Setting the tag to # NO turns the diagrams off. Note that this option also works with HAVE_DOT # disabled, but it is recommended to install and use dot, since it yields more @@ -2040,7 +2149,7 @@ MSCGEN_PATH = DIA_PATH = -# If set to YES, the inheritance and collaboration graphs will hide inheritance +# If set to YES the inheritance and collaboration graphs will hide inheritance # and usage relations if the target is undocumented or is not a class. # The default value is: YES. @@ -2051,7 +2160,7 @@ HIDE_UNDOC_RELATIONS = YES # http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent # Bell Labs. The other options in this section have no effect if this option is # set to NO -# The default value is: NO. +# The default value is: YES. HAVE_DOT = NO @@ -2065,7 +2174,7 @@ HAVE_DOT = NO DOT_NUM_THREADS = 0 -# When you want a differently looking font n the dot files that doxygen +# When you want a differently looking font in the dot files that doxygen # generates you can specify the font name using DOT_FONTNAME. You need to make # sure dot is able to find the font, which can be done by putting it in a # standard location or by setting the DOTFONTPATH environment variable or by @@ -2113,7 +2222,7 @@ COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. # The default value is: NO. @@ -2165,7 +2274,8 @@ INCLUDED_BY_GRAPH = YES # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. +# functions only using the \callgraph command. Disabling a call graph can be +# accomplished by means of the command \hidecallgraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2176,7 +2286,8 @@ CALL_GRAPH = NO # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable caller graphs for selected -# functions only using the \callergraph command. +# functions only using the \callergraph command. Disabling a caller graph can be +# accomplished by means of the command \hidecallergraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2199,11 +2310,17 @@ GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. +# generated by dot. For an explanation of the image formats see the section +# output formats in the documentation of the dot tool (Graphviz (see: +# http://www.graphviz.org/)). # Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order # to make the SVG files visible in IE 9+ (other browsers do not have this # requirement). -# Possible values are: png, jpg, gif and svg. +# Possible values are: png, png:cairo, png:cairo:cairo, png:cairo:gd, png:gd, +# png:gd:gd, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, gif, gif:cairo, +# gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, png:cairo, +# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and +# png:gdiplus:gdiplus. # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2246,6 +2363,24 @@ MSCFILE_DIRS = DIAFILE_DIRS = +# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the +# path where java can find the plantuml.jar file. If left blank, it is assumed +# PlantUML is not used or called during a preprocessing step. Doxygen will +# generate a warning when it encounters a \startuml command in this case and +# will not generate output for the diagram. + +PLANTUML_JAR_PATH = + +# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a +# configuration file for plantuml. + +PLANTUML_CFG_FILE = + +# When using plantuml, the specified paths are searched for files specified by +# the !include statement in a plantuml block. + +PLANTUML_INCLUDE_PATH = + # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes # that will be shown in the graph. If the number of nodes in a graph becomes # larger than this value, doxygen will truncate the graph, which is visualized @@ -2282,7 +2417,7 @@ MAX_DOT_GRAPH_DEPTH = 0 DOT_TRANSPARENT = NO -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) support # this, this feature is disabled by default. @@ -2299,7 +2434,7 @@ DOT_MULTI_TARGETS = YES GENERATE_LEGEND = YES -# If the DOT_CLEANUP tag is set to YES doxygen will remove the intermediate dot +# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot # files that are used to generate the various graphs. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. diff --git a/extension.json b/extension.json index c62d595..6a0a889 100644 --- a/extension.json +++ b/extension.json @@ -34,6 +34,8 @@ }, "AutoloadClasses": { "LinkTitles\\Extension": "includes/LinkTitles_Extension.php", + "LinkTitles\\Targets": "includes/Targets.php", + "LinkTitles\\Config": "includes/Config.php", "LinkTitles\\Special": "includes/LinkTitles_Special.php", "LinkTitles\\TestCase": "tests/phpunit/TestCase.php" }, diff --git a/includes/Config.php b/includes/Config.php new file mode 100644 index 0000000..3c4702e --- /dev/null +++ b/includes/Config.php @@ -0,0 +1,126 @@ + ('bovender') + * 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. + * + * @author Daniel Kraus + */ +namespace LinkTitles; + +/** + * Holds LinkTitles configuration. + * + * This class encapsulates the global configuration variables so we do not have + * to pull those globals into scope in the individual LinkTitles classes. + * + * Using a dedicated configuration class also facilitates overriding certain + * options, i.e. in a maintenance script that is invoked with flags from the + * command line. + * + * @since 5.0.0 + */ +class Config { + /** + * Whether to add links to a page when the page is edited/saved. + * @var bool $parseOnEdit + */ + public $parseOnEdit; + + /** + * Whether to add links to a page when the page is rendered. + * @var bool $parseOnRender + */ + public $parseOnRender; + + /** + * Indicates whether to prioritize short over long titles. + * @var bool $preferShortTitles + */ + public $preferShortTitles; + + /** + * Minimum length of a page title for it to qualify as a potential link target. + * @var int $minimumTitleLength + */ + public $minimumTitleLength; + + /** + * Array of page titles that must never be link targets. + * + * This may be useful to exclude common abbreviations or acronyms from + * automatic linking. + * @var Array $blackList + */ + public $blackList; + + /** + * Array of those name spaces (integer constants) whose pages may be linked. + * @var Array $nameSpaces + */ + public $nameSpaces; + + /** + * Indicates whether to add a link to the first occurrence of a page title + * only (true), or add links to all occurrences on the source page (false). + * @var bool $firstOnly; + */ + public $firstOnly; + + /** + * Indicates whether to operate in smart mode, i.e. link to pages even if the + * case does not match. Without smart mode, pages are linked to only if the + * exact title appears on the source page. + * @var bool $smartMode; + */ + public $smartMode; + + /** + * Mirrors the global MediaWiki variable $wgCapitalLinks that indicates + * whether or not page titles are fully case sensitive + * @var bool $capitalLinks; + */ + public $capitalLinks; + + /** + * Constructs a new Config object. + * + * The object's member variables will automatically be set with the values + * from the corresponding global variables. + */ + public function __construct() { + global $wgLinkTitlesParseOnEdit; + global $wgLinkTitlesParseOnRender; + global $wgLinkTitlesPreferShortTitles; + global $wgLinkTitlesMinimumTitleLength; + global $wgLinkTitlesBlackList; + global $wgLinkTitlesNamespaces; + global $wgLinkTitlesFirstOnly; + global $wgLinkTitlesSmartMode; + global $wgCapitalLinks; + $this->parseOnEdit = $wgLinkTitlesParseOnEdit; + $this->parseOnRender = $wgLinkTitlesParseOnRender; + $this->preferShortTitles = $wgLinkTitlesPreferShortTitles; + $this->minimumTitleLength = $wgLinkTitlesMinimumTitleLength; + $this->blackList = $wgLinkTitlesBlackList; + $this->nameSpaces = $wgLinkTitlesNamespaces; + $this->firstOnly = $wgLinkTitlesFirstOnly; + $this->smartMode = $wgLinkTitlesSmartMode; + $this->capitalLinks = $wgCapitalLinks; // MediaWiki global variable + } + +} diff --git a/includes/LinkTitles_Extension.php b/includes/LinkTitles_Extension.php index 8258518..a168eec 100644 --- a/includes/LinkTitles_Extension.php +++ b/includes/LinkTitles_Extension.php @@ -1,44 +1,32 @@ ('bovender') +/** + * The LinkTitles\Extension class provides entry points for the extension. * - * 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. + * Copyright 2012-2017 Daniel Kraus ('bovender') * - * 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. + * 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. * - * 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. + * 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. + * + * @author Daniel Kraus */ -/// @file namespace LinkTitles; -/// Helper function for development and debugging. -/// @param $var Any variable. Raw content will be dumped to stderr. -/// @return undefined -function dump($var) { - error_log(print_r($var, TRUE) . "\n", 3, 'php://stderr'); -}; - -/// Central class of the extension. Sets up parser hooks. -/// This class contains only static functions; do not instantiate. +/** + * Provides entry points for the extension. + */ class Extension { - /// Caching variable for page titles that are fetched from the DB. - private static $pageTitles; - - /// Caching variable for the current namespace. - /// This is needed because the sort order of the page titles that - /// are cached in self::$pageTitles depends on the namespace of - /// the page currently being processed. - private static $currentNamespace; - /// A Title object for the page that is being parsed. private static $currentTitle; @@ -73,12 +61,6 @@ class Extension { self::BuildDelimiters(); } - /// Helper method to be used in unit testing, were everything takes place - /// in one request. - public static function invalidateCache() { - self::fetchPageTitles(); - } - /// Event handler that is hooked to the PageContentSave event. public static function onPageContentSave( &$wikiPage, &$user, &$content, &$summary, $isMinor, $isWatch, $section, &$flags, &$status ) { @@ -136,16 +118,12 @@ class Extension { ( $wgLinkTitlesFirstOnly ) ? $limit = 1 : $limit = -1; $limitReached = false; self::$currentTitle = $title; - $currentNamespace = $title->getNamespace(); $newText = $text; - if ( !isset( self::$pageTitles ) || ( $currentNamespace != self::$currentNamespace ) ) { - self::$currentNamespace = $currentNamespace; - self::fetchPageTitles(); - } + $targets = Targets::default( $title, new Config() ); // Iterate through the page titles - foreach( self::$pageTitles as $row ) { + foreach( $targets->queryResult as $row ) { self::newTarget( $row->page_namespace, $row->page_title ); // Don't link current page @@ -274,67 +252,6 @@ class Extension { return $output; } - // Fetches the page titles from the database. - private static function fetchPageTitles() { - global $wgLinkTitlesPreferShortTitles; - global $wgLinkTitlesMinimumTitleLength; - global $wgLinkTitlesBlackList; - global $wgLinkTitlesNamespaces; - - ( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'ASC' : $sort_order = 'DESC'; - // Build a blacklist of pages that are not supposed to be link - // targets. This includes the current page. - $blackList = str_replace( ' ', '_', '("' . implode( '","',$wgLinkTitlesBlackList ) . '")' ); - - // Build our weight list. Make sure current namespace is first element - $namespaces = array_diff( $wgLinkTitlesNamespaces, [ self::$currentNamespace ] ); - array_unshift( $namespaces, self::$currentNamespace ); - - // No need for sanitiy check. we are sure that we have at least one element in the array - $weightSelect = "CASE page_namespace "; - $currentWeight = 0; - foreach ($namespaces as &$namspacevalue) { - $currentWeight = $currentWeight + 100; - $weightSelect = $weightSelect . " WHEN " . $namspacevalue . " THEN " . $currentWeight . PHP_EOL; - } - $weightSelect = $weightSelect . " END "; - $namespacesClause = '(' . implode( ', ', $namespaces ) . ')'; - - // Build an SQL query and fetch all page titles ordered by length from - // shortest to longest. Only titles from 'normal' pages (namespace uid - // = 0) are returned. Since the db may be sqlite, we need a try..catch - // structure because sqlite does not support the CHAR_LENGTH function. - $dbr = wfGetDB( DB_SLAVE ); - try { - $res = $dbr->select( - 'page', - array( 'page_title', 'page_namespace' , "weight" => $weightSelect), - array( - 'page_namespace IN ' . $namespacesClause, - 'CHAR_LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength, - 'page_title NOT IN ' . $blackList, - ), - __METHOD__, - array( 'ORDER BY' => 'weight ASC, CHAR_LENGTH(page_title) ' . $sort_order ) - ); - } catch (Exception $e) { - $res = $dbr->select( - 'page', - array( 'page_title', 'page_namespace' , "weight" => $weightSelect ), - array( - 'page_namespace IN ' . $namespacesClause, - 'LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength, - 'page_title NOT IN ' . $blackList, - ), - __METHOD__, - array( 'ORDER BY' => 'weight ASC, LENGTH(page_title) ' . $sort_order ) - ); - } - - self::$pageTitles = $res; - return true; - } - // Build an anonymous callback function to be used in simple mode. private static function simpleModeCallback( array $matches ) { if ( self::checkTargetPage() ) { diff --git a/includes/Targets.php b/includes/Targets.php new file mode 100644 index 0000000..29a11d9 --- /dev/null +++ b/includes/Targets.php @@ -0,0 +1,142 @@ + ('bovender') + * + * 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. + * + * @author Daniel Kraus + */ +namespace LinkTitles; + +/** + * Fetches potential target page titles from the database. + */ +class Targets { + private static $instance; + + /** + * Singleton factory that returns a (cached) database query results with + * potential target page titles. + * + * The subset of pages that may serve as target pages depends on the + * name space of the source page. Therefore, if the $nameSpace differs from + * the cached name space, the database is queried again. + * + * @param String $nameSpace The namespace of the current page. + * @param Config $config LinkTitles configuration. + */ + public static function default( \Title $title, Config $config ) { + if ( ( self::$instance === null ) || ( self::$instance->nameSpace != $title->getNamespace() ) ) { + self::$instance = new Targets( $title, $config ); + } + return self::$instance; + } + + /** + * Invalidates the cache; the next call of Targets::default() will trigger + * a database query. + * + * Use this in unit tests which are performed in a single request cycle so that + * changes to the pages list may not be picked up by the cached Targets instance. + */ + public static function invalidate() { + self::$instance = null; + } + + /** + * Holds the results of a database query for target page titles, filtered + * and sorted. + * @var IResultWrapper $queryResult + */ + public $queryResult; + + /** + * Holds the name space (integer) for which the list of target pages was built. + * @var Int $nameSpace + */ + public $nameSpace; + + private $config; + + /** + * The constructor is private to enforce using the singleton pattern. + * @param \Title $title + */ + private function __construct( \Title $title, Config $config) { + $this->config = $config; + $this->nameSpace = $title->getNameSpace(); + $this->fetch(); + } + + // + /** + * Fetches the page titles from the database. + */ + private function fetch() { + + ( $this->config->preferShortTitles ) ? $sortOrder = 'ASC' : $sortOrder = 'DESC'; + // Build a blacklist of pages that are not supposed to be link + // targets. This includes the current page. + $blackList = str_replace( ' ', '_', '("' . implode( '","',$this->config->blackList ) . '")' ); + + // Build our weight list. Make sure current namespace is first element + $nameSpaces = array_diff( $this->config->nameSpaces, [ $this->nameSpace ] ); + array_unshift( $nameSpaces, $this->nameSpace ); + + // No need for sanitiy check. we are sure that we have at least one element in the array + $weightSelect = "CASE page_namespace "; + $currentWeight = 0; + foreach ($nameSpaces as &$nameSpaceValue) { + $currentWeight = $currentWeight + 100; + $weightSelect = $weightSelect . " WHEN " . $nameSpaceValue . " THEN " . $currentWeight . PHP_EOL; + } + $weightSelect = $weightSelect . " END "; + $nameSpacesClause = '(' . implode( ', ', $nameSpaces ) . ')'; + + // Build an SQL query and fetch all page titles ordered by length from + // shortest to longest. Only titles from 'normal' pages (namespace uid + // = 0) are returned. Since the db may be sqlite, we need a try..catch + // structure because sqlite does not support the CHAR_LENGTH function. + $dbr = wfGetDB( DB_SLAVE ); + try { + $this->queryResult = $dbr->select( + 'page', + array( 'page_title', 'page_namespace' , "weight" => $weightSelect), + array( + 'page_namespace IN ' . $nameSpacesClause, + 'CHAR_LENGTH(page_title) >= ' . $this->config->minimumTitleLength, + 'page_title NOT IN ' . $blackList, + ), + __METHOD__, + array( 'ORDER BY' => 'weight ASC, CHAR_LENGTH(page_title) ' . $sortOrder ) + ); + } catch (Exception $e) { + $this->queryResult = $dbr->select( + 'page', + array( 'page_title', 'page_namespace' , "weight" => $weightSelect ), + array( + 'page_namespace IN ' . $nameSpacesClause, + 'LENGTH(page_title) >= ' . $this->config->minimumTitleLength, + 'page_title NOT IN ' . $blackList, + ), + __METHOD__, + array( 'ORDER BY' => 'weight ASC, LENGTH(page_title) ' . $sortOrder ) + ); + } + } +} diff --git a/tests/phpunit/ConfigTest.php b/tests/phpunit/ConfigTest.php new file mode 100644 index 0000000..0d4b651 --- /dev/null +++ b/tests/phpunit/ConfigTest.php @@ -0,0 +1,20 @@ +setMwGlobals( [ + 'wgLinkTitlesParseOnEdit' => true, + 'wgLinkTitlesParseOnRender' => false + ] ); + $config = new LinkTitles\Config(); + global $wgLinkTitlesParseOnEdit; + $this->assertSame( $config->parseOnEdit, $wgLinkTitlesParseOnEdit ); + } +} diff --git a/tests/phpunit/ParseOnEditTest.php b/tests/phpunit/ParseOnEditTest.php index 0d5f36c..2441b21 100644 --- a/tests/phpunit/ParseOnEditTest.php +++ b/tests/phpunit/ParseOnEditTest.php @@ -8,10 +8,20 @@ class ParseOnEditTest extends LinkTitles\TestCase { public function testParseOnEdit() { $this->setMwGlobals( [ 'wgLinkTitlesParseOnEdit' => true, - 'wgLinkTitlesParseOnRender' => true + 'wgLinkTitlesParseOnRender' => false ] ); $pageId = $this->insertPage( 'test page', 'This page should link to the link target' )['id']; $page = WikiPage::newFromId( $pageId ); $this->assertSame( 'This page should link to the [[link target]]', self::getPageText( $page ) ); } + + public function testDoNotParseOnEdit() { + $this->setMwGlobals( [ + 'wgLinkTitlesParseOnEdit' => false, + 'wgLinkTitlesParseOnRender' => false + ] ); + $pageId = $this->insertPage( 'test page', 'This page should not link to the link target' )['id']; + $page = WikiPage::newFromId( $pageId ); + $this->assertSame( 'This page should not link to the link target', self::getPageText( $page ) ); + } } diff --git a/tests/phpunit/TestCase.php b/tests/phpunit/TestCase.php index 5c4929c..11f7743 100644 --- a/tests/phpunit/TestCase.php +++ b/tests/phpunit/TestCase.php @@ -5,7 +5,7 @@ abstract class TestCase extends \MediaWikiTestCase { protected function setUp() { parent::setUp(); $this->insertPage( 'link target', 'This page serves as a link target' ); - Extension::invalidateCache(); + Targets::invalidate(); // force re-querying the pages table } protected function tearDown() { From e2a6229487d96a51d4dd5c2bf18b729b4cbac311 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 20:57:14 +0200 Subject: [PATCH 04/16] Atom-ignore gh-pages directory. --- .atomignore | 1 + tests/phpunit/TargetsTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .atomignore create mode 100644 tests/phpunit/TargetsTest.php diff --git a/.atomignore b/.atomignore new file mode 100644 index 0000000..abeefe7 --- /dev/null +++ b/.atomignore @@ -0,0 +1 @@ +gh-pages/ diff --git a/tests/phpunit/TargetsTest.php b/tests/phpunit/TargetsTest.php new file mode 100644 index 0000000..c0debaf --- /dev/null +++ b/tests/phpunit/TargetsTest.php @@ -0,0 +1,26 @@ +getDB( DB_MASTER ); + $counter = new SiteStatsInit( $dbr ); + $count = $counter->articles(); + + $this->assertSame( $targets->queryResult->numRows(), $count ); + } +} From 5faf4a5968dd851f14b1f8b4dde2b99b78ae47f6 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 21:06:29 +0200 Subject: [PATCH 05/16] Test Targets class. --- tests/phpunit/ParseOnEditTest.php | 4 ++-- tests/phpunit/TargetsTest.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/ParseOnEditTest.php b/tests/phpunit/ParseOnEditTest.php index 2441b21..817ddfa 100644 --- a/tests/phpunit/ParseOnEditTest.php +++ b/tests/phpunit/ParseOnEditTest.php @@ -10,9 +10,9 @@ class ParseOnEditTest extends LinkTitles\TestCase { 'wgLinkTitlesParseOnEdit' => true, 'wgLinkTitlesParseOnRender' => false ] ); - $pageId = $this->insertPage( 'test page', 'This page should link to the link target' )['id']; + $pageId = $this->insertPage( 'test page', 'This page should link to the link target but not to test page' )['id']; $page = WikiPage::newFromId( $pageId ); - $this->assertSame( 'This page should link to the [[link target]]', self::getPageText( $page ) ); + $this->assertSame( 'This page should link to the [[link target]] but not to test page', self::getPageText( $page ) ); } public function testDoNotParseOnEdit() { diff --git a/tests/phpunit/TargetsTest.php b/tests/phpunit/TargetsTest.php index c0debaf..820af17 100644 --- a/tests/phpunit/TargetsTest.php +++ b/tests/phpunit/TargetsTest.php @@ -17,10 +17,10 @@ class TargetsTest extends LinkTitles\TestCase { // Count number of articles: Inspired by updateArticleCount.php maintenance // script: https://doc.wikimedia.org/mediawiki-core/master/php/updateArticleCount_8php_source.html - $dbr = $this->getDB( DB_MASTER ); + $dbr = wfGetDB( DB_SLAVE ); $counter = new SiteStatsInit( $dbr ); - $count = $counter->articles(); + $count = $counter->pages(); - $this->assertSame( $targets->queryResult->numRows(), $count ); + $this->assertEquals( $targets->queryResult->numRows(), $count ); } } From 6c75eec1bb688db2d2c6f36299612c492e94add3 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 21:08:55 +0200 Subject: [PATCH 06/16] Rename LinkTitles_Magic file. --- extension.json | 2 +- includes/{LinkTitles_Magic.php => Magic.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename includes/{LinkTitles_Magic.php => Magic.php} (100%) diff --git a/extension.json b/extension.json index 6a0a889..75f73d8 100644 --- a/extension.json +++ b/extension.json @@ -66,7 +66,7 @@ }, "callback": "LinkTitles\\Extension::setup", "ExtensionMessagesFiles": { - "LinkTitlesMagic": "includes/LinkTitles_Magic.php" + "LinkTitlesMagic": "includes/Magic.php" }, "MessagesDirs": { "LinkTitles": [ diff --git a/includes/LinkTitles_Magic.php b/includes/Magic.php similarity index 100% rename from includes/LinkTitles_Magic.php rename to includes/Magic.php From 0a519bbc180bc403a8f9f9c774448cc37aaefab7 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 21:14:59 +0200 Subject: [PATCH 07/16] Revise comments. --- includes/LinkTitles_Special.php | 183 +++++++++++++++++--------------- 1 file changed, 100 insertions(+), 83 deletions(-) diff --git a/includes/LinkTitles_Special.php b/includes/LinkTitles_Special.php index 96607a2..3abb6a3 100644 --- a/includes/LinkTitles_Special.php +++ b/includes/LinkTitles_Special.php @@ -1,21 +1,25 @@ ('bovender') +/** + * Provides a special page for the LinkTitles extension. * - * 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. + * Copyright 2012-2017 Daniel Kraus ('bovender') * - * 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. + * 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. * - * 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. + * 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. + * + * @author Daniel Kraus */ namespace LinkTitles; /// @defgroup batch Batch processing @@ -25,17 +29,21 @@ if ( !defined( 'MEDIAWIKI' ) ) { die( 'Not an entry point.' ); } /// @endcond - -/// Provides a special page that can be used to batch-process all pages in -/// the wiki. By default, this can only be performed by sysops. -/// @ingroup batch + +/** + * Provides a special page that can be used to batch-process all pages in + * the wiki. By default, this can only be performed by sysops. + * @ingroup batch + * + */ class Special extends \SpecialPage { - /// Constructor. Announces the special page title and required user right - /// to the parent constructor. + /** + * Constructor. Announces the special page title and required user right to the parent constructor. + */ function __construct() { - // the second parameter in the following function call ensures that only - // users who have the 'linktitles-batch' right get to see this page (by + // the second parameter in the following function call ensures that only + // users who have the 'linktitles-batch' right get to see this page (by // default, this are all sysop users). parent::__construct( 'LinkTitles', 'linktitles-batch' ); } @@ -44,9 +52,11 @@ class Special extends \SpecialPage { return 'pagetools'; } - /// Entry function of the special page class. Will abort if the user does - /// not have appropriate permissions ('linktitles-batch'). - /// @return undefined + + /** + * Entry function of the special page class. Will abort if the user does not have appropriate permissions ('linktitles-batch'). + * @param $par Additional parameters (required by interface; currently not used) + */ function execute($par) { // Prevent non-authorized users from executing the batch processing. if ( !$this->userCanExecute( $this->getUser() ) ) { @@ -76,18 +86,19 @@ class Special extends \SpecialPage { } } - /// Processes wiki articles, starting at the page indicated by - /// $startTitle. If $wgLinkTitlesTimeLimit is reached before all pages are - /// processed, returns the title of the next page that needs processing. - /// @param WebRequest $request WebRequest object that is associated with the special - /// page. - /// @param OutputPage $output Output page for the special page. + /** + * Processes wiki articles, starting at the page indicated by + * $startTitle. If $wgLinkTitlesTimeLimit is reached before all pages are + * processed, returns the title of the next page that needs processing. + * @param WebRequest $request WebRequest object that is associated with the special page. + * @param OutputPage $output Output page for the special page. + */ private function process( \WebRequest &$request, \OutputPage &$output) { global $wgLinkTitlesTimeLimit; - global $wgLinkTitlesNamespaces; + global $wgLinkTitlesNamespaces; - // get our Namespaces - $namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' ); + // get our Namespaces + $namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' ); // Start the stopwatch $startTime = microtime(true); @@ -95,7 +106,7 @@ class Special extends \SpecialPage { // Connect to the database $dbr = wfGetDB( DB_SLAVE ); - // Fetch the start index and max number of records from the POST + // Fetch the start index and max number of records from the POST // request. $postValues = $request->getValues(); @@ -107,26 +118,24 @@ class Special extends \SpecialPage { if ( array_key_exists('e', $postValues) ) { $end = intval($postValues['e']); } - else + else { // No end index was given. Therefore, count pages now. $end = $this->countPages($dbr, $namespacesClause ); }; - array_key_exists('r', $postValues) ? - $reloads = $postValues['r'] : - $reloads = 0; + array_key_exists('r', $postValues) ? $reloads = $postValues['r'] : $reloads = 0; // Retrieve page names from the database. - $res = $dbr->select( + $res = $dbr->select( 'page', array('page_title', 'page_namespace'), - array( - 'page_namespace IN ' . $namespacesClause, - ), - __METHOD__, array( - 'LIMIT' => 999999999, + 'page_namespace IN ' . $namespacesClause, + ), + __METHOD__, + array( + 'LIMIT' => 999999999, 'OFFSET' => $start ) ); @@ -136,7 +145,7 @@ class Special extends \SpecialPage { $curTitle = \Title::makeTitleSafe( $row->page_namespace, $row->page_title); Extension::processPage($curTitle, $this->getContext()); $start += 1; - + // Check if the time limit is exceeded if ( microtime(true)-$startTime > $wgLinkTitlesTimeLimit ) { @@ -149,11 +158,11 @@ class Special extends \SpecialPage { // If we have not reached the last page yet, produce code to reload // the extension's special page. if ( $start < $end ) - { + { $reloads += 1; - // Build a form with hidden values and output JavaScript code that + // Build a form with hidden values and output JavaScript code that // immediately submits the form in order to continue the process. - $output->addHTML($this->getReloaderForm($request->getRequestURL(), + $output->addHTML($this->getReloaderForm($request->getRequestURL(), $start, $end, $reloads)); } else // Last page has been processed @@ -162,8 +171,10 @@ class Special extends \SpecialPage { } } - /// Adds WikiText to the output containing information about the extension - /// and a form and button to start linking. + /* + * Adds WikiText to the output containing information about the extension + * and a form and button to start linking. + */ private function buildInfoPage( &$request, &$output ) { $url = $request->getRequestURL(); @@ -176,8 +187,8 @@ Source code: http://github.com/bovender/LinkTitles == Batch Linking == You can start a batch linking process by clicking on the button below. -This will go through every page in the normal namespace of your Wiki and -insert links automatically. This page will repeatedly reload itself, in +This will go through every page in the normal namespace of your Wiki and +insert links automatically. This page will repeatedly reload itself, in order to prevent blocking the server. To interrupt the process, simply close this page. EOF @@ -192,12 +203,13 @@ EOF ); } - /// Produces informative output in WikiText format to show while working. - /// @param $output Output object. - /// @param $curTitle Title of the currently processed page. - /// @param $index Index of the currently processed page. - /// @param $end Last index that will be processed (i.e., number of - /// pages). + /* + * Produces informative output in WikiText format to show while working. + * @param $output Output object. + * @param $curTitle Title of the currently processed page. + * @param $index Index of the currently processed page. + * @param $end Last index that will be processed (i.e., number of pages). + */ private function addProgressInfo( &$output, $curTitle, $index, $end ) { $progress = $index / $end * 100; $percent = sprintf("%01.1f", $progress); @@ -205,8 +217,8 @@ EOF $output->addWikiText( <<select( 'page', array('pagecount' => "COUNT(page_id)"), - array( - 'page_namespace IN ' . $namespacesClause, - ), - __METHOD__ + array( + 'page_namespace IN ' . $namespacesClause, + ), + __METHOD__ ); - + return $res->current()->pagecount; } } From e4f3da3ab62510217a38e265719f614f5620e853 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 21:15:28 +0200 Subject: [PATCH 08/16] Rename LinkTitles_Special. --- extension.json | 2 +- includes/{LinkTitles_Special.php => Special.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename includes/{LinkTitles_Special.php => Special.php} (100%) diff --git a/extension.json b/extension.json index 75f73d8..c19b194 100644 --- a/extension.json +++ b/extension.json @@ -36,7 +36,7 @@ "LinkTitles\\Extension": "includes/LinkTitles_Extension.php", "LinkTitles\\Targets": "includes/Targets.php", "LinkTitles\\Config": "includes/Config.php", - "LinkTitles\\Special": "includes/LinkTitles_Special.php", + "LinkTitles\\Special": "includes/Special.php", "LinkTitles\\TestCase": "tests/phpunit/TestCase.php" }, "SpecialPages": { diff --git a/includes/LinkTitles_Special.php b/includes/Special.php similarity index 100% rename from includes/LinkTitles_Special.php rename to includes/Special.php From 51fe6b3910ad26d59f18d9d4ed7b9edafd52832d Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 21:16:18 +0200 Subject: [PATCH 09/16] Rename LinkTitles_Extension. --- extension.json | 2 +- includes/{LinkTitles_Extension.php => Extension.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename includes/{LinkTitles_Extension.php => Extension.php} (100%) diff --git a/extension.json b/extension.json index c19b194..e976596 100644 --- a/extension.json +++ b/extension.json @@ -33,7 +33,7 @@ ] }, "AutoloadClasses": { - "LinkTitles\\Extension": "includes/LinkTitles_Extension.php", + "LinkTitles\\Extension": "includes/Extension.php", "LinkTitles\\Targets": "includes/Targets.php", "LinkTitles\\Config": "includes/Config.php", "LinkTitles\\Special": "includes/Special.php", diff --git a/includes/LinkTitles_Extension.php b/includes/Extension.php similarity index 100% rename from includes/LinkTitles_Extension.php rename to includes/Extension.php From 4d5554a74ec5e44e6265dffcb13cebb471f63e6b Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 26 Aug 2017 22:01:52 +0200 Subject: [PATCH 10/16] Add Delimiters class. --- extension.json | 2 +- includes/Config.php | 45 ++++++++++ includes/Delimiters.php | 138 +++++++++++++++++++++++++++++++ includes/Extension.php | 98 +++------------------- tests/phpunit/DelimitersTest.php | 42 ++++++++++ 5 files changed, 238 insertions(+), 87 deletions(-) create mode 100644 includes/Delimiters.php create mode 100644 tests/phpunit/DelimitersTest.php diff --git a/extension.json b/extension.json index e976596..9fa0cda 100644 --- a/extension.json +++ b/extension.json @@ -35,6 +35,7 @@ "AutoloadClasses": { "LinkTitles\\Extension": "includes/Extension.php", "LinkTitles\\Targets": "includes/Targets.php", + "LinkTitles\\Delimiters": "includes/Delimiters.php", "LinkTitles\\Config": "includes/Config.php", "LinkTitles\\Special": "includes/Special.php", "LinkTitles\\TestCase": "tests/phpunit/TestCase.php" @@ -64,7 +65,6 @@ "LinkTitles\\Extension::onParserFirstCallInit" ] }, - "callback": "LinkTitles\\Extension::setup", "ExtensionMessagesFiles": { "LinkTitlesMagic": "includes/Magic.php" }, diff --git a/includes/Config.php b/includes/Config.php index 3c4702e..5264323 100644 --- a/includes/Config.php +++ b/includes/Config.php @@ -96,6 +96,43 @@ class Config { */ public $capitalLinks; + /** + * Whether or not to link to pages only if the page title appears at the + * start of a word on the target page (i.e., link 'MediaWiki' to a page + * 'Media', but not to a page 'Wiki'). + * + * Set both $wordStartOnly and $wordEndOnly to true to enforce matching + * whole titles. + * + * @var bool $wordStartOnly; + */ + public $wordStartOnly; + + /** + * Whether or not to link to pages only if the page title appears at the + * end of a word on the target page (i.e., link 'MediaWiki' to a page + * 'Wiki', but not to a page 'Media'). + * + * Set both $wordStartOnly and $wordEndOnly to true to enforce matching + * whole titles. + * + * @var bool $wordEndOnly; + */ + public $wordEndOnly; + + /** + * Whether or not to skip templates. If set to true, text inside transclusions + * will not be linked. + * @var bool $skipTemplates + */ + public $skipTemplates; + + /** + * Whether or not to parse headings. + * @var bool $parseHeadings + */ + public $parseHeadings; + /** * Constructs a new Config object. * @@ -112,6 +149,10 @@ class Config { global $wgLinkTitlesFirstOnly; global $wgLinkTitlesSmartMode; global $wgCapitalLinks; + global $wgLinkTitlesWordStartOnly; + global $wgLinkTitlesWordEndOnly; + global $wgLinkTitlesSkipTemplates; + global $wgLinkTitlesParseHeadings; $this->parseOnEdit = $wgLinkTitlesParseOnEdit; $this->parseOnRender = $wgLinkTitlesParseOnRender; $this->preferShortTitles = $wgLinkTitlesPreferShortTitles; @@ -121,6 +162,10 @@ class Config { $this->firstOnly = $wgLinkTitlesFirstOnly; $this->smartMode = $wgLinkTitlesSmartMode; $this->capitalLinks = $wgCapitalLinks; // MediaWiki global variable + $this->wordStartOnly = $wgLinkTitlesWordStartOnly; + $this->wordEndOnly = $wgLinkTitlesWordEndOnly; + $this->skipTemplates = $wgLinkTitlesSkipTemplates; + $this->parseHeadings = $wgLinkTitlesParseHeadings; } } diff --git a/includes/Delimiters.php b/includes/Delimiters.php new file mode 100644 index 0000000..d6b513d --- /dev/null +++ b/includes/Delimiters.php @@ -0,0 +1,138 @@ + ('bovender') + * + * 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. + * + * @author Daniel Kraus + */ +namespace LinkTitles; + +/** + * Caches a regular expression that delimits text to be parsed. + */ +class Delimiters { + private static $instance; + + /** + * Singleton factory. + * + * @param Config $config LinkTitles configuration. + */ + public static function default( Config $config ) { + if ( self::$instance === null ) { + self::$instance = new Delimiters( $config ); + } + return self::$instance; + } + + /** + * Invalidates the singleton instance. + * + * Used for unit testing. + */ + public static function invalidate() { + self::$instance = null; + } + + protected function __construct( Config $config) { + $this->config = $config; + $this->buildDelimiters(); + } + + /** + * The splitting expression that separates text to be parsed from text that + * must not be parsed. + * @var String $splitter + */ + public $splitter; + + /** + * Regex that matches the start of a word; this expression depends on the + * setting of LinkTitles\Config->wordStartOnly; + * @var String $wordStart + */ + public $wordStart; + + /** + * Regex that matches the end of a word; this expression depends on the + * setting of LinkTitles\Config->wordEndOnly; + * @var String $wordEnd + */ + public $wordEnd; + + private $config; + + /* + * Builds the delimiter that is used in a regexp to separate + * text that should be parsed from text that should not be + * parsed (e.g. inside existing links etc.) + */ + private function buildDelimiters() { + // Use unicode character properties rather than \b escape sequences + // to detect whole words containing non-ASCII characters as well. + // Note that this requires a PCRE library that was compiled with + // --enable-unicode-properties + ( $this->config->wordStartOnly ) ? $this->wordStart = '(?wordStart = ''; + ( $this->config->wordEndOnly ) ? $this->wordEnd = '(?!\pL)' : $this->wordEnd = ''; + + if ( $this->config->skipTemplates ) + { + // Use recursive regex to balance curly braces; + // see http://www.regular-expressions.info/recurse.html + $templatesDelimiter = '{{(?>[^{}]|(?R))*}}|'; + } else { + // Match template names (ignoring any piped [[]] links in them) + // along with the trailing pipe and parameter name or closing + // braces; also match sequences of '|wordcharacters=' (without + // spaces in them) that usually only occur as parameter names in + // transclusions (but could also occur as wiki table cell contents). + // TODO: Find a way to match parameter names in transclusions, but + // not in table cells or other sequences involving a pipe character + // and equal sign. + $templatesDelimiter = '{{[^|]*?(?:(?:\[\[[^]]+]])?)[^|]*?(?:\|(?:\w+=)?|(?:}}))|\|\w+=|'; + } + + // Build a regular expression that will capture existing wiki links ("[[...]]"), + // wiki headings ("= ... =", "== ... ==" etc.), + // urls ("http://example.com", "[http://example.com]", "[http://example.com Description]", + // and email addresses ("mail@example.com"). + // Since there is a user option to skip headings, we make this part of the expression + // optional. Note that in order to use preg_split(), it is important to have only one + // capturing subpattern (which precludes the use of conditional subpatterns). + ( $this->config->parseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|'; + $urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?'; + $this->splitter = '/(' . // exclude from linking: + '\[\[.*?\]\]|' . // links + $delimiter . // titles (if requested) + $templatesDelimiter . // templates (if requested) + '^ .+?\n|\n .+?\n|\n .+?$|^ .+?$|' . // preformatted text + '.*?<.nowiki>|.*?<\/code>|' . // nowiki/code + '
.*?<\/pre>|.*?<\/html>|' .      // pre/html
+			'