Cicalese has uploaded a new change for review. https://gerrit.wikimedia.org/r/323252
Change subject: Split non-semantic functionality into DisplayTitle ...................................................................... Split non-semantic functionality into DisplayTitle Change-Id: If58d0b9dce6a556d50417c5af6976d63f6114b96 --- M COPYING D SemanticTitle.class.php D SemanticTitle.i18n.magic.php D SemanticTitle.i18n.php D SemanticTitle.php A SemanticTitleHooks.php A extension.json D i18n/ast.json D i18n/be-tarask.json D i18n/cs.json D i18n/de.json D i18n/dsb.json M i18n/en.json D i18n/es.json D i18n/fa.json D i18n/fi.json D i18n/fr.json D i18n/gl.json D i18n/he.json D i18n/hsb.json D i18n/hu.json D i18n/ia.json D i18n/it.json D i18n/ja.json D i18n/ko.json D i18n/ksh.json D i18n/lb.json D i18n/mk.json D i18n/ms.json D i18n/nb.json D i18n/nl.json D i18n/pl.json D i18n/pms.json D i18n/pt-br.json M i18n/qqq.json D i18n/roa-tara.json D i18n/ru.json D i18n/sv.json D i18n/tl.json D i18n/uk.json D i18n/vi.json D i18n/zh-hans.json D i18n/zh-hant.json 43 files changed, 233 insertions(+), 902 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticTitle refs/changes/52/323252/1 diff --git a/COPYING b/COPYING index 076f5fd..20db8a2 100644 --- a/COPYING +++ b/COPYING @@ -1,19 +1,21 @@ The MIT License (MIT) -Copyright (c) 2014-2015 The MITRE Corporation -Copyright (c) 2012 Van de Bugger +Copyright (c) 2016 The MITRE Corporation -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial -portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES -OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/SemanticTitle.class.php b/SemanticTitle.class.php deleted file mode 100644 index 311faf2..0000000 --- a/SemanticTitle.class.php +++ /dev/null @@ -1,464 +0,0 @@ -<?php -/* - * Copyright (c) 2014-2015 The MITRE Corporation - * Copyright (c) 2012 Van de Bugger - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -class SemanticTitle { - - /** - * @since 2.0 - * - * @param Parser &$parser - */ - public static function setup( &$parser ) { - - $parser->setFunctionHook( 'semantic-title', - __CLASS__ . '::hookSemanticTitle' ); - - return true; - - } - - /** - * Handle #semantic-title parser function. - * - * @since 1.0 - * - * @param $parser - * @param $pagename - */ - public static function hookSemanticTitle( $parser, $pagename ) { - - $title = Title::newFromText( $pagename ); - - if ( is_null( $title ) ) { - - return $pagename; - } - - self::getDisplayTitle( $title, $pagename ); - - return $pagename; - - } - - /** - * Get semantic title text. - * - * @since 2.1 - * - * @param Title $title - */ - public static function getText( Title $title ) { - - $text = $title->getPrefixedText(); - - self::getDisplayTitle( $title, $text ); - - return $text; - - } - - /** - * Handle links. Implements LinkBegin hook of Linker class. - * If a link is customized by a user (e. g. [[Target|Text]]) it should - * remain intact. Let us assume a link is not customized if its text is - * the prefixed or (to support semantic queries) non-prefixed title of - * the target page. - * - * @since 1.0 - * - * @param $dummy - * @param Title $target - * @param &$text - * @param &$customAttribs - * @param &$query - * @param &$options - * @param &$ret - */ - public static function onLinkBegin( $dummy, Title $target, &$text, - &$customAttribs, &$query, &$options, &$ret ) { - - if ( isset( $text ) ) { - - if ( !is_string( $text ) ) { - - return true; - - } - - $title = Title::newFromText( $text ); - - if ( is_null( $title ) ) { - - return true; - - } - - if ( $title->getText() != $target->getText() ) { - - return true; - - } - - if ( $title->getSubjectNsText() == $target->getSubjectNsText() || - $title->getSubjectNsText() == '' ) { - - self::getDisplayTitle( $target, $text ); - - } - - } else { - - self::getDisplayTitle( $target, $text ); - - } - - return true; - - } - - /** - * Handle self links. - * - * @since 1.3 - * - * @param Title $nt - * @param &$html - * @param &$trail - * @param &$prefix - */ - public static function onSelfLinkBegin( Title $nt, &$html, &$trail, - &$prefix, &$ret ) { - - self::getDisplayTitle( $nt, $html ); - - return true; - - } - - /** - * Display subtitle if requested - * - * @since 1.0 - * - * @param OutputPage &$out - * @param Skin &$sk - */ - public static function onBeforePageDisplay( OutputPage &$out, Skin &$sk ) { - - if ( isset( $GLOBALS['wgSemanticTitleHideSubtitle'] ) && - ! $GLOBALS['wgSemanticTitleHideSubtitle'] ) { - - $title = $out->getTitle(); - if ( ! $title instanceof Title ) { - - return true; - - } - - // remove fragment (LiquidThreads interaction) - $title = Title::newFromText( $title->getPrefixedText() ); - - if ( $title->isTalkPage() ) { - - if ( $title->getSubjectPage()->exists() ) { - - $pagename = $title->getSubjectPage()->getPrefixedText(); - $displayTitle = $pagename; - $found = self::getDisplayTitle( $title->getSubjectPage(), - $displayTitle ); - - } - - } else { - - if ( $title->exists() ) { - - $pagename = $title->getPrefixedText(); - $displayTitle = $pagename; - $found = self::getDisplayTitle( $title, $displayTitle ); - - } - - } - - - if ( ! $found || $displayTitle == $pagename ) { - - return true; - - } - - if ( $title->isTalkPage() ) { - $pagename = $title->getPrefixedText(); - } - - $out->setSubtitle( - $pagename . - ( $out->getSubtitle() == '' ? '' : ' ' . $out->getSubtitle() ) - ); - } - - return true; - - } - - /** - * Handle page title. - * - * @since 3.0 - * - * @param Parser &$parser - * @param &$text - * @param &$strip_state - */ - public static function onParserBeforeStrip( Parser &$parser, &$text, - &$strip_state ) { - - $title = $parser->getTitle(); - if ( ! $title instanceof Title ) { - - return true; - - } - - // remove fragment (LiquidThreads interaction) - $title = Title::newFromText( $title->getPrefixedText() ); - - $displayTitle = null; - - if ( $title->isTalkPage() ) { - - if ( $title->getSubjectPage()->exists() ) { - - self::getDisplayTitle( $title->getSubjectPage(), $displayTitle ); - if ( is_null( $displayTitle ) ) { - - return true; - - } - - $displayTitle = wfMessage( 'semantictitle-talkpagetitle', - $displayTitle )->plain(); - } - - } else { - - if ( $title->exists() ) { - - self::getSemanticTitle( $title, $displayTitle ); - - } - - } - - if ( is_null( $displayTitle ) ) { - - return true; - - } - - $parser->mOutput->setTitleText( $displayTitle ); - - if ( $title->exists() ) { - - $parser->mOutput->setProperty( 'displaytitle', $displayTitle ); - self::setDisplayTitle( $title, $displayTitle ); - - } - - - return true; - } - - /** - * Get displaytitle page property text. - * - * @since 3.0 - * - * @param Title $title - * @param &$displayTitle - */ - private static function getDisplayTitle( Title $title, &$displayTitle ) { - - $id = $title->getArticleID(); - - $dbr = wfGetDB( DB_SLAVE ); - $result = $dbr->select( - 'page_props', - array( 'pp_value' ), - array( - 'pp_page' => $id, - 'pp_propname' => 'displaytitle' - ), - __METHOD__ - ); - - if ( $result->numRows() > 0 ) { - $row = $result->fetchRow(); - $dt = trim( str_replace( ' ', '', strip_tags( $row['pp_value'] ) ) ); - if ( $dt !== '' ) { - $displayTitle = $row['pp_value']; - } - return true; - } - - return false; - } - - /** - * Set displaytitle page property text. - * - * @since 3.0 - * - * @param Title $title - * @param &$displayTitle - */ - private static function setDisplayTitle( Title $title, &$displayTitle ) { - - $found = self::getDisplayTitle( $title, $old ); - - if ( $found === false ) { - - $id = $title->getArticleID(); - - $dbw = wfGetDB( DB_MASTER ); - $result = $dbw->insert( - 'page_props', - array( - 'pp_page' => $id, - 'pp_propname' => 'displaytitle', - 'pp_value' => $displayTitle - ), - __METHOD__ - ); - - } else if ( $old !== $displayTitle ) { - - $id = $title->getArticleID(); - - $dbw = wfGetDB( DB_MASTER ); - $result = $dbw->update( - 'page_props', - array( - 'pp_value' => $displayTitle - ), - array( - 'pp_page' => $id, - 'pp_propname' => 'displaytitle', - ), - __METHOD__ - ); - - } - - } - - /** - * Retrieves semantic title text, if any, for the specified title. - * The semanticTitle parameter is unchanged if no semantic titie exists - * for the current title object. - * - * @since 2.0 - * - * @param $semanticTitle - */ - private static function getSemanticTitle( $title, &$semanticTitle ) { - - if ( $title->isRedirect() ) { - return; - } - - if ( ! isset( $GLOBALS['wgSemanticTitleProperties'] ) && - ! isset( $GLOBALS['wgSemanticTitleCargoFields'] ) ) { - return; - } - - $namespace = $title->getNamespace(); - - if ( isset( $GLOBALS['wgSemanticTitleProperties'] ) && - array_key_exists( $namespace, - $GLOBALS['wgSemanticTitleProperties'] ) ) { - - $label = $GLOBALS['wgSemanticTitleProperties'][ $namespace ]; - - $store = \SMW\StoreFactory::getStore(); - - if ( class_exists( 'SMWDataItem' ) ) { - $subj = SMWDIWikiPage::newFromTitle( $title ); - } else { - $subj = $title; - } - - $data = $store->getSemanticData( $subj ); - $property = SMWDIProperty::newFromUserLabel( $label ); - $values = $data->getPropertyValues( $property ); - - if ( count( $values ) > 0 ) { - - $value = array_shift( $values ); - - if ( $value->getDIType() == SMWDataItem::TYPE_STRING || - $value->getDIType() == SMWDataItem::TYPE_BLOB ) { - - $name = $value->getString(); - - if ( $name != '' ) { - - $semanticTitle = htmlspecialchars( $name, ENT_QUOTES ); - return; - - } - - } - - } - - } - - if ( isset( $GLOBALS['wgSemanticTitleCargoFields'] ) && - array_key_exists( $namespace, - $GLOBALS['wgSemanticTitleCargoFields'] ) ) { - - $table = - $GLOBALS['wgSemanticTitleCargoFields'][ $namespace ]['table']; - - $field = - $GLOBALS['wgSemanticTitleCargoFields'][ $namespace ]['field']; - - $query = CargoSQLQuery::newFromValues( $table, $field, - '_pageName="' . $title->getPrefixedText() . '"', null, - '_pageName', null, null, '' ); - $rows = $query->run(); - - if ( count( $rows ) > 0 ) { - - $name = $rows[0][$field]; - $semanticTitle = htmlspecialchars( $name, ENT_QUOTES ); - return; - - } - } - } - -} diff --git a/SemanticTitle.i18n.magic.php b/SemanticTitle.i18n.magic.php deleted file mode 100644 index 1e94e6d..0000000 --- a/SemanticTitle.i18n.magic.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -/* - * Copyright (c) 2014-2015 The MITRE Corporation - * Copyright (c) 2012 Van de Bugger - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -$magicWords = array(); - -$magicWords['en'] = array( - 'semantic-title' => array( 0, 'semantic-title' ) -); diff --git a/SemanticTitle.i18n.php b/SemanticTitle.i18n.php deleted file mode 100644 index 28c7dd1..0000000 --- a/SemanticTitle.i18n.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/** - * This is a backwards-compatibility shim, generated by: - * https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php - * - * Beginning with MediaWiki 1.23, translation strings are stored in json files, - * and the EXTENSION.i18n.php file only exists to provide compatibility with - * older releases of MediaWiki. For more information about this migration, see: - * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format - * - * This shim maintains compatibility back to MediaWiki 1.17. - */ -$messages = array(); -if ( !function_exists( 'wfJsonI18nShimbdf83b817028b3cc' ) ) { - function wfJsonI18nShimbdf83b817028b3cc( $cache, $code, &$cachedData ) { - $codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] ); - foreach ( $codeSequence as $csCode ) { - $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json"; - if ( is_readable( $fileName ) ) { - $data = FormatJson::decode( file_get_contents( $fileName ), true ); - foreach ( array_keys( $data ) as $key ) { - if ( $key === '' || $key[0] === '@' ) { - unset( $data[$key] ); - } - } - $cachedData['messages'] = array_merge( $data, $cachedData['messages'] ); - } - - $cachedData['deps'][] = new FileDependency( $fileName ); - } - return true; - } - - $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 'wfJsonI18nShimbdf83b817028b3cc'; -} diff --git a/SemanticTitle.php b/SemanticTitle.php deleted file mode 100644 index fffce72..0000000 --- a/SemanticTitle.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -/* - * Copyright (c) 2014-2015 The MITRE Corporation - * Copyright (c) 2012 Van de Bugger - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -if ( ! defined( 'MEDIAWIKI' ) ) { - die( 'This is an extension to the MediaWiki package and cannot be run standalone' ); -} - -$GLOBALS['wgExtensionCredits']['semantic'][] = array( - 'path' => __FILE__, - 'name' => 'Semantic Title', - 'version' => '3.2', - 'author' => array( - '[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy Cicalese]', - '[https://www.mediawiki.org/wiki/User:Van_de_Bugger Van de Bugger]' - ), - 'descriptionmsg' => 'semantictitle-desc', - 'url' => 'https://www.mediawiki.org/wiki/Extension:SemanticTitle', - 'license-name' => 'MIT' -); - -$GLOBALS['wgAutoloadClasses']['SemanticTitle'] = - __DIR__ . '/SemanticTitle.class.php'; - -$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'SemanticTitle::setup'; -$GLOBALS['wgHooks']['ParserBeforeStrip'][] = - 'SemanticTitle::onParserBeforeStrip'; -$GLOBALS['wgHooks']['BeforePageDisplay'][] = - 'SemanticTitle::onBeforePageDisplay'; -$GLOBALS['wgHooks']['LinkBegin'][] = 'SemanticTitle::onLinkBegin'; -$GLOBALS['wgHooks']['SelfLinkBegin'][] = 'SemanticTitle::onSelfLinkBegin'; - -$GLOBALS['wgMessagesDirs']['SemanticTitle'] = __DIR__ . '/i18n'; -$GLOBALS['wgExtensionMessagesFiles']['SemanticTitle'] = - __DIR__ . '/SemanticTitle.i18n.php'; - -$GLOBALS['wgExtensionMessagesFiles']['SemanticTitleMagic'] = - __DIR__ . '/SemanticTitle.i18n.magic.php'; diff --git a/SemanticTitleHooks.php b/SemanticTitleHooks.php new file mode 100644 index 0000000..5599643 --- /dev/null +++ b/SemanticTitleHooks.php @@ -0,0 +1,187 @@ +<?php +/* + * Copyright (c) 2014-2016 The MITRE Corporation + * Copyright (c) 2012 Van de Bugger + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +class SemanticTitleHooks { + + /** + * Implements ParserBeforeStrip hook. + * See https://www.mediawiki.org/wiki/Manual:Hooks/ParserBeforeStrip + * Handle page title. + * + * @since 3.0 + * @param Parser &$parser the Parser object + * @param string &$text the text + * @param StripState &$strip_state the strip state + * @return bool continue checking hooks + */ + public static function onParserBeforeStrip( Parser &$parser, &$text, + &$strip_state ) { + $title = $parser->getTitle(); + if ( !$title instanceof Title || $title->isTalkPage() ) { + return true; + } + $displaytitle = null; + // remove fragment + $title = Title::newFromText( $title->getPrefixedText() ); + self::getSemanticTitle( $title, $displaytitle ); + if ( is_null( $displaytitle ) ) { + return true; + } + $parser->mOutput->setTitleText( $displaytitle ); + $parser->mOutput->setProperty( 'displaytitle', $displaytitle ); + self::setDisplayTitle( $title, $displaytitle ); + return true; + } + + /** + * Get displaytitle page property text. + * + * @since 1.0 + * @param Title $title the Title object for the page + * @param string &$displaytitle to return the display title, if set + * @return boolean true if the page has a displaytitle page property that is + * different from the prefixed page name, false otherwise + */ + private static function getDisplayTitle( Title $title, &$displaytitle ) { + $pagetitle = $title->getPrefixedText(); + // remove fragment + $title = Title::newFromText( $pagetitle ); + $values = PageProps::getInstance()->getProperties( $title, 'displaytitle' ); + $id = $title->getArticleID(); + if ( array_key_exists( $id, $values ) ) { + $value = $values[$id]; + if ( trim( str_replace( ' ', '', strip_tags( $value ) ) ) !== '' && + $value !== $pagetitle ) { + $displaytitle = $value; + return true; + } + } + return false; + } + + /** + * Set displaytitle page property text. + * + * @since 3.0 + * @param Title $title the Title object + * @param string $displaytitle the display title + */ + private static function setDisplayTitle( Title $title, $displaytitle ) { + $found = self::getDisplayTitle( $title, $old ); + if ( $found === false ) { + $id = $title->getArticleID(); + $dbw = wfGetDB( DB_MASTER ); + $result = $dbw->insert( + 'page_props', + [ + 'pp_page' => $id, + 'pp_propname' => 'displaytitle', + 'pp_value' => $displaytitle + ], + __METHOD__ + ); + } elseif ( $old !== $displaytitle ) { + $id = $title->getArticleID(); + $dbw = wfGetDB( DB_MASTER ); + $result = $dbw->update( + 'page_props', + [ + 'pp_value' => $displaytitle + ], + [ + 'pp_page' => $id, + 'pp_propname' => 'displaytitle', + ], + __METHOD__ + ); + } + } + + /** + * Retrieves semantic title text, if any, for the specified title. + * The semantictitle parameter is unchanged if no semantic titie exists + * for the current title object. + * + * @since 2.0 + * @param Title $title the Title object + * @param string &$semantictitle returns semantic title, if found + * @return not used + */ + private static function getSemanticTitle( $title, &$semantictitle ) { + if ( $title->isRedirect() ) { + return; + } + if ( ! isset( $GLOBALS['wgSemanticTitleProperties'] ) && + ! isset( $GLOBALS['wgSemanticTitleCargoFields'] ) ) { + return; + } + + $namespace = $title->getNamespace(); + if ( array_key_exists( $namespace, + $GLOBALS['wgSemanticTitleProperties'] ) ) { + $label = $GLOBALS['wgSemanticTitleProperties'][ $namespace ]; + $store = \SMW\StoreFactory::getStore(); + if ( class_exists( 'SMWDataItem' ) ) { + $subj = SMWDIWikiPage::newFromTitle( $title ); + } else { + $subj = $title; + } + $data = $store->getSemanticData( $subj ); + $property = SMWDIProperty::newFromUserLabel( $label ); + $values = $data->getPropertyValues( $property ); + if ( count( $values ) > 0 ) { + $value = array_shift( $values ); + if ( $value->getDIType() == SMWDataItem::TYPE_STRING || + $value->getDIType() == SMWDataItem::TYPE_BLOB ) { + $name = $value->getString(); + if ( $name != '' ) { + $semantictitle = htmlspecialchars( $name, ENT_QUOTES ); + return; + } + } elseif ( $value->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) { + $name = $value->getTitle(); + if ( $name != '' ) { + $semantictitle = htmlspecialchars( $name, ENT_QUOTES ); + return; + } + } + } + } + + if ( array_key_exists( $namespace, + $GLOBALS['wgSemanticTitleCargoFields'] ) ) { + $table = $GLOBALS['wgSemanticTitleCargoFields'][ $namespace ]['table']; + $field = $GLOBALS['wgSemanticTitleCargoFields'][ $namespace ]['field']; + $query = CargoSQLQuery::newFromValues( $table, $field, + '_pageName="' . $title->getPrefixedText() . '"', null, + '_pageName', null, null, '' ); + $rows = $query->run(); + if ( count( $rows ) > 0 ) { + $name = $rows[0][$field]; + $semantictitle = htmlspecialchars( $name, ENT_QUOTES ); + return; + } + } + } +} diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..4800df5 --- /dev/null +++ b/extension.json @@ -0,0 +1,27 @@ +{ + "name": "SemanticTitle", + "version": "4.0", + "author": [ + "[https://www.mediawiki.org/wiki/User:Van_de_Bugger Van de Bugger]", + "[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy Cicalese]" + ], + "url": "https://www.mediawiki.org/wiki/Extension:SemanticTitle", + "descriptionmsg": "semantictitle-desc", + "type": "parserhook", + "MessagesDirs": { + "SemanticTitle": [ + "i18n" + ] + }, + "AutoloadClasses": { + "SemanticTitleHooks": "SemanticTitleHooks.php" + }, + "Hooks": { + "ParserBeforeStrip": "SemanticTitleHooks::onParserBeforeStrip" + }, + "config": { + "SemanticTitleProperties": [], + "SemanticTitleCargoFields": [] + }, + "manifest_version": 1 +} diff --git a/i18n/ast.json b/i18n/ast.json deleted file mode 100644 index 6ba1b80..0000000 --- a/i18n/ast.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Xuacu" - ] - }, - "semantictitle-desc": "Define'l títulu visible de la páxina como'l valor d'una propiedá semántica", - "semantictitle-talkpagetitle": "Alderique de $1" -} diff --git a/i18n/be-tarask.json b/i18n/be-tarask.json deleted file mode 100644 index 45ba816..0000000 --- a/i18n/be-tarask.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Red Winged Duck" - ] - }, - "semantictitle-desc": "Зьмяняе бачную назву старонкі на значэньне сэмантычнай уласьцівасьці", - "semantictitle-talkpagetitle": "Абмеркаваньне $1" -} diff --git a/i18n/cs.json b/i18n/cs.json deleted file mode 100644 index df56a5f..0000000 --- a/i18n/cs.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "XenoPheX" - ] - }, - "semantictitle-desc": "Nastaví viditelný titulek stránky na hodnotu sémantické vlastnosti" -} diff --git a/i18n/de.json b/i18n/de.json deleted file mode 100644 index 15949dc..0000000 --- a/i18n/de.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Kghbln", - "Metalhead64" - ] - }, - "semantictitle-desc": "Ermöglicht die Anzeige des Seitennamens entsprechend des Werts eines semantischen Attributs", - "semantictitle-talkpagetitle": "Über $1 diskutieren" -} diff --git a/i18n/dsb.json b/i18n/dsb.json deleted file mode 100644 index 110ed3c..0000000 --- a/i18n/dsb.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Michawiki" - ] - }, - "semantictitle-desc": "Staja widobny titel boka na gódnotu semantiskeje kakosći" -} diff --git a/i18n/en.json b/i18n/en.json index 6cafc1d..cb3070e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5,6 +5,5 @@ "Van de Bugger" ] }, - "semantictitle-desc": "Sets visible page title to value of a semantic property", - "semantictitle-talkpagetitle": "Discuss $1" + "semantictitle-desc": "Sets visible page title to value of a semantic property" } diff --git a/i18n/es.json b/i18n/es.json deleted file mode 100644 index d2da7c2..0000000 --- a/i18n/es.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Armando-Martin" - ] - }, - "semantictitle-desc": "Define el título visible de la página con el valor de una propiedad semántica" -} diff --git a/i18n/fa.json b/i18n/fa.json deleted file mode 100644 index a44a6f7..0000000 --- a/i18n/fa.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Armin1392" - ] - }, - "semantictitle-desc": "نصب عنوان صفحهٔ قابل مشاهده برای مقدار یک ارزش معنایی" -} diff --git a/i18n/fi.json b/i18n/fi.json deleted file mode 100644 index d6ef70d..0000000 --- a/i18n/fi.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Nedergard" - ] - }, - "semantictitle-desc": "Näyttää sivun otsikkona semanttisen ominaisuuden arvon" -} diff --git a/i18n/fr.json b/i18n/fr.json deleted file mode 100644 index c0f8a0f..0000000 --- a/i18n/fr.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "DavidL", - "Wladek92" - ] - }, - "semantictitle-desc": "Définir le titre visible de la page à la valeur d'une propriété sémantique", - "semantictitle-talkpagetitle": "Discuter de $1" -} diff --git a/i18n/gl.json b/i18n/gl.json deleted file mode 100644 index f27966b..0000000 --- a/i18n/gl.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Toliño", - "Elisardojm" - ] - }, - "semantictitle-desc": "Define o título visible da páxina no valor dunha propiedade semántica", - "semantictitle-talkpagetitle": "Conversa $1" -} diff --git a/i18n/he.json b/i18n/he.json deleted file mode 100644 index 167c6de..0000000 --- a/i18n/he.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Amire80" - ] - }, - "semantictitle-desc": "מגדיר את הכותרת הנראית של הדף לערך של מאפיין סמנטי" -} diff --git a/i18n/hsb.json b/i18n/hsb.json deleted file mode 100644 index 8c15b5c..0000000 --- a/i18n/hsb.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Michawiki" - ] - }, - "semantictitle-desc": "Staja widźomny titul strony na hódnotu semantiskeje kajkosće" -} diff --git a/i18n/hu.json b/i18n/hu.json deleted file mode 100644 index 72ef062..0000000 --- a/i18n/hu.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "TK-999" - ] - }, - "semantictitle-desc": "A látható oldalcímet egy szemantikai tulajdonság értékére állítja be" -} diff --git a/i18n/ia.json b/i18n/ia.json deleted file mode 100644 index 3276b25..0000000 --- a/i18n/ia.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "McDutchie" - ] - }, - "semantictitle-desc": "Defini le titulo visibile del pagina como le valor de un proprietate semantic" -} diff --git a/i18n/it.json b/i18n/it.json deleted file mode 100644 index 476743d..0000000 --- a/i18n/it.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Beta16", - "Selven" - ] - }, - "semantictitle-desc": "Imposta il titolo visibile della pagina in base al valore di una proprietà semantica", - "semantictitle-talkpagetitle": "Discuti $1" -} diff --git a/i18n/ja.json b/i18n/ja.json deleted file mode 100644 index 5b2fc56..0000000 --- a/i18n/ja.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Shirayuki" - ] - }, - "semantictitle-desc": "表示されるページ名を意味的プロパティの値に設定する" -} diff --git a/i18n/ko.json b/i18n/ko.json deleted file mode 100644 index 7bceac4..0000000 --- a/i18n/ko.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Freebiekr", - "아라", - "Revi" - ] - }, - "semantictitle-desc": "보이는 문서 제목을 시맨틱 속성 값으로 설정합니다", - "semantictitle-talkpagetitle": "$1 토론하기" -} diff --git a/i18n/ksh.json b/i18n/ksh.json deleted file mode 100644 index 51db450..0000000 --- a/i18n/ksh.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Purodha" - ] - }, - "semantictitle-desc": "Säz dä aanjezeischte Siggetittel op ene Wäät vun ene sematesche Eijeschaff.", - "semantictitle-talkpagetitle": "„$1“ beklaafe" -} diff --git a/i18n/lb.json b/i18n/lb.json deleted file mode 100644 index e6e8b4a..0000000 --- a/i18n/lb.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Robby" - ] - }, - "semantictitle-desc": "Setzt de sichtbare Säitentitel op de Wäert vun enger semantescher Eegeschaft", - "semantictitle-talkpagetitle": "$1 diskutéieren" -} diff --git a/i18n/mk.json b/i18n/mk.json deleted file mode 100644 index c44ecd7..0000000 --- a/i18n/mk.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Bjankuloski06" - ] - }, - "semantictitle-desc": "Го менува видливиот наслов на страницата во вредност на семантичкото својство", - "semantictitle-talkpagetitle": "Поразговарајте за $1" -} diff --git a/i18n/ms.json b/i18n/ms.json deleted file mode 100644 index 173c844..0000000 --- a/i18n/ms.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Anakmalaysia" - ] - }, - "semantictitle-talkpagetitle": "Bincangkan $1" -} diff --git a/i18n/nb.json b/i18n/nb.json deleted file mode 100644 index fe80e63..0000000 --- a/i18n/nb.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Event", - "Jon Harald Søby" - ] - }, - "semantictitle-desc": "Setter synlig sidetittel til verdien av en semantisk egenskap", - "semantictitle-talkpagetitle": "Diskuter $1" -} diff --git a/i18n/nl.json b/i18n/nl.json deleted file mode 100644 index 2657e1f..0000000 --- a/i18n/nl.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Siebrand", - "Rcdeboer" - ] - }, - "semantictitle-desc": "Stel de zichtbare paginanaam in op de waarde van een semantische eigenschap", - "semantictitle-talkpagetitle": "Bespreek $1" -} diff --git a/i18n/pl.json b/i18n/pl.json deleted file mode 100644 index 5d3a589..0000000 --- a/i18n/pl.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "BeginaFelicysym" - ] - }, - "semantictitle-desc": "Ustawia widoczny tytuł strony jako wartość właściwości semantycznej" -} diff --git a/i18n/pms.json b/i18n/pms.json deleted file mode 100644 index d933f41..0000000 --- a/i18n/pms.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Borichèt", - "Dragonòt" - ] - }, - "semantictitle-desc": "A ampòsta ël tìtol visìbil dla pàgina al valor ëd na proprietà semàntica" -} diff --git a/i18n/pt-br.json b/i18n/pt-br.json deleted file mode 100644 index 65ee235..0000000 --- a/i18n/pt-br.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Jaideraf" - ] - }, - "semantictitle-desc": "Define o título visível da página com o valor de uma propriedade semântica", - "semantictitle-talkpagetitle": "Discuta $1" -} diff --git a/i18n/qqq.json b/i18n/qqq.json index c54b942..9a7dd10 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -1,12 +1,12 @@ { "@metadata": { "authors": [ + "Cindy Cicalese", "Purodha", "Shirayuki", "Liuxinyu970226", "Umherirrender" ] }, - "semantictitle-desc": "{{desc|name=Semantic Title|url=https://www.mediawiki.org/wiki/Extension:SemanticTitle}}", - "semantictitle-talkpagetitle": "Format string for the title of a talk page; $1 is the semantic title of the subject page corresponding to the talk page.\n{{Identical|Discuss}}" + "semantictitle-desc": "{{desc|name=Semantic Title|url=https://www.mediawiki.org/wiki/Extension:SemanticTitle}}" } diff --git a/i18n/roa-tara.json b/i18n/roa-tara.json deleted file mode 100644 index 1f0acc9..0000000 --- a/i18n/roa-tara.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Joetaras" - ] - }, - "semantictitle-desc": "'Mboste 'u titole d'a pàgene visibbile cumme valore de 'na probbietà semandeche", - "semantictitle-talkpagetitle": "'Ngazzamende $1" -} diff --git a/i18n/ru.json b/i18n/ru.json deleted file mode 100644 index bb1037e..0000000 --- a/i18n/ru.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Okras" - ] - }, - "semantictitle-desc": "Изменяет видимое имя страницы на значение семантического свойства.", - "semantictitle-talkpagetitle": "Обсудить $1" -} diff --git a/i18n/sv.json b/i18n/sv.json deleted file mode 100644 index eb1115e..0000000 --- a/i18n/sv.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Martinwiss", - "Lokal Profil" - ] - }, - "semantictitle-desc": "Sätter den synliga titeln för en sida till värdet hos en semantisk egenskap", - "semantictitle-talkpagetitle": "Diskutera $1" -} diff --git a/i18n/tl.json b/i18n/tl.json deleted file mode 100644 index 754df98..0000000 --- a/i18n/tl.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "AnakngAraw" - ] - }, - "semantictitle-desc": "Nagtatakda ng nakikitang pamagat ng pahina sa halaga ng isang semantikong katangiang-ari" -} diff --git a/i18n/uk.json b/i18n/uk.json deleted file mode 100644 index b822b5f..0000000 --- a/i18n/uk.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Base", - "Ата" - ] - }, - "semantictitle-desc": "Заміняє заголовок сторінки на значення семантичної властивості", - "semantictitle-talkpagetitle": "Обговорення $1" -} diff --git a/i18n/vi.json b/i18n/vi.json deleted file mode 100644 index e67a5a8..0000000 --- a/i18n/vi.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Max20091" - ] - }, - "semantictitle-talkpagetitle": "Thảo luận $1" -} diff --git a/i18n/zh-hans.json b/i18n/zh-hans.json deleted file mode 100644 index c5eb8f5..0000000 --- a/i18n/zh-hans.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "@metadata": { - "authors": [ - "Linforest", - "Liuxinyu970226" - ] - }, - "semantictitle-desc": "将可见的页面标题设置为语义属性的取值", - "semantictitle-talkpagetitle": "讨论$1" -} diff --git a/i18n/zh-hant.json b/i18n/zh-hant.json deleted file mode 100644 index 909a4bb..0000000 --- a/i18n/zh-hant.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "@metadata": [], - "semantictitle-desc": "將可見的頁面標題設置為語義屬性的取值" -} -- To view, visit https://gerrit.wikimedia.org/r/323252 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If58d0b9dce6a556d50417c5af6976d63f6114b96 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SemanticTitle Gerrit-Branch: master Gerrit-Owner: Cicalese <cical...@mitre.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits