summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Hooks/TitleIsAlwaysKnown.php
blob: 31a16dfc9bee5b5533676b1cb5927f2400c3cdb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

namespace SMW\MediaWiki\Hooks;

use SMW\DIProperty;
use Title;

/**
 * Allows overriding default behaviour for determining if a page exists
 *
 * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleIsAlwaysKnown
 *
 * @license GNU GPL v2+
 * @since 2.0
 *
 * @author mwjames
 */
class TitleIsAlwaysKnown {

	/**
	 * @var Title
	 */
	private $title;

	/**
	 * @var mixed
	 */
	private $result;

	/**
	 * @since  2.0
	 *
	 * @param Title $title
	 * @param mixed &$result
	 */
	public function __construct( Title $title, &$result ) {
		$this->title = $title;
		$this->result =& $result;
	}

	/**
	 * @since 2.0
	 *
	 * @return boolean
	 */
	public function process() {

		// Two possible ways of going forward:
		//
		// The FIRST seen here is to use the hook to override the known status
		// for predefined properties in order to avoid any edit link
		// which makes no-sense for predefined properties
		//
		// The SECOND approach is to inject SMWWikiPageValue with a setLinkOptions setter
		// that enables to set the custom options 'known' for each invoked linker during
		// getShortHTMLText
		// $linker->link( $this->getTitle(), $caption, $customAttributes, $customQuery, $customOptions )
		//
		// @see also HooksTest::testOnTitleIsAlwaysKnown

		if ( $this->title->getNamespace() === SMW_NS_PROPERTY ) {
			if ( !DIProperty::newFromUserLabel( $this->title->getText() )->isUserDefined() ) {
				$this->result = true;
			}
		}

		return true;
	}

}