r93759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93758‎ | r93759 | r93760 >
Date:15:40, 2 August 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Introduce a hook so extensions can customize what's considered to be a CSS/JS page. This is needed for the Gadgets extension in the RL2 branch
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1743,6 +1743,10 @@
17441744 $title: The title in question.
17451745 &$types: The types of protection available.
17461746
 1747+'TitleIsCssOrJsPage': Called when determining if a page is a CSS or JS page
 1748+$title: Title object that is being checked
 1749+$result: Boolean; whether MediaWiki currently thinks this is a CSS/JS page. Hooks may change this value to override the return value of Title::isCssOrJsPage()
 1750+
17471751 'TitleMoveComplete': after moving an article (title)
17481752 $old: old title
17491753 $nt: new title
Index: trunk/phase3/includes/Title.php
@@ -1949,8 +1949,10 @@
19501950 * @return Bool
19511951 */
19521952 public function isCssOrJsPage() {
1953 - return $this->mNamespace == NS_MEDIAWIKI
 1953+ $retval = $this->mNamespace == NS_MEDIAWIKI
19541954 && preg_match( '!\.(?:css|js)$!u', $this->mTextform ) > 0;
 1955+ wfRunHooks( 'TitleIsCssOrJsPage', array( $this, &$retval ) );
 1956+ return $retval;
19551957 }
19561958
19571959 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r93761In ResourceLoaderWikiModule, use isCssOrJsPage() as well as isCssJsSubpage() ...catrope16:00, 2 August 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   20:14, 2 August 2011

Maybe the return value of the hook's handler should be checked?

#Comment by Catrope (talk | contribs)   12:56, 10 August 2011

And what would we do differently if it's true or false? The documentation is maybe a bit terse, but the idea is that this hook works just like userCan: change &$retval to change the return value, and return true/false to allow/prevent other hooks from running. The latter is done by wfRunHooks() behind the scenes.

#Comment by Aaron Schulz (talk | contribs)   16:35, 10 August 2011

Once one hook sets it to false, should others be allowed to make it true (returning false could prevent this)? I don't know, it seems odd though.

#Comment by Aaron Schulz (talk | contribs)   21:57, 11 August 2011

Nevermind, that can't happen.

Status & tagging log